medium-editor
Advanced tools
Comparing version 2.4.2 to 2.4.3
{ | ||
"name": "medium-editor", | ||
"version": "2.4.2", | ||
"version": "2.4.3", | ||
"homepage": "http://daviferreira.github.io/medium-editor/", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -0,1 +1,5 @@ | ||
2.4.3 / 2015-02-16 | ||
* Introduce full content actions | ||
2.4.2 / 2015-02-15 | ||
@@ -2,0 +6,0 @@ ================== |
!function(a,b){"use strict";"object"==typeof module?module.exports=b:"function"==typeof define&&define.amd?define(b):a.MediumEditor=b}(this,function(){"use strict";function a(a,b){return this.init(a,b)}var b;!function(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"],extend:function(a,b){var c;if(void 0===a)return b;for(c in b)b.hasOwnProperty(c)&&a.hasOwnProperty(c)===!1&&(a[c]=b[c]);return a},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){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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},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>'},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>'},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>'},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>'},anchor:{name:"anchor",action:"anchor",aria:"link",tagNames:["a"],contentDefault:"<b>#</b>",contentFA:'<i class="fa fa-link"></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>“</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>•</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>→</b>",contentFA:'<i class="fa fa-indent"></i>'},outdent:{name:"outdent",action:"outdent",aria:"outdent",tagNames:[],contentDefault:"<b>←</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();this.base.selection||this.base.checkSelection(),this.isActive()?this.deactivate():this.activate(),b&&this.base.execAction(b,a)},isActive:function(){return this.button.classList.contains(this.base.options.activeButtonClass)},deactivate:function(){this.button.classList.remove(this.base.options.activeButtonClass),delete this.knownState},activate:function(){this.button.classList.add(this.base.options.activeButtonClass),delete this.knownState},queryCommandState:function(){var a=null;if(this.options.useQueryState)try{a=this.base.options.ownerDocument.queryCommandState(this.getAction())}catch(b){a=null}return a},shouldActivate: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(/<(\/?)(i|b|a)>/gi),"<$1$2>"],[new RegExp(/<a\s+href=("|”|“|“|”)([^&]+)("|”|“|“|”)>/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)for(g=d.split("<br><br>"),this.pasteHTML("<p>"+g.join("</p><p>")+"</p>",e.ownerDocument),e.ownerDocument.execCommand("insertText",!1,"\n"),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(/ /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&&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(){g=function(a){this.base=a},g.prototype={getForm:function(){return this.anchorForm||(this.anchorForm=this.createForm()),this.anchorForm},getInput:function(){return this.getForm().querySelector("input.medium-editor-toolbar-input")},deactivate:function(){return this.anchorForm?(this.anchorForm.parentNode&&this.anchorForm.parentNode.removeChild(this.anchorForm),void delete this.anchorForm):!1},doLinkCreation:function(){var a,b=null,c=this.getForm().querySelector(".medium-editor-toolbar-anchor-target"),d=this.getForm().querySelector(".medium-editor-toolbar-anchor-button");a=c&&c.checked?"_blank":"_self",d&&d.checked&&(b=this.base.options.anchorButtonClass),this.base.createLink(this.getInput(),a,b)},doFormCancel:function(){this.base.showToolbarActions(),this.base.restoreSelection()},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())},createForm:function(){var a,c,d,e,f=this.base.options.ownerDocument,g=f.createElement("div"),h=f.createElement("input"),i=f.createElement("a"),j=f.createElement("a");return g.className="medium-editor-toolbar-form",g.id="medium-editor-toolbar-form-anchor-"+this.base.id,this.base.on(g,"click",function(a){a.stopPropagation(),this.base.keepToolbarAlive=!0}.bind(this)),h.setAttribute("type","text"),h.className="medium-editor-toolbar-input",h.setAttribute("placeholder",this.base.options.anchorInputPlaceholder),g.appendChild(h),this.base.on(h,"keyup",function(a){return a.keyCode===b.keyCode.ENTER?(a.preventDefault(),void this.doLinkCreation()):void(a.keyCode===b.keyCode.ESCAPE&&(a.preventDefault(),this.doFormCancel()))}.bind(this)),this.base.on(h,"click",function(a){a.stopPropagation(),this.base.keepToolbarAlive=!0}.bind(this)),j.setAttribute("href","#"),j.className="medium-editor-toobar-save",j.innerHTML="✓",g.appendChild(j),this.base.on(j,"click",function(a){a.preventDefault(),this.doLinkCreation()}.bind(this),!0),i.setAttribute("href","#"),i.className="medium-editor-toobar-close",i.innerHTML="×",g.appendChild(i),this.base.on(i,"click",function(a){a.preventDefault(),this.doFormCancel()}.bind(this)),this.base.options.anchorTarget&&(a=f.createElement("input"),a.setAttribute("type","checkbox"),a.className="medium-editor-toolbar-anchor-target",c=f.createElement("label"),c.innerHTML=this.base.options.anchorInputCheckboxLabel,c.insertBefore(a,c.firstChild),g.appendChild(c)),this.base.options.anchorButton&&(d=f.createElement("input"),d.setAttribute("type","checkbox"),d.className="medium-editor-toolbar-anchor-button",e=f.createElement("label"),e.innerHTML="Button",e.insertBefore(d,e.firstChild),g.appendChild(e)),this.base.on(f.body,"click",this.handleOutsideInteraction.bind(this),!0),this.base.on(f.body,"focus",this.handleOutsideInteraction.bind(this),!0),g},focus:function(a){var b=this.getInput();b.focus(),b.value=a||""},hideForm:function(){this.getForm().style.display="none"},showForm:function(){this.getForm().style.display="block"},isDisplayed:function(){return"block"===this.getForm().style.display},isClickIntoForm:function(a){return a&&a.type&&"blur"===a.type.toLowerCase()&&a.relatedTarget&&a.relatedTarget===this.getInput()}}}(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,disableAnchorForm:!1,disablePlaceholders:!1,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.extend(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().bindButtons().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,c=function(c){var d,e=!1;for(d=0;d<a.elements.length;d+=1)if(b.isDescendant(a.elements[d],c.target)){e=!0;break}c.target===a.toolbar||-1!==a.elements.indexOf(c.target)||e||b.isDescendant(a.toolbar,c.target)||b.isDescendant(a.anchorPreview,c.target)||(a.options.disablePlaceholders||a.placeholderWrapper(c,a.elements[0]),a.handleBlur())};return this.on(this.options.ownerDocument.body,"click",c,!0),this.on(this.options.ownerDocument.body,"focus",c,!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)):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},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){if(a.which===b.keyCode.TAB){var 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))}else(a.which===b.keyCode.BACKSPACE||a.which===b.keyCode.DELETE||a.which===b.keyCode.ENTER)&&d.onBlockModifier(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.addExtensionForms(),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.options.disableAnchorForm||(this.anchorExtension=new g(this),a.appendChild(this.anchorExtension.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},addExtensionForms:function(){var a,b;this.commands.forEach(function(c){c.hasForm&&(a="function"==typeof c.getForm?c.getForm():null),a&&(b="medium-editor-toolbar-form-"+c.name+"-"+this.id,a.className+=" medium-editor-toolbar-form",a.id=b,this.toolbar.appendChild(a))}.bind(this))},bindSelect:function(){var a,b,c=this;for(this.checkSelectionWrapper=function(a){return a&&this.anchorExtension&&this.anchorExtension.isClickIntoForm(a)?!1:void c.checkSelection()},b=function(a){setTimeout(function(){this.checkSelectionWrapper(a)}.bind(this),0)}.bind(this),this.on(this.options.ownerDocument.documentElement,"mouseup",this.checkSelectionWrapper),a=0;a<this.elements.length;a+=1)this.on(this.elements[a],"keyup",this.checkSelectionWrapper),this.on(this.elements[a],"blur",this.checkSelectionWrapper),this.on(this.elements[a],"click",b);return this},insertHTML:function(a){var b,c,d,e,f,g;if(this.options.ownerDocument.queryCommandSupported("insertHTML"))try{return this.options.ownerDocument.execCommand("insertHTML",!1,a)}catch(h){}if(b=window.getSelection(),b.getRangeAt&&b.rangeCount){for(c=b.getRangeAt(0),c.deleteContents(),d=this.options.ownerDocument.createElement("div"),d.innerHTML=a,e=this.options.ownerDocument.createDocumentFragment();d.firstChild;)f=d.firstChild,g=e.appendChild(f);c.insertNode(e),g&&(c=c.cloneRange(),c.setStartAfter(g),c.collapse(!0),b.removeAllRanges(),b.addRange(c))}},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.hasMultiParagraphs()||c.selectionInContentEditableFalse(this.options.contentWindow)?this.options.staticToolbar?this.anchorExtension&&this.anchorExtension.isDisplayed()&&(this.setToolbarButtonStates(),this.showToolbarActions()):this.hideToolbarActions():(b=c.getSelectionElement(this.options.contentWindow),!b||b.getAttribute("data-disable-toolbar")?this.options.staticToolbar||this.hideToolbarActions():this.checkSelectionElement(a,b))),this},hasMultiParagraphs:function(){var a=c.getSelectionHtml.call(this).replace(/<[\S]+><\/[\S]+>/gim,""),b=a.match(/<(p|h[0-6]|blockquote)>([\s\S]*?)<\/(p|h[0-6]|blockquote)>/g);return b?b.length:0},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.setToolbarButtonStates().setToolbarPosition().showToolbarActions();this.options.staticToolbar||this.hideToolbarActions()},setToolbarPosition:function(){var a,b,c,d=this.options.ownerDocument.documentElement&&this.options.ownerDocument.documentElement.scrollTop||this.options.ownerDocument.body.scrollTop,e=this.elements[0],f=e.getBoundingClientRect(),g=f.top+d,h=50,i=this.options.contentWindow.getSelection(),j=this.options.diffLeft-this.toolbar.offsetWidth/2,k=this.toolbar.offsetWidth/2,l=f.left+f.width/2;return null===i.focusNode?this:(this.showToolbar(),this.options.staticToolbar?(this.options.stickyToolbar?d>g+this.elements[0].offsetHeight-this.toolbar.offsetHeight?this.toolbar.style.top=g+this.elements[0].offsetHeight+"px":d>g-this.toolbar.offsetHeight?(this.toolbar.classList.add("sticky-toolbar"),this.toolbar.style.top="0px"):(this.toolbar.classList.remove("sticky-toolbar"),this.toolbar.style.top=g-this.toolbar.offsetHeight+"px"):this.toolbar.style.top=g-this.toolbar.offsetHeight+"px",this.toolbar.style.left=this.options.toolbarAlign?"left"===this.options.toolbarAlign?f.left+"px":"center"===this.options.toolbarAlign?l-k+"px":f.right-this.toolbar.offsetWidth+"px":l-k+"px"):i.isCollapsed||(a=i.getRangeAt(0),b=a.getBoundingClientRect(),c=(b.left+b.right)/2,b.top<h?(this.toolbar.classList.add("medium-toolbar-arrow-over"),this.toolbar.classList.remove("medium-toolbar-arrow-under"),this.toolbar.style.top=h+b.bottom-this.options.diffTop+this.options.contentWindow.pageYOffset-this.toolbar.offsetHeight+"px"):(this.toolbar.classList.add("medium-toolbar-arrow-under"),this.toolbar.classList.remove("medium-toolbar-arrow-over"),this.toolbar.style.top=b.top+this.options.diffTop+this.options.contentWindow.pageYOffset-this.toolbar.offsetHeight+"px"),this.toolbar.style.left=k>c?j+k+"px":this.options.contentWindow.innerWidth-c<k?this.options.contentWindow.innerWidth+j-k+"px":j+c+"px"),this.hideAnchorPreview(),this) | ||
},setToolbarButtonStates:function(){return this.commands.forEach(function(a){"function"==typeof a.deactivate&&a.deactivate()}.bind(this)),this.checkActiveButtons(),this},checkActiveButtons:function(){var a=Array.prototype.slice.call(this.elements),d=[],e=null,f=c.getSelectedParentElement(this.selectionRange),g=function(a){"function"==typeof a.checkState?a.checkState(f):"function"==typeof a.isActive&&!a.isActive()&&a.shouldActivate(f)&&a.activate()};for(this.commands.forEach(function(a){return"function"==typeof a.queryCommandState&&(e=a.queryCommandState(),null!==e)?void(e&&a.activate()):void d.push(a)});void 0!==f.tagName&&-1===b.parentElements.indexOf(f.tagName.toLowerCase)&&(this.activateButton(f.tagName.toLowerCase()),d.forEach(g.bind(this)),-1===a.indexOf(f));)f=f.parentNode},activateButton:function(a){var b=this.toolbar.querySelector('[data-element="'+a+'"]');null===b||b.classList.contains(this.options.activeButtonClass)||b.classList.add(this.options.activeButtonClass)},bindButtons:function(){return this.setFirstAndLastItems(this.toolbar.querySelectorAll("button")),this},setFirstAndLastItems:function(a){return a.length>0&&(a[0].className+=" "+this.options.firstButtonClass,a[a.length-1].className+=" "+this.options.lastButtonClass),this},execAction:function(a,b){a.indexOf("append-")>-1?(this.execFormatBlock(a.replace("append-","")),this.setToolbarPosition(),this.setToolbarButtonStates()):"anchor"===a?this.options.disableAnchorForm||this.triggerAnchorAction(b):"image"===a?this.options.ownerDocument.execCommand("insertImage",!1,this.options.contentWindow.getSelection()):(this.options.ownerDocument.execCommand(a,!1,null),this.setToolbarPosition(),0===a.indexOf("justify")&&this.setToolbarButtonStates())},showForm:function(a){this.toolbarActions.style.display="none",this.saveSelection();var b=document.getElementById(a);b.style.display="block",this.setToolbarPosition(),this.keepToolbarAlive=!0},hideForm:function(a){var b=document.getElementById(a.id);b.style.display="none",this.showToolbarActions(),this.setToolbarPosition(),this.restoreSelection()},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},triggerAnchorAction:function(){var a=c.getSelectedParentElement(this.selectionRange);return a.tagName&&"a"===a.tagName.toLowerCase()?this.options.ownerDocument.execCommand("unlink",!1,null):this.anchorExtension&&(this.anchorExtension.isDisplayed()?this.showToolbarActions():this.showAnchorForm()),this},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)},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"),this.onShowToolbar&&this.onShowToolbar())},hideToolbar:function(){this.isToolbarShown()&&(this.toolbar.classList.remove("medium-editor-toolbar-active"),this.onHideToolbar&&this.onHideToolbar())},hideToolbarActions:function(){this.commands.forEach(function(a){a.onHide&&"function"==typeof a.onHide&&a.onHide()}),this.keepToolbarAlive=!1,this.hideToolbar()},showToolbarActions:function(){var a=this;this.anchorExtension&&this.anchorExtension.hideForm(),this.toolbarActions.style.display="block",this.keepToolbarAlive=!1,this.delay(function(){a.showToolbar()})},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)}},showAnchorForm:function(a){this.anchorExtension&&(this.toolbarActions.style.display="none",this.saveSelection(),this.anchorExtension.showForm(),this.setToolbarPosition(),this.keepToolbarAlive=!0,this.anchorExtension.focus(a))},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(){if(!this.options.disableAnchorForm&&this.activeAnchor){var a=this,b=this.options.ownerDocument.createRange(),c=this.options.contentWindow.getSelection();b.selectNodeContents(a.activeAnchor),c.removeAllRanges(),c.addRange(b),this.delay(function(){a.activeAnchor&&a.showAnchorForm(a.activeAnchor.attributes.href.value),a.keepToolbarAlive=!1})}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},checkLinkFormat:function(a){var b=/^(https?|ftps?|rtmpt?):\/\/|mailto:/;return(b.test(a)?"":"http://")+a},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])},createLink:function(a,b,c){var d,e;if(this.createLinkInternal(a.value,b,c),this.options.targetBlank||"_blank"===b||c)for(e=this.options.ownerDocument.createEvent("HTMLEvents"),e.initEvent("input",!0,!0,this.options.contentWindow),d=0;d<this.elements.length;d+=1)this.elements[d].dispatchEvent(e);this.checkSelection(),this.showToolbarActions(),a.value=""},createLinkInternal:function(a,d,e){return a&&0!==a.trim().length?(this.restoreSelection(),this.options.checkLinkFormat&&(a=this.checkLinkFormat(a)),this.options.ownerDocument.execCommand("createLink",!1,a),(this.options.targetBlank||"_blank"===d)&&b.setTargetBlank(c.getSelectionStart(this.options.ownerDocument)),void(e&&this.setButtonClass(e))):void this.hideToolbarActions()},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.anchorExtension&&this.anchorExtension.deactivate(),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}()); | ||
},setToolbarButtonStates:function(){return this.commands.forEach(function(a){"function"==typeof a.deactivate&&a.deactivate()}.bind(this)),this.checkActiveButtons(),this},checkActiveButtons:function(){var a=Array.prototype.slice.call(this.elements),d=[],e=null,f=c.getSelectedParentElement(this.selectionRange),g=function(a){"function"==typeof a.checkState?a.checkState(f):"function"==typeof a.isActive&&!a.isActive()&&a.shouldActivate(f)&&a.activate()};for(this.commands.forEach(function(a){return"function"==typeof a.queryCommandState&&(e=a.queryCommandState(),null!==e)?void(e&&a.activate()):void d.push(a)});void 0!==f.tagName&&-1===b.parentElements.indexOf(f.tagName.toLowerCase)&&(this.activateButton(f.tagName.toLowerCase()),d.forEach(g.bind(this)),-1===a.indexOf(f));)f=f.parentNode},activateButton:function(a){var b=this.toolbar.querySelector('[data-element="'+a+'"]');null===b||b.classList.contains(this.options.activeButtonClass)||b.classList.add(this.options.activeButtonClass)},bindButtons:function(){return this.setFirstAndLastItems(this.toolbar.querySelectorAll("button")),this},setFirstAndLastItems:function(a){return a.length>0&&(a[0].className+=" "+this.options.firstButtonClass,a[a.length-1].className+=" "+this.options.lastButtonClass),this},execAction:function(a,b){var c,d=/^full-(.+)$/gi,e=/^append-(.+)$/gi,f=/^justify(left|center|right|full)$/gi;return(c=d.exec(a))?(this.saveSelection(),this.selectAllContents(),this.execAction(c[1],b),void this.restoreSelection()):(c=e.exec(a))?(this.execFormatBlock(c[1]),this.setToolbarPosition(),void this.setToolbarButtonStates()):void("anchor"===a?this.options.disableAnchorForm||this.triggerAnchorAction(b):"image"===a?this.options.ownerDocument.execCommand("insertImage",!1,this.options.contentWindow.getSelection()):(this.options.ownerDocument.execCommand(a,!1,null),this.setToolbarPosition(),f.test(a)&&this.setToolbarButtonStates()))},showForm:function(a){this.toolbarActions.style.display="none",this.saveSelection();var b=document.getElementById(a);b.style.display="block",this.setToolbarPosition(),this.keepToolbarAlive=!0},hideForm:function(a){var b=document.getElementById(a.id);b.style.display="none",this.showToolbarActions(),this.setToolbarPosition(),this.restoreSelection()},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},triggerAnchorAction:function(){var a=c.getSelectedParentElement(this.selectionRange);return a.tagName&&"a"===a.tagName.toLowerCase()?this.options.ownerDocument.execCommand("unlink",!1,null):this.anchorExtension&&(this.anchorExtension.isDisplayed()?this.showToolbarActions():this.showAnchorForm()),this},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)},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"),this.onShowToolbar&&this.onShowToolbar())},hideToolbar:function(){this.isToolbarShown()&&(this.toolbar.classList.remove("medium-editor-toolbar-active"),this.onHideToolbar&&this.onHideToolbar())},hideToolbarActions:function(){this.commands.forEach(function(a){a.onHide&&"function"==typeof a.onHide&&a.onHide()}),this.keepToolbarAlive=!1,this.hideToolbar()},showToolbarActions:function(){var a=this;this.anchorExtension&&this.anchorExtension.hideForm(),this.toolbarActions.style.display="block",this.keepToolbarAlive=!1,this.delay(function(){a.showToolbar()})},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)}},showAnchorForm:function(a){this.anchorExtension&&(this.toolbarActions.style.display="none",this.saveSelection(),this.anchorExtension.showForm(),this.setToolbarPosition(),this.keepToolbarAlive=!0,this.anchorExtension.focus(a))},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(){if(!this.options.disableAnchorForm&&this.activeAnchor){var a=this,b=this.options.ownerDocument.createRange(),c=this.options.contentWindow.getSelection();b.selectNodeContents(a.activeAnchor),c.removeAllRanges(),c.addRange(b),this.delay(function(){a.activeAnchor&&a.showAnchorForm(a.activeAnchor.attributes.href.value),a.keepToolbarAlive=!1})}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},checkLinkFormat:function(a){var b=/^(https?|ftps?|rtmpt?):\/\/|mailto:/;return(b.test(a)?"":"http://")+a},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])},createLink:function(a,b,c){var d,e;if(this.createLinkInternal(a.value,b,c),this.options.targetBlank||"_blank"===b||c)for(e=this.options.ownerDocument.createEvent("HTMLEvents"),e.initEvent("input",!0,!0,this.options.contentWindow),d=0;d<this.elements.length;d+=1)this.elements[d].dispatchEvent(e);this.checkSelection(),this.showToolbarActions(),a.value=""},createLinkInternal:function(a,d,e){return a&&0!==a.trim().length?(this.restoreSelection(),this.options.checkLinkFormat&&(a=this.checkLinkFormat(a)),this.options.ownerDocument.execCommand("createLink",!1,a),(this.options.targetBlank||"_blank"===d)&&b.setTargetBlank(c.getSelectionStart(this.options.ownerDocument)),void(e&&this.setButtonClass(e))):void this.hideToolbarActions()},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.anchorExtension&&this.anchorExtension.deactivate(),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}()); |
{ | ||
"name": "medium-editor", | ||
"version": "2.4.2", | ||
"version": "2.4.3", | ||
"author": "Davi Ferreira <hi@daviferreira.com>", | ||
@@ -5,0 +5,0 @@ "description": "Medium.com WYSIWYG editor clone.", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
832016
72
7955
1