123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842 |
- /**
- * 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.2.0 (2020-02-13)
- */
- (function (domGlobals) {
- 'use strict';
- var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
- var global$2 = tinymce.util.Tools.resolve('tinymce.util.VK');
- var typeOf = function (x) {
- if (x === null) {
- return 'null';
- }
- var t = typeof x;
- if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
- return 'array';
- }
- if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
- return 'string';
- }
- return t;
- };
- var isType = function (type) {
- return function (value) {
- return typeOf(value) === type;
- };
- };
- var isString = isType('string');
- var isArray = isType('array');
- var isBoolean = isType('boolean');
- var isFunction = isType('function');
- var assumeExternalTargets = function (editor) {
- var externalTargets = editor.getParam('link_assume_external_targets', false);
- if (isBoolean(externalTargets) && externalTargets) {
- return 1;
- } else if (isString(externalTargets) && (externalTargets === 'http' || externalTargets === 'https')) {
- return externalTargets;
- }
- return 0;
- };
- var hasContextToolbar = function (editor) {
- return editor.getParam('link_context_toolbar', false, 'boolean');
- };
- var getLinkList = function (editor) {
- return editor.getParam('link_list');
- };
- var getDefaultLinkTarget = function (editor) {
- return editor.getParam('default_link_target');
- };
- var getTargetList = function (editor) {
- return editor.getParam('target_list', true);
- };
- var getRelList = function (editor) {
- return editor.getParam('rel_list', [], 'array');
- };
- var getLinkClassList = function (editor) {
- return editor.getParam('link_class_list', [], 'array');
- };
- var shouldShowLinkTitle = function (editor) {
- return editor.getParam('link_title', true, 'boolean');
- };
- var allowUnsafeLinkTarget = function (editor) {
- return editor.getParam('allow_unsafe_link_target', false, 'boolean');
- };
- var useQuickLink = function (editor) {
- return editor.getParam('link_quicklink', false, 'boolean');
- };
- var getDefaultLinkProtocol = function (editor) {
- return editor.getParam('link_default_protocol', 'http', 'string');
- };
- var Settings = {
- assumeExternalTargets: assumeExternalTargets,
- hasContextToolbar: hasContextToolbar,
- getLinkList: getLinkList,
- getDefaultLinkTarget: getDefaultLinkTarget,
- getTargetList: getTargetList,
- getRelList: getRelList,
- getLinkClassList: getLinkClassList,
- shouldShowLinkTitle: shouldShowLinkTitle,
- allowUnsafeLinkTarget: allowUnsafeLinkTarget,
- useQuickLink: useQuickLink,
- getDefaultLinkProtocol: getDefaultLinkProtocol
- };
- var appendClickRemove = function (link, evt) {
- domGlobals.document.body.appendChild(link);
- link.dispatchEvent(evt);
- domGlobals.document.body.removeChild(link);
- };
- var open = function (url) {
- var link = domGlobals.document.createElement('a');
- link.target = '_blank';
- link.href = url;
- link.rel = 'noreferrer noopener';
- var evt = domGlobals.document.createEvent('MouseEvents');
- evt.initMouseEvent('click', true, true, domGlobals.window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
- appendClickRemove(link, evt);
- };
- var OpenUrl = { open: open };
- var __assign = function () {
- __assign = Object.assign || function __assign(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s)
- if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- var noop = function () {
- };
- var constant = function (value) {
- return function () {
- return value;
- };
- };
- var never = constant(false);
- var always = constant(true);
- var none = function () {
- return NONE;
- };
- var NONE = function () {
- var eq = function (o) {
- return o.isNone();
- };
- var call = function (thunk) {
- return thunk();
- };
- var id = function (n) {
- return n;
- };
- var me = {
- fold: function (n, s) {
- return n();
- },
- is: never,
- isSome: never,
- isNone: always,
- getOr: id,
- getOrThunk: call,
- getOrDie: function (msg) {
- throw new Error(msg || 'error: getOrDie called on none.');
- },
- getOrNull: constant(null),
- getOrUndefined: constant(undefined),
- or: id,
- orThunk: call,
- map: none,
- each: noop,
- bind: none,
- exists: never,
- forall: always,
- filter: none,
- equals: eq,
- equals_: eq,
- toArray: function () {
- return [];
- },
- toString: constant('none()')
- };
- if (Object.freeze) {
- Object.freeze(me);
- }
- return me;
- }();
- var some = function (a) {
- var constant_a = constant(a);
- var self = function () {
- return me;
- };
- var bind = function (f) {
- return f(a);
- };
- var me = {
- fold: function (n, s) {
- return s(a);
- },
- is: function (v) {
- return a === v;
- },
- isSome: always,
- isNone: never,
- getOr: constant_a,
- getOrThunk: constant_a,
- getOrDie: constant_a,
- getOrNull: constant_a,
- getOrUndefined: constant_a,
- or: self,
- orThunk: self,
- map: function (f) {
- return some(f(a));
- },
- each: function (f) {
- f(a);
- },
- bind: bind,
- exists: bind,
- forall: bind,
- filter: function (f) {
- return f(a) ? me : NONE;
- },
- toArray: function () {
- return [a];
- },
- toString: function () {
- return 'some(' + a + ')';
- },
- equals: function (o) {
- return o.is(a);
- },
- equals_: function (o, elementEq) {
- return o.fold(never, function (b) {
- return elementEq(a, b);
- });
- }
- };
- return me;
- };
- var from = function (value) {
- return value === null || value === undefined ? NONE : some(value);
- };
- var Option = {
- some: some,
- none: none,
- from: from
- };
- var nativeSlice = Array.prototype.slice;
- var nativeIndexOf = Array.prototype.indexOf;
- var nativePush = Array.prototype.push;
- var rawIndexOf = function (ts, t) {
- return nativeIndexOf.call(ts, t);
- };
- var contains = function (xs, x) {
- return rawIndexOf(xs, x) > -1;
- };
- var map = function (xs, f) {
- var len = xs.length;
- var r = new Array(len);
- for (var i = 0; i < len; i++) {
- var x = xs[i];
- r[i] = f(x, i);
- }
- return r;
- };
- var each = function (xs, f) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- f(x, i);
- }
- };
- var foldl = function (xs, f, acc) {
- each(xs, function (x) {
- acc = f(acc, x);
- });
- return acc;
- };
- var flatten = function (xs) {
- var r = [];
- for (var i = 0, len = xs.length; i < len; ++i) {
- if (!isArray(xs[i])) {
- throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
- }
- nativePush.apply(r, xs[i]);
- }
- return r;
- };
- var bind = function (xs, f) {
- return flatten(map(xs, f));
- };
- var from$1 = isFunction(Array.from) ? Array.from : function (x) {
- return nativeSlice.call(x);
- };
- var findMap = function (arr, f) {
- for (var i = 0; i < arr.length; i++) {
- var r = f(arr[i], i);
- if (r.isSome()) {
- return r;
- }
- }
- return Option.none();
- };
- var global$3 = tinymce.util.Tools.resolve('tinymce.util.Tools');
- var hasProtocol = function (url) {
- return /^\w+:/i.test(url);
- };
- var getHref = function (elm) {
- var href = elm.getAttribute('data-mce-href');
- return href ? href : elm.getAttribute('href');
- };
- var applyRelTargetRules = function (rel, isUnsafe) {
- var rules = ['noopener'];
- var rels = rel ? rel.split(/\s+/) : [];
- var toString = function (rels) {
- return global$3.trim(rels.sort().join(' '));
- };
- var addTargetRules = function (rels) {
- rels = removeTargetRules(rels);
- return rels.length > 0 ? rels.concat(rules) : rules;
- };
- var removeTargetRules = function (rels) {
- return rels.filter(function (val) {
- return global$3.inArray(rules, val) === -1;
- });
- };
- var newRels = isUnsafe ? addTargetRules(rels) : removeTargetRules(rels);
- return newRels.length > 0 ? toString(newRels) : '';
- };
- var trimCaretContainers = function (text) {
- return text.replace(/\uFEFF/g, '');
- };
- var getAnchorElement = function (editor, selectedElm) {
- selectedElm = selectedElm || editor.selection.getNode();
- if (isImageFigure(selectedElm)) {
- return editor.dom.select('a[href]', selectedElm)[0];
- } else {
- return editor.dom.getParent(selectedElm, 'a[href]');
- }
- };
- var getAnchorText = function (selection, anchorElm) {
- var text = anchorElm ? anchorElm.innerText || anchorElm.textContent : selection.getContent({ format: 'text' });
- return trimCaretContainers(text);
- };
- var isLink = function (elm) {
- return elm && elm.nodeName === 'A' && !!elm.href;
- };
- var hasLinks = function (elements) {
- return global$3.grep(elements, isLink).length > 0;
- };
- var isOnlyTextSelected = function (html) {
- if (/</.test(html) && (!/^<a [^>]+>[^<]+<\/a>$/.test(html) || html.indexOf('href=') === -1)) {
- return false;
- }
- return true;
- };
- var isImageFigure = function (elm) {
- return elm && elm.nodeName === 'FIGURE' && /\bimage\b/i.test(elm.className);
- };
- var getLinkAttrs = function (data) {
- return foldl([
- 'title',
- 'rel',
- 'class',
- 'target'
- ], function (acc, key) {
- data[key].each(function (value) {
- acc[key] = value.length > 0 ? value : null;
- });
- return acc;
- }, { href: data.href });
- };
- var handleExternalTargets = function (href, assumeExternalTargets) {
- if ((assumeExternalTargets === 'http' || assumeExternalTargets === 'https') && !hasProtocol(href)) {
- return assumeExternalTargets + '://' + href;
- }
- return href;
- };
- var applyLinkOverrides = function (editor, linkAttrs) {
- var newLinkAttrs = __assign({}, linkAttrs);
- if (!(Settings.getRelList(editor).length > 0) && Settings.allowUnsafeLinkTarget(editor) === false) {
- var newRel = applyRelTargetRules(newLinkAttrs.rel, newLinkAttrs.target === '_blank');
- newLinkAttrs.rel = newRel ? newRel : null;
- }
- if (Option.from(newLinkAttrs.target).isNone() && Settings.getTargetList(editor) === false) {
- newLinkAttrs.target = Settings.getDefaultLinkTarget(editor);
- }
- newLinkAttrs.href = handleExternalTargets(newLinkAttrs.href, Settings.assumeExternalTargets(editor));
- return newLinkAttrs;
- };
- var updateLink = function (editor, anchorElm, text, linkAttrs) {
- text.each(function (text) {
- if (anchorElm.hasOwnProperty('innerText')) {
- anchorElm.innerText = text;
- } else {
- anchorElm.textContent = text;
- }
- });
- editor.dom.setAttribs(anchorElm, linkAttrs);
- editor.selection.select(anchorElm);
- };
- var createLink = function (editor, selectedElm, text, linkAttrs) {
- if (isImageFigure(selectedElm)) {
- linkImageFigure(editor, selectedElm, linkAttrs);
- } else {
- text.fold(function () {
- editor.execCommand('mceInsertLink', false, linkAttrs);
- }, function (text) {
- editor.insertContent(editor.dom.createHTML('a', linkAttrs, editor.dom.encode(text)));
- });
- }
- };
- var link = function (editor, attachState, data) {
- var selectedElm = editor.selection.getNode();
- var anchorElm = getAnchorElement(editor, selectedElm);
- var linkAttrs = applyLinkOverrides(editor, getLinkAttrs(data));
- editor.undoManager.transact(function () {
- if (data.href === attachState.href) {
- attachState.attach();
- }
- if (anchorElm) {
- editor.focus();
- updateLink(editor, anchorElm, data.text, linkAttrs);
- } else {
- createLink(editor, selectedElm, data.text, linkAttrs);
- }
- });
- };
- var unlink = function (editor) {
- editor.undoManager.transact(function () {
- var node = editor.selection.getNode();
- if (isImageFigure(node)) {
- unlinkImageFigure(editor, node);
- } else {
- var anchorElm = editor.dom.getParent(node, 'a[href]', editor.getBody());
- if (anchorElm) {
- editor.dom.remove(anchorElm, true);
- }
- }
- editor.focus();
- });
- };
- var unlinkImageFigure = function (editor, fig) {
- var img = editor.dom.select('img', fig)[0];
- if (img) {
- var a = editor.dom.getParents(img, 'a[href]', fig)[0];
- if (a) {
- a.parentNode.insertBefore(img, a);
- editor.dom.remove(a);
- }
- }
- };
- var linkImageFigure = function (editor, fig, attrs) {
- var img = editor.dom.select('img', fig)[0];
- if (img) {
- var a = editor.dom.create('a', attrs);
- img.parentNode.insertBefore(a, img);
- a.appendChild(img);
- }
- };
- var Utils = {
- link: link,
- unlink: unlink,
- isLink: isLink,
- hasLinks: hasLinks,
- getHref: getHref,
- isOnlyTextSelected: isOnlyTextSelected,
- getAnchorElement: getAnchorElement,
- getAnchorText: getAnchorText,
- applyRelTargetRules: applyRelTargetRules,
- hasProtocol: hasProtocol
- };
- var cat = function (arr) {
- var r = [];
- var push = function (x) {
- r.push(x);
- };
- for (var i = 0; i < arr.length; i++) {
- arr[i].each(push);
- }
- return r;
- };
- var getValue = function (item) {
- return isString(item.value) ? item.value : '';
- };
- var sanitizeList = function (list, extractValue) {
- var out = [];
- global$3.each(list, function (item) {
- var text = isString(item.text) ? item.text : isString(item.title) ? item.title : '';
- if (item.menu !== undefined) ; else {
- var value = extractValue(item);
- out.push({
- text: text,
- value: value
- });
- }
- });
- return out;
- };
- var sanitizeWith = function (extracter) {
- if (extracter === void 0) {
- extracter = getValue;
- }
- return function (list) {
- return Option.from(list).map(function (list) {
- return sanitizeList(list, extracter);
- });
- };
- };
- var sanitize = function (list) {
- return sanitizeWith(getValue)(list);
- };
- var createUi = function (name, label) {
- return function (items) {
- return {
- name: name,
- type: 'selectbox',
- label: label,
- items: items
- };
- };
- };
- var ListOptions = {
- sanitize: sanitize,
- sanitizeWith: sanitizeWith,
- createUi: createUi,
- getValue: getValue
- };
- var Cell = function (initial) {
- var value = initial;
- var get = function () {
- return value;
- };
- var set = function (v) {
- value = v;
- };
- var clone = function () {
- return Cell(get());
- };
- return {
- get: get,
- set: set,
- clone: clone
- };
- };
- var findTextByValue = function (value, catalog) {
- return findMap(catalog, function (item) {
- return Option.some(item).filter(function (i) {
- return i.value === value;
- });
- });
- };
- var getDelta = function (persistentText, fieldName, catalog, data) {
- var value = data[fieldName];
- var hasPersistentText = persistentText.length > 0;
- return value !== undefined ? findTextByValue(value, catalog).map(function (i) {
- return {
- url: {
- value: i.value,
- meta: {
- text: hasPersistentText ? persistentText : i.text,
- attach: noop
- }
- },
- text: hasPersistentText ? persistentText : i.text
- };
- }) : Option.none();
- };
- var findCatalog = function (settings, fieldName) {
- if (fieldName === 'link') {
- return settings.catalogs.link;
- } else if (fieldName === 'anchor') {
- return settings.catalogs.anchor;
- } else {
- return Option.none();
- }
- };
- var init = function (initialData, linkSettings) {
- var persistentText = Cell(initialData.text);
- var onUrlChange = function (data) {
- if (persistentText.get().length <= 0) {
- var urlText = data.url.meta.text !== undefined ? data.url.meta.text : data.url.value;
- var urlTitle = data.url.meta.title !== undefined ? data.url.meta.title : '';
- return Option.some({
- text: urlText,
- title: urlTitle
- });
- } else {
- return Option.none();
- }
- };
- var onCatalogChange = function (data, change) {
- var catalog = findCatalog(linkSettings, change.name).getOr([]);
- return getDelta(persistentText.get(), change.name, catalog, data);
- };
- var onChange = function (getData, change) {
- if (change.name === 'url') {
- return onUrlChange(getData());
- } else if (contains([
- 'anchor',
- 'link'
- ], change.name)) {
- return onCatalogChange(getData(), change);
- } else if (change.name === 'text') {
- persistentText.set(getData().text);
- return Option.none();
- } else {
- return Option.none();
- }
- };
- return { onChange: onChange };
- };
- var DialogChanges = {
- init: init,
- getDelta: getDelta
- };
- var exports$1 = {}, module = { exports: exports$1 };
- (function (define, exports, module, require) {
- (function (f) {
- if (typeof exports === 'object' && typeof module !== 'undefined') {
- module.exports = f();
- } else if (typeof define === 'function' && define.amd) {
- define([], f);
- } else {
- var g;
- if (typeof window !== 'undefined') {
- g = window;
- } else if (typeof global !== 'undefined') {
- g = global;
- } else if (typeof self !== 'undefined') {
- g = self;
- } else {
- g = this;
- }
- g.EphoxContactWrapper = f();
- }
- }(function () {
- return function () {
- function r(e, n, t) {
- function o(i, f) {
- if (!n[i]) {
- if (!e[i]) {
- var c = 'function' == typeof require && require;
- if (!f && c)
- return c(i, !0);
- if (u)
- return u(i, !0);
- var a = new Error('Cannot find module \'' + i + '\'');
- throw a.code = 'MODULE_NOT_FOUND', a;
- }
- var p = n[i] = { exports: {} };
- e[i][0].call(p.exports, function (r) {
- var n = e[i][1][r];
- return o(n || r);
- }, p, p.exports, r, e, n, t);
- }
- return n[i].exports;
- }
- for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
- o(t[i]);
- return o;
- }
- return r;
- }()({
- 1: [
- function (require, module, exports) {
- var process = module.exports = {};
- var cachedSetTimeout;
- var cachedClearTimeout;
- function defaultSetTimout() {
- throw new Error('setTimeout has not been defined');
- }
- function defaultClearTimeout() {
- throw new Error('clearTimeout has not been defined');
- }
- (function () {
- try {
- if (typeof setTimeout === 'function') {
- cachedSetTimeout = setTimeout;
- } else {
- cachedSetTimeout = defaultSetTimout;
- }
- } catch (e) {
- cachedSetTimeout = defaultSetTimout;
- }
- try {
- if (typeof clearTimeout === 'function') {
- cachedClearTimeout = clearTimeout;
- } else {
- cachedClearTimeout = defaultClearTimeout;
- }
- } catch (e) {
- cachedClearTimeout = defaultClearTimeout;
- }
- }());
- function runTimeout(fun) {
- if (cachedSetTimeout === setTimeout) {
- return setTimeout(fun, 0);
- }
- if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
- cachedSetTimeout = setTimeout;
- return setTimeout(fun, 0);
- }
- try {
- return cachedSetTimeout(fun, 0);
- } catch (e) {
- try {
- return cachedSetTimeout.call(null, fun, 0);
- } catch (e) {
- return cachedSetTimeout.call(this, fun, 0);
- }
- }
- }
- function runClearTimeout(marker) {
- if (cachedClearTimeout === clearTimeout) {
- return clearTimeout(marker);
- }
- if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
- cachedClearTimeout = clearTimeout;
- return clearTimeout(marker);
- }
- try {
- return cachedClearTimeout(marker);
- } catch (e) {
- try {
- return cachedClearTimeout.call(null, marker);
- } catch (e) {
- return cachedClearTimeout.call(this, marker);
- }
- }
- }
- var queue = [];
- var draining = false;
- var currentQueue;
- var queueIndex = -1;
- function cleanUpNextTick() {
- if (!draining || !currentQueue) {
- return;
- }
- draining = false;
- if (currentQueue.length) {
- queue = currentQueue.concat(queue);
- } else {
- queueIndex = -1;
- }
- if (queue.length) {
- drainQueue();
- }
- }
- function drainQueue() {
- if (draining) {
- return;
- }
- var timeout = runTimeout(cleanUpNextTick);
- draining = true;
- var len = queue.length;
- while (len) {
- currentQueue = queue;
- queue = [];
- while (++queueIndex < len) {
- if (currentQueue) {
- currentQueue[queueIndex].run();
- }
- }
- queueIndex = -1;
- len = queue.length;
- }
- currentQueue = null;
- draining = false;
- runClearTimeout(timeout);
- }
- process.nextTick = function (fun) {
- var args = new Array(arguments.length - 1);
- if (arguments.length > 1) {
- for (var i = 1; i < arguments.length; i++) {
- args[i - 1] = arguments[i];
- }
- }
- queue.push(new Item(fun, args));
- if (queue.length === 1 && !draining) {
- runTimeout(drainQueue);
- }
- };
- function Item(fun, array) {
- this.fun = fun;
- this.array = array;
- }
- Item.prototype.run = function () {
- this.fun.apply(null, this.array);
- };
- process.title = 'browser';
- process.browser = true;
- process.env = {};
- process.argv = [];
- process.version = '';
- process.versions = {};
- function noop() {
- }
- process.on = noop;
- process.addListener = noop;
- process.once = noop;
- process.off = noop;
- process.removeListener = noop;
- process.removeAllListeners = noop;
- process.emit = noop;
- process.prependListener = noop;
- process.prependOnceListener = noop;
- process.listeners = function (name) {
- return [];
- };
- process.binding = function (name) {
- throw new Error('process.binding is not supported');
- };
- process.cwd = function () {
- return '/';
- };
- process.chdir = function (dir) {
- throw new Error('process.chdir is not supported');
- };
- process.umask = function () {
- return 0;
- };
- },
- {}
- ],
- 2: [
- function (require, module, exports) {
- (function (setImmediate) {
- (function (root) {
- var setTimeoutFunc = setTimeout;
- function noop() {
- }
- function bind(fn, thisArg) {
- return function () {
- fn.apply(thisArg, arguments);
- };
- }
- function Promise(fn) {
- if (typeof this !== 'object')
- throw new TypeError('Promises must be constructed via new');
- if (typeof fn !== 'function')
- throw new TypeError('not a function');
- this._state = 0;
- this._handled = false;
- this._value = undefined;
- this._deferreds = [];
- doResolve(fn, this);
- }
- function handle(self, deferred) {
- while (self._state === 3) {
- self = self._value;
- }
- if (self._state === 0) {
- self._deferreds.push(deferred);
- return;
- }
- self._handled = true;
- Promise._immediateFn(function () {
- var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
- if (cb === null) {
- (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
- return;
- }
- var ret;
- try {
- ret = cb(self._value);
- } catch (e) {
- reject(deferred.promise, e);
- return;
- }
- resolve(deferred.promise, ret);
- });
- }
- function resolve(self, newValue) {
- try {
- if (newValue === self)
- throw new TypeError('A promise cannot be resolved with itself.');
- if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
- var then = newValue.then;
- if (newValue instanceof Promise) {
- self._state = 3;
- self._value = newValue;
- finale(self);
- return;
- } else if (typeof then === 'function') {
- doResolve(bind(then, newValue), self);
- return;
- }
- }
- self._state = 1;
- self._value = newValue;
- finale(self);
- } catch (e) {
- reject(self, e);
- }
- }
- function reject(self, newValue) {
- self._state = 2;
- self._value = newValue;
- finale(self);
- }
- function finale(self) {
- if (self._state === 2 && self._deferreds.length === 0) {
- Promise._immediateFn(function () {
- if (!self._handled) {
- Promise._unhandledRejectionFn(self._value);
- }
- });
- }
- for (var i = 0, len = self._deferreds.length; i < len; i++) {
- handle(self, self._deferreds[i]);
- }
- self._deferreds = null;
- }
- function Handler(onFulfilled, onRejected, promise) {
- this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
- this.onRejected = typeof onRejected === 'function' ? onRejected : null;
- this.promise = promise;
- }
- function doResolve(fn, self) {
- var done = false;
- try {
- fn(function (value) {
- if (done)
- return;
- done = true;
- resolve(self, value);
- }, function (reason) {
- if (done)
- return;
- done = true;
- reject(self, reason);
- });
- } catch (ex) {
- if (done)
- return;
- done = true;
- reject(self, ex);
- }
- }
- Promise.prototype['catch'] = function (onRejected) {
- return this.then(null, onRejected);
- };
- Promise.prototype.then = function (onFulfilled, onRejected) {
- var prom = new this.constructor(noop);
- handle(this, new Handler(onFulfilled, onRejected, prom));
- return prom;
- };
- Promise.all = function (arr) {
- var args = Array.prototype.slice.call(arr);
- return new Promise(function (resolve, reject) {
- if (args.length === 0)
- return resolve([]);
- var remaining = args.length;
- function res(i, val) {
- try {
- if (val && (typeof val === 'object' || typeof val === 'function')) {
- var then = val.then;
- if (typeof then === 'function') {
- then.call(val, function (val) {
- res(i, val);
- }, reject);
- return;
- }
- }
- args[i] = val;
- if (--remaining === 0) {
- resolve(args);
- }
- } catch (ex) {
- reject(ex);
- }
- }
- for (var i = 0; i < args.length; i++) {
- res(i, args[i]);
- }
- });
- };
- Promise.resolve = function (value) {
- if (value && typeof value === 'object' && value.constructor === Promise) {
- return value;
- }
- return new Promise(function (resolve) {
- resolve(value);
- });
- };
- Promise.reject = function (value) {
- return new Promise(function (resolve, reject) {
- reject(value);
- });
- };
- Promise.race = function (values) {
- return new Promise(function (resolve, reject) {
- for (var i = 0, len = values.length; i < len; i++) {
- values[i].then(resolve, reject);
- }
- });
- };
- Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
- setImmediate(fn);
- } : function (fn) {
- setTimeoutFunc(fn, 0);
- };
- Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
- if (typeof console !== 'undefined' && console) {
- console.warn('Possible Unhandled Promise Rejection:', err);
- }
- };
- Promise._setImmediateFn = function _setImmediateFn(fn) {
- Promise._immediateFn = fn;
- };
- Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
- Promise._unhandledRejectionFn = fn;
- };
- if (typeof module !== 'undefined' && module.exports) {
- module.exports = Promise;
- } else if (!root.Promise) {
- root.Promise = Promise;
- }
- }(this));
- }.call(this, require('timers').setImmediate));
- },
- { 'timers': 3 }
- ],
- 3: [
- function (require, module, exports) {
- (function (setImmediate, clearImmediate) {
- var nextTick = require('process/browser.js').nextTick;
- var apply = Function.prototype.apply;
- var slice = Array.prototype.slice;
- var immediateIds = {};
- var nextImmediateId = 0;
- exports.setTimeout = function () {
- return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
- };
- exports.setInterval = function () {
- return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
- };
- exports.clearTimeout = exports.clearInterval = function (timeout) {
- timeout.close();
- };
- function Timeout(id, clearFn) {
- this._id = id;
- this._clearFn = clearFn;
- }
- Timeout.prototype.unref = Timeout.prototype.ref = function () {
- };
- Timeout.prototype.close = function () {
- this._clearFn.call(window, this._id);
- };
- exports.enroll = function (item, msecs) {
- clearTimeout(item._idleTimeoutId);
- item._idleTimeout = msecs;
- };
- exports.unenroll = function (item) {
- clearTimeout(item._idleTimeoutId);
- item._idleTimeout = -1;
- };
- exports._unrefActive = exports.active = function (item) {
- clearTimeout(item._idleTimeoutId);
- var msecs = item._idleTimeout;
- if (msecs >= 0) {
- item._idleTimeoutId = setTimeout(function onTimeout() {
- if (item._onTimeout)
- item._onTimeout();
- }, msecs);
- }
- };
- exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
- var id = nextImmediateId++;
- var args = arguments.length < 2 ? false : slice.call(arguments, 1);
- immediateIds[id] = true;
- nextTick(function onNextTick() {
- if (immediateIds[id]) {
- if (args) {
- fn.apply(null, args);
- } else {
- fn.call(null);
- }
- exports.clearImmediate(id);
- }
- });
- return id;
- };
- exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
- delete immediateIds[id];
- };
- }.call(this, require('timers').setImmediate, require('timers').clearImmediate));
- },
- {
- 'process/browser.js': 1,
- 'timers': 3
- }
- ],
- 4: [
- function (require, module, exports) {
- var promisePolyfill = require('promise-polyfill');
- var Global = function () {
- if (typeof window !== 'undefined') {
- return window;
- } else {
- return Function('return this;')();
- }
- }();
- module.exports = { boltExport: Global.Promise || promisePolyfill };
- },
- { 'promise-polyfill': 2 }
- ]
- }, {}, [4])(4);
- }));
- }(undefined, exports$1, module, undefined));
- var Promise = module.exports.boltExport;
- var nu = function (baseFn) {
- var data = Option.none();
- var callbacks = [];
- var map = function (f) {
- return nu(function (nCallback) {
- get(function (data) {
- nCallback(f(data));
- });
- });
- };
- var get = function (nCallback) {
- if (isReady()) {
- call(nCallback);
- } else {
- callbacks.push(nCallback);
- }
- };
- var set = function (x) {
- data = Option.some(x);
- run(callbacks);
- callbacks = [];
- };
- var isReady = function () {
- return data.isSome();
- };
- var run = function (cbs) {
- each(cbs, call);
- };
- var call = function (cb) {
- data.each(function (x) {
- domGlobals.setTimeout(function () {
- cb(x);
- }, 0);
- });
- };
- baseFn(set);
- return {
- get: get,
- map: map,
- isReady: isReady
- };
- };
- var pure = function (a) {
- return nu(function (callback) {
- callback(a);
- });
- };
- var LazyValue = {
- nu: nu,
- pure: pure
- };
- var errorReporter = function (err) {
- domGlobals.setTimeout(function () {
- throw err;
- }, 0);
- };
- var make = function (run) {
- var get = function (callback) {
- run().then(callback, errorReporter);
- };
- var map = function (fab) {
- return make(function () {
- return run().then(fab);
- });
- };
- var bind = function (aFutureB) {
- return make(function () {
- return run().then(function (v) {
- return aFutureB(v).toPromise();
- });
- });
- };
- var anonBind = function (futureB) {
- return make(function () {
- return run().then(function () {
- return futureB.toPromise();
- });
- });
- };
- var toLazy = function () {
- return LazyValue.nu(get);
- };
- var toCached = function () {
- var cache = null;
- return make(function () {
- if (cache === null) {
- cache = run();
- }
- return cache;
- });
- };
- var toPromise = run;
- return {
- map: map,
- bind: bind,
- anonBind: anonBind,
- toLazy: toLazy,
- toCached: toCached,
- toPromise: toPromise,
- get: get
- };
- };
- var nu$1 = function (baseFn) {
- return make(function () {
- return new Promise(baseFn);
- });
- };
- var pure$1 = function (a) {
- return make(function () {
- return Promise.resolve(a);
- });
- };
- var Future = {
- nu: nu$1,
- pure: pure$1
- };
- var global$4 = tinymce.util.Tools.resolve('tinymce.util.Delay');
- var delayedConfirm = function (editor, message, callback) {
- var rng = editor.selection.getRng();
- global$4.setEditorTimeout(editor, function () {
- editor.windowManager.confirm(message, function (state) {
- editor.selection.setRng(rng);
- callback(state);
- });
- });
- };
- var tryEmailTransform = function (data) {
- var url = data.href;
- var suggestMailTo = url.indexOf('@') > 0 && url.indexOf('//') === -1 && url.indexOf('mailto:') === -1;
- return suggestMailTo ? Option.some({
- message: 'The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?',
- preprocess: function (oldData) {
- return __assign(__assign({}, oldData), { href: 'mailto:' + url });
- }
- }) : Option.none();
- };
- var tryProtocolTransform = function (assumeExternalTargets, defaultLinkProtocol) {
- return function (data) {
- var url = data.href;
- var suggestProtocol = assumeExternalTargets === 1 && !Utils.hasProtocol(url) || assumeExternalTargets === 0 && /^\s*www[\.|\d\.]/i.test(url);
- return suggestProtocol ? Option.some({
- message: 'The URL you entered seems to be an external link. Do you want to add the required ' + defaultLinkProtocol + ':// prefix?',
- preprocess: function (oldData) {
- return __assign(__assign({}, oldData), { href: defaultLinkProtocol + '://' + url });
- }
- }) : Option.none();
- };
- };
- var preprocess = function (editor, data) {
- return findMap([
- tryEmailTransform,
- tryProtocolTransform(Settings.assumeExternalTargets(editor), Settings.getDefaultLinkProtocol(editor))
- ], function (f) {
- return f(data);
- }).fold(function () {
- return Future.pure(data);
- }, function (transform) {
- return Future.nu(function (callback) {
- delayedConfirm(editor, transform.message, function (state) {
- callback(state ? transform.preprocess(data) : data);
- });
- });
- });
- };
- var DialogConfirms = { preprocess: preprocess };
- var getAnchors = function (editor) {
- var anchorNodes = editor.dom.select('a:not([href])');
- var anchors = bind(anchorNodes, function (anchor) {
- var id = anchor.name || anchor.id;
- return id ? [{
- text: id,
- value: '#' + id
- }] : [];
- });
- return anchors.length > 0 ? Option.some([{
- text: 'None',
- value: ''
- }].concat(anchors)) : Option.none();
- };
- var AnchorListOptions = { getAnchors: getAnchors };
- var getClasses = function (editor) {
- var list = Settings.getLinkClassList(editor);
- if (list.length > 0) {
- return ListOptions.sanitize(list);
- }
- return Option.none();
- };
- var ClassListOptions = { getClasses: getClasses };
- var global$5 = tinymce.util.Tools.resolve('tinymce.util.XHR');
- var parseJson = function (text) {
- try {
- return Option.some(JSON.parse(text));
- } catch (err) {
- return Option.none();
- }
- };
- var getLinks = function (editor) {
- var extractor = function (item) {
- return editor.convertURL(item.value || item.url, 'href');
- };
- var linkList = Settings.getLinkList(editor);
- return Future.nu(function (callback) {
- if (isString(linkList)) {
- global$5.send({
- url: linkList,
- success: function (text) {
- return callback(parseJson(text));
- },
- error: function (_) {
- return callback(Option.none());
- }
- });
- } else if (isFunction(linkList)) {
- linkList(function (output) {
- return callback(Option.some(output));
- });
- } else {
- callback(Option.from(linkList));
- }
- }).map(function (optItems) {
- return optItems.bind(ListOptions.sanitizeWith(extractor)).map(function (items) {
- if (items.length > 0) {
- return [{
- text: 'None',
- value: ''
- }].concat(items);
- } else {
- return items;
- }
- });
- });
- };
- var LinkListOptions = { getLinks: getLinks };
- var getRels = function (editor, initialTarget) {
- var list = Settings.getRelList(editor);
- if (list.length > 0) {
- var isTargetBlank_1 = initialTarget.is('_blank');
- var enforceSafe = Settings.allowUnsafeLinkTarget(editor) === false;
- var safeRelExtractor = function (item) {
- return Utils.applyRelTargetRules(ListOptions.getValue(item), isTargetBlank_1);
- };
- var sanitizer = enforceSafe ? ListOptions.sanitizeWith(safeRelExtractor) : ListOptions.sanitize;
- return sanitizer(list);
- }
- return Option.none();
- };
- var RelOptions = { getRels: getRels };
- var fallbacks = [
- {
- text: 'Current window',
- value: ''
- },
- {
- text: 'New window',
- value: '_blank'
- }
- ];
- var getTargets = function (editor) {
- var list = Settings.getTargetList(editor);
- if (isArray(list)) {
- return ListOptions.sanitize(list).orThunk(function () {
- return Option.some(fallbacks);
- });
- } else if (list === false) {
- return Option.none();
- }
- return Option.some(fallbacks);
- };
- var TargetOptions = { getTargets: getTargets };
- var nonEmptyAttr = function (dom, elem, name) {
- var val = dom.getAttrib(elem, name);
- return val !== null && val.length > 0 ? Option.some(val) : Option.none();
- };
- var extractFromAnchor = function (editor, anchor) {
- var dom = editor.dom;
- var onlyText = Utils.isOnlyTextSelected(editor.selection.getContent());
- var text = onlyText ? Option.some(Utils.getAnchorText(editor.selection, anchor)) : Option.none();
- var url = anchor ? Option.some(dom.getAttrib(anchor, 'href')) : Option.none();
- var target = anchor ? Option.from(dom.getAttrib(anchor, 'target')) : Option.none();
- var rel = nonEmptyAttr(dom, anchor, 'rel');
- var linkClass = nonEmptyAttr(dom, anchor, 'class');
- var title = nonEmptyAttr(dom, anchor, 'title');
- return {
- url: url,
- text: text,
- title: title,
- target: target,
- rel: rel,
- linkClass: linkClass
- };
- };
- var collect = function (editor, linkNode) {
- return LinkListOptions.getLinks(editor).map(function (links) {
- var anchor = extractFromAnchor(editor, linkNode);
- return {
- anchor: anchor,
- catalogs: {
- targets: TargetOptions.getTargets(editor),
- rels: RelOptions.getRels(editor, anchor.target),
- classes: ClassListOptions.getClasses(editor),
- anchor: AnchorListOptions.getAnchors(editor),
- link: links
- },
- optNode: Option.from(linkNode),
- flags: { titleEnabled: Settings.shouldShowLinkTitle(editor) }
- };
- });
- };
- var DialogInfo = { collect: collect };
- var handleSubmit = function (editor, info) {
- return function (api) {
- var data = api.getData();
- if (!data.url.value) {
- Utils.unlink(editor);
- api.close();
- return;
- }
- var getChangedValue = function (key) {
- return Option.from(data[key]).filter(function (value) {
- return !info.anchor[key].is(value);
- });
- };
- var changedData = {
- href: data.url.value,
- text: getChangedValue('text'),
- target: getChangedValue('target'),
- rel: getChangedValue('rel'),
- class: getChangedValue('linkClass'),
- title: getChangedValue('title')
- };
- var attachState = {
- href: data.url.value,
- attach: data.url.meta !== undefined && data.url.meta.attach ? data.url.meta.attach : function () {
- }
- };
- DialogConfirms.preprocess(editor, changedData).get(function (pData) {
- Utils.link(editor, attachState, pData);
- });
- api.close();
- };
- };
- var collectData = function (editor) {
- var anchorNode = Utils.getAnchorElement(editor);
- return DialogInfo.collect(editor, anchorNode);
- };
- var getInitialData = function (info, defaultTarget) {
- return {
- url: {
- value: info.anchor.url.getOr(''),
- meta: {
- attach: function () {
- },
- text: info.anchor.url.fold(function () {
- return '';
- }, function () {
- return info.anchor.text.getOr('');
- }),
- original: { value: info.anchor.url.getOr('') }
- }
- },
- text: info.anchor.text.getOr(''),
- title: info.anchor.title.getOr(''),
- anchor: info.anchor.url.getOr(''),
- link: info.anchor.url.getOr(''),
- rel: info.anchor.rel.getOr(''),
- target: info.anchor.target.or(defaultTarget).getOr(''),
- linkClass: info.anchor.linkClass.getOr('')
- };
- };
- var makeDialog = function (settings, onSubmit, editor) {
- var urlInput = [{
- name: 'url',
- type: 'urlinput',
- filetype: 'file',
- label: 'URL'
- }];
- var displayText = settings.anchor.text.map(function () {
- return {
- name: 'text',
- type: 'input',
- label: 'Text to display'
- };
- }).toArray();
- var titleText = settings.flags.titleEnabled ? [{
- name: 'title',
- type: 'input',
- label: 'Title'
- }] : [];
- var defaultTarget = Option.from(Settings.getDefaultLinkTarget(editor));
- var initialData = getInitialData(settings, defaultTarget);
- var dialogDelta = DialogChanges.init(initialData, settings);
- var catalogs = settings.catalogs;
- var body = {
- type: 'panel',
- items: flatten([
- urlInput,
- displayText,
- titleText,
- cat([
- catalogs.anchor.map(ListOptions.createUi('anchor', 'Anchors')),
- catalogs.rels.map(ListOptions.createUi('rel', 'Rel')),
- catalogs.targets.map(ListOptions.createUi('target', 'Open link in...')),
- catalogs.link.map(ListOptions.createUi('link', 'Link list')),
- catalogs.classes.map(ListOptions.createUi('linkClass', 'Class'))
- ])
- ])
- };
- return {
- title: 'Insert/Edit Link',
- size: 'normal',
- body: body,
- buttons: [
- {
- type: 'cancel',
- name: 'cancel',
- text: 'Cancel'
- },
- {
- type: 'submit',
- name: 'save',
- text: 'Save',
- primary: true
- }
- ],
- initialData: initialData,
- onChange: function (api, _a) {
- var name = _a.name;
- dialogDelta.onChange(api.getData, { name: name }).each(function (newData) {
- api.setData(newData);
- });
- },
- onSubmit: onSubmit
- };
- };
- var open$1 = function (editor) {
- var data = collectData(editor);
- data.map(function (info) {
- var onSubmit = handleSubmit(editor, info);
- return makeDialog(info, onSubmit, editor);
- }).get(function (spec) {
- editor.windowManager.open(spec);
- });
- };
- var Dialog = { open: open$1 };
- var getLink = function (editor, elm) {
- return editor.dom.getParent(elm, 'a[href]');
- };
- var getSelectedLink = function (editor) {
- return getLink(editor, editor.selection.getStart());
- };
- var hasOnlyAltModifier = function (e) {
- return e.altKey === true && e.shiftKey === false && e.ctrlKey === false && e.metaKey === false;
- };
- var gotoLink = function (editor, a) {
- if (a) {
- var href = Utils.getHref(a);
- if (/^#/.test(href)) {
- var targetEl = editor.$(href);
- if (targetEl.length) {
- editor.selection.scrollIntoView(targetEl[0], true);
- }
- } else {
- OpenUrl.open(a.href);
- }
- }
- };
- var openDialog = function (editor) {
- return function () {
- Dialog.open(editor);
- };
- };
- var gotoSelectedLink = function (editor) {
- return function () {
- gotoLink(editor, getSelectedLink(editor));
- };
- };
- var leftClickedOnAHref = function (editor) {
- return function (elm) {
- var sel, rng, node;
- if (Settings.hasContextToolbar(editor) && Utils.isLink(elm)) {
- sel = editor.selection;
- rng = sel.getRng();
- node = rng.startContainer;
- if (node.nodeType === 3 && sel.isCollapsed() && rng.startOffset > 0 && rng.startOffset < node.data.length) {
- return true;
- }
- }
- return false;
- };
- };
- var setupGotoLinks = function (editor) {
- editor.on('click', function (e) {
- var link = getLink(editor, e.target);
- if (link && global$2.metaKeyPressed(e)) {
- e.preventDefault();
- gotoLink(editor, link);
- }
- });
- editor.on('keydown', function (e) {
- var link = getSelectedLink(editor);
- if (link && e.keyCode === 13 && hasOnlyAltModifier(e)) {
- e.preventDefault();
- gotoLink(editor, link);
- }
- });
- };
- var toggleActiveState = function (editor) {
- return function (api) {
- var nodeChangeHandler = function (e) {
- return api.setActive(!editor.readonly && !!Utils.getAnchorElement(editor, e.element));
- };
- editor.on('NodeChange', nodeChangeHandler);
- return function () {
- return editor.off('NodeChange', nodeChangeHandler);
- };
- };
- };
- var toggleEnabledState = function (editor) {
- return function (api) {
- api.setDisabled(!Utils.hasLinks(editor.dom.getParents(editor.selection.getStart())));
- var nodeChangeHandler = function (e) {
- return api.setDisabled(!Utils.hasLinks(e.parents));
- };
- editor.on('NodeChange', nodeChangeHandler);
- return function () {
- return editor.off('NodeChange', nodeChangeHandler);
- };
- };
- };
- var Actions = {
- openDialog: openDialog,
- gotoSelectedLink: gotoSelectedLink,
- leftClickedOnAHref: leftClickedOnAHref,
- setupGotoLinks: setupGotoLinks,
- toggleActiveState: toggleActiveState,
- toggleEnabledState: toggleEnabledState
- };
- var register = function (editor) {
- editor.addCommand('mceLink', function () {
- if (Settings.useQuickLink(editor)) {
- editor.fire('contexttoolbar-show', { toolbarKey: 'quicklink' });
- } else {
- Actions.openDialog(editor)();
- }
- });
- };
- var Commands = { register: register };
- var setup = function (editor) {
- editor.addShortcut('Meta+K', '', function () {
- editor.execCommand('mceLink');
- });
- };
- var Keyboard = { setup: setup };
- var setupButtons = function (editor) {
- editor.ui.registry.addToggleButton('link', {
- icon: 'link',
- tooltip: 'Insert/edit link',
- onAction: Actions.openDialog(editor),
- onSetup: Actions.toggleActiveState(editor)
- });
- editor.ui.registry.addButton('openlink', {
- icon: 'new-tab',
- tooltip: 'Open link',
- onAction: Actions.gotoSelectedLink(editor),
- onSetup: Actions.toggleEnabledState(editor)
- });
- editor.ui.registry.addButton('unlink', {
- icon: 'unlink',
- tooltip: 'Remove link',
- onAction: function () {
- return Utils.unlink(editor);
- },
- onSetup: Actions.toggleEnabledState(editor)
- });
- };
- var setupMenuItems = function (editor) {
- editor.ui.registry.addMenuItem('openlink', {
- text: 'Open link',
- icon: 'new-tab',
- onAction: Actions.gotoSelectedLink(editor),
- onSetup: Actions.toggleEnabledState(editor)
- });
- editor.ui.registry.addMenuItem('link', {
- icon: 'link',
- text: 'Link...',
- shortcut: 'Meta+K',
- onAction: Actions.openDialog(editor)
- });
- editor.ui.registry.addMenuItem('unlink', {
- icon: 'unlink',
- text: 'Remove link',
- onAction: function () {
- return Utils.unlink(editor);
- },
- onSetup: Actions.toggleEnabledState(editor)
- });
- };
- var setupContextMenu = function (editor) {
- var inLink = 'link unlink openlink';
- var noLink = 'link';
- editor.ui.registry.addContextMenu('link', {
- update: function (element) {
- return Utils.hasLinks(editor.dom.getParents(element, 'a')) ? inLink : noLink;
- }
- });
- };
- var setupContextToolbars = function (editor) {
- var collapseSelectionToEnd = function (editor) {
- editor.selection.collapse(false);
- };
- var onSetupLink = function (buttonApi) {
- var node = editor.selection.getNode();
- buttonApi.setDisabled(!Utils.getAnchorElement(editor, node));
- return function () {
- };
- };
- editor.ui.registry.addContextForm('quicklink', {
- launch: {
- type: 'contextformtogglebutton',
- icon: 'link',
- tooltip: 'Link',
- onSetup: Actions.toggleActiveState(editor)
- },
- label: 'Link',
- predicate: function (node) {
- return !!Utils.getAnchorElement(editor, node) && Settings.hasContextToolbar(editor);
- },
- initValue: function () {
- var elm = Utils.getAnchorElement(editor);
- return !!elm ? Utils.getHref(elm) : '';
- },
- commands: [
- {
- type: 'contextformtogglebutton',
- icon: 'link',
- tooltip: 'Link',
- primary: true,
- onSetup: function (buttonApi) {
- var node = editor.selection.getNode();
- buttonApi.setActive(!!Utils.getAnchorElement(editor, node));
- return Actions.toggleActiveState(editor)(buttonApi);
- },
- onAction: function (formApi) {
- var anchor = Utils.getAnchorElement(editor);
- var value = formApi.getValue();
- if (!anchor) {
- var attachState = {
- href: value,
- attach: function () {
- }
- };
- var onlyText = Utils.isOnlyTextSelected(editor.selection.getContent());
- var text = onlyText ? Option.some(Utils.getAnchorText(editor.selection, anchor)).filter(function (t) {
- return t.length > 0;
- }).or(Option.from(value)) : Option.none();
- Utils.link(editor, attachState, {
- href: value,
- text: text,
- title: Option.none(),
- rel: Option.none(),
- target: Option.none(),
- class: Option.none()
- });
- formApi.hide();
- } else {
- editor.dom.setAttrib(anchor, 'href', value);
- collapseSelectionToEnd(editor);
- formApi.hide();
- }
- }
- },
- {
- type: 'contextformbutton',
- icon: 'unlink',
- tooltip: 'Remove link',
- onSetup: onSetupLink,
- onAction: function (formApi) {
- Utils.unlink(editor);
- formApi.hide();
- }
- },
- {
- type: 'contextformbutton',
- icon: 'new-tab',
- tooltip: 'Open link',
- onSetup: onSetupLink,
- onAction: function (formApi) {
- Actions.gotoSelectedLink(editor)();
- formApi.hide();
- }
- }
- ]
- });
- };
- var Controls = {
- setupButtons: setupButtons,
- setupMenuItems: setupMenuItems,
- setupContextMenu: setupContextMenu,
- setupContextToolbars: setupContextToolbars
- };
- function Plugin () {
- global$1.add('link', function (editor) {
- Controls.setupButtons(editor);
- Controls.setupMenuItems(editor);
- Controls.setupContextMenu(editor);
- Controls.setupContextToolbars(editor);
- Actions.setupGotoLinks(editor);
- Commands.register(editor);
- Keyboard.setup(editor);
- });
- }
- Plugin();
- }(window));
|