Socket
Socket
Sign inDemoInstall

medium-editor

Package Overview
Dependencies
Maintainers
3
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

medium-editor - npm Package Compare versions

Comparing version 3.0.7 to 3.0.8

8

bower.json
{
"name": "medium-editor",
"version": "3.0.7",
"version": "3.0.8",
"homepage": "http://daviferreira.github.io/medium-editor/",
"authors": [
"Davi Ferreira <hi@daviferreira.com>"
"Davi Ferreira <hi@daviferreira.com>",
"Nate Mielnik <nathan@outlook.com>",
"Noah Chase <nchase@gmail.com>"
],

@@ -19,3 +21,3 @@ "description": "Medium.com WYSIWYG editor clone written in pure JavaScript.",

],
"license": "THE BEER-WARE LICENSE",
"license": "MIT",
"ignore": [

@@ -22,0 +24,0 @@ "**/.*",

@@ -0,1 +1,8 @@

3.0.8 / 2015-02-27
==================
* MIT License
* Use code from selection.js which is duplicated in core.js
* Fix bug in paste handling + increase paste coverage
3.0.7 / 2015-02-26

@@ -2,0 +9,0 @@ ==================

@@ -1,2 +0,2 @@

"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(++c<d);e&&this._updateClassName()},k.remove=function(){var a,b,c=arguments,d=0,e=c.length,f=!1;do for(a=c[d]+"",b=i(this,a);-1!==b;)this.splice(b,1),f=!0,b=i(this,a);while(++d<e);f&&this._updateClassName()},k.toggle=function(a,b){a+="";var c=this.contains(a),d=c?b!==!0&&"remove":b!==!1&&"add";return d&&this[d](a),b===!0||b===!1?b:!c},k.toString=function(){return this.join(" ")},e.defineProperty){var m={get:l,enumerable:!0,configurable:!0};try{e.defineProperty(d,b,m)}catch(n){-2146823252===n.number&&(m.enumerable=!1,e.defineProperty(d,b,m))}}else e[c].__defineGetter__&&d.__defineGetter__(b,l)}}(self),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(a,b,c){var d;a=a||{};for(d in b)b.hasOwnProperty(d)&&(c||a.hasOwnProperty(d)===!1)&&(a[d]=b[d]);return a}b={isIE:"Microsoft Internet Explorer"===navigator.appName||"Netscape"===navigator.appName&&null!==new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})").exec(navigator.userAgent),keyCode:{BACKSPACE:8,TAB:9,ENTER:13,ESCAPE:27,SPACE:32,DELETE:46},parentElements:["p","h1","h2","h3","h4","h5","h6","blockquote","pre"],defaults:function(a,b){return c(a,b)},extend:function(a,b){return c(a,b,!0)},derives:function(a,b){function d(){}var e=b.prototype;return d.prototype=a.prototype,b.prototype=new d,b.prototype.constructor=a,b.prototype=c(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){if(!a||!b)return!1;for(var c=b.parentNode;null!==c;){if(c===a)return!0;c=c.parentNode}return!1},isElement:function(a){return!(!a||1!==a.nodeType)},now:function(){return Date.now||(new Date).getTime()},throttle:function(a,c){var d,e,f,g,h=50,i=null,j=0;return c||0===c||(c=h),g=function(){j=b.now(),i=null,f=a.apply(d,e),i||(d=e=null)},function(){var h=b.now(),k=c-(h-j);return d=this,e=arguments,0>=k||k>c?(clearTimeout(i),i=null,j=h,f=a.apply(d,e),i||(d=e=null)):i||(i=setTimeout(g,k)),f}},traverseUp:function(a,b){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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},insertHTMLCommand:function(b,c){var d,e,f,g,h,i;if(b.queryCommandSupported("insertHTML"))try{return b.execCommand("insertHTML",!1,c)}catch(j){}if(d=a.getSelection(),d.getRangeAt&&d.rangeCount){for(e=d.getRangeAt(0),e.deleteContents(),f=b.createElement("div"),f.innerHTML=c,g=b.createDocumentFragment();f.firstChild;)h=f.firstChild,i=g.appendChild(h);e.insertNode(g),i&&(e=e.cloneRange(),e.setStartAfter(i),e.collapse(!0),d.removeAllRanges(),d.addRange(e))}},setTargetBlank:function(a){var b;if("a"===a.tagName.toLowerCase())a.target="_blank";else for(a=a.getElementsByTagName("a"),b=0;b<a.length;b+=1)a[b].target="_blank"},isListItemChild:function(a){for(var b=a.parentNode,c=b.tagName.toLowerCase();-1===this.parentElements.indexOf(c)&&"div"!==c;){if("li"===c)return!0;if(b=b.parentNode,!b||!b.tagName)return!1;c=b.tagName.toLowerCase()}return!1}}}(window,document);var c;!function(a){c={getSelectionStart:function(a){var b=a.getSelection().anchorNode,c=b&&3===b.nodeType?b.parentNode:b;return c},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)},selectionInContentEditableFalse:function(a){return this.findMatchingSelectionParent(function(a){return a&&"#text"!==a.nodeName&&"false"===a.getAttribute("contenteditable")},a)},getSelectionHtml:function(){var a,b,c,d,e="";if(void 0!==this.options.contentWindow.getSelection){if(b=this.options.contentWindow.getSelection(),b.rangeCount){for(d=this.options.ownerDocument.createElement("div"),a=0,c=b.rangeCount;c>a;a+=1)d.appendChild(b.getRangeAt(a).cloneContents());e=d.innerHTML}}else void 0!==this.options.ownerDocument.selection&&"Text"===this.options.ownerDocument.selection.type&&(e=this.options.ownerDocument.selection.createRange().htmlText);return e},getCaretOffsets:function(b,c){var d,e;return c||(c=a.getSelection().getRangeAt(0)),d=c.cloneRange(),e=c.cloneRange(),d.selectNodeContents(b),d.setEnd(c.endContainer,c.endOffset),e.selectNodeContents(b),e.setStart(c.endContainer,c.endOffset),{left:d.toString().length,right:e.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},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}}}}(document,window);var d,e;!function(){e={bold:{name:"bold",action:"bold",aria:"bold",tagNames:["b","strong"],style:{prop:"font-weight",value:"700|bold"},useQueryState:!0,contentDefault:"<b>B</b>",contentFA:'<i class="fa fa-bold"></i>',key:"b"},italic:{name:"italic",action:"italic",aria:"italic",tagNames:["i","em"],style:{prop:"font-style",value:"italic"},useQueryState:!0,contentDefault:"<b><i>I</i></b>",contentFA:'<i class="fa fa-italic"></i>',key:"i"},underline:{name:"underline",action:"underline",aria:"underline",tagNames:["u"],style:{prop:"text-decoration",value:"underline"},useQueryState:!0,contentDefault:"<b><u>U</u></b>",contentFA:'<i class="fa fa-underline"></i>',key:"u"},strikethrough:{name:"strikethrough",action:"strikethrough",aria:"strike through",tagNames:["strike"],style:{prop:"text-decoration",value:"line-through"},useQueryState:!0,contentDefault:"<s>A</s>",contentFA:'<i class="fa fa-strikethrough"></i>'},superscript:{name:"superscript",action:"superscript",aria:"superscript",tagNames:["sup"],contentDefault:"<b>x<sup>1</sup></b>",contentFA:'<i class="fa fa-superscript"></i>'},subscript:{name:"subscript",action:"subscript",aria:"subscript",tagNames:["sub"],contentDefault:"<b>x<sub>1</sub></b>",contentFA:'<i class="fa fa-subscript"></i>'},image:{name:"image",action:"image",aria:"image",tagNames:["img"],contentDefault:"<b>image</b>",contentFA:'<i class="fa fa-picture-o"></i>'},quote:{name:"quote",action:"append-blockquote",aria:"blockquote",tagNames:["blockquote"],contentDefault:"<b>&ldquo;</b>",contentFA:'<i class="fa fa-quote-right"></i>'},orderedlist:{name:"orderedlist",action:"insertorderedlist",aria:"ordered list",tagNames:["ol"],useQueryState:!0,contentDefault:"<b>1.</b>",contentFA:'<i class="fa fa-list-ol"></i>'},unorderedlist:{name:"unorderedlist",action:"insertunorderedlist",aria:"unordered list",tagNames:["ul"],useQueryState:!0,contentDefault:"<b>&bull;</b>",contentFA:'<i class="fa fa-list-ul"></i>'},pre:{name:"pre",action:"append-pre",aria:"preformatted text",tagNames:["pre"],contentDefault:"<b>0101</b>",contentFA:'<i class="fa fa-code fa-lg"></i>'},indent:{name:"indent",action:"indent",aria:"indent",tagNames:[],contentDefault:"<b>&rarr;</b>",contentFA:'<i class="fa fa-indent"></i>'},outdent:{name:"outdent",action:"outdent",aria:"outdent",tagNames:[],contentDefault:"<b>&larr;</b>",contentFA:'<i class="fa fa-outdent"></i>'},justifyCenter:{name:"justifyCenter",action:"justifyCenter",aria:"center justify",tagNames:[],style:{prop:"text-align",value:"center"},useQueryState:!0,contentDefault:"<b>C</b>",contentFA:'<i class="fa fa-align-center"></i>'},justifyFull:{name:"justifyFull",action:"justifyFull",aria:"full justify",tagNames:[],style:{prop:"text-align",value:"justify"},useQueryState:!0,contentDefault:"<b>J</b>",contentFA:'<i class="fa fa-align-justify"></i>'},justifyLeft:{name:"justifyLeft",action:"justifyLeft",aria:"left justify",tagNames:[],style:{prop:"text-align",value:"left"},useQueryState:!0,contentDefault:"<b>L</b>",contentFA:'<i class="fa fa-align-left"></i>'},justifyRight:{name:"justifyRight",action:"justifyRight",aria:"right justify",tagNames:[],style:{prop:"text-align",value:"right"},useQueryState:!0,contentDefault:"<b>R</b>",contentFA:'<i class="fa fa-align-right"></i>'},header1:{name:"header1",action:function(a){return"append-"+a.firstHeader},aria:function(a){return a.firstHeader},tagNames:function(a){return[a.firstHeader]},contentDefault:"<b>H1</b>"},header2:{name:"header2",action:function(a){return"append-"+a.secondHeader},aria:function(a){return a.secondHeader},tagNames:function(a){return[a.secondHeader]},contentDefault:"<b>H2</b>"}},d=function(a,b){this.options=a,this.name=a.name,this.init(b)},d.prototype={init:function(a){this.base=a,this.button=this.createButton(),this.base.on(this.button,"click",this.handleClick.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;return a.classList.add("medium-editor-action"),a.classList.add("medium-editor-action-"+this.name),a.setAttribute("data-action",this.getAction()),a.setAttribute("aria-label",this.getAria()),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},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||(this.knownState=d=-1!==c.indexOf(a))}.bind(this))),d)}}}(window,document);var f;!function(){function a(){return[[new RegExp(/<[^>]*docs-internal-guid[^>]*>/gi),""],[new RegExp(/<\/b>(<br[^>]*>)?$/gi),""],[new RegExp(/<span class="Apple-converted-space">\s+<\/span>/g)," "],[new RegExp(/<br class="Apple-interchange-newline">/g),"<br>"],[new RegExp(/<span[^>]*(font-style:italic;font-weight:bold|font-weight:bold;font-style:italic)[^>]*>/gi),'<span class="replace-with italic bold">'],[new RegExp(/<span[^>]*font-style:italic[^>]*>/gi),'<span class="replace-with italic">'],[new RegExp(/<span[^>]*font-weight:bold[^>]*>/gi),'<span class="replace-with bold">'],[new RegExp(/&lt;(\/?)(i|b|a)&gt;/gi),"<$1$2>"],[new RegExp(/&lt;a\s+href=(&quot;|&rdquo;|&ldquo;|“|”)([^&]+)(&quot;|&rdquo;|&ldquo;|“|”)&gt;/gi),'<a href="$2">']]}f={handlePaste:function(a,c,d){var e,f,g="",h="text/html",i="text/plain";if(a.classList.remove("medium-editor-placeholder"),!d.forcePlainText&&!d.cleanPastedHTML)return a;if(d.contentWindow.clipboardData&&void 0===c.clipboardData&&(c.clipboardData=d.contentWindow.clipboardData,h="Text",i="Text"),c.clipboardData&&c.clipboardData.getData&&!c.defaultPrevented){if(c.preventDefault(),d.cleanPastedHTML&&c.clipboardData.getData(h))return this.cleanPaste(c.clipboardData.getData(h),d);if(d.disableReturn||a.getAttribute("data-disable-return"))g=b.htmlEntities(c.clipboardData.getData(i)),b.insertHTMLCommand(d.ownerDocument,g);else{for(e=c.clipboardData.getData(i).split(/[\r\n]/g),f=0;f<e.length;f+=1)""!==e[f]&&(g+="<p>"+b.htmlEntities(e[f])+"</p>");b.insertHTMLCommand(d.ownerDocument,g)}}},cleanPaste:function(d,e){var f,g,h,i=c.getSelectionElement(e.contentWindow),j=/<p|<br|<div/.test(d),k=a();for(f=0;f<k.length;f+=1)d=d.replace(k[f][0],k[f][1]);if(j){g=d.split("<br><br>"),this.pasteHTML("<p>"+g.join("</p><p>")+"</p>",e.ownerDocument);try{e.ownerDocument.execCommand("insertText",!1,"\n")}catch(l){}for(g=i.querySelectorAll("a,p,div,br"),f=0;f<g.length;f+=1)switch(h=g[f],h.tagName.toLowerCase()){case"a":e.targetBlank&&b.setTargetBlank(h);break;case"p":case"div":this.filterCommonBlocks(h);break;case"br":this.filterLineBreak(h)}}else this.pasteHTML(d,e.ownerDocument)},pasteHTML:function(a,c){var d,e,f,g,h=c.createDocumentFragment();for(h.appendChild(c.createElement("body")),g=h.querySelector("body"),g.innerHTML=a,this.cleanupSpans(g,c),d=g.querySelectorAll("*"),f=0;f<d.length;f+=1)e=d[f],e.removeAttribute("class"),e.removeAttribute("style"),e.removeAttribute("dir"),"meta"===e.tagName.toLowerCase()&&e.parentNode.removeChild(e);b.insertHTMLCommand(c,g.innerHTML.replace(/&nbsp;/g," "))},isCommonBlock:function(a){return a&&("p"===a.tagName.toLowerCase()||"div"===a.tagName.toLowerCase())},filterCommonBlocks:function(a){/^\s*$/.test(a.textContent)&&a.parentNode.removeChild(a)},filterLineBreak:function(a){this.isCommonBlock(a.previousElementSibling)?a.parentNode.removeChild(a):!this.isCommonBlock(a.parentNode)||a.parentNode.firstChild!==a&&a.parentNode.lastChild!==a?1===a.parentNode.childElementCount&&""===a.parentNode.textContent&&this.removeWithParent(a):a.parentNode.removeChild(a)},removeWithParent:function(a){a&&a.parentNode&&(a.parentNode.parentNode&&1===a.parentNode.childElementCount?a.parentNode.parentNode.removeChild(a.parentNode):a.parentNode.removeChild(a.parentNode))},cleanupSpans:function(a,c){var d,e,f,g=a.querySelectorAll(".replace-with"),h=function(a){return a&&"#text"!==a.nodeName&&"false"===a.getAttribute("contenteditable")};for(d=0;d<g.length;d+=1)e=g[d],f=c.createElement(e.classList.contains("bold")?"b":"i"),f.innerHTML=e.classList.contains("bold")&&e.classList.contains("italic")?"<i>"+e.innerHTML+"</i>":e.innerHTML,e.parentNode.replaceChild(f,e);for(g=a.querySelectorAll("span"),d=0;d<g.length;d+=1){if(e=g[d],b.traverseUp(e,h))return!1;/^\s*$/.test()?e.parentNode.removeChild(e):e.parentNode.replaceChild(c.createTextNode(e.textContent),e)}}}}(window,document);var g;return function(){function a(){this.parent=!0,this.options={name:"anchor",action:"createLink",aria:"link",tagNames:["a"],contentDefault:"<b>#</b>",contentFA:'<i class="fa fa-link"></i>'},this.name="anchor",this.hasForm=!0}a.prototype={handleClick:function(a){a.preventDefault(),a.stopPropagation(),this.base.selection||this.base.checkSelection();var b=c.getSelectedParentElement(this.base.selectionRange);return b.tagName&&"a"===b.tagName.toLowerCase()?this.base.execAction("unlink"):(this.isDisplayed()||this.showForm(),!1)},getForm:function(){return this.anchorForm||(this.anchorForm=this.createForm()),this.anchorForm},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(),this.base.keepToolbarAlive=!0,b.value=a||"",b.focus()},deactivate:function(){return this.anchorForm?(this.anchorForm.parentNode&&this.anchorForm.parentNode.removeChild(this.anchorForm),void delete this.anchorForm):!1},doLinkCreation: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};this.base.restoreSelection(),this.base.options.checkLinkFormat&&(c.url=this.checkLinkFormat(c.url)),c.target=a&&a.checked?"_blank":"_self",b&&b.checked&&(c.buttonClass=this.base.options.anchorButtonClass),this.base.createLink(c),this.base.keepToolbarAlive=!1,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.keepToolbarAlive=!1,this.base.checkSelection()},createForm:function(){var a,b,c,d,e=this.base.options.ownerDocument,f=e.createElement("div"),g=e.createElement("input"),h=e.createElement("a"),i=e.createElement("a");return f.className="medium-editor-toolbar-form",f.id="medium-editor-toolbar-form-anchor-"+this.base.id,this.base.on(f,"click",this.handleFormClick.bind(this)),g.setAttribute("type","text"),g.className="medium-editor-toolbar-input",g.setAttribute("placeholder",this.base.options.anchorInputPlaceholder),f.appendChild(g),this.base.on(g,"keyup",this.handleTextboxKeyup.bind(this)),this.base.on(g,"click",this.handleFormClick.bind(this)),i.setAttribute("href","#"),i.className="medium-editor-toobar-save",i.innerHTML="fontawesome"===this.base.options.buttonLabels?'<i class="fa fa-check"></i>':"&#10003;",f.appendChild(i),this.base.on(i,"click",this.handleSaveClick.bind(this),!0),h.setAttribute("href","#"),h.className="medium-editor-toobar-close",h.innerHTML="fontawesome"===this.base.options.buttonLabels?'<i class="fa fa-times"></i>':"&times;",f.appendChild(h),this.base.on(h,"click",this.handleCloseClick.bind(this)),this.base.options.anchorTarget&&(a=e.createElement("input"),a.setAttribute("type","checkbox"),a.className="medium-editor-toolbar-anchor-target",b=e.createElement("label"),b.innerHTML=this.base.options.anchorInputCheckboxLabel,b.insertBefore(a,b.firstChild),f.appendChild(b)),this.base.options.anchorButton&&(c=e.createElement("input"),c.setAttribute("type","checkbox"),c.className="medium-editor-toolbar-anchor-button",d=e.createElement("label"),d.innerHTML="Button",d.insertBefore(c,d.firstChild),f.appendChild(d)),this.base.on(e.body,"click",this.handleOutsideInteraction.bind(this),!0),this.base.on(e.body,"focus",this.handleOutsideInteraction.bind(this),!0),f},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},handleOutsideInteraction:function(a){a.target===this.getForm()||b.isDescendant(this.getForm(),a.target)||b.isDescendant(this.base.toolbarActions,a.target)||(this.base.keepToolbarAlive=!1,this.base.checkSelection())},handleTextboxKeyup:function(a){return a.keyCode===b.keyCode.ENTER?(a.preventDefault(),void this.doLinkCreation()):void(a.keyCode===b.keyCode.ESCAPE&&(a.preventDefault(),this.doFormCancel()))},handleFormClick:function(a){a.stopPropagation(),this.base.keepToolbarAlive=!0},handleSaveClick:function(a){a.preventDefault(),this.doLinkCreation()},handleCloseClick:function(a){a.preventDefault(),this.doFormCancel()}},g=b.derives(d,a)}(window,document),function(){a.statics={ButtonsData:e,DefaultButton:d,AnchorExtension:g},a.prototype={defaults:{allowMultiParagraphSelection:!0,anchorInputPlaceholder:"Paste or type a link",anchorInputCheckboxLabel:"Open in new window",anchorPreviewHideDelay:500,buttons:["bold","italic","underline","anchor","header1","header2","quote"],buttonLabels:!1,checkLinkFormat:!1,cleanPastedHTML:!1,delay:0,diffLeft:0,diffTop:-10,disableReturn:!1,disableDoubleReturn:!1,disableToolbar:!1,disableEditing:!1,disablePlaceholders:!1,toolbarAlign:"center",elementsContainer:!1,imageDragging:!0,standardizeSelectionStart:!1,contentWindow:window,ownerDocument:document,firstHeader:"h3",forcePlainText:!0,placeholder:"Type your text",secondHeader:"h4",targetBlank:!1,anchorTarget:!1,anchorButton:!1,anchorButtonClass:"btn",extensions:{},activeButtonClass:"medium-editor-button-active",firstButtonClass:"medium-editor-button-first",lastButtonClass:"medium-editor-button-last"},init:function(a,c){var d=1;if(this.options=b.defaults(c,this.defaults),this.setElementSelection(a),0!==this.elements.length){for(this.options.elementsContainer||(this.options.elementsContainer=this.options.ownerDocument.body);this.options.elementsContainer.querySelector("#medium-editor-toolbar-"+d);)d+=1;return this.id=d,this.setup()}},setup:function(){this.events=[],this.isActive=!0,this.initThrottledMethods().initCommands().initElements().bindSelect().bindDragDrop().bindPaste().setPlaceholders().bindElementActions().bindWindowActions()},on:function(a,b,c,d){a.addEventListener(b,c,d),this.events.push([a,b,c,d])},off: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},delay:function(a){var b=this;setTimeout(function(){b.isActive&&a()},this.options.delay)},removeAllEvents:function(){for(var a=this.events.pop();a;)a[0].removeEventListener(a[1],a[2],a[3]),a=this.events.pop()},initThrottledMethods:function(){var a=this;return this.handleResize=b.throttle(function(){a.isActive&&a.positionToolbarIfShown()}),this.handleBlur=b.throttle(function(){a.isActive&&!a.keepToolbarAlive&&a.hideToolbarActions()}),this},initElements:function(){var a,b=!1;for(a=0;a<this.elements.length;a+=1)this.options.disableEditing||this.elements[a].getAttribute("data-disable-editing")||this.elements[a].setAttribute("contentEditable",!0),this.elements[a].getAttribute("data-placeholder")||this.elements[a].setAttribute("data-placeholder",this.options.placeholder),this.elements[a].setAttribute("data-medium-element",!0),this.elements[a].setAttribute("role","textbox"),this.elements[a].setAttribute("aria-multiline",!0),this.bindParagraphCreation(a),this.options.disableToolbar||this.elements[a].getAttribute("data-disable-toolbar")||(b=!0);return b&&this.initToolbar().setFirstAndLastButtons().bindAnchorPreview(),this},setElementSelection:function(a){a||(a=[]),"string"==typeof a&&(a=this.options.ownerDocument.querySelectorAll(a)),b.isElement(a)&&(a=[a]),this.elements=Array.prototype.slice.apply(a)},bindBlur:function(){var a=this,d=function(d){var e,f=!1,g=a.options.contentWindow.getSelection(),h=g.isCollapsed?null:c.getSelectedParentElement(g.getRangeAt(0));for(e=0;e<a.elements.length;e+=1)if(b.isDescendant(a.elements[e],d.target)||b.isDescendant(a.elements[e],h)){f=!0;break}d.target===a.toolbar||-1!==a.elements.indexOf(d.target)||f||b.isDescendant(a.toolbar,d.target)||b.isDescendant(a.anchorPreview,d.target)||(a.options.disablePlaceholders||a.placeholderWrapper(d,a.elements[0]),a.handleBlur())};return this.on(this.options.ownerDocument.body,"click",d,!0),this.on(this.options.ownerDocument.body,"focus",d,!0),this},bindClick:function(a){var b=this;return this.on(this.elements[a],"click",function(){b.options.disablePlaceholders||this.classList.remove("medium-editor-placeholder"),b.options.staticToolbar&&b.setToolbarPosition()}),this},bindElementActions:function(){var a;for(a=0;a<this.elements.length;a+=1)this.options.disablePlaceholders||this.activatePlaceholder(this.elements[a]),this.bindReturn(a).bindKeydown(a).bindClick(a);return this},activatePlaceholder:function(a){a.querySelector("img")||a.querySelector("blockquote")||""!==a.textContent.replace(/^\s+|\s+$/g,"")||a.classList.add("medium-editor-placeholder")},placeholderWrapper:function(a,b){b=b||a.target,b.classList.remove("medium-editor-placeholder"),"keypress"!==a.type&&this.activatePlaceholder(b)},serialize:function(){var a,b,c={};for(a=0;a<this.elements.length;a+=1)b=""!==this.elements[a].id?this.elements[a].id:"element-"+a,c[b]={value:this.elements[a].innerHTML.trim()};return c},initExtension:function(a,b){return a.parent&&(a.base=this),"function"==typeof a.init&&a.init(this),a.name||(a.name=b),a},initCommands:function(){var a,b,c=this.options.buttons,f=this.options.extensions;this.commands=[],c.forEach(function(b){f[b]?(a=this.initExtension(f[b],b),this.commands.push(a)):"anchor"===b?(a=this.initExtension(new g,b),this.commands.push(a)):e.hasOwnProperty(b)&&(a=new d(e[b],this),this.commands.push(a))}.bind(this));for(b in f)f.hasOwnProperty(b)&&-1===c.indexOf(b)&&(a=this.initExtension(f[b],b));return this},getExtensionByName:function(a){var b;return this.commands&&this.commands.length&&this.commands.forEach(function(c){c.name===a&&(b=c)}),b},callExtensions:function(a){if(!(arguments.length<1)){var b,c,d=Array.prototype.slice.call(arguments,1);for(c in this.options.extensions)this.options.extensions.hasOwnProperty(c)&&(b=this.options.extensions[c],void 0!==b[a]&&b[a].apply(b,d));return this}},bindParagraphCreation:function(a){var d=this;return this.on(this.elements[a],"keypress",function(a){var e,f;a.which===b.keyCode.SPACE&&(e=c.getSelectionStart(d.options.ownerDocument),f=e.tagName.toLowerCase(),"a"===f&&d.options.ownerDocument.execCommand("unlink",!1,null))}),this.on(this.elements[a],"keyup",function(a){var e,f,g=c.getSelectionStart(d.options.ownerDocument);g&&g.getAttribute("data-medium-element")&&0===g.children.length&&!d.options.disableReturn&&!g.getAttribute("data-disable-return")&&d.options.ownerDocument.execCommand("formatBlock",!1,"p"),a.which===b.keyCode.ENTER&&(g=c.getSelectionStart(d.options.ownerDocument),e=g.tagName.toLowerCase(),f=c.getSelectionElement(d.options.contentWindow),d.options.disableReturn||f.getAttribute("data-disable-return")||"li"===e||b.isListItemChild(g)||(a.shiftKey||/h\d/.test(e)||d.options.ownerDocument.execCommand("formatBlock",!1,"p"),"a"===e&&d.options.ownerDocument.execCommand("unlink",!1,null)))}),this},bindReturn:function(a){var d=this;return this.on(this.elements[a],"keypress",function(a){if(a.which===b.keyCode.ENTER)if(d.options.disableReturn||this.getAttribute("data-disable-return"))a.preventDefault();else if(d.options.disableDoubleReturn||this.getAttribute("data-disable-double-return")){var e=c.getSelectionStart(d.options.contentWindow);e&&""===e.textContent.trim()&&a.preventDefault()}}),this},bindKeydown:function(a){var d=this;return this.on(this.elements[a],"keydown",function(a){var e,f,g;a.which===b.keyCode.TAB?(e=c.getSelectionStart(d.options.ownerDocument),f=e&&e.tagName.toLowerCase(),"pre"===f&&(a.preventDefault(),d.options.ownerDocument.execCommand("insertHtml",null," ")),("li"===f||b.isListItemChild(e))&&(a.preventDefault(),a.shiftKey?d.options.ownerDocument.execCommand("outdent",a):d.options.ownerDocument.execCommand("indent",a))):a.which===b.keyCode.BACKSPACE||a.which===b.keyCode.DELETE||a.which===b.keyCode.ENTER?d.onBlockModifier(a):(a.ctrlKey||a.metaKey)&&(g=String.fromCharCode(a.which||a.keyCode).toLowerCase(),d.commands.forEach(function(b){b.options.key&&b.options.key===g&&b.handleClick(a)}))}),this},onBlockModifier:function(a){var d,e,f,g=c.getSelectionStart(this.options.ownerDocument),h=g.tagName.toLowerCase(),i=/^(\s+|<br\/?>)?$/i,j=/h\d/i;(a.which===b.keyCode.BACKSPACE||a.which===b.keyCode.ENTER)&&g.previousElementSibling&&j.test(h)&&0===c.getCaretOffsets(g).left?a.which===b.keyCode.BACKSPACE&&i.test(g.previousElementSibling.innerHTML)?(g.previousElementSibling.parentNode.removeChild(g.previousElementSibling),a.preventDefault()):a.which===b.keyCode.ENTER&&(f=this.options.ownerDocument.createElement("p"),f.innerHTML="<br>",g.previousElementSibling.parentNode.insertBefore(f,g),a.preventDefault()):a.which===b.keyCode.DELETE&&g.nextElementSibling&&g.previousElementSibling&&!j.test(h)&&i.test(g.innerHTML)&&j.test(g.nextElementSibling.tagName)&&(d=document.createRange(),e=window.getSelection(),d.setStart(g.nextElementSibling,0),d.collapse(!0),e.removeAllRanges(),e.addRange(d),g.previousElementSibling.parentNode.removeChild(g),a.preventDefault())},initToolbar:function(){return this.toolbar?this:(this.toolbar=this.createToolbar(),this.keepToolbarAlive=!1,this.toolbarActions=this.toolbar.querySelector(".medium-editor-toolbar-actions"),this.anchorPreview=this.createAnchorPreview(),this)},createToolbar:function(){var a=this.options.ownerDocument.createElement("div");return a.id="medium-editor-toolbar-"+this.id,a.className="medium-editor-toolbar",a.className+=this.options.staticToolbar?" static-toolbar":" stalker-toolbar",a.appendChild(this.toolbarButtons()),this.commands.forEach(function(b){b.hasForm&&a.appendChild(b.getForm())}),this.options.elementsContainer.appendChild(a),a},toolbarButtons:function(){var a,c,d=this.options.ownerDocument.createElement("ul");return d.id="medium-editor-toolbar-actions"+this.id,d.className="medium-editor-toolbar-actions clearfix",this.commands.forEach(function(e){"function"==typeof e.getButton&&(c=e.getButton(this),a=this.options.ownerDocument.createElement("li"),b.isElement(c)?a.appendChild(c):a.innerHTML=c,d.appendChild(a))}.bind(this)),d},bindSelect:function(){var a,c=function(a){return a&&a.type&&"blur"===a.type.toLowerCase()&&a.relatedTarget&&b.isDescendant(this.toolbar,a.relatedTarget)?!1:void this.checkSelection()}.bind(this),d=function(){setTimeout(function(){this.checkSelection()}.bind(this),0)}.bind(this);for(this.on(this.options.ownerDocument.documentElement,"mouseup",this.checkSelection.bind(this)),a=0;a<this.elements.length;a+=1)this.on(this.elements[a],"keyup",this.checkSelection.bind(this)),this.on(this.elements[a],"blur",c),this.on(this.elements[a],"click",d);return this},bindDragDrop:function(){var a,c,d,e,f,g=this;if(!g.options.imageDragging)return this;for(c="medium-editor-dragover",d=function(a){a.preventDefault(),a.dataTransfer.dropEffect="copy","dragover"===a.type?this.classList.add(c):this.classList.remove(c)},e=function(a){var d;a.preventDefault(),a.stopPropagation(),d=Array.prototype.slice.call(a.dataTransfer.files,0),d.some(function(a){if(a.type.match("image")){var c,d;c=new FileReader,c.readAsDataURL(a),d="medium-img-"+ +new Date,b.insertHTMLCommand(g.options.ownerDocument,'<img class="medium-image-loading" id="'+d+'" />'),c.onload=function(){var a=document.getElementById(d);a&&(a.removeAttribute("id"),a.removeAttribute("class"),a.src=c.result)}}}),this.classList.remove(c)},a=0;a<this.elements.length;a+=1)f=this.elements[a],this.on(f,"dragover",d),this.on(f,"dragleave",d),this.on(f,"drop",e);return this},stopSelectionUpdates:function(){this.preventSelectionUpdates=!0},startSelectionUpdates:function(){this.preventSelectionUpdates=!1},checkSelection:function(){var a,b;return this.preventSelectionUpdates||this.keepToolbarAlive===!0||this.options.disableToolbar||(a=this.options.contentWindow.getSelection(),!this.options.updateOnEmptySelection&&""===a.toString().trim()||this.options.allowMultiParagraphSelection===!1&&this.multipleBlockElementsSelected()||c.selectionInContentEditableFalse(this.options.contentWindow)?this.options.staticToolbar?this.showAndUpdateToolbar():this.hideToolbarActions():(b=c.getSelectionElement(this.options.contentWindow),!b||b.getAttribute("data-disable-toolbar")?this.options.staticToolbar||this.hideToolbarActions():this.checkSelectionElement(a,b))),this
},multipleBlockElementsSelected:function(){var a=c.getSelectionHtml.call(this).replace(/<[\S]+><\/[\S]+>/gim,""),b=a.match(/<(p|h[1-6]|blockquote)[^>]*>/g);return!!b&&b.length>1},checkSelectionElement:function(a,d){var e,f,g,h=0;if(this.selection=a,this.selectionRange=this.selection.getRangeAt(0),this.options.standardizeSelectionStart&&this.selectionRange.startContainer.nodeValue&&this.selectionRange.startOffset===this.selectionRange.startContainer.nodeValue.length&&(f=b.findAdjacentTextNodeWithContent(c.getSelectionElement(this.options.contentWindow),this.selectionRange.startContainer,this.options.ownerDocument))){for(h=0;0===f.nodeValue.substr(h,1).trim().length;)h+=1;g=this.options.ownerDocument.createRange(),g.setStart(f,h),g.setEnd(this.selectionRange.endContainer,this.selectionRange.endOffset),this.selection.removeAllRanges(),this.selection.addRange(g),this.selectionRange=g}for(e=0;e<this.elements.length;e+=1)if(this.elements[e]===d)return void this.showAndUpdateToolbar();this.options.staticToolbar||this.hideToolbarActions()},showAndUpdateToolbar:function(){this.setToolbarButtonStates().setToolbarPosition().showToolbarDefaultActions()},setToolbarPosition:function(){var a,b,d,e,f,g,h,i,j,k,l,m=this.options.ownerDocument.documentElement&&this.options.ownerDocument.documentElement.scrollTop||this.options.ownerDocument.body.scrollTop,n=this.options.contentWindow.getSelection(),o=this.options.contentWindow.innerWidth,p=c.getSelectionElement(this.options.contentWindow),q=50;return p&&this.options.contentWindow.getSelection().focusNode?-1===this.elements.indexOf(p)?this:(f=p.getBoundingClientRect(),g=f.top+m,h=f.left+f.width/2,this.toolbar.style.left="0",a=this.toolbar.offsetWidth,b=this.toolbar.offsetHeight,d=a/2,e=this.options.diffLeft-d,this.options.staticToolbar?(this.showToolbar(),this.options.stickyToolbar?m>g+p.offsetHeight-b?(this.toolbar.style.top=g+p.offsetHeight-b+"px",this.toolbar.classList.remove("sticky-toolbar")):m>g-b?(this.toolbar.classList.add("sticky-toolbar"),this.toolbar.style.top="0px"):(this.toolbar.classList.remove("sticky-toolbar"),this.toolbar.style.top=g-b+"px"):this.toolbar.style.top=g-b+"px","left"===this.options.toolbarAlign?l=f.left:"center"===this.options.toolbarAlign?l=h-d:"right"===this.options.toolbarAlign&&(l=f.right-a),0>l?l=0:l+a>o&&(l=o-a),this.toolbar.style.left=l+"px"):n.isCollapsed||(this.showToolbar(),i=n.getRangeAt(0),j=i.getBoundingClientRect(),k=(j.left+j.right)/2,j.top<q?(this.toolbar.classList.add("medium-toolbar-arrow-over"),this.toolbar.classList.remove("medium-toolbar-arrow-under"),this.toolbar.style.top=q+j.bottom-this.options.diffTop+this.options.contentWindow.pageYOffset-b+"px"):(this.toolbar.classList.add("medium-toolbar-arrow-under"),this.toolbar.classList.remove("medium-toolbar-arrow-over"),this.toolbar.style.top=j.top+this.options.diffTop+this.options.contentWindow.pageYOffset-b+"px"),this.toolbar.style.left=d>k?e+d+"px":d>o-k?o+e-d+"px":e+k+"px"),this.hideAnchorPreview(),this):this},setToolbarButtonStates:function(){return this.commands.forEach(function(a){"function"==typeof a.isActive&&a.setInactive()}.bind(this)),this.checkActiveButtons(),this},checkActiveButtons:function(){var a,d=Array.prototype.slice.call(this.elements),e=[],f=null,g=function(b){"function"==typeof b.checkState?b.checkState(a):"function"==typeof b.isActive&&"function"==typeof b.isAlreadyApplied&&!b.isActive()&&b.isAlreadyApplied(a)&&b.setActive()};if(this.selectionRange)for(a=c.getSelectedParentElement(this.selectionRange),this.commands.forEach(function(a){return"function"==typeof a.queryCommandState&&(f=a.queryCommandState(),null!==f)?void(f&&a.setActive()):void e.push(a)});void 0!==a.tagName&&-1===b.parentElements.indexOf(a.tagName.toLowerCase)&&(e.forEach(g.bind(this)),-1===d.indexOf(a));)a=a.parentNode},setFirstAndLastButtons:function(){var a=this.toolbar.querySelectorAll("button");return a.length>0&&(a[0].className+=" "+this.options.firstButtonClass,a[a.length-1].className+=" "+this.options.lastButtonClass),this},queryCommandState:function(a){var b,c=/^full-(.+)$/gi,d=null;b=c.exec(a),b&&(a=b[1]);try{d=this.options.ownerDocument.queryCommandState(a)}catch(e){d=null}return d},execAction:function(a,b){var c,d,e=/^full-(.+)$/gi;return c=e.exec(a),c?(this.saveSelection(),this.selectAllContents(),d=this.execActionInternal(c[1],b),this.restoreSelection()):d=this.execActionInternal(a,b),this.checkSelection(),d},execActionInternal:function(a,b){var c,d=/^append-(.+)$/gi;return c=d.exec(a),c?this.execFormatBlock(c[1]):"createLink"===a?this.createLink(b):"image"===a?this.options.ownerDocument.execCommand("insertImage",!1,this.options.contentWindow.getSelection()):this.options.ownerDocument.execCommand(a,!1,null)},rangeSelectsSingleNode:function(a){var b=a.startContainer;return b===a.endContainer&&b.hasChildNodes()&&a.endOffset===a.startOffset+1},getSelectedParentElement:function(){var a=null,b=this.selectionRange;return a=this.rangeSelectsSingleNode(b)&&3!==b.startContainer.childNodes[b.startOffset].nodeType?b.startContainer.childNodes[b.startOffset]:3===b.startContainer.nodeType?b.startContainer.parentNode:b.startContainer},execFormatBlock:function(a){var d=c.getSelectionData(this.selection.anchorNode);if("blockquote"===a&&d.el&&"blockquote"===d.el.parentNode.tagName.toLowerCase())return this.options.ownerDocument.execCommand("outdent",!1,null);if(d.tagName===a&&(a="p"),b.isIE){if("blockquote"===a)return this.options.ownerDocument.execCommand("indent",!1,a);a="<"+a+">"}return this.options.ownerDocument.execCommand("formatBlock",!1,a)},isToolbarDefaultActionsShown:function(){return!!this.toolbarActions&&"block"===this.toolbarActions.style.display},hideToolbarDefaultActions:function(){this.toolbarActions&&this.isToolbarDefaultActionsShown()&&(this.commands.forEach(function(a){a.onHide&&"function"==typeof a.onHide&&a.onHide()}),this.toolbarActions.style.display="none")},showToolbarDefaultActions:function(){return this.hideExtensionForms(),this.toolbarActions&&!this.isToolbarDefaultActionsShown()&&(this.toolbarActions.style.display="block"),this.keepToolbarAlive=!1,this.delay(function(){this.showToolbar()}.bind(this)),this},hideExtensionForms:function(){this.commands.forEach(function(a){a.hasForm&&a.isDisplayed()&&a.hideForm()})},isToolbarShown:function(){return this.toolbar&&this.toolbar.classList.contains("medium-editor-toolbar-active")},showToolbar:function(){this.toolbar&&!this.isToolbarShown()&&(this.toolbar.classList.add("medium-editor-toolbar-active"),"function"==typeof this.options.onShowToolbar&&this.options.onShowToolbar())},hideToolbar:function(){this.isToolbarShown()&&(this.toolbar.classList.remove("medium-editor-toolbar-active"),"function"==typeof this.options.onHideToolbar&&this.options.onHideToolbar())},hideToolbarActions:function(){this.commands.forEach(function(a){a.onHide&&"function"==typeof a.onHide&&a.onHide()}),this.keepToolbarAlive=!1,this.hideToolbar()},selectAllContents:function(){var a=this.options.ownerDocument.createRange(),b=this.options.contentWindow.getSelection(),d=c.getSelectionElement(this.options.contentWindow);if(d){for(;1===d.children.length;)d=d.children[0];a.selectNodeContents(d),b.removeAllRanges(),b.addRange(a)}},saveSelection:function(){this.selectionState=null;var a,c,d,e=this.options.contentWindow.getSelection(),f=-1;e.rangeCount>0&&(a=e.getRangeAt(0),c=a.cloneRange(),this.elements.forEach(function(c,d){return c===a.startContainer||b.isDescendant(c,a.startContainer)?(f=d,!1):void 0}),f>-1&&(c.selectNodeContents(this.elements[f]),c.setEnd(a.startContainer,a.startOffset),d=c.toString().length,this.selectionState={start:d,end:d+a.toString().length,editableElementIndex:f}))},restoreSelection:function(){if(this.selectionState){var a,b,c,d,e=this.elements[this.selectionState.editableElementIndex],f=0,g=this.options.ownerDocument.createRange(),h=[e],i=!1,j=!1;for(g.setStart(e,0),g.collapse(!0),a=h.pop();!j&&a;){if(3===a.nodeType)d=f+a.length,!i&&this.selectionState.start>=f&&this.selectionState.start<=d&&(g.setStart(a,this.selectionState.start-f),i=!0),i&&this.selectionState.end>=f&&this.selectionState.end<=d&&(g.setEnd(a,this.selectionState.end-f),j=!0),f=d;else for(b=a.childNodes.length-1;b>=0;)h.push(a.childNodes[b]),b-=1;j||(a=h.pop())}c=this.options.contentWindow.getSelection(),c.removeAllRanges(),c.addRange(g)}},hideAnchorPreview:function(){this.anchorPreview.classList.remove("medium-editor-anchor-preview-active")},showAnchorPreview:function(a){if(this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")||a.getAttribute("data-disable-preview"))return!0;var b,c,d=this,e=40,f=a.getBoundingClientRect(),g=(f.left+f.right)/2;return d.anchorPreview.querySelector("i").textContent=a.attributes.href.value,b=d.anchorPreview.offsetWidth/2,c=d.options.diffLeft-b,d.observeAnchorPreview(a),d.anchorPreview.classList.add("medium-toolbar-arrow-over"),d.anchorPreview.classList.remove("medium-toolbar-arrow-under"),d.anchorPreview.style.top=Math.round(e+f.bottom-d.options.diffTop+this.options.contentWindow.pageYOffset-d.anchorPreview.offsetHeight)+"px",d.anchorPreview.style.left=b>g?c+b+"px":this.options.contentWindow.innerWidth-g<b?this.options.contentWindow.innerWidth+c-b+"px":c+g+"px",this.anchorPreview&&!this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")&&this.anchorPreview.classList.add("medium-editor-anchor-preview-active"),this},observeAnchorPreview:function(a){var b=this,c=(new Date).getTime(),d=!0,e=function(){c=(new Date).getTime(),d=!0},f=function(a){a.relatedTarget&&/anchor-preview/.test(a.relatedTarget.className)||(d=!1)},g=setInterval(function(){if(d)return!0;var h=(new Date).getTime()-c;h>b.options.anchorPreviewHideDelay&&(b.hideAnchorPreview(),clearInterval(g),b.off(b.anchorPreview,"mouseover",e),b.off(b.anchorPreview,"mouseout",f),b.off(a,"mouseover",e),b.off(a,"mouseout",f))},200);this.on(b.anchorPreview,"mouseover",e),this.on(b.anchorPreview,"mouseout",f),this.on(a,"mouseover",e),this.on(a,"mouseout",f)},createAnchorPreview:function(){var a=this,b=this.options.ownerDocument.createElement("div");return b.id="medium-editor-anchor-preview-"+this.id,b.className="medium-editor-anchor-preview",b.innerHTML=this.anchorPreviewTemplate(),this.options.elementsContainer.appendChild(b),this.on(b,"click",function(){a.anchorPreviewClickHandler()}),b},anchorPreviewTemplate:function(){return'<div class="medium-editor-toolbar-anchor-preview" id="medium-editor-toolbar-anchor-preview"> <i class="medium-editor-toolbar-anchor-preview-inner"></i></div>'},anchorPreviewClickHandler:function(){var a,b,c=this.getExtensionByName("anchor");c&&this.activeAnchor&&(a=this.options.ownerDocument.createRange(),a.selectNodeContents(this.activeAnchor),b=this.options.contentWindow.getSelection(),b.removeAllRanges(),b.addRange(a),this.delay(function(){this.activeAnchor&&c.showForm(this.activeAnchor.attributes.href.value),this.keepToolbarAlive=!1}.bind(this))),this.hideAnchorPreview()},editorAnchorObserver:function(a){var b=this,c=!0,d=function(){c=!1,b.off(b.activeAnchor,"mouseout",d)};if(a.target&&"a"===a.target.tagName.toLowerCase()){if(!/href=["']\S+["']/.test(a.target.outerHTML)||/href=["']#\S+["']/.test(a.target.outerHTML))return!0;if(this.isToolbarShown())return!0;this.activeAnchor=a.target,this.on(this.activeAnchor,"mouseout",d),this.delay(function(){c&&b.showAnchorPreview(a.target)})}},bindAnchorPreview:function(){var a,b=this;for(this.editorAnchorObserverWrapper=function(a){b.editorAnchorObserver(a)},a=0;a<this.elements.length;a+=1)this.on(this.elements[a],"mouseover",this.editorAnchorObserverWrapper);return this},createLink:function(a){var d,e;if(a.url&&a.url.trim().length>0&&(this.options.ownerDocument.execCommand("createLink",!1,a.url),(this.options.targetBlank||"_blank"===a.target)&&b.setTargetBlank(c.getSelectionStart(this.options.ownerDocument)),a.buttonClass&&this.setButtonClass(a.buttonClass)),this.options.targetBlank||"_blank"===a.target||a.buttonClass)for(d=this.options.ownerDocument.createEvent("HTMLEvents"),d.initEvent("input",!0,!0,this.options.contentWindow),e=0;e<this.elements.length;e+=1)this.elements[e].dispatchEvent(d)},setButtonClass:function(a){var b,d,e=c.getSelectionStart(this.options.ownerDocument),f=a.split(" ");if("a"===e.tagName.toLowerCase())for(d=0;d<f.length;d+=1)e.classList.add(f[d]);else for(e=e.getElementsByTagName("a"),b=0;b<e.length;b+=1)for(d=0;d<f.length;d+=1)e[b].classList.add(f[d])},positionToolbarIfShown:function(){this.isToolbarShown()&&this.setToolbarPosition()},bindWindowActions:function(){var a=this;return this.options.staticToolbar&&this.options.stickyToolbar&&this.on(this.options.contentWindow,"scroll",function(){a.positionToolbarIfShown()},!0),this.on(this.options.contentWindow,"resize",function(){a.handleResize()}),this.bindBlur(),this},activate:function(){this.isActive||this.setup()},deactivate:function(){var a;if(this.isActive){for(this.isActive=!1,void 0!==this.toolbar&&(this.options.elementsContainer.removeChild(this.anchorPreview),this.options.elementsContainer.removeChild(this.toolbar),delete this.toolbar,delete this.anchorPreview),a=0;a<this.elements.length;a+=1)this.elements[a].removeAttribute("contentEditable"),this.elements[a].removeAttribute("data-medium-element");this.commands.forEach(function(a){"function"==typeof a.deactivate&&a.deactivate()}.bind(this)),this.removeAllEvents()}},bindPaste:function(){var a,b=this;for(this.pasteWrapper=function(a){f.handlePaste(this,a,b.options)},a=0;a<this.elements.length;a+=1)this.on(this.elements[a],"paste",this.pasteWrapper);return this},setPlaceholders:function(){return!this.options.disablePlaceholders&&this.elements&&this.elements.length&&this.elements.forEach(function(a){this.activatePlaceholder(a),this.on(a,"blur",this.placeholderWrapper.bind(this)),this.on(a,"keypress",this.placeholderWrapper.bind(this))}.bind(this)),this},cleanPaste:function(a){f.cleanPaste(a,this.options)},pasteHTML:function(a){f.pasteHTML(a,this.options.ownerDocument)}}}(),a}());
"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(++c<d);e&&this._updateClassName()},k.remove=function(){var a,b,c=arguments,d=0,e=c.length,f=!1;do for(a=c[d]+"",b=i(this,a);-1!==b;)this.splice(b,1),f=!0,b=i(this,a);while(++d<e);f&&this._updateClassName()},k.toggle=function(a,b){a+="";var c=this.contains(a),d=c?b!==!0&&"remove":b!==!1&&"add";return d&&this[d](a),b===!0||b===!1?b:!c},k.toString=function(){return this.join(" ")},e.defineProperty){var m={get:l,enumerable:!0,configurable:!0};try{e.defineProperty(d,b,m)}catch(n){-2146823252===n.number&&(m.enumerable=!1,e.defineProperty(d,b,m))}}else e[c].__defineGetter__&&d.__defineGetter__(b,l)}}(self),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(a,b,c){var d;a=a||{};for(d in b)b.hasOwnProperty(d)&&(c||a.hasOwnProperty(d)===!1)&&(a[d]=b[d]);return a}b={isIE:"Microsoft Internet Explorer"===navigator.appName||"Netscape"===navigator.appName&&null!==new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})").exec(navigator.userAgent),keyCode:{BACKSPACE:8,TAB:9,ENTER:13,ESCAPE:27,SPACE:32,DELETE:46},parentElements:["p","h1","h2","h3","h4","h5","h6","blockquote","pre"],defaults:function(a,b){return c(a,b)},extend:function(a,b){return c(a,b,!0)},derives:function(a,b){function d(){}var e=b.prototype;return d.prototype=a.prototype,b.prototype=new d,b.prototype.constructor=a,b.prototype=c(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){if(!a||!b)return!1;for(var c=b.parentNode;null!==c;){if(c===a)return!0;c=c.parentNode}return!1},isElement:function(a){return!(!a||1!==a.nodeType)},now:function(){return Date.now||(new Date).getTime()},throttle:function(a,c){var d,e,f,g,h=50,i=null,j=0;return c||0===c||(c=h),g=function(){j=b.now(),i=null,f=a.apply(d,e),i||(d=e=null)},function(){var h=b.now(),k=c-(h-j);return d=this,e=arguments,0>=k||k>c?(clearTimeout(i),i=null,j=h,f=a.apply(d,e),i||(d=e=null)):i||(i=setTimeout(g,k)),f}},traverseUp:function(a,b){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,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},insertHTMLCommand:function(b,c){var d,e,f,g,h,i;if(b.queryCommandSupported("insertHTML"))try{return b.execCommand("insertHTML",!1,c)}catch(j){}if(d=a.getSelection(),d.getRangeAt&&d.rangeCount){for(e=d.getRangeAt(0),e.deleteContents(),f=b.createElement("div"),f.innerHTML=c,g=b.createDocumentFragment();f.firstChild;)h=f.firstChild,i=g.appendChild(h);e.insertNode(g),i&&(e=e.cloneRange(),e.setStartAfter(i),e.collapse(!0),d.removeAllRanges(),d.addRange(e))}},setTargetBlank:function(a){var b;if("a"===a.tagName.toLowerCase())a.target="_blank";else for(a=a.getElementsByTagName("a"),b=0;b<a.length;b+=1)a[b].target="_blank"},isListItemChild:function(a){for(var b=a.parentNode,c=b.tagName.toLowerCase();-1===this.parentElements.indexOf(c)&&"div"!==c;){if("li"===c)return!0;if(b=b.parentNode,!b||!b.tagName)return!1;c=b.tagName.toLowerCase()}return!1}}}(window,document);var c;!function(a){c={getSelectionStart:function(a){var b=a.getSelection().anchorNode,c=b&&3===b.nodeType?b.parentNode:b;return c},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)},selectionInContentEditableFalse:function(a){return this.findMatchingSelectionParent(function(a){return a&&"#text"!==a.nodeName&&"false"===a.getAttribute("contenteditable")},a)},getSelectionHtml:function(){var a,b,c,d,e="";if(void 0!==this.options.contentWindow.getSelection){if(b=this.options.contentWindow.getSelection(),b.rangeCount){for(d=this.options.ownerDocument.createElement("div"),a=0,c=b.rangeCount;c>a;a+=1)d.appendChild(b.getRangeAt(a).cloneContents());e=d.innerHTML}}else void 0!==this.options.ownerDocument.selection&&"Text"===this.options.ownerDocument.selection.type&&(e=this.options.ownerDocument.selection.createRange().htmlText);return e},getCaretOffsets:function(b,c){var d,e;return c||(c=a.getSelection().getRangeAt(0)),d=c.cloneRange(),e=c.cloneRange(),d.selectNodeContents(b),d.setEnd(c.endContainer,c.endOffset),e.selectNodeContents(b),e.setStart(c.endContainer,c.endOffset),{left:d.toString().length,right:e.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},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}}}}(document,window);var d,e;!function(){e={bold:{name:"bold",action:"bold",aria:"bold",tagNames:["b","strong"],style:{prop:"font-weight",value:"700|bold"},useQueryState:!0,contentDefault:"<b>B</b>",contentFA:'<i class="fa fa-bold"></i>',key:"b"},italic:{name:"italic",action:"italic",aria:"italic",tagNames:["i","em"],style:{prop:"font-style",value:"italic"},useQueryState:!0,contentDefault:"<b><i>I</i></b>",contentFA:'<i class="fa fa-italic"></i>',key:"i"},underline:{name:"underline",action:"underline",aria:"underline",tagNames:["u"],style:{prop:"text-decoration",value:"underline"},useQueryState:!0,contentDefault:"<b><u>U</u></b>",contentFA:'<i class="fa fa-underline"></i>',key:"u"},strikethrough:{name:"strikethrough",action:"strikethrough",aria:"strike through",tagNames:["strike"],style:{prop:"text-decoration",value:"line-through"},useQueryState:!0,contentDefault:"<s>A</s>",contentFA:'<i class="fa fa-strikethrough"></i>'},superscript:{name:"superscript",action:"superscript",aria:"superscript",tagNames:["sup"],contentDefault:"<b>x<sup>1</sup></b>",contentFA:'<i class="fa fa-superscript"></i>'},subscript:{name:"subscript",action:"subscript",aria:"subscript",tagNames:["sub"],contentDefault:"<b>x<sub>1</sub></b>",contentFA:'<i class="fa fa-subscript"></i>'},image:{name:"image",action:"image",aria:"image",tagNames:["img"],contentDefault:"<b>image</b>",contentFA:'<i class="fa fa-picture-o"></i>'},quote:{name:"quote",action:"append-blockquote",aria:"blockquote",tagNames:["blockquote"],contentDefault:"<b>&ldquo;</b>",contentFA:'<i class="fa fa-quote-right"></i>'},orderedlist:{name:"orderedlist",action:"insertorderedlist",aria:"ordered list",tagNames:["ol"],useQueryState:!0,contentDefault:"<b>1.</b>",contentFA:'<i class="fa fa-list-ol"></i>'},unorderedlist:{name:"unorderedlist",action:"insertunorderedlist",aria:"unordered list",tagNames:["ul"],useQueryState:!0,contentDefault:"<b>&bull;</b>",contentFA:'<i class="fa fa-list-ul"></i>'},pre:{name:"pre",action:"append-pre",aria:"preformatted text",tagNames:["pre"],contentDefault:"<b>0101</b>",contentFA:'<i class="fa fa-code fa-lg"></i>'},indent:{name:"indent",action:"indent",aria:"indent",tagNames:[],contentDefault:"<b>&rarr;</b>",contentFA:'<i class="fa fa-indent"></i>'},outdent:{name:"outdent",action:"outdent",aria:"outdent",tagNames:[],contentDefault:"<b>&larr;</b>",contentFA:'<i class="fa fa-outdent"></i>'},justifyCenter:{name:"justifyCenter",action:"justifyCenter",aria:"center justify",tagNames:[],style:{prop:"text-align",value:"center"},useQueryState:!0,contentDefault:"<b>C</b>",contentFA:'<i class="fa fa-align-center"></i>'},justifyFull:{name:"justifyFull",action:"justifyFull",aria:"full justify",tagNames:[],style:{prop:"text-align",value:"justify"},useQueryState:!0,contentDefault:"<b>J</b>",contentFA:'<i class="fa fa-align-justify"></i>'},justifyLeft:{name:"justifyLeft",action:"justifyLeft",aria:"left justify",tagNames:[],style:{prop:"text-align",value:"left"},useQueryState:!0,contentDefault:"<b>L</b>",contentFA:'<i class="fa fa-align-left"></i>'},justifyRight:{name:"justifyRight",action:"justifyRight",aria:"right justify",tagNames:[],style:{prop:"text-align",value:"right"},useQueryState:!0,contentDefault:"<b>R</b>",contentFA:'<i class="fa fa-align-right"></i>'},header1:{name:"header1",action:function(a){return"append-"+a.firstHeader},aria:function(a){return a.firstHeader},tagNames:function(a){return[a.firstHeader]},contentDefault:"<b>H1</b>"},header2:{name:"header2",action:function(a){return"append-"+a.secondHeader},aria:function(a){return a.secondHeader},tagNames:function(a){return[a.secondHeader]},contentDefault:"<b>H2</b>"}},d=function(a,b){this.options=a,this.name=a.name,this.init(b)},d.prototype={init:function(a){this.base=a,this.button=this.createButton(),this.base.on(this.button,"click",this.handleClick.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;return a.classList.add("medium-editor-action"),a.classList.add("medium-editor-action-"+this.name),a.setAttribute("data-action",this.getAction()),a.setAttribute("aria-label",this.getAria()),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},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||(this.knownState=d=-1!==c.indexOf(a))}.bind(this))),d)}}}(window,document);var f;!function(){function a(){return[[new RegExp(/<[^>]*docs-internal-guid[^>]*>/gi),""],[new RegExp(/<\/b>(<br[^>]*>)?$/gi),""],[new RegExp(/<span class="Apple-converted-space">\s+<\/span>/g)," "],[new RegExp(/<br class="Apple-interchange-newline">/g),"<br>"],[new RegExp(/<span[^>]*(font-style:italic;font-weight:bold|font-weight:bold;font-style:italic)[^>]*>/gi),'<span class="replace-with italic bold">'],[new RegExp(/<span[^>]*font-style:italic[^>]*>/gi),'<span class="replace-with italic">'],[new RegExp(/<span[^>]*font-weight:bold[^>]*>/gi),'<span class="replace-with bold">'],[new RegExp(/&lt;(\/?)(i|b|a)&gt;/gi),"<$1$2>"],[new RegExp(/&lt;a\s+href=(&quot;|&rdquo;|&ldquo;|“|”)([^&]+)(&quot;|&rdquo;|&ldquo;|“|”)&gt;/gi),'<a href="$2">']]}f={handlePaste:function(a,c,d){var e,f,g="",h="text/html",i="text/plain";if(a.classList.remove("medium-editor-placeholder"),!d.forcePlainText&&!d.cleanPastedHTML)return a;if(d.contentWindow.clipboardData&&void 0===c.clipboardData&&(c.clipboardData=d.contentWindow.clipboardData,h="Text",i="Text"),c.clipboardData&&c.clipboardData.getData&&!c.defaultPrevented){if(c.preventDefault(),d.cleanPastedHTML&&c.clipboardData.getData(h))return this.cleanPaste(c.clipboardData.getData(h),d);if(d.disableReturn||a.getAttribute("data-disable-return"))g=b.htmlEntities(c.clipboardData.getData(i)),b.insertHTMLCommand(d.ownerDocument,g);else{for(e=c.clipboardData.getData(i).split(/[\r\n]/g),f=0;f<e.length;f+=1)""!==e[f]&&(g+="<p>"+b.htmlEntities(e[f])+"</p>");b.insertHTMLCommand(d.ownerDocument,g)}}},cleanPaste:function(d,e){var f,g,h,i=c.getSelectionElement(e.contentWindow),j=/<p|<br|<div/.test(d),k=a();for(f=0;f<k.length;f+=1)d=d.replace(k[f][0],k[f][1]);if(j){g=d.split("<br><br>"),this.pasteHTML("<p>"+g.join("</p><p>")+"</p>",e.ownerDocument);try{e.ownerDocument.execCommand("insertText",!1,"\n")}catch(l){}for(g=i.querySelectorAll("a,p,div,br"),f=0;f<g.length;f+=1)switch(h=g[f],h.tagName.toLowerCase()){case"a":e.targetBlank&&b.setTargetBlank(h);break;case"p":case"div":this.filterCommonBlocks(h);break;case"br":this.filterLineBreak(h)}}else this.pasteHTML(d,e.ownerDocument)},pasteHTML:function(a,c){var d,e,f,g,h=c.createDocumentFragment();for(h.appendChild(c.createElement("body")),g=h.querySelector("body"),g.innerHTML=a,this.cleanupSpans(g,c),d=g.querySelectorAll("*"),f=0;f<d.length;f+=1)e=d[f],e.removeAttribute("class"),e.removeAttribute("style"),e.removeAttribute("dir"),"meta"===e.tagName.toLowerCase()&&e.parentNode.removeChild(e);b.insertHTMLCommand(c,g.innerHTML.replace(/&nbsp;/g," "))},isCommonBlock:function(a){return a&&("p"===a.tagName.toLowerCase()||"div"===a.tagName.toLowerCase())},filterCommonBlocks:function(a){/^\s*$/.test(a.textContent)&&a.parentNode.removeChild(a)},filterLineBreak:function(a){this.isCommonBlock(a.previousElementSibling)?this.removeWithParent(a):!this.isCommonBlock(a.parentNode)||a.parentNode.firstChild!==a&&a.parentNode.lastChild!==a?1===a.parentNode.childElementCount&&""===a.parentNode.textContent&&this.removeWithParent(a):this.removeWithParent(a)},removeWithParent:function(a){a&&a.parentNode&&(a.parentNode.parentNode&&1===a.parentNode.childElementCount?a.parentNode.parentNode.removeChild(a.parentNode):a.parentNode.removeChild(a))},cleanupSpans:function(a,c){var d,e,f,g=a.querySelectorAll(".replace-with"),h=function(a){return a&&"#text"!==a.nodeName&&"false"===a.getAttribute("contenteditable")};for(d=0;d<g.length;d+=1)e=g[d],f=c.createElement(e.classList.contains("bold")?"b":"i"),f.innerHTML=e.classList.contains("bold")&&e.classList.contains("italic")?"<i>"+e.innerHTML+"</i>":e.innerHTML,e.parentNode.replaceChild(f,e);for(g=a.querySelectorAll("span"),d=0;d<g.length;d+=1){if(e=g[d],b.traverseUp(e,h))return!1;/^\s*$/.test()?e.parentNode.removeChild(e):e.parentNode.replaceChild(c.createTextNode(e.textContent),e)}}}}(window,document);var g;return function(){function a(){this.parent=!0,this.options={name:"anchor",action:"createLink",aria:"link",tagNames:["a"],contentDefault:"<b>#</b>",contentFA:'<i class="fa fa-link"></i>'},this.name="anchor",this.hasForm=!0}a.prototype={handleClick:function(a){a.preventDefault(),a.stopPropagation(),this.base.selection||this.base.checkSelection();var b=c.getSelectedParentElement(this.base.selectionRange);return b.tagName&&"a"===b.tagName.toLowerCase()?this.base.execAction("unlink"):(this.isDisplayed()||this.showForm(),!1)},getForm:function(){return this.anchorForm||(this.anchorForm=this.createForm()),this.anchorForm},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(),this.base.keepToolbarAlive=!0,b.value=a||"",b.focus()},deactivate:function(){return this.anchorForm?(this.anchorForm.parentNode&&this.anchorForm.parentNode.removeChild(this.anchorForm),void delete this.anchorForm):!1},doLinkCreation: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};this.base.restoreSelection(),this.base.options.checkLinkFormat&&(c.url=this.checkLinkFormat(c.url)),c.target=a&&a.checked?"_blank":"_self",b&&b.checked&&(c.buttonClass=this.base.options.anchorButtonClass),this.base.createLink(c),this.base.keepToolbarAlive=!1,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.keepToolbarAlive=!1,this.base.checkSelection()},createForm:function(){var a,b,c,d,e=this.base.options.ownerDocument,f=e.createElement("div"),g=e.createElement("input"),h=e.createElement("a"),i=e.createElement("a");return f.className="medium-editor-toolbar-form",f.id="medium-editor-toolbar-form-anchor-"+this.base.id,this.base.on(f,"click",this.handleFormClick.bind(this)),g.setAttribute("type","text"),g.className="medium-editor-toolbar-input",g.setAttribute("placeholder",this.base.options.anchorInputPlaceholder),f.appendChild(g),this.base.on(g,"keyup",this.handleTextboxKeyup.bind(this)),this.base.on(g,"click",this.handleFormClick.bind(this)),i.setAttribute("href","#"),i.className="medium-editor-toobar-save",i.innerHTML="fontawesome"===this.base.options.buttonLabels?'<i class="fa fa-check"></i>':"&#10003;",f.appendChild(i),this.base.on(i,"click",this.handleSaveClick.bind(this),!0),h.setAttribute("href","#"),h.className="medium-editor-toobar-close",h.innerHTML="fontawesome"===this.base.options.buttonLabels?'<i class="fa fa-times"></i>':"&times;",f.appendChild(h),this.base.on(h,"click",this.handleCloseClick.bind(this)),this.base.options.anchorTarget&&(a=e.createElement("input"),a.setAttribute("type","checkbox"),a.className="medium-editor-toolbar-anchor-target",b=e.createElement("label"),b.innerHTML=this.base.options.anchorInputCheckboxLabel,b.insertBefore(a,b.firstChild),f.appendChild(b)),this.base.options.anchorButton&&(c=e.createElement("input"),c.setAttribute("type","checkbox"),c.className="medium-editor-toolbar-anchor-button",d=e.createElement("label"),d.innerHTML="Button",d.insertBefore(c,d.firstChild),f.appendChild(d)),this.base.on(e.body,"click",this.handleOutsideInteraction.bind(this),!0),this.base.on(e.body,"focus",this.handleOutsideInteraction.bind(this),!0),f},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},handleOutsideInteraction:function(a){a.target===this.getForm()||b.isDescendant(this.getForm(),a.target)||b.isDescendant(this.base.toolbarActions,a.target)||(this.base.keepToolbarAlive=!1,this.base.checkSelection())},handleTextboxKeyup:function(a){return a.keyCode===b.keyCode.ENTER?(a.preventDefault(),void this.doLinkCreation()):void(a.keyCode===b.keyCode.ESCAPE&&(a.preventDefault(),this.doFormCancel()))},handleFormClick:function(a){a.stopPropagation(),this.base.keepToolbarAlive=!0},handleSaveClick:function(a){a.preventDefault(),this.doLinkCreation()},handleCloseClick:function(a){a.preventDefault(),this.doFormCancel()}},g=b.derives(d,a)}(window,document),function(){a.statics={ButtonsData:e,DefaultButton:d,AnchorExtension:g},a.prototype={defaults:{allowMultiParagraphSelection:!0,anchorInputPlaceholder:"Paste or type a link",anchorInputCheckboxLabel:"Open in new window",anchorPreviewHideDelay:500,buttons:["bold","italic","underline","anchor","header1","header2","quote"],buttonLabels:!1,checkLinkFormat:!1,cleanPastedHTML:!1,delay:0,diffLeft:0,diffTop:-10,disableReturn:!1,disableDoubleReturn:!1,disableToolbar:!1,disableEditing:!1,disablePlaceholders:!1,toolbarAlign:"center",elementsContainer:!1,imageDragging:!0,standardizeSelectionStart:!1,contentWindow:window,ownerDocument:document,firstHeader:"h3",forcePlainText:!0,placeholder:"Type your text",secondHeader:"h4",targetBlank:!1,anchorTarget:!1,anchorButton:!1,anchorButtonClass:"btn",extensions:{},activeButtonClass:"medium-editor-button-active",firstButtonClass:"medium-editor-button-first",lastButtonClass:"medium-editor-button-last"},init:function(a,c){var d=1;if(this.options=b.defaults(c,this.defaults),this.setElementSelection(a),0!==this.elements.length){for(this.options.elementsContainer||(this.options.elementsContainer=this.options.ownerDocument.body);this.options.elementsContainer.querySelector("#medium-editor-toolbar-"+d);)d+=1;return this.id=d,this.setup()}},setup:function(){this.events=[],this.isActive=!0,this.initThrottledMethods().initCommands().initElements().bindSelect().bindDragDrop().bindPaste().setPlaceholders().bindElementActions().bindWindowActions()},on:function(a,b,c,d){a.addEventListener(b,c,d),this.events.push([a,b,c,d])},off: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},delay:function(a){var b=this;setTimeout(function(){b.isActive&&a()},this.options.delay)},removeAllEvents:function(){for(var a=this.events.pop();a;)a[0].removeEventListener(a[1],a[2],a[3]),a=this.events.pop()},initThrottledMethods:function(){var a=this;return this.handleResize=b.throttle(function(){a.isActive&&a.positionToolbarIfShown()}),this.handleBlur=b.throttle(function(){a.isActive&&!a.keepToolbarAlive&&a.hideToolbarActions()}),this},initElements:function(){var a,b=!1;for(a=0;a<this.elements.length;a+=1)this.options.disableEditing||this.elements[a].getAttribute("data-disable-editing")||this.elements[a].setAttribute("contentEditable",!0),this.elements[a].getAttribute("data-placeholder")||this.elements[a].setAttribute("data-placeholder",this.options.placeholder),this.elements[a].setAttribute("data-medium-element",!0),this.elements[a].setAttribute("role","textbox"),this.elements[a].setAttribute("aria-multiline",!0),this.bindParagraphCreation(a),this.options.disableToolbar||this.elements[a].getAttribute("data-disable-toolbar")||(b=!0);return b&&this.initToolbar().setFirstAndLastButtons().bindAnchorPreview(),this},setElementSelection:function(a){a||(a=[]),"string"==typeof a&&(a=this.options.ownerDocument.querySelectorAll(a)),b.isElement(a)&&(a=[a]),this.elements=Array.prototype.slice.apply(a)},bindBlur:function(){var a=this,d=function(d){var e,f=!1,g=a.options.contentWindow.getSelection(),h=g.isCollapsed?null:c.getSelectedParentElement(g.getRangeAt(0));for(e=0;e<a.elements.length;e+=1)if(b.isDescendant(a.elements[e],d.target)||b.isDescendant(a.elements[e],h)){f=!0;break}d.target===a.toolbar||-1!==a.elements.indexOf(d.target)||f||b.isDescendant(a.toolbar,d.target)||b.isDescendant(a.anchorPreview,d.target)||(a.options.disablePlaceholders||a.placeholderWrapper(d,a.elements[0]),a.handleBlur())};return this.on(this.options.ownerDocument.body,"click",d,!0),this.on(this.options.ownerDocument.body,"focus",d,!0),this},bindClick:function(a){var b=this;return this.on(this.elements[a],"click",function(){b.options.disablePlaceholders||this.classList.remove("medium-editor-placeholder"),b.options.staticToolbar&&b.setToolbarPosition()}),this},bindElementActions:function(){var a;for(a=0;a<this.elements.length;a+=1)this.options.disablePlaceholders||this.activatePlaceholder(this.elements[a]),this.bindReturn(a).bindKeydown(a).bindClick(a);return this},activatePlaceholder:function(a){a.querySelector("img")||a.querySelector("blockquote")||""!==a.textContent.replace(/^\s+|\s+$/g,"")||a.classList.add("medium-editor-placeholder")},placeholderWrapper:function(a,b){b=b||a.target,b.classList.remove("medium-editor-placeholder"),"keypress"!==a.type&&this.activatePlaceholder(b)},serialize:function(){var a,b,c={};for(a=0;a<this.elements.length;a+=1)b=""!==this.elements[a].id?this.elements[a].id:"element-"+a,c[b]={value:this.elements[a].innerHTML.trim()};return c},initExtension:function(a,b){return a.parent&&(a.base=this),"function"==typeof a.init&&a.init(this),a.name||(a.name=b),a},initCommands:function(){var a,b,c=this.options.buttons,f=this.options.extensions;this.commands=[],c.forEach(function(b){f[b]?(a=this.initExtension(f[b],b),this.commands.push(a)):"anchor"===b?(a=this.initExtension(new g,b),this.commands.push(a)):e.hasOwnProperty(b)&&(a=new d(e[b],this),this.commands.push(a))}.bind(this));for(b in f)f.hasOwnProperty(b)&&-1===c.indexOf(b)&&(a=this.initExtension(f[b],b));return this},getExtensionByName:function(a){var b;return this.commands&&this.commands.length&&this.commands.forEach(function(c){c.name===a&&(b=c)}),b},callExtensions:function(a){if(!(arguments.length<1)){var b,c,d=Array.prototype.slice.call(arguments,1);for(c in this.options.extensions)this.options.extensions.hasOwnProperty(c)&&(b=this.options.extensions[c],void 0!==b[a]&&b[a].apply(b,d));return this}},bindParagraphCreation:function(a){var d=this;return this.on(this.elements[a],"keypress",function(a){var e,f;a.which===b.keyCode.SPACE&&(e=c.getSelectionStart(d.options.ownerDocument),f=e.tagName.toLowerCase(),"a"===f&&d.options.ownerDocument.execCommand("unlink",!1,null))}),this.on(this.elements[a],"keyup",function(a){var e,f,g=c.getSelectionStart(d.options.ownerDocument);g&&g.getAttribute("data-medium-element")&&0===g.children.length&&!d.options.disableReturn&&!g.getAttribute("data-disable-return")&&d.options.ownerDocument.execCommand("formatBlock",!1,"p"),a.which===b.keyCode.ENTER&&(g=c.getSelectionStart(d.options.ownerDocument),e=g.tagName.toLowerCase(),f=c.getSelectionElement(d.options.contentWindow),d.options.disableReturn||f.getAttribute("data-disable-return")||"li"===e||b.isListItemChild(g)||(a.shiftKey||/h\d/.test(e)||d.options.ownerDocument.execCommand("formatBlock",!1,"p"),"a"===e&&d.options.ownerDocument.execCommand("unlink",!1,null)))}),this},bindReturn:function(a){var d=this;return this.on(this.elements[a],"keypress",function(a){if(a.which===b.keyCode.ENTER)if(d.options.disableReturn||this.getAttribute("data-disable-return"))a.preventDefault();else if(d.options.disableDoubleReturn||this.getAttribute("data-disable-double-return")){var e=c.getSelectionStart(d.options.contentWindow);e&&""===e.textContent.trim()&&a.preventDefault()}}),this},bindKeydown:function(a){var d=this;return this.on(this.elements[a],"keydown",function(a){var e,f,g;a.which===b.keyCode.TAB?(e=c.getSelectionStart(d.options.ownerDocument),f=e&&e.tagName.toLowerCase(),"pre"===f&&(a.preventDefault(),d.options.ownerDocument.execCommand("insertHtml",null," ")),("li"===f||b.isListItemChild(e))&&(a.preventDefault(),a.shiftKey?d.options.ownerDocument.execCommand("outdent",a):d.options.ownerDocument.execCommand("indent",a))):a.which===b.keyCode.BACKSPACE||a.which===b.keyCode.DELETE||a.which===b.keyCode.ENTER?d.onBlockModifier(a):(a.ctrlKey||a.metaKey)&&(g=String.fromCharCode(a.which||a.keyCode).toLowerCase(),d.commands.forEach(function(b){b.options.key&&b.options.key===g&&b.handleClick(a)}))}),this},onBlockModifier:function(a){var d,e,f,g=c.getSelectionStart(this.options.ownerDocument),h=g.tagName.toLowerCase(),i=/^(\s+|<br\/?>)?$/i,j=/h\d/i;(a.which===b.keyCode.BACKSPACE||a.which===b.keyCode.ENTER)&&g.previousElementSibling&&j.test(h)&&0===c.getCaretOffsets(g).left?a.which===b.keyCode.BACKSPACE&&i.test(g.previousElementSibling.innerHTML)?(g.previousElementSibling.parentNode.removeChild(g.previousElementSibling),a.preventDefault()):a.which===b.keyCode.ENTER&&(f=this.options.ownerDocument.createElement("p"),f.innerHTML="<br>",g.previousElementSibling.parentNode.insertBefore(f,g),a.preventDefault()):a.which===b.keyCode.DELETE&&g.nextElementSibling&&g.previousElementSibling&&!j.test(h)&&i.test(g.innerHTML)&&j.test(g.nextElementSibling.tagName)&&(d=document.createRange(),e=window.getSelection(),d.setStart(g.nextElementSibling,0),d.collapse(!0),e.removeAllRanges(),e.addRange(d),g.previousElementSibling.parentNode.removeChild(g),a.preventDefault())},initToolbar:function(){return this.toolbar?this:(this.toolbar=this.createToolbar(),this.keepToolbarAlive=!1,this.toolbarActions=this.toolbar.querySelector(".medium-editor-toolbar-actions"),this.anchorPreview=this.createAnchorPreview(),this)},createToolbar:function(){var a=this.options.ownerDocument.createElement("div");return a.id="medium-editor-toolbar-"+this.id,a.className="medium-editor-toolbar",a.className+=this.options.staticToolbar?" static-toolbar":" stalker-toolbar",a.appendChild(this.toolbarButtons()),this.commands.forEach(function(b){b.hasForm&&a.appendChild(b.getForm())}),this.options.elementsContainer.appendChild(a),a},toolbarButtons:function(){var a,c,d=this.options.ownerDocument.createElement("ul");return d.id="medium-editor-toolbar-actions"+this.id,d.className="medium-editor-toolbar-actions clearfix",this.commands.forEach(function(e){"function"==typeof e.getButton&&(c=e.getButton(this),a=this.options.ownerDocument.createElement("li"),b.isElement(c)?a.appendChild(c):a.innerHTML=c,d.appendChild(a))}.bind(this)),d},bindSelect:function(){var a,c=function(a){return a&&a.type&&"blur"===a.type.toLowerCase()&&a.relatedTarget&&b.isDescendant(this.toolbar,a.relatedTarget)?!1:void this.checkSelection()}.bind(this),d=function(){setTimeout(function(){this.checkSelection()}.bind(this),0)}.bind(this);for(this.on(this.options.ownerDocument.documentElement,"mouseup",this.checkSelection.bind(this)),a=0;a<this.elements.length;a+=1)this.on(this.elements[a],"keyup",this.checkSelection.bind(this)),this.on(this.elements[a],"blur",c),this.on(this.elements[a],"click",d);return this},bindDragDrop:function(){var a,c,d,e,f,g=this;if(!g.options.imageDragging)return this;for(c="medium-editor-dragover",d=function(a){a.preventDefault(),a.dataTransfer.dropEffect="copy","dragover"===a.type?this.classList.add(c):this.classList.remove(c)},e=function(a){var d;a.preventDefault(),a.stopPropagation(),d=Array.prototype.slice.call(a.dataTransfer.files,0),d.some(function(a){if(a.type.match("image")){var c,d;c=new FileReader,c.readAsDataURL(a),d="medium-img-"+ +new Date,b.insertHTMLCommand(g.options.ownerDocument,'<img class="medium-image-loading" id="'+d+'" />'),c.onload=function(){var a=document.getElementById(d);a&&(a.removeAttribute("id"),a.removeAttribute("class"),a.src=c.result)}}}),this.classList.remove(c)},a=0;a<this.elements.length;a+=1)f=this.elements[a],this.on(f,"dragover",d),this.on(f,"dragleave",d),this.on(f,"drop",e);return this},stopSelectionUpdates:function(){this.preventSelectionUpdates=!0},startSelectionUpdates:function(){this.preventSelectionUpdates=!1},checkSelection:function(){var a,b;return this.preventSelectionUpdates||this.keepToolbarAlive===!0||this.options.disableToolbar||(a=this.options.contentWindow.getSelection(),!this.options.updateOnEmptySelection&&""===a.toString().trim()||this.options.allowMultiParagraphSelection===!1&&this.multipleBlockElementsSelected()||c.selectionInContentEditableFalse(this.options.contentWindow)?this.options.staticToolbar?this.showAndUpdateToolbar():this.hideToolbarActions():(b=c.getSelectionElement(this.options.contentWindow),!b||b.getAttribute("data-disable-toolbar")?this.options.staticToolbar||this.hideToolbarActions():this.checkSelectionElement(a,b))),this
},multipleBlockElementsSelected:function(){var a=c.getSelectionHtml.call(this).replace(/<[\S]+><\/[\S]+>/gim,""),b=a.match(/<(p|h[1-6]|blockquote)[^>]*>/g);return!!b&&b.length>1},checkSelectionElement:function(a,d){var e,f,g,h=0;if(this.selection=a,this.selectionRange=this.selection.getRangeAt(0),this.options.standardizeSelectionStart&&this.selectionRange.startContainer.nodeValue&&this.selectionRange.startOffset===this.selectionRange.startContainer.nodeValue.length&&(f=b.findAdjacentTextNodeWithContent(c.getSelectionElement(this.options.contentWindow),this.selectionRange.startContainer,this.options.ownerDocument))){for(h=0;0===f.nodeValue.substr(h,1).trim().length;)h+=1;g=this.options.ownerDocument.createRange(),g.setStart(f,h),g.setEnd(this.selectionRange.endContainer,this.selectionRange.endOffset),this.selection.removeAllRanges(),this.selection.addRange(g),this.selectionRange=g}for(e=0;e<this.elements.length;e+=1)if(this.elements[e]===d)return void this.showAndUpdateToolbar();this.options.staticToolbar||this.hideToolbarActions()},showAndUpdateToolbar:function(){this.setToolbarButtonStates().setToolbarPosition().showToolbarDefaultActions()},setToolbarPosition:function(){var a,b,d,e,f,g,h,i,j,k,l,m=this.options.ownerDocument.documentElement&&this.options.ownerDocument.documentElement.scrollTop||this.options.ownerDocument.body.scrollTop,n=this.options.contentWindow.getSelection(),o=this.options.contentWindow.innerWidth,p=c.getSelectionElement(this.options.contentWindow),q=50;return p&&this.options.contentWindow.getSelection().focusNode?-1===this.elements.indexOf(p)?this:(f=p.getBoundingClientRect(),g=f.top+m,h=f.left+f.width/2,this.toolbar.style.left="0",a=this.toolbar.offsetWidth,b=this.toolbar.offsetHeight,d=a/2,e=this.options.diffLeft-d,this.options.staticToolbar?(this.showToolbar(),this.options.stickyToolbar?m>g+p.offsetHeight-b?(this.toolbar.style.top=g+p.offsetHeight-b+"px",this.toolbar.classList.remove("sticky-toolbar")):m>g-b?(this.toolbar.classList.add("sticky-toolbar"),this.toolbar.style.top="0px"):(this.toolbar.classList.remove("sticky-toolbar"),this.toolbar.style.top=g-b+"px"):this.toolbar.style.top=g-b+"px","left"===this.options.toolbarAlign?l=f.left:"center"===this.options.toolbarAlign?l=h-d:"right"===this.options.toolbarAlign&&(l=f.right-a),0>l?l=0:l+a>o&&(l=o-a),this.toolbar.style.left=l+"px"):n.isCollapsed||(this.showToolbar(),i=n.getRangeAt(0),j=i.getBoundingClientRect(),k=(j.left+j.right)/2,j.top<q?(this.toolbar.classList.add("medium-toolbar-arrow-over"),this.toolbar.classList.remove("medium-toolbar-arrow-under"),this.toolbar.style.top=q+j.bottom-this.options.diffTop+this.options.contentWindow.pageYOffset-b+"px"):(this.toolbar.classList.add("medium-toolbar-arrow-under"),this.toolbar.classList.remove("medium-toolbar-arrow-over"),this.toolbar.style.top=j.top+this.options.diffTop+this.options.contentWindow.pageYOffset-b+"px"),this.toolbar.style.left=d>k?e+d+"px":d>o-k?o+e-d+"px":e+k+"px"),this.hideAnchorPreview(),this):this},setToolbarButtonStates:function(){return this.commands.forEach(function(a){"function"==typeof a.isActive&&a.setInactive()}.bind(this)),this.checkActiveButtons(),this},checkActiveButtons:function(){var a,d=Array.prototype.slice.call(this.elements),e=[],f=null,g=function(b){"function"==typeof b.checkState?b.checkState(a):"function"==typeof b.isActive&&"function"==typeof b.isAlreadyApplied&&!b.isActive()&&b.isAlreadyApplied(a)&&b.setActive()};if(this.selectionRange)for(a=c.getSelectedParentElement(this.selectionRange),this.commands.forEach(function(a){return"function"==typeof a.queryCommandState&&(f=a.queryCommandState(),null!==f)?void(f&&a.setActive()):void e.push(a)});void 0!==a.tagName&&-1===b.parentElements.indexOf(a.tagName.toLowerCase)&&(e.forEach(g.bind(this)),-1===d.indexOf(a));)a=a.parentNode},setFirstAndLastButtons:function(){var a=this.toolbar.querySelectorAll("button");return a.length>0&&(a[0].className+=" "+this.options.firstButtonClass,a[a.length-1].className+=" "+this.options.lastButtonClass),this},queryCommandState:function(a){var b,c=/^full-(.+)$/gi,d=null;b=c.exec(a),b&&(a=b[1]);try{d=this.options.ownerDocument.queryCommandState(a)}catch(e){d=null}return d},execAction:function(a,b){var c,d,e=/^full-(.+)$/gi;return c=e.exec(a),c?(this.saveSelection(),this.selectAllContents(),d=this.execActionInternal(c[1],b),this.restoreSelection()):d=this.execActionInternal(a,b),this.checkSelection(),d},execActionInternal:function(a,b){var c,d=/^append-(.+)$/gi;return c=d.exec(a),c?this.execFormatBlock(c[1]):"createLink"===a?this.createLink(b):"image"===a?this.options.ownerDocument.execCommand("insertImage",!1,this.options.contentWindow.getSelection()):this.options.ownerDocument.execCommand(a,!1,null)},getSelectedParentElement:function(){return c.getSelectedParentElement()},execFormatBlock:function(a){var d=c.getSelectionData(this.selection.anchorNode);if("blockquote"===a&&d.el&&"blockquote"===d.el.parentNode.tagName.toLowerCase())return this.options.ownerDocument.execCommand("outdent",!1,null);if(d.tagName===a&&(a="p"),b.isIE){if("blockquote"===a)return this.options.ownerDocument.execCommand("indent",!1,a);a="<"+a+">"}return this.options.ownerDocument.execCommand("formatBlock",!1,a)},isToolbarDefaultActionsShown:function(){return!!this.toolbarActions&&"block"===this.toolbarActions.style.display},hideToolbarDefaultActions:function(){this.toolbarActions&&this.isToolbarDefaultActionsShown()&&(this.commands.forEach(function(a){a.onHide&&"function"==typeof a.onHide&&a.onHide()}),this.toolbarActions.style.display="none")},showToolbarDefaultActions:function(){return this.hideExtensionForms(),this.toolbarActions&&!this.isToolbarDefaultActionsShown()&&(this.toolbarActions.style.display="block"),this.keepToolbarAlive=!1,this.delay(function(){this.showToolbar()}.bind(this)),this},hideExtensionForms:function(){this.commands.forEach(function(a){a.hasForm&&a.isDisplayed()&&a.hideForm()})},isToolbarShown:function(){return this.toolbar&&this.toolbar.classList.contains("medium-editor-toolbar-active")},showToolbar:function(){this.toolbar&&!this.isToolbarShown()&&(this.toolbar.classList.add("medium-editor-toolbar-active"),"function"==typeof this.options.onShowToolbar&&this.options.onShowToolbar())},hideToolbar:function(){this.isToolbarShown()&&(this.toolbar.classList.remove("medium-editor-toolbar-active"),"function"==typeof this.options.onHideToolbar&&this.options.onHideToolbar())},hideToolbarActions:function(){this.commands.forEach(function(a){a.onHide&&"function"==typeof a.onHide&&a.onHide()}),this.keepToolbarAlive=!1,this.hideToolbar()},selectAllContents:function(){var a=this.options.ownerDocument.createRange(),b=this.options.contentWindow.getSelection(),d=c.getSelectionElement(this.options.contentWindow);if(d){for(;1===d.children.length;)d=d.children[0];a.selectNodeContents(d),b.removeAllRanges(),b.addRange(a)}},saveSelection:function(){this.selectionState=null;var a,c,d,e=this.options.contentWindow.getSelection(),f=-1;e.rangeCount>0&&(a=e.getRangeAt(0),c=a.cloneRange(),this.elements.forEach(function(c,d){return c===a.startContainer||b.isDescendant(c,a.startContainer)?(f=d,!1):void 0}),f>-1&&(c.selectNodeContents(this.elements[f]),c.setEnd(a.startContainer,a.startOffset),d=c.toString().length,this.selectionState={start:d,end:d+a.toString().length,editableElementIndex:f}))},restoreSelection:function(){if(this.selectionState){var a,b,c,d,e=this.elements[this.selectionState.editableElementIndex],f=0,g=this.options.ownerDocument.createRange(),h=[e],i=!1,j=!1;for(g.setStart(e,0),g.collapse(!0),a=h.pop();!j&&a;){if(3===a.nodeType)d=f+a.length,!i&&this.selectionState.start>=f&&this.selectionState.start<=d&&(g.setStart(a,this.selectionState.start-f),i=!0),i&&this.selectionState.end>=f&&this.selectionState.end<=d&&(g.setEnd(a,this.selectionState.end-f),j=!0),f=d;else for(b=a.childNodes.length-1;b>=0;)h.push(a.childNodes[b]),b-=1;j||(a=h.pop())}c=this.options.contentWindow.getSelection(),c.removeAllRanges(),c.addRange(g)}},hideAnchorPreview:function(){this.anchorPreview.classList.remove("medium-editor-anchor-preview-active")},showAnchorPreview:function(a){if(this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")||a.getAttribute("data-disable-preview"))return!0;var b,c,d=this,e=40,f=a.getBoundingClientRect(),g=(f.left+f.right)/2;return d.anchorPreview.querySelector("i").textContent=a.attributes.href.value,b=d.anchorPreview.offsetWidth/2,c=d.options.diffLeft-b,d.observeAnchorPreview(a),d.anchorPreview.classList.add("medium-toolbar-arrow-over"),d.anchorPreview.classList.remove("medium-toolbar-arrow-under"),d.anchorPreview.style.top=Math.round(e+f.bottom-d.options.diffTop+this.options.contentWindow.pageYOffset-d.anchorPreview.offsetHeight)+"px",d.anchorPreview.style.left=b>g?c+b+"px":this.options.contentWindow.innerWidth-g<b?this.options.contentWindow.innerWidth+c-b+"px":c+g+"px",this.anchorPreview&&!this.anchorPreview.classList.contains("medium-editor-anchor-preview-active")&&this.anchorPreview.classList.add("medium-editor-anchor-preview-active"),this},observeAnchorPreview:function(a){var b=this,c=(new Date).getTime(),d=!0,e=function(){c=(new Date).getTime(),d=!0},f=function(a){a.relatedTarget&&/anchor-preview/.test(a.relatedTarget.className)||(d=!1)},g=setInterval(function(){if(d)return!0;var h=(new Date).getTime()-c;h>b.options.anchorPreviewHideDelay&&(b.hideAnchorPreview(),clearInterval(g),b.off(b.anchorPreview,"mouseover",e),b.off(b.anchorPreview,"mouseout",f),b.off(a,"mouseover",e),b.off(a,"mouseout",f))},200);this.on(b.anchorPreview,"mouseover",e),this.on(b.anchorPreview,"mouseout",f),this.on(a,"mouseover",e),this.on(a,"mouseout",f)},createAnchorPreview:function(){var a=this,b=this.options.ownerDocument.createElement("div");return b.id="medium-editor-anchor-preview-"+this.id,b.className="medium-editor-anchor-preview",b.innerHTML=this.anchorPreviewTemplate(),this.options.elementsContainer.appendChild(b),this.on(b,"click",function(){a.anchorPreviewClickHandler()}),b},anchorPreviewTemplate:function(){return'<div class="medium-editor-toolbar-anchor-preview" id="medium-editor-toolbar-anchor-preview"> <i class="medium-editor-toolbar-anchor-preview-inner"></i></div>'},anchorPreviewClickHandler:function(){var a,b,c=this.getExtensionByName("anchor");c&&this.activeAnchor&&(a=this.options.ownerDocument.createRange(),a.selectNodeContents(this.activeAnchor),b=this.options.contentWindow.getSelection(),b.removeAllRanges(),b.addRange(a),this.delay(function(){this.activeAnchor&&c.showForm(this.activeAnchor.attributes.href.value),this.keepToolbarAlive=!1}.bind(this))),this.hideAnchorPreview()},editorAnchorObserver:function(a){var b=this,c=!0,d=function(){c=!1,b.off(b.activeAnchor,"mouseout",d)};if(a.target&&"a"===a.target.tagName.toLowerCase()){if(!/href=["']\S+["']/.test(a.target.outerHTML)||/href=["']#\S+["']/.test(a.target.outerHTML))return!0;if(this.isToolbarShown())return!0;this.activeAnchor=a.target,this.on(this.activeAnchor,"mouseout",d),this.delay(function(){c&&b.showAnchorPreview(a.target)})}},bindAnchorPreview:function(){var a,b=this;for(this.editorAnchorObserverWrapper=function(a){b.editorAnchorObserver(a)},a=0;a<this.elements.length;a+=1)this.on(this.elements[a],"mouseover",this.editorAnchorObserverWrapper);return this},createLink:function(a){var d,e;if(a.url&&a.url.trim().length>0&&(this.options.ownerDocument.execCommand("createLink",!1,a.url),(this.options.targetBlank||"_blank"===a.target)&&b.setTargetBlank(c.getSelectionStart(this.options.ownerDocument)),a.buttonClass&&this.setButtonClass(a.buttonClass)),this.options.targetBlank||"_blank"===a.target||a.buttonClass)for(d=this.options.ownerDocument.createEvent("HTMLEvents"),d.initEvent("input",!0,!0,this.options.contentWindow),e=0;e<this.elements.length;e+=1)this.elements[e].dispatchEvent(d)},setButtonClass:function(a){var b,d,e=c.getSelectionStart(this.options.ownerDocument),f=a.split(" ");if("a"===e.tagName.toLowerCase())for(d=0;d<f.length;d+=1)e.classList.add(f[d]);else for(e=e.getElementsByTagName("a"),b=0;b<e.length;b+=1)for(d=0;d<f.length;d+=1)e[b].classList.add(f[d])},positionToolbarIfShown:function(){this.isToolbarShown()&&this.setToolbarPosition()},bindWindowActions:function(){var a=this;return this.options.staticToolbar&&this.options.stickyToolbar&&this.on(this.options.contentWindow,"scroll",function(){a.positionToolbarIfShown()},!0),this.on(this.options.contentWindow,"resize",function(){a.handleResize()}),this.bindBlur(),this},activate:function(){this.isActive||this.setup()},deactivate:function(){var a;if(this.isActive){for(this.isActive=!1,void 0!==this.toolbar&&(this.options.elementsContainer.removeChild(this.anchorPreview),this.options.elementsContainer.removeChild(this.toolbar),delete this.toolbar,delete this.anchorPreview),a=0;a<this.elements.length;a+=1)this.elements[a].removeAttribute("contentEditable"),this.elements[a].removeAttribute("data-medium-element");this.commands.forEach(function(a){"function"==typeof a.deactivate&&a.deactivate()}.bind(this)),this.removeAllEvents()}},bindPaste:function(){var a,b=this;for(this.pasteWrapper=function(a){f.handlePaste(this,a,b.options)},a=0;a<this.elements.length;a+=1)this.on(this.elements[a],"paste",this.pasteWrapper);return this},setPlaceholders:function(){return!this.options.disablePlaceholders&&this.elements&&this.elements.length&&this.elements.forEach(function(a){this.activatePlaceholder(a),this.on(a,"blur",this.placeholderWrapper.bind(this)),this.on(a,"keypress",this.placeholderWrapper.bind(this))}.bind(this)),this},cleanPaste:function(a){f.cleanPaste(a,this.options)},pasteHTML:function(a){f.pasteHTML(a,this.options.ownerDocument)}}}(),a}());

@@ -267,2 +267,12 @@ /*global module, require, process*/

gruntConfig.bump = {
options: {
files: ['bower.json', 'package.json'],
updateConfigs: [],
commit: false,
createTag: false,
push: false
}
}
grunt.initConfig(gruntConfig);

@@ -269,0 +279,0 @@

{
"name": "medium-editor",
"version": "3.0.7",
"version": "3.0.8",
"author": "Davi Ferreira <hi@daviferreira.com>",
"contributors": [
{
"name": "Nate Mielnik",
"email": "nathan@outlook.com"
},
{
"name": "Noah Chase",
"email": "nchase@gmail.com"
}
],
"description": "Medium.com WYSIWYG editor clone.",

@@ -26,3 +36,3 @@ "main": "dist/js/medium-editor.js",

},
"license": "THE BEER-WARE LICENSE",
"license": "MIT",
"devDependencies": {

@@ -32,2 +42,3 @@ "brfs": "1.3.0",

"grunt-autoprefixer": "~2.2.0",
"grunt-bump": "^0.3.0",
"grunt-contrib-concat": "^0.5.0",

@@ -34,0 +45,0 @@ "grunt-contrib-connect": "^0.9.0",

# MediumEditor
[![Join the chat at https://gitter.im/daviferreira/medium-editor](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/daviferreira/medium-editor?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This is a clone of [medium.com](https://medium.com) inline editor toolbar.

@@ -459,112 +461,6 @@

```
project : medium-editor
repo age : 1 year, 9 months
active : 269 days
commits : 1037
files : 75
authors :
613 Davi Ferreira 59.1%
131 Nate Mielnik 12.6%
35 Noah Chase 3.4%
31 Andy Yaco-Mink 3.0%
20 Maxime de Visscher 1.9%
8 Derek Odegard 0.8%
8 Pedro Nasser 0.8%
8 Jarl Gunnar T. Flaten 0.8%
8 Seif 0.8%
7 Alfonso (the fonz) de la Osa 0.7%
7 Aidan Threadgold 0.7%
7 OmniaGM 0.7%
7 Charl Gottschalk 0.7%
6 Dayjo 0.6%
6 Pascal 0.6%
5 Raul Matei 0.5%
5 Martin Thurau 0.5%
4 minikomi 0.4%
4 Sebastian Zuchmanski 0.4%
3 ʞuıɯ-oɔɐʎ ʎpuɐ 0.3%
3 Nikita Korotaev 0.3%
3 Patrick Cavanaugh 0.3%
3 Ionică Bizău 0.3%
3 Pavel Linkesch 0.3%
3 Javier Marín 0.3%
3 Jeff Bellsey 0.3%
3 Troels Knak-Nielsen 0.3%
3 arol 0.3%
3 Andrew Hubbs 0.3%
3 steoo 0.3%
3 Dmitri Cherniak 0.3%
3 Brian Reavis 0.3%
2 David Van Der Beek 0.2%
2 Joel 0.2%
2 Jeremy 0.2%
2 petr.jasek 0.2%
2 Son Tran-Nguyen 0.2%
2 Alexander Hofbauer 0.2%
2 Robin Andersson 0.2%
2 Patrick Stillhart 0.2%
2 Jacob Magnusson 0.2%
2 Karl Sander 0.2%
2 jj 0.2%
2 mako 0.2%
2 Ethan Turkeltaub 0.2%
1 shaohua 0.1%
1 t_kjaergaard 0.1%
1 typify 0.1%
1 unknown 0.1%
1 valentinnew 0.1%
1 waffleio 0.1%
1 zzjin 0.1%
1 Michal Czeraszkiewicz 0.1%
1 Alberto Gasparin 0.1%
1 Bitdeli Chef 0.1%
1 Brooke McKim 0.1%
1 Bruno Peres 0.1%
1 Carlos Alexandre Fuechter 0.1%
1 Cenk Dölek 0.1%
1 Chris 0.1%
1 Dave Jarvis 0.1%
1 David Collien 0.1%
1 David Hellsing 0.1%
1 Denis Gorbachev 0.1%
1 Diana Liao 0.1%
1 Enrico Berti 0.1%
1 Harry Hogg 0.1%
1 Harshil Shah 0.1%
1 IndieSquidge 0.1%
1 Jack Parker 0.1%
1 Jeff Welch 0.1%
1 Johann Troendle 0.1%
1 Mark Kraemer 0.1%
1 Max 0.1%
1 Maxime Dantec 0.1%
1 Maxime De Visscher 0.1%
1 Michael Kay 0.1%
1 Adam Mulligan 0.1%
1 Moore Adam 0.1%
1 Nic Malan 0.1%
1 Nick Semenkovich 0.1%
1 Noah Paessel 0.1%
1 Patrick Kempff 0.1%
1 Peleg Rosenthal 0.1%
1 Randson Oliveira 0.1%
1 Richard Park 0.1%
1 Robert Koritnik 0.1%
1 Sarah Squire 0.1%
1 Scott Carleton 0.1%
1 Steoo 0.1%
1 Søren Torp Petersen 0.1%
1 Tom MacWright 0.1%
1 Wildhoney 0.1%
1 happyaccidents 0.1%
1 mako yass 0.1%
1 mbrookes 0.1%
1 muescha 0.1%
```
[https://github.com/daviferreira/medium-editor/graphs/contributors](https://github.com/daviferreira/medium-editor/graphs/contributors)
## License
"THE BEER-WARE LICENSE" (Revision 42):
As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.
MIT: https://github.com/daviferreira/medium-editor/blob/master/LICENSE

@@ -91,3 +91,3 @@ /*global MediumEditor, describe, it, expect, spyOn, jasmine, fireEvent,

// regression test for https://github.com/daviferreira/medium-editor/issues/390
xit('should work with multiple elements of the same class', function () {
it('should work with multiple elements of the same class', function () {
var editor,

@@ -94,0 +94,0 @@ el,

@@ -51,2 +51,7 @@ /*global MediumEditor, describe, it, expect, spyOn,

output: '<p>One<br>Two</p><p>Three<br>Four</p>'
},
{
source: 'Non <p> or <div> with only <br> elements',
paste: '<p>One</p><div><h1><br /></h1></div><p>Two</p><span><span><br /></span></span><p>Three</p>',
output: '<p>One</p><p>Two</p><p>Three</p>'
}

@@ -53,0 +58,0 @@ ];

@@ -1,2 +0,2 @@

/*global Util, Selection*/
/*global Util, Selection, console*/
var pasteHandler;

@@ -169,11 +169,10 @@

// remove stray br's following common block elements
el.parentNode.removeChild(el);
this.removeWithParent(el);
} else if (this.isCommonBlock(el.parentNode) && (el.parentNode.firstChild === el || el.parentNode.lastChild === el)) {
// remove br's just inside open or close tags of a div/p
el.parentNode.removeChild(el);
this.removeWithParent(el);
} else if (el.parentNode.childElementCount === 1 && el.parentNode.textContent === '') {
// and br's that are the only child of a div/p
// and br's that are the only child of elements other than div/p
this.removeWithParent(el);
}
},

@@ -187,3 +186,3 @@

} else {
el.parentNode.removeChild(el.parentNode);
el.parentNode.removeChild(el);
}

@@ -190,0 +189,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc