diff --git a/CHANGES.md b/CHANGES.md index 26b0c2fdb..a7671f245 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,17 @@ +4.12.0 / 2015-06-01 +================== +* Fix pasting links when targetBlank option is being used +* Fix for spellcheck option after destroy +* Fix over-reaching keyboard shortcuts for commands +* Expose new 'positionToolbar' custom event +* Add new isKey() helper in util +* Add cleanup on destroy for auto-link and placeholder extensions +* Base extension changes + * Add getEditorElements(), getEditorId(), and getEditorOption() helpers + * Add on(), off(), subscribe(), and execAction() helpers + * Introduce destroy() lifecycle method + deprecate deactivate() + + 4.11.1 / 2015-05-26 ================== * Fix issue with auto-linked text after manually unlinking diff --git a/bower.json b/bower.json index 775bf9d59..c841eed5a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "medium-editor", - "version": "4.11.1", + "version": "4.12.0", "homepage": "http://yabwe.github.io/medium-editor/", "authors": [ "Davi Ferreira ", diff --git a/dist/js/medium-editor.js b/dist/js/medium-editor.js index 3ed0f040b..2a33df527 100644 --- a/dist/js/medium-editor.js +++ b/dist/js/medium-editor.js @@ -478,6 +478,32 @@ var Util; return false; }, + /** + * Returns true if the key associated to the event is inside keys array + * + * @see : https://github.com/jquery/jquery/blob/0705be475092aede1eddae01319ec931fb9c65fc/src/event.js#L473-L484 + * @see : http://stackoverflow.com/q/4471582/569101 + */ + isKey: function (event, keys) { + var keyCode = event.which; + + // getting the key code from event + if (null === keyCode) { + keyCode = event.charCode !== null ? event.charCode : event.keyCode; + } + + // it's not an array let's just compare strings! + if (false === Array.isArray(keys)) { + return keyCode === keys; + } + + if (-1 === keys.indexOf(keyCode)) { + return false; + } + + return true; + }, + parentElements: ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'pre'], extend: function extend(/* dest, source1, source2, ...*/) { @@ -673,43 +699,25 @@ var Util; }, getSelectionRange: function (ownerDocument) { - var selection = ownerDocument.getSelection(); - if (selection.rangeCount === 0) { - return null; - } - return selection.getRangeAt(0); + this.deprecated('Util.getSelectionRange', 'Selection.getSelectionRange', 'v5.0.0'); + + return Selection.getSelectionRange(ownerDocument); }, - // http://stackoverflow.com/questions/1197401/how-can-i-get-the-element-the-caret-is-in-with-javascript-when-using-contentedi - // by You getSelectionStart: function (ownerDocument) { - var node = ownerDocument.getSelection().anchorNode, - startNode = (node && node.nodeType === 3 ? node.parentNode : node); - return startNode; + this.deprecated('Util.getSelectionStart', 'Selection.getSelectionStart', 'v5.0.0'); + + return Selection.getSelectionStart(ownerDocument); }, getSelectionData: function (el) { - var tagName; - - if (el && el.tagName) { - tagName = el.tagName.toLowerCase(); - } - - while (el && this.parentElements.indexOf(tagName) === -1) { - el = el.parentNode; - if (el && el.tagName) { - tagName = el.tagName.toLowerCase(); - } - } + this.deprecated('Util.getSelectionData', 'Selection.getSelectionData', 'v5.0.0'); - return { - el: el, - tagName: tagName - }; + return Selection.getSelectionData(el); }, execFormatBlock: function (doc, tagName) { - var selectionData = this.getSelectionData(this.getSelectionStart(doc)); + var selectionData = Selection.getSelectionData(Selection.getSelectionStart(doc)); // FF handles blockquote differently on formatBlock // allowing nesting, we need to use outdent // https://developer.mozilla.org/en-US/docs/Rich-Text_Editing_in_Mozilla @@ -948,7 +956,7 @@ var Util; for (var i = 0; i < rootNode.childNodes.length; i++) { nextNode = rootNode.childNodes[i]; if (!firstChild) { - if (Util.isDescendant(nextNode, startNode, true)) { + if (this.isDescendant(nextNode, startNode, true)) { firstChild = nextNode; } } else { @@ -1083,8 +1091,9 @@ var Util; }, this); }, - getClosestTag: function (el, tag) { // get the closest parent - return Util.traverseUp(el, function (element) { + // get the closest parent + getClosestTag: function (el, tag) { + return this.traverseUp(el, function (element) { return element.tagName.toLowerCase() === tag.toLowerCase(); }); }, @@ -1352,11 +1361,9 @@ var ButtonsData; })(); var editorDefaults; (function () { - // summary: The default options hash used by the Editor editorDefaults = { - allowMultiParagraphSelection: true, buttons: ['bold', 'italic', 'underline', 'anchor', 'header1', 'header2', 'quote'], buttonLabels: false, @@ -1383,7 +1390,6 @@ var editorDefaults; lastButtonClass: 'medium-editor-button-last', spellcheck: true }; - })(); var Extension; @@ -1495,6 +1501,15 @@ var Extension; */ checkState: undefined, + /* destroy: [function ()] + * + * This method should remove any created html, custom event handlers + * or any other cleanup tasks that should be performed. + * If implemented, this function will be called when MediumEditor's + * destroy method has been called. + */ + destroy: undefined, + /* As alternatives to checkState, these functions provide a more structured * path to updating the state of an extension (usually a button) whenever * the state of the editor & toolbar are updated. @@ -1581,8 +1596,60 @@ var Extension; * passed via the 'ownerDocument' optin to MediumEditor * and is the global 'document' object by default */ - 'document': undefined + 'document': undefined, + + /* getEditorElements: [function ()] + * + * Helper function which returns an array containing + * all the contenteditable elements for this instance + * of MediumEditor + */ + getEditorElements: function () { + return this.base.elements; + }, + + /* getEditorId: [function ()] + * + * Helper function which returns a unique identifier + * for this instance of MediumEditor + */ + getEditorId: function () { + return this.base.id; + }, + + /* getEditorOptions: [function (option)] + * + * Helper function which returns the value of an option + * used to initialize this instance of MediumEditor + */ + getEditorOption: function (option) { + return this.base.options[option]; + } }; + + /* List of method names to add to the prototype of Extension + * Each of these methods will be defined as helpers that + * just call directly into the MediumEditor instance. + * + * example for 'on' method: + * Extension.prototype.on = function () { + * return this.base.on.apply(this.base, arguments); + * } + */ + [ + // general helpers + 'execAction', + + // event handling + 'on', + 'off', + 'subscribe' + + ].forEach(function (helper) { + Extension.prototype[helper] = function () { + return this.base[helper].apply(this.base, arguments); + }; + }); })(); var Selection; @@ -1717,15 +1784,22 @@ var Selection; }, getSelectedParentElement: function (range) { - var selectedParentElement = null; + if (!range) { + return null; + } + + // Selection encompasses a single element if (this.rangeSelectsSingleNode(range) && range.startContainer.childNodes[range.startOffset].nodeType !== 3) { - selectedParentElement = range.startContainer.childNodes[range.startOffset]; - } else if (range.startContainer.nodeType === 3) { - selectedParentElement = range.startContainer.parentNode; - } else { - selectedParentElement = range.startContainer; + return range.startContainer.childNodes[range.startOffset]; + } + + // Selection range starts inside a text node, so get its parent + if (range.startContainer.nodeType === 3) { + return range.startContainer.parentNode; } - return selectedParentElement; + + // Selection starts inside an element + return range.startContainer; }, getSelectedElements: function (doc) { @@ -1734,8 +1808,7 @@ var Selection; toRet, currNode; - if (!selection.rangeCount || - !selection.getRangeAt(0).commonAncestorContainer) { + if (!selection.rangeCount || selection.isCollapsed || !selection.getRangeAt(0).commonAncestorContainer) { return []; } @@ -1785,6 +1858,43 @@ var Selection; sel.removeAllRanges(); sel.addRange(range); + }, + + getSelectionRange: function (ownerDocument) { + var selection = ownerDocument.getSelection(); + if (selection.rangeCount === 0 || true === selection.isCollapsed) { + return null; + } + return selection.getRangeAt(0); + }, + + // http://stackoverflow.com/questions/1197401/how-can-i-get-the-element-the-caret-is-in-with-javascript-when-using-contentedi + // by You + getSelectionStart: function (ownerDocument) { + var node = ownerDocument.getSelection().anchorNode, + startNode = (node && node.nodeType === 3 ? node.parentNode : node); + + return startNode; + }, + + getSelectionData: function (el) { + var tagName; + + if (el && el.tagName) { + tagName = el.tagName.toLowerCase(); + } + + while (el && Util.parentElements.indexOf(tagName) === -1) { + el = el.parentNode; + if (el && el.tagName) { + tagName = el.tagName.toLowerCase(); + } + } + + return { + el: el, + tagName: tagName + }; } }; }()); @@ -1803,7 +1913,6 @@ var Events; }; Events.prototype = { - InputEventOnContenteditableSupported: !Util.isIE, // Helpers for event handling @@ -1844,27 +1953,20 @@ var Events; // custom events attachCustomEvent: function (event, listener) { this.setupListener(event); - // If we don't support this custom event, don't do anything - if (this.listeners[event]) { - if (!this.customEvents[event]) { - this.customEvents[event] = []; - } - this.customEvents[event].push(listener); + if (!this.customEvents[event]) { + this.customEvents[event] = []; } + this.customEvents[event].push(listener); }, detachCustomEvent: function (event, listener) { var index = this.indexOfCustomListener(event, listener); if (index !== -1) { this.customEvents[event].splice(index, 1); - // TODO: If array is empty, should detach internal listeners via destoryListener() + // TODO: If array is empty, should detach internal listeners via destroyListener() } }, - defineCustomEvent: function (event) { - this.listeners[event] = true; - }, - indexOfCustomListener: function (event, listener) { if (!this.customEvents[event] || !this.customEvents[event].length) { return -1; @@ -1952,18 +2054,20 @@ var Events; var wrapper = function (aCommandName, aShowDefaultUI, aValueArgument) { var result = doc.execCommand.orig.apply(this, arguments); - if (doc.execCommand.listeners) { - var args = Array.prototype.slice.call(arguments); - doc.execCommand.listeners.forEach(function (listener) { - listener({ - command: aCommandName, - value: aValueArgument, - args: args, - result: result - }); - }); + if (!doc.execCommand.listeners) { + return result; } + var args = Array.prototype.slice.call(arguments); + doc.execCommand.listeners.forEach(function (listener) { + listener({ + command: aCommandName, + value: aValueArgument, + args: args, + result: result + }); + }); + return result; }; @@ -2000,17 +2104,14 @@ var Events; this.attachDOMEvent(this.options.ownerDocument.body, 'mousedown', this.handleBodyMousedown.bind(this), true); this.attachDOMEvent(this.options.ownerDocument.body, 'click', this.handleBodyClick.bind(this), true); this.attachDOMEvent(this.options.ownerDocument.body, 'focus', this.handleBodyFocus.bind(this), true); - this.listeners[name] = true; break; case 'blur': // Detecting when focus is lost this.setupListener('externalInteraction'); - this.listeners[name] = true; break; case 'focus': // Detecting when focus moves into some part of MediumEditor this.setupListener('externalInteraction'); - this.listeners[name] = true; break; case 'editableInput': // setup cache for knowing when the content has changed @@ -2033,65 +2134,54 @@ var Events; // Listen to calls to execCommand this.attachToExecCommand(); } - - this.listeners[name] = true; break; case 'editableClick': // Detecting click in the contenteditables this.base.elements.forEach(function (element) { this.attachDOMEvent(element, 'click', this.handleClick.bind(this)); }.bind(this)); - this.listeners[name] = true; break; case 'editableBlur': // Detecting blur in the contenteditables this.base.elements.forEach(function (element) { this.attachDOMEvent(element, 'blur', this.handleBlur.bind(this)); }.bind(this)); - this.listeners[name] = true; break; case 'editableKeypress': // Detecting keypress in the contenteditables this.base.elements.forEach(function (element) { this.attachDOMEvent(element, 'keypress', this.handleKeypress.bind(this)); }.bind(this)); - this.listeners[name] = true; break; case 'editableKeyup': // Detecting keyup in the contenteditables this.base.elements.forEach(function (element) { this.attachDOMEvent(element, 'keyup', this.handleKeyup.bind(this)); }.bind(this)); - this.listeners[name] = true; break; case 'editableKeydown': // Detecting keydown on the contenteditables this.base.elements.forEach(function (element) { this.attachDOMEvent(element, 'keydown', this.handleKeydown.bind(this)); }.bind(this)); - this.listeners[name] = true; break; case 'editableKeydownEnter': // Detecting keydown for ENTER on the contenteditables this.setupListener('editableKeydown'); - this.listeners[name] = true; break; case 'editableKeydownTab': // Detecting keydown for TAB on the contenteditable this.setupListener('editableKeydown'); - this.listeners[name] = true; break; case 'editableKeydownDelete': // Detecting keydown for DELETE/BACKSPACE on the contenteditables this.setupListener('editableKeydown'); - this.listeners[name] = true; break; case 'editableMouseover': // Detecting mouseover on the contenteditables this.base.elements.forEach(function (element) { this.attachDOMEvent(element, 'mouseover', this.handleMouseover.bind(this)); }, this); - this.listeners[name] = true; break; case 'editableDrag': // Detecting dragover and dragleave on the contenteditables @@ -2099,23 +2189,21 @@ var Events; this.attachDOMEvent(element, 'dragover', this.handleDragging.bind(this)); this.attachDOMEvent(element, 'dragleave', this.handleDragging.bind(this)); }, this); - this.listeners[name] = true; break; case 'editableDrop': // Detecting drop on the contenteditables this.base.elements.forEach(function (element) { this.attachDOMEvent(element, 'drop', this.handleDrop.bind(this)); }, this); - this.listeners[name] = true; break; case 'editablePaste': // Detecting paste on the contenteditables this.base.elements.forEach(function (element) { this.attachDOMEvent(element, 'paste', this.handlePaste.bind(this)); }, this); - this.listeners[name] = true; break; } + this.listeners[name] = true; }, focusElement: function (element) { @@ -2196,8 +2284,7 @@ var Events; // to document, since this is where the event is handled // However, currentTarget will have an 'activeElement' property // which will point to whatever element has focus. - if (event.currentTarget && - event.currentTarget.activeElement) { + if (event.currentTarget && event.currentTarget.activeElement) { var activeElement = event.currentTarget.activeElement, currentTarget; // We can look at the 'activeElement' to determine if the selectionchange has @@ -2290,17 +2377,16 @@ var Events; handleKeydown: function (event) { this.triggerCustomEvent('editableKeydown', event, event.currentTarget); - switch (event.which) { - case Util.keyCode.ENTER: - this.triggerCustomEvent('editableKeydownEnter', event, event.currentTarget); - break; - case Util.keyCode.TAB: - this.triggerCustomEvent('editableKeydownTab', event, event.currentTarget); - break; - case Util.keyCode.DELETE: - case Util.keyCode.BACKSPACE: - this.triggerCustomEvent('editableKeydownDelete', event, event.currentTarget); - break; + if (Util.isKey(event, Util.keyCode.ENTER)) { + return this.triggerCustomEvent('editableKeydownEnter', event, event.currentTarget); + } + + if (Util.isKey(event, Util.keyCode.TAB)) { + return this.triggerCustomEvent('editableKeydownTab', event, event.currentTarget); + } + + if (Util.isKey(event, [Util.keyCode.DELETE, Util.keyCode.BACKSPACE])) { + return this.triggerCustomEvent('editableKeydownDelete', event, event.currentTarget); } } }; @@ -2477,7 +2563,7 @@ var AnchorExtension; evt.preventDefault(); evt.stopPropagation(); - var selectedParentElement = Selection.getSelectedParentElement(Util.getSelectionRange(this.base.options.ownerDocument)); + var selectedParentElement = Selection.getSelectedParentElement(Selection.getSelectionRange(this.base.options.ownerDocument)); if (selectedParentElement.tagName && selectedParentElement.tagName.toLowerCase() === 'a') { return this.base.execAction('unlink'); @@ -3143,12 +3229,11 @@ var Button; /*global Util, Extension */ Button = Extension.extend({ - init: function () { this.button = this.createButton(); - this.base.on(this.button, 'click', this.handleClick.bind(this)); + this.on(this.button, 'click', this.handleClick.bind(this)); if (this.key) { - this.base.subscribe('editableKeydown', this.handleKeydown.bind(this)); + this.subscribe('editableKeydown', this.handleKeydown.bind(this)); } }, @@ -3162,19 +3247,24 @@ var Button; getButton: function () { return this.button; }, + getAction: function () { return (typeof this.action === 'function') ? this.action(this.base.options) : this.action; }, + getAria: function () { return (typeof this.aria === 'function') ? this.aria(this.base.options) : this.aria; }, + getTagNames: function () { return (typeof this.tagNames === 'function') ? this.tagNames(this.base.options) : this.tagNames; }, + createButton: function () { var button = this.document.createElement('button'), content = this.contentDefault, - ariaLabel = this.getAria(); + ariaLabel = this.getAria(), + buttonLabels = this.getEditorOption('buttonLabels'); button.classList.add('medium-editor-action'); button.classList.add('medium-editor-action-' + this.name); button.setAttribute('data-action', this.getAction()); @@ -3182,51 +3272,56 @@ var Button; button.setAttribute('title', ariaLabel); button.setAttribute('aria-label', ariaLabel); } - if (this.base.options.buttonLabels) { - if (this.base.options.buttonLabels === 'fontawesome' && this.contentFA) { + if (buttonLabels) { + if (buttonLabels === 'fontawesome' && this.contentFA) { content = this.contentFA; - } else if (typeof this.base.options.buttonLabels === 'object' && this.base.options.buttonLabels[this.name]) { - content = this.base.options.buttonLabels[this.name]; + } else if (typeof buttonLabels === 'object' && buttonLabels[this.name]) { + content = buttonLabels[this.name]; } } button.innerHTML = content; return button; }, - handleKeydown: function (evt) { - var key = String.fromCharCode(evt.which || evt.keyCode).toLowerCase(), - action; - if (this.key === key && Util.isMetaCtrlKey(evt)) { - evt.preventDefault(); - evt.stopPropagation(); + handleKeydown: function (event) { + var action; + + if (Util.isKey(event, this.key.charCodeAt(0)) && Util.isMetaCtrlKey(event) && !event.shiftKey) { + event.preventDefault(); + event.stopPropagation(); action = this.getAction(); if (action) { - this.base.execAction(action); + this.execAction(action); } } }, - handleClick: function (evt) { - evt.preventDefault(); - evt.stopPropagation(); + + handleClick: function (event) { + event.preventDefault(); + event.stopPropagation(); var action = this.getAction(); if (action) { - this.base.execAction(action); + this.execAction(action); } }, + isActive: function () { - return this.button.classList.contains(this.base.options.activeButtonClass); + return this.button.classList.contains(this.getEditorOption('activeButtonClass')); }, + setInactive: function () { - this.button.classList.remove(this.base.options.activeButtonClass); + this.button.classList.remove(this.getEditorOption('activeButtonClass')); delete this.knownState; }, + setActive: function () { - this.button.classList.add(this.base.options.activeButtonClass); + this.button.classList.add(this.getEditorOption('activeButtonClass')); delete this.knownState; }, + queryCommandState: function () { var queryState = null; if (this.useQueryState) { @@ -3234,6 +3329,7 @@ var Button; } return queryState; }, + isAlreadyApplied: function (node) { var isMatch = false, tagNames = this.getTagNames(), @@ -3268,6 +3364,7 @@ var Button; } }); }()); + var FormExtension; (function () { 'use strict'; @@ -3280,7 +3377,6 @@ var FormExtension; * a 'form' inside the toolbar */ FormExtension = Button.extend({ - // default labels for the form buttons formSaveLabel: '✓', formCloseLabel: '×', @@ -3316,7 +3412,6 @@ var FormExtension; */ hideForm: noop }); - })(); var AnchorForm; (function () { @@ -3325,7 +3420,6 @@ var AnchorForm; /*global Util, Selection, FormExtension */ AnchorForm = FormExtension.extend({ - /* Anchor Form Options */ /* customClassOption: [string] (previously options.anchorButton + options.anchorButtonClass) @@ -3361,10 +3455,6 @@ var AnchorForm; */ targetCheckboxText: 'Open in new window', - /* ----- internal options needed from base ----- */ - 'window': window, - 'document': document, - // Options for the Button base class name: 'anchor', action: 'createLink', @@ -3376,14 +3466,14 @@ var AnchorForm; // Called when the button the toolbar is clicked // Overrides ButtonExtension.handleClick - handleClick: function (evt) { - evt.preventDefault(); - evt.stopPropagation(); + handleClick: function (event) { + event.preventDefault(); + event.stopPropagation(); - var selectedParentElement = Selection.getSelectedParentElement(Util.getSelectionRange(this.document)); + var selectedParentElement = Selection.getSelectedParentElement(Selection.getSelectionRange(this.document)); if (selectedParentElement.tagName && selectedParentElement.tagName.toLowerCase() === 'a') { - return this.base.execAction('unlink'); + return this.execAction('unlink'); } if (!this.isDisplayed()) { @@ -3395,11 +3485,9 @@ var AnchorForm; // Called when user hits the defined shortcut (CTRL / COMMAND + K) // Overrides Button.handleKeydown - handleKeydown: function (evt) { - var key = String.fromCharCode(evt.which || evt.keyCode).toLowerCase(); - - if (this.key === key && Util.isMetaCtrlKey(evt)) { - this.handleClick(evt); + handleKeydown: function (event) { + if (Util.isKey(event, this.key.charCodeAt(0)) && Util.isMetaCtrlKey(event)) { + this.handleClick(event); } }, @@ -3412,19 +3500,18 @@ var AnchorForm; }, getTemplate: function () { - var template = [ '' ]; template.push( '', - this.base.options.buttonLabels === 'fontawesome' ? '' : this.formSaveLabel, + this.getEditorOption('buttonLabels') === 'fontawesome' ? '' : this.formSaveLabel, '' ); template.push('', - this.base.options.buttonLabels === 'fontawesome' ? '' : this.formCloseLabel, + this.getEditorOption('buttonLabels') === 'fontawesome' ? '' : this.formCloseLabel, ''); // both of these options are slightly moot with the ability to @@ -3478,8 +3565,8 @@ var AnchorForm; input.focus(); }, - // Called by core when tearing down medium-editor (deactivate) - deactivate: function () { + // Called by core when tearing down medium-editor (destroy) + destroy: function () { if (!this.form) { return false; } @@ -3491,6 +3578,11 @@ var AnchorForm; delete this.form; }, + // TODO: deprecate + deactivate: function () { + Util.deprecatedMethod.call(this, 'deactivate', 'destroy', arguments, 'v5.0.0'); + }, + // core methods getFormOpts: function () { @@ -3505,10 +3597,9 @@ var AnchorForm; opts.url = this.checkLinkFormat(opts.url); } + opts.target = '_self'; if (targetCheckbox && targetCheckbox.checked) { opts.target = '_blank'; - } else { - opts.target = '_self'; } if (buttonCheckbox && buttonCheckbox.checked) { @@ -3525,7 +3616,7 @@ var AnchorForm; completeFormSave: function (opts) { this.base.restoreSelection(); - this.base.createLink(opts); + this.execAction(this.action, opts); this.base.checkSelection(); }, @@ -3540,23 +3631,22 @@ var AnchorForm; }, // form creation and event handling - attachFormEvents: function (form) { var close = form.querySelector('.medium-editor-toolbar-close'), save = form.querySelector('.medium-editor-toolbar-save'), input = form.querySelector('.medium-editor-toolbar-input'); // Handle clicks on the form itself - this.base.on(form, 'click', this.handleFormClick.bind(this)); + this.on(form, 'click', this.handleFormClick.bind(this)); // Handle typing in the textbox - this.base.on(input, 'keyup', this.handleTextboxKeyup.bind(this)); + this.on(input, 'keyup', this.handleTextboxKeyup.bind(this)); // Handle close button clicks - this.base.on(close, 'click', this.handleCloseClick.bind(this)); + this.on(close, 'click', this.handleCloseClick.bind(this)); // Handle save button clicks (capture) - this.base.on(save, 'click', this.handleSaveClick.bind(this), true); + this.on(save, 'click', this.handleSaveClick.bind(this), true); }, @@ -3566,7 +3656,7 @@ var AnchorForm; // Anchor Form (div) form.className = 'medium-editor-toolbar-form'; - form.id = 'medium-editor-toolbar-form-anchor-' + this.base.id; + form.id = 'medium-editor-toolbar-form-anchor-' + this.getEditorId(); form.innerHTML = this.getTemplate(); this.attachFormEvents(form); @@ -3632,11 +3722,9 @@ var AnchorPreview; previewValueSelector: 'a', /* ----- internal options needed from base ----- */ - 'window': window, - 'document': document, - diffLeft: 0, - diffTop: -10, - elementsContainer: false, + diffLeft: 0, // deprecated (should use .getEditorOption() instead) + diffTop: -10, // deprecated (should use .getEditorOption() instead) + elementsContainer: false, // deprecated (should use .getEditorOption() instead) init: function () { this.anchorPreview = this.createPreview(); @@ -3656,11 +3744,11 @@ var AnchorPreview; createPreview: function () { var el = this.document.createElement('div'); - el.id = 'medium-editor-anchor-preview-' + this.base.id; + el.id = 'medium-editor-anchor-preview-' + this.getEditorId(); el.className = 'medium-editor-anchor-preview'; el.innerHTML = this.getTemplate(); - this.base.on(el, 'click', this.handleClick.bind(this)); + this.on(el, 'click', this.handleClick.bind(this)); return el; }, @@ -3671,7 +3759,7 @@ var AnchorPreview; ''; }, - deactivate: function () { + destroy: function () { if (this.anchorPreview) { if (this.anchorPreview.parentNode) { this.anchorPreview.parentNode.removeChild(this.anchorPreview); @@ -3680,6 +3768,11 @@ var AnchorPreview; } }, + // TODO: deprecate + deactivate: function () { + Util.deprecatedMethod.call(this, 'deactivate', 'destroy', arguments, 'v5.0.0'); + }, + hidePreview: function () { this.anchorPreview.classList.remove('medium-editor-anchor-preview-active'); this.activeAnchor = null; @@ -3732,7 +3825,7 @@ var AnchorPreview; }, attachToEditables: function () { - this.base.subscribe('editableMouseover', this.handleEditableMouseover.bind(this)); + this.subscribe('editableMouseover', this.handleEditableMouseover.bind(this)); }, handleClick: function (event) { @@ -3759,47 +3852,48 @@ var AnchorPreview; handleAnchorMouseout: function () { this.anchorToPreview = null; - this.base.off(this.activeAnchor, 'mouseout', this.instanceHandleAnchorMouseout); + this.off(this.activeAnchor, 'mouseout', this.instanceHandleAnchorMouseout); this.instanceHandleAnchorMouseout = null; }, handleEditableMouseover: function (event) { var target = Util.getClosestTag(event.target, 'a'); - if (target) { + if (false === target) { + return; + } - // Detect empty href attributes - // The browser will make href="" or href="#top" - // into absolute urls when accessed as event.targed.href, so check the html - if (!/href=["']\S+["']/.test(target.outerHTML) || /href=["']#\S+["']/.test(target.outerHTML)) { - return true; - } + // Detect empty href attributes + // The browser will make href="" or href="#top" + // into absolute urls when accessed as event.targed.href, so check the html + if (!/href=["']\S+["']/.test(target.outerHTML) || /href=["']#\S+["']/.test(target.outerHTML)) { + return true; + } - // only show when hovering on anchors - if (this.base.toolbar && this.base.toolbar.isDisplayed()) { - // only show when toolbar is not present - return true; - } + // only show when hovering on anchors + if (this.base.toolbar && this.base.toolbar.isDisplayed()) { + // only show when toolbar is not present + return true; + } - // detach handler for other anchor in case we hovered multiple anchors quickly - if (this.activeAnchor && this.activeAnchor !== target) { - this.detachPreviewHandlers(); - } + // detach handler for other anchor in case we hovered multiple anchors quickly + if (this.activeAnchor && this.activeAnchor !== target) { + this.detachPreviewHandlers(); + } - this.anchorToPreview = target; + this.anchorToPreview = target; - this.instanceHandleAnchorMouseout = this.handleAnchorMouseout.bind(this); - this.base.on(this.anchorToPreview, 'mouseout', this.instanceHandleAnchorMouseout); - // Using setTimeout + delay because: - // - We're going to show the anchor preview according to the configured delay - // if the mouse has not left the anchor tag in that time - this.base.delay(function () { - if (this.anchorToPreview) { - //this.activeAnchor = this.anchorToPreview; - this.showPreview(this.anchorToPreview); - } - }.bind(this)); - } + this.instanceHandleAnchorMouseout = this.handleAnchorMouseout.bind(this); + this.on(this.anchorToPreview, 'mouseout', this.instanceHandleAnchorMouseout); + // Using setTimeout + delay because: + // - We're going to show the anchor preview according to the configured delay + // if the mouse has not left the anchor tag in that time + this.base.delay(function () { + if (this.anchorToPreview) { + //this.activeAnchor = this.anchorToPreview; + this.showPreview(this.anchorToPreview); + } + }.bind(this)); }, handlePreviewMouseover: function () { @@ -3828,11 +3922,11 @@ var AnchorPreview; // cleanup clearInterval(this.intervalTimer); if (this.instanceHandlePreviewMouseover) { - this.base.off(this.anchorPreview, 'mouseover', this.instanceHandlePreviewMouseover); - this.base.off(this.anchorPreview, 'mouseout', this.instanceHandlePreviewMouseout); + this.off(this.anchorPreview, 'mouseover', this.instanceHandlePreviewMouseover); + this.off(this.anchorPreview, 'mouseout', this.instanceHandlePreviewMouseout); if (this.activeAnchor) { - this.base.off(this.activeAnchor, 'mouseover', this.instanceHandlePreviewMouseover); - this.base.off(this.activeAnchor, 'mouseout', this.instanceHandlePreviewMouseout); + this.off(this.activeAnchor, 'mouseover', this.instanceHandlePreviewMouseover); + this.off(this.activeAnchor, 'mouseout', this.instanceHandlePreviewMouseout); } } @@ -3851,10 +3945,10 @@ var AnchorPreview; this.intervalTimer = setInterval(this.updatePreview.bind(this), 200); - this.base.on(this.anchorPreview, 'mouseover', this.instanceHandlePreviewMouseover); - this.base.on(this.anchorPreview, 'mouseout', this.instanceHandlePreviewMouseout); - this.base.on(this.activeAnchor, 'mouseover', this.instanceHandlePreviewMouseover); - this.base.on(this.activeAnchor, 'mouseout', this.instanceHandlePreviewMouseout); + this.on(this.anchorPreview, 'mouseover', this.instanceHandlePreviewMouseover); + this.on(this.anchorPreview, 'mouseout', this.instanceHandlePreviewMouseout); + this.on(this.activeAnchor, 'mouseover', this.instanceHandlePreviewMouseover); + this.on(this.activeAnchor, 'mouseout', this.instanceHandlePreviewMouseout); } }); }()); @@ -3888,15 +3982,21 @@ LINK_REGEXP_TEXT = } AutoLink = Extension.extend({ - init: function () { this.disableEventHandling = false; - this.base.subscribe('editableKeypress', this.onKeypress.bind(this)); - this.base.subscribe('editableBlur', this.onBlur.bind(this)); + this.subscribe('editableKeypress', this.onKeypress.bind(this)); + this.subscribe('editableBlur', this.onBlur.bind(this)); // MS IE has it's own auto-URL detect feature but ours is better in some ways. Be consistent. this.document.execCommand('AutoUrlDetect', false, false); }, + destroy: function () { + // Turn AutoUrlDetect back on + if (this.document.queryCommandSupported('AutoUrlDetect')) { + this.document.execCommand('AutoUrlDetect', false, true); + } + }, + onBlur: function (blurEvent, editable) { this.performLinking(editable); }, @@ -3906,9 +4006,7 @@ LINK_REGEXP_TEXT = return; } - if (keyPressEvent.keyCode === Util.keyCode.SPACE || - keyPressEvent.keyCode === Util.keyCode.ENTER || - keyPressEvent.which === Util.keyCode.SPACE) { + if (Util.isKey(keyPressEvent, [Util.keyCode.SPACE, Util.keyCode.ENTER])) { clearTimeout(this.performLinkingTimeout); // Saving/restoring the selection in the middle of a keypress doesn't work well... this.performLinkingTimeout = setTimeout(function () { @@ -4019,6 +4117,7 @@ LINK_REGEXP_TEXT = // If the regexp detected a bare domain that doesn't use one of our expected TLDs, bail out. matchOk = matchOk && (match[0].indexOf('/') !== -1 || KNOWN_TLDS_REGEXP.test(match[0].split('.').pop().split('?').shift())); + if (matchOk) { matches.push({ href: match[0], @@ -4031,8 +4130,7 @@ LINK_REGEXP_TEXT = }, findOrCreateMatchingTextNodes: function (element, match) { - var treeWalker = this.document.createTreeWalker(element, NodeFilter.SHOW_TEXT, - null, false), + var treeWalker = this.document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null, false), matchedNodes = [], currentTextIndex = 0, startReached = false, @@ -4100,10 +4198,9 @@ var ImageDragging; 'use strict'; ImageDragging = Extension.extend({ - init: function () { - this.base.subscribe('editableDrag', this.handleDrag.bind(this)); - this.base.subscribe('editableDrop', this.handleDrop.bind(this)); + this.subscribe('editableDrag', this.handleDrag.bind(this)); + this.subscribe('editableDrop', this.handleDrop.bind(this)); }, handleDrag: function (event) { @@ -4151,14 +4248,13 @@ var ImageDragging; event.target.classList.remove(className); } }); - }()); var FontSizeForm; (function () { 'use strict'; - /*global FormExtension, Selection */ + /*global FormExtension, Selection, Util */ FontSizeForm = FormExtension.extend({ @@ -4213,8 +4309,8 @@ var FontSizeForm; input.focus(); }, - // Called by core when tearing down medium-editor (deactivate) - deactivate: function () { + // Called by core when tearing down medium-editor (destroy) + destroy: function () { if (!this.form) { return false; } @@ -4226,6 +4322,11 @@ var FontSizeForm; delete this.form; }, + // TODO: deprecate + deactivate: function () { + Util.deprecatedMethod.call(this, 'deactivate', 'destroy', arguments, 'v5.0.0'); + }, + // core methods doFormSave: function () { @@ -4240,7 +4341,6 @@ var FontSizeForm; }, // form creation and event handling - createForm: function () { var doc = this.document, form = doc.createElement('div'), @@ -4250,10 +4350,10 @@ var FontSizeForm; // Font Size Form (div) form.className = 'medium-editor-toolbar-form'; - form.id = 'medium-editor-toolbar-form-fontsize-' + this.base.id; + form.id = 'medium-editor-toolbar-form-fontsize-' + this.getEditorId(); // Handle clicks on the form itself - this.base.on(form, 'click', this.handleFormClick.bind(this)); + this.on(form, 'click', this.handleFormClick.bind(this)); // Add font size slider input.setAttribute('type', 'range'); @@ -4263,29 +4363,29 @@ var FontSizeForm; form.appendChild(input); // Handle typing in the textbox - this.base.on(input, 'change', this.handleSliderChange.bind(this)); + this.on(input, 'change', this.handleSliderChange.bind(this)); // Add save buton save.setAttribute('href', '#'); save.className = 'medium-editor-toobar-save'; - save.innerHTML = this.base.options.buttonLabels === 'fontawesome' ? + save.innerHTML = this.getEditorOption('buttonLabels') === 'fontawesome' ? '' : '✓'; form.appendChild(save); // Handle save button clicks (capture) - this.base.on(save, 'click', this.handleSaveClick.bind(this), true); + this.on(save, 'click', this.handleSaveClick.bind(this), true); // Add close button close.setAttribute('href', '#'); close.className = 'medium-editor-toobar-close'; - close.innerHTML = this.base.options.buttonLabels === 'fontawesome' ? + close.innerHTML = this.getEditorOption('buttonLabels') === 'fontawesome' ? '' : '×'; form.appendChild(close); // Handle close button clicks - this.base.on(close, 'click', this.handleCloseClick.bind(this)); + this.on(close, 'click', this.handleCloseClick.bind(this)); return form; }, @@ -4307,7 +4407,7 @@ var FontSizeForm; if (size === '4') { this.clearFontSize(); } else { - this.base.execAction('fontSize', { size: size }); + this.execAction('fontSize', { size: size }); } }, @@ -4378,7 +4478,6 @@ var PasteHandler; /*jslint regexp: false*/ PasteHandler = Extension.extend({ - /* Paste Options */ /* forcePlainText: [boolean] @@ -4410,14 +4509,12 @@ var PasteHandler; cleanTags: ['meta'], /* ----- internal options needed from base ----- */ - 'window': window, - 'document': document, - targetBlank: false, - disableReturn: false, + targetBlank: false, // deprecated (should use .getEditorOption() instead) + disableReturn: false, // deprecated (should use .getEditorOption() instead) init: function () { if (this.forcePlainText || this.cleanPastedHTML) { - this.base.subscribe('editablePaste', this.handlePaste.bind(this)); + this.subscribe('editablePaste', this.handlePaste.bind(this)); } }, @@ -4482,43 +4579,38 @@ var PasteHandler; text = text.replace(replacements[i][0], replacements[i][1]); } - if (multiline) { - // double br's aren't converted to p tags, but we want paragraphs. - elList = text.split('

'); + if (!multiline) { + return this.pasteHTML(text); + } - this.pasteHTML('

' + elList.join('

') + '

'); + // double br's aren't converted to p tags, but we want paragraphs. + elList = text.split('

'); - try { - this.document.execCommand('insertText', false, '\n'); - } catch (ignore) { } - - // block element cleanup - elList = el.querySelectorAll('a,p,div,br'); - for (i = 0; i < elList.length; i += 1) { - workEl = elList[i]; - - // Microsoft Word replaces some spaces with newlines. - // While newlines between block elements are meaningless, newlines within - // elements are sometimes actually spaces. - workEl.innerHTML = workEl.innerHTML.replace(/\n/gi, ' '); - - switch (workEl.tagName.toLowerCase()) { - case 'a': - if (this.targetBlank) { - Util.setTargetBlank(workEl); - } - break; - case 'p': - case 'div': - this.filterCommonBlocks(workEl); - break; - case 'br': - this.filterLineBreak(workEl); - break; - } + this.pasteHTML('

' + elList.join('

') + '

'); + + try { + this.document.execCommand('insertText', false, '\n'); + } catch (ignore) { } + + // block element cleanup + elList = el.querySelectorAll('a,p,div,br'); + for (i = 0; i < elList.length; i += 1) { + workEl = elList[i]; + + // Microsoft Word replaces some spaces with newlines. + // While newlines between block elements are meaningless, newlines within + // elements are sometimes actually spaces. + workEl.innerHTML = workEl.innerHTML.replace(/\n/gi, ' '); + + switch (workEl.tagName.toLowerCase()) { + case 'p': + case 'div': + this.filterCommonBlocks(workEl); + break; + case 'br': + this.filterLineBreak(workEl); + break; } - } else { - this.pasteHTML(text); } }, @@ -4541,6 +4633,11 @@ var PasteHandler; for (i = 0; i < elList.length; i += 1) { workEl = elList[i]; + + if ('a' === workEl.tagName.toLowerCase() && this.targetBlank) { + Util.setTargetBlank(workEl); + } + Util.cleanupAttrs(workEl, options.cleanAttrs); Util.cleanupTags(workEl, options.cleanTags); } @@ -4559,7 +4656,6 @@ var PasteHandler; }, filterLineBreak: function (el) { - if (this.isCommonBlock(el.previousElementSibling)) { // remove stray br's following common block elements this.removeWithParent(el); @@ -4619,7 +4715,6 @@ var PasteHandler; } } }); - }()); var Placeholder; @@ -4650,7 +4745,7 @@ var Placeholder; }, initPlaceholders: function () { - this.base.elements.forEach(function (el) { + this.getEditorElements().forEach(function (el) { if (!el.getAttribute('data-placeholder')) { el.setAttribute('data-placeholder', this.text); } @@ -4658,6 +4753,14 @@ var Placeholder; }, this); }, + destroy: function () { + this.getEditorElements().forEach(function (el) { + if (el.getAttribute('data-placeholder') === this.text) { + el.removeAttribute('data-placeholder'); + } + }, this); + }, + showPlaceholder: function (el) { if (el) { el.classList.add('medium-editor-placeholder'); @@ -4673,29 +4776,29 @@ var Placeholder; updatePlaceholder: function (el) { // if one of these element ('img, blockquote, ul, ol') are found inside the given element, we won't display the placeholder if (!(el.querySelector('img, blockquote, ul, ol')) && el.textContent.replace(/^\s+|\s+$/g, '') === '') { - this.showPlaceholder(el); - } else { - this.hidePlaceholder(el); + return this.showPlaceholder(el); } + + this.hidePlaceholder(el); }, attachEventHandlers: function () { // Custom events - this.base.subscribe('blur', this.handleExternalInteraction.bind(this)); + this.subscribe('blur', this.handleExternalInteraction.bind(this)); // Check placeholder on blur - this.base.subscribe('editableBlur', this.handleBlur.bind(this)); + this.subscribe('editableBlur', this.handleBlur.bind(this)); // if we don't want the placeholder to be removed on click but when user start typing if (this.hideOnClick) { - this.base.subscribe('editableClick', this.handleHidePlaceholderEvent.bind(this)); + this.subscribe('editableClick', this.handleHidePlaceholderEvent.bind(this)); } else { - this.base.subscribe('editableKeyup', this.handleBlur.bind(this)); + this.subscribe('editableKeyup', this.handleBlur.bind(this)); } // Events where we always hide the placeholder - this.base.subscribe('editableKeypress', this.handleHidePlaceholderEvent.bind(this)); - this.base.subscribe('editablePaste', this.handleHidePlaceholderEvent.bind(this)); + this.subscribe('editableKeypress', this.handleHidePlaceholderEvent.bind(this)); + this.subscribe('editablePaste', this.handleHidePlaceholderEvent.bind(this)); }, handleHidePlaceholderEvent: function (event, element) { @@ -4720,7 +4823,7 @@ var Toolbar; (function () { 'use strict'; - Toolbar = function Toolbar(instance) { + Toolbar = function (instance) { this.base = instance; this.options = instance.options; @@ -4728,7 +4831,6 @@ var Toolbar; }; Toolbar.prototype = { - // Toolbar creation/deletion createToolbar: function () { @@ -4791,7 +4893,7 @@ var Toolbar; return ul; }, - deactivate: function () { + destroy: function () { if (this.toolbar) { if (this.toolbar.parentNode) { this.toolbar.parentNode.removeChild(this.toolbar); @@ -4800,6 +4902,11 @@ var Toolbar; } }, + // TODO: deprecate + deactivate: function () { + Util.deprecatedMethod.call(this, 'deactivate', 'destroy', arguments, 'v5.0.0'); + }, + // Toolbar accessors getToolbarElement: function () { @@ -4828,7 +4935,6 @@ var Toolbar; }, attachEventHandlers: function () { - // MediumEditor custom events for when user beings and ends interaction with a contenteditable and its elements this.base.subscribe('blur', this.handleBlur.bind(this)); this.base.subscribe('focus', this.handleFocus.bind(this)); @@ -5021,44 +5127,41 @@ var Toolbar; }, checkState: function () { + if (this.base.preventSelectionUpdates) { + return; + } - if (!this.base.preventSelectionUpdates) { - - // If no editable has focus OR selection is inside contenteditable = false - // hide toolbar - if (!this.base.getFocusedElement() || - Selection.selectionInContentEditableFalse(this.options.contentWindow)) { - this.hideToolbar(); - return; - } + // If no editable has focus OR selection is inside contenteditable = false + // hide toolbar + if (!this.base.getFocusedElement() || + Selection.selectionInContentEditableFalse(this.options.contentWindow)) { + return this.hideToolbar(); + } - // If there's no selection element, selection element doesn't belong to this editor - // or toolbar is disabled for this selection element - // hide toolbar - var selectionElement = Selection.getSelectionElement(this.options.contentWindow); - if (!selectionElement || - this.base.elements.indexOf(selectionElement) === -1 || - selectionElement.getAttribute('data-disable-toolbar')) { - this.hideToolbar(); - return; - } + // If there's no selection element, selection element doesn't belong to this editor + // or toolbar is disabled for this selection element + // hide toolbar + var selectionElement = Selection.getSelectionElement(this.options.contentWindow); + if (!selectionElement || + this.base.elements.indexOf(selectionElement) === -1 || + selectionElement.getAttribute('data-disable-toolbar')) { + return this.hideToolbar(); + } - // Now we know there's a focused editable with a selection + // Now we know there's a focused editable with a selection - // If the updateOnEmptySelection option is true, show the toolbar - if (this.options.updateOnEmptySelection && this.options.staticToolbar) { - this.showAndUpdateToolbar(); - return; - } + // If the updateOnEmptySelection option is true, show the toolbar + if (this.options.updateOnEmptySelection && this.options.staticToolbar) { + return this.showAndUpdateToolbar(); + } - // If we don't have a 'valid' selection -> hide toolbar - if (this.options.contentWindow.getSelection().toString().trim() === '' || - (this.options.allowMultiParagraphSelection === false && this.multipleBlockElementsSelected())) { - this.hideToolbar(); - } else { - this.showAndUpdateToolbar(); - } + // If we don't have a 'valid' selection -> hide toolbar + if (this.options.contentWindow.getSelection().toString().trim() === '' || + (this.options.allowMultiParagraphSelection === false && this.multipleBlockElementsSelected())) { + return this.hideToolbar(); } + + this.showAndUpdateToolbar(); }, // leaving here backward compatibility / statics @@ -5071,6 +5174,7 @@ var Toolbar; showAndUpdateToolbar: function () { this.modifySelection(); this.setToolbarButtonStates(); + this.base.trigger('positionToolbar', {}, this.base.getFocusedElement()); this.showToolbarDefaultActions(); this.setToolbarPosition(); }, @@ -5082,13 +5186,14 @@ var Toolbar; extension.setInactive(); } }.bind(this)); + this.checkActiveButtons(); }, checkActiveButtons: function () { var manualStateChecks = [], queryState = null, - selectionRange = Util.getSelectionRange(this.options.ownerDocument), + selectionRange = Selection.getSelectionRange(this.options.ownerDocument), parentNode, updateExtensionState = function (extension) { if (typeof extension.checkState === 'function') { @@ -5159,7 +5264,6 @@ var Toolbar; if (this.options.staticToolbar) { this.showToolbar(); this.positionStaticToolbar(container); - } else if (!selection.isCollapsed) { this.showToolbar(); this.positionToolbar(selection); @@ -5208,12 +5312,18 @@ var Toolbar; toolbarElement.style.top = containerTop - toolbarHeight + 'px'; } - if (this.options.toolbarAlign === 'left') { - targetLeft = containerRect.left; - } else if (this.options.toolbarAlign === 'center') { - targetLeft = containerCenter - halfOffsetWidth; - } else if (this.options.toolbarAlign === 'right') { - targetLeft = containerRect.right - toolbarWidth; + switch (this.options.toolbarAlign) { + case 'left': + targetLeft = containerRect.left; + break; + + case 'right': + targetLeft = containerRect.right - toolbarWidth; + break; + + case 'center': + targetLeft = containerCenter - halfOffsetWidth; + break; } if (targetLeft < 0) { @@ -5249,6 +5359,7 @@ var Toolbar; toolbarElement.classList.remove('medium-toolbar-arrow-over'); toolbarElement.style.top = boundary.top + this.options.diffTop + this.options.contentWindow.pageYOffset - toolbarHeight + 'px'; } + if (middleBoundary < halfOffsetWidth) { toolbarElement.style.left = defaultLeft + halfOffsetWidth + 'px'; } else if ((windowWidth - middleBoundary) < halfOffsetWidth) { @@ -5292,7 +5403,7 @@ function MediumEditor(elements, options) { if (this.options.disableReturn || element.getAttribute('data-disable-return')) { event.preventDefault(); } else if (this.options.disableDoubleReturn || element.getAttribute('data-disable-double-return')) { - var node = Util.getSelectionStart(this.options.ownerDocument); + var node = Selection.getSelectionStart(this.options.ownerDocument); // if current text selection is empty OR previous sibling text is empty if ((node && node.textContent.trim() === '') || @@ -5304,7 +5415,7 @@ function MediumEditor(elements, options) { function handleTabKeydown(event) { // Override tab only for pre nodes - var node = Util.getSelectionStart(this.options.ownerDocument), + var node = Selection.getSelectionStart(this.options.ownerDocument), tag = node && node.tagName.toLowerCase(); if (tag === 'pre') { @@ -5326,25 +5437,25 @@ function MediumEditor(elements, options) { } function handleBlockDeleteKeydowns(event) { - var p, node = Util.getSelectionStart(this.options.ownerDocument), + var p, node = Selection.getSelectionStart(this.options.ownerDocument), tagName = node.tagName.toLowerCase(), isEmpty = /^(\s+|)?$/i, isHeader = /h\d/i; - if ((event.which === Util.keyCode.BACKSPACE || event.which === Util.keyCode.ENTER) && + if (Util.isKey(event, [Util.keyCode.BACKSPACE, Util.keyCode.ENTER]) && // has a preceeding sibling node.previousElementSibling && // in a header isHeader.test(tagName) && // at the very end of the block Selection.getCaretOffsets(node).left === 0) { - if (event.which === Util.keyCode.BACKSPACE && isEmpty.test(node.previousElementSibling.innerHTML)) { + if (Util.isKey(event, Util.keyCode.BACKSPACE) && isEmpty.test(node.previousElementSibling.innerHTML)) { // backspacing the begining of a header into an empty previous element will // change the tagName of the current node to prevent one // instead delete previous node and cancel the event. node.previousElementSibling.parentNode.removeChild(node.previousElementSibling); event.preventDefault(); - } else if (event.which === Util.keyCode.ENTER) { + } else if (Util.isKey(event, Util.keyCode.ENTER)) { // hitting return in the begining of a header will create empty header elements before the current one // instead, make "


" element, which are what happens if you hit return in an empty paragraph p = this.options.ownerDocument.createElement('p'); @@ -5352,7 +5463,7 @@ function MediumEditor(elements, options) { node.previousElementSibling.parentNode.insertBefore(p, node); event.preventDefault(); } - } else if (event.which === Util.keyCode.DELETE && + } else if (Util.isKey(event, Util.keyCode.DELETE) && // between two sibling elements node.nextElementSibling && node.previousElementSibling && @@ -5373,7 +5484,7 @@ function MediumEditor(elements, options) { node.previousElementSibling.parentNode.removeChild(node); event.preventDefault(); - } else if (event.which === Util.keyCode.BACKSPACE && + } else if (Util.isKey(event, Util.keyCode.BACKSPACE) && tagName === 'li' && // hitting backspace inside an empty li isEmpty.test(node.innerHTML) && @@ -5408,7 +5519,7 @@ function MediumEditor(elements, options) { } function handleKeyup(event) { - var node = Util.getSelectionStart(this.options.ownerDocument), + var node = Selection.getSelectionStart(this.options.ownerDocument), tagName; if (!node) { @@ -5419,7 +5530,7 @@ function MediumEditor(elements, options) { this.options.ownerDocument.execCommand('formatBlock', false, 'p'); } - if (event.which === Util.keyCode.ENTER && !Util.isListItem(node)) { + if (Util.isKey(event, Util.keyCode.ENTER) && !Util.isListItem(node)) { tagName = node.tagName.toLowerCase(); // For anchor tags, unlink if (tagName === 'a') { @@ -5679,9 +5790,9 @@ function MediumEditor(elements, options) { // Backwards compatability var defaultsBC = { hideDelay: this.options.anchorPreviewHideDelay, // deprecated - diffLeft: this.options.diffLeft, - diffTop: this.options.diffTop, - elementsContainer: this.options.elementsContainer + diffLeft: this.options.diffLeft, // deprecated (should use .getEditorOption() instead) + diffTop: this.options.diffTop, // deprecated (should use .getEditorOption() instead) + elementsContainer: this.options.elementsContainer // deprecated (should use .getEditorOption() instead) }; return new MediumEditor.extensions.anchorPreview( @@ -5709,8 +5820,8 @@ function MediumEditor(elements, options) { var defaultsBC = { forcePlainText: this.options.forcePlainText, // deprecated cleanPastedHTML: this.options.cleanPastedHTML, // deprecated - disableReturn: this.options.disableReturn, - targetBlank: this.options.targetBlank + disableReturn: this.options.disableReturn, // deprecated (should use .getEditorOption() instead) + targetBlank: this.options.targetBlank // deprecated (should use .getEditorOption() instead) }; return new MediumEditor.extensions.paste( @@ -5725,13 +5836,6 @@ function MediumEditor(elements, options) { name; this.commands = []; - // add toolbar custom events to the list of known events by the editor - // we need to have this for the initialization of extensions - // initToolbar is called after initCommands - // add toolbar custom events to the list of known events by the editor - this.createEvent('showToolbar'); - this.createEvent('hideToolbar'); - buttons.forEach(function (buttonName) { if (extensions[buttonName]) { ext = initExtension(extensions[buttonName], buttonName, this); @@ -5807,6 +5911,7 @@ function MediumEditor(elements, options) { Util.deprecated('placeholder', 'placeholder.text', 'v5.0.0'); } } + return Util.defaults({}, options, defaults); } @@ -5855,7 +5960,6 @@ function MediumEditor(elements, options) { MediumEditor.selection = Selection; MediumEditor.prototype = { - defaults: editorDefaults, // NOT DOCUMENTED - exposed for backwards compatability @@ -5905,12 +6009,26 @@ function MediumEditor(elements, options) { this.isActive = false; + this.commands.forEach(function (extension) { + if (typeof extension.destroy === 'function') { + extension.destroy(); + } else if (typeof extension.deactivate === 'function') { + Util.warn('Extension .deactivate() function has been deprecated. Use .destroy() instead. This will be removed in version 5.0.0'); + extension.deactivate(); + } + }, this); + if (this.toolbar !== undefined) { - this.toolbar.deactivate(); + this.toolbar.destroy(); delete this.toolbar; } this.elements.forEach(function (element) { + // Reset elements content, fix for issue where after editor destroyed the red underlines on spelling errors are left + if (this.options.spellcheck) { + element.innerHTML = element.innerHTML; + } + element.removeAttribute('contentEditable'); element.removeAttribute('spellcheck'); element.removeAttribute('data-medium-element'); @@ -5929,12 +6047,6 @@ function MediumEditor(elements, options) { }, this); this.elements = []; - this.commands.forEach(function (extension) { - if (typeof extension.deactivate === 'function') { - extension.deactivate(); - } - }, this); - this.events.destroy(); }, @@ -5954,8 +6066,9 @@ function MediumEditor(elements, options) { this.events.detachCustomEvent(event, listener); }, - createEvent: function (event) { - this.events.defineCustomEvent(event); + createEvent: function () { + Util.warn('.createEvent() has been deprecated and is no longer needed. ' + + 'You can attach and trigger custom events without calling this method. This will be removed in v5.0.0'); }, trigger: function (name, data, editable) { @@ -6284,11 +6397,11 @@ function MediumEditor(elements, options) { this.options.ownerDocument.execCommand('createLink', false, opts.url); if (this.options.targetBlank || opts.target === '_blank') { - Util.setTargetBlank(Util.getSelectionStart(this.options.ownerDocument), opts.url); + Util.setTargetBlank(Selection.getSelectionStart(this.options.ownerDocument), opts.url); } if (opts.buttonClass) { - Util.addClassToAnchors(Util.getSelectionStart(this.options.ownerDocument), opts.buttonClass); + Util.addClassToAnchors(Selection.getSelectionStart(this.options.ownerDocument), opts.buttonClass); } } @@ -6332,7 +6445,7 @@ MediumEditor.version = (function (major, minor, revision) { }; }).apply(this, ({ // grunt-bump looks for this: - 'version': '4.11.1' + 'version': '4.12.0' }).version.split('.')); return MediumEditor; diff --git a/dist/js/medium-editor.min.js b/dist/js/medium-editor.min.js index 8e3569767..2c6f55bb7 100644 --- a/dist/js/medium-editor.min.js +++ b/dist/js/medium-editor.min.js @@ -1,3 +1,5 @@ -"classList"in document.createElement("_")||!function(a){"use strict";if("Element"in a){var b="classList",c="prototype",d=a.Element[c],e=Object,f=String[c].trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=Array[c].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a,this.code=DOMException[a],this.message=b},i=function(a,b){if(""===b)throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return g.call(a,b)},j=function(a){for(var b=f.call(a.getAttribute("class")||""),c=b?b.split(/\s+/):[],d=0,e=c.length;e>d;d++)this.push(c[d]);this._updateClassName=function(){a.setAttribute("class",this.toString())}},k=j[c]=[],l=function(){return new j(this)};if(h[c]=Error[c],k.item=function(a){return this[a]||null},k.contains=function(a){return a+="",-1!==i(this,a)},k.add=function(){var a,b=arguments,c=0,d=b.length,e=!1;do a=b[c]+"",-1===i(this,a)&&(this.push(a),e=!0);while(++ci;i++)e+=String.fromCharCode(f[i]);c.push(e)}else if("Blob"===b(a)||"File"===b(a)){if(!g)throw new h("NOT_READABLE_ERR");var k=new g;c.push(k.readAsBinaryString(a))}else a instanceof d?"base64"===a.encoding&&p?c.push(p(a.data)):"URI"===a.encoding?c.push(decodeURIComponent(a.data)):"raw"===a.encoding&&c.push(a.data):("string"!=typeof a&&(a+=""),c.push(unescape(encodeURIComponent(a))))},e.getBlob=function(a){return arguments.length||(a=null),new d(this.data.join(""),a,"raw")},e.toString=function(){return"[object BlobBuilder]"},f.slice=function(a,b,c){var e=arguments.length;return 3>e&&(c=null),new d(this.data.slice(a,e>1?b:this.data.length),c,this.encoding)},f.toString=function(){return"[object Blob]"},f.close=function(){this.size=0,delete this.data},c}(a);a.Blob=function(a,b){var d=b?b.type||"":"",e=new c;if(a)for(var f=0,g=a.length;g>f;f++)e.append(Uint8Array&&a[f]instanceof Uint8Array?a[f].buffer:a[f]);var h=e.getBlob(d);return!h.slice&&h.webkitSlice&&(h.slice=h.webkitSlice),h};var d=Object.getPrototypeOf||function(a){return a.__proto__};a.Blob.prototype=d(new a.Blob)}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content||this),function(a,b){"use strict";"object"==typeof module?module.exports=b:"function"==typeof define&&define.amd?define(function(){return b}):a.MediumEditor=b}(this,function(){"use strict";function a(a,b){return this.init(a,b)}var b;!function(a){function c(b,c,d){d||(d=a);try{for(var e=0;e=0,keyCode:{BACKSPACE:8,TAB:9,ENTER:13,ESCAPE:27,SPACE:32,DELETE:46},isMetaCtrlKey:function(a){return this.isMac&&a.metaKey||!this.isMac&&a.ctrlKey?!0:!1},parentElements:["p","h1","h2","h3","h4","h5","h6","blockquote","pre"],extend:function(){var a=[!0].concat(Array.prototype.slice.call(arguments));return d.apply(this,a)},defaults:function(){var a=[!1].concat(Array.prototype.slice.call(arguments));return d.apply(this,a)},derives:function(a,b){function c(){}var e=b.prototype;return c.prototype=a.prototype,b.prototype=new c,b.prototype.constructor=a,b.prototype=d(!1,b.prototype,e),b},findAdjacentTextNodeWithContent:function(a,b,c){var d,e=!1,f=c.createNodeIterator(a,NodeFilter.SHOW_TEXT,null,!1);for(d=f.nextNode();d;){if(d===b)e=!0;else if(e&&3===d.nodeType&&d.nodeValue&&d.nodeValue.trim().length>0)break;d=f.nextNode()}return d},isDescendant:function(a,b,c){if(!a||!b)return!1;if(c&&a===b)return!0;for(var d=b.parentNode;null!==d;){if(d===a)return!0;d=d.parentNode}return!1},isElement:function(a){return!(!a||1!==a.nodeType)},now:Date.now,throttle:function(a,b){var c,d,e,f=50,g=null,h=0,i=function(){h=Date.now(),g=null,e=a.apply(c,d),g||(c=d=null)};return b||0===b||(b=f),function(){var f=Date.now(),j=b-(f-h);return c=this,d=arguments,0>=j||j>b?(g&&(clearTimeout(g),g=null),h=f,e=a.apply(c,d),g||(c=d=null)):g||(g=setTimeout(i,j)),e}},traverseUp:function(a,b){if(!a)return!1;do{if(1===a.nodeType){if(b(a))return a;if(a.getAttribute("data-medium-element"))return!1}a=a.parentNode}while(a);return!1},htmlEntities:function(a){return String(a).replace(/&/g,"&").replace(//g,">").replace(/"/g,""")},insertHTMLCommand:function(a,b){var c,d,e,f,g,h,i;if(a.queryCommandSupported("insertHTML"))try{return a.execCommand("insertHTML",!1,b)}catch(j){}if(c=a.defaultView.getSelection(),c.getRangeAt&&c.rangeCount){if(d=c.getRangeAt(0),i=d.commonAncestorContainer,3===i.nodeType&&i.nodeValue===d.toString()||3!==i.nodeType&&i.innerHTML===d.toString()){for(;i.parentNode&&1===i.parentNode.childNodes.length&&!i.parentNode.getAttribute("data-medium-element");)i=i.parentNode;d.selectNode(i)}for(d.deleteContents(),e=a.createElement("div"),e.innerHTML=b,f=a.createDocumentFragment();e.firstChild;)g=e.firstChild,h=f.appendChild(g);d.insertNode(f),h&&(d=d.cloneRange(),d.setStartAfter(h),d.collapse(!0),c.removeAllRanges(),c.addRange(d))}},getSelectionRange:function(a){var b=a.getSelection();return 0===b.rangeCount?null:b.getRangeAt(0)},getSelectionStart:function(a){var b=a.getSelection().anchorNode,c=b&&3===b.nodeType?b.parentNode:b;return c},getSelectionData:function(a){var b;for(a&&a.tagName&&(b=a.tagName.toLowerCase());a&&-1===this.parentElements.indexOf(b);)a=a.parentNode,a&&a.tagName&&(b=a.tagName.toLowerCase());return{el:a,tagName:b}},execFormatBlock:function(a,b){var c=this.getSelectionData(this.getSelectionStart(a));if("blockquote"===b&&c.el&&"blockquote"===c.el.parentNode.tagName.toLowerCase())return a.execCommand("outdent",!1,null);if(c.tagName===b&&(b="p"),this.isIE){if("blockquote"===b)return a.execCommand("indent",!1,b);b="<"+b+">"}return a.execCommand("formatBlock",!1,b)},setTargetBlank:function(a,b){var c,d=b||!1;if("a"===a.tagName.toLowerCase())a.target="_blank";else for(a=a.getElementsByTagName("a"),c=0;cd?(e=e.parentNode,c-=1):(f=f.parentNode,d-=1);for(;e!==f;)e=e.parentNode,f=f.parentNode;return e},ensureUrlHasProtocol:function(a){return-1===a.indexOf("://")?"http://"+a:a},warn:function(){void 0!==a.console&&"function"==typeof a.console.warn&&a.console.warn.apply(console,arguments)},deprecated:function(a,c,d){var e=a+" is deprecated, please use "+c+" instead.";d&&(e+=" Will be removed in "+d),b.warn(e)},deprecatedMethod:function(a,c,d,e){b.deprecated(a,c,e),"function"==typeof this[c]&&this[c].apply(this,d)},cleanupAttrs:function(a,b){b.forEach(function(b){a.removeAttribute(b)})},cleanupTags:function(a,b){b.forEach(function(b){a.tagName.toLowerCase()===b&&a.parentNode.removeChild(a)},this)},getClosestTag:function(a,c){return b.traverseUp(a,function(a){return a.tagName.toLowerCase()===c.toLowerCase()})},unwrap:function(a,b){for(var c=b.createDocumentFragment(),d=Array.prototype.slice.call(a.childNodes),e=0;eB",contentFA:'',key:"b"},italic:{name:"italic",action:"italic",aria:"italic",tagNames:["i","em"],style:{prop:"font-style",value:"italic"},useQueryState:!0,contentDefault:"I",contentFA:'',key:"i"},underline:{name:"underline",action:"underline",aria:"underline",tagNames:["u"],style:{prop:"text-decoration",value:"underline"},useQueryState:!0,contentDefault:"U",contentFA:'',key:"u"},strikethrough:{name:"strikethrough",action:"strikethrough",aria:"strike through",tagNames:["strike"],style:{prop:"text-decoration",value:"line-through"},useQueryState:!0,contentDefault:"A",contentFA:''},superscript:{name:"superscript",action:"superscript",aria:"superscript",tagNames:["sup"],contentDefault:"x1",contentFA:''},subscript:{name:"subscript",action:"subscript",aria:"subscript",tagNames:["sub"],contentDefault:"x1",contentFA:''},image:{name:"image",action:"image",aria:"image",tagNames:["img"],contentDefault:"image",contentFA:''},quote:{name:"quote",action:"append-blockquote",aria:"blockquote",tagNames:["blockquote"],contentDefault:"",contentFA:''},orderedlist:{name:"orderedlist",action:"insertorderedlist",aria:"ordered list",tagNames:["ol"],useQueryState:!0,contentDefault:"1.",contentFA:''},unorderedlist:{name:"unorderedlist",action:"insertunorderedlist",aria:"unordered list",tagNames:["ul"],useQueryState:!0,contentDefault:"",contentFA:''},pre:{name:"pre",action:"append-pre",aria:"preformatted text",tagNames:["pre"],contentDefault:"0101",contentFA:''},indent:{name:"indent",action:"indent",aria:"indent",tagNames:[],contentDefault:"",contentFA:''},outdent:{name:"outdent",action:"outdent",aria:"outdent",tagNames:[],contentDefault:"",contentFA:''},justifyCenter:{name:"justifyCenter",action:"justifyCenter",aria:"center justify",tagNames:[],style:{prop:"text-align",value:"center"},contentDefault:"C",contentFA:''},justifyFull:{name:"justifyFull",action:"justifyFull",aria:"full justify",tagNames:[],style:{prop:"text-align",value:"justify"},contentDefault:"J",contentFA:''},justifyLeft:{name:"justifyLeft",action:"justifyLeft",aria:"left justify",tagNames:[],style:{prop:"text-align",value:"left"},contentDefault:"L",contentFA:''},justifyRight:{name:"justifyRight",action:"justifyRight",aria:"right justify",tagNames:[],style:{prop:"text-align",value:"right"},contentDefault:"R",contentFA:''},header1:{name:"header1",action:function(a){return"append-"+a.firstHeader},aria:function(a){return a.firstHeader},tagNames:function(a){return[a.firstHeader]},contentDefault:"H1"},header2:{name:"header2",action:function(a){return"append-"+a.secondHeader},aria:function(a){return a.secondHeader},tagNames:function(a){return[a.secondHeader]},contentDefault:"H2"},removeFormat:{name:"removeFormat",aria:"remove formatting",action:"removeFormat",contentDefault:"X",contentFA:''}}}();var d;!function(){d={allowMultiParagraphSelection:!0,buttons:["bold","italic","underline","anchor","header1","header2","quote"],buttonLabels:!1,delay:0,diffLeft:0,diffTop:-10,disableReturn:!1,disableDoubleReturn:!1,disableToolbar:!1,disableEditing:!1,autoLink:!1,toolbarAlign:"center",elementsContainer:!1,imageDragging:!0,standardizeSelectionStart:!1,contentWindow:window,ownerDocument:document,firstHeader:"h3",secondHeader:"h4",targetBlank:!1,extensions:{},activeButtonClass:"medium-editor-button-active",firstButtonClass:"medium-editor-button-first",lastButtonClass:"medium-editor-button-last",spellcheck:!0}}();var e;!function(){e=function(a){b.extend(this,a)},e.extend=function(a){var c,d=this;c=a&&a.hasOwnProperty("constructor")?a.constructor:function(){return d.apply(this,arguments)},b.extend(c,d);var e=function(){this.constructor=c};return e.prototype=d.prototype,c.prototype=new e,a&&b.extend(c.prototype,a),c},e.prototype={init:function(){},base:void 0,name:void 0,checkState:void 0,queryCommandState:void 0,isActive:void 0,isAlreadyApplied:void 0,setActive:void 0,setInactive:void 0,window:void 0,document:void 0}}();var f;!function(){f={findMatchingSelectionParent:function(a,c){var d,e,f=c.getSelection();return 0===f.rangeCount?!1:(d=f.getRangeAt(0),e=d.commonAncestorContainer,b.traverseUp(e,a))},getSelectionElement:function(a){return this.findMatchingSelectionParent(function(a){return a.getAttribute("data-medium-element")},a)},importSelectionMoveCursorPastAnchor:function(a,c){var d=function(a){return"a"===a.nodeName.toLowerCase()};if(a.start===a.end&&3===c.startContainer.nodeType&&c.startOffset===c.startContainer.nodeValue.length&&b.traverseUp(c.startContainer,d)){for(var e=c.startContainer,f=c.startContainer.parentNode;null!==f&&"a"!==f.nodeName.toLowerCase();)f.childNodes[f.childNodes.length-1]!==e?f=null:(e=f,f=f.parentNode);if(null!==f&&"a"===f.nodeName.toLowerCase()){for(var g=null,h=0;null===g&&ha;a+=1)c.appendChild(e.getRangeAt(a).cloneContents());d=c.innerHTML}return d},getCaretOffsets:function(a,b){var c,d;return b||(b=window.getSelection().getRangeAt(0)),c=b.cloneRange(),d=b.cloneRange(),c.selectNodeContents(a),c.setEnd(b.endContainer,b.endOffset),d.selectNodeContents(a),d.setStart(b.endContainer,b.endOffset),{left:c.toString().length,right:d.toString().length}},rangeSelectsSingleNode:function(a){var b=a.startContainer;return b===a.endContainer&&b.hasChildNodes()&&a.endOffset===a.startOffset+1},getSelectedParentElement:function(a){var b=null;return b=this.rangeSelectsSingleNode(a)&&3!==a.startContainer.childNodes[a.startOffset].nodeType?a.startContainer.childNodes[a.startOffset]:3===a.startContainer.nodeType?a.startContainer.parentNode:a.startContainer},getSelectedElements:function(a){var b,c,d,e=a.getSelection();if(!e.rangeCount||!e.getRangeAt(0).commonAncestorContainer)return[];if(b=e.getRangeAt(0),3===b.commonAncestorContainer.nodeType){for(c=[],d=b.commonAncestorContainer;d.parentNode&&1===d.parentNode.childNodes.length;)c.push(d.parentNode),d=d.parentNode;return c}return[].filter.call(b.commonAncestorContainer.getElementsByTagName("*"),function(a){return"function"==typeof e.containsNode?e.containsNode(a,!0):!0})},selectNode:function(a,b){var c=b.createRange(),d=b.getSelection();c.selectNodeContents(a),d.removeAllRanges(),d.addRange(c)},moveCursor:function(a,b,c){var d,e,f=c||0;d=a.createRange(),e=a.getSelection(),d.setStart(b,f),d.collapse(!0),e.removeAllRanges(),e.addRange(d)}}}();var g;!function(){g=function(a){this.base=a,this.options=this.base.options,this.events=[],this.customEvents={},this.listeners={}},g.prototype={InputEventOnContenteditableSupported:!b.isIE,attachDOMEvent:function(a,b,c,d){a.addEventListener(b,c,d),this.events.push([a,b,c,d])},detachDOMEvent:function(a,b,c,d){var e,f=this.indexOfListener(a,b,c,d);-1!==f&&(e=this.events.splice(f,1)[0],e[0].removeEventListener(e[1],e[2],e[3]))},indexOfListener:function(a,b,c,d){var e,f,g;for(e=0,f=this.events.length;f>e;e+=1)if(g=this.events[e],g[0]===a&&g[1]===b&&g[2]===c&&g[3]===d)return e;return-1},detachAllDOMEvents:function(){for(var a=this.events.pop();a;)a[0].removeEventListener(a[1],a[2],a[3]),a=this.events.pop()},attachCustomEvent:function(a,b){this.setupListener(a),this.listeners[a]&&(this.customEvents[a]||(this.customEvents[a]=[]),this.customEvents[a].push(b))},detachCustomEvent:function(a,b){var c=this.indexOfCustomListener(a,b);-1!==c&&this.customEvents[a].splice(c,1)},defineCustomEvent:function(a){this.listeners[a]=!0},indexOfCustomListener:function(a,b){return this.customEvents[a]&&this.customEvents[a].length?this.customEvents[a].indexOf(b):-1},detachAllCustomEvents:function(){this.customEvents={}},triggerCustomEvent:function(a,b,c){this.customEvents[a]&&this.customEvents[a].forEach(function(a){a(b,c)})},destroy:function(){this.detachAllDOMEvents(),this.detachAllCustomEvents(),this.detachExecCommand()},attachToExecCommand:function(){this.execCommandListener||(this.execCommandListener=function(a){this.handleDocumentExecCommand(a)}.bind(this),this.wrapExecCommand(),this.options.ownerDocument.execCommand.listeners.push(this.execCommandListener))},detachExecCommand:function(){var a=this.options.ownerDocument;if(this.execCommandListener&&a.execCommand.listeners){var b=a.execCommand.listeners.indexOf(this.execCommandListener);-1!==b&&a.execCommand.listeners.splice(b,1),a.execCommand.listeners.length||this.unwrapExecCommand()}},wrapExecCommand:function(){var a=this.options.ownerDocument;if(!a.execCommand.listeners){var b=function(b,c,d){var e=a.execCommand.orig.apply(this,arguments);if(a.execCommand.listeners){var f=Array.prototype.slice.call(arguments);a.execCommand.listeners.forEach(function(a){a({command:b,value:d,args:f,result:e})})}return e};b.orig=a.execCommand,b.listeners=[],a.execCommand=b}},unwrapExecCommand:function(){var a=this.options.ownerDocument;a.execCommand.orig&&(a.execCommand=a.execCommand.orig)},setupListener:function(a){if(!this.listeners[a])switch(a){case"externalInteraction":this.attachDOMEvent(this.options.ownerDocument.body,"mousedown",this.handleBodyMousedown.bind(this),!0),this.attachDOMEvent(this.options.ownerDocument.body,"click",this.handleBodyClick.bind(this),!0),this.attachDOMEvent(this.options.ownerDocument.body,"focus",this.handleBodyFocus.bind(this),!0),this.listeners[a]=!0;break;case"blur":this.setupListener("externalInteraction"),this.listeners[a]=!0;break;case"focus":this.setupListener("externalInteraction"),this.listeners[a]=!0;break;case"editableInput":this.contentCache=[],this.base.elements.forEach(function(a){this.contentCache[a.getAttribute("medium-editor-index")]=a.innerHTML,this.InputEventOnContenteditableSupported&&this.attachDOMEvent(a,"input",this.handleInput.bind(this))}.bind(this)),this.InputEventOnContenteditableSupported||(this.setupListener("editableKeypress"),this.keypressUpdateInput=!0,this.attachDOMEvent(document,"selectionchange",this.handleDocumentSelectionChange.bind(this)),this.attachToExecCommand()),this.listeners[a]=!0;break;case"editableClick":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"click",this.handleClick.bind(this))}.bind(this)),this.listeners[a]=!0;break;case"editableBlur":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"blur",this.handleBlur.bind(this))}.bind(this)),this.listeners[a]=!0;break;case"editableKeypress":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"keypress",this.handleKeypress.bind(this))}.bind(this)),this.listeners[a]=!0;break;case"editableKeyup":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"keyup",this.handleKeyup.bind(this))}.bind(this)),this.listeners[a]=!0;break;case"editableKeydown":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"keydown",this.handleKeydown.bind(this))}.bind(this)),this.listeners[a]=!0;break;case"editableKeydownEnter":this.setupListener("editableKeydown"),this.listeners[a]=!0;break;case"editableKeydownTab":this.setupListener("editableKeydown"),this.listeners[a]=!0;break;case"editableKeydownDelete":this.setupListener("editableKeydown"),this.listeners[a]=!0;break;case"editableMouseover":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"mouseover",this.handleMouseover.bind(this))},this),this.listeners[a]=!0;break;case"editableDrag":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"dragover",this.handleDragging.bind(this)),this.attachDOMEvent(a,"dragleave",this.handleDragging.bind(this))},this),this.listeners[a]=!0;break;case"editableDrop":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"drop",this.handleDrop.bind(this))},this),this.listeners[a]=!0;break;case"editablePaste":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"paste",this.handlePaste.bind(this))},this),this.listeners[a]=!0}},focusElement:function(a){a.focus(),this.updateFocus(a,{target:a,type:"focus"})},updateFocus:function(a,c){var d,e=this.base.toolbar?this.base.toolbar.getToolbarElement():null,f=this.base.getExtensionByName("anchor-preview"),g=f&&f.getPreviewElement?f.getPreviewElement():null,h=this.base.getFocusedElement();h&&"click"===c.type&&this.lastMousedownTarget&&(b.isDescendant(h,this.lastMousedownTarget,!0)||b.isDescendant(e,this.lastMousedownTarget,!0)||b.isDescendant(g,this.lastMousedownTarget,!0))&&(d=h),d||this.base.elements.some(function(c){return!d&&b.isDescendant(c,a,!0)&&(d=c),!!d},this);var i=!b.isDescendant(h,a,!0)&&!b.isDescendant(e,a,!0)&&!b.isDescendant(g,a,!0);d!==h&&(h&&i&&(h.removeAttribute("data-medium-focused"),this.triggerCustomEvent("blur",c,h)),d&&(d.setAttribute("data-medium-focused",!0),this.triggerCustomEvent("focus",c,d))),i&&this.triggerCustomEvent("externalInteraction",c)},updateInput:function(a,b){var c=a.getAttribute("medium-editor-index");a.innerHTML!==this.contentCache[c]&&this.triggerCustomEvent("editableInput",b,a),this.contentCache[c]=a.innerHTML},handleDocumentSelectionChange:function(a){if(a.currentTarget&&a.currentTarget.activeElement){var c,d=a.currentTarget.activeElement;this.base.elements.some(function(a){return b.isDescendant(a,d,!0)?(c=a,!0):!1},this),c&&this.updateInput(c,{target:d,currentTarget:c})}},handleDocumentExecCommand:function(){var a=this.base.getFocusedElement();a&&this.updateInput(a,{target:a,currentTarget:a})},handleBodyClick:function(a){this.updateFocus(a.target,a)},handleBodyFocus:function(a){this.updateFocus(a.target,a)},handleBodyMousedown:function(a){this.lastMousedownTarget=a.target},handleInput:function(a){this.updateInput(a.currentTarget,a)},handleClick:function(a){this.triggerCustomEvent("editableClick",a,a.currentTarget)},handleBlur:function(a){this.triggerCustomEvent("editableBlur",a,a.currentTarget)},handleKeypress:function(a){if(this.triggerCustomEvent("editableKeypress",a,a.currentTarget),this.keypressUpdateInput){var b={target:a.target,currentTarget:a.currentTarget};setTimeout(function(){this.updateInput(b.currentTarget,b)}.bind(this),0)}},handleKeyup:function(a){this.triggerCustomEvent("editableKeyup",a,a.currentTarget)},handleMouseover:function(a){this.triggerCustomEvent("editableMouseover",a,a.currentTarget)},handleDragging:function(a){this.triggerCustomEvent("editableDrag",a,a.currentTarget)},handleDrop:function(a){this.triggerCustomEvent("editableDrop",a,a.currentTarget)},handlePaste:function(a){this.triggerCustomEvent("editablePaste",a,a.currentTarget)},handleKeydown:function(a){switch(this.triggerCustomEvent("editableKeydown",a,a.currentTarget),a.which){case b.keyCode.ENTER:this.triggerCustomEvent("editableKeydownEnter",a,a.currentTarget);break;case b.keyCode.TAB:this.triggerCustomEvent("editableKeydownTab",a,a.currentTarget);break;case b.keyCode.DELETE:case b.keyCode.BACKSPACE:this.triggerCustomEvent("editableKeydownDelete",a,a.currentTarget)}}}}();var h;!function(){h=function(a,c){b.deprecated("MediumEditor.statics.DefaultButton","MediumEditor.extensions.button","v5.0.0"),this.options=a,this.name=a.name,this.init(c)},h.prototype={init:function(a){this.base=a,this.button=this.createButton(),this.base.on(this.button,"click",this.handleClick.bind(this)),this.options.key&&this.base.subscribe("editableKeydown",this.handleKeydown.bind(this))},getButton:function(){return this.button},getAction:function(){return"function"==typeof this.options.action?this.options.action(this.base.options):this.options.action},getAria:function(){return"function"==typeof this.options.aria?this.options.aria(this.base.options):this.options.aria},getTagNames:function(){return"function"==typeof this.options.tagNames?this.options.tagNames(this.base.options):this.options.tagNames},createButton:function(){var a=this.base.options.ownerDocument.createElement("button"),b=this.options.contentDefault,c=this.getAria();return a.classList.add("medium-editor-action"),a.classList.add("medium-editor-action-"+this.name),a.setAttribute("data-action",this.getAction()),c&&(a.setAttribute("title",c),a.setAttribute("aria-label",c)),this.base.options.buttonLabels&&("fontawesome"===this.base.options.buttonLabels&&this.options.contentFA?b=this.options.contentFA:"object"==typeof this.base.options.buttonLabels&&this.base.options.buttonLabels[this.name]&&(b=this.base.options.buttonLabels[this.options.name])),a.innerHTML=b,a},handleKeydown:function(a){var c,d=String.fromCharCode(a.which||a.keyCode).toLowerCase();this.options.key===d&&b.isMetaCtrlKey(a)&&(a.preventDefault(),a.stopPropagation(),c=this.getAction(),c&&this.base.execAction(c))},handleClick:function(a){a.preventDefault(),a.stopPropagation();var b=this.getAction();b&&this.base.execAction(b)},isActive:function(){return this.button.classList.contains(this.base.options.activeButtonClass)},setInactive:function(){this.button.classList.remove(this.base.options.activeButtonClass),delete this.knownState},setActive:function(){this.button.classList.add(this.base.options.activeButtonClass),delete this.knownState},queryCommandState:function(){var a=null;return this.options.useQueryState&&(a=this.base.queryCommandState(this.getAction())),a},isAlreadyApplied:function(a){var b,c,d=!1,e=this.getTagNames();return this.knownState===!1||this.knownState===!0?this.knownState:(e&&e.length>0&&a.tagName&&(d=-1!==e.indexOf(a.tagName.toLowerCase())),!d&&this.options.style&&(b=this.options.style.value.split("|"),c=this.base.options.contentWindow.getComputedStyle(a,null).getPropertyValue(this.options.style.prop),b.forEach(function(a){this.knownState||(d=-1!==c.indexOf(a),(d||"text-decoration"!==this.options.style.prop)&&(this.knownState=d))},this)),d)}}}();var i;!function(){function a(){b.deprecated("MediumEditor.statics.AnchorExtension","MediumEditor.extensions.anchor","v5.0.0"),this.parent=!0,this.options={name:"anchor",action:"createLink",aria:"link",tagNames:["a"],contentDefault:"#",contentFA:'',key:"k"},this.name="anchor",this.hasForm=!0}a.prototype={formSaveLabel:"✓",formCloseLabel:"×",handleClick:function(a){a.preventDefault(),a.stopPropagation();var c=f.getSelectedParentElement(b.getSelectionRange(this.base.options.ownerDocument));return c.tagName&&"a"===c.tagName.toLowerCase()?this.base.execAction("unlink"):(this.isDisplayed()||this.showForm(),!1)},handleKeydown:function(a){var c=String.fromCharCode(a.which||a.keyCode).toLowerCase();this.options.key===c&&b.isMetaCtrlKey(a)&&(a.preventDefault(),a.stopPropagation(),this.handleClick(a))},getForm:function(){return this.form||(this.form=this.createForm()),this.form},getTemplate:function(){var a=[''];return a.push('',"fontawesome"===this.base.options.buttonLabels?'':this.formSaveLabel,""),a.push('',"fontawesome"===this.base.options.buttonLabels?'':this.formCloseLabel,""), -this.base.options.anchorTarget&&a.push('',""),this.base.options.anchorButton&&a.push('',""),a.join("")},isDisplayed:function(){return"block"===this.getForm().style.display},hideForm:function(){this.getForm().style.display="none",this.getInput().value=""},showForm:function(a){var b=this.getInput();this.base.saveSelection(),this.base.hideToolbarDefaultActions(),this.getForm().style.display="block",this.base.setToolbarPosition(),b.value=a||"",b.focus()},deactivate:function(){return this.form?(this.form.parentNode&&this.form.parentNode.removeChild(this.form),void delete this.form):!1},getFormOpts:function(){var a=this.getForm().querySelector(".medium-editor-toolbar-anchor-target"),b=this.getForm().querySelector(".medium-editor-toolbar-anchor-button"),c={url:this.getInput().value};return this.base.options.checkLinkFormat&&(c.url=this.checkLinkFormat(c.url)),a&&a.checked?c.target="_blank":c.target="_self",b&&b.checked&&(c.buttonClass=this.base.options.anchorButtonClass),c},doFormSave:function(){var a=this.getFormOpts();this.completeFormSave(a)},completeFormSave:function(a){this.base.restoreSelection(),this.base.createLink(a),this.base.checkSelection()},checkLinkFormat:function(a){var b=/^(https?|ftps?|rtmpt?):\/\/|mailto:/;return(b.test(a)?"":"http://")+a},doFormCancel:function(){this.base.restoreSelection(),this.base.checkSelection()},attachFormEvents:function(a){var b=a.querySelector(".medium-editor-toolbar-close"),c=a.querySelector(".medium-editor-toolbar-save"),d=a.querySelector(".medium-editor-toolbar-input");this.base.on(a,"click",this.handleFormClick.bind(this)),this.base.on(d,"keyup",this.handleTextboxKeyup.bind(this)),this.base.on(b,"click",this.handleCloseClick.bind(this)),this.base.on(c,"click",this.handleSaveClick.bind(this),!0)},createForm:function(){var a=this.base.options.ownerDocument,b=a.createElement("div");return b.className="medium-editor-toolbar-form",b.id="medium-editor-toolbar-form-anchor-"+this.base.id,b.innerHTML=this.getTemplate(),this.attachFormEvents(b),b},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},handleTextboxKeyup:function(a){return a.keyCode===b.keyCode.ENTER?(a.preventDefault(),void this.doFormSave()):void(a.keyCode===b.keyCode.ESCAPE&&(a.preventDefault(),this.doFormCancel()))},handleFormClick:function(a){a.stopPropagation()},handleSaveClick:function(a){a.preventDefault(),this.doFormSave()},handleCloseClick:function(a){a.preventDefault(),this.doFormCancel()}},i=b.derives(h,a)}();var j;!function(){j=function(){b.deprecated("MediumEditor.statics.AnchorPreview","MediumEditor.extensions.anchorPreview","v5.0.0"),this.parent=!0,this.name="anchor-preview"},j.prototype={previewValueSelector:"a",init:function(){this.anchorPreview=this.createPreview(),this.base.options.elementsContainer.appendChild(this.anchorPreview),this.attachToEditables()},getPreviewElement:function(){return this.anchorPreview},createPreview:function(){var a=this.base.options.ownerDocument.createElement("div");return a.id="medium-editor-anchor-preview-"+this.base.id,a.className="medium-editor-anchor-preview",a.innerHTML=this.getTemplate(),this.base.on(a,"click",this.handleClick.bind(this)),a},getTemplate:function(){return'
'},deactivate:function(){this.anchorPreview&&(this.anchorPreview.parentNode&&this.anchorPreview.parentNode.removeChild(this.anchorPreview),delete this.anchorPreview)},hidePreview:function(){this.anchorPreview.classList.remove("medium-editor-anchor-preview-active"),this.activeAnchor=null},showPreview:function(a){return this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")||a.getAttribute("data-disable-preview")?!0:(this.previewValueSelector&&(this.anchorPreview.querySelector(this.previewValueSelector).textContent=a.attributes.href.value,this.anchorPreview.querySelector(this.previewValueSelector).href=a.attributes.href.value),this.anchorPreview.classList.add("medium-toolbar-arrow-over"),this.anchorPreview.classList.remove("medium-toolbar-arrow-under"),this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")||this.anchorPreview.classList.add("medium-editor-anchor-preview-active"),this.activeAnchor=a,this.positionPreview(),this.attachPreviewHandlers(),this)},positionPreview:function(){var a,b,c=this.anchorPreview.offsetHeight,d=this.activeAnchor.getBoundingClientRect(),e=(d.left+d.right)/2;a=this.anchorPreview.offsetWidth/2,b=this.base.options.diffLeft-a,this.anchorPreview.style.top=Math.round(c+d.bottom-this.base.options.diffTop+this.base.options.contentWindow.pageYOffset-this.anchorPreview.offsetHeight)+"px",a>e?this.anchorPreview.style.left=b+a+"px":this.base.options.contentWindow.innerWidth-ethis.base.options.anchorPreviewHideDelay&&this.detachPreviewHandlers()},detachPreviewHandlers:function(){clearInterval(this.intervalTimer),this.instanceHandlePreviewMouseover&&(this.base.off(this.anchorPreview,"mouseover",this.instanceHandlePreviewMouseover),this.base.off(this.anchorPreview,"mouseout",this.instanceHandlePreviewMouseout),this.activeAnchor&&(this.base.off(this.activeAnchor,"mouseover",this.instanceHandlePreviewMouseover),this.base.off(this.activeAnchor,"mouseout",this.instanceHandlePreviewMouseout))),this.hidePreview(),this.hovering=this.instanceHandlePreviewMouseover=this.instanceHandlePreviewMouseout=null},attachPreviewHandlers:function(){this.lastOver=(new Date).getTime(),this.hovering=!0,this.instanceHandlePreviewMouseover=this.handlePreviewMouseover.bind(this),this.instanceHandlePreviewMouseout=this.handlePreviewMouseout.bind(this),this.intervalTimer=setInterval(this.updatePreview.bind(this),200),this.base.on(this.anchorPreview,"mouseover",this.instanceHandlePreviewMouseover),this.base.on(this.anchorPreview,"mouseout",this.instanceHandlePreviewMouseout),this.base.on(this.activeAnchor,"mouseover",this.instanceHandlePreviewMouseover),this.base.on(this.activeAnchor,"mouseout",this.instanceHandlePreviewMouseout)}}}();var k;!function(){function a(){b.deprecated("MediumEditor.statics.FontSizeExtension","MediumEditor.extensions.fontSize","v5.0.0"),this.parent=!0,this.options={name:"fontsize",action:"fontSize",aria:"increase/decrease font size",contentDefault:"±",contentFA:''},this.name="fontsize",this.hasForm=!0}a.prototype={handleClick:function(a){if(a.preventDefault(),a.stopPropagation(),!this.isDisplayed()){var b=this.base.options.ownerDocument.queryCommandValue("fontSize")+"";this.showForm(b)}return!1},getForm:function(){return this.form||(this.form=this.createForm()),this.form},isDisplayed:function(){return"block"===this.getForm().style.display},hideForm:function(){this.getForm().style.display="none",this.getInput().value=""},showForm:function(a){var b=this.getInput();this.base.saveSelection(),this.base.hideToolbarDefaultActions(),this.getForm().style.display="block",this.base.setToolbarPosition(),b.value=a||"",b.focus()},deactivate:function(){return this.form?(this.form.parentNode&&this.form.parentNode.removeChild(this.form),void delete this.form):!1},doFormSave:function(){this.base.restoreSelection(),this.base.checkSelection()},doFormCancel:function(){this.base.restoreSelection(),this.clearFontSize(),this.base.checkSelection()},createForm:function(){var a=this.base.options.ownerDocument,b=a.createElement("div"),c=a.createElement("input"),d=a.createElement("a"),e=a.createElement("a");return b.className="medium-editor-toolbar-form",b.id="medium-editor-toolbar-form-fontsize-"+this.base.id,this.base.on(b,"click",this.handleFormClick.bind(this)),c.setAttribute("type","range"),c.setAttribute("min","1"),c.setAttribute("max","7"),c.className="medium-editor-toolbar-input",b.appendChild(c),this.base.on(c,"change",this.handleSliderChange.bind(this)),e.setAttribute("href","#"),e.className="medium-editor-toobar-save",e.innerHTML="fontawesome"===this.base.options.buttonLabels?'':"✓",b.appendChild(e),this.base.on(e,"click",this.handleSaveClick.bind(this),!0),d.setAttribute("href","#"),d.className="medium-editor-toobar-close",d.innerHTML="fontawesome"===this.base.options.buttonLabels?'':"×",b.appendChild(d),this.base.on(d,"click",this.handleCloseClick.bind(this)),b},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},clearFontSize:function(){f.getSelectedElements(this.base.options.ownerDocument).forEach(function(a){"FONT"===a.tagName&&a.hasAttribute("size")&&a.removeAttribute("size")})},handleSliderChange:function(){var a=this.getInput().value;"4"===a?this.clearFontSize():this.base.execAction("fontSize",{size:a})},handleFormClick:function(a){a.stopPropagation()},handleSaveClick:function(a){a.preventDefault(),this.doFormSave()},handleCloseClick:function(a){a.preventDefault(),this.doFormCancel()}},k=b.derives(h,a)}();var l;!function(){l=e.extend({init:function(){this.button=this.createButton(),this.base.on(this.button,"click",this.handleClick.bind(this)),this.key&&this.base.subscribe("editableKeydown",this.handleKeydown.bind(this))},getButton:function(){return this.button},getAction:function(){return"function"==typeof this.action?this.action(this.base.options):this.action},getAria:function(){return"function"==typeof this.aria?this.aria(this.base.options):this.aria},getTagNames:function(){return"function"==typeof this.tagNames?this.tagNames(this.base.options):this.tagNames},createButton:function(){var a=this.document.createElement("button"),b=this.contentDefault,c=this.getAria();return a.classList.add("medium-editor-action"),a.classList.add("medium-editor-action-"+this.name),a.setAttribute("data-action",this.getAction()),c&&(a.setAttribute("title",c),a.setAttribute("aria-label",c)),this.base.options.buttonLabels&&("fontawesome"===this.base.options.buttonLabels&&this.contentFA?b=this.contentFA:"object"==typeof this.base.options.buttonLabels&&this.base.options.buttonLabels[this.name]&&(b=this.base.options.buttonLabels[this.name])),a.innerHTML=b,a},handleKeydown:function(a){var c,d=String.fromCharCode(a.which||a.keyCode).toLowerCase();this.key===d&&b.isMetaCtrlKey(a)&&(a.preventDefault(),a.stopPropagation(),c=this.getAction(),c&&this.base.execAction(c))},handleClick:function(a){a.preventDefault(),a.stopPropagation();var b=this.getAction();b&&this.base.execAction(b)},isActive:function(){return this.button.classList.contains(this.base.options.activeButtonClass)},setInactive:function(){this.button.classList.remove(this.base.options.activeButtonClass),delete this.knownState},setActive:function(){this.button.classList.add(this.base.options.activeButtonClass),delete this.knownState},queryCommandState:function(){var a=null;return this.useQueryState&&(a=this.base.queryCommandState(this.getAction())),a},isAlreadyApplied:function(a){var b,c,d=!1,e=this.getTagNames();return this.knownState===!1||this.knownState===!0?this.knownState:(e&&e.length>0&&a.tagName&&(d=-1!==e.indexOf(a.tagName.toLowerCase())),!d&&this.style&&(b=this.style.value.split("|"),c=this.window.getComputedStyle(a,null).getPropertyValue(this.style.prop),b.forEach(function(a){this.knownState||(d=-1!==c.indexOf(a),(d||"text-decoration"!==this.style.prop)&&(this.knownState=d))},this)),d)}})}();var m;!function(){var a=function(){};m=l.extend({formSaveLabel:"✓",formCloseLabel:"×",hasForm:!0,getForm:a,isDisplayed:a,hideForm:a})}();var n;!function(){n=m.extend({customClassOption:null,customClassOptionText:"Button",linkValidation:!1,placeholderText:"Paste or type a link",targetCheckbox:!1,targetCheckboxText:"Open in new window",window:window,document:document,name:"anchor",action:"createLink",aria:"link",tagNames:["a"],contentDefault:"#",contentFA:'',key:"k",handleClick:function(a){a.preventDefault(),a.stopPropagation();var c=f.getSelectedParentElement(b.getSelectionRange(this.document));return c.tagName&&"a"===c.tagName.toLowerCase()?this.base.execAction("unlink"):(this.isDisplayed()||this.showForm(),!1)},handleKeydown:function(a){var c=String.fromCharCode(a.which||a.keyCode).toLowerCase();this.key===c&&b.isMetaCtrlKey(a)&&this.handleClick(a)},getForm:function(){return this.form||(this.form=this.createForm()),this.form},getTemplate:function(){var a=[''];return a.push('',"fontawesome"===this.base.options.buttonLabels?'':this.formSaveLabel,""),a.push('',"fontawesome"===this.base.options.buttonLabels?'':this.formCloseLabel,""),this.targetCheckbox&&a.push('',""),this.customClassOption&&a.push('',""),a.join("")},isDisplayed:function(){return"block"===this.getForm().style.display},hideForm:function(){this.getForm().style.display="none",this.getInput().value=""},showForm:function(a){var b=this.getInput();this.base.saveSelection(),this.base.hideToolbarDefaultActions(),this.getForm().style.display="block",this.base.setToolbarPosition(),b.value=a||"",b.focus()},deactivate:function(){return this.form?(this.form.parentNode&&this.form.parentNode.removeChild(this.form),void delete this.form):!1},getFormOpts:function(){var a=this.getForm().querySelector(".medium-editor-toolbar-anchor-target"),b=this.getForm().querySelector(".medium-editor-toolbar-anchor-button"),c={url:this.getInput().value};return this.linkValidation&&(c.url=this.checkLinkFormat(c.url)),a&&a.checked?c.target="_blank":c.target="_self",b&&b.checked&&(c.buttonClass=this.customClassOption),c},doFormSave:function(){var a=this.getFormOpts();this.completeFormSave(a)},completeFormSave:function(a){this.base.restoreSelection(),this.base.createLink(a),this.base.checkSelection()},checkLinkFormat:function(a){var b=/^(https?|ftps?|rtmpt?):\/\/|mailto:/;return(b.test(a)?"":"http://")+a},doFormCancel:function(){this.base.restoreSelection(),this.base.checkSelection()},attachFormEvents:function(a){var b=a.querySelector(".medium-editor-toolbar-close"),c=a.querySelector(".medium-editor-toolbar-save"),d=a.querySelector(".medium-editor-toolbar-input");this.base.on(a,"click",this.handleFormClick.bind(this)),this.base.on(d,"keyup",this.handleTextboxKeyup.bind(this)),this.base.on(b,"click",this.handleCloseClick.bind(this)),this.base.on(c,"click",this.handleSaveClick.bind(this),!0)},createForm:function(){var a=this.document,b=a.createElement("div");return b.className="medium-editor-toolbar-form",b.id="medium-editor-toolbar-form-anchor-"+this.base.id,b.innerHTML=this.getTemplate(),this.attachFormEvents(b),b},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},handleTextboxKeyup:function(a){return a.keyCode===b.keyCode.ENTER?(a.preventDefault(),void this.doFormSave()):void(a.keyCode===b.keyCode.ESCAPE&&(a.preventDefault(),this.doFormCancel()))},handleFormClick:function(a){a.stopPropagation()},handleSaveClick:function(a){a.preventDefault(),this.doFormSave()},handleCloseClick:function(a){a.preventDefault(),this.doFormCancel()}})}();var o;!function(){o=e.extend({name:"anchor-preview",hideDelay:500,previewValueSelector:"a",window:window,document:document,diffLeft:0,diffTop:-10,elementsContainer:!1,init:function(){this.anchorPreview=this.createPreview(),this.elementsContainer||(this.elementsContainer=this.document.body),this.elementsContainer.appendChild(this.anchorPreview),this.attachToEditables()},getPreviewElement:function(){return this.anchorPreview},createPreview:function(){var a=this.document.createElement("div");return a.id="medium-editor-anchor-preview-"+this.base.id,a.className="medium-editor-anchor-preview",a.innerHTML=this.getTemplate(),this.base.on(a,"click",this.handleClick.bind(this)),a},getTemplate:function(){return'
'},deactivate:function(){this.anchorPreview&&(this.anchorPreview.parentNode&&this.anchorPreview.parentNode.removeChild(this.anchorPreview),delete this.anchorPreview)},hidePreview:function(){this.anchorPreview.classList.remove("medium-editor-anchor-preview-active"),this.activeAnchor=null},showPreview:function(a){return this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")||a.getAttribute("data-disable-preview")?!0:(this.previewValueSelector&&(this.anchorPreview.querySelector(this.previewValueSelector).textContent=a.attributes.href.value,this.anchorPreview.querySelector(this.previewValueSelector).href=a.attributes.href.value),this.anchorPreview.classList.add("medium-toolbar-arrow-over"),this.anchorPreview.classList.remove("medium-toolbar-arrow-under"),this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")||this.anchorPreview.classList.add("medium-editor-anchor-preview-active"),this.activeAnchor=a,this.positionPreview(),this.attachPreviewHandlers(),this)},positionPreview:function(){var a,b,c=this.anchorPreview.offsetHeight,d=this.activeAnchor.getBoundingClientRect(),e=(d.left+d.right)/2;a=this.anchorPreview.offsetWidth/2,b=this.diffLeft-a,this.anchorPreview.style.top=Math.round(c+d.bottom-this.diffTop+this.window.pageYOffset-this.anchorPreview.offsetHeight)+"px",a>e?this.anchorPreview.style.left=b+a+"px":this.window.innerWidth-ethis.hideDelay&&this.detachPreviewHandlers()},detachPreviewHandlers:function(){clearInterval(this.intervalTimer),this.instanceHandlePreviewMouseover&&(this.base.off(this.anchorPreview,"mouseover",this.instanceHandlePreviewMouseover),this.base.off(this.anchorPreview,"mouseout",this.instanceHandlePreviewMouseout),this.activeAnchor&&(this.base.off(this.activeAnchor,"mouseover",this.instanceHandlePreviewMouseover),this.base.off(this.activeAnchor,"mouseout",this.instanceHandlePreviewMouseout))),this.hidePreview(),this.hovering=this.instanceHandlePreviewMouseover=this.instanceHandlePreviewMouseout=null},attachPreviewHandlers:function(){this.lastOver=(new Date).getTime(),this.hovering=!0,this.instanceHandlePreviewMouseover=this.handlePreviewMouseover.bind(this),this.instanceHandlePreviewMouseout=this.handlePreviewMouseout.bind(this),this.intervalTimer=setInterval(this.updatePreview.bind(this),200),this.base.on(this.anchorPreview,"mouseover",this.instanceHandlePreviewMouseover),this.base.on(this.anchorPreview,"mouseout",this.instanceHandlePreviewMouseout),this.base.on(this.activeAnchor,"mouseover",this.instanceHandlePreviewMouseover),this.base.on(this.activeAnchor,"mouseout",this.instanceHandlePreviewMouseout)}})}();var p,q,r;q="com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw",r="(((?:(https?://|ftps?://|nntp://)|www\\d{0,3}[.]|[a-z0-9.\\-]+[.]("+q+")\\/)\\S+(?:[^\\s`!\\[\\]{};:'\".,?«»“”‘’])))|(([a-z0-9\\-]+\\.)?[a-z0-9\\-]+\\.("+q+"))",function(){function a(a){return!b.getClosestTag(a,"a")}var c=new RegExp("^("+q+")$","i");p=e.extend({init:function(){this.disableEventHandling=!1,this.base.subscribe("editableKeypress",this.onKeypress.bind(this)),this.base.subscribe("editableBlur",this.onBlur.bind(this)),this.document.execCommand("AutoUrlDetect",!1,!1)},onBlur:function(a,b){this.performLinking(b)},onKeypress:function(a){this.disableEventHandling||(a.keyCode===b.keyCode.SPACE||a.keyCode===b.keyCode.ENTER||a.which===b.keyCode.SPACE)&&(clearTimeout(this.performLinkingTimeout),this.performLinkingTimeout=setTimeout(function(){try{var b=this.base.exportSelection();this.performLinking(a.target)&&this.base.importSelection(b,!0)}catch(c){window.console&&window.console.error("Failed to perform linking",c),this.disableEventHandling=!0}}.bind(this),0))},performLinking:function(a){var b=a.querySelectorAll("p"),c=!1;0===b.length&&(b=[a]);for(var d=0;d=c&&d!==e&&0!==f&&(b||a).splitText(f)},removeObsoleteAutoLinkSpans:function(c){for(var d=c.querySelectorAll('span[data-auto-link="true"]'),e=!1,f=0;f0;)d[f].parentNode.insertBefore(d[f].firstChild,d[f]);d[f].parentNode.removeChild(d[f])}}return e},performLinkingWithinElement:function(a){for(var b=this.findLinkableText(a),c=!1,d=0;db.end+1)throw new Error("PerformLinking overshot the target!");f&&d.push(h||g),e+=g.nodeValue.length,null!==h&&(e+=h.nodeValue.length,c.nextNode()),h=null}return d},createLink:function(a,c){for(var d=!1,e=0;e'),c.onload=function(){var a=this.document.getElementById(d);a&&(a.removeAttribute("id"),a.removeAttribute("class"),a.src=c.result)}.bind(this)}}.bind(this))),a.target.classList.remove(d)}})}();var t;!function(){t=m.extend({name:"fontsize",action:"fontSize",aria:"increase/decrease font size",contentDefault:"±",contentFA:'',handleClick:function(a){if(a.preventDefault(),a.stopPropagation(),!this.isDisplayed()){var b=this.document.queryCommandValue("fontSize")+"";this.showForm(b)}return!1},getForm:function(){return this.form||(this.form=this.createForm()),this.form},isDisplayed:function(){return"block"===this.getForm().style.display},hideForm:function(){this.getForm().style.display="none",this.getInput().value=""},showForm:function(a){var b=this.getInput();this.base.saveSelection(),this.base.hideToolbarDefaultActions(),this.getForm().style.display="block",this.base.setToolbarPosition(),b.value=a||"",b.focus()},deactivate:function(){return this.form?(this.form.parentNode&&this.form.parentNode.removeChild(this.form),void delete this.form):!1},doFormSave:function(){this.base.restoreSelection(),this.base.checkSelection()},doFormCancel:function(){this.base.restoreSelection(),this.clearFontSize(),this.base.checkSelection()},createForm:function(){var a=this.document,b=a.createElement("div"),c=a.createElement("input"),d=a.createElement("a"),e=a.createElement("a");return b.className="medium-editor-toolbar-form",b.id="medium-editor-toolbar-form-fontsize-"+this.base.id,this.base.on(b,"click",this.handleFormClick.bind(this)),c.setAttribute("type","range"),c.setAttribute("min","1"),c.setAttribute("max","7"),c.className="medium-editor-toolbar-input",b.appendChild(c),this.base.on(c,"change",this.handleSliderChange.bind(this)),e.setAttribute("href","#"),e.className="medium-editor-toobar-save",e.innerHTML="fontawesome"===this.base.options.buttonLabels?'':"✓",b.appendChild(e),this.base.on(e,"click",this.handleSaveClick.bind(this),!0),d.setAttribute("href","#"),d.className="medium-editor-toobar-close",d.innerHTML="fontawesome"===this.base.options.buttonLabels?'':"×",b.appendChild(d),this.base.on(d,"click",this.handleCloseClick.bind(this)),b},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},clearFontSize:function(){f.getSelectedElements(this.document).forEach(function(a){"FONT"===a.tagName&&a.hasAttribute("size")&&a.removeAttribute("size")})},handleSliderChange:function(){var a=this.getInput().value;"4"===a?this.clearFontSize():this.base.execAction("fontSize",{size:a})},handleFormClick:function(a){a.stopPropagation()},handleSaveClick:function(a){a.preventDefault(),this.doFormSave()},handleCloseClick:function(a){a.preventDefault(),this.doFormCancel()}})}();var u;!function(){function a(){return[[new RegExp(/<[^>]*docs-internal-guid[^>]*>/gi),""],[new RegExp(/<\/b>(]*>)?$/gi),""],[new RegExp(/\s+<\/span>/g)," "],[new RegExp(/
/g),"
"],[new RegExp(/]*(font-style:italic;font-weight:bold|font-weight:bold;font-style:italic)[^>]*>/gi),''],[new RegExp(/]*font-style:italic[^>]*>/gi),''],[new RegExp(/]*font-weight:bold[^>]*>/gi),''],[new RegExp(/<(\/?)(i|b|a)>/gi),"<$1$2>"],[new RegExp(/<a(?:(?!href).)+href=(?:"|”|“|"|“|”)(((?!"|”|“|"|“|”).)*)(?:"|”|“|"|“|”)(?:(?!>).)*>/gi),''],[new RegExp(/<\/p>\n+/gi),"

"],[new RegExp(/\n+

/gi),""]]}u=e.extend({forcePlainText:!0,cleanPastedHTML:!1,cleanReplacements:[],cleanAttrs:["class","style","dir"],cleanTags:["meta"],window:window,document:document,targetBlank:!1,disableReturn:!1,init:function(){(this.forcePlainText||this.cleanPastedHTML)&&this.base.subscribe("editablePaste",this.handlePaste.bind(this))},handlePaste:function(a,c){var d,e,f,g,h="",i="text/html",j="text/plain";if(this.window.clipboardData&&void 0===a.clipboardData&&(a.clipboardData=this.window.clipboardData,i="Text",j="Text"),a.clipboardData&&a.clipboardData.getData&&!a.defaultPrevented){if(a.preventDefault(),f=a.clipboardData.getData(i),g=a.clipboardData.getData(j),this.cleanPastedHTML&&f)return this.cleanPaste(f);if(this.disableReturn||c.getAttribute("data-disable-return"))h=b.htmlEntities(g);else if(d=g.split(/[\r\n]+/g),d.length>1)for(e=0;e"+b.htmlEntities(d[e])+"

");else h=b.htmlEntities(d[0]);b.insertHTMLCommand(this.document,h)}}, -cleanPaste:function(c){var d,e,g,h=f.getSelectionElement(this.window),i=/
"),this.pasteHTML("

"+e.join("

")+"

");try{this.document.execCommand("insertText",!1,"\n")}catch(k){}for(e=h.querySelectorAll("a,p,div,br"),d=0;d"+d.innerHTML+"":e.innerHTML=d.innerHTML,d.parentNode.replaceChild(e,d);for(f=a.querySelectorAll("span"),c=0;c0&&(d[0].classList.add(this.options.firstButtonClass),d[d.length-1].classList.add(this.options.lastButtonClass)),f},deactivate:function(){this.toolbar&&(this.toolbar.parentNode&&this.toolbar.parentNode.removeChild(this.toolbar),delete this.toolbar)},getToolbarElement:function(){return this.toolbar||(this.toolbar=this.createToolbar()),this.toolbar},getToolbarActionsElement:function(){return this.getToolbarElement().querySelector(".medium-editor-toolbar-actions")},initThrottledMethods:function(){this.throttledPositionToolbar=b.throttle(function(){this.base.isActive&&this.positionToolbarIfShown()}.bind(this))},attachEventHandlers:function(){this.base.subscribe("blur",this.handleBlur.bind(this)),this.base.subscribe("focus",this.handleFocus.bind(this)),this.base.subscribe("editableClick",this.handleEditableClick.bind(this)),this.base.subscribe("editableKeyup",this.handleEditableKeyup.bind(this)),this.base.on(this.options.ownerDocument.documentElement,"mouseup",this.handleDocumentMouseup.bind(this)),this.options.staticToolbar&&this.options.stickyToolbar&&this.base.on(this.options.contentWindow,"scroll",this.handleWindowScroll.bind(this),!0),this.base.on(this.options.contentWindow,"resize",this.handleWindowResize.bind(this))},handleWindowScroll:function(){this.positionToolbarIfShown()},handleWindowResize:function(){this.throttledPositionToolbar()},handleDocumentMouseup:function(a){return a&&a.target&&b.isDescendant(this.getToolbarElement(),a.target)?!1:void this.checkState()},handleEditableClick:function(){setTimeout(function(){this.checkState()}.bind(this),0)},handleEditableKeyup:function(){this.checkState()},handleBlur:function(){clearTimeout(this.hideTimeout),clearTimeout(this.delayShowTimeout),this.hideTimeout=setTimeout(function(){this.hideToolbar()}.bind(this),1)},handleFocus:function(){this.checkState()},isDisplayed:function(){return this.getToolbarElement().classList.contains("medium-editor-toolbar-active")},showToolbar:function(){clearTimeout(this.hideTimeout),this.isDisplayed()||(this.getToolbarElement().classList.add("medium-editor-toolbar-active"),this.base.trigger("showToolbar",{},this.base.getFocusedElement()),"function"==typeof this.options.onShowToolbar&&(b.deprecated("onShowToolbar","the showToolbar custom event","v5.0.0"),this.options.onShowToolbar()))},hideToolbar:function(){this.isDisplayed()&&(this.getToolbarElement().classList.remove("medium-editor-toolbar-active"),this.base.trigger("hideToolbar",{},this.base.getFocusedElement()),this.base.commands.forEach(function(a){"function"==typeof a.onHide&&(b.deprecated("onHide","the hideToolbar custom event","v5.0.0"),a.onHide())}),"function"==typeof this.options.onHideToolbar&&(b.deprecated("onHideToolbar","the hideToolbar custom event","v5.0.0"),this.options.onHideToolbar()))},isToolbarDefaultActionsDisplayed:function(){return"block"===this.getToolbarActionsElement().style.display},hideToolbarDefaultActions:function(){this.isToolbarDefaultActionsDisplayed()&&(this.getToolbarActionsElement().style.display="none")},showToolbarDefaultActions:function(){this.hideExtensionForms(),this.isToolbarDefaultActionsDisplayed()||(this.getToolbarActionsElement().style.display="block"),this.delayShowTimeout=this.base.delay(function(){this.showToolbar()}.bind(this))},hideExtensionForms:function(){this.base.commands.forEach(function(a){a.hasForm&&a.isDisplayed()&&a.hideForm()})},multipleBlockElementsSelected:function(){var a=f.getSelectionHtml.call(this).replace(/<[\S]+><\/[\S]+>/gim,""),b=a.match(/<(p|h[1-6]|blockquote)[^>]*>/g);return!!b&&b.length>1},modifySelection:function(){var a=this.options.contentWindow.getSelection(),c=a.getRangeAt(0);if(this.options.standardizeSelectionStart&&c.startContainer.nodeValue&&c.startOffset===c.startContainer.nodeValue.length){var d=b.findAdjacentTextNodeWithContent(f.getSelectionElement(this.options.contentWindow),c.startContainer,this.options.ownerDocument);if(d){for(var e=0;0===d.nodeValue.substr(e,1).trim().length;)e+=1;var g=this.options.ownerDocument.createRange();g.setStart(d,e),g.setEnd(c.endContainer,c.endOffset),a.removeAllRanges(),a.addRange(g),c=g}}},checkState:function(){if(!this.base.preventSelectionUpdates){if(!this.base.getFocusedElement()||f.selectionInContentEditableFalse(this.options.contentWindow))return void this.hideToolbar();var a=f.getSelectionElement(this.options.contentWindow);if(!a||-1===this.base.elements.indexOf(a)||a.getAttribute("data-disable-toolbar"))return void this.hideToolbar();if(this.options.updateOnEmptySelection&&this.options.staticToolbar)return void this.showAndUpdateToolbar();""===this.options.contentWindow.getSelection().toString().trim()||this.options.allowMultiParagraphSelection===!1&&this.multipleBlockElementsSelected()?this.hideToolbar():this.showAndUpdateToolbar()}},getFocusedElement:function(){return this.base.getFocusedElement()},showAndUpdateToolbar:function(){this.modifySelection(),this.setToolbarButtonStates(),this.showToolbarDefaultActions(),this.setToolbarPosition()},setToolbarButtonStates:function(){this.base.commands.forEach(function(a){"function"==typeof a.isActive&&"function"==typeof a.setInactive&&a.setInactive()}.bind(this)),this.checkActiveButtons()},checkActiveButtons:function(){var a,c=[],d=null,e=b.getSelectionRange(this.options.ownerDocument),g=function(b){"function"==typeof b.checkState?b.checkState(a):"function"==typeof b.isActive&&"function"==typeof b.isAlreadyApplied&&"function"==typeof b.setActive&&!b.isActive()&&b.isAlreadyApplied(a)&&b.setActive()};if(e)for(a=f.getSelectedParentElement(e),this.base.commands.forEach(function(a){return"function"==typeof a.queryCommandState&&(d=a.queryCommandState(),null!==d)?void(d&&"function"==typeof a.setActive&&a.setActive()):void c.push(a)});void 0!==a.tagName&&-1===b.parentElements.indexOf(a.tagName.toLowerCase)&&(c.forEach(g),-1===this.base.elements.indexOf(a));)a=a.parentNode},positionToolbarIfShown:function(){this.isDisplayed()&&this.setToolbarPosition()},setToolbarPosition:function(){var a,b=this.base.getFocusedElement(),c=this.options.contentWindow.getSelection();return b?(this.options.staticToolbar?(this.showToolbar(),this.positionStaticToolbar(b)):c.isCollapsed||(this.showToolbar(),this.positionToolbar(c)),a=this.base.getExtensionByName("anchor-preview"),void(a&&"function"==typeof a.hidePreview&&a.hidePreview())):this},positionStaticToolbar:function(a){this.getToolbarElement().style.left="0";var b,c=this.options.ownerDocument.documentElement&&this.options.ownerDocument.documentElement.scrollTop||this.options.ownerDocument.body.scrollTop,d=this.options.contentWindow.innerWidth,e=this.getToolbarElement(),f=a.getBoundingClientRect(),g=f.top+c,h=f.left+f.width/2,i=e.offsetHeight,j=e.offsetWidth,k=j/2;this.options.stickyToolbar?c>g+a.offsetHeight-i?(e.style.top=g+a.offsetHeight-i+"px",e.classList.remove("sticky-toolbar")):c>g-i?(e.classList.add("sticky-toolbar"),e.style.top="0px"):(e.classList.remove("sticky-toolbar"),e.style.top=g-i+"px"):e.style.top=g-i+"px","left"===this.options.toolbarAlign?b=f.left:"center"===this.options.toolbarAlign?b=h-k:"right"===this.options.toolbarAlign&&(b=f.right-j),0>b?b=0:b+j>d&&(b=d-Math.ceil(j)-1),e.style.left=b+"px"},positionToolbar:function(a){this.getToolbarElement().style.left="0";var b=this.options.contentWindow.innerWidth,c=a.getRangeAt(0),d=c.getBoundingClientRect(),e=(d.left+d.right)/2,f=this.getToolbarElement(),g=f.offsetHeight,h=f.offsetWidth,i=h/2,j=50,k=this.options.diffLeft-i;d.tope?f.style.left=k+i+"px":i>b-e?f.style.left=b+k-i+"px":f.style.left=k+e+"px"}}}();var x;return function(){x={button:l,form:m,anchor:n,anchorPreview:o,autoLink:p,fontSize:t,imageDragging:s,paste:u,placeholder:v}}(),function(){function l(a,c){if(this.options.disableReturn||c.getAttribute("data-disable-return"))a.preventDefault();else if(this.options.disableDoubleReturn||c.getAttribute("data-disable-double-return")){var d=b.getSelectionStart(this.options.ownerDocument);(d&&""===d.textContent.trim()||d.previousElementSibling&&""===d.previousElementSibling.textContent.trim())&&a.preventDefault()}}function m(a){var c=b.getSelectionStart(this.options.ownerDocument),d=c&&c.tagName.toLowerCase();"pre"===d&&(a.preventDefault(),b.insertHTMLCommand(this.options.ownerDocument," ")),b.isListItem(c)&&(a.preventDefault(),a.shiftKey?this.options.ownerDocument.execCommand("outdent",!1,null):this.options.ownerDocument.execCommand("indent",!1,null))}function n(a){var c,d=b.getSelectionStart(this.options.ownerDocument),e=d.tagName.toLowerCase(),g=/^(\s+|)?$/i,h=/h\d/i;(a.which===b.keyCode.BACKSPACE||a.which===b.keyCode.ENTER)&&d.previousElementSibling&&h.test(e)&&0===f.getCaretOffsets(d).left?a.which===b.keyCode.BACKSPACE&&g.test(d.previousElementSibling.innerHTML)?(d.previousElementSibling.parentNode.removeChild(d.previousElementSibling),a.preventDefault()):a.which===b.keyCode.ENTER&&(c=this.options.ownerDocument.createElement("p"),c.innerHTML="
",d.previousElementSibling.parentNode.insertBefore(c,d),a.preventDefault()):a.which===b.keyCode.DELETE&&d.nextElementSibling&&d.previousElementSibling&&!h.test(e)&&g.test(d.innerHTML)&&h.test(d.nextElementSibling.tagName)?(f.moveCursor(this.options.ownerDocument,d.nextElementSibling),d.previousElementSibling.parentNode.removeChild(d),a.preventDefault()):a.which===b.keyCode.BACKSPACE&&"li"===e&&g.test(d.innerHTML)&&!d.previousElementSibling&&!d.parentElement.previousElementSibling&&d.nextElementSibling&&"li"===d.nextElementSibling.tagName.toLowerCase()&&(c=this.options.ownerDocument.createElement("p"),c.innerHTML="
",d.parentElement.parentElement.insertBefore(c,d.parentElement),f.moveCursor(this.options.ownerDocument,c),d.parentElement.removeChild(d),a.preventDefault())}function o(a){var c,d=b.getSelectionStart(this.options.ownerDocument);d&&(d.getAttribute("data-medium-element")&&0===d.children.length&&this.options.ownerDocument.execCommand("formatBlock",!1,"p"),a.which!==b.keyCode.ENTER||b.isListItem(d)||(c=d.tagName.toLowerCase(),"a"===c?this.options.ownerDocument.execCommand("unlink",!1,null):a.shiftKey||a.ctrlKey||/h\d/.test(c)||this.options.ownerDocument.execCommand("formatBlock",!1,"p")))}function p(a){a||(a=[]),"string"==typeof a&&(a=this.options.ownerDocument.querySelectorAll(a)),b.isElement(a)&&(a=[a]);var c=Array.prototype.slice.apply(a);this.elements=[],c.forEach(function(a){this.elements.push("textarea"===a.tagName.toLowerCase()?y.call(this,a):a)},this)}function q(a,b){return Object.keys(b).forEach(function(c){void 0===a[c]&&(a[c]=b[c])}),a}function r(a,c,d){"undefined"!=typeof a.parent&&b.warn("Extension .parent property has been deprecated. The .base property for extensions will always be set to MediumEditor in version 5.0.0");var e={window:d.options.contentWindow,document:d.options.ownerDocument};return a.parent!==!1&&(e.base=d),a=q(a,e),"function"==typeof a.init&&a.init(d),a.name||(a.name=c),a}function s(){var a,b=!1;if(this.options.disableAnchorPreview)return!1;if(this.options.anchorPreview===!1)return!1;if(this.options.extensions["anchor-preview"])return!1;if(this.options.disableToolbar)return!1;for(a=0;a0&&(a=f.getRangeAt(0),c=a.cloneRange(),this.elements.some(function(c,d){return c===a.startContainer||b.isDescendant(c,a.startContainer)?(g=d,!0):!1}),g>-1&&(c.selectNodeContents(this.elements[g]),c.setEnd(a.startContainer,a.startOffset),d=c.toString().length,e={start:d,end:d+a.toString().length,editableElementIndex:g})),null!==e&&0===e.editableElementIndex&&delete e.editableElementIndex,e},saveSelection:function(){this.selectionState=this.exportSelection()},importSelection:function(a,b){if(a){var c,d,e,g,h=void 0===a.editableElementIndex?0:a.editableElementIndex,i={editableElementIndex:h,start:a.start,end:a.end},j=this.elements[i.editableElementIndex],k=0,l=this.options.ownerDocument.createRange(),m=[j],n=!1,o=!1;for(l.setStart(j,0),l.collapse(!0),c=m.pop();!o&&c;){if(3===c.nodeType)g=k+c.length,!n&&i.start>=k&&i.start<=g&&(l.setStart(c,i.start-k),n=!0),n&&i.end>=k&&i.end<=g&&(l.setEnd(c,i.end-k),o=!0),k=g;else for(d=c.childNodes.length-1;d>=0;)m.push(c.childNodes[d]),d-=1;o||(c=m.pop())}b&&(l=f.importSelectionMoveCursorPastAnchor(i,l)),e=this.options.contentWindow.getSelection(),e.removeAllRanges(),e.addRange(l)}},restoreSelection:function(){this.importSelection(this.selectionState)},createLink:function(a){var c,d;if(a.url&&a.url.trim().length>0&&(this.options.ownerDocument.execCommand("createLink",!1,a.url),(this.options.targetBlank||"_blank"===a.target)&&b.setTargetBlank(b.getSelectionStart(this.options.ownerDocument),a.url),a.buttonClass&&b.addClassToAnchors(b.getSelectionStart(this.options.ownerDocument),a.buttonClass)),this.options.targetBlank||"_blank"===a.target||a.buttonClass)for(c=this.options.ownerDocument.createEvent("HTMLEvents"),c.initEvent("input",!0,!0,this.options.contentWindow),d=0;db;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a,this.code=DOMException[a],this.message=b},i=function(a,b){if(""===b)throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return g.call(a,b)},j=function(a){for(var b=f.call(a.getAttribute("class")||""),c=b?b.split(/\s+/):[],d=0,e=c.length;e>d;d++)this.push(c[d]);this._updateClassName=function(){a.setAttribute("class",this.toString())}},k=j[c]=[],l=function(){return new j(this)};if(h[c]=Error[c],k.item=function(a){return this[a]||null},k.contains=function(a){return a+="",-1!==i(this,a)},k.add=function(){var a,b=arguments,c=0,d=b.length,e=!1;do a=b[c]+"",-1===i(this,a)&&(this.push(a),e=!0);while(++ci;i++)e+=String.fromCharCode(f[i]);c.push(e)}else if("Blob"===b(a)||"File"===b(a)){if(!g)throw new h("NOT_READABLE_ERR");var k=new g;c.push(k.readAsBinaryString(a))}else a instanceof d?"base64"===a.encoding&&p?c.push(p(a.data)):"URI"===a.encoding?c.push(decodeURIComponent(a.data)):"raw"===a.encoding&&c.push(a.data):("string"!=typeof a&&(a+=""),c.push(unescape(encodeURIComponent(a))))},e.getBlob=function(a){return arguments.length||(a=null),new d(this.data.join(""),a,"raw")},e.toString=function(){return"[object BlobBuilder]"},f.slice=function(a,b,c){var e=arguments.length;return 3>e&&(c=null),new d(this.data.slice(a,e>1?b:this.data.length),c,this.encoding)},f.toString=function(){return"[object Blob]"},f.close=function(){this.size=0,delete this.data},c}(a);a.Blob=function(a,b){var d=b?b.type||"":"",e=new c;if(a)for(var f=0,g=a.length;g>f;f++)e.append(Uint8Array&&a[f]instanceof Uint8Array?a[f].buffer:a[f]);var h=e.getBlob(d);return!h.slice&&h.webkitSlice&&(h.slice=h.webkitSlice),h};var d=Object.getPrototypeOf||function(a){return a.__proto__};a.Blob.prototype=d(new a.Blob)}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content||this),function(a,b){"use strict";"object"==typeof module?module.exports=b:"function"==typeof define&&define.amd?define(function(){return b}):a.MediumEditor=b}(this,function(){"use strict";function a(a,b){return this.init(a,b)}var b;!function(a){function c(b,c,d){d||(d=a);try{for(var e=0;e=0,keyCode:{BACKSPACE:8,TAB:9,ENTER:13,ESCAPE:27,SPACE:32,DELETE:46},isMetaCtrlKey:function(a){return this.isMac&&a.metaKey||!this.isMac&&a.ctrlKey?!0:!1},isKey:function(a,b){var c=a.which;return null===c&&(c=null!==a.charCode?a.charCode:a.keyCode),!1===Array.isArray(b)?c===b:-1===b.indexOf(c)?!1:!0},parentElements:["p","h1","h2","h3","h4","h5","h6","blockquote","pre"],extend:function(){var a=[!0].concat(Array.prototype.slice.call(arguments));return d.apply(this,a)},defaults:function(){var a=[!1].concat(Array.prototype.slice.call(arguments));return d.apply(this,a)},derives:function(a,b){function c(){}var e=b.prototype;return c.prototype=a.prototype,b.prototype=new c,b.prototype.constructor=a,b.prototype=d(!1,b.prototype,e),b},findAdjacentTextNodeWithContent:function(a,b,c){var d,e=!1,f=c.createNodeIterator(a,NodeFilter.SHOW_TEXT,null,!1);for(d=f.nextNode();d;){if(d===b)e=!0;else if(e&&3===d.nodeType&&d.nodeValue&&d.nodeValue.trim().length>0)break;d=f.nextNode()}return d},isDescendant:function(a,b,c){if(!a||!b)return!1;if(c&&a===b)return!0;for(var d=b.parentNode;null!==d;){if(d===a)return!0;d=d.parentNode}return!1},isElement:function(a){return!(!a||1!==a.nodeType)},now:Date.now,throttle:function(a,b){var c,d,e,f=50,g=null,h=0,i=function(){h=Date.now(),g=null,e=a.apply(c,d),g||(c=d=null)};return b||0===b||(b=f),function(){var f=Date.now(),j=b-(f-h);return c=this,d=arguments,0>=j||j>b?(g&&(clearTimeout(g),g=null),h=f,e=a.apply(c,d),g||(c=d=null)):g||(g=setTimeout(i,j)),e}},traverseUp:function(a,b){if(!a)return!1;do{if(1===a.nodeType){if(b(a))return a;if(a.getAttribute("data-medium-element"))return!1}a=a.parentNode}while(a);return!1},htmlEntities:function(a){return String(a).replace(/&/g,"&").replace(//g,">").replace(/"/g,""")},insertHTMLCommand:function(a,b){var c,d,e,f,g,h,i;if(a.queryCommandSupported("insertHTML"))try{return a.execCommand("insertHTML",!1,b)}catch(j){}if(c=a.defaultView.getSelection(),c.getRangeAt&&c.rangeCount){if(d=c.getRangeAt(0),i=d.commonAncestorContainer,3===i.nodeType&&i.nodeValue===d.toString()||3!==i.nodeType&&i.innerHTML===d.toString()){for(;i.parentNode&&1===i.parentNode.childNodes.length&&!i.parentNode.getAttribute("data-medium-element");)i=i.parentNode;d.selectNode(i)}for(d.deleteContents(),e=a.createElement("div"),e.innerHTML=b,f=a.createDocumentFragment();e.firstChild;)g=e.firstChild,h=f.appendChild(g);d.insertNode(f),h&&(d=d.cloneRange(),d.setStartAfter(h),d.collapse(!0),c.removeAllRanges(),c.addRange(d))}},getSelectionRange:function(a){return this.deprecated("Util.getSelectionRange","Selection.getSelectionRange","v5.0.0"),f.getSelectionRange(a)},getSelectionStart:function(a){return this.deprecated("Util.getSelectionStart","Selection.getSelectionStart","v5.0.0"),f.getSelectionStart(a)},getSelectionData:function(a){return this.deprecated("Util.getSelectionData","Selection.getSelectionData","v5.0.0"),f.getSelectionData(a)},execFormatBlock:function(a,b){var c=f.getSelectionData(f.getSelectionStart(a));if("blockquote"===b&&c.el&&"blockquote"===c.el.parentNode.tagName.toLowerCase())return a.execCommand("outdent",!1,null);if(c.tagName===b&&(b="p"),this.isIE){if("blockquote"===b)return a.execCommand("indent",!1,b);b="<"+b+">"}return a.execCommand("formatBlock",!1,b)},setTargetBlank:function(a,b){var c,d=b||!1;if("a"===a.tagName.toLowerCase())a.target="_blank";else for(a=a.getElementsByTagName("a"),c=0;cd?(e=e.parentNode,c-=1):(f=f.parentNode,d-=1);for(;e!==f;)e=e.parentNode,f=f.parentNode;return e},ensureUrlHasProtocol:function(a){return-1===a.indexOf("://")?"http://"+a:a},warn:function(){void 0!==a.console&&"function"==typeof a.console.warn&&a.console.warn.apply(console,arguments)},deprecated:function(a,c,d){var e=a+" is deprecated, please use "+c+" instead.";d&&(e+=" Will be removed in "+d),b.warn(e)},deprecatedMethod:function(a,c,d,e){b.deprecated(a,c,e),"function"==typeof this[c]&&this[c].apply(this,d)},cleanupAttrs:function(a,b){b.forEach(function(b){a.removeAttribute(b)})},cleanupTags:function(a,b){b.forEach(function(b){a.tagName.toLowerCase()===b&&a.parentNode.removeChild(a)},this)},getClosestTag:function(a,b){return this.traverseUp(a,function(a){return a.tagName.toLowerCase()===b.toLowerCase()})},unwrap:function(a,b){for(var c=b.createDocumentFragment(),d=Array.prototype.slice.call(a.childNodes),e=0;eB",contentFA:'',key:"b"},italic:{name:"italic",action:"italic",aria:"italic",tagNames:["i","em"],style:{prop:"font-style",value:"italic"},useQueryState:!0,contentDefault:"I",contentFA:'',key:"i"},underline:{name:"underline",action:"underline",aria:"underline",tagNames:["u"],style:{prop:"text-decoration",value:"underline"},useQueryState:!0,contentDefault:"U",contentFA:'',key:"u"},strikethrough:{name:"strikethrough",action:"strikethrough",aria:"strike through",tagNames:["strike"],style:{prop:"text-decoration",value:"line-through"},useQueryState:!0,contentDefault:"A",contentFA:''},superscript:{name:"superscript",action:"superscript",aria:"superscript",tagNames:["sup"],contentDefault:"x1",contentFA:''},subscript:{name:"subscript",action:"subscript",aria:"subscript",tagNames:["sub"],contentDefault:"x1",contentFA:''},image:{name:"image",action:"image",aria:"image",tagNames:["img"],contentDefault:"image",contentFA:''},quote:{name:"quote",action:"append-blockquote",aria:"blockquote",tagNames:["blockquote"],contentDefault:"",contentFA:''},orderedlist:{name:"orderedlist",action:"insertorderedlist",aria:"ordered list",tagNames:["ol"],useQueryState:!0,contentDefault:"1.",contentFA:''},unorderedlist:{name:"unorderedlist",action:"insertunorderedlist",aria:"unordered list",tagNames:["ul"],useQueryState:!0,contentDefault:"",contentFA:''},pre:{name:"pre",action:"append-pre",aria:"preformatted text",tagNames:["pre"],contentDefault:"0101",contentFA:''},indent:{name:"indent",action:"indent",aria:"indent",tagNames:[],contentDefault:"",contentFA:''},outdent:{name:"outdent",action:"outdent",aria:"outdent",tagNames:[],contentDefault:"",contentFA:''},justifyCenter:{name:"justifyCenter",action:"justifyCenter",aria:"center justify",tagNames:[],style:{prop:"text-align",value:"center"},contentDefault:"C",contentFA:''},justifyFull:{name:"justifyFull",action:"justifyFull",aria:"full justify",tagNames:[],style:{prop:"text-align",value:"justify"},contentDefault:"J",contentFA:''},justifyLeft:{name:"justifyLeft",action:"justifyLeft",aria:"left justify",tagNames:[],style:{prop:"text-align",value:"left"},contentDefault:"L",contentFA:''},justifyRight:{name:"justifyRight",action:"justifyRight",aria:"right justify",tagNames:[],style:{prop:"text-align",value:"right"},contentDefault:"R",contentFA:''},header1:{name:"header1",action:function(a){return"append-"+a.firstHeader},aria:function(a){return a.firstHeader},tagNames:function(a){return[a.firstHeader]},contentDefault:"H1"},header2:{name:"header2",action:function(a){return"append-"+a.secondHeader},aria:function(a){return a.secondHeader},tagNames:function(a){return[a.secondHeader]},contentDefault:"H2"},removeFormat:{name:"removeFormat",aria:"remove formatting",action:"removeFormat",contentDefault:"X",contentFA:''}}}();var d;!function(){d={allowMultiParagraphSelection:!0,buttons:["bold","italic","underline","anchor","header1","header2","quote"],buttonLabels:!1,delay:0,diffLeft:0,diffTop:-10,disableReturn:!1,disableDoubleReturn:!1,disableToolbar:!1,disableEditing:!1,autoLink:!1,toolbarAlign:"center",elementsContainer:!1,imageDragging:!0,standardizeSelectionStart:!1,contentWindow:window,ownerDocument:document,firstHeader:"h3",secondHeader:"h4",targetBlank:!1,extensions:{},activeButtonClass:"medium-editor-button-active",firstButtonClass:"medium-editor-button-first",lastButtonClass:"medium-editor-button-last",spellcheck:!0}}();var e;!function(){e=function(a){b.extend(this,a)},e.extend=function(a){var c,d=this;c=a&&a.hasOwnProperty("constructor")?a.constructor:function(){return d.apply(this,arguments)},b.extend(c,d);var e=function(){this.constructor=c};return e.prototype=d.prototype,c.prototype=new e,a&&b.extend(c.prototype,a),c},e.prototype={init:function(){},base:void 0,name:void 0,checkState:void 0,destroy:void 0,queryCommandState:void 0,isActive:void 0,isAlreadyApplied:void 0,setActive:void 0,setInactive:void 0,window:void 0,document:void 0,getEditorElements:function(){return this.base.elements},getEditorId:function(){return this.base.id},getEditorOption:function(a){return this.base.options[a]}},["execAction","on","off","subscribe"].forEach(function(a){e.prototype[a]=function(){return this.base[a].apply(this.base,arguments)}})}();var f;!function(){f={findMatchingSelectionParent:function(a,c){var d,e,f=c.getSelection();return 0===f.rangeCount?!1:(d=f.getRangeAt(0),e=d.commonAncestorContainer,b.traverseUp(e,a))},getSelectionElement:function(a){return this.findMatchingSelectionParent(function(a){return a.getAttribute("data-medium-element")},a)},importSelectionMoveCursorPastAnchor:function(a,c){var d=function(a){return"a"===a.nodeName.toLowerCase()};if(a.start===a.end&&3===c.startContainer.nodeType&&c.startOffset===c.startContainer.nodeValue.length&&b.traverseUp(c.startContainer,d)){for(var e=c.startContainer,f=c.startContainer.parentNode;null!==f&&"a"!==f.nodeName.toLowerCase();)f.childNodes[f.childNodes.length-1]!==e?f=null:(e=f,f=f.parentNode);if(null!==f&&"a"===f.nodeName.toLowerCase()){for(var g=null,h=0;null===g&&ha;a+=1)c.appendChild(e.getRangeAt(a).cloneContents());d=c.innerHTML}return d},getCaretOffsets:function(a,b){var c,d;return b||(b=window.getSelection().getRangeAt(0)),c=b.cloneRange(),d=b.cloneRange(),c.selectNodeContents(a),c.setEnd(b.endContainer,b.endOffset),d.selectNodeContents(a),d.setStart(b.endContainer,b.endOffset),{left:c.toString().length,right:d.toString().length}},rangeSelectsSingleNode:function(a){var b=a.startContainer;return b===a.endContainer&&b.hasChildNodes()&&a.endOffset===a.startOffset+1},getSelectedParentElement:function(a){return a?this.rangeSelectsSingleNode(a)&&3!==a.startContainer.childNodes[a.startOffset].nodeType?a.startContainer.childNodes[a.startOffset]:3===a.startContainer.nodeType?a.startContainer.parentNode:a.startContainer:null},getSelectedElements:function(a){var b,c,d,e=a.getSelection();if(!e.rangeCount||e.isCollapsed||!e.getRangeAt(0).commonAncestorContainer)return[];if(b=e.getRangeAt(0),3===b.commonAncestorContainer.nodeType){for(c=[],d=b.commonAncestorContainer;d.parentNode&&1===d.parentNode.childNodes.length;)c.push(d.parentNode),d=d.parentNode;return c}return[].filter.call(b.commonAncestorContainer.getElementsByTagName("*"),function(a){return"function"==typeof e.containsNode?e.containsNode(a,!0):!0})},selectNode:function(a,b){var c=b.createRange(),d=b.getSelection();c.selectNodeContents(a),d.removeAllRanges(),d.addRange(c)},moveCursor:function(a,b,c){var d,e,f=c||0;d=a.createRange(),e=a.getSelection(),d.setStart(b,f),d.collapse(!0),e.removeAllRanges(),e.addRange(d)},getSelectionRange:function(a){var b=a.getSelection();return 0===b.rangeCount||!0===b.isCollapsed?null:b.getRangeAt(0)},getSelectionStart:function(a){var b=a.getSelection().anchorNode,c=b&&3===b.nodeType?b.parentNode:b;return c},getSelectionData:function(a){var c;for(a&&a.tagName&&(c=a.tagName.toLowerCase());a&&-1===b.parentElements.indexOf(c);)a=a.parentNode,a&&a.tagName&&(c=a.tagName.toLowerCase());return{el:a,tagName:c}}}}();var g;!function(){g=function(a){this.base=a,this.options=this.base.options,this.events=[],this.customEvents={},this.listeners={}},g.prototype={InputEventOnContenteditableSupported:!b.isIE,attachDOMEvent:function(a,b,c,d){a.addEventListener(b,c,d),this.events.push([a,b,c,d])},detachDOMEvent:function(a,b,c,d){var e,f=this.indexOfListener(a,b,c,d);-1!==f&&(e=this.events.splice(f,1)[0],e[0].removeEventListener(e[1],e[2],e[3]))},indexOfListener:function(a,b,c,d){var e,f,g;for(e=0,f=this.events.length;f>e;e+=1)if(g=this.events[e],g[0]===a&&g[1]===b&&g[2]===c&&g[3]===d)return e;return-1},detachAllDOMEvents:function(){for(var a=this.events.pop();a;)a[0].removeEventListener(a[1],a[2],a[3]),a=this.events.pop()},attachCustomEvent:function(a,b){this.setupListener(a),this.customEvents[a]||(this.customEvents[a]=[]),this.customEvents[a].push(b)},detachCustomEvent:function(a,b){var c=this.indexOfCustomListener(a,b);-1!==c&&this.customEvents[a].splice(c,1)},indexOfCustomListener:function(a,b){return this.customEvents[a]&&this.customEvents[a].length?this.customEvents[a].indexOf(b):-1},detachAllCustomEvents:function(){this.customEvents={}},triggerCustomEvent:function(a,b,c){this.customEvents[a]&&this.customEvents[a].forEach(function(a){a(b,c)})},destroy:function(){this.detachAllDOMEvents(),this.detachAllCustomEvents(),this.detachExecCommand()},attachToExecCommand:function(){this.execCommandListener||(this.execCommandListener=function(a){this.handleDocumentExecCommand(a)}.bind(this),this.wrapExecCommand(),this.options.ownerDocument.execCommand.listeners.push(this.execCommandListener))},detachExecCommand:function(){var a=this.options.ownerDocument;if(this.execCommandListener&&a.execCommand.listeners){var b=a.execCommand.listeners.indexOf(this.execCommandListener);-1!==b&&a.execCommand.listeners.splice(b,1),a.execCommand.listeners.length||this.unwrapExecCommand()}},wrapExecCommand:function(){var a=this.options.ownerDocument;if(!a.execCommand.listeners){var b=function(b,c,d){var e=a.execCommand.orig.apply(this,arguments);if(!a.execCommand.listeners)return e;var f=Array.prototype.slice.call(arguments);return a.execCommand.listeners.forEach(function(a){a({command:b,value:d,args:f,result:e})}),e};b.orig=a.execCommand,b.listeners=[],a.execCommand=b}},unwrapExecCommand:function(){var a=this.options.ownerDocument;a.execCommand.orig&&(a.execCommand=a.execCommand.orig)},setupListener:function(a){if(!this.listeners[a]){switch(a){case"externalInteraction":this.attachDOMEvent(this.options.ownerDocument.body,"mousedown",this.handleBodyMousedown.bind(this),!0),this.attachDOMEvent(this.options.ownerDocument.body,"click",this.handleBodyClick.bind(this),!0),this.attachDOMEvent(this.options.ownerDocument.body,"focus",this.handleBodyFocus.bind(this),!0);break;case"blur":this.setupListener("externalInteraction");break;case"focus":this.setupListener("externalInteraction");break;case"editableInput":this.contentCache=[],this.base.elements.forEach(function(a){this.contentCache[a.getAttribute("medium-editor-index")]=a.innerHTML,this.InputEventOnContenteditableSupported&&this.attachDOMEvent(a,"input",this.handleInput.bind(this))}.bind(this)),this.InputEventOnContenteditableSupported||(this.setupListener("editableKeypress"),this.keypressUpdateInput=!0,this.attachDOMEvent(document,"selectionchange",this.handleDocumentSelectionChange.bind(this)),this.attachToExecCommand());break;case"editableClick":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"click",this.handleClick.bind(this))}.bind(this));break;case"editableBlur":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"blur",this.handleBlur.bind(this))}.bind(this));break;case"editableKeypress":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"keypress",this.handleKeypress.bind(this))}.bind(this));break;case"editableKeyup":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"keyup",this.handleKeyup.bind(this))}.bind(this));break;case"editableKeydown":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"keydown",this.handleKeydown.bind(this))}.bind(this));break;case"editableKeydownEnter":this.setupListener("editableKeydown");break;case"editableKeydownTab":this.setupListener("editableKeydown");break;case"editableKeydownDelete":this.setupListener("editableKeydown");break;case"editableMouseover":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"mouseover",this.handleMouseover.bind(this))},this);break;case"editableDrag":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"dragover",this.handleDragging.bind(this)),this.attachDOMEvent(a,"dragleave",this.handleDragging.bind(this))},this);break;case"editableDrop":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"drop",this.handleDrop.bind(this))},this);break;case"editablePaste":this.base.elements.forEach(function(a){this.attachDOMEvent(a,"paste",this.handlePaste.bind(this))},this)}this.listeners[a]=!0}},focusElement:function(a){a.focus(),this.updateFocus(a,{target:a,type:"focus"})},updateFocus:function(a,c){var d,e=this.base.toolbar?this.base.toolbar.getToolbarElement():null,f=this.base.getExtensionByName("anchor-preview"),g=f&&f.getPreviewElement?f.getPreviewElement():null,h=this.base.getFocusedElement();h&&"click"===c.type&&this.lastMousedownTarget&&(b.isDescendant(h,this.lastMousedownTarget,!0)||b.isDescendant(e,this.lastMousedownTarget,!0)||b.isDescendant(g,this.lastMousedownTarget,!0))&&(d=h),d||this.base.elements.some(function(c){return!d&&b.isDescendant(c,a,!0)&&(d=c),!!d},this);var i=!b.isDescendant(h,a,!0)&&!b.isDescendant(e,a,!0)&&!b.isDescendant(g,a,!0);d!==h&&(h&&i&&(h.removeAttribute("data-medium-focused"),this.triggerCustomEvent("blur",c,h)),d&&(d.setAttribute("data-medium-focused",!0),this.triggerCustomEvent("focus",c,d))),i&&this.triggerCustomEvent("externalInteraction",c)},updateInput:function(a,b){var c=a.getAttribute("medium-editor-index");a.innerHTML!==this.contentCache[c]&&this.triggerCustomEvent("editableInput",b,a),this.contentCache[c]=a.innerHTML},handleDocumentSelectionChange:function(a){if(a.currentTarget&&a.currentTarget.activeElement){var c,d=a.currentTarget.activeElement;this.base.elements.some(function(a){return b.isDescendant(a,d,!0)?(c=a,!0):!1},this),c&&this.updateInput(c,{target:d,currentTarget:c})}},handleDocumentExecCommand:function(){var a=this.base.getFocusedElement();a&&this.updateInput(a,{target:a,currentTarget:a})},handleBodyClick:function(a){this.updateFocus(a.target,a)},handleBodyFocus:function(a){this.updateFocus(a.target,a)},handleBodyMousedown:function(a){this.lastMousedownTarget=a.target},handleInput:function(a){this.updateInput(a.currentTarget,a)},handleClick:function(a){this.triggerCustomEvent("editableClick",a,a.currentTarget)},handleBlur:function(a){this.triggerCustomEvent("editableBlur",a,a.currentTarget)},handleKeypress:function(a){if(this.triggerCustomEvent("editableKeypress",a,a.currentTarget),this.keypressUpdateInput){var b={target:a.target,currentTarget:a.currentTarget};setTimeout(function(){this.updateInput(b.currentTarget,b)}.bind(this),0)}},handleKeyup:function(a){this.triggerCustomEvent("editableKeyup",a,a.currentTarget)},handleMouseover:function(a){this.triggerCustomEvent("editableMouseover",a,a.currentTarget)},handleDragging:function(a){this.triggerCustomEvent("editableDrag",a,a.currentTarget)},handleDrop:function(a){this.triggerCustomEvent("editableDrop",a,a.currentTarget)},handlePaste:function(a){this.triggerCustomEvent("editablePaste",a,a.currentTarget)},handleKeydown:function(a){return this.triggerCustomEvent("editableKeydown",a,a.currentTarget),b.isKey(a,b.keyCode.ENTER)?this.triggerCustomEvent("editableKeydownEnter",a,a.currentTarget):b.isKey(a,b.keyCode.TAB)?this.triggerCustomEvent("editableKeydownTab",a,a.currentTarget):b.isKey(a,[b.keyCode.DELETE,b.keyCode.BACKSPACE])?this.triggerCustomEvent("editableKeydownDelete",a,a.currentTarget):void 0}}}();var h;!function(){h=function(a,c){b.deprecated("MediumEditor.statics.DefaultButton","MediumEditor.extensions.button","v5.0.0"),this.options=a,this.name=a.name,this.init(c)},h.prototype={init:function(a){this.base=a,this.button=this.createButton(),this.base.on(this.button,"click",this.handleClick.bind(this)),this.options.key&&this.base.subscribe("editableKeydown",this.handleKeydown.bind(this))},getButton:function(){return this.button},getAction:function(){return"function"==typeof this.options.action?this.options.action(this.base.options):this.options.action},getAria:function(){return"function"==typeof this.options.aria?this.options.aria(this.base.options):this.options.aria},getTagNames:function(){return"function"==typeof this.options.tagNames?this.options.tagNames(this.base.options):this.options.tagNames},createButton:function(){var a=this.base.options.ownerDocument.createElement("button"),b=this.options.contentDefault,c=this.getAria();return a.classList.add("medium-editor-action"),a.classList.add("medium-editor-action-"+this.name),a.setAttribute("data-action",this.getAction()),c&&(a.setAttribute("title",c),a.setAttribute("aria-label",c)),this.base.options.buttonLabels&&("fontawesome"===this.base.options.buttonLabels&&this.options.contentFA?b=this.options.contentFA:"object"==typeof this.base.options.buttonLabels&&this.base.options.buttonLabels[this.name]&&(b=this.base.options.buttonLabels[this.options.name])),a.innerHTML=b,a},handleKeydown:function(a){var c,d=String.fromCharCode(a.which||a.keyCode).toLowerCase();this.options.key===d&&b.isMetaCtrlKey(a)&&(a.preventDefault(),a.stopPropagation(),c=this.getAction(),c&&this.base.execAction(c))},handleClick:function(a){a.preventDefault(),a.stopPropagation();var b=this.getAction();b&&this.base.execAction(b)},isActive:function(){return this.button.classList.contains(this.base.options.activeButtonClass)},setInactive:function(){this.button.classList.remove(this.base.options.activeButtonClass),delete this.knownState},setActive:function(){this.button.classList.add(this.base.options.activeButtonClass),delete this.knownState},queryCommandState:function(){var a=null;return this.options.useQueryState&&(a=this.base.queryCommandState(this.getAction())),a},isAlreadyApplied:function(a){var b,c,d=!1,e=this.getTagNames();return this.knownState===!1||this.knownState===!0?this.knownState:(e&&e.length>0&&a.tagName&&(d=-1!==e.indexOf(a.tagName.toLowerCase())),!d&&this.options.style&&(b=this.options.style.value.split("|"),c=this.base.options.contentWindow.getComputedStyle(a,null).getPropertyValue(this.options.style.prop),b.forEach(function(a){this.knownState||(d=-1!==c.indexOf(a),(d||"text-decoration"!==this.options.style.prop)&&(this.knownState=d))},this)),d)}}}();var i;!function(){function a(){b.deprecated("MediumEditor.statics.AnchorExtension","MediumEditor.extensions.anchor","v5.0.0"),this.parent=!0,this.options={name:"anchor",action:"createLink",aria:"link",tagNames:["a"],contentDefault:"#",contentFA:'',key:"k"},this.name="anchor",this.hasForm=!0}a.prototype={formSaveLabel:"✓",formCloseLabel:"×",handleClick:function(a){a.preventDefault(),a.stopPropagation();var b=f.getSelectedParentElement(f.getSelectionRange(this.base.options.ownerDocument));return b.tagName&&"a"===b.tagName.toLowerCase()?this.base.execAction("unlink"):(this.isDisplayed()||this.showForm(),!1)},handleKeydown:function(a){var c=String.fromCharCode(a.which||a.keyCode).toLowerCase(); + +this.options.key===c&&b.isMetaCtrlKey(a)&&(a.preventDefault(),a.stopPropagation(),this.handleClick(a))},getForm:function(){return this.form||(this.form=this.createForm()),this.form},getTemplate:function(){var a=[''];return a.push('
',"fontawesome"===this.base.options.buttonLabels?'':this.formSaveLabel,""),a.push('',"fontawesome"===this.base.options.buttonLabels?'':this.formCloseLabel,""),this.base.options.anchorTarget&&a.push('',""),this.base.options.anchorButton&&a.push('',""),a.join("")},isDisplayed:function(){return"block"===this.getForm().style.display},hideForm:function(){this.getForm().style.display="none",this.getInput().value=""},showForm:function(a){var b=this.getInput();this.base.saveSelection(),this.base.hideToolbarDefaultActions(),this.getForm().style.display="block",this.base.setToolbarPosition(),b.value=a||"",b.focus()},deactivate:function(){return this.form?(this.form.parentNode&&this.form.parentNode.removeChild(this.form),void delete this.form):!1},getFormOpts:function(){var a=this.getForm().querySelector(".medium-editor-toolbar-anchor-target"),b=this.getForm().querySelector(".medium-editor-toolbar-anchor-button"),c={url:this.getInput().value};return this.base.options.checkLinkFormat&&(c.url=this.checkLinkFormat(c.url)),a&&a.checked?c.target="_blank":c.target="_self",b&&b.checked&&(c.buttonClass=this.base.options.anchorButtonClass),c},doFormSave:function(){var a=this.getFormOpts();this.completeFormSave(a)},completeFormSave:function(a){this.base.restoreSelection(),this.base.createLink(a),this.base.checkSelection()},checkLinkFormat:function(a){var b=/^(https?|ftps?|rtmpt?):\/\/|mailto:/;return(b.test(a)?"":"http://")+a},doFormCancel:function(){this.base.restoreSelection(),this.base.checkSelection()},attachFormEvents:function(a){var b=a.querySelector(".medium-editor-toolbar-close"),c=a.querySelector(".medium-editor-toolbar-save"),d=a.querySelector(".medium-editor-toolbar-input");this.base.on(a,"click",this.handleFormClick.bind(this)),this.base.on(d,"keyup",this.handleTextboxKeyup.bind(this)),this.base.on(b,"click",this.handleCloseClick.bind(this)),this.base.on(c,"click",this.handleSaveClick.bind(this),!0)},createForm:function(){var a=this.base.options.ownerDocument,b=a.createElement("div");return b.className="medium-editor-toolbar-form",b.id="medium-editor-toolbar-form-anchor-"+this.base.id,b.innerHTML=this.getTemplate(),this.attachFormEvents(b),b},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},handleTextboxKeyup:function(a){return a.keyCode===b.keyCode.ENTER?(a.preventDefault(),void this.doFormSave()):void(a.keyCode===b.keyCode.ESCAPE&&(a.preventDefault(),this.doFormCancel()))},handleFormClick:function(a){a.stopPropagation()},handleSaveClick:function(a){a.preventDefault(),this.doFormSave()},handleCloseClick:function(a){a.preventDefault(),this.doFormCancel()}},i=b.derives(h,a)}();var j;!function(){j=function(){b.deprecated("MediumEditor.statics.AnchorPreview","MediumEditor.extensions.anchorPreview","v5.0.0"),this.parent=!0,this.name="anchor-preview"},j.prototype={previewValueSelector:"a",init:function(){this.anchorPreview=this.createPreview(),this.base.options.elementsContainer.appendChild(this.anchorPreview),this.attachToEditables()},getPreviewElement:function(){return this.anchorPreview},createPreview:function(){var a=this.base.options.ownerDocument.createElement("div");return a.id="medium-editor-anchor-preview-"+this.base.id,a.className="medium-editor-anchor-preview",a.innerHTML=this.getTemplate(),this.base.on(a,"click",this.handleClick.bind(this)),a},getTemplate:function(){return'
'},deactivate:function(){this.anchorPreview&&(this.anchorPreview.parentNode&&this.anchorPreview.parentNode.removeChild(this.anchorPreview),delete this.anchorPreview)},hidePreview:function(){this.anchorPreview.classList.remove("medium-editor-anchor-preview-active"),this.activeAnchor=null},showPreview:function(a){return this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")||a.getAttribute("data-disable-preview")?!0:(this.previewValueSelector&&(this.anchorPreview.querySelector(this.previewValueSelector).textContent=a.attributes.href.value,this.anchorPreview.querySelector(this.previewValueSelector).href=a.attributes.href.value),this.anchorPreview.classList.add("medium-toolbar-arrow-over"),this.anchorPreview.classList.remove("medium-toolbar-arrow-under"),this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")||this.anchorPreview.classList.add("medium-editor-anchor-preview-active"),this.activeAnchor=a,this.positionPreview(),this.attachPreviewHandlers(),this)},positionPreview:function(){var a,b,c=this.anchorPreview.offsetHeight,d=this.activeAnchor.getBoundingClientRect(),e=(d.left+d.right)/2;a=this.anchorPreview.offsetWidth/2,b=this.base.options.diffLeft-a,this.anchorPreview.style.top=Math.round(c+d.bottom-this.base.options.diffTop+this.base.options.contentWindow.pageYOffset-this.anchorPreview.offsetHeight)+"px",a>e?this.anchorPreview.style.left=b+a+"px":this.base.options.contentWindow.innerWidth-ethis.base.options.anchorPreviewHideDelay&&this.detachPreviewHandlers()},detachPreviewHandlers:function(){clearInterval(this.intervalTimer),this.instanceHandlePreviewMouseover&&(this.base.off(this.anchorPreview,"mouseover",this.instanceHandlePreviewMouseover),this.base.off(this.anchorPreview,"mouseout",this.instanceHandlePreviewMouseout),this.activeAnchor&&(this.base.off(this.activeAnchor,"mouseover",this.instanceHandlePreviewMouseover),this.base.off(this.activeAnchor,"mouseout",this.instanceHandlePreviewMouseout))),this.hidePreview(),this.hovering=this.instanceHandlePreviewMouseover=this.instanceHandlePreviewMouseout=null},attachPreviewHandlers:function(){this.lastOver=(new Date).getTime(),this.hovering=!0,this.instanceHandlePreviewMouseover=this.handlePreviewMouseover.bind(this),this.instanceHandlePreviewMouseout=this.handlePreviewMouseout.bind(this),this.intervalTimer=setInterval(this.updatePreview.bind(this),200),this.base.on(this.anchorPreview,"mouseover",this.instanceHandlePreviewMouseover),this.base.on(this.anchorPreview,"mouseout",this.instanceHandlePreviewMouseout),this.base.on(this.activeAnchor,"mouseover",this.instanceHandlePreviewMouseover),this.base.on(this.activeAnchor,"mouseout",this.instanceHandlePreviewMouseout)}}}();var k;!function(){function a(){b.deprecated("MediumEditor.statics.FontSizeExtension","MediumEditor.extensions.fontSize","v5.0.0"),this.parent=!0,this.options={name:"fontsize",action:"fontSize",aria:"increase/decrease font size",contentDefault:"±",contentFA:''},this.name="fontsize",this.hasForm=!0}a.prototype={handleClick:function(a){if(a.preventDefault(),a.stopPropagation(),!this.isDisplayed()){var b=this.base.options.ownerDocument.queryCommandValue("fontSize")+"";this.showForm(b)}return!1},getForm:function(){return this.form||(this.form=this.createForm()),this.form},isDisplayed:function(){return"block"===this.getForm().style.display},hideForm:function(){this.getForm().style.display="none",this.getInput().value=""},showForm:function(a){var b=this.getInput();this.base.saveSelection(),this.base.hideToolbarDefaultActions(),this.getForm().style.display="block",this.base.setToolbarPosition(),b.value=a||"",b.focus()},deactivate:function(){return this.form?(this.form.parentNode&&this.form.parentNode.removeChild(this.form),void delete this.form):!1},doFormSave:function(){this.base.restoreSelection(),this.base.checkSelection()},doFormCancel:function(){this.base.restoreSelection(),this.clearFontSize(),this.base.checkSelection()},createForm:function(){var a=this.base.options.ownerDocument,b=a.createElement("div"),c=a.createElement("input"),d=a.createElement("a"),e=a.createElement("a");return b.className="medium-editor-toolbar-form",b.id="medium-editor-toolbar-form-fontsize-"+this.base.id,this.base.on(b,"click",this.handleFormClick.bind(this)),c.setAttribute("type","range"),c.setAttribute("min","1"),c.setAttribute("max","7"),c.className="medium-editor-toolbar-input",b.appendChild(c),this.base.on(c,"change",this.handleSliderChange.bind(this)),e.setAttribute("href","#"),e.className="medium-editor-toobar-save",e.innerHTML="fontawesome"===this.base.options.buttonLabels?'':"✓",b.appendChild(e),this.base.on(e,"click",this.handleSaveClick.bind(this),!0),d.setAttribute("href","#"),d.className="medium-editor-toobar-close",d.innerHTML="fontawesome"===this.base.options.buttonLabels?'':"×",b.appendChild(d),this.base.on(d,"click",this.handleCloseClick.bind(this)),b},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},clearFontSize:function(){f.getSelectedElements(this.base.options.ownerDocument).forEach(function(a){"FONT"===a.tagName&&a.hasAttribute("size")&&a.removeAttribute("size")})},handleSliderChange:function(){var a=this.getInput().value;"4"===a?this.clearFontSize():this.base.execAction("fontSize",{size:a})},handleFormClick:function(a){a.stopPropagation()},handleSaveClick:function(a){a.preventDefault(),this.doFormSave()},handleCloseClick:function(a){a.preventDefault(),this.doFormCancel()}},k=b.derives(h,a)}();var l;!function(){l=e.extend({init:function(){this.button=this.createButton(),this.on(this.button,"click",this.handleClick.bind(this)),this.key&&this.subscribe("editableKeydown",this.handleKeydown.bind(this))},getButton:function(){return this.button},getAction:function(){return"function"==typeof this.action?this.action(this.base.options):this.action},getAria:function(){return"function"==typeof this.aria?this.aria(this.base.options):this.aria},getTagNames:function(){return"function"==typeof this.tagNames?this.tagNames(this.base.options):this.tagNames},createButton:function(){var a=this.document.createElement("button"),b=this.contentDefault,c=this.getAria(),d=this.getEditorOption("buttonLabels");return a.classList.add("medium-editor-action"),a.classList.add("medium-editor-action-"+this.name),a.setAttribute("data-action",this.getAction()),c&&(a.setAttribute("title",c),a.setAttribute("aria-label",c)),d&&("fontawesome"===d&&this.contentFA?b=this.contentFA:"object"==typeof d&&d[this.name]&&(b=d[this.name])),a.innerHTML=b,a},handleKeydown:function(a){var c;b.isKey(a,this.key.charCodeAt(0))&&b.isMetaCtrlKey(a)&&!a.shiftKey&&(a.preventDefault(),a.stopPropagation(),c=this.getAction(),c&&this.execAction(c))},handleClick:function(a){a.preventDefault(),a.stopPropagation();var b=this.getAction();b&&this.execAction(b)},isActive:function(){return this.button.classList.contains(this.getEditorOption("activeButtonClass"))},setInactive:function(){this.button.classList.remove(this.getEditorOption("activeButtonClass")),delete this.knownState},setActive:function(){this.button.classList.add(this.getEditorOption("activeButtonClass")),delete this.knownState},queryCommandState:function(){var a=null;return this.useQueryState&&(a=this.base.queryCommandState(this.getAction())),a},isAlreadyApplied:function(a){var b,c,d=!1,e=this.getTagNames();return this.knownState===!1||this.knownState===!0?this.knownState:(e&&e.length>0&&a.tagName&&(d=-1!==e.indexOf(a.tagName.toLowerCase())),!d&&this.style&&(b=this.style.value.split("|"),c=this.window.getComputedStyle(a,null).getPropertyValue(this.style.prop),b.forEach(function(a){this.knownState||(d=-1!==c.indexOf(a),(d||"text-decoration"!==this.style.prop)&&(this.knownState=d))},this)),d)}})}();var m;!function(){var a=function(){};m=l.extend({formSaveLabel:"✓",formCloseLabel:"×",hasForm:!0,getForm:a,isDisplayed:a,hideForm:a})}();var n;!function(){n=m.extend({customClassOption:null,customClassOptionText:"Button",linkValidation:!1,placeholderText:"Paste or type a link",targetCheckbox:!1,targetCheckboxText:"Open in new window",name:"anchor",action:"createLink",aria:"link",tagNames:["a"],contentDefault:"#",contentFA:'',key:"k",handleClick:function(a){a.preventDefault(),a.stopPropagation();var b=f.getSelectedParentElement(f.getSelectionRange(this.document));return b.tagName&&"a"===b.tagName.toLowerCase()?this.execAction("unlink"):(this.isDisplayed()||this.showForm(),!1)},handleKeydown:function(a){b.isKey(a,this.key.charCodeAt(0))&&b.isMetaCtrlKey(a)&&this.handleClick(a)},getForm:function(){return this.form||(this.form=this.createForm()),this.form},getTemplate:function(){var a=[''];return a.push('',"fontawesome"===this.getEditorOption("buttonLabels")?'':this.formSaveLabel,""),a.push('',"fontawesome"===this.getEditorOption("buttonLabels")?'':this.formCloseLabel,""),this.targetCheckbox&&a.push('',""),this.customClassOption&&a.push('',""),a.join("")},isDisplayed:function(){return"block"===this.getForm().style.display},hideForm:function(){this.getForm().style.display="none",this.getInput().value=""},showForm:function(a){var b=this.getInput();this.base.saveSelection(),this.base.hideToolbarDefaultActions(),this.getForm().style.display="block",this.base.setToolbarPosition(),b.value=a||"",b.focus()},destroy:function(){return this.form?(this.form.parentNode&&this.form.parentNode.removeChild(this.form),void delete this.form):!1},deactivate:function(){b.deprecatedMethod.call(this,"deactivate","destroy",arguments,"v5.0.0")},getFormOpts:function(){var a=this.getForm().querySelector(".medium-editor-toolbar-anchor-target"),b=this.getForm().querySelector(".medium-editor-toolbar-anchor-button"),c={url:this.getInput().value};return this.linkValidation&&(c.url=this.checkLinkFormat(c.url)),c.target="_self",a&&a.checked&&(c.target="_blank"),b&&b.checked&&(c.buttonClass=this.customClassOption),c},doFormSave:function(){var a=this.getFormOpts();this.completeFormSave(a)},completeFormSave:function(a){this.base.restoreSelection(),this.execAction(this.action,a),this.base.checkSelection()},checkLinkFormat:function(a){var b=/^(https?|ftps?|rtmpt?):\/\/|mailto:/;return(b.test(a)?"":"http://")+a},doFormCancel:function(){this.base.restoreSelection(),this.base.checkSelection()},attachFormEvents:function(a){var b=a.querySelector(".medium-editor-toolbar-close"),c=a.querySelector(".medium-editor-toolbar-save"),d=a.querySelector(".medium-editor-toolbar-input");this.on(a,"click",this.handleFormClick.bind(this)),this.on(d,"keyup",this.handleTextboxKeyup.bind(this)),this.on(b,"click",this.handleCloseClick.bind(this)),this.on(c,"click",this.handleSaveClick.bind(this),!0)},createForm:function(){var a=this.document,b=a.createElement("div");return b.className="medium-editor-toolbar-form",b.id="medium-editor-toolbar-form-anchor-"+this.getEditorId(),b.innerHTML=this.getTemplate(),this.attachFormEvents(b),b},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},handleTextboxKeyup:function(a){return a.keyCode===b.keyCode.ENTER?(a.preventDefault(),void this.doFormSave()):void(a.keyCode===b.keyCode.ESCAPE&&(a.preventDefault(),this.doFormCancel()))},handleFormClick:function(a){a.stopPropagation()},handleSaveClick:function(a){a.preventDefault(),this.doFormSave()},handleCloseClick:function(a){a.preventDefault(),this.doFormCancel()}})}();var o;!function(){o=e.extend({name:"anchor-preview",hideDelay:500,previewValueSelector:"a",diffLeft:0,diffTop:-10,elementsContainer:!1,init:function(){this.anchorPreview=this.createPreview(),this.elementsContainer||(this.elementsContainer=this.document.body),this.elementsContainer.appendChild(this.anchorPreview),this.attachToEditables()},getPreviewElement:function(){return this.anchorPreview},createPreview:function(){var a=this.document.createElement("div");return a.id="medium-editor-anchor-preview-"+this.getEditorId(),a.className="medium-editor-anchor-preview",a.innerHTML=this.getTemplate(),this.on(a,"click",this.handleClick.bind(this)),a},getTemplate:function(){return'
'},destroy:function(){this.anchorPreview&&(this.anchorPreview.parentNode&&this.anchorPreview.parentNode.removeChild(this.anchorPreview),delete this.anchorPreview)},deactivate:function(){b.deprecatedMethod.call(this,"deactivate","destroy",arguments,"v5.0.0")},hidePreview:function(){this.anchorPreview.classList.remove("medium-editor-anchor-preview-active"),this.activeAnchor=null},showPreview:function(a){return this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")||a.getAttribute("data-disable-preview")?!0:(this.previewValueSelector&&(this.anchorPreview.querySelector(this.previewValueSelector).textContent=a.attributes.href.value,this.anchorPreview.querySelector(this.previewValueSelector).href=a.attributes.href.value),this.anchorPreview.classList.add("medium-toolbar-arrow-over"),this.anchorPreview.classList.remove("medium-toolbar-arrow-under"),this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")||this.anchorPreview.classList.add("medium-editor-anchor-preview-active"),this.activeAnchor=a,this.positionPreview(),this.attachPreviewHandlers(),this)},positionPreview:function(){var a,b,c=this.anchorPreview.offsetHeight,d=this.activeAnchor.getBoundingClientRect(),e=(d.left+d.right)/2;a=this.anchorPreview.offsetWidth/2,b=this.diffLeft-a,this.anchorPreview.style.top=Math.round(c+d.bottom-this.diffTop+this.window.pageYOffset-this.anchorPreview.offsetHeight)+"px",a>e?this.anchorPreview.style.left=b+a+"px":this.window.innerWidth-ethis.hideDelay&&this.detachPreviewHandlers()},detachPreviewHandlers:function(){clearInterval(this.intervalTimer),this.instanceHandlePreviewMouseover&&(this.off(this.anchorPreview,"mouseover",this.instanceHandlePreviewMouseover),this.off(this.anchorPreview,"mouseout",this.instanceHandlePreviewMouseout),this.activeAnchor&&(this.off(this.activeAnchor,"mouseover",this.instanceHandlePreviewMouseover),this.off(this.activeAnchor,"mouseout",this.instanceHandlePreviewMouseout))),this.hidePreview(),this.hovering=this.instanceHandlePreviewMouseover=this.instanceHandlePreviewMouseout=null},attachPreviewHandlers:function(){this.lastOver=(new Date).getTime(),this.hovering=!0,this.instanceHandlePreviewMouseover=this.handlePreviewMouseover.bind(this),this.instanceHandlePreviewMouseout=this.handlePreviewMouseout.bind(this),this.intervalTimer=setInterval(this.updatePreview.bind(this),200),this.on(this.anchorPreview,"mouseover",this.instanceHandlePreviewMouseover),this.on(this.anchorPreview,"mouseout",this.instanceHandlePreviewMouseout),this.on(this.activeAnchor,"mouseover",this.instanceHandlePreviewMouseover),this.on(this.activeAnchor,"mouseout",this.instanceHandlePreviewMouseout)}})}();var p,q,r;q="com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw",r="(((?:(https?://|ftps?://|nntp://)|www\\d{0,3}[.]|[a-z0-9.\\-]+[.]("+q+")\\/)\\S+(?:[^\\s`!\\[\\]{};:'\".,?«»“”‘’])))|(([a-z0-9\\-]+\\.)?[a-z0-9\\-]+\\.("+q+"))",function(){function a(a){return!b.getClosestTag(a,"a")}var c=new RegExp("^("+q+")$","i");p=e.extend({init:function(){this.disableEventHandling=!1,this.subscribe("editableKeypress",this.onKeypress.bind(this)),this.subscribe("editableBlur",this.onBlur.bind(this)),this.document.execCommand("AutoUrlDetect",!1,!1)},destroy:function(){this.document.queryCommandSupported("AutoUrlDetect")&&this.document.execCommand("AutoUrlDetect",!1,!0)},onBlur:function(a,b){this.performLinking(b)},onKeypress:function(a){this.disableEventHandling||b.isKey(a,[b.keyCode.SPACE,b.keyCode.ENTER])&&(clearTimeout(this.performLinkingTimeout),this.performLinkingTimeout=setTimeout(function(){try{var b=this.base.exportSelection();this.performLinking(a.target)&&this.base.importSelection(b,!0)}catch(c){window.console&&window.console.error("Failed to perform linking",c),this.disableEventHandling=!0}}.bind(this),0))},performLinking:function(a){var b=a.querySelectorAll("p"),c=!1;0===b.length&&(b=[a]);for(var d=0;d=c&&d!==e&&0!==f&&(b||a).splitText(f)},removeObsoleteAutoLinkSpans:function(c){for(var d=c.querySelectorAll('span[data-auto-link="true"]'),e=!1,f=0;f0;)d[f].parentNode.insertBefore(d[f].firstChild,d[f]);d[f].parentNode.removeChild(d[f])}}return e},performLinkingWithinElement:function(a){for(var b=this.findLinkableText(a),c=!1,d=0;db.end+1)throw new Error("PerformLinking overshot the target!");f&&d.push(h||g),e+=g.nodeValue.length,null!==h&&(e+=h.nodeValue.length,c.nextNode()),h=null}return d},createLink:function(a,c){for(var d=!1,e=0;e'),c.onload=function(){var a=this.document.getElementById(d);a&&(a.removeAttribute("id"),a.removeAttribute("class"),a.src=c.result)}.bind(this)}}.bind(this))),a.target.classList.remove(d)}})}();var t;!function(){t=m.extend({name:"fontsize",action:"fontSize",aria:"increase/decrease font size",contentDefault:"±",contentFA:'',handleClick:function(a){if(a.preventDefault(),a.stopPropagation(),!this.isDisplayed()){var b=this.document.queryCommandValue("fontSize")+"";this.showForm(b)}return!1},getForm:function(){return this.form||(this.form=this.createForm()),this.form},isDisplayed:function(){return"block"===this.getForm().style.display},hideForm:function(){this.getForm().style.display="none",this.getInput().value=""},showForm:function(a){var b=this.getInput();this.base.saveSelection(),this.base.hideToolbarDefaultActions(),this.getForm().style.display="block",this.base.setToolbarPosition(),b.value=a||"",b.focus()},destroy:function(){return this.form?(this.form.parentNode&&this.form.parentNode.removeChild(this.form),void delete this.form):!1},deactivate:function(){b.deprecatedMethod.call(this,"deactivate","destroy",arguments,"v5.0.0")},doFormSave:function(){this.base.restoreSelection(),this.base.checkSelection()},doFormCancel:function(){this.base.restoreSelection(),this.clearFontSize(),this.base.checkSelection()},createForm:function(){var a=this.document,b=a.createElement("div"),c=a.createElement("input"),d=a.createElement("a"),e=a.createElement("a");return b.className="medium-editor-toolbar-form",b.id="medium-editor-toolbar-form-fontsize-"+this.getEditorId(),this.on(b,"click",this.handleFormClick.bind(this)),c.setAttribute("type","range"),c.setAttribute("min","1"),c.setAttribute("max","7"),c.className="medium-editor-toolbar-input",b.appendChild(c),this.on(c,"change",this.handleSliderChange.bind(this)),e.setAttribute("href","#"),e.className="medium-editor-toobar-save",e.innerHTML="fontawesome"===this.getEditorOption("buttonLabels")?'':"✓",b.appendChild(e),this.on(e,"click",this.handleSaveClick.bind(this),!0),d.setAttribute("href","#"),d.className="medium-editor-toobar-close",d.innerHTML="fontawesome"===this.getEditorOption("buttonLabels")?'':"×",b.appendChild(d),this.on(d,"click",this.handleCloseClick.bind(this)),b},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},clearFontSize:function(){f.getSelectedElements(this.document).forEach(function(a){"FONT"===a.tagName&&a.hasAttribute("size")&&a.removeAttribute("size")})},handleSliderChange:function(){var a=this.getInput().value;"4"===a?this.clearFontSize():this.execAction("fontSize",{size:a})},handleFormClick:function(a){a.stopPropagation()},handleSaveClick:function(a){a.preventDefault(),this.doFormSave()},handleCloseClick:function(a){a.preventDefault(),this.doFormCancel()}})}();var u;!function(){function a(){return[[new RegExp(/<[^>]*docs-internal-guid[^>]*>/gi),""],[new RegExp(/<\/b>(]*>)?$/gi),""],[new RegExp(/\s+<\/span>/g)," "],[new RegExp(/
/g),"
"],[new RegExp(/]*(font-style:italic;font-weight:bold|font-weight:bold;font-style:italic)[^>]*>/gi),''],[new RegExp(/]*font-style:italic[^>]*>/gi),''],[new RegExp(/]*font-weight:bold[^>]*>/gi),''],[new RegExp(/<(\/?)(i|b|a)>/gi),"<$1$2>"],[new RegExp(/<a(?:(?!href).)+href=(?:"|”|“|"|“|”)(((?!"|”|“|"|“|”).)*)(?:"|”|“|"|“|”)(?:(?!>).)*>/gi),''],[new RegExp(/<\/p>\n+/gi),"

"],[new RegExp(/\n+

/gi),""]]}u=e.extend({forcePlainText:!0,cleanPastedHTML:!1,cleanReplacements:[],cleanAttrs:["class","style","dir"],cleanTags:["meta"],targetBlank:!1,disableReturn:!1,init:function(){(this.forcePlainText||this.cleanPastedHTML)&&this.subscribe("editablePaste",this.handlePaste.bind(this)); + +},handlePaste:function(a,c){var d,e,f,g,h="",i="text/html",j="text/plain";if(this.window.clipboardData&&void 0===a.clipboardData&&(a.clipboardData=this.window.clipboardData,i="Text",j="Text"),a.clipboardData&&a.clipboardData.getData&&!a.defaultPrevented){if(a.preventDefault(),f=a.clipboardData.getData(i),g=a.clipboardData.getData(j),this.cleanPastedHTML&&f)return this.cleanPaste(f);if(this.disableReturn||c.getAttribute("data-disable-return"))h=b.htmlEntities(g);else if(d=g.split(/[\r\n]+/g),d.length>1)for(e=0;e"+b.htmlEntities(d[e])+"

");else h=b.htmlEntities(d[0]);b.insertHTMLCommand(this.document,h)}},cleanPaste:function(b){var c,d,e,g=f.getSelectionElement(this.window),h=/
"),this.pasteHTML("

"+d.join("

")+"

");try{this.document.execCommand("insertText",!1,"\n")}catch(j){}for(d=g.querySelectorAll("a,p,div,br"),c=0;c"+d.innerHTML+"":e.innerHTML=d.innerHTML,d.parentNode.replaceChild(e,d);for(f=a.querySelectorAll("span"),c=0;c0&&(d[0].classList.add(this.options.firstButtonClass),d[d.length-1].classList.add(this.options.lastButtonClass)),f},destroy:function(){this.toolbar&&(this.toolbar.parentNode&&this.toolbar.parentNode.removeChild(this.toolbar),delete this.toolbar)},deactivate:function(){b.deprecatedMethod.call(this,"deactivate","destroy",arguments,"v5.0.0")},getToolbarElement:function(){return this.toolbar||(this.toolbar=this.createToolbar()),this.toolbar},getToolbarActionsElement:function(){return this.getToolbarElement().querySelector(".medium-editor-toolbar-actions")},initThrottledMethods:function(){this.throttledPositionToolbar=b.throttle(function(){this.base.isActive&&this.positionToolbarIfShown()}.bind(this))},attachEventHandlers:function(){this.base.subscribe("blur",this.handleBlur.bind(this)),this.base.subscribe("focus",this.handleFocus.bind(this)),this.base.subscribe("editableClick",this.handleEditableClick.bind(this)),this.base.subscribe("editableKeyup",this.handleEditableKeyup.bind(this)),this.base.on(this.options.ownerDocument.documentElement,"mouseup",this.handleDocumentMouseup.bind(this)),this.options.staticToolbar&&this.options.stickyToolbar&&this.base.on(this.options.contentWindow,"scroll",this.handleWindowScroll.bind(this),!0),this.base.on(this.options.contentWindow,"resize",this.handleWindowResize.bind(this))},handleWindowScroll:function(){this.positionToolbarIfShown()},handleWindowResize:function(){this.throttledPositionToolbar()},handleDocumentMouseup:function(a){return a&&a.target&&b.isDescendant(this.getToolbarElement(),a.target)?!1:void this.checkState()},handleEditableClick:function(){setTimeout(function(){this.checkState()}.bind(this),0)},handleEditableKeyup:function(){this.checkState()},handleBlur:function(){clearTimeout(this.hideTimeout),clearTimeout(this.delayShowTimeout),this.hideTimeout=setTimeout(function(){this.hideToolbar()}.bind(this),1)},handleFocus:function(){this.checkState()},isDisplayed:function(){return this.getToolbarElement().classList.contains("medium-editor-toolbar-active")},showToolbar:function(){clearTimeout(this.hideTimeout),this.isDisplayed()||(this.getToolbarElement().classList.add("medium-editor-toolbar-active"),this.base.trigger("showToolbar",{},this.base.getFocusedElement()),"function"==typeof this.options.onShowToolbar&&(b.deprecated("onShowToolbar","the showToolbar custom event","v5.0.0"),this.options.onShowToolbar()))},hideToolbar:function(){this.isDisplayed()&&(this.getToolbarElement().classList.remove("medium-editor-toolbar-active"),this.base.trigger("hideToolbar",{},this.base.getFocusedElement()),this.base.commands.forEach(function(a){"function"==typeof a.onHide&&(b.deprecated("onHide","the hideToolbar custom event","v5.0.0"),a.onHide())}),"function"==typeof this.options.onHideToolbar&&(b.deprecated("onHideToolbar","the hideToolbar custom event","v5.0.0"),this.options.onHideToolbar()))},isToolbarDefaultActionsDisplayed:function(){return"block"===this.getToolbarActionsElement().style.display},hideToolbarDefaultActions:function(){this.isToolbarDefaultActionsDisplayed()&&(this.getToolbarActionsElement().style.display="none")},showToolbarDefaultActions:function(){this.hideExtensionForms(),this.isToolbarDefaultActionsDisplayed()||(this.getToolbarActionsElement().style.display="block"),this.delayShowTimeout=this.base.delay(function(){this.showToolbar()}.bind(this))},hideExtensionForms:function(){this.base.commands.forEach(function(a){a.hasForm&&a.isDisplayed()&&a.hideForm()})},multipleBlockElementsSelected:function(){var a=f.getSelectionHtml.call(this).replace(/<[\S]+><\/[\S]+>/gim,""),b=a.match(/<(p|h[1-6]|blockquote)[^>]*>/g);return!!b&&b.length>1},modifySelection:function(){var a=this.options.contentWindow.getSelection(),c=a.getRangeAt(0);if(this.options.standardizeSelectionStart&&c.startContainer.nodeValue&&c.startOffset===c.startContainer.nodeValue.length){var d=b.findAdjacentTextNodeWithContent(f.getSelectionElement(this.options.contentWindow),c.startContainer,this.options.ownerDocument);if(d){for(var e=0;0===d.nodeValue.substr(e,1).trim().length;)e+=1;var g=this.options.ownerDocument.createRange();g.setStart(d,e),g.setEnd(c.endContainer,c.endOffset),a.removeAllRanges(),a.addRange(g),c=g}}},checkState:function(){if(!this.base.preventSelectionUpdates){if(!this.base.getFocusedElement()||f.selectionInContentEditableFalse(this.options.contentWindow))return this.hideToolbar();var a=f.getSelectionElement(this.options.contentWindow);return!a||-1===this.base.elements.indexOf(a)||a.getAttribute("data-disable-toolbar")?this.hideToolbar():this.options.updateOnEmptySelection&&this.options.staticToolbar?this.showAndUpdateToolbar():""===this.options.contentWindow.getSelection().toString().trim()||this.options.allowMultiParagraphSelection===!1&&this.multipleBlockElementsSelected()?this.hideToolbar():void this.showAndUpdateToolbar()}},getFocusedElement:function(){return this.base.getFocusedElement()},showAndUpdateToolbar:function(){this.modifySelection(),this.setToolbarButtonStates(),this.base.trigger("positionToolbar",{},this.base.getFocusedElement()),this.showToolbarDefaultActions(),this.setToolbarPosition()},setToolbarButtonStates:function(){this.base.commands.forEach(function(a){"function"==typeof a.isActive&&"function"==typeof a.setInactive&&a.setInactive()}.bind(this)),this.checkActiveButtons()},checkActiveButtons:function(){var a,c=[],d=null,e=f.getSelectionRange(this.options.ownerDocument),g=function(b){"function"==typeof b.checkState?b.checkState(a):"function"==typeof b.isActive&&"function"==typeof b.isAlreadyApplied&&"function"==typeof b.setActive&&!b.isActive()&&b.isAlreadyApplied(a)&&b.setActive()};if(e)for(a=f.getSelectedParentElement(e),this.base.commands.forEach(function(a){return"function"==typeof a.queryCommandState&&(d=a.queryCommandState(),null!==d)?void(d&&"function"==typeof a.setActive&&a.setActive()):void c.push(a)});void 0!==a.tagName&&-1===b.parentElements.indexOf(a.tagName.toLowerCase)&&(c.forEach(g),-1===this.base.elements.indexOf(a));)a=a.parentNode},positionToolbarIfShown:function(){this.isDisplayed()&&this.setToolbarPosition()},setToolbarPosition:function(){var a,b=this.base.getFocusedElement(),c=this.options.contentWindow.getSelection();return b?(this.options.staticToolbar?(this.showToolbar(),this.positionStaticToolbar(b)):c.isCollapsed||(this.showToolbar(),this.positionToolbar(c)),a=this.base.getExtensionByName("anchor-preview"),void(a&&"function"==typeof a.hidePreview&&a.hidePreview())):this},positionStaticToolbar:function(a){this.getToolbarElement().style.left="0";var b,c=this.options.ownerDocument.documentElement&&this.options.ownerDocument.documentElement.scrollTop||this.options.ownerDocument.body.scrollTop,d=this.options.contentWindow.innerWidth,e=this.getToolbarElement(),f=a.getBoundingClientRect(),g=f.top+c,h=f.left+f.width/2,i=e.offsetHeight,j=e.offsetWidth,k=j/2;switch(this.options.stickyToolbar?c>g+a.offsetHeight-i?(e.style.top=g+a.offsetHeight-i+"px",e.classList.remove("sticky-toolbar")):c>g-i?(e.classList.add("sticky-toolbar"),e.style.top="0px"):(e.classList.remove("sticky-toolbar"),e.style.top=g-i+"px"):e.style.top=g-i+"px",this.options.toolbarAlign){case"left":b=f.left;break;case"right":b=f.right-j;break;case"center":b=h-k}0>b?b=0:b+j>d&&(b=d-Math.ceil(j)-1),e.style.left=b+"px"},positionToolbar:function(a){this.getToolbarElement().style.left="0";var b=this.options.contentWindow.innerWidth,c=a.getRangeAt(0),d=c.getBoundingClientRect(),e=(d.left+d.right)/2,f=this.getToolbarElement(),g=f.offsetHeight,h=f.offsetWidth,i=h/2,j=50,k=this.options.diffLeft-i;d.tope?f.style.left=k+i+"px":i>b-e?f.style.left=b+k-i+"px":f.style.left=k+e+"px"}}}();var x;return function(){x={button:l,form:m,anchor:n,anchorPreview:o,autoLink:p,fontSize:t,imageDragging:s,paste:u,placeholder:v}}(),function(){function l(a,b){if(this.options.disableReturn||b.getAttribute("data-disable-return"))a.preventDefault();else if(this.options.disableDoubleReturn||b.getAttribute("data-disable-double-return")){var c=f.getSelectionStart(this.options.ownerDocument);(c&&""===c.textContent.trim()||c.previousElementSibling&&""===c.previousElementSibling.textContent.trim())&&a.preventDefault()}}function m(a){var c=f.getSelectionStart(this.options.ownerDocument),d=c&&c.tagName.toLowerCase();"pre"===d&&(a.preventDefault(),b.insertHTMLCommand(this.options.ownerDocument," ")),b.isListItem(c)&&(a.preventDefault(),a.shiftKey?this.options.ownerDocument.execCommand("outdent",!1,null):this.options.ownerDocument.execCommand("indent",!1,null))}function n(a){var c,d=f.getSelectionStart(this.options.ownerDocument),e=d.tagName.toLowerCase(),g=/^(\s+|)?$/i,h=/h\d/i;b.isKey(a,[b.keyCode.BACKSPACE,b.keyCode.ENTER])&&d.previousElementSibling&&h.test(e)&&0===f.getCaretOffsets(d).left?b.isKey(a,b.keyCode.BACKSPACE)&&g.test(d.previousElementSibling.innerHTML)?(d.previousElementSibling.parentNode.removeChild(d.previousElementSibling),a.preventDefault()):b.isKey(a,b.keyCode.ENTER)&&(c=this.options.ownerDocument.createElement("p"),c.innerHTML="
",d.previousElementSibling.parentNode.insertBefore(c,d),a.preventDefault()):b.isKey(a,b.keyCode.DELETE)&&d.nextElementSibling&&d.previousElementSibling&&!h.test(e)&&g.test(d.innerHTML)&&h.test(d.nextElementSibling.tagName)?(f.moveCursor(this.options.ownerDocument,d.nextElementSibling),d.previousElementSibling.parentNode.removeChild(d),a.preventDefault()):b.isKey(a,b.keyCode.BACKSPACE)&&"li"===e&&g.test(d.innerHTML)&&!d.previousElementSibling&&!d.parentElement.previousElementSibling&&d.nextElementSibling&&"li"===d.nextElementSibling.tagName.toLowerCase()&&(c=this.options.ownerDocument.createElement("p"),c.innerHTML="
",d.parentElement.parentElement.insertBefore(c,d.parentElement),f.moveCursor(this.options.ownerDocument,c),d.parentElement.removeChild(d),a.preventDefault())}function o(a){var c,d=f.getSelectionStart(this.options.ownerDocument);d&&(d.getAttribute("data-medium-element")&&0===d.children.length&&this.options.ownerDocument.execCommand("formatBlock",!1,"p"),b.isKey(a,b.keyCode.ENTER)&&!b.isListItem(d)&&(c=d.tagName.toLowerCase(),"a"===c?this.options.ownerDocument.execCommand("unlink",!1,null):a.shiftKey||a.ctrlKey||/h\d/.test(c)||this.options.ownerDocument.execCommand("formatBlock",!1,"p")))}function p(a){a||(a=[]),"string"==typeof a&&(a=this.options.ownerDocument.querySelectorAll(a)),b.isElement(a)&&(a=[a]);var c=Array.prototype.slice.apply(a);this.elements=[],c.forEach(function(a){this.elements.push("textarea"===a.tagName.toLowerCase()?y.call(this,a):a)},this)}function q(a,b){return Object.keys(b).forEach(function(c){void 0===a[c]&&(a[c]=b[c])}),a}function r(a,c,d){"undefined"!=typeof a.parent&&b.warn("Extension .parent property has been deprecated. The .base property for extensions will always be set to MediumEditor in version 5.0.0");var e={window:d.options.contentWindow,document:d.options.ownerDocument};return a.parent!==!1&&(e.base=d),a=q(a,e),"function"==typeof a.init&&a.init(d),a.name||(a.name=c),a}function s(){var a,b=!1;if(this.options.disableAnchorPreview)return!1;if(this.options.anchorPreview===!1)return!1;if(this.options.extensions["anchor-preview"])return!1;if(this.options.disableToolbar)return!1;for(a=0;a0&&(a=f.getRangeAt(0),c=a.cloneRange(),this.elements.some(function(c,d){return c===a.startContainer||b.isDescendant(c,a.startContainer)?(g=d,!0):!1}),g>-1&&(c.selectNodeContents(this.elements[g]),c.setEnd(a.startContainer,a.startOffset),d=c.toString().length,e={start:d,end:d+a.toString().length,editableElementIndex:g})),null!==e&&0===e.editableElementIndex&&delete e.editableElementIndex,e},saveSelection:function(){this.selectionState=this.exportSelection()},importSelection:function(a,b){if(a){var c,d,e,g,h=void 0===a.editableElementIndex?0:a.editableElementIndex,i={editableElementIndex:h,start:a.start,end:a.end},j=this.elements[i.editableElementIndex],k=0,l=this.options.ownerDocument.createRange(),m=[j],n=!1,o=!1;for(l.setStart(j,0),l.collapse(!0),c=m.pop();!o&&c;){if(3===c.nodeType)g=k+c.length,!n&&i.start>=k&&i.start<=g&&(l.setStart(c,i.start-k),n=!0),n&&i.end>=k&&i.end<=g&&(l.setEnd(c,i.end-k),o=!0),k=g;else for(d=c.childNodes.length-1;d>=0;)m.push(c.childNodes[d]),d-=1;o||(c=m.pop())}b&&(l=f.importSelectionMoveCursorPastAnchor(i,l)),e=this.options.contentWindow.getSelection(),e.removeAllRanges(),e.addRange(l)}},restoreSelection:function(){this.importSelection(this.selectionState)},createLink:function(a){var c,d;if(a.url&&a.url.trim().length>0&&(this.options.ownerDocument.execCommand("createLink",!1,a.url),(this.options.targetBlank||"_blank"===a.target)&&b.setTargetBlank(f.getSelectionStart(this.options.ownerDocument),a.url),a.buttonClass&&b.addClassToAnchors(f.getSelectionStart(this.options.ownerDocument),a.buttonClass)),this.options.targetBlank||"_blank"===a.target||a.buttonClass)for(c=this.options.ownerDocument.createEvent("HTMLEvents"),c.initEvent("input",!0,!0,this.options.contentWindow),d=0;d", "contributors": [ { diff --git a/src/js/version.js b/src/js/version.js index 41ebe012d..eb799c352 100644 --- a/src/js/version.js +++ b/src/js/version.js @@ -11,5 +11,5 @@ MediumEditor.version = (function (major, minor, revision) { }; }).apply(this, ({ // grunt-bump looks for this: - 'version': '4.11.1' + 'version': '4.12.0' }).version.split('.'));