UNPKG

@codedoc/core

Version:

Create beautiful modern documentation websites.

49 lines 2.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.copyLineLiks$ = exports.copyLineLinks = void 0; var transport_1 = require("@connectv/sdh/transport"); var renderer_1 = require("../../../transport/renderer"); var clipboard_1 = require("../../../transport/clipboard"); var toast_1 = require("../../util/toast"); var line_link_1 = require("./line-link"); function copyLineLinks() { var renderer = renderer_1.getRenderer(); transport_1.onReady(function () { var _exec = function () { document.querySelectorAll('pre>code>.-codedoc-code-line').forEach(function (line$) { var counter$ = line$.querySelector('.-codedoc-line-counter'); counter$ === null || counter$ === void 0 ? void 0 : counter$.addEventListener('click', function (event) { event.stopPropagation(); var link = line_link_1.lineLink(line$); clipboard_1.copyToClipboard(link, function () { return renderer.render(renderer.create(toast_1.Toast, null, "Link Copied to Clipboard!", renderer.create("br", null), renderer.create("a", { href: link, style: "font-size: 12px; color: white" }, link))).on(document.body); }); }); counter$ === null || counter$ === void 0 ? void 0 : counter$.addEventListener('mousedown', function (event) { return event.stopPropagation(); }); counter$ === null || counter$ === void 0 ? void 0 : counter$.addEventListener('mouseup', function (event) { return event.stopPropagation(); }); }); }; var _detect = function () { var _a; var linked = line_link_1.linkedLines(); if (linked.length > 0) { (_a = linked[0].parentElement) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.selected').forEach(function (el) { return el.classList.remove('selected'); }); } linked.forEach(function (line$) { var _a; line$ === null || line$ === void 0 ? void 0 : line$.classList.add('selected'); (_a = line$ === null || line$ === void 0 ? void 0 : line$.parentElement) === null || _a === void 0 ? void 0 : _a.classList.add('has-selection'); }); if (linked.length > 0) setTimeout(function () { var _a; return (_a = linked[0]) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'center' }); }, 300); }; _exec(); _detect(); window.addEventListener('navigation', function () { _exec(); _detect(); }); window.addEventListener('hashchange', _detect); }); } exports.copyLineLinks = copyLineLinks; exports.copyLineLiks$ = transport_1.funcTransport(copyLineLinks); //# sourceMappingURL=copy-line-link.js.map