/*! * 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 i(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,i),e.l=!0,e.exports}i.m=t,i.c=r,i.d=function(n,e,t){i.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:t})},i.r=function(n){Object.defineProperty(n,"__esModule",{value:!0})},i.n=function(n){var e=n&&n.__esModule?function(){return n["default"]}:function(){return n};return i.d(e,"a",e),e},i.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},i.p="",i(i.s="./src/js/plugins/autolink/plugin.js")}({"./src/js/plugins/autolink/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.Env');\n\n var getAutoLinkPattern = function (editor) {\n return editor.getParam('autolink_pattern', /^(https?:\\/\\/|ssh:\\/\\/|ftp:\\/\\/|file:\\/|www\\.|(?:mailto:)?[A-Z0-9._%+\\-]+@(?!.*@))(.+)$/i);\n };\n var getDefaultLinkTarget = function (editor) {\n return editor.getParam('default_link_target', false);\n };\n var getDefaultLinkProtocol = function (editor) {\n return editor.getParam('link_default_protocol', 'http', 'string');\n };\n\n var rangeEqualsDelimiterOrSpace = function (rangeString, delimiter) {\n return rangeString === delimiter || rangeString === ' ' || rangeString.charCodeAt(0) === 160;\n };\n var handleEclipse = function (editor) {\n parseCurrentLine(editor, -1, '(');\n };\n var handleSpacebar = function (editor) {\n parseCurrentLine(editor, 0, '');\n };\n var handleEnter = function (editor) {\n parseCurrentLine(editor, -1, '');\n };\n var scopeIndex = function (container, index) {\n if (index < 0) {\n index = 0;\n }\n if (container.nodeType === 3) {\n var len = container.data.length;\n if (index > len) {\n index = len;\n }\n }\n return index;\n };\n var setStart = function (rng, container, offset) {\n if (container.nodeType !== 1 || container.hasChildNodes()) {\n rng.setStart(container, scopeIndex(container, offset));\n } else {\n rng.setStartBefore(container);\n }\n };\n var setEnd = function (rng, container, offset) {\n if (container.nodeType !== 1 || container.hasChildNodes()) {\n rng.setEnd(container, scopeIndex(container, offset));\n } else {\n rng.setEndAfter(container);\n }\n };\n var parseCurrentLine = function (editor, endOffset, delimiter) {\n var end, endContainer, bookmark, text, prev, len, rngText;\n var autoLinkPattern = getAutoLinkPattern(editor);\n var defaultLinkTarget = getDefaultLinkTarget(editor);\n if (editor.selection.getNode().tagName === 'A') {\n return;\n }\n var rng = editor.selection.getRng().cloneRange();\n if (rng.startOffset < 5) {\n prev = rng.endContainer.previousSibling;\n if (!prev) {\n if (!rng.endContainer.firstChild || !rng.endContainer.firstChild.nextSibling) {\n return;\n }\n prev = rng.endContainer.firstChild.nextSibling;\n }\n len = prev.length;\n setStart(rng, prev, len);\n setEnd(rng, prev, len);\n if (rng.endOffset < 5) {\n return;\n }\n end = rng.endOffset;\n endContainer = prev;\n } else {\n endContainer = rng.endContainer;\n if (endContainer.nodeType !== 3 && endContainer.firstChild) {\n while (endContainer.nodeType !== 3 && endContainer.firstChild) {\n endContainer = endContainer.firstChild;\n }\n if (endContainer.nodeType === 3) {\n setStart(rng, endContainer, 0);\n setEnd(rng, endContainer, endContainer.nodeValue.length);\n }\n }\n if (rng.endOffset === 1) {\n end = 2;\n } else {\n end = rng.endOffset - 1 - endOffset;\n }\n }\n var start = end;\n do {\n setStart(rng, endContainer, end >= 2 ? end - 2 : 0);\n setEnd(rng, endContainer, end >= 1 ? end - 1 : 0);\n end -= 1;\n rngText = rng.toString();\n } while (rngText !== ' ' && rngText !== '' && rngText.charCodeAt(0) !== 160 && end - 2 >= 0 && rngText !== delimiter);\n if (rangeEqualsDelimiterOrSpace(rng.toString(), delimiter)) {\n setStart(rng, endContainer, end);\n setEnd(rng, endContainer, start);\n end += 1;\n } else if (rng.startOffset === 0) {\n setStart(rng, endContainer, 0);\n setEnd(rng, endContainer, start);\n } else {\n setStart(rng, endContainer, end);\n setEnd(rng, endContainer, start);\n }\n text = rng.toString();\n if (text.charAt(text.length - 1) === '.') {\n setEnd(rng, endContainer, start - 1);\n }\n text = rng.toString().trim();\n var matches = text.match(autoLinkPattern);\n var protocol = getDefaultLinkProtocol(editor);\n if (matches) {\n if (matches[1] === 'www.') {\n matches[1] = protocol + '://www.';\n } else if (/@$/.test(matches[1]) && !/^mailto:/.test(matches[1])) {\n matches[1] = 'mailto:' + matches[1];\n }\n bookmark = editor.selection.getBookmark();\n editor.selection.setRng(rng);\n editor.execCommand('createlink', false, matches[1] + matches[2]);\n if (defaultLinkTarget !== false) {\n editor.dom.setAttrib(editor.selection.getNode(), 'target', defaultLinkTarget);\n }\n editor.selection.moveToBookmark(bookmark);\n editor.nodeChanged();\n }\n };\n var setup = function (editor) {\n var autoUrlDetectState;\n editor.on('keydown', function (e) {\n if (e.keyCode === 13) {\n return handleEnter(editor);\n }\n });\n if (global$1.browser.isIE()) {\n editor.on('focus', function () {\n if (!autoUrlDetectState) {\n autoUrlDetectState = true;\n try {\n editor.execCommand('AutoUrlDetect', false, true);\n } catch (ex) {\n }\n }\n });\n return;\n }\n editor.on('keypress', function (e) {\n if (e.keyCode === 41) {\n return handleEclipse(editor);\n }\n });\n editor.on('keyup', function (e) {\n if (e.keyCode === 32) {\n return handleSpacebar(editor);\n }\n });\n };\n\n function Plugin () {\n global.add('autolink', function (editor) {\n setup(editor);\n });\n }\n\n Plugin();\n\n}());\n\n\n//# sourceURL=webpack:///./src/js/plugins/autolink/plugin.js?")}});