@codedoc/core
Version:
Create beautiful modern documentation websites.
42 lines • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.smartCopy$ = exports.initSmartCopy = exports.smartCopy = void 0;
var transport_1 = require("@connectv/sdh/transport");
var clipboard_1 = require("../../transport/clipboard");
var copy_confirm_1 = require("./copy-confirm");
function _findTarget(anchor$) {
if (anchor$.previousElementSibling) {
var nephew$ = anchor$.previousElementSibling.querySelector('pre>code');
if (nephew$)
return nephew$;
var target$ = _findTarget(anchor$.previousElementSibling);
if (target$)
return target$;
else if (anchor$.parentElement)
return _findTarget(anchor$.parentElement);
}
if (anchor$.parentElement)
return _findTarget(anchor$.parentElement);
}
function smartCopy(el$, self) {
if (self === void 0) { self = false; }
var target$ = self ? el$ : _findTarget(el$);
if (target$) {
var lines$_1 = [];
if (target$.classList.contains('has-selection'))
target$.querySelectorAll('div').forEach((function (line$) {
if (line$.classList.contains('selected'))
lines$_1.push(line$);
}));
else
target$.querySelectorAll('div').forEach(function (line$) { return lines$_1.push(line$); });
clipboard_1.copyToClipboard(lines$_1.map(function (line$) { return line$.getAttribute('data-content'); }).join('\n'), function () { return copy_confirm_1.copyConfirm.apply(void 0, lines$_1); });
}
}
exports.smartCopy = smartCopy;
function initSmartCopy() {
window.smartCopy = smartCopy;
}
exports.initSmartCopy = initSmartCopy;
exports.smartCopy$ = transport_1.funcTransport(initSmartCopy);
//# sourceMappingURL=smart-copy.js.map