medium-editor
Advanced tools
Comparing version 1.9.13 to 2.0.0
{ | ||
"name": "medium-editor", | ||
"version": "1.9.13", | ||
"version": "2.0.0", | ||
"homepage": "http://daviferreira.github.io/medium-editor/", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -0,1 +1,18 @@ | ||
2.0.0 / 2015-01-06 | ||
================== | ||
* Adds static toolbar feature | ||
* Now uses textContent instead of innerText | ||
* Fixes plain text paste on IE | ||
* Hides placeholder on mouse click | ||
* Adds a 'collapse' option to 'selectElementContents' helper | ||
* Allows toolbar button states to change when selection is collapsed | ||
* In hideToolbarActions, calls an optional 'onHideToolbar' method | ||
* Ensures that ul.id and anchor.id are unique | ||
* Avoids grabbing selection on keypress for contenteditable except for spacebar | ||
* Supports disabling anchorForm, avoiding unnecessary event handling and element creation | ||
* Supports disabling placeholders, including not attaching event handlers when not needed | ||
* Various minor bug fixes and improvements | ||
1.9.13 / 2014-11-24 | ||
@@ -2,0 +19,0 @@ =================== |
@@ -1,1 +0,2 @@ | ||
function MediumEditor(a,b){"use strict";return this.init(a,b)}"object"==typeof module?module.exports=MediumEditor:"function"==typeof define&&define.amd&&define(function(){"use strict";return MediumEditor}),function(a,b){"use strict";function c(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}function d(a,b){for(var c=b.parentNode;null!==c;){if(c===a)return!0;c=c.parentNode}return!1}function e(){var a,b,c,d=this.options.contentWindow.getSelection();if(d.getRangeAt&&d.rangeCount){for(c=[],a=0,b=d.rangeCount;b>a;a+=1)c.push(d.getRangeAt(a));return c}return null}function f(a){var b,c,d=this.options.contentWindow.getSelection();if(a)for(d.removeAllRanges(),b=0,c=a.length;c>b;b+=1)d.addRange(a[b])}function g(){var a=this.options.ownerDocument.getSelection().anchorNode,b=a&&3===a.nodeType?a.parentNode:a;return b}function h(){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}function i(a){return!(!a||1!==a.nodeType)}MediumEditor.prototype={defaults:{allowMultiParagraphSelection:!0,anchorInputPlaceholder:"Paste or type a link",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,elementsContainer:!1,contentWindow:a,ownerDocument:b,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"},isIE:"Microsoft Internet Explorer"===navigator.appName||"Netscape"===navigator.appName&&null!==new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})").exec(navigator.userAgent),init:function(a,d){return this.options=c(d,this.defaults),this.setElementSelection(a),0!==this.elements.length?(this.parentElements=["p","h1","h2","h3","h4","h5","h6","blockquote","pre"],this.options.elementsContainer||(this.options.elementsContainer=b.body),this.id=this.options.elementsContainer.querySelectorAll(".medium-editor-toolbar").length+1,this.setup()):void 0},setup:function(){this.events=[],this.isActive=!0,this.initElements().bindSelect().bindPaste().setPlaceholders().bindWindowActions().passInstance()},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.events.indexOf([a,b,c,d]);-1!==f&&(e=this.events.splice(f,1),e[0].removeEventListener(e[1],e[2],e[3]))},removeAllEvents:function(){for(var a=this.events.pop();a;)a[0].removeEventListener(a[1],a[2],a[3]),a=this.events.pop()},initElements:function(){this.updateElementList();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.bindParagraphCreation(a).bindReturn(a).bindTab(a),this.options.disableToolbar||this.elements[a].getAttribute("data-disable-toolbar")||(b=!0);return b&&this.initToolbar().bindButtons().bindAnchorForm().bindAnchorPreview(),this},setElementSelection:function(a){this.elementSelection=a,this.updateElementList()},updateElementList:function(){this.elements="string"==typeof this.elementSelection?this.options.ownerDocument.querySelectorAll(this.elementSelection):this.elementSelection,1===this.elements.nodeType&&(this.elements=[this.elements])},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},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))}},passInstance:function(){var a,b,c=this;for(b in c.options.extensions)c.options.extensions.hasOwnProperty(b)&&(a=c.options.extensions[b],a.parent&&(a.base=c));return c},bindParagraphCreation:function(a){var c=this;return this.on(this.elements[a],"keypress",function(a){var d,e=g.call(c);32===a.which&&(d=e.tagName.toLowerCase(),"a"===d&&b.execCommand("unlink",!1,null))}),this.on(this.elements[a],"keyup",function(a){var d,e,f=g.call(c);f&&f.getAttribute("data-medium-element")&&0===f.children.length&&!c.options.disableReturn&&!f.getAttribute("data-disable-return")&&b.execCommand("formatBlock",!1,"p"),13===a.which&&(f=g.call(c),d=f.tagName.toLowerCase(),e=c.getSelectionElement(),c.options.disableReturn||e.getAttribute("data-disable-return")||"li"===d||c.isListItemChild(f)||(a.shiftKey||b.execCommand("formatBlock",!1,"p"),"a"===d&&b.execCommand("unlink",!1,null)))}),this},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},bindReturn:function(a){var b=this;return this.on(this.elements[a],"keypress",function(a){if(13===a.which)if(b.options.disableReturn||this.getAttribute("data-disable-return"))a.preventDefault();else if(b.options.disableDoubleReturn||this.getAttribute("data-disable-double-return")){var c=g.call(b);c&&"\n"===c.innerText&&a.preventDefault()}}),this},bindTab:function(a){var c=this;return this.on(this.elements[a],"keydown",function(a){if(9===a.which){var d=g.call(c).tagName.toLowerCase();"pre"===d&&(a.preventDefault(),b.execCommand("insertHtml",null," ")),"li"===d&&(a.preventDefault(),a.shiftKey?b.execCommand("outdent",a):b.execCommand("indent",a))}}),this},buttonTemplate:function(a){var b=this.getButtonLabels(this.options.buttonLabels),c={bold:'<button class="medium-editor-action medium-editor-action-bold" data-action="bold" data-element="b">'+b.bold+"</button>",italic:'<button class="medium-editor-action medium-editor-action-italic" data-action="italic" data-element="i">'+b.italic+"</button>",underline:'<button class="medium-editor-action medium-editor-action-underline" data-action="underline" data-element="u">'+b.underline+"</button>",strikethrough:'<button class="medium-editor-action medium-editor-action-strikethrough" data-action="strikethrough" data-element="strike">'+b.strikethrough+"</button>",superscript:'<button class="medium-editor-action medium-editor-action-superscript" data-action="superscript" data-element="sup">'+b.superscript+"</button>",subscript:'<button class="medium-editor-action medium-editor-action-subscript" data-action="subscript" data-element="sub">'+b.subscript+"</button>",anchor:'<button class="medium-editor-action medium-editor-action-anchor" data-action="anchor" data-element="a">'+b.anchor+"</button>",image:'<button class="medium-editor-action medium-editor-action-image" data-action="image" data-element="img">'+b.image+"</button>",header1:'<button class="medium-editor-action medium-editor-action-header1" data-action="append-'+this.options.firstHeader+'" data-element="'+this.options.firstHeader+'">'+b.header1+"</button>",header2:'<button class="medium-editor-action medium-editor-action-header2" data-action="append-'+this.options.secondHeader+'" data-element="'+this.options.secondHeader+'">'+b.header2+"</button>",quote:'<button class="medium-editor-action medium-editor-action-quote" data-action="append-blockquote" data-element="blockquote">'+b.quote+"</button>",orderedlist:'<button class="medium-editor-action medium-editor-action-orderedlist" data-action="insertorderedlist" data-element="ol">'+b.orderedlist+"</button>",unorderedlist:'<button class="medium-editor-action medium-editor-action-unorderedlist" data-action="insertunorderedlist" data-element="ul">'+b.unorderedlist+"</button>",pre:'<button class="medium-editor-action medium-editor-action-pre" data-action="append-pre" data-element="pre">'+b.pre+"</button>",indent:'<button class="medium-editor-action medium-editor-action-indent" data-action="indent" data-element="ul">'+b.indent+"</button>",outdent:'<button class="medium-editor-action medium-editor-action-outdent" data-action="outdent" data-element="ul">'+b.outdent+"</button>",justifyCenter:'<button class="medium-editor-action medium-editor-action-justifyCenter" data-action="justifyCenter" data-element="">'+b.justifyCenter+"</button>",justifyFull:'<button class="medium-editor-action medium-editor-action-justifyFull" data-action="justifyFull" data-element="">'+b.justifyFull+"</button>",justifyLeft:'<button class="medium-editor-action medium-editor-action-justifyLeft" data-action="justifyLeft" data-element="">'+b.justifyLeft+"</button>",justifyRight:'<button class="medium-editor-action medium-editor-action-justifyRight" data-action="justifyRight" data-element="">'+b.justifyRight+"</button>"};return c[a]||!1},getButtonLabels:function(a){var b,c,d={bold:"<b>B</b>",italic:"<b><i>I</i></b>",underline:"<b><u>U</u></b>",strikethrough:"<s>A</s>",superscript:"<b>x<sup>1</sup></b>",subscript:"<b>x<sub>1</sub></b>",anchor:"<b>#</b>",image:"<b>image</b>",header1:"<b>H1</b>",header2:"<b>H2</b>",quote:"<b>“</b>",orderedlist:"<b>1.</b>",unorderedlist:"<b>•</b>",pre:"<b>0101</b>",indent:"<b>→</b>",outdent:"<b>←</b>",justifyCenter:"<b>C</b>",justifyFull:"<b>J</b>",justifyLeft:"<b>L</b>",justifyRight:"<b>R</b>"};if("fontawesome"===a?b={bold:'<i class="fa fa-bold"></i>',italic:'<i class="fa fa-italic"></i>',underline:'<i class="fa fa-underline"></i>',strikethrough:'<i class="fa fa-strikethrough"></i>',superscript:'<i class="fa fa-superscript"></i>',subscript:'<i class="fa fa-subscript"></i>',anchor:'<i class="fa fa-link"></i>',image:'<i class="fa fa-picture-o"></i>',quote:'<i class="fa fa-quote-right"></i>',orderedlist:'<i class="fa fa-list-ol"></i>',unorderedlist:'<i class="fa fa-list-ul"></i>',pre:'<i class="fa fa-code fa-lg"></i>',indent:'<i class="fa fa-indent"></i>',outdent:'<i class="fa fa-outdent"></i>',justifyCenter:'<i class="fa fa-align-center"></i>',justifyFull:'<i class="fa fa-align-justify"></i>',justifyLeft:'<i class="fa fa-align-left"></i>',justifyRight:'<i class="fa fa-align-right"></i>'}:"object"==typeof a&&(b=a),"object"==typeof b)for(c in b)b.hasOwnProperty(c)&&(d[c]=b[c]);return d},initToolbar:function(){return this.toolbar?this:(this.toolbar=this.createToolbar(),this.keepToolbarAlive=!1,this.anchorForm=this.toolbar.querySelector(".medium-editor-toolbar-form-anchor"),this.anchorInput=this.anchorForm.querySelector("input.medium-editor-toolbar-anchor-input"),this.anchorTarget=this.anchorForm.querySelector("input.medium-editor-toolbar-anchor-target"),this.anchorButton=this.anchorForm.querySelector("input.medium-editor-toolbar-anchor-button"),this.toolbarActions=this.toolbar.querySelector(".medium-editor-toolbar-actions"),this.anchorPreview=this.createAnchorPreview(),this)},createToolbar:function(){var a=b.createElement("div");return a.id="medium-editor-toolbar-"+this.id,a.className="medium-editor-toolbar",a.appendChild(this.toolbarButtons()),a.appendChild(this.toolbarFormAnchor()),this.options.elementsContainer.appendChild(a),a},toolbarButtons:function(){var a,c,d,e,f=this.options.buttons,g=b.createElement("ul");for(g.id="medium-editor-toolbar-actions",g.className="medium-editor-toolbar-actions clearfix",c=0;c<f.length;c+=1)this.options.extensions.hasOwnProperty(f[c])?(e=this.options.extensions[f[c]],d=void 0!==e.getButton?e.getButton():null):d=this.buttonTemplate(f[c]),d&&(a=b.createElement("li"),i(d)?a.appendChild(d):a.innerHTML=d,g.appendChild(a));return g},toolbarFormAnchor:function(){var a=b.createElement("div"),c=b.createElement("input"),d=b.createElement("label"),e=b.createElement("input"),f=b.createElement("label"),g=b.createElement("input"),h=b.createElement("a"),i=b.createElement("a");return h.setAttribute("href","#"),h.className="medium-editor-toobar-anchor-close",h.innerHTML="×",i.setAttribute("href","#"),i.className="medium-editor-toobar-anchor-save",i.innerHTML="✓",c.setAttribute("type","text"),c.className="medium-editor-toolbar-anchor-input",c.setAttribute("placeholder",this.options.anchorInputPlaceholder),e.setAttribute("type","checkbox"),e.className="medium-editor-toolbar-anchor-target",d.innerHTML="Open in New Window?",d.insertBefore(e,d.firstChild),g.setAttribute("type","checkbox"),g.className="medium-editor-toolbar-anchor-button",f.innerHTML="Button",f.insertBefore(g,f.firstChild),a.className="medium-editor-toolbar-form-anchor",a.id="medium-editor-toolbar-form-anchor",a.appendChild(c),a.appendChild(i),a.appendChild(h),this.options.anchorTarget&&a.appendChild(d),this.options.anchorButton&&a.appendChild(f),a},bindSelect:function(){var a,c=this,d="";for(this.checkSelectionWrapper=function(a){return a&&c.clickingIntoArchorForm(a)?!1:(clearTimeout(d),void(d=setTimeout(function(){c.checkSelection()},c.options.delay)))},this.on(b.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);return this},checkSelection:function(){var a,b;return this.keepToolbarAlive===!0||this.options.disableToolbar||(a=this.options.contentWindow.getSelection(),""===a.toString().trim()||this.options.allowMultiParagraphSelection===!1&&this.hasMultiParagraphs()||this.selectionInContentEditableFalse()?this.hideToolbarActions():(b=this.getSelectionElement(),!b||b.getAttribute("data-disable-toolbar")?this.hideToolbarActions():this.checkSelectionElement(a,b))),this},clickingIntoArchorForm:function(a){var b=this;return a.type&&"blur"===a.type.toLowerCase()&&a.relatedTarget&&a.relatedTarget===b.anchorInput?!0:!1},hasMultiParagraphs:function(){var a=h.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,b){var c;for(this.selection=a,this.selectionRange=this.selection.getRangeAt(0),c=0;c<this.elements.length;c+=1)if(this.elements[c]===b)return void this.setToolbarButtonStates().setToolbarPosition().showToolbarActions();this.hideToolbarActions()},findMatchingSelectionParent:function(a){var b,c,d=this.options.contentWindow.getSelection();if(0===d.rangeCount)return!1;b=d.getRangeAt(0),c=b.commonAncestorContainer;do{if(1===c.nodeType){if(a(c))return c;if(c.getAttribute("data-medium-element"))return!1}c=c.parentNode}while(c);return!1},getSelectionElement:function(){return this.findMatchingSelectionParent(function(a){return a.getAttribute("data-medium-element")})},selectionInContentEditableFalse:function(){return this.findMatchingSelectionParent(function(a){return a&&"#text"!==a.nodeName&&"false"===a.getAttribute("contenteditable")})},setToolbarPosition:function(){var a=50,b=this.options.contentWindow.getSelection(),c=b.getRangeAt(0),d=c.getBoundingClientRect(),e=this.options.diffLeft-this.toolbar.offsetWidth/2,f=(d.left+d.right)/2,g=this.toolbar.offsetWidth/2;return d.top<a?(this.toolbar.classList.add("medium-toolbar-arrow-over"),this.toolbar.classList.remove("medium-toolbar-arrow-under"),this.toolbar.style.top=a+d.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=d.top+this.options.diffTop+this.options.contentWindow.pageYOffset-this.toolbar.offsetHeight+"px"),this.toolbar.style.left=g>f?e+g+"px":this.options.contentWindow.innerWidth-f<g?this.options.contentWindow.innerWidth+e-g+"px":e+f+"px",this.hideAnchorPreview(),this},setToolbarButtonStates:function(){var a,b=this.toolbarActions.querySelectorAll("button");for(a=0;a<b.length;a+=1)b[a].classList.remove(this.options.activeButtonClass);return this.checkActiveButtons(),this},checkActiveButtons:function(){for(var a=Array.prototype.slice.call(this.elements),b=this.getSelectedParentElement();void 0!==b.tagName&&-1===this.parentElements.indexOf(b.tagName.toLowerCase)&&(this.activateButton(b.tagName.toLowerCase()),this.callExtensions("checkState",b),-1===a.indexOf(b));)b=b.parentNode},activateButton:function(a){var b=this.toolbar.querySelector('[data-element="'+a+'"]');null!==b&&-1===b.className.indexOf(this.options.activeButtonClass)&&(b.className+=" "+this.options.activeButtonClass)},bindButtons:function(){var a,b=this.toolbar.querySelectorAll("button"),c=this,d=function(a){a.preventDefault(),a.stopPropagation(),void 0===c.selection&&c.checkSelection(),this.className.indexOf(c.options.activeButtonClass)>-1?this.classList.remove(c.options.activeButtonClass):this.className+=" "+c.options.activeButtonClass,this.hasAttribute("data-action")&&c.execAction(this.getAttribute("data-action"),a)};for(a=0;a<b.length;a+=1)this.on(b[a],"click",d);return this.setFirstAndLastItems(b),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.triggerAnchorAction(b):"image"===a?this.options.ownerDocument.execCommand("insertImage",!1,this.options.contentWindow.getSelection()):(this.options.ownerDocument.execCommand(a,!1,null),this.setToolbarPosition())},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)?b.startContainer.childNodes[b.startOffset]:3===b.startContainer.nodeType?b.startContainer.parentNode:b.startContainer},triggerAnchorAction:function(){var a=this.getSelectedParentElement();return a.tagName&&"a"===a.tagName.toLowerCase()?this.options.ownerDocument.execCommand("unlink",!1,null):"block"===this.anchorForm.style.display?this.showToolbarActions():this.showAnchorForm(),this},execFormatBlock:function(a){var b=this.getSelectionData(this.selection.anchorNode);if("blockquote"===a&&b.el&&"blockquote"===b.el.parentNode.tagName.toLowerCase())return this.options.ownerDocument.execCommand("outdent",!1,null);if(b.tagName===a&&(a="p"),this.isIE){if("blockquote"===a)return this.options.ownerDocument.execCommand("indent",!1,a);a="<"+a+">"}return this.options.ownerDocument.execCommand("formatBlock",!1,a)},getSelectionData:function(a){var b;for(a&&a.tagName&&(b=a.tagName.toLowerCase());a&&-1===this.parentElements.indexOf(b);)a=a.parentNode,a&&a.tagName&&(b=a.tagName.toLowerCase());return{el:a,tagName:b}},getFirstChild:function(a){for(var b=a.firstChild;null!==b&&1!==b.nodeType;)b=b.nextSibling;return b},hideToolbarActions:function(){this.keepToolbarAlive=!1,void 0!==this.toolbar&&this.toolbar.classList.remove("medium-editor-toolbar-active")},showToolbarActions:function(){var a,b=this;this.anchorForm.style.display="none",this.toolbarActions.style.display="block",this.keepToolbarAlive=!1,clearTimeout(a),a=setTimeout(function(){b.toolbar&&!b.toolbar.classList.contains("medium-editor-toolbar-active")&&b.toolbar.classList.add("medium-editor-toolbar-active")},100)},saveSelection:function(){this.savedSelection=e.call(this)},restoreSelection:function(){f.call(this,this.savedSelection)},showAnchorForm:function(a){this.toolbarActions.style.display="none",this.saveSelection(),this.anchorForm.style.display="block",this.setToolbarPosition(),this.keepToolbarAlive=!0,this.anchorInput.focus(),this.anchorInput.value=a||""},bindAnchorForm:function(){var a=this.anchorForm.querySelector("a.medium-editor-toobar-anchor-close"),b=this.anchorForm.querySelector("a.medium-editor-toobar-anchor-save"),c=this;return this.on(this.anchorForm,"click",function(a){a.stopPropagation(),c.keepToolbarAlive=!0}),this.on(this.anchorInput,"keyup",function(a){var b,d=null;13===a.keyCode&&(a.preventDefault(),b=c.options.anchorTarget&&c.anchorTarget.checked?"_blank":"_self",c.options.anchorButton&&c.anchorButton.checked&&(d=c.options.anchorButtonClass),c.createLink(this,b,d))}),this.on(b,"click",function(a){var b,d=null;a.preventDefault(),b=c.options.anchorTarget&&c.anchorTarget.checked?"_blank":"_self",c.options.anchorButton&&c.anchorButton.checked&&(d=c.options.anchorButtonClass),c.createLink(c.anchorInput,b,d)},!0),this.on(this.anchorInput,"click",function(a){a.stopPropagation(),c.keepToolbarAlive=!0}),this.on(this.options.ownerDocument.body,"click",function(a){a.target===c.anchorForm||d(c.anchorForm,a.target)||d(c.toolbarActions,a.target)||(c.keepToolbarAlive=!1,c.checkSelection())},!0),this.on(this.options.ownerDocument.body,"focus",function(a){a.target===c.anchorForm||d(c.anchorForm,a.target)||d(c.toolbarActions,a.target)||(c.keepToolbarAlive=!1,c.checkSelection())},!0),this.on(a,"click",function(a){a.preventDefault(),c.showToolbarActions(),f.call(c,c.savedSelection)}),this},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,e=this,f=40,g=a.getBoundingClientRect(),h=(g.left+g.right)/2;return e.anchorPreview.querySelector("i").textContent=a.href,b=e.anchorPreview.offsetWidth/2,c=e.options.diffLeft-b,clearTimeout(d),d=setTimeout(function(){e.anchorPreview&&!e.anchorPreview.classList.contains("medium-editor-anchor-preview-active")&&e.anchorPreview.classList.add("medium-editor-anchor-preview-active")},100),e.observeAnchorPreview(a),e.anchorPreview.classList.add("medium-toolbar-arrow-over"),e.anchorPreview.classList.remove("medium-toolbar-arrow-under"),e.anchorPreview.style.top=Math.round(f+g.bottom-e.options.diffTop+this.options.contentWindow.pageYOffset-e.anchorPreview.offsetHeight)+"px",e.anchorPreview.style.left=b>h?c+b+"px":this.options.contentWindow.innerWidth-h<b?this.options.contentWindow.innerWidth+c-b+"px":c+h+"px",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.activeAnchor){var a=this,b=this.options.ownerDocument.createRange(),c=this.options.contentWindow.getSelection();b.selectNodeContents(a.activeAnchor),c.removeAllRanges(),c.addRange(b),setTimeout(function(){a.activeAnchor&&a.showAnchorForm(a.activeAnchor.href),a.keepToolbarAlive=!1},100+a.options.delay)}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.toolbar.classList.contains("medium-editor-toolbar-active"))return!0;this.activeAnchor=a.target,this.on(this.activeAnchor,"mouseout",d),setTimeout(function(){c&&b.showAnchorPreview(a.target)},b.options.delay)}},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},setTargetBlank:function(a){var b;if(a=a||g.call(this),"a"===a.tagName.toLowerCase())a.target="_blank";else for(a=a.getElementsByTagName("a"),b=0;b<a.length;b+=1)a[b].target="_blank"},setButtonClass:function(a){var b,c,d=g.call(this),e=a.split(" ");if("a"===d.tagName.toLowerCase())for(c=0;c<e.length;c+=1)d.classList.add(e[c]);else for(d=d.getElementsByTagName("a"),b=0;b<d.length;b+=1)for(c=0;c<e.length;c+=1)d[b].classList.add(e[c])},createLink:function(a,b,c){var d,e;if(0===a.value.trim().length)return void this.hideToolbarActions();if(f.call(this,this.savedSelection),this.options.checkLinkFormat&&(a.value=this.checkLinkFormat(a.value)),this.options.ownerDocument.execCommand("createLink",!1,a.value),(this.options.targetBlank||"_blank"===b)&&this.setTargetBlank(),c&&this.setButtonClass(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=""},bindWindowActions:function(){var a,b=this;return this.windowResizeHandler=function(){clearTimeout(a),a=setTimeout(function(){b.toolbar&&b.toolbar.classList.contains("medium-editor-toolbar-active")&&b.setToolbarPosition()},100)},this.on(this.options.contentWindow,"resize",this.windowResizeHandler),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.removeAllEvents()}},htmlEntities:function(a){return String(a).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},bindPaste:function(){var a,b=this;for(this.pasteWrapper=function(a){var c,d,e="";if(this.classList.remove("medium-editor-placeholder"),!b.options.forcePlainText&&!b.options.cleanPastedHTML)return this;if(a.clipboardData&&a.clipboardData.getData&&!a.defaultPrevented){if(a.preventDefault(),b.options.cleanPastedHTML&&a.clipboardData.getData("text/html"))return b.cleanPaste(a.clipboardData.getData("text/html"));if(b.options.disableReturn||this.getAttribute("data-disable-return"))e=b.htmlEntities(a.clipboardData.getData("text/plain")),b.options.ownerDocument.execCommand("insertHTML",!1,e);else{for(c=a.clipboardData.getData("text/plain").split(/[\r\n]/g),d=0;d<c.length;d+=1)""!==c[d]&&(e+=navigator.userAgent.match(/firefox/i)&&0===d?b.htmlEntities(c[d]):"<p>"+b.htmlEntities(c[d])+"</p>");b.options.ownerDocument.execCommand("insertHTML",!1,e)}}},a=0;a<this.elements.length;a+=1)this.on(this.elements[a],"paste",this.pasteWrapper);return this},setPlaceholders:function(){var a,b=function(a){a.querySelector("img")||a.querySelector("blockquote")||""!==a.textContent.replace(/^\s+|\s+$/g,"")||a.classList.add("medium-editor-placeholder")},c=function(a){this.classList.remove("medium-editor-placeholder"),"keypress"!==a.type&&b(this)};for(a=0;a<this.elements.length;a+=1)b(this.elements[a]),this.on(this.elements[a],"blur",c),this.on(this.elements[a],"keypress",c);return this},cleanPaste:function(a){var b,c,d,e=this.getSelectionElement(),f=/<p|<br|<div/.test(a),g=[[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">']];for(b=0;b<g.length;b+=1)a=a.replace(g[b][0],g[b][1]);if(f)for(c=a.split("<br><br>"),this.pasteHTML("<p>"+c.join("</p><p>")+"</p>"),this.options.ownerDocument.execCommand("insertText",!1,"\n"),c=e.querySelectorAll("a,p,div,br"),b=0;b<c.length;b+=1)switch(d=c[b],d.tagName.toLowerCase()){case"a":this.options.targetBlank&&this.setTargetBlank(d);break;case"p":case"div":this.filterCommonBlocks(d);break;case"br":this.filterLineBreak(d)}else this.pasteHTML(a)},pasteHTML:function(a){var b,c,d,e,f=this.options.ownerDocument.createDocumentFragment();for(f.appendChild(this.options.ownerDocument.createElement("body")),e=f.querySelector("body"),e.innerHTML=a,this.cleanupSpans(e),b=e.querySelectorAll("*"),d=0;d<b.length;d+=1)c=b[d],c.removeAttribute("class"),c.removeAttribute("style"),c.removeAttribute("dir"),"meta"===c.tagName.toLowerCase()&&c.parentNode.removeChild(c);this.options.ownerDocument.execCommand("insertHTML",!1,e.innerHTML.replace(/ /g," "))},isCommonBlock:function(a){return a&&("p"===a.tagName.toLowerCase()||"div"===a.tagName.toLowerCase())},filterCommonBlocks:function(a){/^\s*$/.test(a.innerText)&&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){var b,c,d,e=a.querySelectorAll(".replace-with");for(b=0;b<e.length;b+=1)c=e[b],d=this.options.ownerDocument.createElement(c.classList.contains("bold")?"b":"i"),d.innerHTML=c.classList.contains("bold")&&c.classList.contains("italic")?"<i>"+c.innerHTML+"</i>":c.innerHTML,c.parentNode.replaceChild(d,c);for(e=a.querySelectorAll("span"),b=0;b<e.length;b+=1)c=e[b],/^\s*$/.test()?c.parentNode.removeChild(c):c.parentNode.replaceChild(this.options.ownerDocument.createTextNode(c.innerText),c)}}}(window,document); | ||
function MediumEditor(a,b){"use strict";return this.init(a,b)}"object"==typeof module?module.exports=MediumEditor:"function"==typeof define&&define.amd&&define(function(){"use strict";return MediumEditor}),function(a,b){"use strict";function c(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}function d(a,b){for(var c=b.parentNode;null!==c;){if(c===a)return!0;c=c.parentNode}return!1}function e(){var a,b,c,d=this.options.contentWindow.getSelection();if(d.getRangeAt&&d.rangeCount){for(c=[],a=0,b=d.rangeCount;b>a;a+=1)c.push(d.getRangeAt(a));return c}return null}function f(a){var b,c,d=this.options.contentWindow.getSelection();if(a)for(d.removeAllRanges(),b=0,c=a.length;c>b;b+=1)d.addRange(a[b])}function g(){var a=this.options.ownerDocument.getSelection().anchorNode,b=a&&3===a.nodeType?a.parentNode:a;return b}function h(){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}function i(a){return!(!a||1!==a.nodeType)}function j(b,c){var d,e,f,g,h,i;if(b.queryCommandSupported("insertHTML"))return b.execCommand("insertHTML",!1,c);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))}}MediumEditor.prototype={defaults:{allowMultiParagraphSelection:!0,anchorInputPlaceholder:"Paste or type a link",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,contentWindow:a,ownerDocument:b,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"},isIE:"Microsoft Internet Explorer"===navigator.appName||"Netscape"===navigator.appName&&null!==new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})").exec(navigator.userAgent),init:function(a,d){var e=1;if(this.options=c(d,this.defaults),this.setElementSelection(a),0!==this.elements.length){for(this.parentElements=["p","h1","h2","h3","h4","h5","h6","blockquote","pre"],this.options.elementsContainer||(this.options.elementsContainer=b.body);this.options.elementsContainer.querySelector("#medium-editor-toolbar-"+e);)e+=1;return this.id=e,this.setup()}},setup:function(){this.events=[],this.isActive=!0,this.initElements().bindSelect().bindPaste().setPlaceholders().bindElementActions().bindWindowActions().passInstance()},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.events.indexOf([a,b,c,d]);-1!==f&&(e=this.events.splice(f,1),e[0].removeEventListener(e[1],e[2],e[3]))},removeAllEvents:function(){for(var a=this.events.pop();a;)a[0].removeEventListener(a[1],a[2],a[3]),a=this.events.pop()},initElements:function(){this.updateElementList();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.bindParagraphCreation(a),this.options.disableToolbar||this.elements[a].getAttribute("data-disable-toolbar")||(b=!0);return b&&this.initToolbar().bindButtons().bindAnchorForm().bindAnchorPreview(),this},setElementSelection:function(a){this.elementSelection=a,this.updateElementList()},updateElementList:function(){this.elements="string"==typeof this.elementSelection?this.options.ownerDocument.querySelectorAll(this.elementSelection):this.elementSelection,1===this.elements.nodeType&&(this.elements=[this.elements])},bindBlur:function(){var a,c=this,e=function(b){b.target===c.toolbar||b.target===c.elements[0]||d(c.elements[0],b.target)||d(c.toolbar,b.target)||d(c.anchorPreview,b.target)||(c.options.disablePlaceholders||c.placeholderWrapper(c.elements[0],b),clearTimeout(a),a=setTimeout(function(){c.keepToolbarAlive||c.hideToolbarActions()},200))};return this.on(b.body,"click",e,!0),this.on(b.body,"focus",e,!0),this},bindKeypress:function(a){if(this.options.disablePlaceholders)return this;var b=this;return this.on(this.elements[a],"keypress",function(a){b.placeholderWrapper(this,a)}),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).bindTab(a).bindBlur(a).bindClick(a).bindKeypress(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){a.classList.remove("medium-editor-placeholder"),"keypress"!==b.type&&this.activatePlaceholder(a)},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},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))}},passInstance:function(){var a,b,c=this;for(b in c.options.extensions)c.options.extensions.hasOwnProperty(b)&&(a=c.options.extensions[b],a.parent&&(a.base=c));return c},bindParagraphCreation:function(a){var c=this;return this.on(this.elements[a],"keypress",function(a){var d,e;32===a.which&&(d=g.call(c),e=d.tagName.toLowerCase(),"a"===e&&b.execCommand("unlink",!1,null))}),this.on(this.elements[a],"keyup",function(a){var d,e,f=g.call(c);f&&f.getAttribute("data-medium-element")&&0===f.children.length&&!c.options.disableReturn&&!f.getAttribute("data-disable-return")&&b.execCommand("formatBlock",!1,"p"),13===a.which&&(f=g.call(c),d=f.tagName.toLowerCase(),e=c.getSelectionElement(),c.options.disableReturn||e.getAttribute("data-disable-return")||"li"===d||c.isListItemChild(f)||(a.shiftKey||b.execCommand("formatBlock",!1,"p"),"a"===d&&b.execCommand("unlink",!1,null)))}),this},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},bindReturn:function(a){var b=this;return this.on(this.elements[a],"keypress",function(a){if(13===a.which)if(b.options.disableReturn||this.getAttribute("data-disable-return"))a.preventDefault();else if(b.options.disableDoubleReturn||this.getAttribute("data-disable-double-return")){var c=g.call(b);c&&"\n"===c.textContent&&a.preventDefault()}}),this},bindTab:function(a){var c=this;return this.on(this.elements[a],"keydown",function(a){if(9===a.which){var d=g.call(c).tagName.toLowerCase();"pre"===d&&(a.preventDefault(),b.execCommand("insertHtml",null," ")),"li"===d&&(a.preventDefault(),a.shiftKey?b.execCommand("outdent",a):b.execCommand("indent",a))}}),this},buttonTemplate:function(a){var b=this.getButtonLabels(this.options.buttonLabels),c={bold:'<button class="medium-editor-action medium-editor-action-bold" data-action="bold" data-element="b">'+b.bold+"</button>",italic:'<button class="medium-editor-action medium-editor-action-italic" data-action="italic" data-element="i">'+b.italic+"</button>",underline:'<button class="medium-editor-action medium-editor-action-underline" data-action="underline" data-element="u">'+b.underline+"</button>",strikethrough:'<button class="medium-editor-action medium-editor-action-strikethrough" data-action="strikethrough" data-element="strike">'+b.strikethrough+"</button>",superscript:'<button class="medium-editor-action medium-editor-action-superscript" data-action="superscript" data-element="sup">'+b.superscript+"</button>",subscript:'<button class="medium-editor-action medium-editor-action-subscript" data-action="subscript" data-element="sub">'+b.subscript+"</button>",anchor:'<button class="medium-editor-action medium-editor-action-anchor" data-action="anchor" data-element="a">'+b.anchor+"</button>",image:'<button class="medium-editor-action medium-editor-action-image" data-action="image" data-element="img">'+b.image+"</button>",header1:'<button class="medium-editor-action medium-editor-action-header1" data-action="append-'+this.options.firstHeader+'" data-element="'+this.options.firstHeader+'">'+b.header1+"</button>",header2:'<button class="medium-editor-action medium-editor-action-header2" data-action="append-'+this.options.secondHeader+'" data-element="'+this.options.secondHeader+'">'+b.header2+"</button>",quote:'<button class="medium-editor-action medium-editor-action-quote" data-action="append-blockquote" data-element="blockquote">'+b.quote+"</button>",orderedlist:'<button class="medium-editor-action medium-editor-action-orderedlist" data-action="insertorderedlist" data-element="ol">'+b.orderedlist+"</button>",unorderedlist:'<button class="medium-editor-action medium-editor-action-unorderedlist" data-action="insertunorderedlist" data-element="ul">'+b.unorderedlist+"</button>",pre:'<button class="medium-editor-action medium-editor-action-pre" data-action="append-pre" data-element="pre">'+b.pre+"</button>",indent:'<button class="medium-editor-action medium-editor-action-indent" data-action="indent" data-element="ul">'+b.indent+"</button>",outdent:'<button class="medium-editor-action medium-editor-action-outdent" data-action="outdent" data-element="ul">'+b.outdent+"</button>",justifyCenter:'<button class="medium-editor-action medium-editor-action-justifyCenter" data-action="justifyCenter" data-element="">'+b.justifyCenter+"</button>",justifyFull:'<button class="medium-editor-action medium-editor-action-justifyFull" data-action="justifyFull" data-element="">'+b.justifyFull+"</button>",justifyLeft:'<button class="medium-editor-action medium-editor-action-justifyLeft" data-action="justifyLeft" data-element="">'+b.justifyLeft+"</button>",justifyRight:'<button class="medium-editor-action medium-editor-action-justifyRight" data-action="justifyRight" data-element="">'+b.justifyRight+"</button>"};return c[a]||!1},getButtonLabels:function(a){var b,c,d={bold:"<b>B</b>",italic:"<b><i>I</i></b>",underline:"<b><u>U</u></b>",strikethrough:"<s>A</s>",superscript:"<b>x<sup>1</sup></b>",subscript:"<b>x<sub>1</sub></b>",anchor:"<b>#</b>",image:"<b>image</b>",header1:"<b>H1</b>",header2:"<b>H2</b>",quote:"<b>“</b>",orderedlist:"<b>1.</b>",unorderedlist:"<b>•</b>",pre:"<b>0101</b>",indent:"<b>→</b>",outdent:"<b>←</b>",justifyCenter:"<b>C</b>",justifyFull:"<b>J</b>",justifyLeft:"<b>L</b>",justifyRight:"<b>R</b>"};if("fontawesome"===a?b={bold:'<i class="fa fa-bold"></i>',italic:'<i class="fa fa-italic"></i>',underline:'<i class="fa fa-underline"></i>',strikethrough:'<i class="fa fa-strikethrough"></i>',superscript:'<i class="fa fa-superscript"></i>',subscript:'<i class="fa fa-subscript"></i>',anchor:'<i class="fa fa-link"></i>',image:'<i class="fa fa-picture-o"></i>',quote:'<i class="fa fa-quote-right"></i>',orderedlist:'<i class="fa fa-list-ol"></i>',unorderedlist:'<i class="fa fa-list-ul"></i>',pre:'<i class="fa fa-code fa-lg"></i>',indent:'<i class="fa fa-indent"></i>',outdent:'<i class="fa fa-outdent"></i>',justifyCenter:'<i class="fa fa-align-center"></i>',justifyFull:'<i class="fa fa-align-justify"></i>',justifyLeft:'<i class="fa fa-align-left"></i>',justifyRight:'<i class="fa fa-align-right"></i>'}:"object"==typeof a&&(b=a),"object"==typeof b)for(c in b)b.hasOwnProperty(c)&&(d[c]=b[c]);return d},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.options.disableAnchorForm||(this.anchorForm=this.toolbar.querySelector(".medium-editor-toolbar-form-anchor"),this.anchorInput=this.anchorForm.querySelector("input.medium-editor-toolbar-anchor-input"),this.anchorTarget=this.anchorForm.querySelector("input.medium-editor-toolbar-anchor-target"),this.anchorButton=this.anchorForm.querySelector("input.medium-editor-toolbar-anchor-button")),this)},createToolbar:function(){var a=b.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||a.appendChild(this.toolbarFormAnchor()),this.options.elementsContainer.appendChild(a),a},toolbarButtons:function(){var a,c,d,e,f=this.options.buttons,g=b.createElement("ul");for(g.id="medium-editor-toolbar-actions"+this.id,g.className="medium-editor-toolbar-actions clearfix",c=0;c<f.length;c+=1)this.options.extensions.hasOwnProperty(f[c])?(e=this.options.extensions[f[c]],d=void 0!==e.getButton?e.getButton():null):d=this.buttonTemplate(f[c]),d&&(a=b.createElement("li"),i(d)?a.appendChild(d):a.innerHTML=d,g.appendChild(a));return g},toolbarFormAnchor:function(){var a=b.createElement("div"),c=b.createElement("input"),d=b.createElement("label"),e=b.createElement("input"),f=b.createElement("label"),g=b.createElement("input"),h=b.createElement("a"),i=b.createElement("a");return h.setAttribute("href","#"),h.className="medium-editor-toobar-anchor-close",h.innerHTML="×",i.setAttribute("href","#"),i.className="medium-editor-toobar-anchor-save",i.innerHTML="✓",c.setAttribute("type","text"),c.className="medium-editor-toolbar-anchor-input",c.setAttribute("placeholder",this.options.anchorInputPlaceholder),e.setAttribute("type","checkbox"),e.className="medium-editor-toolbar-anchor-target",d.innerHTML="Open in New Window?",d.insertBefore(e,d.firstChild),g.setAttribute("type","checkbox"),g.className="medium-editor-toolbar-anchor-button",f.innerHTML="Button",f.insertBefore(g,f.firstChild),a.className="medium-editor-toolbar-form-anchor",a.id="medium-editor-toolbar-form-anchor-"+this.id,a.appendChild(c),a.appendChild(i),a.appendChild(h),this.options.anchorTarget&&a.appendChild(d),this.options.anchorButton&&a.appendChild(f),a},bindSelect:function(){var a,c=this,d="";for(this.checkSelectionWrapper=function(a){return!c.options.disableAnchorForm&&a&&c.clickingIntoArchorForm(a)?!1:(clearTimeout(d),void(d=setTimeout(function(){c.checkSelection()},c.options.delay)))},this.on(b.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",this.checkSelectionWrapper);return this},checkSelection:function(){var a,b;return this.keepToolbarAlive===!0||this.options.disableToolbar||(a=this.options.contentWindow.getSelection(),!this.options.updateOnEmptySelection&&""===a.toString().trim()||this.options.allowMultiParagraphSelection===!1&&this.hasMultiParagraphs()||this.selectionInContentEditableFalse()?this.options.staticToolbar?this.anchorForm&&"block"===this.anchorForm.style.display&&(this.setToolbarButtonStates(),this.showToolbarActions()):this.hideToolbarActions():(b=this.getSelectionElement(),!b||b.getAttribute("data-disable-toolbar")?this.options.staticToolbar||this.hideToolbarActions():this.checkSelectionElement(a,b))),this},clickingIntoArchorForm:function(a){var b=this;return a.type&&"blur"===a.type.toLowerCase()&&a.relatedTarget&&a.relatedTarget===b.anchorInput?!0:!1},hasMultiParagraphs:function(){var a=h.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,b){var c;for(this.selection=a,this.selectionRange=this.selection.getRangeAt(0),c=0;c<this.elements.length;c+=1)if(this.elements[c]===b)return void this.setToolbarButtonStates().setToolbarPosition().showToolbarActions();this.options.staticToolbar||this.hideToolbarActions()},findMatchingSelectionParent:function(a){var b,c,d=this.options.contentWindow.getSelection();if(0===d.rangeCount)return!1;b=d.getRangeAt(0),c=b.commonAncestorContainer;do{if(1===c.nodeType){if(a(c))return c;if(c.getAttribute("data-medium-element"))return!1}c=c.parentNode}while(c);return!1},getSelectionElement:function(){return this.findMatchingSelectionParent(function(a){return a.getAttribute("data-medium-element")})},selectionInContentEditableFalse:function(){return this.findMatchingSelectionParent(function(a){return a&&"#text"!==a.nodeName&&"false"===a.getAttribute("contenteditable")})},setToolbarPosition:function(){var c,d,e,f=b.documentElement&&b.documentElement.scrollTop||b.body.scrollTop,g=this.elements[0],h=g.getBoundingClientRect(),i=h.top+f,j=50,k=a.getSelection(),l=this.options.diffLeft-this.toolbar.offsetWidth/2,m=this.toolbar.offsetWidth/2;return null===k.focusNode?this:(this.toolbar.classList.add("medium-editor-toolbar-active"),this.options.staticToolbar?(this.options.stickyToolbar?f>i+this.elements[0].offsetHeight-this.toolbar.offsetHeight?this.toolbar.style.top=i+this.elements[0].offsetHeight+"px":f>i-this.toolbar.offsetHeight?(this.toolbar.classList.add("sticky-toolbar"),this.toolbar.style.top="0px"):(this.toolbar.classList.remove("sticky-toolbar"),this.toolbar.style.top=i-this.toolbar.offsetHeight+"px"):this.toolbar.style.top=i-this.toolbar.offsetHeight+"px",this.toolbar.style.left=h.left+"px"):k.isCollapsed||(c=k.getRangeAt(0),d=c.getBoundingClientRect(),e=(d.left+d.right)/2,d.top<j?(this.toolbar.classList.add("medium-toolbar-arrow-over"),this.toolbar.classList.remove("medium-toolbar-arrow-under"),this.toolbar.style.top=j+d.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=d.top+this.options.diffTop+this.options.contentWindow.pageYOffset-this.toolbar.offsetHeight+"px"),this.toolbar.style.left=m>e?l+m+"px":this.options.contentWindow.innerWidth-e<m?this.options.contentWindow.innerWidth+l-m+"px":l+e+"px"),this.hideAnchorPreview(),this)},setToolbarButtonStates:function(){var a,b=this.toolbarActions.querySelectorAll("button");for(a=0;a<b.length;a+=1)b[a].classList.remove(this.options.activeButtonClass);return this.checkActiveButtons(),this},checkActiveButtons:function(){for(var a=Array.prototype.slice.call(this.elements),b=this.getSelectedParentElement();void 0!==b.tagName&&-1===this.parentElements.indexOf(b.tagName.toLowerCase)&&(this.activateButton(b.tagName.toLowerCase()),this.callExtensions("checkState",b),-1===a.indexOf(b));)b=b.parentNode},activateButton:function(a){var b=this.toolbar.querySelector('[data-element="'+a+'"]');null!==b&&-1===b.className.indexOf(this.options.activeButtonClass)&&(b.className+=" "+this.options.activeButtonClass)},bindButtons:function(){var a,b=this.toolbar.querySelectorAll("button"),c=this,d=function(a){a.preventDefault(),a.stopPropagation(),void 0===c.selection&&c.checkSelection(),this.className.indexOf(c.options.activeButtonClass)>-1?this.classList.remove(c.options.activeButtonClass):this.className+=" "+c.options.activeButtonClass,this.hasAttribute("data-action")&&c.execAction(this.getAttribute("data-action"),a)};for(a=0;a<b.length;a+=1)this.on(b[a],"click",d);return this.setFirstAndLastItems(b),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())},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)?b.startContainer.childNodes[b.startOffset]:3===b.startContainer.nodeType?b.startContainer.parentNode:b.startContainer},triggerAnchorAction:function(){var a=this.getSelectedParentElement();return a.tagName&&"a"===a.tagName.toLowerCase()?this.options.ownerDocument.execCommand("unlink",!1,null):this.anchorForm&&("block"===this.anchorForm.style.display?this.showToolbarActions():this.showAnchorForm()),this},execFormatBlock:function(a){var b=this.getSelectionData(this.selection.anchorNode);if("blockquote"===a&&b.el&&"blockquote"===b.el.parentNode.tagName.toLowerCase())return this.options.ownerDocument.execCommand("outdent",!1,null);if(b.tagName===a&&(a="p"),this.isIE){if("blockquote"===a)return this.options.ownerDocument.execCommand("indent",!1,a);a="<"+a+">"}return this.options.ownerDocument.execCommand("formatBlock",!1,a)},getSelectionData:function(a){var b;for(a&&a.tagName&&(b=a.tagName.toLowerCase());a&&-1===this.parentElements.indexOf(b);)a=a.parentNode,a&&a.tagName&&(b=a.tagName.toLowerCase());return{el:a,tagName:b}},getFirstChild:function(a){for(var b=a.firstChild;null!==b&&1!==b.nodeType;)b=b.nextSibling;return b},hideToolbarActions:function(){this.keepToolbarAlive=!1,void 0!==this.toolbar&&this.toolbar.classList.contains("medium-editor-toolbar-active")&&(this.toolbar.classList.remove("medium-editor-toolbar-active"),this.onHideToolbar&&this.onHideToolbar())},showToolbarActions:function(){var a,b=this;this.anchorForm&&(this.anchorForm.style.display="none"),this.toolbarActions.style.display="block",this.keepToolbarAlive=!1,clearTimeout(a),a=setTimeout(function(){b.toolbar&&!b.toolbar.classList.contains("medium-editor-toolbar-active")&&b.toolbar.classList.add("medium-editor-toolbar-active")},100)},saveSelection:function(){this.savedSelection=e.call(this)},restoreSelection:function(){f.call(this,this.savedSelection)},showAnchorForm:function(a){this.anchorForm&&(this.toolbarActions.style.display="none",this.saveSelection(),this.anchorForm.style.display="block",this.setToolbarPosition(),this.keepToolbarAlive=!0,this.anchorInput.focus(),this.anchorInput.value=a||"")},bindAnchorForm:function(){if(!this.anchorForm)return this;var a=this.anchorForm.querySelector("a.medium-editor-toobar-anchor-close"),b=this.anchorForm.querySelector("a.medium-editor-toobar-anchor-save"),c=this;return this.on(this.anchorForm,"click",function(a){a.stopPropagation(),c.keepToolbarAlive=!0}),this.on(this.anchorInput,"keyup",function(a){var b,d=null;13===a.keyCode&&(a.preventDefault(),b=c.options.anchorTarget&&c.anchorTarget.checked?"_blank":"_self",c.options.anchorButton&&c.anchorButton.checked&&(d=c.options.anchorButtonClass),c.createLink(this,b,d))}),this.on(b,"click",function(a){var b,d=null;a.preventDefault(),b=c.options.anchorTarget&&c.anchorTarget.checked?"_blank":"_self",c.options.anchorButton&&c.anchorButton.checked&&(d=c.options.anchorButtonClass),c.createLink(c.anchorInput,b,d)},!0),this.on(this.anchorInput,"click",function(a){a.stopPropagation(),c.keepToolbarAlive=!0}),this.on(this.options.ownerDocument.body,"click",function(a){a.target===c.anchorForm||d(c.anchorForm,a.target)||d(c.toolbarActions,a.target)||(c.keepToolbarAlive=!1,c.checkSelection())},!0),this.on(this.options.ownerDocument.body,"focus",function(a){a.target===c.anchorForm||d(c.anchorForm,a.target)||d(c.toolbarActions,a.target)||(c.keepToolbarAlive=!1,c.checkSelection())},!0),this.on(a,"click",function(a){a.preventDefault(),c.showToolbarActions(),f.call(c,c.savedSelection)}),this},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,e=this,f=40,g=a.getBoundingClientRect(),h=(g.left+g.right)/2;return e.anchorPreview.querySelector("i").textContent=a.href,b=e.anchorPreview.offsetWidth/2,c=e.options.diffLeft-b,clearTimeout(d),d=setTimeout(function(){e.anchorPreview&&!e.anchorPreview.classList.contains("medium-editor-anchor-preview-active")&&e.anchorPreview.classList.add("medium-editor-anchor-preview-active")},100),e.observeAnchorPreview(a),e.anchorPreview.classList.add("medium-toolbar-arrow-over"),e.anchorPreview.classList.remove("medium-toolbar-arrow-under"),e.anchorPreview.style.top=Math.round(f+g.bottom-e.options.diffTop+this.options.contentWindow.pageYOffset-e.anchorPreview.offsetHeight)+"px",e.anchorPreview.style.left=b>h?c+b+"px":this.options.contentWindow.innerWidth-h<b?this.options.contentWindow.innerWidth+c-b+"px":c+h+"px",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),setTimeout(function(){a.activeAnchor&&a.showAnchorForm(a.activeAnchor.href),a.keepToolbarAlive=!1},100+a.options.delay)}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.toolbar.classList.contains("medium-editor-toolbar-active"))return!0;this.activeAnchor=a.target,this.on(this.activeAnchor,"mouseout",d),setTimeout(function(){c&&b.showAnchorPreview(a.target)},b.options.delay)}},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},setTargetBlank:function(a){var b;if(a=a||g.call(this),"a"===a.tagName.toLowerCase())a.target="_blank";else for(a=a.getElementsByTagName("a"),b=0;b<a.length;b+=1)a[b].target="_blank"},setButtonClass:function(a){var b,c,d=g.call(this),e=a.split(" ");if("a"===d.tagName.toLowerCase())for(c=0;c<e.length;c+=1)d.classList.add(e[c]);else for(d=d.getElementsByTagName("a"),b=0;b<d.length;b+=1)for(c=0;c<e.length;c+=1)d[b].classList.add(e[c])},createLink:function(a,b,c){var d,e;if(0===a.value.trim().length)return void this.hideToolbarActions();if(f.call(this,this.savedSelection),this.options.checkLinkFormat&&(a.value=this.checkLinkFormat(a.value)),this.options.ownerDocument.execCommand("createLink",!1,a.value),(this.options.targetBlank||"_blank"===b)&&this.setTargetBlank(),c&&this.setButtonClass(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=""},bindWindowActions:function(){var b,c=this;return this.windowResizeHandler=function(){clearTimeout(b),b=setTimeout(function(){c.toolbar&&c.toolbar.classList.contains("medium-editor-toolbar-active")&&c.setToolbarPosition()},100)},this.options.staticToolbar&&this.options.stickyToolbar&&this.on(a,"scroll",function(){c.toolbar&&c.toolbar.classList.contains("medium-editor-toolbar-active")&&c.setToolbarPosition()},!0),this.on(this.options.contentWindow,"resize",this.windowResizeHandler),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.removeAllEvents()}},htmlEntities:function(a){return String(a).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},bindPaste:function(){var b,c=this;for(this.pasteWrapper=function(b){var d,e,f="",g="text/html",h="text/plain";if(this.classList.remove("medium-editor-placeholder"),!c.options.forcePlainText&&!c.options.cleanPastedHTML)return this;if(a.clipboardData&&void 0===b.clipboardData&&(b.clipboardData=a.clipboardData,g="Text",h="Text"),b.clipboardData&&b.clipboardData.getData&&!b.defaultPrevented){if(b.preventDefault(),c.options.cleanPastedHTML&&b.clipboardData.getData(g))return c.cleanPaste(b.clipboardData.getData(g));if(c.options.disableReturn||this.getAttribute("data-disable-return"))f=c.htmlEntities(b.clipboardData.getData(h)),j(c.options.ownerDocument,f);else{for(d=b.clipboardData.getData(h).split(/[\r\n]/g),e=0;e<d.length;e+=1)""!==d[e]&&(f+=navigator.userAgent.match(/firefox/i)&&0===e?c.htmlEntities(d[e]):"<p>"+c.htmlEntities(d[e])+"</p>");j(c.options.ownerDocument,f)}}},b=0;b<this.elements.length;b+=1)this.on(this.elements[b],"paste",this.pasteWrapper);return this},setPlaceholders:function(){if(this.options.disablePlaceholders)return this;var a,b=function(a){a.querySelector("img")||a.querySelector("blockquote")||""!==a.textContent.replace(/^\s+|\s+$/g,"")||a.classList.add("medium-editor-placeholder")},c=function(a){this.classList.remove("medium-editor-placeholder"),"keypress"!==a.type&&b(this)};for(a=0;a<this.elements.length;a+=1)b(this.elements[a]),this.on(this.elements[a],"blur",c),this.on(this.elements[a],"keypress",c);return this},cleanPaste:function(a){var b,c,d,e=this.getSelectionElement(),f=/<p|<br|<div/.test(a),g=[[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">']]; | ||
for(b=0;b<g.length;b+=1)a=a.replace(g[b][0],g[b][1]);if(f)for(c=a.split("<br><br>"),this.pasteHTML("<p>"+c.join("</p><p>")+"</p>"),this.options.ownerDocument.execCommand("insertText",!1,"\n"),c=e.querySelectorAll("a,p,div,br"),b=0;b<c.length;b+=1)switch(d=c[b],d.tagName.toLowerCase()){case"a":this.options.targetBlank&&this.setTargetBlank(d);break;case"p":case"div":this.filterCommonBlocks(d);break;case"br":this.filterLineBreak(d)}else this.pasteHTML(a)},pasteHTML:function(a){var b,c,d,e,f=this.options.ownerDocument.createDocumentFragment();for(f.appendChild(this.options.ownerDocument.createElement("body")),e=f.querySelector("body"),e.innerHTML=a,this.cleanupSpans(e),b=e.querySelectorAll("*"),d=0;d<b.length;d+=1)c=b[d],c.removeAttribute("class"),c.removeAttribute("style"),c.removeAttribute("dir"),"meta"===c.tagName.toLowerCase()&&c.parentNode.removeChild(c);this.options.ownerDocument.execCommand("insertHTML",!1,e.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){var b,c,d,e=a.querySelectorAll(".replace-with");for(b=0;b<e.length;b+=1)c=e[b],d=this.options.ownerDocument.createElement(c.classList.contains("bold")?"b":"i"),d.innerHTML=c.classList.contains("bold")&&c.classList.contains("italic")?"<i>"+c.innerHTML+"</i>":c.innerHTML,c.parentNode.replaceChild(d,c);for(e=a.querySelectorAll("span"),b=0;b<e.length;b+=1)c=e[b],/^\s*$/.test()?c.parentNode.removeChild(c):c.parentNode.replaceChild(this.options.ownerDocument.createTextNode(c.textContent),c)}}}(window,document); |
@@ -100,2 +100,6 @@ /*global module, require*/ | ||
main: { | ||
options: { | ||
noAdvanced: true | ||
}, | ||
expand: true, | ||
@@ -108,2 +112,6 @@ cwd: 'dist/css/', | ||
themes: { | ||
options: { | ||
noAdvanced: true | ||
}, | ||
expand: true, | ||
@@ -110,0 +118,0 @@ cwd: 'dist/css/themes/', |
{ | ||
"name": "medium-editor", | ||
"version": "1.9.13", | ||
"version": "2.0.0", | ||
"author": "Davi Ferreira <hi@daviferreira.com>", | ||
@@ -25,4 +25,4 @@ "description": "Medium.com WYSIWYG editor clone.", | ||
"grunt": "~0.4.5", | ||
"grunt-autoprefixer": "~2.0.0", | ||
"grunt-contrib-uglify": "~0.6.0", | ||
"grunt-autoprefixer": "~2.1.0", | ||
"grunt-contrib-uglify": "~0.7.0", | ||
"grunt-contrib-jasmine": "~0.8.0", | ||
@@ -36,4 +36,4 @@ "grunt-contrib-csslint": "~0.3.1", | ||
"brfs": "1.2.0", | ||
"grunt-sass": "~0.16.0", | ||
"grunt-contrib-cssmin": "~0.10.0" | ||
"grunt-sass": "~0.17.0", | ||
"grunt-contrib-cssmin": "~0.11.0" | ||
}, | ||
@@ -40,0 +40,0 @@ "scripts": { |
209
README.md
@@ -52,32 +52,43 @@ # MediumEditor | ||
If you want to support IE9, you will need to use a classList pollyfill, like Eli Gray's, available at [https://github.com/eligrey/classList.js](https://github.com/eligrey/classList.js). | ||
If you want to support IE9, you will need to use a classList pollyfill, like Eli Grey's, available at [https://github.com/eligrey/classList.js](https://github.com/eligrey/classList.js). | ||
## Initialization options | ||
### Core options | ||
* __allowMultiParagraphSelection__: enables the toolbar when selecting multiple paragraphs/block elements. Default: true | ||
* __anchorInputPlaceholder__: text to be shown as placeholder of the anchor input. Default: _Paste or type a link_ | ||
* __anchorPreviewHideDelay__: time in milliseconds to show the anchor tag preview after the mouse has left the anchor tag. Default: 500 | ||
* __buttons__: the set of buttons to display on the toolbar. Default: ['bold', 'italic', 'underline', 'anchor', 'header1', 'header2', 'quote'] | ||
* __buttonLabels__: type of labels on the buttons. Values: 'fontawesome', `{'bold': '<b>b</b>', 'italic': '<i>i</i>'}`. Default: false | ||
* __checkLinkFormat__: enables/disables check for common URL protocols on anchor links. Default: false | ||
* __cleanPastedHTML__: cleans pasted content from different sources, like google docs etc. Default: false | ||
* __delay__: time in milliseconds to show the toolbar or anchor tag preview. Default: 0 | ||
* __diffLeft__: value in pixels to be added to the X axis positioning of the toolbar. Default: 0 | ||
* __diffTop__: value in pixels to be added to the Y axis positioning of the toolbar. Default: -10 | ||
* __disableReturn__: enables/disables the use of the return-key. You can also set specific element behavior by using setting a data-disable-return attribute. Default: false | ||
* __disableDoubleReturn__: allows/disallows two (or more) empty new lines. You can also set specific element behavior by using setting a data-disable-double-return attribute. Default: false | ||
* __disableToolbar__: enables/disables the toolbar, adding only the contenteditable behavior. You can also set specific element behavior by using setting a data-disable-toolbar attribute. Default: false | ||
* __disableEditing__: enables/disables adding the contenteditable behavior. Useful for using the toolbar with customized buttons/actions. You can also set specific element behavior by using setting a data-disable-editing attribute. Default: false | ||
* __disablePlaceholders__: enables/disables support for __placeholder__, including DOM element creation and attaching event handlers. When disabled, medium-editor will ignore the __placholder__ option and not show placeholder text. Default: false | ||
* __elementsContainer__: specifies a DOM node to contain MediumEditor's toolbar and anchor preview elements. Default: document.body | ||
* __extensions__: extension to use (see _Extensions_) for more. Default: {} | ||
* __firstHeader__: HTML tag to be used as first header. Default: h3 | ||
* __forcePlainText__: Forces pasting as plain text. Default: true | ||
* __placeholder__: Defines the default placeholder for empty contenteditables. You can overwrite it by setting a data-placeholder attribute on your elements. Default: 'Type your text' | ||
* __placeholder__: Defines the default placeholder for empty contenteditables when __disablePlaceholders__ is not set to true. You can overwrite it by setting a data-placeholder attribute on your elements. Default: 'Type your text' | ||
* __secondHeader__: HTML tag to be used as second header. Default: h4 | ||
* __targetBlank__: enables/disables target="\_blank" for anchor tags. Default: false | ||
### Toolbar options | ||
* __activeButtonClass__: CSS class added to active buttons in the toolbar. Default: 'medium-editor-button-active' | ||
* __buttons__: the set of buttons to display on the toolbar. Default: ['bold', 'italic', 'underline', 'anchor', 'header1', 'header2', 'quote'] | ||
* __buttonLabels__: type of labels on the buttons. Values: 'fontawesome', `{'bold': '<b>b</b>', 'italic': '<i>i</i>'}`. Default: false | ||
* __diffLeft__: value in pixels to be added to the X axis positioning of the toolbar. Default: 0 | ||
* __diffTop__: value in pixels to be added to the Y axis positioning of the toolbar. Default: -10 | ||
* __disableToolbar__: enables/disables the toolbar, adding only the contenteditable behavior. You can also set specific element behavior by using setting a data-disable-toolbar attribute. Default: false | ||
* __firstButtonClass__: CSS class added to the first button in the toolbar. Default: 'medium-editor-button-first' | ||
* __lastButtonClass__: CSS class added to the last button in the toolbar. Default: 'medium-editor-button-last' | ||
* __onHideToolbar__: optional callback that will be called each time the toolbar is actually hidden for this instance of medium-editor. | ||
* __staticToolbar__: enable/disable the toolbar always displaying in the same location relative to the medium-editor element. Default: false | ||
* __stickyToolbar__: enable/disable the toolbar "sticking" to the medium-editor element when the page is being scrolled. Default: false | ||
* __updateOnEmptySelection__: update the state of the toolbar buttons even when the selection is collapse (there is no selection, just a cursor). Default: false | ||
### Anchor form options | ||
* __anchorButton__: enables/disables adding class __anchorButtonClass__ to anchor tags. Default: false | ||
* __anchorButtonClass__: class to add to anchor tags, when __anchorButton__ is set to true. Default: btn | ||
* __extensions__: extension to use (see _Extensions_) for more. Default: {} | ||
* __activeButtonClass__: CSS class added to active buttons. Default: 'medium-editor-button-active' | ||
* __firstButtonClass__: CSS class added to the first button. Default: 'medium-editor-button-first' | ||
* __lastButtonClass__: CSS class added to the last button. Default: 'medium-editor-button-last' | ||
* __anchorInputPlaceholder__: text to be shown as placeholder of the anchor input. Default: _Paste or type a link_ | ||
* __anchorPreviewHideDelay__: time in milliseconds to show the anchor tag preview after the mouse has left the anchor tag. Default: 500 | ||
* __checkLinkFormat__: enables/disables check for common URL protocols on anchor links. Default: false | ||
* __disableAnchorForm__: enables/disables the built-in anchor url collection ux, including DOM element creation and attaching event handlers. When disabled, medium-editor will not automatically handle collecting a url if a 'anchor' button is included in the toolbar. Default: false | ||
* __targetBlank__: enables/disables target="\_blank" for anchor tags. Default: false | ||
@@ -150,3 +161,3 @@ Example: | ||
To add additional additional functions that are not supported by the native [browser API](https://developer.mozilla.org/de/docs/Rich-Text_Editing_in_Mozilla) you can | ||
To add additional functions that are not supported by the native [browser API](https://developer.mozilla.org/en/docs/Rich-Text_Editing_in_Mozilla) you can | ||
write extensions that are then integrated into the toolbar. The Extension API is currently unstable and very minimal. | ||
@@ -156,3 +167,3 @@ | ||
* `getButton` is called when the editor is initialized and should return a element that is integrated into the toolbar. | ||
* `getButton` is called when the editor is initialized and should return an element that is integrated into the toolbar. | ||
Usually this will be a `<button>` element like the onces Medium Editor uses. All event handling on this button is | ||
@@ -169,3 +180,3 @@ _entirely up to you_ so you should either keep a reference or bind your eventhandlers before returning it. You can | ||
* `parent` add this property to your extension class constructor and set it to true to be able to access the Medium Editor instance through the `base` property that will be set during the initialization | ||
* `parent` add this property to your extension class constructor and set it to `true` to be able to access the Medium Editor instance through the `base` property that will be set during the initialization | ||
@@ -182,3 +193,3 @@ ### Examples | ||
this.button.className = 'medium-editor-action'; | ||
this.button.innerText = 'H'; | ||
this.button.textContent = 'H'; | ||
this.button.onclick = this.onClick.bind(this); | ||
@@ -218,3 +229,3 @@ this.classApplier = rangy.createCssClassApplier("highlight", { | ||
this.button.className = 'medium-editor-action'; | ||
this.button.innerText = 'X'; | ||
this.button.textContent = 'X'; | ||
this.button.onclick = this.onClick.bind(this); | ||
@@ -246,5 +257,5 @@ } | ||
## Image Upload | ||
## Image Upload & embeds | ||
[Pavel Linkesch](https://github.com/orthes) has developed a jQuery plugin to upload images following Medium.com functionality. Check it out at [http://orthes.github.io/medium-editor-insert-plugin/](http://orthes.github.io/medium-editor-insert-plugin/) | ||
[Pavel Linkesch](https://github.com/orthes) has developed a jQuery plugin to upload images & embed content (from Twitter, Youtube, Vimeo, etc.) following Medium.com functionality. Check it out at [http://orthes.github.io/medium-editor-insert-plugin/](http://orthes.github.io/medium-editor-insert-plugin/) | ||
@@ -298,76 +309,84 @@ ## Laravel | ||
project : medium-editor | ||
repo age : 1 year, 6 months | ||
active : 190 days | ||
commits : 638 | ||
files : 58 | ||
repo age : 1 year, 7 months | ||
active : 206 days | ||
commits : 694 | ||
files : 59 | ||
authors : | ||
451 Davi Ferreira 70.7% | ||
20 Maxime de Visscher 3.1% | ||
18 Andy Yaco-Mink 2.8% | ||
8 Jarl Gunnar T. Flaten 1.3% | ||
8 Seif 1.3% | ||
8 Derek Odegard 1.3% | ||
8 Pedro Nasser 1.3% | ||
7 OmniaGM 1.1% | ||
7 Alfonso (the fonz) de la Osa 1.1% | ||
6 Pascal 0.9% | ||
6 Dayjo 0.9% | ||
5 Raul Matei 0.8% | ||
5 Martin Thurau 0.8% | ||
4 Sebastian Zuchmanski 0.6% | ||
4 minikomi 0.6% | ||
3 ʞuıɯ-oɔɐʎ ʎpuɐ 0.5% | ||
3 Andrew Hubbs 0.5% | ||
3 Dmitri Cherniak 0.5% | ||
3 Troels Knak-Nielsen 0.5% | ||
3 arol 0.5% | ||
3 Nikita Korotaev 0.5% | ||
3 Pavel Linkesch 0.5% | ||
2 mako 0.3% | ||
2 Alexander Hofbauer 0.3% | ||
2 Son Tran-Nguyen 0.3% | ||
2 Ethan Turkeltaub 0.3% | ||
2 Jacob Magnusson 0.3% | ||
1 Richard Park 0.2% | ||
1 Robert Koritnik 0.2% | ||
1 Sarah Squire 0.2% | ||
1 Scott Carleton 0.2% | ||
1 Søren Torp Petersen 0.2% | ||
1 Tom MacWright 0.2% | ||
1 happyaccidents 0.2% | ||
1 mako yass 0.2% | ||
1 mbrookes 0.2% | ||
1 muescha 0.2% | ||
1 shaohua 0.2% | ||
1 t_kjaergaard 0.2% | ||
1 typify 0.2% | ||
1 waffleio 0.2% | ||
1 zzjin 0.2% | ||
1 Nic Malan 0.2% | ||
1 Alberto Gasparin 0.2% | ||
1 Bitdeli Chef 0.2% | ||
1 Carlos Alexandre Fuechter 0.2% | ||
1 Cenk Dölek 0.2% | ||
1 David Collien 0.2% | ||
1 David Hellsing 0.2% | ||
1 Denis Gorbachev 0.2% | ||
1 Diana Liao 0.2% | ||
1 Harshil Shah 0.2% | ||
1 IndieSquidge 0.2% | ||
1 Ionică Bizău 0.2% | ||
1 Jack Parker 0.2% | ||
1 Jeff Welch 0.2% | ||
1 Johann Troendle 0.2% | ||
1 Mark Kraemer 0.2% | ||
1 Max 0.2% | ||
1 Maxime Dantec 0.2% | ||
1 Maxime De Visscher 0.2% | ||
1 Michael Kay 0.2% | ||
1 Moore Adam 0.2% | ||
1 Adam Mulligan 0.2% | ||
1 Nick Semenkovich 0.2% | ||
1 Noah Paessel 0.2% | ||
1 Patrick Kempff 0.2% | ||
1 Peleg Rosenthal 0.2% | ||
1 Randson Oliveira 0.2% | ||
478 Davi Ferreira 68.9% | ||
20 Maxime de Visscher 2.9% | ||
18 Andy Yaco-Mink 2.6% | ||
9 Noah Chase 1.3% | ||
8 Jarl Gunnar T. Flaten 1.2% | ||
8 Seif 1.2% | ||
8 Derek Odegard 1.2% | ||
8 Pedro Nasser 1.2% | ||
7 Aidan Threadgold 1.0% | ||
7 Alfonso (the fonz) de la Osa 1.0% | ||
7 OmniaGM 1.0% | ||
6 Pascal 0.9% | ||
6 Dayjo 0.9% | ||
5 Nate Mielnik 0.7% | ||
5 Raul Matei 0.7% | ||
5 Martin Thurau 0.7% | ||
4 Sebastian Zuchmanski 0.6% | ||
4 minikomi 0.6% | ||
3 Troels Knak-Nielsen 0.4% | ||
3 Pavel Linkesch 0.4% | ||
3 Dmitri Cherniak 0.4% | ||
3 ʞuıɯ-oɔɐʎ ʎpuɐ 0.4% | ||
3 Andrew Hubbs 0.4% | ||
3 Nikita Korotaev 0.4% | ||
3 arol 0.4% | ||
2 Son Tran-Nguyen 0.3% | ||
2 Alexander Hofbauer 0.3% | ||
2 Ethan Turkeltaub 0.3% | ||
2 Jacob Magnusson 0.3% | ||
2 Jeremy 0.3% | ||
2 Joel 0.3% | ||
2 jj 0.3% | ||
2 mako 0.3% | ||
1 Max 0.1% | ||
1 Maxime De Visscher 0.1% | ||
1 Johann Troendle 0.1% | ||
1 Michael Kay 0.1% | ||
1 Moore Adam 0.1% | ||
1 Jeff Welch 0.1% | ||
1 Nic Malan 0.1% | ||
1 Nick Semenkovich 0.1% | ||
1 Jack Parker 0.1% | ||
1 Ionică Bizău 0.1% | ||
1 Noah Paessel 0.1% | ||
1 IndieSquidge 0.1% | ||
1 Harshil Shah 0.1% | ||
1 Patrick Kempff 0.1% | ||
1 Diana Liao 0.1% | ||
1 Denis Gorbachev 0.1% | ||
1 Peleg Rosenthal 0.1% | ||
1 Randson Oliveira 0.1% | ||
1 David Hellsing 0.1% | ||
1 Richard Park 0.1% | ||
1 Robert Koritnik 0.1% | ||
1 Sarah Squire 0.1% | ||
1 Scott Carleton 0.1% | ||
1 David Collien 0.1% | ||
1 Dave Jarvis 0.1% | ||
1 Adam Mulligan 0.1% | ||
1 Søren Torp Petersen 0.1% | ||
1 Tom MacWright 0.1% | ||
1 Cenk Dölek 0.1% | ||
1 Carlos Alexandre Fuechter 0.1% | ||
1 happyaccidents 0.1% | ||
1 zzjin 0.1% | ||
1 Alberto Gasparin 0.1% | ||
1 mako yass 0.1% | ||
1 mbrookes 0.1% | ||
1 Bitdeli Chef 0.1% | ||
1 muescha 0.1% | ||
1 shaohua 0.1% | ||
1 t_kjaergaard 0.1% | ||
1 typify 0.1% | ||
1 valentinnew 0.1% | ||
1 waffleio 0.1% | ||
1 Mark Kraemer 0.1% | ||
1 Maxime Dantec 0.1% | ||
``` | ||
@@ -374,0 +393,0 @@ |
@@ -74,3 +74,3 @@ /*global MediumEditor, describe, it, expect, spyOn, | ||
spyOn(MediumEditor.prototype, 'hideToolbarActions').and.callThrough(); | ||
fireEvent(editor.elements[0], 'blur', undefined, undefined, editor.elements[0], document.querySelector('#medium-editor-toolbar-form-anchor input')); | ||
fireEvent(editor.elements[0], 'blur', undefined, undefined, editor.elements[0], document.querySelector('#medium-editor-toolbar-form-anchor-' + editor.id + ' input')); | ||
jasmine.clock().tick(1); | ||
@@ -77,0 +77,0 @@ expect(editor.hideToolbarActions).not.toHaveBeenCalled(); |
@@ -26,6 +26,13 @@ function fireEvent (element, event, keyCode, ctrlKey, target, relatedTarget) { | ||
function selectElementContents(el) { | ||
function selectElementContents(el, options) { | ||
options = options || {}; | ||
var range = document.createRange(), | ||
sel = window.getSelection(); | ||
range.selectNodeContents(el); | ||
if (options.collapse) { | ||
range.collapse(options.collapse === true); | ||
} | ||
sel.removeAllRanges(); | ||
@@ -32,0 +39,0 @@ sel.addRange(range); |
@@ -83,2 +83,4 @@ /*global MediumEditor, describe, it, expect, spyOn, | ||
disableToolbar: false, | ||
disableAnchorForm: false, | ||
disablePlaceholders: false, | ||
elementsContainer: document.body, | ||
@@ -148,2 +150,17 @@ contentWindow: window, | ||
it('should not reset ID when deactivated and then re-initialized', function () { | ||
var secondEditor = document.createElement('div'), | ||
editor1 = new MediumEditor('.editor'), | ||
editor2; | ||
secondEditor.className = 'editor-two'; | ||
document.body.appendChild(secondEditor); | ||
editor2 = new MediumEditor('.editor-two'); | ||
editor1.deactivate(); | ||
editor1.init('.editor'); | ||
expect(editor1.id).not.toEqual(editor2.id); | ||
}); | ||
it('should use document.body as element container when no container element is specified', function () { | ||
@@ -150,0 +167,0 @@ spyOn(document.body, 'appendChild').and.callThrough(); |
@@ -54,3 +54,3 @@ /*global MediumEditor, describe, it, expect, spyOn, | ||
editor.elements[0].innerHTML = ''; | ||
fireEvent(editor.elements[0], 'blur'); | ||
fireEvent(document.querySelector('div'), 'click'); | ||
expect(editor.elements[0].className).toContain('medium-editor-placeholder'); | ||
@@ -80,2 +80,19 @@ }); | ||
it('should not set placeholder for empty elements when disablePlaceholders is set to true', function () { | ||
var editor = new MediumEditor('.editor', { | ||
disablePlaceholders: true | ||
}); | ||
expect(editor.elements[0].className).not.toContain('medium-editor-placeholder'); | ||
}); | ||
it('should not add a placeholder to empty elements on blur when disablePlaceholders is set to true', function () { | ||
this.el.innerHTML = 'some text'; | ||
var editor = new MediumEditor('.editor', { | ||
disablePlaceholders: true | ||
}); | ||
expect(editor.elements[0].className).not.toContain('medium-editor-placeholder'); | ||
editor.elements[0].innerHTML = ''; | ||
fireEvent(document.querySelector('div'), 'click'); | ||
expect(editor.elements[0].className).not.toContain('medium-editor-placeholder'); | ||
}); | ||
}); |
@@ -84,2 +84,15 @@ /*global MediumEditor, describe, it, expect, spyOn, | ||
}); | ||
it('should update button states when updateOnEmptySelection is true and the selection is empty', function () { | ||
spyOn(MediumEditor.prototype, 'setToolbarButtonStates').and.callThrough(); | ||
var editor = new MediumEditor('.editor', { | ||
updateOnEmptySelection: true | ||
}); | ||
selectElementContents(this.el, { collapse: 'toStart' }); | ||
editor.checkSelection(); | ||
expect(editor.setToolbarButtonStates.calls.count()).toEqual(1); | ||
}); | ||
}); | ||
@@ -86,0 +99,0 @@ }); |
/*global MediumEditor, describe, it, expect, spyOn, | ||
afterEach, beforeEach, selectElementContents, runs, | ||
waitsFor, tearDown, xit */ | ||
fireEvent, waitsFor, tearDown, xit */ | ||
@@ -33,5 +33,21 @@ describe('Toolbar TestCase', function () { | ||
var editor = new MediumEditor('.editor'); | ||
expect(editor.toolbar.className).toBe('medium-editor-toolbar'); | ||
expect(editor.toolbar.className).toMatch(/medium-editor-toolbar/); | ||
expect(document.querySelectorAll('.medium-editor-toolbar').length).toBe(1); | ||
}); | ||
it('should not create an anchor form element if disableAnchorForm is set to true', function() { | ||
expect(document.querySelectorAll('.medium-editor-toolbar-form-anchor').length).toBe(0); | ||
var editor = new MediumEditor('.editor', { | ||
disableAnchorForm: true | ||
}); | ||
expect(editor.toolbar.querySelectorAll('.medium-editor-toolbar-form-anchor').length).toBe(0); | ||
}); | ||
it('should not call MediumEditor\'s toolbarFormAnchor method if disableAnchorForm is set to true', function() { | ||
spyOn(MediumEditor.prototype, 'toolbarFormAnchor').and.callThrough(); | ||
var editor = new MediumEditor('.editor', { | ||
disableAnchorForm: true | ||
}); | ||
expect(editor.toolbarFormAnchor).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
@@ -107,2 +123,15 @@ | ||
it('should call onHideToolbar when toolbar is hidden', function () { | ||
var editor = new MediumEditor('.editor'); | ||
editor.toolbar.classList.add('medium-editor-toolbar-active'); | ||
editor.onHideToolbar = function() {}; | ||
spyOn(editor, 'onHideToolbar').and.callThrough(); | ||
fireEvent(editor.elements[0], 'focus'); | ||
fireEvent(editor.elements[0], 'blur'); | ||
expect(editor.onHideToolbar).toHaveBeenCalled(); | ||
}); | ||
// jasmine 2.0 changed async tests, runs no longer exists | ||
@@ -109,0 +138,0 @@ xit('should show the toolbar if it\'s text are selected even though one or more elements that has a data attr of disable-toolbar', function () { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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 too big to display
Sorry, the diff of this file is not supported yet
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
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
699927
59
5448
391