/*! * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ * * Version: 5.7.0 (2021-02-10) * */ !function(t){var r={};function o(n){if(r[n])return r[n].exports;var e=r[n]={i:n,l:!1,exports:{}};return t[n].call(e.exports,e,e.exports,o),e.l=!0,e.exports}o.m=t,o.c=r,o.d=function(n,e,t){o.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:t})},o.r=function(n){Object.defineProperty(n,"__esModule",{value:!0})},o.n=function(n){var e=n&&n.__esModule?function(){return n["default"]}:function(){return n};return o.d(e,"a",e),e},o.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},o.p="",o(o.s="./src/js/plugins/anchor/plugin.js")}({"./src/js/plugins/anchor/plugin.js":function(module,exports){eval("/**\n * Copyright (c) Tiny Technologies, Inc. All rights reserved.\n * Licensed under the LGPL or a commercial license.\n * For LGPL see License.txt in the project root for license information.\n * For commercial licenses see https://www.tiny.cloud/\n *\n * Version: 5.7.0 (2021-02-10)\n */\n (function () {\n 'use strict';\n\n var global = tinymce.util.Tools.resolve('tinymce.PluginManager');\n\n var global$1 = tinymce.util.Tools.resolve('tinymce.dom.RangeUtils');\n\n var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools');\n\n var allowHtmlInNamedAnchor = function (editor) {\n return editor.getParam('allow_html_in_named_anchor', false, 'boolean');\n };\n\n var namedAnchorSelector = 'a:not([href])';\n var isEmptyString = function (str) {\n return !str;\n };\n var getIdFromAnchor = function (elm) {\n var id = elm.getAttribute('id') || elm.getAttribute('name');\n return id || '';\n };\n var isAnchor = function (elm) {\n return elm && elm.nodeName.toLowerCase() === 'a';\n };\n var isNamedAnchor = function (elm) {\n return isAnchor(elm) && !elm.getAttribute('href') && getIdFromAnchor(elm) !== '';\n };\n var isEmptyNamedAnchor = function (elm) {\n return isNamedAnchor(elm) && !elm.firstChild;\n };\n\n var removeEmptyNamedAnchorsInSelection = function (editor) {\n var dom = editor.dom;\n global$1(dom).walk(editor.selection.getRng(), function (nodes) {\n global$2.each(nodes, function (node) {\n if (isEmptyNamedAnchor(node)) {\n dom.remove(node, false);\n }\n });\n });\n };\n var isValidId = function (id) {\n return /^[A-Za-z][A-Za-z0-9\\-:._]*$/.test(id);\n };\n var getNamedAnchor = function (editor) {\n return editor.dom.getParent(editor.selection.getStart(), namedAnchorSelector);\n };\n var getId = function (editor) {\n var anchor = getNamedAnchor(editor);\n if (anchor) {\n return getIdFromAnchor(anchor);\n } else {\n return '';\n }\n };\n var createAnchor = function (editor, id) {\n editor.undoManager.transact(function () {\n if (!allowHtmlInNamedAnchor(editor)) {\n editor.selection.collapse(true);\n }\n if (editor.selection.isCollapsed()) {\n editor.insertContent(editor.dom.createHTML('a', { id: id }));\n } else {\n removeEmptyNamedAnchorsInSelection(editor);\n editor.formatter.remove('namedAnchor', null, null, true);\n editor.formatter.apply('namedAnchor', { value: id });\n editor.addVisual();\n }\n });\n };\n var updateAnchor = function (editor, id, anchorElement) {\n anchorElement.removeAttribute('name');\n anchorElement.id = id;\n editor.addVisual();\n editor.undoManager.add();\n };\n var insert = function (editor, id) {\n var anchor = getNamedAnchor(editor);\n if (anchor) {\n updateAnchor(editor, id, anchor);\n } else {\n createAnchor(editor, id);\n }\n editor.focus();\n };\n\n var insertAnchor = function (editor, newId) {\n if (!isValidId(newId)) {\n editor.windowManager.alert('Id should start with a letter, followed only by letters, numbers, dashes, dots, colons or underscores.');\n return false;\n } else {\n insert(editor, newId);\n return true;\n }\n };\n var open = function (editor) {\n var currentId = getId(editor);\n editor.windowManager.open({\n title: 'Anchor',\n size: 'normal',\n body: {\n type: 'panel',\n items: [{\n name: 'id',\n type: 'input',\n label: 'ID',\n placeholder: 'example'\n }]\n },\n buttons: [\n {\n type: 'cancel',\n name: 'cancel',\n text: 'Cancel'\n },\n {\n type: 'submit',\n name: 'save',\n text: 'Save',\n primary: true\n }\n ],\n initialData: { id: currentId },\n onSubmit: function (api) {\n if (insertAnchor(editor, api.getData().id)) {\n api.close();\n }\n }\n });\n };\n\n var register = function (editor) {\n editor.addCommand('mceAnchor', function () {\n open(editor);\n });\n };\n\n var isNamedAnchorNode = function (node) {\n return node && isEmptyString(node.attr('href')) && !isEmptyString(node.attr('id') || node.attr('name'));\n };\n var isEmptyNamedAnchorNode = function (node) {\n return isNamedAnchorNode(node) && !node.firstChild;\n };\n var setContentEditable = function (state) {\n return function (nodes) {\n for (var i = 0; i < nodes.length; i++) {\n var node = nodes[i];\n if (isEmptyNamedAnchorNode(node)) {\n node.attr('contenteditable', state);\n }\n }\n };\n };\n var setup = function (editor) {\n editor.on('PreInit', function () {\n editor.parser.addNodeFilter('a', setContentEditable('false'));\n editor.serializer.addNodeFilter('a', setContentEditable(null));\n });\n };\n\n var registerFormats = function (editor) {\n editor.formatter.register('namedAnchor', {\n inline: 'a',\n selector: namedAnchorSelector,\n remove: 'all',\n split: true,\n deep: true,\n attributes: { id: '%value' },\n onmatch: function (node, _fmt, _itemName) {\n return isNamedAnchor(node);\n }\n });\n };\n\n var register$1 = function (editor) {\n editor.ui.registry.addToggleButton('anchor', {\n icon: 'bookmark',\n tooltip: 'Anchor',\n onAction: function () {\n return editor.execCommand('mceAnchor');\n },\n onSetup: function (buttonApi) {\n return editor.selection.selectorChangedWithUnbind('a:not([href])', buttonApi.setActive).unbind;\n }\n });\n editor.ui.registry.addMenuItem('anchor', {\n icon: 'bookmark',\n text: 'Anchor...',\n onAction: function () {\n return editor.execCommand('mceAnchor');\n }\n });\n };\n\n function Plugin () {\n global.add('anchor', function (editor) {\n setup(editor);\n register(editor);\n register$1(editor);\n editor.on('PreInit', function () {\n registerFormats(editor);\n });\n });\n }\n\n Plugin();\n\n}());\n\n\n//# sourceURL=webpack:///./src/js/plugins/anchor/plugin.js?")}});