1&&b.composer.selection.deselect(),g(n.cells),n.end!==d&&b.fire("tableselectchange").fire("tableselectchange:composer")))},i=function(c){a.removeEventListener("mousemove",h),a.removeEventListener("mouseup",i),b.fire("tableselect").fire("tableselect:composer"),setTimeout(function(){k()},0)},j=function(c){a.ownerDocument.removeEventListener("click",j),m.getParentElement(c.target,{query:"table"},!1,a)!=n.table&&(f(),n.table=null,n.start=null,n.end=null,b.fire("tableunselect").fire("tableunselect:composer"))},k=function(){a.ownerDocument.addEventListener("click",j)},l=function(c,d){n.start=c,n.end=d,n.table=m.getParentElement(n.start,{query:"table"},!1,a),selectedCells=m.table.getCellsBetween(n.start,n.end),g(selectedCells),k(),b.fire("tableselect").fire("tableselect:composer")},m=wysihtml.dom,n={table:null,start:null,end:null,cells:null,select:l},o="wysiwyg-tmp-selected-cell";return c()};wysihtml.Editor.prototype.defaults.handleTables=!0,wysihtml.quirks.tableCellsSelection=d,wysihtml.views.Composer.prototype.observe=b}();
+//# sourceMappingURL=wysihtml.table_editing.min.map
\ No newline at end of file
diff --git a/dist/minified/wysihtml.table_editing.min.map b/dist/minified/wysihtml.table_editing.min.map
new file mode 100644
index 0000000..e450e78
--- /dev/null
+++ b/dist/minified/wysihtml.table_editing.min.map
@@ -0,0 +1 @@
+{"version":3,"file":"wysihtml.table_editing.min.js","sources":["../wysihtml.table_editing.js"],"names":["wysihtml","commands","addTableCells","exec","composer","command","value","tableSelection","start","end","tableSelect","dom","table","orderSelectionEnds","addCells","setTimeout","select","state","createTable","col","row","html","cols","rows","parseInt","tableStyle","deleteTableCells","selCell","idx","indexOf","removeCells","findCell","mergeTableCells","this","unmergeCell","mergeCellsBetween","getAttribute","queryInList","list","query","q","ret","e","len","length","querySelectorAll","i","unshift","removeElement","el","parentNode","removeChild","insertAfter","referenceNode","newNode","insertBefore","nextSibling","nextNode","node","tag","element","nodeType","tagName","toLowerCase","api","MapCell","cell","isColspan","isRowspan","firstCol","lastCol","firstRow","lastRow","isReal","spanCollection","modified","TableModifyerByCell","getParentElement","prototype","addSpannedCellToMap","map","r","c","cspan","rspan","spanCollect","rmax","cmax","rr","cc","push","setCellAsModified","s","smax","setTableMap","ridx","cells","cidx","tableRows","getTableRows","getRowCells","inlineTables","inlineCells","allCells","tableCells","lang","array","without","inlineRows","allRows","getMapIndex","r_length","c_length","r_idx","c_idx","getElementAtIndex","getMapElsTo","to_cell","els","idx_start","idx_end","temp_idx","temp_cidx","maxr","maxc","secondcell","createCells","nr","attrs","doc","ownerDocument","frag","createDocumentFragment","createElement","attr","hasOwnProperty","setAttribute","appendChild","document","createTextNode","correctColIndexForUnreals","corrIdx","getLastNewCellOnRow","rowLimit","removeEmptyTable","splitRowToCells","colspan","cType","newCells","removeAttribute","getRealRowEl","force","injectRowAt","new_cells","n_cidx","firstChild","canMerge","to","decreaseCellSpan","span","removeSurplusLines","allRowspan","childNodes","test","textContent","innerText","fillMissingCells","r_max","c_max","prevcell","parent","rectify","unmerge","thisCell","rowspan","merge","innerHTML","window","console","log","collapseCellToNextRow","cellIdx","newRowIdx","newIdx","lastCell","removeRowCell","getRowElementsByCell","modRow","getColumnElementsByCell","removeRow","oldRow","removeColCell","removeColumn","remove","what","addRow","where","newRow","addRowCell","cr","colSpanAttr","add","addColumn","addColCell","doAdd","handleCellAddWithRowspan","modCell","temp_r_cells","nrow","addRowsNr","crow","getCellsBetween","cell1","cell2","c1","findRowByCell","findColumnByCell","oldObserverFunction","views","Composer","observe","extendedObserverFunction","call","config","handleTables","initTableHandling","hideHandlers","win","removeEventListener","execCommand","bind","iframeInitiator","actions","removeListeners","sandbox","getIframe","browser","supportsCommand","addListeners","addEventListener","quirks","tableCellsSelection","editable","editor","init","handleMouseDown","event","target","handleSelectionMousedown","removeCellSelections","addClass","selectionClass","handleMouseMove","handleMouseUp","fire","selectedCells","removeClass","addSelections","oldEnd","curTable","selection","deselect","bindSideclick","sideClickHandler","selectCells","Editor","defaults"],"mappings":"AAAAA,SAASC,SAASC,eAChBC,KAAM,SAASC,EAAUC,E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EAAOR,MAAQ,KACfQ,EAAOP,IAAM,KACb0O,EAAOW,KAAK,iBAAiBA,KAAK,4BAIlCQ,EAAgB,WAClBpB,EAAShH,cAAc6G,iBAAiB,QAASwB,IAG/CC,EAAc,SAAShQ,EAAOC,GAChCO,EAAOR,MAAQA,EACfQ,EAAOP,IAAMA,EACbO,EAAOJ,MAAQD,EAAIkE,iBAAiB7D,EAAOR,OAAQ+B,MAAO,UAAU,EAAO2M,GAC3Ea,cAAgBpP,EAAIC,MAAMuM,gBAAgBnM,EAAOR,MAAOQ,EAAOP,KAC/DwP,EAAcF,eACdO,IACAnB,EAAOW,KAAK,eAAeA,KAAK,yBAG9BnP,EAAMX,SAASW,IACfK,GACEJ,MAAO,KACPJ,MAAO,KACPC,IAAK,KACLuF,MAAO,KACPhF,OAAQwP,GAEVb,EAAiB,2BAErB,OAAOP,KAITpP,UAASyQ,OAAO3L,UAAU4L,SAAS1C,cAAe,EAClDhO,SAASgP,OAAOC,oBAAsBA,EACtCjP,SAAS0N,MAAMC,SAAS7I,UAAU8I,QAAUC"}
\ No newline at end of file
diff --git a/dist/minified/wysihtml.toolbar.min.js b/dist/minified/wysihtml.toolbar.min.js
new file mode 100644
index 0000000..7732aba
--- /dev/null
+++ b/dist/minified/wysihtml.toolbar.min.js
@@ -0,0 +1,2 @@
+!function(a){var b=a.dom,c="wysihtml-command-dialog-opened",d="input, select, textarea",e="[data-wysihtml-dialog-field]",f="data-wysihtml-dialog-field";a.toolbar.Dialog=a.lang.Dispatcher.extend({constructor:function(a,b){this.link=a,this.container=b},_observe:function(){if(!this._observed){var d=this,e=function(a){var b=d._serialize();d.fire("save",b),d.hide(),a.preventDefault(),a.stopPropagation()};b.observe(d.link,"click",function(){b.hasClass(d.link,c)&&setTimeout(function(){d.hide()},0)}),b.observe(this.container,"keydown",function(b){var c=b.keyCode;c===a.ENTER_KEY&&e(b),c===a.ESCAPE_KEY&&d.cancel()}),b.delegate(this.container,"[data-wysihtml-dialog-action=save]","click",e),b.delegate(this.container,"[data-wysihtml-dialog-action=cancel]","click",function(a){d.cancel(),a.preventDefault(),a.stopPropagation()}),this._observed=!0}},_serialize:function(){for(var a={},b=this.container.querySelectorAll(e),c=b.length,d=0;c>d;d++)a[b[d].getAttribute(f)]=b[d].value;return a},_interpolate:function(a){for(var b,c,d,g=document.querySelector(":focus"),h=this.container.querySelectorAll(e),i=h.length,j=0;i>j;j++)b=h[j],b!==g&&(a&&"hidden"===b.type||(c=b.getAttribute(f),d=this.elementToChange&&"boolean"!=typeof this.elementToChange?this.elementToChange.getAttribute(c)||"":b.defaultValue,b.value=d))},update:function(a){this.elementToChange=a?a:this.elementToChange,this._interpolate()},show:function(a){var e=this.container.querySelector(d);if(this._observe(),this.update(a),b.addClass(this.link,c),this.container.style.display="",this.isOpen=!0,this.fire("show"),e&&!a)try{e.focus()}catch(f){}},_hide:function(a){this.elementToChange=null,b.removeClass(this.link,c),this.container.style.display="none",this.isOpen=!1},hide:function(){this._hide(),this.fire("hide")},cancel:function(){this._hide(),this.fire("cancel")}})}(wysihtml),function(a){var b=(a.dom,"[data-wysihtml-dialog-field]"),c="data-wysihtml-dialog-field";a.toolbar.Dialog_bgColorStyle=a.toolbar.Dialog.extend({multiselect:!0,_serialize:function(){for(var a={},d=this.container.querySelectorAll(b),e=d.length,f=0;e>f;f++)a[d[f].getAttribute(c)]=d[f].value;return a},_interpolate:function(d){for(var e,f=document.querySelector(":focus"),g=this.container.querySelectorAll(b),h=g.length,i=0,j=this.elementToChange?a.lang.object(this.elementToChange).isArray()?this.elementToChange[0]:this.elementToChange:null,k=j?j.getAttribute("style"):null,l=k?a.quirks.styleParser.parseColor(k,"background-color"):null;h>i;i++)e=g[i],e!==f&&(d&&"hidden"===e.type||"color"===e.getAttribute(c)&&(l?l[3]&&1!=l[3]?e.value="rgba("+l[0]+","+l[1]+","+l[2]+","+l[3]+");":e.value="rgb("+l[0]+","+l[1]+","+l[2]+");":e.value="rgb(0,0,0);"))}})}(wysihtml),function(a){a.toolbar.Dialog_createTable=a.toolbar.Dialog.extend({show:function(a){this.base(a)}})}(wysihtml),function(a){a.dom;a.toolbar.Dialog_fontSizeStyle=a.toolbar.Dialog.extend({multiselect:!0,_serialize:function(){return{size:this.container.querySelector('[data-wysihtml-dialog-field="size"]').value}},_interpolate:function(b){var c=document.querySelector(":focus"),d=this.container.querySelector("[data-wysihtml-dialog-field='size']"),e=this.elementToChange?a.lang.object(this.elementToChange).isArray()?this.elementToChange[0]:this.elementToChange:null,f=e?e.getAttribute("style"):null,g=f?a.quirks.styleParser.parseFontSize(f):null;d&&d!==c&&g&&!/^\s*$/.test(g)&&(d.value=g)}})}(wysihtml),function(a){var b="[data-wysihtml-dialog-field]",c="data-wysihtml-dialog-field";a.toolbar.Dialog_foreColorStyle=a.toolbar.Dialog.extend({multiselect:!0,_serialize:function(){for(var a={},d=this.container.querySelectorAll(b),e=d.length,f=0;e>f;f++)a[d[f].getAttribute(c)]=d[f].value;return a},_interpolate:function(d){for(var e,f,g=a.quirks.styleParser,h=document.querySelector(":focus"),i=this.container.querySelectorAll(b),j=i.length,k=0,l=this.elementToChange?a.lang.object(this.elementToChange).isArray()?this.elementToChange[0]:this.elementToChange:null,m=l?l.getAttribute("style"):null,n=m?g.parseColor(m,"color"):null;j>k;k++)e=i[k],e!==h&&(d&&"hidden"===e.type||"color"===e.getAttribute(c)&&(f=(e.dataset.colormode||"rgb").toLowerCase(),f="hex"===f?"hash":f,n?e.value=g.unparseColor(n,f):e.value=g.unparseColor([0,0,0],f)))}})}(wysihtml),function(a){var b=a.dom,c={position:"relative"},d={left:0,margin:0,opacity:0,overflow:"hidden",padding:0,position:"absolute",top:0,zIndex:1},e={cursor:"inherit",fontSize:"50px",height:"50px",marginTop:"-25px",outline:0,padding:0,position:"absolute",right:"-4px",top:"50%"},f={"x-webkit-speech":"",speech:""};a.toolbar.Speech=function(g,h){var i=document.createElement("input");if(!a.browser.supportsSpeechApiOn(i))return void(h.style.display="none");var j=g.editor.textarea.element.getAttribute("lang");j&&(f.lang=j);var k=document.createElement("div");a.lang.object(d).merge({width:h.offsetWidth+"px",height:h.offsetHeight+"px"}),b.insert(i).into(k),b.insert(k).into(h),b.setStyles(e).on(i),b.setAttributes(f).on(i),b.setStyles(d).on(k),b.setStyles(c).on(h);var l="onwebkitspeechchange"in i?"webkitspeechchange":"speechchange";b.observe(i,l,function(){g.execCommand("insertText",i.value),i.value=""}),b.observe(i,"click",function(a){b.hasClass(h,"wysihtml-command-disabled")&&a.preventDefault(),a.stopPropagation()})}}(wysihtml),function(a){function b(b,c){var d=b.commands.state(c.name,c.value);return!c.dialog.multiselect&&a.lang.object(d).isArray()&&(d=1===d.length?d[0]:!0),d}var c="wysihtml-command-disabled",d="wysihtml-commands-disabled",e="wysihtml-command-active",f="wysihtml-action-active",g=a.dom;a.toolbar.Toolbar=Base.extend({constructor:function(b,g,h){this.editor=b,this.container="string"==typeof g?document.getElementById(g):g,this.composer=b.composer,this._getLinks("command"),this._getLinks("action"),this._observe(),h&&this.show(),null!=b.config.classNameCommandDisabled&&(c=b.config.classNameCommandDisabled),null!=b.config.classNameCommandsDisabled&&(d=b.config.classNameCommandsDisabled),null!=b.config.classNameCommandActive&&(e=b.config.classNameCommandActive),null!=b.config.classNameActionActive&&(f=b.config.classNameActionActive);for(var i=this.container.querySelectorAll("[data-wysihtml-command=insertSpeech]"),j=i.length,k=0;j>k;k++)new a.toolbar.Speech(this,i[k])},_getLinks:function(b){for(var c,d,e,f,g,h,i=this[b+"Links"]=a.lang.array(this.container.querySelectorAll("[data-wysihtml-"+b+"]")).get(),j=i.length,k=0,l=this[b+"Mapping"]={};j>k;k++)c=i[k],e=c.getAttribute("data-wysihtml-"+b),f=c.getAttribute("data-wysihtml-"+b+"-value"),h=c.getAttribute("data-wysihtml-"+b+"-blank-value"),d=this.container.querySelector("[data-wysihtml-"+b+"-group='"+e+"']"),g=this._getDialog(c,e),l[e+":"+f]={link:c,group:d,name:e,value:f,tracksBlankValue:h,dialog:g,state:!1}},_getDialog:function(b,c){var d,e,f=this,g=this.container.querySelector("[data-wysihtml-dialog='"+c+"']");return g&&(d=a.toolbar["Dialog_"+c]?new a.toolbar["Dialog_"+c](b,g):new a.toolbar.Dialog(b,g),d.on("show",function(){e=f.composer.selection.getBookmark(),f.editor.fire("show:dialog",{command:c,dialogContainer:g,commandLink:b})}),d.on("save",function(a){e&&f.composer.selection.setBookmark(e),f._execCommand(c,a),f.editor.fire("save:dialog",{command:c,dialogContainer:g,commandLink:b}),f._hideAllDialogs(),f._preventInstantFocus(),e=void 0}),d.on("cancel",function(){e&&f.composer.selection.setBookmark(e),f.editor.fire("cancel:dialog",{command:c,dialogContainer:g,commandLink:b}),e=void 0,f._preventInstantFocus()}),d.on("hide",function(){f.editor.fire("hide:dialog",{command:c,dialogContainer:g,commandLink:b}),e=void 0})),d},execCommand:function(a,b){this.commandsDisabled||this._execCommand(a,b)},_execCommand:function(a,b){this.editor.focus(!1),this.composer.commands.exec(a,b),this._updateLinkStates()},execAction:function(a){var b=this.editor;"change_view"===a&&(b.currentView===b.textarea||"source"===b.currentView?b.fire("change_view","composer"):b.fire("change_view","textarea")),"showSource"==a&&b.fire("showSource")},_observe:function(){for(var c=this,e=this.editor,f=this.container,h=this.commandLinks.concat(this.actionLinks),i=h.length,j=0;i>j;j++)"A"===h[j].nodeName?g.setAttributes({href:"javascript:;",unselectable:"on"}).on(h[j]):g.setAttributes({unselectable:"on"}).on(h[j]);g.delegate(f,"[data-wysihtml-command], [data-wysihtml-action]","mousedown",function(a){a.preventDefault()}),g.delegate(f,"[data-wysihtml-command]","click",function(a){var d,e=this,f=e.getAttribute("data-wysihtml-command"),g=e.getAttribute("data-wysihtml-command-value"),h=c.commandMapping[f+":"+g];g||!h.dialog?c.execCommand(f,g):(d=b(c.composer,h),h.dialog.show(d)),a.preventDefault()}),g.delegate(f,"[data-wysihtml-action]","click",function(a){var b=this.getAttribute("data-wysihtml-action");c.execAction(b),a.preventDefault()}),e.on("interaction:composer",function(a){c.preventFocus||c._updateLinkStates()}),this._ownerDocumentClick=function(b){a.dom.contains(c.container,b.target)||a.dom.contains(c.composer.element,b.target)||(c._updateLinkStates(),c._preventInstantFocus())},this.container.ownerDocument.addEventListener("click",this._ownerDocumentClick,!1),this.editor.on("destroy:composer",this.destroy.bind(this)),this.editor.config.handleTables&&(e.on("tableselect:composer",function(){c.container.querySelectorAll('[data-wysihtml-hiddentools="table"]')[0].style.display=""}),e.on("tableunselect:composer",function(){c.container.querySelectorAll('[data-wysihtml-hiddentools="table"]')[0].style.display="none"})),e.on("change_view",function(a){setTimeout(function(){c.commandsDisabled="composer"!==a,c._updateLinkStates(),c.commandsDisabled?g.addClass(f,d):g.removeClass(f,d)},0)})},destroy:function(){this.container.ownerDocument.removeEventListener("click",this._ownerDocumentClick,!1)},_hideAllDialogs:function(){var a=this.commandMapping;for(var b in a)a[b].dialog&&a[b].dialog.hide()},_preventInstantFocus:function(){this.preventFocus=!0,setTimeout(function(){this.preventFocus=!1}.bind(this),0)},_updateLinkStates:function(){var a,d,h,i,j,k=this.commandMapping,l=this.composer,m=this.actionMapping;for(a in k)i=k[a],this.commandsDisabled?(d=!1,g.removeClass(i.link,e),i.group&&g.removeClass(i.group,e),i.dialog&&i.dialog.hide()):(d=this.composer.commands.state(i.name,i.value),g.removeClass(i.link,c),i.group&&g.removeClass(i.group,c)),(i.state!==d||i.tracksBlankValue)&&(i.state=d,d?i.tracksBlankValue?g.removeClass(i.link,e):(g.addClass(i.link,e),i.group&&g.addClass(i.group,e),!i.dialog||"undefined"!=typeof i.value&&null!==i.value||(d&&"object"==typeof d?(d=b(l,i),i.state=d,j=i.dialog.container.dataset?i.dialog.container.dataset.showdialogonselection:!1,l.config.showToolbarDialogsOnSelection||j?i.dialog.show(d):i.dialog.update(d)):i.dialog.hide())):i.tracksBlankValue?g.addClass(i.link,e):(g.removeClass(i.link,e),i.group&&g.removeClass(i.group,e),i.dialog&&!i.value&&i.dialog.hide()));for(a in m)h=m[a],"change_view"===h.name&&(h.state=this.editor.currentView===this.editor.textarea||"source"===this.editor.currentView,h.state?g.addClass(h.link,f):g.removeClass(h.link,f))},show:function(){this.container.style.display=""},hide:function(){this.container.style.display="none"}}),a.Editor.prototype.defaults.toolbar=void 0,a.Editor.prototype.defaults.showToolbarAfterInit=!0,a.Editor.prototype.defaults.showToolbarDialogsOnSelection=!0,a.extendEditor(function(b){b.config.toolbar&&(b.toolbar=new a.toolbar.Toolbar(b,b.config.toolbar,b.config.showToolbarAfterInit),b.on("destroy:composer",function(){b&&b.toolbar&&b.toolbar.destroy()}))})}(wysihtml);
+//# sourceMappingURL=wysihtml.toolbar.min.map
\ No newline at end of file
diff --git a/dist/minified/wysihtml.toolbar.min.map b/dist/minified/wysihtml.toolbar.min.map
new file mode 100644
index 0000000..69bccfb
--- /dev/null
+++ b/dist/minified/wysihtml.toolbar.min.map
@@ -0,0 +1 @@
+{"version":3,"file":"wysihtml.toolbar.min.js","sources":["../wysihtml.toolbar.js"],"names":["wysihtml","dom","CLASS_NAME_OPENED","SELECTOR_FORM_ELEMENTS","SELECTOR_FIELDS","ATTRIBUTE_FIELDS","toolbar","Dialog","lang","Dispatcher","extend","constructor","link","container","this","_observe","_observed","that","callbackWrapper","event","attributes","_serialize","fire","hide","preventDefault","stopPropagation","observe","hasClass","setTimeout","keyCode","ENTER_KEY","ESCAPE_KEY","cancel","delegate","data","fields","querySelectorAll","length","i","getAttribute","value","_interpolate","avoidHiddenFields","field","fieldName","newValue","focusedElement","document","querySelector","type","elementToChange","defaultValue","update","show","firstField","addClass","style","display","isOpen","focus","e","_hide","removeClass","Dialog_bgColorStyle","multiselect","firstElement","object","isArray","colorStr","color","quirks","styleParser","parseColor","Dialog_createTable","base","Dialog_fontSizeStyle","size","styleStr","parseFontSize","test","Dialog_foreColorStyle","colourMode","colourStr","colour","dataset","colormode","toLowerCase","unparseColor","linkStyles","position","wrapperStyles","left","margin","opacity","overflow","padding","top","zIndex","inputStyles","cursor","fontSize","height","marginTop","outline","right","inputAttributes","x-webkit-speech","speech","Speech","parent","input","createElement","browser","supportsSpeechApiOn","editor","textarea","element","wrapper","merge","width","offsetWidth","offsetHeight","insert","into","setStyles","on","setAttributes","eventName","execCommand","getCommandState","composer","command","state","commands","name","dialog","CLASS_NAME_COMMAND_DISABLED","CLASS_NAME_COMMANDS_DISABLED","CLASS_NAME_COMMAND_ACTIVE","CLASS_NAME_ACTION_ACTIVE","Toolbar","Base","showOnInit","getElementById","_getLinks","config","classNameCommandDisabled","classNameCommandsDisabled","classNameCommandActive","classNameActionActive","speechInputLinks","group","tracksBlankValue","links","array","get","mapping","_getDialog","caretBookmark","dialogElement","selection","getBookmark","dialogContainer","commandLink","setBookmark","_execCommand","_hideAllDialogs","_preventInstantFocus","undefined","commandValue","commandsDisabled","exec","_updateLinkStates","execAction","action","currentView","commandLinks","concat","actionLinks","nodeName","href","unselectable","commandObj","commandMapping","preventFocus","_ownerDocumentClick","contains","target","ownerDocument","addEventListener","destroy","bind","handleTables","removeEventListener","displayDialogAttributeValue","actionMapping","showdialogonselection","showToolbarDialogsOnSelection","Editor","prototype","defaults","showToolbarAfterInit","extendEditor"],"mappings":"CA8BA,SAAUA,GACR,GAAIC,GAA0BD,EAASC,IACnCC,EAA0B,iCAC1BC,EAA0B,0BAC1BC,EAA0B,+BAC1BC,EAA0B,4BAG9BL,GAASM,QAAQC,OAASP,EAASQ,KAAKC,WAAWC,QAEjDC,YAAa,SAASC,EAAMC,GAC1BC,KAAKF,KAAaA,EAClBE,KAAKD,UAAaA,GAGpBE,SAAU,WACR,IAAID,KAAKE,UAAT,CAIA,GAAIC,GAAOH,KACPI,EAAkB,SAASC,GACzB,GAAIC,GAAaH,EAAKI,YACtBJ,GAAKK,KAAK,OAAQF,GAClBH,EAAKM,OACLJ,EAAMK,iBACNL,EAAMM,kBAGZxB,GAAIyB,QAAQT,EAAKL,KAAM,QAAS,WAC1BX,EAAI0B,SAASV,EAAKL,KAAMV,IAC1B0B,WAAW,WAAaX,EAAKM,QAA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AwC,WAA5BrG,KAAKoG,OAAO6D,YAC3ED,EAAO1C,MACTnI,EAAIsD,SAASuH,EAAOlK,KAAM+H,GAE1B1I,EAAI6D,YAAYgH,EAAOlK,KAAM+H,KAMrCtF,KAAM,WACJvC,KAAKD,UAAU2C,MAAMC,QAAU,IAGjClC,KAAM,WACJT,KAAKD,UAAU2C,MAAMC,QAAU,UAqBnCzD,EAASsM,OAAOC,UAAUC,SAASlM,QAAUkK,OAI7CxK,EAASsM,OAAOC,UAAUC,SAASC,sBAAuB,EAG1DzM,EAASsM,OAAOC,UAAUC,SAASH,+BAA+B,EAGlErM,EAAS0M,aAAa,SAASxF,GACzBA,EAAO+B,OAAO3I,UAChB4G,EAAO5G,QAAU,GAAIN,GAASM,QAAQsI,QAAQ1B,EAAQA,EAAO+B,OAAO3I,QAAS4G,EAAO+B,OAAOwD,sBAC3FvF,EAAOW,GAAG,mBAAoB,WACxBX,GAAUA,EAAO5G,SACnB4G,EAAO5G,QAAQwL,gBAMtB9L"}
\ No newline at end of file
diff --git a/dist/wysihtml-toolbar.js b/dist/wysihtml-toolbar.js
deleted file mode 100644
index 26bafae..0000000
--- a/dist/wysihtml-toolbar.js
+++ /dev/null
@@ -1,19308 +0,0 @@
-/**
- * @license wysihtml v0.5.5
- * https://github.com/Voog/wysihtml
- *
- * Author: Christopher Blum (https://github.com/tiff)
- * Secondary author of extended features: Oliver Pulges (https://github.com/pulges)
- *
- * Copyright (C) 2012 XING AG
- * Licensed under the MIT license (MIT)
- *
- */
-var wysihtml5 = {
- version: "0.5.5",
-
- // namespaces
- commands: {},
- dom: {},
- quirks: {},
- toolbar: {},
- lang: {},
- selection: {},
- views: {},
-
- INVISIBLE_SPACE: "\uFEFF",
- INVISIBLE_SPACE_REG_EXP: /\uFEFF/g,
-
- VOID_ELEMENTS: "area, base, br, col, embed, hr, img, input, keygen, link, meta, param, source, track, wbr",
-
- EMPTY_FUNCTION: function() {},
-
- ELEMENT_NODE: 1,
- TEXT_NODE: 3,
-
- BACKSPACE_KEY: 8,
- ENTER_KEY: 13,
- ESCAPE_KEY: 27,
- SPACE_KEY: 32,
- TAB_KEY: 9,
- DELETE_KEY: 46
-};
-;wysihtml5.polyfills = function(win, doc) {
-
- // TODO: in future try to replace most inline compability checks with polyfills for code readability
-
- // IE8 SUPPORT BLOCK
- // You can compile without all this if IE8 is not needed
-
- // String trim for ie8
- if (!String.prototype.trim) {
- (function() {
- // Make sure we trim BOM and NBSP
- var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
- String.prototype.trim = function() {
- return this.replace(rtrim, '');
- };
- })();
- }
-
- // addEventListener, removeEventListener
- (function() {
- var s_add = 'addEventListener',
- s_rem = 'removeEventListener';
- if( doc[s_add] ) return;
- win.Element.prototype[ s_add ] = win[ s_add ] = doc[ s_add ] = function( on, fn, self ) {
- return (self = this).attachEvent( 'on' + on, function(e){
- var e = e || win.event;
- e.target = e.target || e.srcElement;
- e.preventDefault = e.preventDefault || function(){e.returnValue = false};
- e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true};
- e.which = e.button ? ( e.button === 2 ? 3 : e.button === 4 ? 2 : e.button ) : e.keyCode;
- fn.call(self, e);
- });
- };
- win.Element.prototype[ s_rem ] = win[ s_rem ] = doc[ s_rem ] = function( on, fn ) {
- return this.detachEvent( 'on' + on, fn );
- };
- })();
-
- // element.textContent polyfill.
- if (Object.defineProperty && Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(win.Element.prototype, "textContent") && !Object.getOwnPropertyDescriptor(win.Element.prototype, "textContent").get) {
- (function() {
- var innerText = Object.getOwnPropertyDescriptor(win.Element.prototype, "innerText");
- Object.defineProperty(win.Element.prototype, "textContent",
- {
- get: function() {
- return innerText.get.call(this);
- },
- set: function(s) {
- return innerText.set.call(this, s);
- }
- }
- );
- })();
- }
-
- // isArray polyfill for ie8
- if(!Array.isArray) {
- Array.isArray = function(arg) {
- return Object.prototype.toString.call(arg) === '[object Array]';
- };
- }
-
- // Array indexOf for ie8
- if (!Array.prototype.indexOf) {
- Array.prototype.indexOf = function(a,f) {
- for(var c=this.length,r=-1,d=f>>>0; ~(c-d); r=this[--c]===a?c:r);
- return r;
- };
- }
-
- // Function.prototype.bind()
- // TODO: clean the code from variable 'that' as it can be confusing
- if (!Function.prototype.bind) {
- Function.prototype.bind = function(oThis) {
- if (typeof this !== 'function') {
- // closest thing possible to the ECMAScript 5
- // internal IsCallable function
- throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
- }
-
- var aArgs = Array.prototype.slice.call(arguments, 1),
- fToBind = this,
- fNOP = function() {},
- fBound = function() {
- return fToBind.apply(this instanceof fNOP && oThis
- ? this
- : oThis,
- aArgs.concat(Array.prototype.slice.call(arguments)));
- };
-
- fNOP.prototype = this.prototype;
- fBound.prototype = new fNOP();
-
- return fBound;
- };
- }
-
- // closest and matches polyfill
- // https://github.com/jonathantneal/closest
- (function (ELEMENT) {
- ELEMENT.matches = ELEMENT.matches || ELEMENT.mozMatchesSelector || ELEMENT.msMatchesSelector || ELEMENT.oMatchesSelector || ELEMENT.webkitMatchesSelector || function matches(selector) {
- var
- element = this,
- elements = (element.document || element.ownerDocument).querySelectorAll(selector),
- index = 0;
-
- while (elements[index] && elements[index] !== element) {
- ++index;
- }
-
- return elements[index] ? true : false;
- };
-
- ELEMENT.closest = ELEMENT.closest || function closest(selector) {
- var element = this;
-
- while (element) {
- if (element.matches(selector)) {
- break;
- }
-
- element = element.parentElement;
- }
-
- return element;
- };
- }(Element.prototype));
-
- // Element.classList for ie8-9 (toggle all IE)
- // source http://purl.eligrey.com/github/classList.js/blob/master/classList.js
-
- if ("document" in win) {
- // Full polyfill for browsers with no classList support
- if (!("classList" in doc.createElement("_"))) {
- (function(view) {
- "use strict";
- if (!('Element' in view)) return;
-
- var
- classListProp = "classList",
- protoProp = "prototype",
- elemCtrProto = view.Element[protoProp],
- objCtr = Object,
- strTrim = String[protoProp].trim || function() {
- return this.replace(/^\s+|\s+$/g, "");
- },
- arrIndexOf = Array[protoProp].indexOf || function(item) {
- var
- i = 0,
- len = this.length;
- for (; i < len; i++) {
- if (i in this && this[i] === item) {
- return i;
- }
- }
- return -1;
- }, // Vendors: please allow content code to instantiate DOMExceptions
- DOMEx = function(type, message) {
- this.name = type;
- this.code = DOMException[type];
- this.message = message;
- },
- checkTokenAndGetIndex = function(classList, token) {
- if (token === "") {
- throw new DOMEx(
- "SYNTAX_ERR", "An invalid or illegal string was specified"
- );
- }
- if (/\s/.test(token)) {
- throw new DOMEx(
- "INVALID_CHARACTER_ERR", "String contains an invalid character"
- );
- }
- return arrIndexOf.call(classList, token);
- },
- ClassList = function(elem) {
- var
- trimmedClasses = strTrim.call(elem.getAttribute("class") || ""),
- classes = trimmedClasses ? trimmedClasses.split(/\s+/) : [],
- i = 0,
- len = classes.length;
- for (; i < len; i++) {
- this.push(classes[i]);
- }
- this._updateClassName = function() {
- elem.setAttribute("class", this.toString());
- };
- },
- classListProto = ClassList[protoProp] = [],
- classListGetter = function() {
- return new ClassList(this);
- };
- // Most DOMException implementations don't allow calling DOMException's toString()
- // on non-DOMExceptions. Error's toString() is sufficient here.
- DOMEx[protoProp] = Error[protoProp];
- classListProto.item = function(i) {
- return this[i] || null;
- };
- classListProto.contains = function(token) {
- token += "";
- return checkTokenAndGetIndex(this, token) !== -1;
- };
- classListProto.add = function() {
- var
- tokens = arguments,
- i = 0,
- l = tokens.length,
- token, updated = false;
- do {
- token = tokens[i] + "";
- if (checkTokenAndGetIndex(this, token) === -1) {
- this.push(token);
- updated = true;
- }
- }
- while (++i < l);
-
- if (updated) {
- this._updateClassName();
- }
- };
- classListProto.remove = function() {
- var
- tokens = arguments,
- i = 0,
- l = tokens.length,
- token, updated = false,
- index;
- do {
- token = tokens[i] + "";
- index = checkTokenAndGetIndex(this, token);
- while (index !== -1) {
- this.splice(index, 1);
- updated = true;
- index = checkTokenAndGetIndex(this, token);
- }
- }
- while (++i < l);
-
- if (updated) {
- this._updateClassName();
- }
- };
- classListProto.toggle = function(token, force) {
- token += "";
-
- var
- result = this.contains(token),
- method = result ?
- force !== true && "remove" :
- force !== false && "add";
-
- if (method) {
- this[method](token);
- }
-
- if (force === true || force === false) {
- return force;
- } else {
- return !result;
- }
- };
- classListProto.toString = function() {
- return this.join(" ");
- };
-
- if (objCtr.defineProperty) {
- var classListPropDesc = {
- get: classListGetter,
- enumerable: true,
- configurable: true
- };
- try {
- objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
- } catch (ex) { // IE 8 doesn't support enumerable:true
- if (ex.number === -0x7FF5EC54) {
- classListPropDesc.enumerable = false;
- objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
- }
- }
- } else if (objCtr[protoProp].__defineGetter__) {
- elemCtrProto.__defineGetter__(classListProp, classListGetter);
- }
-
- }(win));
-
- } else if ("DOMTokenList" in win) {
- // There is full or partial native classList support, so just check if we need
- // to normalize the add/remove and toggle APIs.
- // DOMTokenList is expected to exist (removes conflicts with multiple polyfills present on site)
-
- (function() {
- "use strict";
-
- var testElement = doc.createElement("_");
-
- testElement.classList.add("c1", "c2");
-
- // Polyfill for IE 10/11 and Firefox <26, where classList.add and
- // classList.remove exist but support only one argument at a time.
- if (!testElement.classList.contains("c2")) {
- var createMethod = function(method) {
- var original = win.DOMTokenList.prototype[method];
-
- win.DOMTokenList.prototype[method] = function(token) {
- var i, len = arguments.length;
-
- for (i = 0; i < len; i++) {
- token = arguments[i];
- original.call(this, token);
- }
- };
- };
- createMethod('add');
- createMethod('remove');
- }
-
- testElement.classList.toggle("c3", false);
-
- // Polyfill for IE 10 and Firefox <24, where classList.toggle does not
- // support the second argument.
- if (testElement.classList.contains("c3")) {
- var _toggle = win.DOMTokenList.prototype.toggle;
-
- win.DOMTokenList.prototype.toggle = function(token, force) {
- if (1 in arguments && !this.contains(token) === !force) {
- return force;
- } else {
- return _toggle.call(this, token);
- }
- };
-
- }
-
- testElement = null;
- }());
-
- }
-
- }
-
- // Safary has a bug of not restoring selection after node.normalize correctly.
- // Detects the misbegaviour and patches it
- var normalizeHasCaretError = function() {
- if ("createRange" in document && "getSelection" in window) {
- var e = document.createElement('div'),
- t1 = document.createTextNode('a'),
- t2 = document.createTextNode('a'),
- t3 = document.createTextNode('a'),
- r = document.createRange(),
- s, ret;
-
- e.setAttribute('contenteditable', 'true');
- e.appendChild(t1);
- e.appendChild(t2);
- e.appendChild(t3);
- document.body.appendChild(e);
- r.setStart(t2, 1);
- r.setEnd(t2, 1);
-
- s = window.getSelection();
- s.removeAllRanges();
- s.addRange(r);
- e.normalize();
- s = window.getSelection();
-
- ret = (e.childNodes.length !== 1 || s.anchorNode !== e.firstChild || s.anchorOffset !== 2);
- e.parentNode.removeChild(e);
- s.removeAllRanges();
- return ret;
- }
- };
-
- var getTextNodes = function(node){
- var all = [];
- for (node=node.firstChild;node;node=node.nextSibling){
- if (node.nodeType == 3) {
- all.push(node);
- } else {
- all = all.concat(getTextNodes(node));
- }
- }
- return all;
- };
-
- var isInDom = function(node) {
- var doc = node.ownerDocument,
- n = node;
-
- do {
- if (n === doc) {
- return true;
- }
- n = n.parentNode;
- } while(n);
-
- return false;
- };
-
- var normalizeFix = function() {
- var f = Node.prototype.normalize;
- var nf = function() {
- var texts = getTextNodes(this),
- s = this.ownerDocument.defaultView.getSelection(),
- anode = s.anchorNode,
- aoffset = s.anchorOffset,
- aelement = anode && anode.nodeType === 1 && anode.childNodes.length > 0 ? anode.childNodes[aoffset] : undefined,
- fnode = s.focusNode,
- foffset = s.focusOffset,
- felement = fnode && fnode.nodeType === 1 && foffset > 0 ? fnode.childNodes[foffset -1] : undefined,
- r = this.ownerDocument.createRange(),
- prevTxt = texts.shift(),
- curText = prevTxt ? texts.shift() : null;
-
- if (felement && felement.nodeType === 3) {
- fnode = felement;
- foffset = felement.nodeValue.length;
- felement = undefined;
- }
-
- if (aelement && aelement.nodeType === 3) {
- anode = aelement;
- aoffset = 0;
- aelement = undefined;
- }
-
- if ((anode === fnode && foffset < aoffset) || (anode !== fnode && (anode.compareDocumentPosition(fnode) & Node.DOCUMENT_POSITION_PRECEDING) && !(anode.compareDocumentPosition(fnode) & Node.DOCUMENT_POSITION_CONTAINS))) {
- fnode = [anode, anode = fnode][0];
- foffset = [aoffset, aoffset = foffset][0];
- }
-
- while(prevTxt && curText) {
- if (curText.previousSibling && curText.previousSibling === prevTxt) {
- if (anode === curText) {
- anode = prevTxt;
- aoffset = prevTxt.nodeValue.length + aoffset;
- }
- if (fnode === curText) {
- fnode = prevTxt;
- foffset = prevTxt.nodeValue.length + foffset;
- }
- prevTxt.nodeValue = prevTxt.nodeValue + curText.nodeValue;
- curText.parentNode.removeChild(curText);
- curText = texts.shift();
- } else {
- prevTxt = curText;
- curText = texts.shift();
- }
- }
-
- if (felement) {
- foffset = Array.prototype.indexOf.call(felement.parentNode.childNodes, felement) + 1;
- }
-
- if (aelement) {
- aoffset = Array.prototype.indexOf.call(aelement.parentNode.childNodes, aelement);
- }
-
- if (isInDom(this) && anode && anode.parentNode && fnode && fnode.parentNode) {
- r.setStart(anode, aoffset);
- r.setEnd(fnode, foffset);
- s.removeAllRanges();
- s.addRange(r);
- }
- };
- Node.prototype.normalize = nf;
- };
-
- var F = function() {
- window.removeEventListener("load", F);
- if ("Node" in window && "normalize" in Node.prototype && normalizeHasCaretError()) {
- normalizeFix();
- }
- };
-
- if (doc.readyState !== "complete") {
- window.addEventListener("load", F);
- } else {
- F();
- }
-
- // CustomEvent for ie9 and up
- function nativeCustomEventSupported() {
- try {
- var p = new CustomEvent('cat', {detail: {foo: 'bar'}});
- return 'cat' === p.type && 'bar' === p.detail.foo;
- } catch (e) {}
- return false;
- }
- var customEventSupported = nativeCustomEventSupported();
-
- // Polyfills CustomEvent object for IE9 and up
- (function() {
- if (!customEventSupported && "CustomEvent" in window) {
- function CustomEvent(event, params) {
- params = params || {bubbles: false, cancelable: false, detail: undefined};
- var evt = doc.createEvent('CustomEvent');
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
- return evt;
- }
- CustomEvent.prototype = win.Event.prototype;
- win.CustomEvent = CustomEvent;
- customEventSupported = true;
- }
- })();
-};
-
-wysihtml5.polyfills(window, document);
-;/**
- * Rangy, a cross-browser JavaScript range and selection library
- * https://github.com/timdown/rangy
- *
- * Copyright 2015, Tim Down
- * Licensed under the MIT license.
- * Version: 1.3.0
- * Build date: 10 May 2015
- */
-
-(function(factory, root) {
- if (typeof define == "function" && define.amd) {
- // AMD. Register as an anonymous module.
- define(factory);
- } else if (typeof module != "undefined" && typeof exports == "object") {
- // Node/CommonJS style
- module.exports = factory();
- } else {
- // No AMD or CommonJS support so we place Rangy in (probably) the global variable
- root.rangy = factory();
- }
-})(function() {
-
- var OBJECT = "object", FUNCTION = "function", UNDEFINED = "undefined";
-
- // Minimal set of properties required for DOM Level 2 Range compliance. Comparison constants such as START_TO_START
- // are omitted because ranges in KHTML do not have them but otherwise work perfectly well. See issue 113.
- var domRangeProperties = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed",
- "commonAncestorContainer"];
-
- // Minimal set of methods required for DOM Level 2 Range compliance
- var domRangeMethods = ["setStart", "setStartBefore", "setStartAfter", "setEnd", "setEndBefore",
- "setEndAfter", "collapse", "selectNode", "selectNodeContents", "compareBoundaryPoints", "deleteContents",
- "extractContents", "cloneContents", "insertNode", "surroundContents", "cloneRange", "toString", "detach"];
-
- var textRangeProperties = ["boundingHeight", "boundingLeft", "boundingTop", "boundingWidth", "htmlText", "text"];
-
- // Subset of TextRange's full set of methods that we're interested in
- var textRangeMethods = ["collapse", "compareEndPoints", "duplicate", "moveToElementText", "parentElement", "select",
- "setEndPoint", "getBoundingClientRect"];
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Trio of functions taken from Peter Michaux's article:
- // http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting
- function isHostMethod(o, p) {
- var t = typeof o[p];
- return t == FUNCTION || (!!(t == OBJECT && o[p])) || t == "unknown";
- }
-
- function isHostObject(o, p) {
- return !!(typeof o[p] == OBJECT && o[p]);
- }
-
- function isHostProperty(o, p) {
- return typeof o[p] != UNDEFINED;
- }
-
- // Creates a convenience function to save verbose repeated calls to tests functions
- function createMultiplePropertyTest(testFunc) {
- return function(o, props) {
- var i = props.length;
- while (i--) {
- if (!testFunc(o, props[i])) {
- return false;
- }
- }
- return true;
- };
- }
-
- // Next trio of functions are a convenience to save verbose repeated calls to previous two functions
- var areHostMethods = createMultiplePropertyTest(isHostMethod);
- var areHostObjects = createMultiplePropertyTest(isHostObject);
- var areHostProperties = createMultiplePropertyTest(isHostProperty);
-
- function isTextRange(range) {
- return range && areHostMethods(range, textRangeMethods) && areHostProperties(range, textRangeProperties);
- }
-
- function getBody(doc) {
- return isHostObject(doc, "body") ? doc.body : doc.getElementsByTagName("body")[0];
- }
-
- var forEach = [].forEach ?
- function(arr, func) {
- arr.forEach(func);
- } :
- function(arr, func) {
- for (var i = 0, len = arr.length; i < len; ++i) {
- func(arr[i], i);
- }
- };
-
- var modules = {};
-
- var isBrowser = (typeof window != UNDEFINED && typeof document != UNDEFINED);
-
- var util = {
- isHostMethod: isHostMethod,
- isHostObject: isHostObject,
- isHostProperty: isHostProperty,
- areHostMethods: areHostMethods,
- areHostObjects: areHostObjects,
- areHostProperties: areHostProperties,
- isTextRange: isTextRange,
- getBody: getBody,
- forEach: forEach
- };
-
- var api = {
- version: "1.3.0",
- initialized: false,
- isBrowser: isBrowser,
- supported: true,
- util: util,
- features: {},
- modules: modules,
- config: {
- alertOnFail: false,
- alertOnWarn: false,
- preferTextRange: false,
- autoInitialize: (typeof rangyAutoInitialize == UNDEFINED) ? true : rangyAutoInitialize
- }
- };
-
- function consoleLog(msg) {
- if (typeof console != UNDEFINED && isHostMethod(console, "log")) {
- console.log(msg);
- }
- }
-
- function alertOrLog(msg, shouldAlert) {
- if (isBrowser && shouldAlert) {
- alert(msg);
- } else {
- consoleLog(msg);
- }
- }
-
- function fail(reason) {
- api.initialized = true;
- api.supported = false;
- alertOrLog("Rangy is not supported in this environment. Reason: " + reason, api.config.alertOnFail);
- }
-
- api.fail = fail;
-
- function warn(msg) {
- alertOrLog("Rangy warning: " + msg, api.config.alertOnWarn);
- }
-
- api.warn = warn;
-
- // Add utility extend() method
- var extend;
- if ({}.hasOwnProperty) {
- util.extend = extend = function(obj, props, deep) {
- var o, p;
- for (var i in props) {
- if (props.hasOwnProperty(i)) {
- o = obj[i];
- p = props[i];
- if (deep && o !== null && typeof o == "object" && p !== null && typeof p == "object") {
- extend(o, p, true);
- }
- obj[i] = p;
- }
- }
- // Special case for toString, which does not show up in for...in loops in IE <= 8
- if (props.hasOwnProperty("toString")) {
- obj.toString = props.toString;
- }
- return obj;
- };
-
- util.createOptions = function(optionsParam, defaults) {
- var options = {};
- extend(options, defaults);
- if (optionsParam) {
- extend(options, optionsParam);
- }
- return options;
- };
- } else {
- fail("hasOwnProperty not supported");
- }
-
- // Test whether we're in a browser and bail out if not
- if (!isBrowser) {
- fail("Rangy can only run in a browser");
- }
-
- // Test whether Array.prototype.slice can be relied on for NodeLists and use an alternative toArray() if not
- (function() {
- var toArray;
-
- if (isBrowser) {
- var el = document.createElement("div");
- el.appendChild(document.createElement("span"));
- var slice = [].slice;
- try {
- if (slice.call(el.childNodes, 0)[0].nodeType == 1) {
- toArray = function(arrayLike) {
- return slice.call(arrayLike, 0);
- };
- }
- } catch (e) {}
- }
-
- if (!toArray) {
- toArray = function(arrayLike) {
- var arr = [];
- for (var i = 0, len = arrayLike.length; i < len; ++i) {
- arr[i] = arrayLike[i];
- }
- return arr;
- };
- }
-
- util.toArray = toArray;
- })();
-
- // Very simple event handler wrapper function that doesn't attempt to solve issues such as "this" handling or
- // normalization of event properties
- var addListener;
- if (isBrowser) {
- if (isHostMethod(document, "addEventListener")) {
- addListener = function(obj, eventType, listener) {
- obj.addEventListener(eventType, listener, false);
- };
- } else if (isHostMethod(document, "attachEvent")) {
- addListener = function(obj, eventType, listener) {
- obj.attachEvent("on" + eventType, listener);
- };
- } else {
- fail("Document does not have required addEventListener or attachEvent method");
- }
-
- util.addListener = addListener;
- }
-
- var initListeners = [];
-
- function getErrorDesc(ex) {
- return ex.message || ex.description || String(ex);
- }
-
- // Initialization
- function init() {
- if (!isBrowser || api.initialized) {
- return;
- }
- var testRange;
- var implementsDomRange = false, implementsTextRange = false;
-
- // First, perform basic feature tests
-
- if (isHostMethod(document, "createRange")) {
- testRange = document.createRange();
- if (areHostMethods(testRange, domRangeMethods) && areHostProperties(testRange, domRangeProperties)) {
- implementsDomRange = true;
- }
- }
-
- var body = getBody(document);
- if (!body || body.nodeName.toLowerCase() != "body") {
- fail("No body element found");
- return;
- }
-
- if (body && isHostMethod(body, "createTextRange")) {
- testRange = body.createTextRange();
- if (isTextRange(testRange)) {
- implementsTextRange = true;
- }
- }
-
- if (!implementsDomRange && !implementsTextRange) {
- fail("Neither Range nor TextRange are available");
- return;
- }
-
- api.initialized = true;
- api.features = {
- implementsDomRange: implementsDomRange,
- implementsTextRange: implementsTextRange
- };
-
- // Initialize modules
- var module, errorMessage;
- for (var moduleName in modules) {
- if ( (module = modules[moduleName]) instanceof Module ) {
- module.init(module, api);
- }
- }
-
- // Call init listeners
- for (var i = 0, len = initListeners.length; i < len; ++i) {
- try {
- initListeners[i](api);
- } catch (ex) {
- errorMessage = "Rangy init listener threw an exception. Continuing. Detail: " + getErrorDesc(ex);
- consoleLog(errorMessage);
- }
- }
- }
-
- function deprecationNotice(deprecated, replacement, module) {
- if (module) {
- deprecated += " in module " + module.name;
- }
- api.warn("DEPRECATED: " + deprecated + " is deprecated. Please use " +
- replacement + " instead.");
- }
-
- function createAliasForDeprecatedMethod(owner, deprecated, replacement, module) {
- owner[deprecated] = function() {
- deprecationNotice(deprecated, replacement, module);
- return owner[replacement].apply(owner, util.toArray(arguments));
- };
- }
-
- util.deprecationNotice = deprecationNotice;
- util.createAliasForDeprecatedMethod = createAliasForDeprecatedMethod;
-
- // Allow external scripts to initialize this library in case it's loaded after the document has loaded
- api.init = init;
-
- // Execute listener immediately if already initialized
- api.addInitListener = function(listener) {
- if (api.initialized) {
- listener(api);
- } else {
- initListeners.push(listener);
- }
- };
-
- var shimListeners = [];
-
- api.addShimListener = function(listener) {
- shimListeners.push(listener);
- };
-
- function shim(win) {
- win = win || window;
- init();
-
- // Notify listeners
- for (var i = 0, len = shimListeners.length; i < len; ++i) {
- shimListeners[i](win);
- }
- }
-
- if (isBrowser) {
- api.shim = api.createMissingNativeApi = shim;
- createAliasForDeprecatedMethod(api, "createMissingNativeApi", "shim");
- }
-
- function Module(name, dependencies, initializer) {
- this.name = name;
- this.dependencies = dependencies;
- this.initialized = false;
- this.supported = false;
- this.initializer = initializer;
- }
-
- Module.prototype = {
- init: function() {
- var requiredModuleNames = this.dependencies || [];
- for (var i = 0, len = requiredModuleNames.length, requiredModule, moduleName; i < len; ++i) {
- moduleName = requiredModuleNames[i];
-
- requiredModule = modules[moduleName];
- if (!requiredModule || !(requiredModule instanceof Module)) {
- throw new Error("required module '" + moduleName + "' not found");
- }
-
- requiredModule.init();
-
- if (!requiredModule.supported) {
- throw new Error("required module '" + moduleName + "' not supported");
- }
- }
-
- // Now run initializer
- this.initializer(this);
- },
-
- fail: function(reason) {
- this.initialized = true;
- this.supported = false;
- throw new Error(reason);
- },
-
- warn: function(msg) {
- api.warn("Module " + this.name + ": " + msg);
- },
-
- deprecationNotice: function(deprecated, replacement) {
- api.warn("DEPRECATED: " + deprecated + " in module " + this.name + " is deprecated. Please use " +
- replacement + " instead");
- },
-
- createError: function(msg) {
- return new Error("Error in Rangy " + this.name + " module: " + msg);
- }
- };
-
- function createModule(name, dependencies, initFunc) {
- var newModule = new Module(name, dependencies, function(module) {
- if (!module.initialized) {
- module.initialized = true;
- try {
- initFunc(api, module);
- module.supported = true;
- } catch (ex) {
- var errorMessage = "Module '" + name + "' failed to load: " + getErrorDesc(ex);
- consoleLog(errorMessage);
- if (ex.stack) {
- consoleLog(ex.stack);
- }
- }
- }
- });
- modules[name] = newModule;
- return newModule;
- }
-
- api.createModule = function(name) {
- // Allow 2 or 3 arguments (second argument is an optional array of dependencies)
- var initFunc, dependencies;
- if (arguments.length == 2) {
- initFunc = arguments[1];
- dependencies = [];
- } else {
- initFunc = arguments[2];
- dependencies = arguments[1];
- }
-
- var module = createModule(name, dependencies, initFunc);
-
- // Initialize the module immediately if the core is already initialized
- if (api.initialized && api.supported) {
- module.init();
- }
- };
-
- api.createCoreModule = function(name, dependencies, initFunc) {
- createModule(name, dependencies, initFunc);
- };
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Ensure rangy.rangePrototype and rangy.selectionPrototype are available immediately
-
- function RangePrototype() {}
- api.RangePrototype = RangePrototype;
- api.rangePrototype = new RangePrototype();
-
- function SelectionPrototype() {}
- api.selectionPrototype = new SelectionPrototype();
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // DOM utility methods used by Rangy
- api.createCoreModule("DomUtil", [], function(api, module) {
- var UNDEF = "undefined";
- var util = api.util;
- var getBody = util.getBody;
-
- // Perform feature tests
- if (!util.areHostMethods(document, ["createDocumentFragment", "createElement", "createTextNode"])) {
- module.fail("document missing a Node creation method");
- }
-
- if (!util.isHostMethod(document, "getElementsByTagName")) {
- module.fail("document missing getElementsByTagName method");
- }
-
- var el = document.createElement("div");
- if (!util.areHostMethods(el, ["insertBefore", "appendChild", "cloneNode"] ||
- !util.areHostObjects(el, ["previousSibling", "nextSibling", "childNodes", "parentNode"]))) {
- module.fail("Incomplete Element implementation");
- }
-
- // innerHTML is required for Range's createContextualFragment method
- if (!util.isHostProperty(el, "innerHTML")) {
- module.fail("Element is missing innerHTML property");
- }
-
- var textNode = document.createTextNode("test");
- if (!util.areHostMethods(textNode, ["splitText", "deleteData", "insertData", "appendData", "cloneNode"] ||
- !util.areHostObjects(el, ["previousSibling", "nextSibling", "childNodes", "parentNode"]) ||
- !util.areHostProperties(textNode, ["data"]))) {
- module.fail("Incomplete Text Node implementation");
- }
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Removed use of indexOf because of a bizarre bug in Opera that is thrown in one of the Acid3 tests. I haven't been
- // able to replicate it outside of the test. The bug is that indexOf returns -1 when called on an Array that
- // contains just the document as a single element and the value searched for is the document.
- var arrayContains = /*Array.prototype.indexOf ?
- function(arr, val) {
- return arr.indexOf(val) > -1;
- }:*/
-
- function(arr, val) {
- var i = arr.length;
- while (i--) {
- if (arr[i] === val) {
- return true;
- }
- }
- return false;
- };
-
- // Opera 11 puts HTML elements in the null namespace, it seems, and IE 7 has undefined namespaceURI
- function isHtmlNamespace(node) {
- var ns;
- return typeof node.namespaceURI == UNDEF || ((ns = node.namespaceURI) === null || ns == "http://www.w3.org/1999/xhtml");
- }
-
- function parentElement(node) {
- var parent = node.parentNode;
- return (parent.nodeType == 1) ? parent : null;
- }
-
- function getNodeIndex(node) {
- var i = 0;
- while( (node = node.previousSibling) ) {
- ++i;
- }
- return i;
- }
-
- function getNodeLength(node) {
- switch (node.nodeType) {
- case 7:
- case 10:
- return 0;
- case 3:
- case 8:
- return node.length;
- default:
- return node.childNodes.length;
- }
- }
-
- function getCommonAncestor(node1, node2) {
- var ancestors = [], n;
- for (n = node1; n; n = n.parentNode) {
- ancestors.push(n);
- }
-
- for (n = node2; n; n = n.parentNode) {
- if (arrayContains(ancestors, n)) {
- return n;
- }
- }
-
- return null;
- }
-
- function isAncestorOf(ancestor, descendant, selfIsAncestor) {
- var n = selfIsAncestor ? descendant : descendant.parentNode;
- while (n) {
- if (n === ancestor) {
- return true;
- } else {
- n = n.parentNode;
- }
- }
- return false;
- }
-
- function isOrIsAncestorOf(ancestor, descendant) {
- return isAncestorOf(ancestor, descendant, true);
- }
-
- function getClosestAncestorIn(node, ancestor, selfIsAncestor) {
- var p, n = selfIsAncestor ? node : node.parentNode;
- while (n) {
- p = n.parentNode;
- if (p === ancestor) {
- return n;
- }
- n = p;
- }
- return null;
- }
-
- function isCharacterDataNode(node) {
- var t = node.nodeType;
- return t == 3 || t == 4 || t == 8 ; // Text, CDataSection or Comment
- }
-
- function isTextOrCommentNode(node) {
- if (!node) {
- return false;
- }
- var t = node.nodeType;
- return t == 3 || t == 8 ; // Text or Comment
- }
-
- function insertAfter(node, precedingNode) {
- var nextNode = precedingNode.nextSibling, parent = precedingNode.parentNode;
- if (nextNode) {
- parent.insertBefore(node, nextNode);
- } else {
- parent.appendChild(node);
- }
- return node;
- }
-
- // Note that we cannot use splitText() because it is bugridden in IE 9.
- function splitDataNode(node, index, positionsToPreserve) {
- var newNode = node.cloneNode(false);
- newNode.deleteData(0, index);
- node.deleteData(index, node.length - index);
- insertAfter(newNode, node);
-
- // Preserve positions
- if (positionsToPreserve) {
- for (var i = 0, position; position = positionsToPreserve[i++]; ) {
- // Handle case where position was inside the portion of node after the split point
- if (position.node == node && position.offset > index) {
- position.node = newNode;
- position.offset -= index;
- }
- // Handle the case where the position is a node offset within node's parent
- else if (position.node == node.parentNode && position.offset > getNodeIndex(node)) {
- ++position.offset;
- }
- }
- }
- return newNode;
- }
-
- function getDocument(node) {
- if (node.nodeType == 9) {
- return node;
- } else if (typeof node.ownerDocument != UNDEF) {
- return node.ownerDocument;
- } else if (typeof node.document != UNDEF) {
- return node.document;
- } else if (node.parentNode) {
- return getDocument(node.parentNode);
- } else {
- throw module.createError("getDocument: no document found for node");
- }
- }
-
- function getWindow(node) {
- var doc = getDocument(node);
- if (typeof doc.defaultView != UNDEF) {
- return doc.defaultView;
- } else if (typeof doc.parentWindow != UNDEF) {
- return doc.parentWindow;
- } else {
- throw module.createError("Cannot get a window object for node");
- }
- }
-
- function getIframeDocument(iframeEl) {
- if (typeof iframeEl.contentDocument != UNDEF) {
- return iframeEl.contentDocument;
- } else if (typeof iframeEl.contentWindow != UNDEF) {
- return iframeEl.contentWindow.document;
- } else {
- throw module.createError("getIframeDocument: No Document object found for iframe element");
- }
- }
-
- function getIframeWindow(iframeEl) {
- if (typeof iframeEl.contentWindow != UNDEF) {
- return iframeEl.contentWindow;
- } else if (typeof iframeEl.contentDocument != UNDEF) {
- return iframeEl.contentDocument.defaultView;
- } else {
- throw module.createError("getIframeWindow: No Window object found for iframe element");
- }
- }
-
- // This looks bad. Is it worth it?
- function isWindow(obj) {
- return obj && util.isHostMethod(obj, "setTimeout") && util.isHostObject(obj, "document");
- }
-
- function getContentDocument(obj, module, methodName) {
- var doc;
-
- if (!obj) {
- doc = document;
- }
-
- // Test if a DOM node has been passed and obtain a document object for it if so
- else if (util.isHostProperty(obj, "nodeType")) {
- doc = (obj.nodeType == 1 && obj.tagName.toLowerCase() == "iframe") ?
- getIframeDocument(obj) : getDocument(obj);
- }
-
- // Test if the doc parameter appears to be a Window object
- else if (isWindow(obj)) {
- doc = obj.document;
- }
-
- if (!doc) {
- throw module.createError(methodName + "(): Parameter must be a Window object or DOM node");
- }
-
- return doc;
- }
-
- function getRootContainer(node) {
- var parent;
- while ( (parent = node.parentNode) ) {
- node = parent;
- }
- return node;
- }
-
- function comparePoints(nodeA, offsetA, nodeB, offsetB) {
- // See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-Comparing
- var nodeC, root, childA, childB, n;
- if (nodeA == nodeB) {
- // Case 1: nodes are the same
- return offsetA === offsetB ? 0 : (offsetA < offsetB) ? -1 : 1;
- } else if ( (nodeC = getClosestAncestorIn(nodeB, nodeA, true)) ) {
- // Case 2: node C (container B or an ancestor) is a child node of A
- return offsetA <= getNodeIndex(nodeC) ? -1 : 1;
- } else if ( (nodeC = getClosestAncestorIn(nodeA, nodeB, true)) ) {
- // Case 3: node C (container A or an ancestor) is a child node of B
- return getNodeIndex(nodeC) < offsetB ? -1 : 1;
- } else {
- root = getCommonAncestor(nodeA, nodeB);
- if (!root) {
- throw new Error("comparePoints error: nodes have no common ancestor");
- }
-
- // Case 4: containers are siblings or descendants of siblings
- childA = (nodeA === root) ? root : getClosestAncestorIn(nodeA, root, true);
- childB = (nodeB === root) ? root : getClosestAncestorIn(nodeB, root, true);
-
- if (childA === childB) {
- // This shouldn't be possible
- throw module.createError("comparePoints got to case 4 and childA and childB are the same!");
- } else {
- n = root.firstChild;
- while (n) {
- if (n === childA) {
- return -1;
- } else if (n === childB) {
- return 1;
- }
- n = n.nextSibling;
- }
- }
- }
- }
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Test for IE's crash (IE 6/7) or exception (IE >= 8) when a reference to garbage-collected text node is queried
- var crashyTextNodes = false;
-
- function isBrokenNode(node) {
- var n;
- try {
- n = node.parentNode;
- return false;
- } catch (e) {
- return true;
- }
- }
-
- (function() {
- var el = document.createElement("b");
- el.innerHTML = "1";
- var textNode = el.firstChild;
- el.innerHTML = " ";
- crashyTextNodes = isBrokenNode(textNode);
-
- api.features.crashyTextNodes = crashyTextNodes;
- })();
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- function inspectNode(node) {
- if (!node) {
- return "[No node]";
- }
- if (crashyTextNodes && isBrokenNode(node)) {
- return "[Broken node]";
- }
- if (isCharacterDataNode(node)) {
- return '"' + node.data + '"';
- }
- if (node.nodeType == 1) {
- var idAttr = node.id ? ' id="' + node.id + '"' : "";
- return "<" + node.nodeName + idAttr + ">[index:" + getNodeIndex(node) + ",length:" + node.childNodes.length + "][" + (node.innerHTML || "[innerHTML not supported]").slice(0, 25) + "]";
- }
- return node.nodeName;
- }
-
- function fragmentFromNodeChildren(node) {
- var fragment = getDocument(node).createDocumentFragment(), child;
- while ( (child = node.firstChild) ) {
- fragment.appendChild(child);
- }
- return fragment;
- }
-
- var getComputedStyleProperty;
- if (typeof window.getComputedStyle != UNDEF) {
- getComputedStyleProperty = function(el, propName) {
- return getWindow(el).getComputedStyle(el, null)[propName];
- };
- } else if (typeof document.documentElement.currentStyle != UNDEF) {
- getComputedStyleProperty = function(el, propName) {
- return el.currentStyle ? el.currentStyle[propName] : "";
- };
- } else {
- module.fail("No means of obtaining computed style properties found");
- }
-
- function createTestElement(doc, html, contentEditable) {
- var body = getBody(doc);
- var el = doc.createElement("div");
- el.contentEditable = "" + !!contentEditable;
- if (html) {
- el.innerHTML = html;
- }
-
- // Insert the test element at the start of the body to prevent scrolling to the bottom in iOS (issue #292)
- var bodyFirstChild = body.firstChild;
- if (bodyFirstChild) {
- body.insertBefore(el, bodyFirstChild);
- } else {
- body.appendChild(el);
- }
-
- return el;
- }
-
- function removeNode(node) {
- return node.parentNode.removeChild(node);
- }
-
- function NodeIterator(root) {
- this.root = root;
- this._next = root;
- }
-
- NodeIterator.prototype = {
- _current: null,
-
- hasNext: function() {
- return !!this._next;
- },
-
- next: function() {
- var n = this._current = this._next;
- var child, next;
- if (this._current) {
- child = n.firstChild;
- if (child) {
- this._next = child;
- } else {
- next = null;
- while ((n !== this.root) && !(next = n.nextSibling)) {
- n = n.parentNode;
- }
- this._next = next;
- }
- }
- return this._current;
- },
-
- detach: function() {
- this._current = this._next = this.root = null;
- }
- };
-
- function createIterator(root) {
- return new NodeIterator(root);
- }
-
- function DomPosition(node, offset) {
- this.node = node;
- this.offset = offset;
- }
-
- DomPosition.prototype = {
- equals: function(pos) {
- return !!pos && this.node === pos.node && this.offset == pos.offset;
- },
-
- inspect: function() {
- return "[DomPosition(" + inspectNode(this.node) + ":" + this.offset + ")]";
- },
-
- toString: function() {
- return this.inspect();
- }
- };
-
- function DOMException(codeName) {
- this.code = this[codeName];
- this.codeName = codeName;
- this.message = "DOMException: " + this.codeName;
- }
-
- DOMException.prototype = {
- INDEX_SIZE_ERR: 1,
- HIERARCHY_REQUEST_ERR: 3,
- WRONG_DOCUMENT_ERR: 4,
- NO_MODIFICATION_ALLOWED_ERR: 7,
- NOT_FOUND_ERR: 8,
- NOT_SUPPORTED_ERR: 9,
- INVALID_STATE_ERR: 11,
- INVALID_NODE_TYPE_ERR: 24
- };
-
- DOMException.prototype.toString = function() {
- return this.message;
- };
-
- api.dom = {
- arrayContains: arrayContains,
- isHtmlNamespace: isHtmlNamespace,
- parentElement: parentElement,
- getNodeIndex: getNodeIndex,
- getNodeLength: getNodeLength,
- getCommonAncestor: getCommonAncestor,
- isAncestorOf: isAncestorOf,
- isOrIsAncestorOf: isOrIsAncestorOf,
- getClosestAncestorIn: getClosestAncestorIn,
- isCharacterDataNode: isCharacterDataNode,
- isTextOrCommentNode: isTextOrCommentNode,
- insertAfter: insertAfter,
- splitDataNode: splitDataNode,
- getDocument: getDocument,
- getWindow: getWindow,
- getIframeWindow: getIframeWindow,
- getIframeDocument: getIframeDocument,
- getBody: getBody,
- isWindow: isWindow,
- getContentDocument: getContentDocument,
- getRootContainer: getRootContainer,
- comparePoints: comparePoints,
- isBrokenNode: isBrokenNode,
- inspectNode: inspectNode,
- getComputedStyleProperty: getComputedStyleProperty,
- createTestElement: createTestElement,
- removeNode: removeNode,
- fragmentFromNodeChildren: fragmentFromNodeChildren,
- createIterator: createIterator,
- DomPosition: DomPosition
- };
-
- api.DOMException = DOMException;
- });
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Pure JavaScript implementation of DOM Range
- api.createCoreModule("DomRange", ["DomUtil"], function(api, module) {
- var dom = api.dom;
- var util = api.util;
- var DomPosition = dom.DomPosition;
- var DOMException = api.DOMException;
-
- var isCharacterDataNode = dom.isCharacterDataNode;
- var getNodeIndex = dom.getNodeIndex;
- var isOrIsAncestorOf = dom.isOrIsAncestorOf;
- var getDocument = dom.getDocument;
- var comparePoints = dom.comparePoints;
- var splitDataNode = dom.splitDataNode;
- var getClosestAncestorIn = dom.getClosestAncestorIn;
- var getNodeLength = dom.getNodeLength;
- var arrayContains = dom.arrayContains;
- var getRootContainer = dom.getRootContainer;
- var crashyTextNodes = api.features.crashyTextNodes;
-
- var removeNode = dom.removeNode;
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Utility functions
-
- function isNonTextPartiallySelected(node, range) {
- return (node.nodeType != 3) &&
- (isOrIsAncestorOf(node, range.startContainer) || isOrIsAncestorOf(node, range.endContainer));
- }
-
- function getRangeDocument(range) {
- return range.document || getDocument(range.startContainer);
- }
-
- function getRangeRoot(range) {
- return getRootContainer(range.startContainer);
- }
-
- function getBoundaryBeforeNode(node) {
- return new DomPosition(node.parentNode, getNodeIndex(node));
- }
-
- function getBoundaryAfterNode(node) {
- return new DomPosition(node.parentNode, getNodeIndex(node) + 1);
- }
-
- function insertNodeAtPosition(node, n, o) {
- var firstNodeInserted = node.nodeType == 11 ? node.firstChild : node;
- if (isCharacterDataNode(n)) {
- if (o == n.length) {
- dom.insertAfter(node, n);
- } else {
- n.parentNode.insertBefore(node, o == 0 ? n : splitDataNode(n, o));
- }
- } else if (o >= n.childNodes.length) {
- n.appendChild(node);
- } else {
- n.insertBefore(node, n.childNodes[o]);
- }
- return firstNodeInserted;
- }
-
- function rangesIntersect(rangeA, rangeB, touchingIsIntersecting) {
- assertRangeValid(rangeA);
- assertRangeValid(rangeB);
-
- if (getRangeDocument(rangeB) != getRangeDocument(rangeA)) {
- throw new DOMException("WRONG_DOCUMENT_ERR");
- }
-
- var startComparison = comparePoints(rangeA.startContainer, rangeA.startOffset, rangeB.endContainer, rangeB.endOffset),
- endComparison = comparePoints(rangeA.endContainer, rangeA.endOffset, rangeB.startContainer, rangeB.startOffset);
-
- return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
- }
-
- function cloneSubtree(iterator) {
- var partiallySelected;
- for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
- partiallySelected = iterator.isPartiallySelectedSubtree();
- node = node.cloneNode(!partiallySelected);
- if (partiallySelected) {
- subIterator = iterator.getSubtreeIterator();
- node.appendChild(cloneSubtree(subIterator));
- subIterator.detach();
- }
-
- if (node.nodeType == 10) { // DocumentType
- throw new DOMException("HIERARCHY_REQUEST_ERR");
- }
- frag.appendChild(node);
- }
- return frag;
- }
-
- function iterateSubtree(rangeIterator, func, iteratorState) {
- var it, n;
- iteratorState = iteratorState || { stop: false };
- for (var node, subRangeIterator; node = rangeIterator.next(); ) {
- if (rangeIterator.isPartiallySelectedSubtree()) {
- if (func(node) === false) {
- iteratorState.stop = true;
- return;
- } else {
- // The node is partially selected by the Range, so we can use a new RangeIterator on the portion of
- // the node selected by the Range.
- subRangeIterator = rangeIterator.getSubtreeIterator();
- iterateSubtree(subRangeIterator, func, iteratorState);
- subRangeIterator.detach();
- if (iteratorState.stop) {
- return;
- }
- }
- } else {
- // The whole node is selected, so we can use efficient DOM iteration to iterate over the node and its
- // descendants
- it = dom.createIterator(node);
- while ( (n = it.next()) ) {
- if (func(n) === false) {
- iteratorState.stop = true;
- return;
- }
- }
- }
- }
- }
-
- function deleteSubtree(iterator) {
- var subIterator;
- while (iterator.next()) {
- if (iterator.isPartiallySelectedSubtree()) {
- subIterator = iterator.getSubtreeIterator();
- deleteSubtree(subIterator);
- subIterator.detach();
- } else {
- iterator.remove();
- }
- }
- }
-
- function extractSubtree(iterator) {
- for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
-
- if (iterator.isPartiallySelectedSubtree()) {
- node = node.cloneNode(false);
- subIterator = iterator.getSubtreeIterator();
- node.appendChild(extractSubtree(subIterator));
- subIterator.detach();
- } else {
- iterator.remove();
- }
- if (node.nodeType == 10) { // DocumentType
- throw new DOMException("HIERARCHY_REQUEST_ERR");
- }
- frag.appendChild(node);
- }
- return frag;
- }
-
- function getNodesInRange(range, nodeTypes, filter) {
- var filterNodeTypes = !!(nodeTypes && nodeTypes.length), regex;
- var filterExists = !!filter;
- if (filterNodeTypes) {
- regex = new RegExp("^(" + nodeTypes.join("|") + ")$");
- }
-
- var nodes = [];
- iterateSubtree(new RangeIterator(range, false), function(node) {
- if (filterNodeTypes && !regex.test(node.nodeType)) {
- return;
- }
- if (filterExists && !filter(node)) {
- return;
- }
- // Don't include a boundary container if it is a character data node and the range does not contain any
- // of its character data. See issue 190.
- var sc = range.startContainer;
- if (node == sc && isCharacterDataNode(sc) && range.startOffset == sc.length) {
- return;
- }
-
- var ec = range.endContainer;
- if (node == ec && isCharacterDataNode(ec) && range.endOffset == 0) {
- return;
- }
-
- nodes.push(node);
- });
- return nodes;
- }
-
- function inspect(range) {
- var name = (typeof range.getName == "undefined") ? "Range" : range.getName();
- return "[" + name + "(" + dom.inspectNode(range.startContainer) + ":" + range.startOffset + ", " +
- dom.inspectNode(range.endContainer) + ":" + range.endOffset + ")]";
- }
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // RangeIterator code partially borrows from IERange by Tim Ryan (http://github.com/timcameronryan/IERange)
-
- function RangeIterator(range, clonePartiallySelectedTextNodes) {
- this.range = range;
- this.clonePartiallySelectedTextNodes = clonePartiallySelectedTextNodes;
-
-
- if (!range.collapsed) {
- this.sc = range.startContainer;
- this.so = range.startOffset;
- this.ec = range.endContainer;
- this.eo = range.endOffset;
- var root = range.commonAncestorContainer;
-
- if (this.sc === this.ec && isCharacterDataNode(this.sc)) {
- this.isSingleCharacterDataNode = true;
- this._first = this._last = this._next = this.sc;
- } else {
- this._first = this._next = (this.sc === root && !isCharacterDataNode(this.sc)) ?
- this.sc.childNodes[this.so] : getClosestAncestorIn(this.sc, root, true);
- this._last = (this.ec === root && !isCharacterDataNode(this.ec)) ?
- this.ec.childNodes[this.eo - 1] : getClosestAncestorIn(this.ec, root, true);
- }
- }
- }
-
- RangeIterator.prototype = {
- _current: null,
- _next: null,
- _first: null,
- _last: null,
- isSingleCharacterDataNode: false,
-
- reset: function() {
- this._current = null;
- this._next = this._first;
- },
-
- hasNext: function() {
- return !!this._next;
- },
-
- next: function() {
- // Move to next node
- var current = this._current = this._next;
- if (current) {
- this._next = (current !== this._last) ? current.nextSibling : null;
-
- // Check for partially selected text nodes
- if (isCharacterDataNode(current) && this.clonePartiallySelectedTextNodes) {
- if (current === this.ec) {
- (current = current.cloneNode(true)).deleteData(this.eo, current.length - this.eo);
- }
- if (this._current === this.sc) {
- (current = current.cloneNode(true)).deleteData(0, this.so);
- }
- }
- }
-
- return current;
- },
-
- remove: function() {
- var current = this._current, start, end;
-
- if (isCharacterDataNode(current) && (current === this.sc || current === this.ec)) {
- start = (current === this.sc) ? this.so : 0;
- end = (current === this.ec) ? this.eo : current.length;
- if (start != end) {
- current.deleteData(start, end - start);
- }
- } else {
- if (current.parentNode) {
- removeNode(current);
- } else {
- }
- }
- },
-
- // Checks if the current node is partially selected
- isPartiallySelectedSubtree: function() {
- var current = this._current;
- return isNonTextPartiallySelected(current, this.range);
- },
-
- getSubtreeIterator: function() {
- var subRange;
- if (this.isSingleCharacterDataNode) {
- subRange = this.range.cloneRange();
- subRange.collapse(false);
- } else {
- subRange = new Range(getRangeDocument(this.range));
- var current = this._current;
- var startContainer = current, startOffset = 0, endContainer = current, endOffset = getNodeLength(current);
-
- if (isOrIsAncestorOf(current, this.sc)) {
- startContainer = this.sc;
- startOffset = this.so;
- }
- if (isOrIsAncestorOf(current, this.ec)) {
- endContainer = this.ec;
- endOffset = this.eo;
- }
-
- updateBoundaries(subRange, startContainer, startOffset, endContainer, endOffset);
- }
- return new RangeIterator(subRange, this.clonePartiallySelectedTextNodes);
- },
-
- detach: function() {
- this.range = this._current = this._next = this._first = this._last = this.sc = this.so = this.ec = this.eo = null;
- }
- };
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- var beforeAfterNodeTypes = [1, 3, 4, 5, 7, 8, 10];
- var rootContainerNodeTypes = [2, 9, 11];
- var readonlyNodeTypes = [5, 6, 10, 12];
- var insertableNodeTypes = [1, 3, 4, 5, 7, 8, 10, 11];
- var surroundNodeTypes = [1, 3, 4, 5, 7, 8];
-
- function createAncestorFinder(nodeTypes) {
- return function(node, selfIsAncestor) {
- var t, n = selfIsAncestor ? node : node.parentNode;
- while (n) {
- t = n.nodeType;
- if (arrayContains(nodeTypes, t)) {
- return n;
- }
- n = n.parentNode;
- }
- return null;
- };
- }
-
- var getDocumentOrFragmentContainer = createAncestorFinder( [9, 11] );
- var getReadonlyAncestor = createAncestorFinder(readonlyNodeTypes);
- var getDocTypeNotationEntityAncestor = createAncestorFinder( [6, 10, 12] );
-
- function assertNoDocTypeNotationEntityAncestor(node, allowSelf) {
- if (getDocTypeNotationEntityAncestor(node, allowSelf)) {
- throw new DOMException("INVALID_NODE_TYPE_ERR");
- }
- }
-
- function assertValidNodeType(node, invalidTypes) {
- if (!arrayContains(invalidTypes, node.nodeType)) {
- throw new DOMException("INVALID_NODE_TYPE_ERR");
- }
- }
-
- function assertValidOffset(node, offset) {
- if (offset < 0 || offset > (isCharacterDataNode(node) ? node.length : node.childNodes.length)) {
- throw new DOMException("INDEX_SIZE_ERR");
- }
- }
-
- function assertSameDocumentOrFragment(node1, node2) {
- if (getDocumentOrFragmentContainer(node1, true) !== getDocumentOrFragmentContainer(node2, true)) {
- throw new DOMException("WRONG_DOCUMENT_ERR");
- }
- }
-
- function assertNodeNotReadOnly(node) {
- if (getReadonlyAncestor(node, true)) {
- throw new DOMException("NO_MODIFICATION_ALLOWED_ERR");
- }
- }
-
- function assertNode(node, codeName) {
- if (!node) {
- throw new DOMException(codeName);
- }
- }
-
- function isValidOffset(node, offset) {
- return offset <= (isCharacterDataNode(node) ? node.length : node.childNodes.length);
- }
-
- function isRangeValid(range) {
- return (!!range.startContainer && !!range.endContainer &&
- !(crashyTextNodes && (dom.isBrokenNode(range.startContainer) || dom.isBrokenNode(range.endContainer))) &&
- getRootContainer(range.startContainer) == getRootContainer(range.endContainer) &&
- isValidOffset(range.startContainer, range.startOffset) &&
- isValidOffset(range.endContainer, range.endOffset));
- }
-
- function assertRangeValid(range) {
- if (!isRangeValid(range)) {
- throw new Error("Range error: Range is not valid. This usually happens after DOM mutation. Range: (" + range.inspect() + ")");
- }
- }
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Test the browser's innerHTML support to decide how to implement createContextualFragment
- var styleEl = document.createElement("style");
- var htmlParsingConforms = false;
- try {
- styleEl.innerHTML = "x ";
- htmlParsingConforms = (styleEl.firstChild.nodeType == 3); // Opera incorrectly creates an element node
- } catch (e) {
- // IE 6 and 7 throw
- }
-
- api.features.htmlParsingConforms = htmlParsingConforms;
-
- var createContextualFragment = htmlParsingConforms ?
-
- // Implementation as per HTML parsing spec, trusting in the browser's implementation of innerHTML. See
- // discussion and base code for this implementation at issue 67.
- // Spec: http://html5.org/specs/dom-parsing.html#extensions-to-the-range-interface
- // Thanks to Aleks Williams.
- function(fragmentStr) {
- // "Let node the context object's start's node."
- var node = this.startContainer;
- var doc = getDocument(node);
-
- // "If the context object's start's node is null, raise an INVALID_STATE_ERR
- // exception and abort these steps."
- if (!node) {
- throw new DOMException("INVALID_STATE_ERR");
- }
-
- // "Let element be as follows, depending on node's interface:"
- // Document, Document Fragment: null
- var el = null;
-
- // "Element: node"
- if (node.nodeType == 1) {
- el = node;
-
- // "Text, Comment: node's parentElement"
- } else if (isCharacterDataNode(node)) {
- el = dom.parentElement(node);
- }
-
- // "If either element is null or element's ownerDocument is an HTML document
- // and element's local name is "html" and element's namespace is the HTML
- // namespace"
- if (el === null || (
- el.nodeName == "HTML" &&
- dom.isHtmlNamespace(getDocument(el).documentElement) &&
- dom.isHtmlNamespace(el)
- )) {
-
- // "let element be a new Element with "body" as its local name and the HTML
- // namespace as its namespace.""
- el = doc.createElement("body");
- } else {
- el = el.cloneNode(false);
- }
-
- // "If the node's document is an HTML document: Invoke the HTML fragment parsing algorithm."
- // "If the node's document is an XML document: Invoke the XML fragment parsing algorithm."
- // "In either case, the algorithm must be invoked with fragment as the input
- // and element as the context element."
- el.innerHTML = fragmentStr;
-
- // "If this raises an exception, then abort these steps. Otherwise, let new
- // children be the nodes returned."
-
- // "Let fragment be a new DocumentFragment."
- // "Append all new children to fragment."
- // "Return fragment."
- return dom.fragmentFromNodeChildren(el);
- } :
-
- // In this case, innerHTML cannot be trusted, so fall back to a simpler, non-conformant implementation that
- // previous versions of Rangy used (with the exception of using a body element rather than a div)
- function(fragmentStr) {
- var doc = getRangeDocument(this);
- var el = doc.createElement("body");
- el.innerHTML = fragmentStr;
-
- return dom.fragmentFromNodeChildren(el);
- };
-
- function splitRangeBoundaries(range, positionsToPreserve) {
- assertRangeValid(range);
-
- var sc = range.startContainer, so = range.startOffset, ec = range.endContainer, eo = range.endOffset;
- var startEndSame = (sc === ec);
-
- if (isCharacterDataNode(ec) && eo > 0 && eo < ec.length) {
- splitDataNode(ec, eo, positionsToPreserve);
- }
-
- if (isCharacterDataNode(sc) && so > 0 && so < sc.length) {
- sc = splitDataNode(sc, so, positionsToPreserve);
- if (startEndSame) {
- eo -= so;
- ec = sc;
- } else if (ec == sc.parentNode && eo >= getNodeIndex(sc)) {
- eo++;
- }
- so = 0;
- }
- range.setStartAndEnd(sc, so, ec, eo);
- }
-
- function rangeToHtml(range) {
- assertRangeValid(range);
- var container = range.commonAncestorContainer.parentNode.cloneNode(false);
- container.appendChild( range.cloneContents() );
- return container.innerHTML;
- }
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- var rangeProperties = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed",
- "commonAncestorContainer"];
-
- var s2s = 0, s2e = 1, e2e = 2, e2s = 3;
- var n_b = 0, n_a = 1, n_b_a = 2, n_i = 3;
-
- util.extend(api.rangePrototype, {
- compareBoundaryPoints: function(how, range) {
- assertRangeValid(this);
- assertSameDocumentOrFragment(this.startContainer, range.startContainer);
-
- var nodeA, offsetA, nodeB, offsetB;
- var prefixA = (how == e2s || how == s2s) ? "start" : "end";
- var prefixB = (how == s2e || how == s2s) ? "start" : "end";
- nodeA = this[prefixA + "Container"];
- offsetA = this[prefixA + "Offset"];
- nodeB = range[prefixB + "Container"];
- offsetB = range[prefixB + "Offset"];
- return comparePoints(nodeA, offsetA, nodeB, offsetB);
- },
-
- insertNode: function(node) {
- assertRangeValid(this);
- assertValidNodeType(node, insertableNodeTypes);
- assertNodeNotReadOnly(this.startContainer);
-
- if (isOrIsAncestorOf(node, this.startContainer)) {
- throw new DOMException("HIERARCHY_REQUEST_ERR");
- }
-
- // No check for whether the container of the start of the Range is of a type that does not allow
- // children of the type of node: the browser's DOM implementation should do this for us when we attempt
- // to add the node
-
- var firstNodeInserted = insertNodeAtPosition(node, this.startContainer, this.startOffset);
- this.setStartBefore(firstNodeInserted);
- },
-
- cloneContents: function() {
- assertRangeValid(this);
-
- var clone, frag;
- if (this.collapsed) {
- return getRangeDocument(this).createDocumentFragment();
- } else {
- if (this.startContainer === this.endContainer && isCharacterDataNode(this.startContainer)) {
- clone = this.startContainer.cloneNode(true);
- clone.data = clone.data.slice(this.startOffset, this.endOffset);
- frag = getRangeDocument(this).createDocumentFragment();
- frag.appendChild(clone);
- return frag;
- } else {
- var iterator = new RangeIterator(this, true);
- clone = cloneSubtree(iterator);
- iterator.detach();
- }
- return clone;
- }
- },
-
- canSurroundContents: function() {
- assertRangeValid(this);
- assertNodeNotReadOnly(this.startContainer);
- assertNodeNotReadOnly(this.endContainer);
-
- // Check if the contents can be surrounded. Specifically, this means whether the range partially selects
- // no non-text nodes.
- var iterator = new RangeIterator(this, true);
- var boundariesInvalid = (iterator._first && (isNonTextPartiallySelected(iterator._first, this)) ||
- (iterator._last && isNonTextPartiallySelected(iterator._last, this)));
- iterator.detach();
- return !boundariesInvalid;
- },
-
- surroundContents: function(node) {
- assertValidNodeType(node, surroundNodeTypes);
-
- if (!this.canSurroundContents()) {
- throw new DOMException("INVALID_STATE_ERR");
- }
-
- // Extract the contents
- var content = this.extractContents();
-
- // Clear the children of the node
- if (node.hasChildNodes()) {
- while (node.lastChild) {
- node.removeChild(node.lastChild);
- }
- }
-
- // Insert the new node and add the extracted contents
- insertNodeAtPosition(node, this.startContainer, this.startOffset);
- node.appendChild(content);
-
- this.selectNode(node);
- },
-
- cloneRange: function() {
- assertRangeValid(this);
- var range = new Range(getRangeDocument(this));
- var i = rangeProperties.length, prop;
- while (i--) {
- prop = rangeProperties[i];
- range[prop] = this[prop];
- }
- return range;
- },
-
- toString: function() {
- assertRangeValid(this);
- var sc = this.startContainer;
- if (sc === this.endContainer && isCharacterDataNode(sc)) {
- return (sc.nodeType == 3 || sc.nodeType == 4) ? sc.data.slice(this.startOffset, this.endOffset) : "";
- } else {
- var textParts = [], iterator = new RangeIterator(this, true);
- iterateSubtree(iterator, function(node) {
- // Accept only text or CDATA nodes, not comments
- if (node.nodeType == 3 || node.nodeType == 4) {
- textParts.push(node.data);
- }
- });
- iterator.detach();
- return textParts.join("");
- }
- },
-
- // The methods below are all non-standard. The following batch were introduced by Mozilla but have since
- // been removed from Mozilla.
-
- compareNode: function(node) {
- assertRangeValid(this);
-
- var parent = node.parentNode;
- var nodeIndex = getNodeIndex(node);
-
- if (!parent) {
- throw new DOMException("NOT_FOUND_ERR");
- }
-
- var startComparison = this.comparePoint(parent, nodeIndex),
- endComparison = this.comparePoint(parent, nodeIndex + 1);
-
- if (startComparison < 0) { // Node starts before
- return (endComparison > 0) ? n_b_a : n_b;
- } else {
- return (endComparison > 0) ? n_a : n_i;
- }
- },
-
- comparePoint: function(node, offset) {
- assertRangeValid(this);
- assertNode(node, "HIERARCHY_REQUEST_ERR");
- assertSameDocumentOrFragment(node, this.startContainer);
-
- if (comparePoints(node, offset, this.startContainer, this.startOffset) < 0) {
- return -1;
- } else if (comparePoints(node, offset, this.endContainer, this.endOffset) > 0) {
- return 1;
- }
- return 0;
- },
-
- createContextualFragment: createContextualFragment,
-
- toHtml: function() {
- return rangeToHtml(this);
- },
-
- // touchingIsIntersecting determines whether this method considers a node that borders a range intersects
- // with it (as in WebKit) or not (as in Gecko pre-1.9, and the default)
- intersectsNode: function(node, touchingIsIntersecting) {
- assertRangeValid(this);
- if (getRootContainer(node) != getRangeRoot(this)) {
- return false;
- }
-
- var parent = node.parentNode, offset = getNodeIndex(node);
- if (!parent) {
- return true;
- }
-
- var startComparison = comparePoints(parent, offset, this.endContainer, this.endOffset),
- endComparison = comparePoints(parent, offset + 1, this.startContainer, this.startOffset);
-
- return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
- },
-
- isPointInRange: function(node, offset) {
- assertRangeValid(this);
- assertNode(node, "HIERARCHY_REQUEST_ERR");
- assertSameDocumentOrFragment(node, this.startContainer);
-
- return (comparePoints(node, offset, this.startContainer, this.startOffset) >= 0) &&
- (comparePoints(node, offset, this.endContainer, this.endOffset) <= 0);
- },
-
- // The methods below are non-standard and invented by me.
-
- // Sharing a boundary start-to-end or end-to-start does not count as intersection.
- intersectsRange: function(range) {
- return rangesIntersect(this, range, false);
- },
-
- // Sharing a boundary start-to-end or end-to-start does count as intersection.
- intersectsOrTouchesRange: function(range) {
- return rangesIntersect(this, range, true);
- },
-
- intersection: function(range) {
- if (this.intersectsRange(range)) {
- var startComparison = comparePoints(this.startContainer, this.startOffset, range.startContainer, range.startOffset),
- endComparison = comparePoints(this.endContainer, this.endOffset, range.endContainer, range.endOffset);
-
- var intersectionRange = this.cloneRange();
- if (startComparison == -1) {
- intersectionRange.setStart(range.startContainer, range.startOffset);
- }
- if (endComparison == 1) {
- intersectionRange.setEnd(range.endContainer, range.endOffset);
- }
- return intersectionRange;
- }
- return null;
- },
-
- union: function(range) {
- if (this.intersectsOrTouchesRange(range)) {
- var unionRange = this.cloneRange();
- if (comparePoints(range.startContainer, range.startOffset, this.startContainer, this.startOffset) == -1) {
- unionRange.setStart(range.startContainer, range.startOffset);
- }
- if (comparePoints(range.endContainer, range.endOffset, this.endContainer, this.endOffset) == 1) {
- unionRange.setEnd(range.endContainer, range.endOffset);
- }
- return unionRange;
- } else {
- throw new DOMException("Ranges do not intersect");
- }
- },
-
- containsNode: function(node, allowPartial) {
- if (allowPartial) {
- return this.intersectsNode(node, false);
- } else {
- return this.compareNode(node) == n_i;
- }
- },
-
- containsNodeContents: function(node) {
- return this.comparePoint(node, 0) >= 0 && this.comparePoint(node, getNodeLength(node)) <= 0;
- },
-
- containsRange: function(range) {
- var intersection = this.intersection(range);
- return intersection !== null && range.equals(intersection);
- },
-
- containsNodeText: function(node) {
- var nodeRange = this.cloneRange();
- nodeRange.selectNode(node);
- var textNodes = nodeRange.getNodes([3]);
- if (textNodes.length > 0) {
- nodeRange.setStart(textNodes[0], 0);
- var lastTextNode = textNodes.pop();
- nodeRange.setEnd(lastTextNode, lastTextNode.length);
- return this.containsRange(nodeRange);
- } else {
- return this.containsNodeContents(node);
- }
- },
-
- getNodes: function(nodeTypes, filter) {
- assertRangeValid(this);
- return getNodesInRange(this, nodeTypes, filter);
- },
-
- getDocument: function() {
- return getRangeDocument(this);
- },
-
- collapseBefore: function(node) {
- this.setEndBefore(node);
- this.collapse(false);
- },
-
- collapseAfter: function(node) {
- this.setStartAfter(node);
- this.collapse(true);
- },
-
- getBookmark: function(containerNode) {
- var doc = getRangeDocument(this);
- var preSelectionRange = api.createRange(doc);
- containerNode = containerNode || dom.getBody(doc);
- preSelectionRange.selectNodeContents(containerNode);
- var range = this.intersection(preSelectionRange);
- var start = 0, end = 0;
- if (range) {
- preSelectionRange.setEnd(range.startContainer, range.startOffset);
- start = preSelectionRange.toString().length;
- end = start + range.toString().length;
- }
-
- return {
- start: start,
- end: end,
- containerNode: containerNode
- };
- },
-
- moveToBookmark: function(bookmark) {
- var containerNode = bookmark.containerNode;
- var charIndex = 0;
- this.setStart(containerNode, 0);
- this.collapse(true);
- var nodeStack = [containerNode], node, foundStart = false, stop = false;
- var nextCharIndex, i, childNodes;
-
- while (!stop && (node = nodeStack.pop())) {
- if (node.nodeType == 3) {
- nextCharIndex = charIndex + node.length;
- if (!foundStart && bookmark.start >= charIndex && bookmark.start <= nextCharIndex) {
- this.setStart(node, bookmark.start - charIndex);
- foundStart = true;
- }
- if (foundStart && bookmark.end >= charIndex && bookmark.end <= nextCharIndex) {
- this.setEnd(node, bookmark.end - charIndex);
- stop = true;
- }
- charIndex = nextCharIndex;
- } else {
- childNodes = node.childNodes;
- i = childNodes.length;
- while (i--) {
- nodeStack.push(childNodes[i]);
- }
- }
- }
- },
-
- getName: function() {
- return "DomRange";
- },
-
- equals: function(range) {
- return Range.rangesEqual(this, range);
- },
-
- isValid: function() {
- return isRangeValid(this);
- },
-
- inspect: function() {
- return inspect(this);
- },
-
- detach: function() {
- // In DOM4, detach() is now a no-op.
- }
- });
-
- function copyComparisonConstantsToObject(obj) {
- obj.START_TO_START = s2s;
- obj.START_TO_END = s2e;
- obj.END_TO_END = e2e;
- obj.END_TO_START = e2s;
-
- obj.NODE_BEFORE = n_b;
- obj.NODE_AFTER = n_a;
- obj.NODE_BEFORE_AND_AFTER = n_b_a;
- obj.NODE_INSIDE = n_i;
- }
-
- function copyComparisonConstants(constructor) {
- copyComparisonConstantsToObject(constructor);
- copyComparisonConstantsToObject(constructor.prototype);
- }
-
- function createRangeContentRemover(remover, boundaryUpdater) {
- return function() {
- assertRangeValid(this);
-
- var sc = this.startContainer, so = this.startOffset, root = this.commonAncestorContainer;
-
- var iterator = new RangeIterator(this, true);
-
- // Work out where to position the range after content removal
- var node, boundary;
- if (sc !== root) {
- node = getClosestAncestorIn(sc, root, true);
- boundary = getBoundaryAfterNode(node);
- sc = boundary.node;
- so = boundary.offset;
- }
-
- // Check none of the range is read-only
- iterateSubtree(iterator, assertNodeNotReadOnly);
-
- iterator.reset();
-
- // Remove the content
- var returnValue = remover(iterator);
- iterator.detach();
-
- // Move to the new position
- boundaryUpdater(this, sc, so, sc, so);
-
- return returnValue;
- };
- }
-
- function createPrototypeRange(constructor, boundaryUpdater) {
- function createBeforeAfterNodeSetter(isBefore, isStart) {
- return function(node) {
- assertValidNodeType(node, beforeAfterNodeTypes);
- assertValidNodeType(getRootContainer(node), rootContainerNodeTypes);
-
- var boundary = (isBefore ? getBoundaryBeforeNode : getBoundaryAfterNode)(node);
- (isStart ? setRangeStart : setRangeEnd)(this, boundary.node, boundary.offset);
- };
- }
-
- function setRangeStart(range, node, offset) {
- var ec = range.endContainer, eo = range.endOffset;
- if (node !== range.startContainer || offset !== range.startOffset) {
- // Check the root containers of the range and the new boundary, and also check whether the new boundary
- // is after the current end. In either case, collapse the range to the new position
- if (getRootContainer(node) != getRootContainer(ec) || comparePoints(node, offset, ec, eo) == 1) {
- ec = node;
- eo = offset;
- }
- boundaryUpdater(range, node, offset, ec, eo);
- }
- }
-
- function setRangeEnd(range, node, offset) {
- var sc = range.startContainer, so = range.startOffset;
- if (node !== range.endContainer || offset !== range.endOffset) {
- // Check the root containers of the range and the new boundary, and also check whether the new boundary
- // is after the current end. In either case, collapse the range to the new position
- if (getRootContainer(node) != getRootContainer(sc) || comparePoints(node, offset, sc, so) == -1) {
- sc = node;
- so = offset;
- }
- boundaryUpdater(range, sc, so, node, offset);
- }
- }
-
- // Set up inheritance
- var F = function() {};
- F.prototype = api.rangePrototype;
- constructor.prototype = new F();
-
- util.extend(constructor.prototype, {
- setStart: function(node, offset) {
- assertNoDocTypeNotationEntityAncestor(node, true);
- assertValidOffset(node, offset);
-
- setRangeStart(this, node, offset);
- },
-
- setEnd: function(node, offset) {
- assertNoDocTypeNotationEntityAncestor(node, true);
- assertValidOffset(node, offset);
-
- setRangeEnd(this, node, offset);
- },
-
- /**
- * Convenience method to set a range's start and end boundaries. Overloaded as follows:
- * - Two parameters (node, offset) creates a collapsed range at that position
- * - Three parameters (node, startOffset, endOffset) creates a range contained with node starting at
- * startOffset and ending at endOffset
- * - Four parameters (startNode, startOffset, endNode, endOffset) creates a range starting at startOffset in
- * startNode and ending at endOffset in endNode
- */
- setStartAndEnd: function() {
- var args = arguments;
- var sc = args[0], so = args[1], ec = sc, eo = so;
-
- switch (args.length) {
- case 3:
- eo = args[2];
- break;
- case 4:
- ec = args[2];
- eo = args[3];
- break;
- }
-
- boundaryUpdater(this, sc, so, ec, eo);
- },
-
- setBoundary: function(node, offset, isStart) {
- this["set" + (isStart ? "Start" : "End")](node, offset);
- },
-
- setStartBefore: createBeforeAfterNodeSetter(true, true),
- setStartAfter: createBeforeAfterNodeSetter(false, true),
- setEndBefore: createBeforeAfterNodeSetter(true, false),
- setEndAfter: createBeforeAfterNodeSetter(false, false),
-
- collapse: function(isStart) {
- assertRangeValid(this);
- if (isStart) {
- boundaryUpdater(this, this.startContainer, this.startOffset, this.startContainer, this.startOffset);
- } else {
- boundaryUpdater(this, this.endContainer, this.endOffset, this.endContainer, this.endOffset);
- }
- },
-
- selectNodeContents: function(node) {
- assertNoDocTypeNotationEntityAncestor(node, true);
-
- boundaryUpdater(this, node, 0, node, getNodeLength(node));
- },
-
- selectNode: function(node) {
- assertNoDocTypeNotationEntityAncestor(node, false);
- assertValidNodeType(node, beforeAfterNodeTypes);
-
- var start = getBoundaryBeforeNode(node), end = getBoundaryAfterNode(node);
- boundaryUpdater(this, start.node, start.offset, end.node, end.offset);
- },
-
- extractContents: createRangeContentRemover(extractSubtree, boundaryUpdater),
-
- deleteContents: createRangeContentRemover(deleteSubtree, boundaryUpdater),
-
- canSurroundContents: function() {
- assertRangeValid(this);
- assertNodeNotReadOnly(this.startContainer);
- assertNodeNotReadOnly(this.endContainer);
-
- // Check if the contents can be surrounded. Specifically, this means whether the range partially selects
- // no non-text nodes.
- var iterator = new RangeIterator(this, true);
- var boundariesInvalid = (iterator._first && isNonTextPartiallySelected(iterator._first, this) ||
- (iterator._last && isNonTextPartiallySelected(iterator._last, this)));
- iterator.detach();
- return !boundariesInvalid;
- },
-
- splitBoundaries: function() {
- splitRangeBoundaries(this);
- },
-
- splitBoundariesPreservingPositions: function(positionsToPreserve) {
- splitRangeBoundaries(this, positionsToPreserve);
- },
-
- normalizeBoundaries: function() {
- assertRangeValid(this);
-
- var sc = this.startContainer, so = this.startOffset, ec = this.endContainer, eo = this.endOffset;
-
- var mergeForward = function(node) {
- var sibling = node.nextSibling;
- if (sibling && sibling.nodeType == node.nodeType) {
- ec = node;
- eo = node.length;
- node.appendData(sibling.data);
- removeNode(sibling);
- }
- };
-
- var mergeBackward = function(node) {
- var sibling = node.previousSibling;
- if (sibling && sibling.nodeType == node.nodeType) {
- sc = node;
- var nodeLength = node.length;
- so = sibling.length;
- node.insertData(0, sibling.data);
- removeNode(sibling);
- if (sc == ec) {
- eo += so;
- ec = sc;
- } else if (ec == node.parentNode) {
- var nodeIndex = getNodeIndex(node);
- if (eo == nodeIndex) {
- ec = node;
- eo = nodeLength;
- } else if (eo > nodeIndex) {
- eo--;
- }
- }
- }
- };
-
- var normalizeStart = true;
- var sibling;
-
- if (isCharacterDataNode(ec)) {
- if (eo == ec.length) {
- mergeForward(ec);
- } else if (eo == 0) {
- sibling = ec.previousSibling;
- if (sibling && sibling.nodeType == ec.nodeType) {
- eo = sibling.length;
- if (sc == ec) {
- normalizeStart = false;
- }
- sibling.appendData(ec.data);
- removeNode(ec);
- ec = sibling;
- }
- }
- } else {
- if (eo > 0) {
- var endNode = ec.childNodes[eo - 1];
- if (endNode && isCharacterDataNode(endNode)) {
- mergeForward(endNode);
- }
- }
- normalizeStart = !this.collapsed;
- }
-
- if (normalizeStart) {
- if (isCharacterDataNode(sc)) {
- if (so == 0) {
- mergeBackward(sc);
- } else if (so == sc.length) {
- sibling = sc.nextSibling;
- if (sibling && sibling.nodeType == sc.nodeType) {
- if (ec == sibling) {
- ec = sc;
- eo += sc.length;
- }
- sc.appendData(sibling.data);
- removeNode(sibling);
- }
- }
- } else {
- if (so < sc.childNodes.length) {
- var startNode = sc.childNodes[so];
- if (startNode && isCharacterDataNode(startNode)) {
- mergeBackward(startNode);
- }
- }
- }
- } else {
- sc = ec;
- so = eo;
- }
-
- boundaryUpdater(this, sc, so, ec, eo);
- },
-
- collapseToPoint: function(node, offset) {
- assertNoDocTypeNotationEntityAncestor(node, true);
- assertValidOffset(node, offset);
- this.setStartAndEnd(node, offset);
- }
- });
-
- copyComparisonConstants(constructor);
- }
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Updates commonAncestorContainer and collapsed after boundary change
- function updateCollapsedAndCommonAncestor(range) {
- range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
- range.commonAncestorContainer = range.collapsed ?
- range.startContainer : dom.getCommonAncestor(range.startContainer, range.endContainer);
- }
-
- function updateBoundaries(range, startContainer, startOffset, endContainer, endOffset) {
- range.startContainer = startContainer;
- range.startOffset = startOffset;
- range.endContainer = endContainer;
- range.endOffset = endOffset;
- range.document = dom.getDocument(startContainer);
-
- updateCollapsedAndCommonAncestor(range);
- }
-
- function Range(doc) {
- this.startContainer = doc;
- this.startOffset = 0;
- this.endContainer = doc;
- this.endOffset = 0;
- this.document = doc;
- updateCollapsedAndCommonAncestor(this);
- }
-
- createPrototypeRange(Range, updateBoundaries);
-
- util.extend(Range, {
- rangeProperties: rangeProperties,
- RangeIterator: RangeIterator,
- copyComparisonConstants: copyComparisonConstants,
- createPrototypeRange: createPrototypeRange,
- inspect: inspect,
- toHtml: rangeToHtml,
- getRangeDocument: getRangeDocument,
- rangesEqual: function(r1, r2) {
- return r1.startContainer === r2.startContainer &&
- r1.startOffset === r2.startOffset &&
- r1.endContainer === r2.endContainer &&
- r1.endOffset === r2.endOffset;
- }
- });
-
- api.DomRange = Range;
- });
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Wrappers for the browser's native DOM Range and/or TextRange implementation
- api.createCoreModule("WrappedRange", ["DomRange"], function(api, module) {
- var WrappedRange, WrappedTextRange;
- var dom = api.dom;
- var util = api.util;
- var DomPosition = dom.DomPosition;
- var DomRange = api.DomRange;
- var getBody = dom.getBody;
- var getContentDocument = dom.getContentDocument;
- var isCharacterDataNode = dom.isCharacterDataNode;
-
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- if (api.features.implementsDomRange) {
- // This is a wrapper around the browser's native DOM Range. It has two aims:
- // - Provide workarounds for specific browser bugs
- // - provide convenient extensions, which are inherited from Rangy's DomRange
-
- (function() {
- var rangeProto;
- var rangeProperties = DomRange.rangeProperties;
-
- function updateRangeProperties(range) {
- var i = rangeProperties.length, prop;
- while (i--) {
- prop = rangeProperties[i];
- range[prop] = range.nativeRange[prop];
- }
- // Fix for broken collapsed property in IE 9.
- range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
- }
-
- function updateNativeRange(range, startContainer, startOffset, endContainer, endOffset) {
- var startMoved = (range.startContainer !== startContainer || range.startOffset != startOffset);
- var endMoved = (range.endContainer !== endContainer || range.endOffset != endOffset);
- var nativeRangeDifferent = !range.equals(range.nativeRange);
-
- // Always set both boundaries for the benefit of IE9 (see issue 35)
- if (startMoved || endMoved || nativeRangeDifferent) {
- range.setEnd(endContainer, endOffset);
- range.setStart(startContainer, startOffset);
- }
- }
-
- var createBeforeAfterNodeSetter;
-
- WrappedRange = function(range) {
- if (!range) {
- throw module.createError("WrappedRange: Range must be specified");
- }
- this.nativeRange = range;
- updateRangeProperties(this);
- };
-
- DomRange.createPrototypeRange(WrappedRange, updateNativeRange);
-
- rangeProto = WrappedRange.prototype;
-
- rangeProto.selectNode = function(node) {
- this.nativeRange.selectNode(node);
- updateRangeProperties(this);
- };
-
- rangeProto.cloneContents = function() {
- return this.nativeRange.cloneContents();
- };
-
- // Due to a long-standing Firefox bug that I have not been able to find a reliable way to detect,
- // insertNode() is never delegated to the native range.
-
- rangeProto.surroundContents = function(node) {
- this.nativeRange.surroundContents(node);
- updateRangeProperties(this);
- };
-
- rangeProto.collapse = function(isStart) {
- this.nativeRange.collapse(isStart);
- updateRangeProperties(this);
- };
-
- rangeProto.cloneRange = function() {
- return new WrappedRange(this.nativeRange.cloneRange());
- };
-
- rangeProto.refresh = function() {
- updateRangeProperties(this);
- };
-
- rangeProto.toString = function() {
- return this.nativeRange.toString();
- };
-
- // Create test range and node for feature detection
-
- var testTextNode = document.createTextNode("test");
- getBody(document).appendChild(testTextNode);
- var range = document.createRange();
-
- /*--------------------------------------------------------------------------------------------------------*/
-
- // Test for Firefox 2 bug that prevents moving the start of a Range to a point after its current end and
- // correct for it
-
- range.setStart(testTextNode, 0);
- range.setEnd(testTextNode, 0);
-
- try {
- range.setStart(testTextNode, 1);
-
- rangeProto.setStart = function(node, offset) {
- this.nativeRange.setStart(node, offset);
- updateRangeProperties(this);
- };
-
- rangeProto.setEnd = function(node, offset) {
- this.nativeRange.setEnd(node, offset);
- updateRangeProperties(this);
- };
-
- createBeforeAfterNodeSetter = function(name) {
- return function(node) {
- this.nativeRange[name](node);
- updateRangeProperties(this);
- };
- };
-
- } catch(ex) {
-
- rangeProto.setStart = function(node, offset) {
- try {
- this.nativeRange.setStart(node, offset);
- } catch (ex) {
- this.nativeRange.setEnd(node, offset);
- this.nativeRange.setStart(node, offset);
- }
- updateRangeProperties(this);
- };
-
- rangeProto.setEnd = function(node, offset) {
- try {
- this.nativeRange.setEnd(node, offset);
- } catch (ex) {
- this.nativeRange.setStart(node, offset);
- this.nativeRange.setEnd(node, offset);
- }
- updateRangeProperties(this);
- };
-
- createBeforeAfterNodeSetter = function(name, oppositeName) {
- return function(node) {
- try {
- this.nativeRange[name](node);
- } catch (ex) {
- this.nativeRange[oppositeName](node);
- this.nativeRange[name](node);
- }
- updateRangeProperties(this);
- };
- };
- }
-
- rangeProto.setStartBefore = createBeforeAfterNodeSetter("setStartBefore", "setEndBefore");
- rangeProto.setStartAfter = createBeforeAfterNodeSetter("setStartAfter", "setEndAfter");
- rangeProto.setEndBefore = createBeforeAfterNodeSetter("setEndBefore", "setStartBefore");
- rangeProto.setEndAfter = createBeforeAfterNodeSetter("setEndAfter", "setStartAfter");
-
- /*--------------------------------------------------------------------------------------------------------*/
-
- // Always use DOM4-compliant selectNodeContents implementation: it's simpler and less code than testing
- // whether the native implementation can be trusted
- rangeProto.selectNodeContents = function(node) {
- this.setStartAndEnd(node, 0, dom.getNodeLength(node));
- };
-
- /*--------------------------------------------------------------------------------------------------------*/
-
- // Test for and correct WebKit bug that has the behaviour of compareBoundaryPoints round the wrong way for
- // constants START_TO_END and END_TO_START: https://bugs.webkit.org/show_bug.cgi?id=20738
-
- range.selectNodeContents(testTextNode);
- range.setEnd(testTextNode, 3);
-
- var range2 = document.createRange();
- range2.selectNodeContents(testTextNode);
- range2.setEnd(testTextNode, 4);
- range2.setStart(testTextNode, 2);
-
- if (range.compareBoundaryPoints(range.START_TO_END, range2) == -1 &&
- range.compareBoundaryPoints(range.END_TO_START, range2) == 1) {
- // This is the wrong way round, so correct for it
-
- rangeProto.compareBoundaryPoints = function(type, range) {
- range = range.nativeRange || range;
- if (type == range.START_TO_END) {
- type = range.END_TO_START;
- } else if (type == range.END_TO_START) {
- type = range.START_TO_END;
- }
- return this.nativeRange.compareBoundaryPoints(type, range);
- };
- } else {
- rangeProto.compareBoundaryPoints = function(type, range) {
- return this.nativeRange.compareBoundaryPoints(type, range.nativeRange || range);
- };
- }
-
- /*--------------------------------------------------------------------------------------------------------*/
-
- // Test for IE deleteContents() and extractContents() bug and correct it. See issue 107.
-
- var el = document.createElement("div");
- el.innerHTML = "123";
- var textNode = el.firstChild;
- var body = getBody(document);
- body.appendChild(el);
-
- range.setStart(textNode, 1);
- range.setEnd(textNode, 2);
- range.deleteContents();
-
- if (textNode.data == "13") {
- // Behaviour is correct per DOM4 Range so wrap the browser's implementation of deleteContents() and
- // extractContents()
- rangeProto.deleteContents = function() {
- this.nativeRange.deleteContents();
- updateRangeProperties(this);
- };
-
- rangeProto.extractContents = function() {
- var frag = this.nativeRange.extractContents();
- updateRangeProperties(this);
- return frag;
- };
- } else {
- }
-
- body.removeChild(el);
- body = null;
-
- /*--------------------------------------------------------------------------------------------------------*/
-
- // Test for existence of createContextualFragment and delegate to it if it exists
- if (util.isHostMethod(range, "createContextualFragment")) {
- rangeProto.createContextualFragment = function(fragmentStr) {
- return this.nativeRange.createContextualFragment(fragmentStr);
- };
- }
-
- /*--------------------------------------------------------------------------------------------------------*/
-
- // Clean up
- getBody(document).removeChild(testTextNode);
-
- rangeProto.getName = function() {
- return "WrappedRange";
- };
-
- api.WrappedRange = WrappedRange;
-
- api.createNativeRange = function(doc) {
- doc = getContentDocument(doc, module, "createNativeRange");
- return doc.createRange();
- };
- })();
- }
-
- if (api.features.implementsTextRange) {
- /*
- This is a workaround for a bug where IE returns the wrong container element from the TextRange's parentElement()
- method. For example, in the following (where pipes denote the selection boundaries):
-
-
-
- var range = document.selection.createRange();
- alert(range.parentElement().id); // Should alert "ul" but alerts "b"
-
- This method returns the common ancestor node of the following:
- - the parentElement() of the textRange
- - the parentElement() of the textRange after calling collapse(true)
- - the parentElement() of the textRange after calling collapse(false)
- */
- var getTextRangeContainerElement = function(textRange) {
- var parentEl = textRange.parentElement();
- var range = textRange.duplicate();
- range.collapse(true);
- var startEl = range.parentElement();
- range = textRange.duplicate();
- range.collapse(false);
- var endEl = range.parentElement();
- var startEndContainer = (startEl == endEl) ? startEl : dom.getCommonAncestor(startEl, endEl);
-
- return startEndContainer == parentEl ? startEndContainer : dom.getCommonAncestor(parentEl, startEndContainer);
- };
-
- var textRangeIsCollapsed = function(textRange) {
- return textRange.compareEndPoints("StartToEnd", textRange) == 0;
- };
-
- // Gets the boundary of a TextRange expressed as a node and an offset within that node. This function started
- // out as an improved version of code found in Tim Cameron Ryan's IERange (http://code.google.com/p/ierange/)
- // but has grown, fixing problems with line breaks in preformatted text, adding workaround for IE TextRange
- // bugs, handling for inputs and images, plus optimizations.
- var getTextRangeBoundaryPosition = function(textRange, wholeRangeContainerElement, isStart, isCollapsed, startInfo) {
- var workingRange = textRange.duplicate();
- workingRange.collapse(isStart);
- var containerElement = workingRange.parentElement();
-
- // Sometimes collapsing a TextRange that's at the start of a text node can move it into the previous node, so
- // check for that
- if (!dom.isOrIsAncestorOf(wholeRangeContainerElement, containerElement)) {
- containerElement = wholeRangeContainerElement;
- }
-
-
- // Deal with nodes that cannot "contain rich HTML markup". In practice, this means form inputs, images and
- // similar. See http://msdn.microsoft.com/en-us/library/aa703950%28VS.85%29.aspx
- if (!containerElement.canHaveHTML) {
- var pos = new DomPosition(containerElement.parentNode, dom.getNodeIndex(containerElement));
- return {
- boundaryPosition: pos,
- nodeInfo: {
- nodeIndex: pos.offset,
- containerElement: pos.node
- }
- };
- }
-
- var workingNode = dom.getDocument(containerElement).createElement("span");
-
- // Workaround for HTML5 Shiv's insane violation of document.createElement(). See Rangy issue 104 and HTML5
- // Shiv issue 64: https://github.com/aFarkas/html5shiv/issues/64
- if (workingNode.parentNode) {
- dom.removeNode(workingNode);
- }
-
- var comparison, workingComparisonType = isStart ? "StartToStart" : "StartToEnd";
- var previousNode, nextNode, boundaryPosition, boundaryNode;
- var start = (startInfo && startInfo.containerElement == containerElement) ? startInfo.nodeIndex : 0;
- var childNodeCount = containerElement.childNodes.length;
- var end = childNodeCount;
-
- // Check end first. Code within the loop assumes that the endth child node of the container is definitely
- // after the range boundary.
- var nodeIndex = end;
-
- while (true) {
- if (nodeIndex == childNodeCount) {
- containerElement.appendChild(workingNode);
- } else {
- containerElement.insertBefore(workingNode, containerElement.childNodes[nodeIndex]);
- }
- workingRange.moveToElementText(workingNode);
- comparison = workingRange.compareEndPoints(workingComparisonType, textRange);
- if (comparison == 0 || start == end) {
- break;
- } else if (comparison == -1) {
- if (end == start + 1) {
- // We know the endth child node is after the range boundary, so we must be done.
- break;
- } else {
- start = nodeIndex;
- }
- } else {
- end = (end == start + 1) ? start : nodeIndex;
- }
- nodeIndex = Math.floor((start + end) / 2);
- containerElement.removeChild(workingNode);
- }
-
-
- // We've now reached or gone past the boundary of the text range we're interested in
- // so have identified the node we want
- boundaryNode = workingNode.nextSibling;
-
- if (comparison == -1 && boundaryNode && isCharacterDataNode(boundaryNode)) {
- // This is a character data node (text, comment, cdata). The working range is collapsed at the start of
- // the node containing the text range's boundary, so we move the end of the working range to the
- // boundary point and measure the length of its text to get the boundary's offset within the node.
- workingRange.setEndPoint(isStart ? "EndToStart" : "EndToEnd", textRange);
-
- var offset;
-
- if (/[\r\n]/.test(boundaryNode.data)) {
- /*
- For the particular case of a boundary within a text node containing rendered line breaks (within a
- element, for example), we need a slightly complicated approach to get the boundary's offset in
- IE. The facts:
-
- - Each line break is represented as \r in the text node's data/nodeValue properties
- - Each line break is represented as \r\n in the TextRange's 'text' property
- - The 'text' property of the TextRange does not contain trailing line breaks
-
- To get round the problem presented by the final fact above, we can use the fact that TextRange's
- moveStart() and moveEnd() methods return the actual number of characters moved, which is not
- necessarily the same as the number of characters it was instructed to move. The simplest approach is
- to use this to store the characters moved when moving both the start and end of the range to the
- start of the document body and subtracting the start offset from the end offset (the
- "move-negative-gazillion" method). However, this is extremely slow when the document is large and
- the range is near the end of it. Clearly doing the mirror image (i.e. moving the range boundaries to
- the end of the document) has the same problem.
-
- Another approach that works is to use moveStart() to move the start boundary of the range up to the
- end boundary one character at a time and incrementing a counter with the value returned by the
- moveStart() call. However, the check for whether the start boundary has reached the end boundary is
- expensive, so this method is slow (although unlike "move-negative-gazillion" is largely unaffected
- by the location of the range within the document).
-
- The approach used below is a hybrid of the two methods above. It uses the fact that a string
- containing the TextRange's 'text' property with each \r\n converted to a single \r character cannot
- be longer than the text of the TextRange, so the start of the range is moved that length initially
- and then a character at a time to make up for any trailing line breaks not contained in the 'text'
- property. This has good performance in most situations compared to the previous two methods.
- */
- var tempRange = workingRange.duplicate();
- var rangeLength = tempRange.text.replace(/\r\n/g, "\r").length;
-
- offset = tempRange.moveStart("character", rangeLength);
- while ( (comparison = tempRange.compareEndPoints("StartToEnd", tempRange)) == -1) {
- offset++;
- tempRange.moveStart("character", 1);
- }
- } else {
- offset = workingRange.text.length;
- }
- boundaryPosition = new DomPosition(boundaryNode, offset);
- } else {
-
- // If the boundary immediately follows a character data node and this is the end boundary, we should favour
- // a position within that, and likewise for a start boundary preceding a character data node
- previousNode = (isCollapsed || !isStart) && workingNode.previousSibling;
- nextNode = (isCollapsed || isStart) && workingNode.nextSibling;
- if (nextNode && isCharacterDataNode(nextNode)) {
- boundaryPosition = new DomPosition(nextNode, 0);
- } else if (previousNode && isCharacterDataNode(previousNode)) {
- boundaryPosition = new DomPosition(previousNode, previousNode.data.length);
- } else {
- boundaryPosition = new DomPosition(containerElement, dom.getNodeIndex(workingNode));
- }
- }
-
- // Clean up
- dom.removeNode(workingNode);
-
- return {
- boundaryPosition: boundaryPosition,
- nodeInfo: {
- nodeIndex: nodeIndex,
- containerElement: containerElement
- }
- };
- };
-
- // Returns a TextRange representing the boundary of a TextRange expressed as a node and an offset within that
- // node. This function started out as an optimized version of code found in Tim Cameron Ryan's IERange
- // (http://code.google.com/p/ierange/)
- var createBoundaryTextRange = function(boundaryPosition, isStart) {
- var boundaryNode, boundaryParent, boundaryOffset = boundaryPosition.offset;
- var doc = dom.getDocument(boundaryPosition.node);
- var workingNode, childNodes, workingRange = getBody(doc).createTextRange();
- var nodeIsDataNode = isCharacterDataNode(boundaryPosition.node);
-
- if (nodeIsDataNode) {
- boundaryNode = boundaryPosition.node;
- boundaryParent = boundaryNode.parentNode;
- } else {
- childNodes = boundaryPosition.node.childNodes;
- boundaryNode = (boundaryOffset < childNodes.length) ? childNodes[boundaryOffset] : null;
- boundaryParent = boundaryPosition.node;
- }
-
- // Position the range immediately before the node containing the boundary
- workingNode = doc.createElement("span");
-
- // Making the working element non-empty element persuades IE to consider the TextRange boundary to be within
- // the element rather than immediately before or after it
- workingNode.innerHTML = "feff;";
-
- // insertBefore is supposed to work like appendChild if the second parameter is null. However, a bug report
- // for IERange suggests that it can crash the browser: http://code.google.com/p/ierange/issues/detail?id=12
- if (boundaryNode) {
- boundaryParent.insertBefore(workingNode, boundaryNode);
- } else {
- boundaryParent.appendChild(workingNode);
- }
-
- workingRange.moveToElementText(workingNode);
- workingRange.collapse(!isStart);
-
- // Clean up
- boundaryParent.removeChild(workingNode);
-
- // Move the working range to the text offset, if required
- if (nodeIsDataNode) {
- workingRange[isStart ? "moveStart" : "moveEnd"]("character", boundaryOffset);
- }
-
- return workingRange;
- };
-
- /*------------------------------------------------------------------------------------------------------------*/
-
- // This is a wrapper around a TextRange, providing full DOM Range functionality using rangy's DomRange as a
- // prototype
-
- WrappedTextRange = function(textRange) {
- this.textRange = textRange;
- this.refresh();
- };
-
- WrappedTextRange.prototype = new DomRange(document);
-
- WrappedTextRange.prototype.refresh = function() {
- var start, end, startBoundary;
-
- // TextRange's parentElement() method cannot be trusted. getTextRangeContainerElement() works around that.
- var rangeContainerElement = getTextRangeContainerElement(this.textRange);
-
- if (textRangeIsCollapsed(this.textRange)) {
- end = start = getTextRangeBoundaryPosition(this.textRange, rangeContainerElement, true,
- true).boundaryPosition;
- } else {
- startBoundary = getTextRangeBoundaryPosition(this.textRange, rangeContainerElement, true, false);
- start = startBoundary.boundaryPosition;
-
- // An optimization used here is that if the start and end boundaries have the same parent element, the
- // search scope for the end boundary can be limited to exclude the portion of the element that precedes
- // the start boundary
- end = getTextRangeBoundaryPosition(this.textRange, rangeContainerElement, false, false,
- startBoundary.nodeInfo).boundaryPosition;
- }
-
- this.setStart(start.node, start.offset);
- this.setEnd(end.node, end.offset);
- };
-
- WrappedTextRange.prototype.getName = function() {
- return "WrappedTextRange";
- };
-
- DomRange.copyComparisonConstants(WrappedTextRange);
-
- var rangeToTextRange = function(range) {
- if (range.collapsed) {
- return createBoundaryTextRange(new DomPosition(range.startContainer, range.startOffset), true);
- } else {
- var startRange = createBoundaryTextRange(new DomPosition(range.startContainer, range.startOffset), true);
- var endRange = createBoundaryTextRange(new DomPosition(range.endContainer, range.endOffset), false);
- var textRange = getBody( DomRange.getRangeDocument(range) ).createTextRange();
- textRange.setEndPoint("StartToStart", startRange);
- textRange.setEndPoint("EndToEnd", endRange);
- return textRange;
- }
- };
-
- WrappedTextRange.rangeToTextRange = rangeToTextRange;
-
- WrappedTextRange.prototype.toTextRange = function() {
- return rangeToTextRange(this);
- };
-
- api.WrappedTextRange = WrappedTextRange;
-
- // IE 9 and above have both implementations and Rangy makes both available. The next few lines sets which
- // implementation to use by default.
- if (!api.features.implementsDomRange || api.config.preferTextRange) {
- // Add WrappedTextRange as the Range property of the global object to allow expression like Range.END_TO_END to work
- var globalObj = (function(f) { return f("return this;")(); })(Function);
- if (typeof globalObj.Range == "undefined") {
- globalObj.Range = WrappedTextRange;
- }
-
- api.createNativeRange = function(doc) {
- doc = getContentDocument(doc, module, "createNativeRange");
- return getBody(doc).createTextRange();
- };
-
- api.WrappedRange = WrappedTextRange;
- }
- }
-
- api.createRange = function(doc) {
- doc = getContentDocument(doc, module, "createRange");
- return new api.WrappedRange(api.createNativeRange(doc));
- };
-
- api.createRangyRange = function(doc) {
- doc = getContentDocument(doc, module, "createRangyRange");
- return new DomRange(doc);
- };
-
- util.createAliasForDeprecatedMethod(api, "createIframeRange", "createRange");
- util.createAliasForDeprecatedMethod(api, "createIframeRangyRange", "createRangyRange");
-
- api.addShimListener(function(win) {
- var doc = win.document;
- if (typeof doc.createRange == "undefined") {
- doc.createRange = function() {
- return api.createRange(doc);
- };
- }
- doc = win = null;
- });
- });
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // This module creates a selection object wrapper that conforms as closely as possible to the Selection specification
- // in the HTML Editing spec (http://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#selections)
- api.createCoreModule("WrappedSelection", ["DomRange", "WrappedRange"], function(api, module) {
- api.config.checkSelectionRanges = true;
-
- var BOOLEAN = "boolean";
- var NUMBER = "number";
- var dom = api.dom;
- var util = api.util;
- var isHostMethod = util.isHostMethod;
- var DomRange = api.DomRange;
- var WrappedRange = api.WrappedRange;
- var DOMException = api.DOMException;
- var DomPosition = dom.DomPosition;
- var getNativeSelection;
- var selectionIsCollapsed;
- var features = api.features;
- var CONTROL = "Control";
- var getDocument = dom.getDocument;
- var getBody = dom.getBody;
- var rangesEqual = DomRange.rangesEqual;
-
-
- // Utility function to support direction parameters in the API that may be a string ("backward", "backwards",
- // "forward" or "forwards") or a Boolean (true for backwards).
- function isDirectionBackward(dir) {
- return (typeof dir == "string") ? /^backward(s)?$/i.test(dir) : !!dir;
- }
-
- function getWindow(win, methodName) {
- if (!win) {
- return window;
- } else if (dom.isWindow(win)) {
- return win;
- } else if (win instanceof WrappedSelection) {
- return win.win;
- } else {
- var doc = dom.getContentDocument(win, module, methodName);
- return dom.getWindow(doc);
- }
- }
-
- function getWinSelection(winParam) {
- return getWindow(winParam, "getWinSelection").getSelection();
- }
-
- function getDocSelection(winParam) {
- return getWindow(winParam, "getDocSelection").document.selection;
- }
-
- function winSelectionIsBackward(sel) {
- var backward = false;
- if (sel.anchorNode) {
- backward = (dom.comparePoints(sel.anchorNode, sel.anchorOffset, sel.focusNode, sel.focusOffset) == 1);
- }
- return backward;
- }
-
- // Test for the Range/TextRange and Selection features required
- // Test for ability to retrieve selection
- var implementsWinGetSelection = isHostMethod(window, "getSelection"),
- implementsDocSelection = util.isHostObject(document, "selection");
-
- features.implementsWinGetSelection = implementsWinGetSelection;
- features.implementsDocSelection = implementsDocSelection;
-
- var useDocumentSelection = implementsDocSelection && (!implementsWinGetSelection || api.config.preferTextRange);
-
- if (useDocumentSelection) {
- getNativeSelection = getDocSelection;
- api.isSelectionValid = function(winParam) {
- var doc = getWindow(winParam, "isSelectionValid").document, nativeSel = doc.selection;
-
- // Check whether the selection TextRange is actually contained within the correct document
- return (nativeSel.type != "None" || getDocument(nativeSel.createRange().parentElement()) == doc);
- };
- } else if (implementsWinGetSelection) {
- getNativeSelection = getWinSelection;
- api.isSelectionValid = function() {
- return true;
- };
- } else {
- module.fail("Neither document.selection or window.getSelection() detected.");
- return false;
- }
-
- api.getNativeSelection = getNativeSelection;
-
- var testSelection = getNativeSelection();
-
- // In Firefox, the selection is null in an iframe with display: none. See issue #138.
- if (!testSelection) {
- module.fail("Native selection was null (possibly issue 138?)");
- return false;
- }
-
- var testRange = api.createNativeRange(document);
- var body = getBody(document);
-
- // Obtaining a range from a selection
- var selectionHasAnchorAndFocus = util.areHostProperties(testSelection,
- ["anchorNode", "focusNode", "anchorOffset", "focusOffset"]);
-
- features.selectionHasAnchorAndFocus = selectionHasAnchorAndFocus;
-
- // Test for existence of native selection extend() method
- var selectionHasExtend = isHostMethod(testSelection, "extend");
- features.selectionHasExtend = selectionHasExtend;
-
- // Test if rangeCount exists
- var selectionHasRangeCount = (typeof testSelection.rangeCount == NUMBER);
- features.selectionHasRangeCount = selectionHasRangeCount;
-
- var selectionSupportsMultipleRanges = false;
- var collapsedNonEditableSelectionsSupported = true;
-
- var addRangeBackwardToNative = selectionHasExtend ?
- function(nativeSelection, range) {
- var doc = DomRange.getRangeDocument(range);
- var endRange = api.createRange(doc);
- endRange.collapseToPoint(range.endContainer, range.endOffset);
- nativeSelection.addRange(getNativeRange(endRange));
- nativeSelection.extend(range.startContainer, range.startOffset);
- } : null;
-
- if (util.areHostMethods(testSelection, ["addRange", "getRangeAt", "removeAllRanges"]) &&
- typeof testSelection.rangeCount == NUMBER && features.implementsDomRange) {
-
- (function() {
- // Previously an iframe was used but this caused problems in some circumstances in IE, so tests are
- // performed on the current document's selection. See issue 109.
-
- // Note also that if a selection previously existed, it is wiped and later restored by these tests. This
- // will result in the selection direction begin reversed if the original selection was backwards and the
- // browser does not support setting backwards selections (Internet Explorer, I'm looking at you).
- var sel = window.getSelection();
- if (sel) {
- // Store the current selection
- var originalSelectionRangeCount = sel.rangeCount;
- var selectionHasMultipleRanges = (originalSelectionRangeCount > 1);
- var originalSelectionRanges = [];
- var originalSelectionBackward = winSelectionIsBackward(sel);
- for (var i = 0; i < originalSelectionRangeCount; ++i) {
- originalSelectionRanges[i] = sel.getRangeAt(i);
- }
-
- // Create some test elements
- var testEl = dom.createTestElement(document, "", false);
- var textNode = testEl.appendChild( document.createTextNode("\u00a0\u00a0\u00a0") );
-
- // Test whether the native selection will allow a collapsed selection within a non-editable element
- var r1 = document.createRange();
-
- r1.setStart(textNode, 1);
- r1.collapse(true);
- sel.removeAllRanges();
- sel.addRange(r1);
- collapsedNonEditableSelectionsSupported = (sel.rangeCount == 1);
- sel.removeAllRanges();
-
- // Test whether the native selection is capable of supporting multiple ranges.
- if (!selectionHasMultipleRanges) {
- // Doing the original feature test here in Chrome 36 (and presumably later versions) prints a
- // console error of "Discontiguous selection is not supported." that cannot be suppressed. There's
- // nothing we can do about this while retaining the feature test so we have to resort to a browser
- // sniff. I'm not happy about it. See
- // https://code.google.com/p/chromium/issues/detail?id=399791
- var chromeMatch = window.navigator.appVersion.match(/Chrome\/(.*?) /);
- if (chromeMatch && parseInt(chromeMatch[1]) >= 36) {
- selectionSupportsMultipleRanges = false;
- } else {
- var r2 = r1.cloneRange();
- r1.setStart(textNode, 0);
- r2.setEnd(textNode, 3);
- r2.setStart(textNode, 2);
- sel.addRange(r1);
- sel.addRange(r2);
- selectionSupportsMultipleRanges = (sel.rangeCount == 2);
- }
- }
-
- // Clean up
- dom.removeNode(testEl);
- sel.removeAllRanges();
-
- for (i = 0; i < originalSelectionRangeCount; ++i) {
- if (i == 0 && originalSelectionBackward) {
- if (addRangeBackwardToNative) {
- addRangeBackwardToNative(sel, originalSelectionRanges[i]);
- } else {
- api.warn("Rangy initialization: original selection was backwards but selection has been restored forwards because the browser does not support Selection.extend");
- sel.addRange(originalSelectionRanges[i]);
- }
- } else {
- sel.addRange(originalSelectionRanges[i]);
- }
- }
- }
- })();
- }
-
- features.selectionSupportsMultipleRanges = selectionSupportsMultipleRanges;
- features.collapsedNonEditableSelectionsSupported = collapsedNonEditableSelectionsSupported;
-
- // ControlRanges
- var implementsControlRange = false, testControlRange;
-
- if (body && isHostMethod(body, "createControlRange")) {
- testControlRange = body.createControlRange();
- if (util.areHostProperties(testControlRange, ["item", "add"])) {
- implementsControlRange = true;
- }
- }
- features.implementsControlRange = implementsControlRange;
-
- // Selection collapsedness
- if (selectionHasAnchorAndFocus) {
- selectionIsCollapsed = function(sel) {
- return sel.anchorNode === sel.focusNode && sel.anchorOffset === sel.focusOffset;
- };
- } else {
- selectionIsCollapsed = function(sel) {
- return sel.rangeCount ? sel.getRangeAt(sel.rangeCount - 1).collapsed : false;
- };
- }
-
- function updateAnchorAndFocusFromRange(sel, range, backward) {
- var anchorPrefix = backward ? "end" : "start", focusPrefix = backward ? "start" : "end";
- sel.anchorNode = range[anchorPrefix + "Container"];
- sel.anchorOffset = range[anchorPrefix + "Offset"];
- sel.focusNode = range[focusPrefix + "Container"];
- sel.focusOffset = range[focusPrefix + "Offset"];
- }
-
- function updateAnchorAndFocusFromNativeSelection(sel) {
- var nativeSel = sel.nativeSelection;
- sel.anchorNode = nativeSel.anchorNode;
- sel.anchorOffset = nativeSel.anchorOffset;
- sel.focusNode = nativeSel.focusNode;
- sel.focusOffset = nativeSel.focusOffset;
- }
-
- function updateEmptySelection(sel) {
- sel.anchorNode = sel.focusNode = null;
- sel.anchorOffset = sel.focusOffset = 0;
- sel.rangeCount = 0;
- sel.isCollapsed = true;
- sel._ranges.length = 0;
- }
-
- function getNativeRange(range) {
- var nativeRange;
- if (range instanceof DomRange) {
- nativeRange = api.createNativeRange(range.getDocument());
- nativeRange.setEnd(range.endContainer, range.endOffset);
- nativeRange.setStart(range.startContainer, range.startOffset);
- } else if (range instanceof WrappedRange) {
- nativeRange = range.nativeRange;
- } else if (features.implementsDomRange && (range instanceof dom.getWindow(range.startContainer).Range)) {
- nativeRange = range;
- }
- return nativeRange;
- }
-
- function rangeContainsSingleElement(rangeNodes) {
- if (!rangeNodes.length || rangeNodes[0].nodeType != 1) {
- return false;
- }
- for (var i = 1, len = rangeNodes.length; i < len; ++i) {
- if (!dom.isAncestorOf(rangeNodes[0], rangeNodes[i])) {
- return false;
- }
- }
- return true;
- }
-
- function getSingleElementFromRange(range) {
- var nodes = range.getNodes();
- if (!rangeContainsSingleElement(nodes)) {
- throw module.createError("getSingleElementFromRange: range " + range.inspect() + " did not consist of a single element");
- }
- return nodes[0];
- }
-
- // Simple, quick test which only needs to distinguish between a TextRange and a ControlRange
- function isTextRange(range) {
- return !!range && typeof range.text != "undefined";
- }
-
- function updateFromTextRange(sel, range) {
- // Create a Range from the selected TextRange
- var wrappedRange = new WrappedRange(range);
- sel._ranges = [wrappedRange];
-
- updateAnchorAndFocusFromRange(sel, wrappedRange, false);
- sel.rangeCount = 1;
- sel.isCollapsed = wrappedRange.collapsed;
- }
-
- function updateControlSelection(sel) {
- // Update the wrapped selection based on what's now in the native selection
- sel._ranges.length = 0;
- if (sel.docSelection.type == "None") {
- updateEmptySelection(sel);
- } else {
- var controlRange = sel.docSelection.createRange();
- if (isTextRange(controlRange)) {
- // This case (where the selection type is "Control" and calling createRange() on the selection returns
- // a TextRange) can happen in IE 9. It happens, for example, when all elements in the selected
- // ControlRange have been removed from the ControlRange and removed from the document.
- updateFromTextRange(sel, controlRange);
- } else {
- sel.rangeCount = controlRange.length;
- var range, doc = getDocument(controlRange.item(0));
- for (var i = 0; i < sel.rangeCount; ++i) {
- range = api.createRange(doc);
- range.selectNode(controlRange.item(i));
- sel._ranges.push(range);
- }
- sel.isCollapsed = sel.rangeCount == 1 && sel._ranges[0].collapsed;
- updateAnchorAndFocusFromRange(sel, sel._ranges[sel.rangeCount - 1], false);
- }
- }
- }
-
- function addRangeToControlSelection(sel, range) {
- var controlRange = sel.docSelection.createRange();
- var rangeElement = getSingleElementFromRange(range);
-
- // Create a new ControlRange containing all the elements in the selected ControlRange plus the element
- // contained by the supplied range
- var doc = getDocument(controlRange.item(0));
- var newControlRange = getBody(doc).createControlRange();
- for (var i = 0, len = controlRange.length; i < len; ++i) {
- newControlRange.add(controlRange.item(i));
- }
- try {
- newControlRange.add(rangeElement);
- } catch (ex) {
- throw module.createError("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)");
- }
- newControlRange.select();
-
- // Update the wrapped selection based on what's now in the native selection
- updateControlSelection(sel);
- }
-
- var getSelectionRangeAt;
-
- if (isHostMethod(testSelection, "getRangeAt")) {
- // try/catch is present because getRangeAt() must have thrown an error in some browser and some situation.
- // Unfortunately, I didn't write a comment about the specifics and am now scared to take it out. Let that be a
- // lesson to us all, especially me.
- getSelectionRangeAt = function(sel, index) {
- try {
- return sel.getRangeAt(index);
- } catch (ex) {
- return null;
- }
- };
- } else if (selectionHasAnchorAndFocus) {
- getSelectionRangeAt = function(sel) {
- var doc = getDocument(sel.anchorNode);
- var range = api.createRange(doc);
- range.setStartAndEnd(sel.anchorNode, sel.anchorOffset, sel.focusNode, sel.focusOffset);
-
- // Handle the case when the selection was selected backwards (from the end to the start in the
- // document)
- if (range.collapsed !== this.isCollapsed) {
- range.setStartAndEnd(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset);
- }
-
- return range;
- };
- }
-
- function WrappedSelection(selection, docSelection, win) {
- this.nativeSelection = selection;
- this.docSelection = docSelection;
- this._ranges = [];
- this.win = win;
- this.refresh();
- }
-
- WrappedSelection.prototype = api.selectionPrototype;
-
- function deleteProperties(sel) {
- sel.win = sel.anchorNode = sel.focusNode = sel._ranges = null;
- sel.rangeCount = sel.anchorOffset = sel.focusOffset = 0;
- sel.detached = true;
- }
-
- var cachedRangySelections = [];
-
- function actOnCachedSelection(win, action) {
- var i = cachedRangySelections.length, cached, sel;
- while (i--) {
- cached = cachedRangySelections[i];
- sel = cached.selection;
- if (action == "deleteAll") {
- deleteProperties(sel);
- } else if (cached.win == win) {
- if (action == "delete") {
- cachedRangySelections.splice(i, 1);
- return true;
- } else {
- return sel;
- }
- }
- }
- if (action == "deleteAll") {
- cachedRangySelections.length = 0;
- }
- return null;
- }
-
- var getSelection = function(win) {
- // Check if the parameter is a Rangy Selection object
- if (win && win instanceof WrappedSelection) {
- win.refresh();
- return win;
- }
-
- win = getWindow(win, "getNativeSelection");
-
- var sel = actOnCachedSelection(win);
- var nativeSel = getNativeSelection(win), docSel = implementsDocSelection ? getDocSelection(win) : null;
- if (sel) {
- sel.nativeSelection = nativeSel;
- sel.docSelection = docSel;
- sel.refresh();
- } else {
- sel = new WrappedSelection(nativeSel, docSel, win);
- cachedRangySelections.push( { win: win, selection: sel } );
- }
- return sel;
- };
-
- api.getSelection = getSelection;
-
- util.createAliasForDeprecatedMethod(api, "getIframeSelection", "getSelection");
-
- var selProto = WrappedSelection.prototype;
-
- function createControlSelection(sel, ranges) {
- // Ensure that the selection becomes of type "Control"
- var doc = getDocument(ranges[0].startContainer);
- var controlRange = getBody(doc).createControlRange();
- for (var i = 0, el, len = ranges.length; i < len; ++i) {
- el = getSingleElementFromRange(ranges[i]);
- try {
- controlRange.add(el);
- } catch (ex) {
- throw module.createError("setRanges(): Element within one of the specified Ranges could not be added to control selection (does it have layout?)");
- }
- }
- controlRange.select();
-
- // Update the wrapped selection based on what's now in the native selection
- updateControlSelection(sel);
- }
-
- // Selecting a range
- if (!useDocumentSelection && selectionHasAnchorAndFocus && util.areHostMethods(testSelection, ["removeAllRanges", "addRange"])) {
- selProto.removeAllRanges = function() {
- this.nativeSelection.removeAllRanges();
- updateEmptySelection(this);
- };
-
- var addRangeBackward = function(sel, range) {
- addRangeBackwardToNative(sel.nativeSelection, range);
- sel.refresh();
- };
-
- if (selectionHasRangeCount) {
- selProto.addRange = function(range, direction) {
- if (implementsControlRange && implementsDocSelection && this.docSelection.type == CONTROL) {
- addRangeToControlSelection(this, range);
- } else {
- if (isDirectionBackward(direction) && selectionHasExtend) {
- addRangeBackward(this, range);
- } else {
- var previousRangeCount;
- if (selectionSupportsMultipleRanges) {
- previousRangeCount = this.rangeCount;
- } else {
- this.removeAllRanges();
- previousRangeCount = 0;
- }
- // Clone the native range so that changing the selected range does not affect the selection.
- // This is contrary to the spec but is the only way to achieve consistency between browsers. See
- // issue 80.
- var clonedNativeRange = getNativeRange(range).cloneRange();
- try {
- this.nativeSelection.addRange(clonedNativeRange);
- } catch (ex) {
- }
-
- // Check whether adding the range was successful
- this.rangeCount = this.nativeSelection.rangeCount;
-
- if (this.rangeCount == previousRangeCount + 1) {
- // The range was added successfully
-
- // Check whether the range that we added to the selection is reflected in the last range extracted from
- // the selection
- if (api.config.checkSelectionRanges) {
- var nativeRange = getSelectionRangeAt(this.nativeSelection, this.rangeCount - 1);
- if (nativeRange && !rangesEqual(nativeRange, range)) {
- // Happens in WebKit with, for example, a selection placed at the start of a text node
- range = new WrappedRange(nativeRange);
- }
- }
- this._ranges[this.rangeCount - 1] = range;
- updateAnchorAndFocusFromRange(this, range, selectionIsBackward(this.nativeSelection));
- this.isCollapsed = selectionIsCollapsed(this);
- } else {
- // The range was not added successfully. The simplest thing is to refresh
- this.refresh();
- }
- }
- }
- };
- } else {
- selProto.addRange = function(range, direction) {
- if (isDirectionBackward(direction) && selectionHasExtend) {
- addRangeBackward(this, range);
- } else {
- this.nativeSelection.addRange(getNativeRange(range));
- this.refresh();
- }
- };
- }
-
- selProto.setRanges = function(ranges) {
- if (implementsControlRange && implementsDocSelection && ranges.length > 1) {
- createControlSelection(this, ranges);
- } else {
- this.removeAllRanges();
- for (var i = 0, len = ranges.length; i < len; ++i) {
- this.addRange(ranges[i]);
- }
- }
- };
- } else if (isHostMethod(testSelection, "empty") && isHostMethod(testRange, "select") &&
- implementsControlRange && useDocumentSelection) {
-
- selProto.removeAllRanges = function() {
- // Added try/catch as fix for issue #21
- try {
- this.docSelection.empty();
-
- // Check for empty() not working (issue #24)
- if (this.docSelection.type != "None") {
- // Work around failure to empty a control selection by instead selecting a TextRange and then
- // calling empty()
- var doc;
- if (this.anchorNode) {
- doc = getDocument(this.anchorNode);
- } else if (this.docSelection.type == CONTROL) {
- var controlRange = this.docSelection.createRange();
- if (controlRange.length) {
- doc = getDocument( controlRange.item(0) );
- }
- }
- if (doc) {
- var textRange = getBody(doc).createTextRange();
- textRange.select();
- this.docSelection.empty();
- }
- }
- } catch(ex) {}
- updateEmptySelection(this);
- };
-
- selProto.addRange = function(range) {
- if (this.docSelection.type == CONTROL) {
- addRangeToControlSelection(this, range);
- } else {
- api.WrappedTextRange.rangeToTextRange(range).select();
- this._ranges[0] = range;
- this.rangeCount = 1;
- this.isCollapsed = this._ranges[0].collapsed;
- updateAnchorAndFocusFromRange(this, range, false);
- }
- };
-
- selProto.setRanges = function(ranges) {
- this.removeAllRanges();
- var rangeCount = ranges.length;
- if (rangeCount > 1) {
- createControlSelection(this, ranges);
- } else if (rangeCount) {
- this.addRange(ranges[0]);
- }
- };
- } else {
- module.fail("No means of selecting a Range or TextRange was found");
- return false;
- }
-
- selProto.getRangeAt = function(index) {
- if (index < 0 || index >= this.rangeCount) {
- throw new DOMException("INDEX_SIZE_ERR");
- } else {
- // Clone the range to preserve selection-range independence. See issue 80.
- return this._ranges[index].cloneRange();
- }
- };
-
- var refreshSelection;
-
- if (useDocumentSelection) {
- refreshSelection = function(sel) {
- var range;
- if (api.isSelectionValid(sel.win)) {
- range = sel.docSelection.createRange();
- } else {
- range = getBody(sel.win.document).createTextRange();
- range.collapse(true);
- }
-
- if (sel.docSelection.type == CONTROL) {
- updateControlSelection(sel);
- } else if (isTextRange(range)) {
- updateFromTextRange(sel, range);
- } else {
- updateEmptySelection(sel);
- }
- };
- } else if (isHostMethod(testSelection, "getRangeAt") && typeof testSelection.rangeCount == NUMBER) {
- refreshSelection = function(sel) {
- if (implementsControlRange && implementsDocSelection && sel.docSelection.type == CONTROL) {
- updateControlSelection(sel);
- } else {
- sel._ranges.length = sel.rangeCount = sel.nativeSelection.rangeCount;
- if (sel.rangeCount) {
- for (var i = 0, len = sel.rangeCount; i < len; ++i) {
- sel._ranges[i] = new api.WrappedRange(sel.nativeSelection.getRangeAt(i));
- }
- updateAnchorAndFocusFromRange(sel, sel._ranges[sel.rangeCount - 1], selectionIsBackward(sel.nativeSelection));
- sel.isCollapsed = selectionIsCollapsed(sel);
- } else {
- updateEmptySelection(sel);
- }
- }
- };
- } else if (selectionHasAnchorAndFocus && typeof testSelection.isCollapsed == BOOLEAN && typeof testRange.collapsed == BOOLEAN && features.implementsDomRange) {
- refreshSelection = function(sel) {
- var range, nativeSel = sel.nativeSelection;
- if (nativeSel.anchorNode) {
- range = getSelectionRangeAt(nativeSel, 0);
- sel._ranges = [range];
- sel.rangeCount = 1;
- updateAnchorAndFocusFromNativeSelection(sel);
- sel.isCollapsed = selectionIsCollapsed(sel);
- } else {
- updateEmptySelection(sel);
- }
- };
- } else {
- module.fail("No means of obtaining a Range or TextRange from the user's selection was found");
- return false;
- }
-
- selProto.refresh = function(checkForChanges) {
- var oldRanges = checkForChanges ? this._ranges.slice(0) : null;
- var oldAnchorNode = this.anchorNode, oldAnchorOffset = this.anchorOffset;
-
- refreshSelection(this);
- if (checkForChanges) {
- // Check the range count first
- var i = oldRanges.length;
- if (i != this._ranges.length) {
- return true;
- }
-
- // Now check the direction. Checking the anchor position is the same is enough since we're checking all the
- // ranges after this
- if (this.anchorNode != oldAnchorNode || this.anchorOffset != oldAnchorOffset) {
- return true;
- }
-
- // Finally, compare each range in turn
- while (i--) {
- if (!rangesEqual(oldRanges[i], this._ranges[i])) {
- return true;
- }
- }
- return false;
- }
- };
-
- // Removal of a single range
- var removeRangeManually = function(sel, range) {
- var ranges = sel.getAllRanges();
- sel.removeAllRanges();
- for (var i = 0, len = ranges.length; i < len; ++i) {
- if (!rangesEqual(range, ranges[i])) {
- sel.addRange(ranges[i]);
- }
- }
- if (!sel.rangeCount) {
- updateEmptySelection(sel);
- }
- };
-
- if (implementsControlRange && implementsDocSelection) {
- selProto.removeRange = function(range) {
- if (this.docSelection.type == CONTROL) {
- var controlRange = this.docSelection.createRange();
- var rangeElement = getSingleElementFromRange(range);
-
- // Create a new ControlRange containing all the elements in the selected ControlRange minus the
- // element contained by the supplied range
- var doc = getDocument(controlRange.item(0));
- var newControlRange = getBody(doc).createControlRange();
- var el, removed = false;
- for (var i = 0, len = controlRange.length; i < len; ++i) {
- el = controlRange.item(i);
- if (el !== rangeElement || removed) {
- newControlRange.add(controlRange.item(i));
- } else {
- removed = true;
- }
- }
- newControlRange.select();
-
- // Update the wrapped selection based on what's now in the native selection
- updateControlSelection(this);
- } else {
- removeRangeManually(this, range);
- }
- };
- } else {
- selProto.removeRange = function(range) {
- removeRangeManually(this, range);
- };
- }
-
- // Detecting if a selection is backward
- var selectionIsBackward;
- if (!useDocumentSelection && selectionHasAnchorAndFocus && features.implementsDomRange) {
- selectionIsBackward = winSelectionIsBackward;
-
- selProto.isBackward = function() {
- return selectionIsBackward(this);
- };
- } else {
- selectionIsBackward = selProto.isBackward = function() {
- return false;
- };
- }
-
- // Create an alias for backwards compatibility. From 1.3, everything is "backward" rather than "backwards"
- selProto.isBackwards = selProto.isBackward;
-
- // Selection stringifier
- // This is conformant to the old HTML5 selections draft spec but differs from WebKit and Mozilla's implementation.
- // The current spec does not yet define this method.
- selProto.toString = function() {
- var rangeTexts = [];
- for (var i = 0, len = this.rangeCount; i < len; ++i) {
- rangeTexts[i] = "" + this._ranges[i];
- }
- return rangeTexts.join("");
- };
-
- function assertNodeInSameDocument(sel, node) {
- if (sel.win.document != getDocument(node)) {
- throw new DOMException("WRONG_DOCUMENT_ERR");
- }
- }
-
- // No current browser conforms fully to the spec for this method, so Rangy's own method is always used
- selProto.collapse = function(node, offset) {
- assertNodeInSameDocument(this, node);
- var range = api.createRange(node);
- range.collapseToPoint(node, offset);
- this.setSingleRange(range);
- this.isCollapsed = true;
- };
-
- selProto.collapseToStart = function() {
- if (this.rangeCount) {
- var range = this._ranges[0];
- this.collapse(range.startContainer, range.startOffset);
- } else {
- throw new DOMException("INVALID_STATE_ERR");
- }
- };
-
- selProto.collapseToEnd = function() {
- if (this.rangeCount) {
- var range = this._ranges[this.rangeCount - 1];
- this.collapse(range.endContainer, range.endOffset);
- } else {
- throw new DOMException("INVALID_STATE_ERR");
- }
- };
-
- // The spec is very specific on how selectAllChildren should be implemented and not all browsers implement it as
- // specified so the native implementation is never used by Rangy.
- selProto.selectAllChildren = function(node) {
- assertNodeInSameDocument(this, node);
- var range = api.createRange(node);
- range.selectNodeContents(node);
- this.setSingleRange(range);
- };
-
- selProto.deleteFromDocument = function() {
- // Sepcial behaviour required for IE's control selections
- if (implementsControlRange && implementsDocSelection && this.docSelection.type == CONTROL) {
- var controlRange = this.docSelection.createRange();
- var element;
- while (controlRange.length) {
- element = controlRange.item(0);
- controlRange.remove(element);
- dom.removeNode(element);
- }
- this.refresh();
- } else if (this.rangeCount) {
- var ranges = this.getAllRanges();
- if (ranges.length) {
- this.removeAllRanges();
- for (var i = 0, len = ranges.length; i < len; ++i) {
- ranges[i].deleteContents();
- }
- // The spec says nothing about what the selection should contain after calling deleteContents on each
- // range. Firefox moves the selection to where the final selected range was, so we emulate that
- this.addRange(ranges[len - 1]);
- }
- }
- };
-
- // The following are non-standard extensions
- selProto.eachRange = function(func, returnValue) {
- for (var i = 0, len = this._ranges.length; i < len; ++i) {
- if ( func( this.getRangeAt(i) ) ) {
- return returnValue;
- }
- }
- };
-
- selProto.getAllRanges = function() {
- var ranges = [];
- this.eachRange(function(range) {
- ranges.push(range);
- });
- return ranges;
- };
-
- selProto.setSingleRange = function(range, direction) {
- this.removeAllRanges();
- this.addRange(range, direction);
- };
-
- selProto.callMethodOnEachRange = function(methodName, params) {
- var results = [];
- this.eachRange( function(range) {
- results.push( range[methodName].apply(range, params || []) );
- } );
- return results;
- };
-
- function createStartOrEndSetter(isStart) {
- return function(node, offset) {
- var range;
- if (this.rangeCount) {
- range = this.getRangeAt(0);
- range["set" + (isStart ? "Start" : "End")](node, offset);
- } else {
- range = api.createRange(this.win.document);
- range.setStartAndEnd(node, offset);
- }
- this.setSingleRange(range, this.isBackward());
- };
- }
-
- selProto.setStart = createStartOrEndSetter(true);
- selProto.setEnd = createStartOrEndSetter(false);
-
- // Add select() method to Range prototype. Any existing selection will be removed.
- api.rangePrototype.select = function(direction) {
- getSelection( this.getDocument() ).setSingleRange(this, direction);
- };
-
- selProto.changeEachRange = function(func) {
- var ranges = [];
- var backward = this.isBackward();
-
- this.eachRange(function(range) {
- func(range);
- ranges.push(range);
- });
-
- this.removeAllRanges();
- if (backward && ranges.length == 1) {
- this.addRange(ranges[0], "backward");
- } else {
- this.setRanges(ranges);
- }
- };
-
- selProto.containsNode = function(node, allowPartial) {
- return this.eachRange( function(range) {
- return range.containsNode(node, allowPartial);
- }, true ) || false;
- };
-
- selProto.getBookmark = function(containerNode) {
- return {
- backward: this.isBackward(),
- rangeBookmarks: this.callMethodOnEachRange("getBookmark", [containerNode])
- };
- };
-
- selProto.moveToBookmark = function(bookmark) {
- var selRanges = [];
- for (var i = 0, rangeBookmark, range; rangeBookmark = bookmark.rangeBookmarks[i++]; ) {
- range = api.createRange(this.win);
- range.moveToBookmark(rangeBookmark);
- selRanges.push(range);
- }
- if (bookmark.backward) {
- this.setSingleRange(selRanges[0], "backward");
- } else {
- this.setRanges(selRanges);
- }
- };
-
- selProto.saveRanges = function() {
- return {
- backward: this.isBackward(),
- ranges: this.callMethodOnEachRange("cloneRange")
- };
- };
-
- selProto.restoreRanges = function(selRanges) {
- this.removeAllRanges();
- for (var i = 0, range; range = selRanges.ranges[i]; ++i) {
- this.addRange(range, (selRanges.backward && i == 0));
- }
- };
-
- selProto.toHtml = function() {
- var rangeHtmls = [];
- this.eachRange(function(range) {
- rangeHtmls.push( DomRange.toHtml(range) );
- });
- return rangeHtmls.join("");
- };
-
- if (features.implementsTextRange) {
- selProto.getNativeTextRange = function() {
- var sel, textRange;
- if ( (sel = this.docSelection) ) {
- var range = sel.createRange();
- if (isTextRange(range)) {
- return range;
- } else {
- throw module.createError("getNativeTextRange: selection is a control selection");
- }
- } else if (this.rangeCount > 0) {
- return api.WrappedTextRange.rangeToTextRange( this.getRangeAt(0) );
- } else {
- throw module.createError("getNativeTextRange: selection contains no range");
- }
- };
- }
-
- function inspect(sel) {
- var rangeInspects = [];
- var anchor = new DomPosition(sel.anchorNode, sel.anchorOffset);
- var focus = new DomPosition(sel.focusNode, sel.focusOffset);
- var name = (typeof sel.getName == "function") ? sel.getName() : "Selection";
-
- if (typeof sel.rangeCount != "undefined") {
- for (var i = 0, len = sel.rangeCount; i < len; ++i) {
- rangeInspects[i] = DomRange.inspect(sel.getRangeAt(i));
- }
- }
- return "[" + name + "(Ranges: " + rangeInspects.join(", ") +
- ")(anchor: " + anchor.inspect() + ", focus: " + focus.inspect() + "]";
- }
-
- selProto.getName = function() {
- return "WrappedSelection";
- };
-
- selProto.inspect = function() {
- return inspect(this);
- };
-
- selProto.detach = function() {
- actOnCachedSelection(this.win, "delete");
- deleteProperties(this);
- };
-
- WrappedSelection.detachAll = function() {
- actOnCachedSelection(null, "deleteAll");
- };
-
- WrappedSelection.inspect = inspect;
- WrappedSelection.isDirectionBackward = isDirectionBackward;
-
- api.Selection = WrappedSelection;
-
- api.selectionPrototype = selProto;
-
- api.addShimListener(function(win) {
- if (typeof win.getSelection == "undefined") {
- win.getSelection = function() {
- return getSelection(win);
- };
- }
- win = null;
- });
- });
-
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Wait for document to load before initializing
- var docReady = false;
-
- var loadHandler = function(e) {
- if (!docReady) {
- docReady = true;
- if (!api.initialized && api.config.autoInitialize) {
- init();
- }
- }
- };
-
- if (isBrowser) {
- // Test whether the document has already been loaded and initialize immediately if so
- if (document.readyState == "complete") {
- loadHandler();
- } else {
- if (isHostMethod(document, "addEventListener")) {
- document.addEventListener("DOMContentLoaded", loadHandler, false);
- }
-
- // Add a fallback in case the DOMContentLoaded event isn't supported
- addListener(window, "load", loadHandler);
- }
- }
-
- return api;
-}, this);
-;/**
- * Text range module for Rangy.
- * Text-based manipulation and searching of ranges and selections.
- *
- * Features
- *
- * - Ability to move range boundaries by character or word offsets
- * - Customizable word tokenizer
- * - Ignores text nodes inside
- */
-(function(wysihtml5) {
- var /**
- * Don't auto-link urls that are contained in the following elements:
- */
- IGNORE_URLS_IN = wysihtml5.lang.array(["CODE", "PRE", "A", "SCRIPT", "HEAD", "TITLE", "STYLE"]),
- /**
- * revision 1:
- * /(\S+\.{1}[^\s\,\.\!]+)/g
- *
- * revision 2:
- * /(\b(((https?|ftp):\/\/)|(www\.))[-A-Z0-9+&@#\/%?=~_|!:,.;\[\]]*[-A-Z0-9+&@#\/%=~_|])/gim
- *
- * put this in the beginning if you don't wan't to match within a word
- * (^|[\>\(\{\[\s\>])
- */
- URL_REG_EXP = /((https?:\/\/|www\.)[^\s<]{3,})/gi,
- TRAILING_CHAR_REG_EXP = /([^\w\/\-](,?))$/i,
- MAX_DISPLAY_LENGTH = 100,
- BRACKETS = { ")": "(", "]": "[", "}": "{" };
-
- function autoLink(element, ignoreInClasses) {
- if (_hasParentThatShouldBeIgnored(element, ignoreInClasses)) {
- return element;
- }
-
- if (element === element.ownerDocument.documentElement) {
- element = element.ownerDocument.body;
- }
-
- return _parseNode(element, ignoreInClasses);
- }
-
- /**
- * This is basically a rebuild of
- * the rails auto_link_urls text helper
- */
- function _convertUrlsToLinks(str) {
- return str.replace(URL_REG_EXP, function(match, url) {
- var punctuation = (url.match(TRAILING_CHAR_REG_EXP) || [])[1] || "",
- opening = BRACKETS[punctuation];
- url = url.replace(TRAILING_CHAR_REG_EXP, "");
-
- if (url.split(opening).length > url.split(punctuation).length) {
- url = url + punctuation;
- punctuation = "";
- }
- var realUrl = url,
- displayUrl = url;
- if (url.length > MAX_DISPLAY_LENGTH) {
- displayUrl = displayUrl.substr(0, MAX_DISPLAY_LENGTH) + "...";
- }
- // Add http prefix if necessary
- if (realUrl.substr(0, 4) === "www.") {
- realUrl = "http://" + realUrl;
- }
-
- return '' + displayUrl + ' ' + punctuation;
- });
- }
-
- /**
- * Creates or (if already cached) returns a temp element
- * for the given document object
- */
- function _getTempElement(context) {
- var tempElement = context._wysihtml5_tempElement;
- if (!tempElement) {
- tempElement = context._wysihtml5_tempElement = context.createElement("div");
- }
- return tempElement;
- }
-
- /**
- * Replaces the original text nodes with the newly auto-linked dom tree
- */
- function _wrapMatchesInNode(textNode) {
- var parentNode = textNode.parentNode,
- nodeValue = wysihtml5.lang.string(textNode.data).escapeHTML(),
- tempElement = _getTempElement(parentNode.ownerDocument);
-
- // We need to insert an empty/temporary to fix IE quirks
- // Elsewise IE would strip white space in the beginning
- tempElement.innerHTML = " " + _convertUrlsToLinks(nodeValue);
- tempElement.removeChild(tempElement.firstChild);
-
- while (tempElement.firstChild) {
- // inserts tempElement.firstChild before textNode
- parentNode.insertBefore(tempElement.firstChild, textNode);
- }
- parentNode.removeChild(textNode);
- }
-
- function _hasParentThatShouldBeIgnored(node, ignoreInClasses) {
- var nodeName;
- while (node.parentNode) {
- node = node.parentNode;
- nodeName = node.nodeName;
- if (node.className && wysihtml5.lang.array(node.className.split(' ')).contains(ignoreInClasses)) {
- return true;
- }
- if (IGNORE_URLS_IN.contains(nodeName)) {
- return true;
- } else if (nodeName === "body") {
- return false;
- }
- }
- return false;
- }
-
- function _parseNode(element, ignoreInClasses) {
- if (IGNORE_URLS_IN.contains(element.nodeName)) {
- return;
- }
-
- if (element.className && wysihtml5.lang.array(element.className.split(' ')).contains(ignoreInClasses)) {
- return;
- }
-
- if (element.nodeType === wysihtml5.TEXT_NODE && element.data.match(URL_REG_EXP)) {
- _wrapMatchesInNode(element);
- return;
- }
-
- var childNodes = wysihtml5.lang.array(element.childNodes).get(),
- childNodesLength = childNodes.length,
- i = 0;
-
- for (; i 0 && (elementClassName == className || new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
- };
-})(wysihtml5);
-;wysihtml5.dom.contains = (function() {
- var documentElement = document.documentElement;
- if (documentElement.contains) {
- return function(container, element) {
- if (element.nodeType !== wysihtml5.ELEMENT_NODE) {
- if (element.parentNode === container) {
- return true;
- }
- element = element.parentNode;
- }
- return container !== element && container.contains(element);
- };
- } else if (documentElement.compareDocumentPosition) {
- return function(container, element) {
- // https://developer.mozilla.org/en/DOM/Node.compareDocumentPosition
- return !!(container.compareDocumentPosition(element) & 16);
- };
- }
-})();
-;/**
- * Converts an HTML fragment/element into a unordered/ordered list
- *
- * @param {Element} element The element which should be turned into a list
- * @param {String} listType The list type in which to convert the tree (either "ul" or "ol")
- * @return {Element} The created list
- *
- * @example
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- *
- *
- *
- *
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- *
- */
-wysihtml5.dom.convertToList = (function() {
- function _createListItem(doc, list) {
- var listItem = doc.createElement("li");
- list.appendChild(listItem);
- return listItem;
- }
-
- function _createList(doc, type) {
- return doc.createElement(type);
- }
-
- function convertToList(element, listType, uneditableClass) {
- if (element.nodeName === "UL" || element.nodeName === "OL" || element.nodeName === "MENU") {
- // Already a list
- return element;
- }
-
- var doc = element.ownerDocument,
- list = _createList(doc, listType),
- lineBreaks = element.querySelectorAll("br"),
- lineBreaksLength = lineBreaks.length,
- childNodes,
- childNodesLength,
- childNode,
- lineBreak,
- parentNode,
- isBlockElement,
- isLineBreak,
- currentListItem,
- i;
-
- // First find at the end of inline elements and move them behind them
- for (i=0; i if empty, otherwise create a new one
- currentListItem = currentListItem.firstChild ? _createListItem(doc, list) : currentListItem;
- currentListItem.appendChild(childNode);
- currentListItem = null;
- continue;
- }
-
- if (isLineBreak) {
- // Only create a new list item in the next iteration when the current one has already content
- currentListItem = currentListItem.firstChild ? null : currentListItem;
- continue;
- }
-
- currentListItem.appendChild(childNode);
- }
-
- if (childNodes.length === 0) {
- _createListItem(doc, list);
- }
-
- element.parentNode.replaceChild(list, element);
- return list;
- }
-
- return convertToList;
-})();
-;/**
- * Copy a set of attributes from one element to another
- *
- * @param {Array} attributesToCopy List of attributes which should be copied
- * @return {Object} Returns an object which offers the "from" method which can be invoked with the element where to
- * copy the attributes from., this again returns an object which provides a method named "to" which can be invoked
- * with the element where to copy the attributes to (see example)
- *
- * @example
- * var textarea = document.querySelector("textarea"),
- * div = document.querySelector("div[contenteditable=true]"),
- * anotherDiv = document.querySelector("div.preview");
- * wysihtml5.dom.copyAttributes(["spellcheck", "value", "placeholder"]).from(textarea).to(div).andTo(anotherDiv);
- *
- */
-wysihtml5.dom.copyAttributes = function(attributesToCopy) {
- return {
- from: function(elementToCopyFrom) {
- return {
- to: function(elementToCopyTo) {
- var attribute,
- i = 0,
- length = attributesToCopy.length;
- for (; i 0) {
- var hasOneStyle = false,
- styles = (Array.isArray(properties.styleProperty)) ? properties.styleProperty : [properties.styleProperty];
- for (var j = 0, maxStyleP = styles.length; j < maxStyleP; j++) {
- // Some old IE-s have different property name for cssFloat
- prop = wysihtml5.browser.fixStyleKey(styles[j]);
- if (node.style[prop]) {
- if (properties.styleValue) {
- // Style value as additional parameter
- if (properties.styleValue instanceof RegExp) {
- // style value as Regexp
- if (node.style[prop].trim().match(properties.styleValue).length > 0) {
- hasOneStyle = true;
- break;
- }
- } else if (Array.isArray(properties.styleValue)) {
- // style value as array
- if (properties.styleValue.indexOf(node.style[prop].trim())) {
- hasOneStyle = true;
- break;
- }
- } else {
- // style value as string
- if (properties.styleValue === node.style[prop].trim().replace(/, /g, ",")) {
- hasOneStyle = true;
- break;
- }
- }
- } else {
- hasOneStyle = true;
- break;
- }
- }
- if (!hasOneStyle) {
- return false;
- }
- }
- }
-
- if (properties.attribute) {
- var attr = wysihtml5.dom.getAttributes(node),
- attrList = [],
- hasOneAttribute = false;
-
- if (Array.isArray(properties.attribute)) {
- attrList = properties.attribute;
- } else {
- attrList[properties.attribute] = properties.attributeValue;
- }
-
- for (var a in attrList) {
- if (attrList.hasOwnProperty(a)) {
- if (typeof attrList[a] === "undefined") {
- if (typeof attr[a] !== "undefined") {
- hasOneAttribute = true;
- break;
- }
- } else if (attr[a] === attrList[a]) {
- hasOneAttribute = true;
- break;
- }
- }
- }
-
- if (!hasOneAttribute) {
- return false;
- }
-
- }
-
- return true;
- }
-
- };
- };
-})(wysihtml5);
-;/**
- * Returns the given html wrapped in a div element
- *
- * Fixing IE's inability to treat unknown elements (HTML5 section, article, ...) correctly
- * when inserted via innerHTML
- *
- * @param {String} html The html which should be wrapped in a dom element
- * @param {Obejct} [context] Document object of the context the html belongs to
- *
- * @example
- * wysihtml5.dom.getAsDom("foo ");
- */
-wysihtml5.dom.getAsDom = (function() {
-
- var _innerHTMLShiv = function(html, context) {
- var tempElement = context.createElement("div");
- tempElement.style.display = "none";
- context.body.appendChild(tempElement);
- // IE throws an exception when trying to insert via innerHTML
- try { tempElement.innerHTML = html; } catch(e) {}
- context.body.removeChild(tempElement);
- return tempElement;
- };
-
- /**
- * Make sure IE supports HTML5 tags, which is accomplished by simply creating one instance of each element
- */
- var _ensureHTML5Compatibility = function(context) {
- if (context._wysihtml5_supportsHTML5Tags) {
- return;
- }
- for (var i=0, length=HTML5_ELEMENTS.length; i "block"
- */
-wysihtml5.dom.getStyle = (function() {
- var stylePropertyMapping = {
- "float": ("styleFloat" in document.createElement("div").style) ? "styleFloat" : "cssFloat"
- },
- REG_EXP_CAMELIZE = /\-[a-z]/g;
-
- function camelize(str) {
- return str.replace(REG_EXP_CAMELIZE, function(match) {
- return match.charAt(1).toUpperCase();
- });
- }
-
- return function(property) {
- return {
- from: function(element) {
- if (element.nodeType !== wysihtml5.ELEMENT_NODE) {
- return;
- }
-
- var doc = element.ownerDocument,
- camelizedProperty = stylePropertyMapping[property] || camelize(property),
- style = element.style,
- currentStyle = element.currentStyle,
- styleValue = style[camelizedProperty];
- if (styleValue) {
- return styleValue;
- }
-
- // currentStyle is no standard and only supported by Opera and IE but it has one important advantage over the standard-compliant
- // window.getComputedStyle, since it returns css property values in their original unit:
- // If you set an elements width to "50%", window.getComputedStyle will give you it's current width in px while currentStyle
- // gives you the original "50%".
- // Opera supports both, currentStyle and window.getComputedStyle, that's why checking for currentStyle should have higher prio
- if (currentStyle) {
- try {
- return currentStyle[camelizedProperty];
- } catch(e) {
- //ie will occasionally fail for unknown reasons. swallowing exception
- }
- }
-
- var win = doc.defaultView || doc.parentWindow,
- needsOverflowReset = (property === "height" || property === "width") && element.nodeName === "TEXTAREA",
- originalOverflow,
- returnValue;
-
- if (win.getComputedStyle) {
- // Chrome and Safari both calculate a wrong width and height for textareas when they have scroll bars
- // therfore we remove and restore the scrollbar and calculate the value in between
- if (needsOverflowReset) {
- originalOverflow = style.overflow;
- style.overflow = "hidden";
- }
- returnValue = win.getComputedStyle(element, null).getPropertyValue(property);
- if (needsOverflowReset) {
- style.overflow = originalOverflow || "";
- }
- return returnValue;
- }
- }
- };
- };
-})();
-;wysihtml5.dom.getTextNodes = function(node, ingoreEmpty){
- var all = [];
- for (node=node.firstChild;node;node=node.nextSibling){
- if (node.nodeType == 3) {
- if (!ingoreEmpty || !(/^\s*$/).test(node.innerText || node.textContent)) {
- all.push(node);
- }
- } else {
- all = all.concat(wysihtml5.dom.getTextNodes(node, ingoreEmpty));
- }
- }
- return all;
-};
-;/**
- * High performant way to check whether an element with a specific tag name is in the given document
- * Optimized for being heavily executed
- * Unleashes the power of live node lists
- *
- * @param {Object} doc The document object of the context where to check
- * @param {String} tagName Upper cased tag name
- * @example
- * wysihtml5.dom.hasElementWithTagName(document, "IMG");
- */
-wysihtml5.dom.hasElementWithTagName = (function() {
- var LIVE_CACHE = {},
- DOCUMENT_IDENTIFIER = 1;
-
- function _getDocumentIdentifier(doc) {
- return doc._wysihtml5_identifier || (doc._wysihtml5_identifier = DOCUMENT_IDENTIFIER++);
- }
-
- return function(doc, tagName) {
- var key = _getDocumentIdentifier(doc) + ":" + tagName,
- cacheEntry = LIVE_CACHE[key];
- if (!cacheEntry) {
- cacheEntry = LIVE_CACHE[key] = doc.getElementsByTagName(tagName);
- }
-
- return cacheEntry.length > 0;
- };
-})();
-;/**
- * High performant way to check whether an element with a specific class name is in the given document
- * Optimized for being heavily executed
- * Unleashes the power of live node lists
- *
- * @param {Object} doc The document object of the context where to check
- * @param {String} tagName Upper cased tag name
- * @example
- * wysihtml5.dom.hasElementWithClassName(document, "foobar");
- */
-(function(wysihtml5) {
- var LIVE_CACHE = {},
- DOCUMENT_IDENTIFIER = 1;
-
- function _getDocumentIdentifier(doc) {
- return doc._wysihtml5_identifier || (doc._wysihtml5_identifier = DOCUMENT_IDENTIFIER++);
- }
-
- wysihtml5.dom.hasElementWithClassName = function(doc, className) {
- // getElementsByClassName is not supported by IE<9
- // but is sometimes mocked via library code (which then doesn't return live node lists)
- if (!wysihtml5.browser.supportsNativeGetElementsByClassName()) {
- return !!doc.querySelector("." + className);
- }
-
- var key = _getDocumentIdentifier(doc) + ":" + className,
- cacheEntry = LIVE_CACHE[key];
- if (!cacheEntry) {
- cacheEntry = LIVE_CACHE[key] = doc.getElementsByClassName(className);
- }
-
- return cacheEntry.length > 0;
- };
-})(wysihtml5);
-;wysihtml5.dom.insert = function(elementToInsert) {
- return {
- after: function(element) {
- element.parentNode.insertBefore(elementToInsert, element.nextSibling);
- },
-
- before: function(element) {
- element.parentNode.insertBefore(elementToInsert, element);
- },
-
- into: function(element) {
- element.appendChild(elementToInsert);
- }
- };
-};
-;wysihtml5.dom.insertCSS = function(rules) {
- rules = rules.join("\n");
-
- return {
- into: function(doc) {
- var styleElement = doc.createElement("style");
- styleElement.type = "text/css";
-
- if (styleElement.styleSheet) {
- styleElement.styleSheet.cssText = rules;
- } else {
- styleElement.appendChild(doc.createTextNode(rules));
- }
-
- var link = doc.querySelector("head link");
- if (link) {
- link.parentNode.insertBefore(styleElement, link);
- return;
- } else {
- var head = doc.querySelector("head");
- if (head) {
- head.appendChild(styleElement);
- }
- }
- }
- };
-};
-;// TODO: Refactor dom tree traversing here
-(function(wysihtml5) {
- wysihtml5.dom.lineBreaks = function(node) {
-
- function _isLineBreak(n) {
- return n.nodeName === "BR";
- }
-
- /**
- * Checks whether the elment causes a visual line break
- * ( or block elements)
- */
- function _isLineBreakOrBlockElement(element) {
- if (_isLineBreak(element)) {
- return true;
- }
-
- if (wysihtml5.dom.getStyle("display").from(element) === "block") {
- return true;
- }
-
- return false;
- }
-
- return {
-
- /* wysihtml5.dom.lineBreaks(element).add();
- *
- * Adds line breaks before and after the given node if the previous and next siblings
- * aren't already causing a visual line break (block element or )
- */
- add: function(options) {
- var doc = node.ownerDocument,
- nextSibling = wysihtml5.dom.domNode(node).next({ignoreBlankTexts: true}),
- previousSibling = wysihtml5.dom.domNode(node).prev({ignoreBlankTexts: true});
-
- if (nextSibling && !_isLineBreakOrBlockElement(nextSibling)) {
- wysihtml5.dom.insert(doc.createElement("br")).after(node);
- }
- if (previousSibling && !_isLineBreakOrBlockElement(previousSibling)) {
- wysihtml5.dom.insert(doc.createElement("br")).before(node);
- }
- },
-
- /* wysihtml5.dom.lineBreaks(element).remove();
- *
- * Removes line breaks before and after the given node
- */
- remove: function(options) {
- var nextSibling = wysihtml5.dom.domNode(node).next({ignoreBlankTexts: true}),
- previousSibling = wysihtml5.dom.domNode(node).prev({ignoreBlankTexts: true});
-
- if (nextSibling && _isLineBreak(nextSibling)) {
- nextSibling.parentNode.removeChild(nextSibling);
- }
- if (previousSibling && _isLineBreak(previousSibling)) {
- previousSibling.parentNode.removeChild(previousSibling);
- }
- }
- };
- };
-})(wysihtml5);;/**
- * Method to set dom events
- *
- * @example
- * wysihtml5.dom.observe(iframe.contentWindow.document.body, ["focus", "blur"], function() { ... });
- */
-wysihtml5.dom.observe = function(element, eventNames, handler) {
- eventNames = typeof(eventNames) === "string" ? [eventNames] : eventNames;
-
- var handlerWrapper,
- eventName,
- i = 0,
- length = eventNames.length;
-
- for (; i
- *
- * var userHTML = '';
- * wysihtml5.dom.parse(userHTML);
- * // => 'I'm a table! '
- *
- * var userHTML = 'foobar foobar
';
- * wysihtml5.dom.parse(userHTML, {
- * tags: {
- * div: undefined,
- * br: true
- * }
- * });
- * // => ''
- *
- * var userHTML = 'foo
bar
';
- * wysihtml5.dom.parse(userHTML, {
- * classes: {
- * red: 1,
- * green: 1
- * },
- * tags: {
- * div: {
- * rename_tag: "p"
- * }
- * }
- * });
- * // => 'foo
bar
'
- */
-
-wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
- /* TODO: Currently escaped module pattern as otherwise folloowing default swill be shared among multiple editors.
- * Refactor whole code as this method while workind is kind of awkward too */
-
- /**
- * It's not possible to use a XMLParser/DOMParser as HTML5 is not always well-formed XML
- * new DOMParser().parseFromString(' ') will cause a parseError since the
- * node isn't closed
- *
- * Therefore we've to use the browser's ordinary HTML parser invoked by setting innerHTML.
- */
- var NODE_TYPE_MAPPING = {
- "1": _handleElement,
- "3": _handleText,
- "8": _handleComment
- },
- // Rename unknown tags to this
- DEFAULT_NODE_NAME = "span",
- WHITE_SPACE_REG_EXP = /\s+/,
- defaultRules = { tags: {}, classes: {} },
- currentRules = {},
- blockElements = ["ADDRESS" ,"BLOCKQUOTE" ,"CENTER" ,"DIR" ,"DIV" ,"DL" ,"FIELDSET" ,
- "FORM", "H1" ,"H2" ,"H3" ,"H4" ,"H5" ,"H6" ,"ISINDEX" ,"MENU",
- "NOFRAMES", "NOSCRIPT" ,"OL" ,"P" ,"PRE","TABLE", "UL"];
-
- /**
- * Iterates over all childs of the element, recreates them, appends them into a document fragment
- * which later replaces the entire body content
- */
- function parse(elementOrHtml, config) {
- wysihtml5.lang.object(currentRules).merge(defaultRules).merge(config.rules).get();
-
- var context = config.context || elementOrHtml.ownerDocument || document,
- fragment = context.createDocumentFragment(),
- isString = typeof(elementOrHtml) === "string",
- clearInternals = false,
- element,
- newNode,
- firstChild;
-
- if (config.clearInternals === true) {
- clearInternals = true;
- }
-
- if (isString) {
- element = wysihtml5.dom.getAsDom(elementOrHtml, context);
- } else {
- element = elementOrHtml;
- }
-
- if (currentRules.selectors) {
- _applySelectorRules(element, currentRules.selectors);
- }
-
- while (element.firstChild) {
- firstChild = element.firstChild;
- newNode = _convert(firstChild, config.cleanUp, clearInternals, config.uneditableClass);
- if (newNode) {
- fragment.appendChild(newNode);
- }
- if (firstChild !== newNode) {
- element.removeChild(firstChild);
- }
- }
-
- if (config.unjoinNbsps) {
- // replace joined non-breakable spaces with unjoined
- var txtnodes = wysihtml5.dom.getTextNodes(fragment);
- for (var n = txtnodes.length; n--;) {
- txtnodes[n].nodeValue = txtnodes[n].nodeValue.replace(/([\S\u00A0])\u00A0/gi, "$1 ");
- }
- }
-
- // Clear element contents
- element.innerHTML = "";
-
- // Insert new DOM tree
- element.appendChild(fragment);
-
- return isString ? wysihtml5.quirks.getCorrectInnerHTML(element) : element;
- }
-
- function _convert(oldNode, cleanUp, clearInternals, uneditableClass) {
- var oldNodeType = oldNode.nodeType,
- oldChilds = oldNode.childNodes,
- oldChildsLength = oldChilds.length,
- method = NODE_TYPE_MAPPING[oldNodeType],
- i = 0,
- fragment,
- newNode,
- newChild,
- nodeDisplay;
-
- // Passes directly elemets with uneditable class
- if (uneditableClass && oldNodeType === 1 && wysihtml5.dom.hasClass(oldNode, uneditableClass)) {
- return oldNode;
- }
-
- newNode = method && method(oldNode, clearInternals);
-
- // Remove or unwrap node in case of return value null or false
- if (!newNode) {
- if (newNode === false) {
- // false defines that tag should be removed but contents should remain (unwrap)
- fragment = oldNode.ownerDocument.createDocumentFragment();
-
- for (i = oldChildsLength; i--;) {
- if (oldChilds[i]) {
- newChild = _convert(oldChilds[i], cleanUp, clearInternals, uneditableClass);
- if (newChild) {
- if (oldChilds[i] === newChild) {
- i--;
- }
- fragment.insertBefore(newChild, fragment.firstChild);
- }
- }
- }
-
- nodeDisplay = wysihtml5.dom.getStyle("display").from(oldNode);
-
- if (nodeDisplay === '') {
- // Handle display style when element not in dom
- nodeDisplay = wysihtml5.lang.array(blockElements).contains(oldNode.tagName) ? "block" : "";
- }
- if (wysihtml5.lang.array(["block", "flex", "table"]).contains(nodeDisplay)) {
- fragment.appendChild(oldNode.ownerDocument.createElement("br"));
- }
-
- // TODO: try to minimize surplus spaces
- if (wysihtml5.lang.array([
- "div", "pre", "p",
- "table", "td", "th",
- "ul", "ol", "li",
- "dd", "dl",
- "footer", "header", "section",
- "h1", "h2", "h3", "h4", "h5", "h6"
- ]).contains(oldNode.nodeName.toLowerCase()) && oldNode.parentNode.lastChild !== oldNode) {
- // add space at first when unwraping non-textflow elements
- if (!oldNode.nextSibling || oldNode.nextSibling.nodeType !== 3 || !(/^\s/).test(oldNode.nextSibling.nodeValue)) {
- fragment.appendChild(oldNode.ownerDocument.createTextNode(" "));
- }
- }
-
- if (fragment.normalize) {
- fragment.normalize();
- }
- return fragment;
- } else {
- // Remove
- return null;
- }
- }
-
- // Converts all childnodes
- for (i=0; i elements
- if (cleanUp &&
- newNode.nodeName.toLowerCase() === DEFAULT_NODE_NAME &&
- (!newNode.childNodes.length ||
- ((/^\s*$/gi).test(newNode.innerHTML) && (clearInternals || (oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary"))) ||
- !newNode.attributes.length)
- ) {
- fragment = newNode.ownerDocument.createDocumentFragment();
- while (newNode.firstChild) {
- fragment.appendChild(newNode.firstChild);
- }
- if (fragment.normalize) {
- fragment.normalize();
- }
- return fragment;
- }
-
- if (newNode.normalize) {
- newNode.normalize();
- }
- return newNode;
- }
-
- function _applySelectorRules (element, selectorRules) {
- var sel, method, els;
-
- for (sel in selectorRules) {
- if (selectorRules.hasOwnProperty(sel)) {
- if (wysihtml5.lang.object(selectorRules[sel]).isFunction()) {
- method = selectorRules[sel];
- } else if (typeof(selectorRules[sel]) === "string" && elementHandlingMethods[selectorRules[sel]]) {
- method = elementHandlingMethods[selectorRules[sel]];
- }
- els = element.querySelectorAll(sel);
- for (var i = els.length; i--;) {
- method(els[i]);
- }
- }
- }
- }
-
- function _handleElement(oldNode, clearInternals) {
- var rule,
- newNode,
- tagRules = currentRules.tags,
- nodeName = oldNode.nodeName.toLowerCase(),
- scopeName = oldNode.scopeName,
- renameTag;
-
- /**
- * We already parsed that element
- * ignore it! (yes, this sometimes happens in IE8 when the html is invalid)
- */
- if (oldNode._wysihtml5) {
- return null;
- }
- oldNode._wysihtml5 = 1;
-
- if (oldNode.className === "wysihtml5-temp") {
- return null;
- }
-
- /**
- * IE is the only browser who doesn't include the namespace in the
- * nodeName, that's why we have to prepend it by ourselves
- * scopeName is a proprietary IE feature
- * read more here http://msdn.microsoft.com/en-us/library/ms534388(v=vs.85).aspx
- */
- if (scopeName && scopeName != "HTML") {
- nodeName = scopeName + ":" + nodeName;
- }
- /**
- * Repair node
- * IE is a bit bitchy when it comes to invalid nested markup which includes unclosed tags
- * A doesn't need to be closed according HTML4-5 spec, we simply replace it with a
to preserve its content and layout
- */
- if ("outerHTML" in oldNode) {
- if (!wysihtml5.browser.autoClosesUnclosedTags() &&
- oldNode.nodeName === "P" &&
- oldNode.outerHTML.slice(-4).toLowerCase() !== "") {
- nodeName = "div";
- }
- }
-
- if (nodeName in tagRules) {
- rule = tagRules[nodeName];
- if (!rule || rule.remove) {
- return null;
- } else if (rule.unwrap) {
- return false;
- }
- rule = typeof(rule) === "string" ? { rename_tag: rule } : rule;
- } else if (oldNode.firstChild) {
- rule = { rename_tag: DEFAULT_NODE_NAME };
- } else {
- // Remove empty unknown elements
- return null;
- }
-
- // tests if type condition is met or node should be removed/unwrapped/renamed
- if (rule.one_of_type && !_testTypes(oldNode, currentRules, rule.one_of_type, clearInternals)) {
- if (rule.remove_action) {
- if (rule.remove_action === "unwrap") {
- return false;
- } else if (rule.remove_action === "rename") {
- renameTag = rule.remove_action_rename_to || DEFAULT_NODE_NAME;
- } else {
- return null;
- }
- } else {
- return null;
- }
- }
-
- newNode = oldNode.ownerDocument.createElement(renameTag || rule.rename_tag || nodeName);
- _handleAttributes(oldNode, newNode, rule, clearInternals);
- _handleStyles(oldNode, newNode, rule);
-
- oldNode = null;
-
- if (newNode.normalize) { newNode.normalize(); }
- return newNode;
- }
-
- function _testTypes(oldNode, rules, types, clearInternals) {
- var definition, type;
-
- // do not interfere with placeholder span or pasting caret position is not maintained
- if (oldNode.nodeName === "SPAN" && !clearInternals && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
- return true;
- }
-
- for (type in types) {
- if (types.hasOwnProperty(type) && rules.type_definitions && rules.type_definitions[type]) {
- definition = rules.type_definitions[type];
- if (_testType(oldNode, definition)) {
- return true;
- }
- }
- }
- return false;
- }
-
- function array_contains(a, obj) {
- var i = a.length;
- while (i--) {
- if (a[i] === obj) {
- return true;
- }
- }
- return false;
- }
-
- function _testType(oldNode, definition) {
-
- var nodeClasses = oldNode.getAttribute("class"),
- nodeStyles = oldNode.getAttribute("style"),
- classesLength, s, s_corrected, a, attr, currentClass, styleProp;
-
- // test for methods
- if (definition.methods) {
- for (var m in definition.methods) {
- if (definition.methods.hasOwnProperty(m) && typeCeckMethods[m]) {
-
- if (typeCeckMethods[m](oldNode)) {
- return true;
- }
- }
- }
- }
-
- // test for classes, if one found return true
- if (nodeClasses && definition.classes) {
- nodeClasses = nodeClasses.replace(/^\s+/g, '').replace(/\s+$/g, '').split(WHITE_SPACE_REG_EXP);
- classesLength = nodeClasses.length;
- for (var i = 0; i < classesLength; i++) {
- if (definition.classes[nodeClasses[i]]) {
- return true;
- }
- }
- }
-
- // test for styles, if one found return true
- if (nodeStyles && definition.styles) {
-
- nodeStyles = nodeStyles.split(';');
- for (s in definition.styles) {
- if (definition.styles.hasOwnProperty(s)) {
- for (var sp = nodeStyles.length; sp--;) {
- styleProp = nodeStyles[sp].split(':');
-
- if (styleProp[0].replace(/\s/g, '').toLowerCase() === s) {
- if (definition.styles[s] === true || definition.styles[s] === 1 || wysihtml5.lang.array(definition.styles[s]).contains(styleProp[1].replace(/\s/g, '').toLowerCase()) ) {
- return true;
- }
- }
- }
- }
- }
- }
-
- // test for attributes in general against regex match
- if (definition.attrs) {
- for (a in definition.attrs) {
- if (definition.attrs.hasOwnProperty(a)) {
- attr = wysihtml5.dom.getAttribute(oldNode, a);
- if (typeof(attr) === "string") {
- if (attr.search(definition.attrs[a]) > -1) {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
-
- function _handleStyles(oldNode, newNode, rule) {
- var s, v;
- if(rule && rule.keep_styles) {
- for (s in rule.keep_styles) {
- if (rule.keep_styles.hasOwnProperty(s)) {
- v = (s === "float") ? oldNode.style.styleFloat || oldNode.style.cssFloat : oldNode.style[s];
- // value can be regex and if so should match or style skipped
- if (rule.keep_styles[s] instanceof RegExp && !(rule.keep_styles[s].test(v))) {
- continue;
- }
- if (s === "float") {
- // IE compability
- newNode.style[(oldNode.style.styleFloat) ? 'styleFloat': 'cssFloat'] = v;
- } else if (oldNode.style[s]) {
- newNode.style[s] = v;
- }
- }
- }
- }
- };
-
- function _getAttributesBeginningWith(beginning, attributes) {
- var returnAttributes = [];
- for (var attr in attributes) {
- if (attributes.hasOwnProperty(attr) && attr.indexOf(beginning) === 0) {
- returnAttributes.push(attr);
- }
- }
- return returnAttributes;
- }
-
- function _checkAttribute(attributeName, attributeValue, methodName, nodeName) {
- var method = wysihtml5.lang.object(methodName).isFunction() ? methodName : attributeCheckMethods[methodName],
- newAttributeValue;
-
- if (method) {
- newAttributeValue = method(attributeValue, nodeName);
- if (typeof(newAttributeValue) === "string") {
- return newAttributeValue;
- }
- }
-
- return false;
- }
-
- function _checkAttributes(oldNode, local_attributes) {
- var globalAttributes = wysihtml5.lang.object(currentRules.attributes || {}).clone(), // global values for check/convert values of attributes
- checkAttributes = wysihtml5.lang.object(globalAttributes).merge( wysihtml5.lang.object(local_attributes || {}).clone()).get(),
- attributes = {},
- oldAttributes = wysihtml5.dom.getAttributes(oldNode),
- attributeName, newValue, matchingAttributes;
-
- for (attributeName in checkAttributes) {
- if ((/\*$/).test(attributeName)) {
-
- matchingAttributes = _getAttributesBeginningWith(attributeName.slice(0,-1), oldAttributes);
- for (var i = 0, imax = matchingAttributes.length; i < imax; i++) {
-
- newValue = _checkAttribute(matchingAttributes[i], oldAttributes[matchingAttributes[i]], checkAttributes[attributeName], oldNode.nodeName);
- if (newValue !== false) {
- attributes[matchingAttributes[i]] = newValue;
- }
- }
- } else {
- newValue = _checkAttribute(attributeName, oldAttributes[attributeName], checkAttributes[attributeName], oldNode.nodeName);
- if (newValue !== false) {
- attributes[attributeName] = newValue;
- }
- }
- }
-
- return attributes;
- }
-
- // TODO: refactor. Too long to read
- function _handleAttributes(oldNode, newNode, rule, clearInternals) {
- var attributes = {}, // fresh new set of attributes to set on newNode
- setClass = rule.set_class, // classes to set
- addClass = rule.add_class, // add classes based on existing attributes
- addStyle = rule.add_style, // add styles based on existing attributes
- setAttributes = rule.set_attributes, // attributes to set on the current node
- allowedClasses = currentRules.classes,
- i = 0,
- classes = [],
- styles = [],
- newClasses = [],
- oldClasses = [],
- classesLength,
- newClassesLength,
- currentClass,
- newClass,
- attributeName,
- method;
-
- if (setAttributes) {
- attributes = wysihtml5.lang.object(setAttributes).clone();
- }
-
- // check/convert values of attributes
- attributes = wysihtml5.lang.object(attributes).merge(_checkAttributes(oldNode, rule.check_attributes)).get();
-
- if (setClass) {
- classes.push(setClass);
- }
-
- if (addClass) {
- for (attributeName in addClass) {
- method = addClassMethods[addClass[attributeName]];
- if (!method) {
- continue;
- }
- newClass = method(wysihtml5.dom.getAttribute(oldNode, attributeName));
- if (typeof(newClass) === "string") {
- classes.push(newClass);
- }
- }
- }
-
- if (addStyle) {
- for (attributeName in addStyle) {
- method = addStyleMethods[addStyle[attributeName]];
- if (!method) {
- continue;
- }
-
- newStyle = method(wysihtml5.dom.getAttribute(oldNode, attributeName));
- if (typeof(newStyle) === "string") {
- styles.push(newStyle);
- }
- }
- }
-
-
- if (typeof(allowedClasses) === "string" && allowedClasses === "any") {
- if (oldNode.getAttribute("class")) {
- if (currentRules.classes_blacklist) {
- oldClasses = oldNode.getAttribute("class");
- if (oldClasses) {
- classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
- }
-
- classesLength = classes.length;
- for (; i
0) {
- attributes["class"] = wysihtml5.lang.array(classes).unique().join(" ");
- }
- }
- } else {
- // make sure that wysihtml5 temp class doesn't get stripped out
- if (!clearInternals) {
- allowedClasses["_wysihtml5-temp-placeholder"] = 1;
- allowedClasses["_rangySelectionBoundary"] = 1;
- allowedClasses["wysiwyg-tmp-selected-cell"] = 1;
- }
-
- // add old classes last
- oldClasses = oldNode.getAttribute("class");
- if (oldClasses) {
- classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
- }
- classesLength = classes.length;
- for (; i under https when it's new attribute value is non-https
- // TODO: Investigate this further and check for smarter handling
- try {
- newNode.setAttribute(attributeName, attributes[attributeName]);
- } catch(e) {}
- }
-
- // IE8 sometimes loses the width/height attributes when those are set before the "src"
- // so we make sure to set them again
- if (attributes.src) {
- if (typeof(attributes.width) !== "undefined") {
- newNode.setAttribute("width", attributes.width);
- }
- if (typeof(attributes.height) !== "undefined") {
- newNode.setAttribute("height", attributes.height);
- }
- }
- }
-
- function _handleText(oldNode) {
- var nextSibling = oldNode.nextSibling;
- if (nextSibling && nextSibling.nodeType === wysihtml5.TEXT_NODE) {
- // Concatenate text nodes
- nextSibling.data = oldNode.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "") + nextSibling.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
- } else {
- // \uFEFF = wysihtml5.INVISIBLE_SPACE (used as a hack in certain rich text editing situations)
- var data = oldNode.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
- return oldNode.ownerDocument.createTextNode(data);
- }
- }
-
- function _handleComment(oldNode) {
- if (currentRules.comments) {
- return oldNode.ownerDocument.createComment(oldNode.nodeValue);
- }
- }
-
- // ------------ attribute checks ------------ \\
- var attributeCheckMethods = {
- url: (function() {
- var REG_EXP = /^https?:\/\//i;
- return function(attributeValue) {
- if (!attributeValue || !attributeValue.match(REG_EXP)) {
- return null;
- }
- return attributeValue.replace(REG_EXP, function(match) {
- return match.toLowerCase();
- });
- };
- })(),
-
- src: (function() {
- var REG_EXP = /^(\/|https?:\/\/)/i;
- return function(attributeValue) {
- if (!attributeValue || !attributeValue.match(REG_EXP)) {
- return null;
- }
- return attributeValue.replace(REG_EXP, function(match) {
- return match.toLowerCase();
- });
- };
- })(),
-
- href: (function() {
- var REG_EXP = /^(#|\/|https?:\/\/|mailto:|tel:)/i;
- return function(attributeValue) {
- if (!attributeValue || !attributeValue.match(REG_EXP)) {
- return null;
- }
- return attributeValue.replace(REG_EXP, function(match) {
- return match.toLowerCase();
- });
- };
- })(),
-
- alt: (function() {
- var REG_EXP = /[^ a-z0-9_\-]/gi;
- return function(attributeValue, nodeName) {
- if (!attributeValue) {
- if (nodeName === "IMG") {
- return "";
- } else {
- return null;
- }
- }
- return attributeValue.replace(REG_EXP, "");
- };
- })(),
-
- // Integers. Does not work with floating point numbers and units
- numbers: (function() {
- var REG_EXP = /\D/g;
- return function(attributeValue) {
- attributeValue = (attributeValue || "").replace(REG_EXP, "");
- return attributeValue || null;
- };
- })(),
-
- // Useful for with/height attributes where floating points and percentages are allowed
- dimension: (function() {
- var REG_EXP = /\D*(\d+)(\.\d+)?\s?(%)?\D*/;
- return function(attributeValue) {
- attributeValue = (attributeValue || "").replace(REG_EXP, "$1$2$3");
- return attributeValue || null;
- };
- })(),
-
- any: (function() {
- return function(attributeValue) {
- if (!attributeValue) {
- return null;
- }
- return attributeValue;
- };
- })()
- };
-
- // ------------ style converter (converts an html attribute to a style) ------------ \\
- var addStyleMethods = {
- align_text: (function() {
- var mapping = {
- left: "text-align: left;",
- right: "text-align: right;",
- center: "text-align: center;"
- };
- return function(attributeValue) {
- return mapping[String(attributeValue).toLowerCase()];
- };
- })(),
- };
-
- // ------------ class converter (converts an html attribute to a class name) ------------ \\
- var addClassMethods = {
- align_img: (function() {
- var mapping = {
- left: "wysiwyg-float-left",
- right: "wysiwyg-float-right"
- };
- return function(attributeValue) {
- return mapping[String(attributeValue).toLowerCase()];
- };
- })(),
-
- align_text: (function() {
- var mapping = {
- left: "wysiwyg-text-align-left",
- right: "wysiwyg-text-align-right",
- center: "wysiwyg-text-align-center",
- justify: "wysiwyg-text-align-justify"
- };
- return function(attributeValue) {
- return mapping[String(attributeValue).toLowerCase()];
- };
- })(),
-
- clear_br: (function() {
- var mapping = {
- left: "wysiwyg-clear-left",
- right: "wysiwyg-clear-right",
- both: "wysiwyg-clear-both",
- all: "wysiwyg-clear-both"
- };
- return function(attributeValue) {
- return mapping[String(attributeValue).toLowerCase()];
- };
- })(),
-
- size_font: (function() {
- var mapping = {
- "1": "wysiwyg-font-size-xx-small",
- "2": "wysiwyg-font-size-small",
- "3": "wysiwyg-font-size-medium",
- "4": "wysiwyg-font-size-large",
- "5": "wysiwyg-font-size-x-large",
- "6": "wysiwyg-font-size-xx-large",
- "7": "wysiwyg-font-size-xx-large",
- "-": "wysiwyg-font-size-smaller",
- "+": "wysiwyg-font-size-larger"
- };
- return function(attributeValue) {
- return mapping[String(attributeValue).charAt(0)];
- };
- })()
- };
-
- // checks if element is possibly visible
- var typeCeckMethods = {
- has_visible_contet: (function() {
- var txt,
- isVisible = false,
- visibleElements = ['img', 'video', 'picture', 'br', 'script', 'noscript',
- 'style', 'table', 'iframe', 'object', 'embed', 'audio',
- 'svg', 'input', 'button', 'select','textarea', 'canvas'];
-
- return function(el) {
-
- // has visible innertext. so is visible
- txt = (el.innerText || el.textContent).replace(/\s/g, '');
- if (txt && txt.length > 0) {
- return true;
- }
-
- // matches list of visible dimensioned elements
- for (var i = visibleElements.length; i--;) {
- if (el.querySelector(visibleElements[i])) {
- return true;
- }
- }
-
- // try to measure dimesions in last resort. (can find only of elements in dom)
- if (el.offsetWidth && el.offsetWidth > 0 && el.offsetHeight && el.offsetHeight > 0) {
- return true;
- }
-
- return false;
- };
- })()
- };
-
- var elementHandlingMethods = {
- unwrap: function (element) {
- wysihtml5.dom.unwrap(element);
- },
-
- remove: function (element) {
- element.parentNode.removeChild(element);
- }
- };
-
- return parse(elementOrHtml_current, config_current);
-};
-;/**
- * Checks for empty text node childs and removes them
- *
- * @param {Element} node The element in which to cleanup
- * @example
- * wysihtml5.dom.removeEmptyTextNodes(element);
- */
-wysihtml5.dom.removeEmptyTextNodes = function(node) {
- var childNode,
- childNodes = wysihtml5.lang.array(node.childNodes).get(),
- childNodesLength = childNodes.length,
- i = 0;
-
- for (; i to a ) and keeps its childs
- *
- * @param {Element} element The list element which should be renamed
- * @param {Element} newNodeName The desired tag name
- *
- * @example
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- *
- *
- *
- *
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- *
- */
-wysihtml5.dom.renameElement = function(element, newNodeName) {
- var newElement = element.ownerDocument.createElement(newNodeName),
- firstChild;
- while (firstChild = element.firstChild) {
- newElement.appendChild(firstChild);
- }
- wysihtml5.dom.copyAttributes(["align", "className"]).from(element).to(newElement);
-
- if (element.parentNode) {
- element.parentNode.replaceChild(newElement, element);
- }
-
- return newElement;
-};
-;/**
- * Takes an element, removes it and replaces it with it's childs
- *
- * @param {Object} node The node which to replace with it's child nodes
- * @example
- *
- * hello
- *
- *
- */
-wysihtml5.dom.replaceWithChildNodes = function(node) {
- if (!node.parentNode) {
- return;
- }
-
- while (node.firstChild) {
- node.parentNode.insertBefore(node.firstChild, node);
- }
- node.parentNode.removeChild(node);
-};
-;/**
- * Unwraps an unordered/ordered list
- *
- * @param {Element} element The list element which should be unwrapped
- *
- * @example
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- *
- *
- *
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- */
-(function(dom) {
- function _isBlockElement(node) {
- return dom.getStyle("display").from(node) === "block";
- }
-
- function _isLineBreak(node) {
- return node.nodeName === "BR";
- }
-
- function _appendLineBreak(element) {
- var lineBreak = element.ownerDocument.createElement("br");
- element.appendChild(lineBreak);
- }
-
- function resolveList(list, useLineBreaks) {
- if (!list.nodeName.match(/^(MENU|UL|OL)$/)) {
- return;
- }
-
- var doc = list.ownerDocument,
- fragment = doc.createDocumentFragment(),
- previousSibling = wysihtml5.dom.domNode(list).prev({ignoreBlankTexts: true}),
- nextSibling = wysihtml5.dom.domNode(list).next({ignoreBlankTexts: true}),
- firstChild,
- lastChild,
- isLastChild,
- shouldAppendLineBreak,
- paragraph,
- listItem,
- lastListItem = list.lastElementChild || list.lastChild,
- isLastItem;
-
- if (useLineBreaks) {
- // Insert line break if list is after a non-block element
- if (previousSibling && !_isBlockElement(previousSibling) && !_isLineBreak(previousSibling)) {
- _appendLineBreak(fragment);
- }
-
- while (listItem = (list.firstElementChild || list.firstChild)) {
- lastChild = listItem.lastChild;
- isLastItem = listItem === lastListItem;
- while (firstChild = listItem.firstChild) {
- isLastChild = firstChild === lastChild;
- // This needs to be done before appending it to the fragment, as it otherwise will lose style information
- shouldAppendLineBreak = (!isLastItem || (nextSibling && !_isBlockElement(nextSibling))) && isLastChild && !_isBlockElement(firstChild) && !_isLineBreak(firstChild);
- fragment.appendChild(firstChild);
- if (shouldAppendLineBreak) {
- _appendLineBreak(fragment);
- }
- }
-
- listItem.parentNode.removeChild(listItem);
- }
- } else {
- while (listItem = (list.firstElementChild || list.firstChild)) {
- if (listItem.querySelector && listItem.querySelector("div, p, ul, ol, menu, blockquote, h1, h2, h3, h4, h5, h6")) {
- while (firstChild = listItem.firstChild) {
- fragment.appendChild(firstChild);
- }
- } else {
- paragraph = doc.createElement("p");
- while (firstChild = listItem.firstChild) {
- paragraph.appendChild(firstChild);
- }
- fragment.appendChild(paragraph);
- }
- listItem.parentNode.removeChild(listItem);
- }
- }
-
- list.parentNode.replaceChild(fragment, list);
- }
-
- dom.resolveList = resolveList;
-})(wysihtml5.dom);
-;/**
- * Sandbox for executing javascript, parsing css styles and doing dom operations in a secure way
- *
- * Browser Compatibility:
- * - Secure in MSIE 6+, but only when the user hasn't made changes to his security level "restricted"
- * - Partially secure in other browsers (Firefox, Opera, Safari, Chrome, ...)
- *
- * Please note that this class can't benefit from the HTML5 sandbox attribute for the following reasons:
- * - sandboxing doesn't work correctly with inlined content (src="javascript:'...'")
- * - sandboxing of physical documents causes that the dom isn't accessible anymore from the outside (iframe.contentWindow, ...)
- * - setting the "allow-same-origin" flag would fix that, but then still javascript and dom events refuse to fire
- * - therefore the "allow-scripts" flag is needed, which then would deactivate any security, as the js executed inside the iframe
- * can do anything as if the sandbox attribute wasn't set
- *
- * @param {Function} [readyCallback] Method that gets invoked when the sandbox is ready
- * @param {Object} [config] Optional parameters
- *
- * @example
- * new wysihtml5.dom.Sandbox(function(sandbox) {
- * sandbox.getWindow().document.body.innerHTML = ' ';
- * });
- */
-(function(wysihtml5) {
- var /**
- * Default configuration
- */
- doc = document,
- /**
- * Properties to unset/protect on the window object
- */
- windowProperties = [
- "parent", "top", "opener", "frameElement", "frames",
- "localStorage", "globalStorage", "sessionStorage", "indexedDB"
- ],
- /**
- * Properties on the window object which are set to an empty function
- */
- windowProperties2 = [
- "open", "close", "openDialog", "showModalDialog",
- "alert", "confirm", "prompt",
- "openDatabase", "postMessage",
- "XMLHttpRequest", "XDomainRequest"
- ],
- /**
- * Properties to unset/protect on the document object
- */
- documentProperties = [
- "referrer",
- "write", "open", "close"
- ];
-
- wysihtml5.dom.Sandbox = Base.extend(
- /** @scope wysihtml5.dom.Sandbox.prototype */ {
-
- constructor: function(readyCallback, config) {
- this.callback = readyCallback || wysihtml5.EMPTY_FUNCTION;
- this.config = wysihtml5.lang.object({}).merge(config).get();
- if (!this.config.className) {
- this.config.className = "wysihtml5-sandbox";
- }
- this.editableArea = this._createIframe();
- },
-
- insertInto: function(element) {
- if (typeof(element) === "string") {
- element = doc.getElementById(element);
- }
-
- element.appendChild(this.editableArea);
- },
-
- getIframe: function() {
- return this.editableArea;
- },
-
- getWindow: function() {
- this._readyError();
- },
-
- getDocument: function() {
- this._readyError();
- },
-
- destroy: function() {
- var iframe = this.getIframe();
- iframe.parentNode.removeChild(iframe);
- },
-
- _readyError: function() {
- throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet");
- },
-
- /**
- * Creates the sandbox iframe
- *
- * Some important notes:
- * - We can't use HTML5 sandbox for now:
- * setting it causes that the iframe's dom can't be accessed from the outside
- * Therefore we need to set the "allow-same-origin" flag which enables accessing the iframe's dom
- * But then there's another problem, DOM events (focus, blur, change, keypress, ...) aren't fired.
- * In order to make this happen we need to set the "allow-scripts" flag.
- * A combination of allow-scripts and allow-same-origin is almost the same as setting no sandbox attribute at all.
- * - Chrome & Safari, doesn't seem to support sandboxing correctly when the iframe's html is inlined (no physical document)
- * - IE needs to have the security="restricted" attribute set before the iframe is
- * inserted into the dom tree
- * - Believe it or not but in IE "security" in document.createElement("iframe") is false, even
- * though it supports it
- * - When an iframe has security="restricted", in IE eval() & execScript() don't work anymore
- * - IE doesn't fire the onload event when the content is inlined in the src attribute, therefore we rely
- * on the onreadystatechange event
- */
- _createIframe: function() {
- var that = this,
- iframe = doc.createElement("iframe");
- iframe.className = this.config.className;
- wysihtml5.dom.setAttributes({
- "security": "restricted",
- "allowtransparency": "true",
- "frameborder": 0,
- "width": 0,
- "height": 0,
- "marginwidth": 0,
- "marginheight": 0
- }).on(iframe);
-
- // Setting the src like this prevents ssl warnings in IE6
- if (wysihtml5.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()) {
- iframe.src = "javascript:''";
- }
-
- iframe.onload = function() {
- iframe.onreadystatechange = iframe.onload = null;
- that._onLoadIframe(iframe);
- };
-
- iframe.onreadystatechange = function() {
- if (/loaded|complete/.test(iframe.readyState)) {
- iframe.onreadystatechange = iframe.onload = null;
- that._onLoadIframe(iframe);
- }
- };
-
- return iframe;
- },
-
- /**
- * Callback for when the iframe has finished loading
- */
- _onLoadIframe: function(iframe) {
- // don't resume when the iframe got unloaded (eg. by removing it from the dom)
- if (!wysihtml5.dom.contains(doc.documentElement, iframe)) {
- return;
- }
-
- var that = this,
- iframeWindow = iframe.contentWindow,
- iframeDocument = iframe.contentWindow.document,
- charset = doc.characterSet || doc.charset || "utf-8",
- sandboxHtml = this._getHtml({
- charset: charset,
- stylesheets: this.config.stylesheets
- });
-
- // Create the basic dom tree including proper DOCTYPE and charset
- iframeDocument.open("text/html", "replace");
- iframeDocument.write(sandboxHtml);
- iframeDocument.close();
-
- this.getWindow = function() { return iframe.contentWindow; };
- this.getDocument = function() { return iframe.contentWindow.document; };
-
- // Catch js errors and pass them to the parent's onerror event
- // addEventListener("error") doesn't work properly in some browsers
- // TODO: apparently this doesn't work in IE9!
- iframeWindow.onerror = function(errorMessage, fileName, lineNumber) {
- throw new Error("wysihtml5.Sandbox: " + errorMessage, fileName, lineNumber);
- };
-
- if (!wysihtml5.browser.supportsSandboxedIframes()) {
- // Unset a bunch of sensitive variables
- // Please note: This isn't hack safe!
- // It more or less just takes care of basic attacks and prevents accidental theft of sensitive information
- // IE is secure though, which is the most important thing, since IE is the only browser, who
- // takes over scripts & styles into contentEditable elements when copied from external websites
- // or applications (Microsoft Word, ...)
- var i, length;
- for (i=0, length=windowProperties.length; i';
- }
- }
- templateVars.stylesheets = html;
-
- return wysihtml5.lang.string(
- ''
- + ' #{stylesheets}'
- + ''
- ).interpolate(templateVars);
- },
-
- /**
- * Method to unset/override existing variables
- * @example
- * // Make cookie unreadable and unwritable
- * this._unset(document, "cookie", "", true);
- */
- _unset: function(object, property, value, setter) {
- try { object[property] = value; } catch(e) {}
-
- try { object.__defineGetter__(property, function() { return value; }); } catch(e) {}
- if (setter) {
- try { object.__defineSetter__(property, function() {}); } catch(e) {}
- }
-
- if (!wysihtml5.browser.crashesWhenDefineProperty(property)) {
- try {
- var config = {
- get: function() { return value; }
- };
- if (setter) {
- config.set = function() {};
- }
- Object.defineProperty(object, property, config);
- } catch(e) {}
- }
- }
- });
-})(wysihtml5);
-;(function(wysihtml5) {
- var doc = document;
- wysihtml5.dom.ContentEditableArea = Base.extend({
- getContentEditable: function() {
- return this.element;
- },
-
- getWindow: function() {
- return this.element.ownerDocument.defaultView || this.element.ownerDocument.parentWindow;
- },
-
- getDocument: function() {
- return this.element.ownerDocument;
- },
-
- constructor: function(readyCallback, config, contentEditable) {
- this.callback = readyCallback || wysihtml5.EMPTY_FUNCTION;
- this.config = wysihtml5.lang.object({}).merge(config).get();
- if (!this.config.className) {
- this.config.className = "wysihtml5-sandbox";
- }
- if (contentEditable) {
- this.element = this._bindElement(contentEditable);
- } else {
- this.element = this._createElement();
- }
- },
-
- destroy: function() {
-
- },
-
- // creates a new contenteditable and initiates it
- _createElement: function() {
- var element = doc.createElement("div");
- element.className = this.config.className;
- this._loadElement(element);
- return element;
- },
-
- // initiates an allready existent contenteditable
- _bindElement: function(contentEditable) {
- contentEditable.className = contentEditable.className ? contentEditable.className + " wysihtml5-sandbox" : "wysihtml5-sandbox";
- this._loadElement(contentEditable, true);
- return contentEditable;
- },
-
- _loadElement: function(element, contentExists) {
- var that = this;
-
- if (!contentExists) {
- var innerHtml = this._getHtml();
- element.innerHTML = innerHtml;
- }
-
- this.loaded = true;
- // Trigger the callback
- setTimeout(function() { that.callback(that); }, 0);
- },
-
- _getHtml: function(templateVars) {
- return '';
- }
-
- });
-})(wysihtml5);
-;(function() {
- var mapping = {
- "className": "class"
- };
- wysihtml5.dom.setAttributes = function(attributes) {
- return {
- on: function(element) {
- for (var i in attributes) {
- element.setAttribute(mapping[i] || i, attributes[i]);
- }
- }
- };
- };
-})();
-;wysihtml5.dom.setStyles = function(styles) {
- return {
- on: function(element) {
- var style = element.style;
- if (typeof(styles) === "string") {
- style.cssText += ";" + styles;
- return;
- }
- for (var i in styles) {
- if (i === "float") {
- style.cssFloat = styles[i];
- style.styleFloat = styles[i];
- } else {
- style[i] = styles[i];
- }
- }
- }
- };
-};
-;/**
- * Simulate HTML5 placeholder attribute
- *
- * Needed since
- * - div[contentEditable] elements don't support it
- * - older browsers (such as IE8 and Firefox 3.6) don't support it at all
- *
- * @param {Object} parent Instance of main wysihtml5.Editor class
- * @param {Element} view Instance of wysihtml5.views.* class
- * @param {String} placeholderText
- *
- * @example
- * wysihtml.dom.simulatePlaceholder(this, composer, "Foobar");
- */
-(function(dom) {
- dom.simulatePlaceholder = function(editor, view, placeholderText, placeholderClassName) {
- var CLASS_NAME = placeholderClassName || "wysihtml5-placeholder",
- unset = function() {
- var composerIsVisible = view.element.offsetWidth > 0 && view.element.offsetHeight > 0;
- if (view.hasPlaceholderSet()) {
- view.clear();
- view.element.focus();
- if (composerIsVisible ) {
- setTimeout(function() {
- var sel = view.selection.getSelection();
- if (!sel.focusNode || !sel.anchorNode) {
- view.selection.selectNode(view.element.firstChild || view.element);
- }
- }, 0);
- }
- }
- view.placeholderSet = false;
- dom.removeClass(view.element, CLASS_NAME);
- },
- set = function() {
- if (view.isEmpty() && !view.placeholderSet) {
- view.placeholderSet = true;
- view.setValue(placeholderText, false);
- dom.addClass(view.element, CLASS_NAME);
- }
- };
-
- editor
- .on("set_placeholder", set)
- .on("unset_placeholder", unset)
- .on("focus:composer", unset)
- .on("paste:composer", unset)
- .on("blur:composer", set);
-
- set();
- };
-})(wysihtml5.dom);
-;(function(dom) {
- var documentElement = document.documentElement;
- if ("textContent" in documentElement) {
- dom.setTextContent = function(element, text) {
- element.textContent = text;
- };
-
- dom.getTextContent = function(element) {
- return element.textContent;
- };
- } else if ("innerText" in documentElement) {
- dom.setTextContent = function(element, text) {
- element.innerText = text;
- };
-
- dom.getTextContent = function(element) {
- return element.innerText;
- };
- } else {
- dom.setTextContent = function(element, text) {
- element.nodeValue = text;
- };
-
- dom.getTextContent = function(element) {
- return element.nodeValue;
- };
- }
-})(wysihtml5.dom);
-;/**
- * Get a set of attribute from one element
- *
- * IE gives wrong results for hasAttribute/getAttribute, for example:
- * var td = document.createElement("td");
- * td.getAttribute("rowspan"); // => "1" in IE
- *
- * Therefore we have to check the element's outerHTML for the attribute
-*/
-
-wysihtml5.dom.getAttribute = function(node, attributeName) {
- var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly();
- attributeName = attributeName.toLowerCase();
- var nodeName = node.nodeName;
- if (nodeName == "IMG" && attributeName == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
- // Get 'src' attribute value via object property since this will always contain the
- // full absolute url (http://...)
- // this fixes a very annoying bug in firefox (ver 3.6 & 4) and IE 8 where images copied from the same host
- // will have relative paths, which the sanitizer strips out (see attributeCheckMethods.url)
- return node.src;
- } else if (HAS_GET_ATTRIBUTE_BUG && "outerHTML" in node) {
- // Don't trust getAttribute/hasAttribute in IE 6-8, instead check the element's outerHTML
- var outerHTML = node.outerHTML.toLowerCase(),
- // TODO: This might not work for attributes without value:
- hasAttribute = outerHTML.indexOf(" " + attributeName + "=") != -1;
-
- return hasAttribute ? node.getAttribute(attributeName) : null;
- } else{
- return node.getAttribute(attributeName);
- }
-};
-;/**
- * Get all attributes of an element
- *
- * IE gives wrong results for hasAttribute/getAttribute, for example:
- * var td = document.createElement("td");
- * td.getAttribute("rowspan"); // => "1" in IE
- *
- * Therefore we have to check the element's outerHTML for the attribute
-*/
-
-wysihtml5.dom.getAttributes = function(node) {
- var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly(),
- nodeName = node.nodeName,
- attributes = [],
- attr;
-
- for (attr in node.attributes) {
- if ((node.attributes.hasOwnProperty && node.attributes.hasOwnProperty(attr)) || (!node.attributes.hasOwnProperty && Object.prototype.hasOwnProperty.call(node.attributes, attr))) {
- if (node.attributes[attr].specified) {
- if (nodeName == "IMG" && node.attributes[attr].name.toLowerCase() == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
- attributes['src'] = node.src;
- } else if (wysihtml5.lang.array(['rowspan', 'colspan']).contains(node.attributes[attr].name.toLowerCase()) && HAS_GET_ATTRIBUTE_BUG) {
- if (node.attributes[attr].value !== 1) {
- attributes[node.attributes[attr].name] = node.attributes[attr].value;
- }
- } else {
- attributes[node.attributes[attr].name] = node.attributes[attr].value;
- }
- }
- }
- }
- return attributes;
-};
-;/**
- * Check whether the given node is a proper loaded image
- * FIXME: Returns undefined when unknown (Chrome, Safari)
-*/
-
-wysihtml5.dom.isLoadedImage = function (node) {
- try {
- return node.complete && !node.mozMatchesSelector(":-moz-broken");
- } catch(e) {
- if (node.complete && node.readyState === "complete") {
- return true;
- }
- }
-};
-;(function(wysihtml5) {
-
- var api = wysihtml5.dom;
-
- var MapCell = function(cell) {
- this.el = cell;
- this.isColspan= false;
- this.isRowspan= false;
- this.firstCol= true;
- this.lastCol= true;
- this.firstRow= true;
- this.lastRow= true;
- this.isReal= true;
- this.spanCollection= [];
- this.modified = false;
- };
-
- var TableModifyerByCell = function (cell, table) {
- if (cell) {
- this.cell = cell;
- this.table = api.getParentElement(cell, { query: "table" });
- } else if (table) {
- this.table = table;
- this.cell = this.table.querySelectorAll('th, td')[0];
- }
- };
-
- function queryInList(list, query) {
- var ret = [],
- q;
- for (var e = 0, len = list.length; e < len; e++) {
- q = list[e].querySelectorAll(query);
- if (q) {
- for(var i = q.length; i--; ret.unshift(q[i]));
- }
- }
- return ret;
- }
-
- function removeElement(el) {
- el.parentNode.removeChild(el);
- }
-
- function insertAfter(referenceNode, newNode) {
- referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
- }
-
- function nextNode(node, tag) {
- var element = node.nextSibling;
- while (element.nodeType !=1) {
- element = element.nextSibling;
- if (!tag || tag == element.tagName.toLowerCase()) {
- return element;
- }
- }
- return null;
- }
-
- TableModifyerByCell.prototype = {
-
- addSpannedCellToMap: function(cell, map, r, c, cspan, rspan) {
- var spanCollect = [],
- rmax = r + ((rspan) ? parseInt(rspan, 10) - 1 : 0),
- cmax = c + ((cspan) ? parseInt(cspan, 10) - 1 : 0);
-
- for (var rr = r; rr <= rmax; rr++) {
- if (typeof map[rr] == "undefined") { map[rr] = []; }
- for (var cc = c; cc <= cmax; cc++) {
- map[rr][cc] = new MapCell(cell);
- map[rr][cc].isColspan = (cspan && parseInt(cspan, 10) > 1);
- map[rr][cc].isRowspan = (rspan && parseInt(rspan, 10) > 1);
- map[rr][cc].firstCol = cc == c;
- map[rr][cc].lastCol = cc == cmax;
- map[rr][cc].firstRow = rr == r;
- map[rr][cc].lastRow = rr == rmax;
- map[rr][cc].isReal = cc == c && rr == r;
- map[rr][cc].spanCollection = spanCollect;
-
- spanCollect.push(map[rr][cc]);
- }
- }
- },
-
- setCellAsModified: function(cell) {
- cell.modified = true;
- if (cell.spanCollection.length > 0) {
- for (var s = 0, smax = cell.spanCollection.length; s < smax; s++) {
- cell.spanCollection[s].modified = true;
- }
- }
- },
-
- setTableMap: function() {
- var map = [];
- var tableRows = this.getTableRows(),
- ridx, row, cells, cidx, cell,
- c,
- cspan, rspan;
-
- for (ridx = 0; ridx < tableRows.length; ridx++) {
- row = tableRows[ridx];
- cells = this.getRowCells(row);
- c = 0;
- if (typeof map[ridx] == "undefined") { map[ridx] = []; }
- for (cidx = 0; cidx < cells.length; cidx++) {
- cell = cells[cidx];
-
- // If cell allready set means it is set by col or rowspan,
- // so increase cols index until free col is found
- while (typeof map[ridx][c] != "undefined") { c++; }
-
- cspan = api.getAttribute(cell, 'colspan');
- rspan = api.getAttribute(cell, 'rowspan');
-
- if (cspan || rspan) {
- this.addSpannedCellToMap(cell, map, ridx, c, cspan, rspan);
- c = c + ((cspan) ? parseInt(cspan, 10) : 1);
- } else {
- map[ridx][c] = new MapCell(cell);
- c++;
- }
- }
- }
- this.map = map;
- return map;
- },
-
- getRowCells: function(row) {
- var inlineTables = this.table.querySelectorAll('table'),
- inlineCells = (inlineTables) ? queryInList(inlineTables, 'th, td') : [],
- allCells = row.querySelectorAll('th, td'),
- tableCells = (inlineCells.length > 0) ? wysihtml5.lang.array(allCells).without(inlineCells) : allCells;
-
- return tableCells;
- },
-
- getTableRows: function() {
- var inlineTables = this.table.querySelectorAll('table'),
- inlineRows = (inlineTables) ? queryInList(inlineTables, 'tr') : [],
- allRows = this.table.querySelectorAll('tr'),
- tableRows = (inlineRows.length > 0) ? wysihtml5.lang.array(allRows).without(inlineRows) : allRows;
-
- return tableRows;
- },
-
- getMapIndex: function(cell) {
- var r_length = this.map.length,
- c_length = (this.map && this.map[0]) ? this.map[0].length : 0;
-
- for (var r_idx = 0;r_idx < r_length; r_idx++) {
- for (var c_idx = 0;c_idx < c_length; c_idx++) {
- if (this.map[r_idx][c_idx].el === cell) {
- return {'row': r_idx, 'col': c_idx};
- }
- }
- }
- return false;
- },
-
- getElementAtIndex: function(idx) {
- this.setTableMap();
- if (this.map[idx.row] && this.map[idx.row][idx.col] && this.map[idx.row][idx.col].el) {
- return this.map[idx.row][idx.col].el;
- }
- return null;
- },
-
- getMapElsTo: function(to_cell) {
- var els = [];
- this.setTableMap();
- this.idx_start = this.getMapIndex(this.cell);
- this.idx_end = this.getMapIndex(to_cell);
-
- // switch indexes if start is bigger than end
- if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
- var temp_idx = this.idx_start;
- this.idx_start = this.idx_end;
- this.idx_end = temp_idx;
- }
- if (this.idx_start.col > this.idx_end.col) {
- var temp_cidx = this.idx_start.col;
- this.idx_start.col = this.idx_end.col;
- this.idx_end.col = temp_cidx;
- }
-
- if (this.idx_start != null && this.idx_end != null) {
- for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
- for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
- els.push(this.map[row][col].el);
- }
- }
- }
- return els;
- },
-
- orderSelectionEnds: function(secondcell) {
- this.setTableMap();
- this.idx_start = this.getMapIndex(this.cell);
- this.idx_end = this.getMapIndex(secondcell);
-
- // switch indexes if start is bigger than end
- if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
- var temp_idx = this.idx_start;
- this.idx_start = this.idx_end;
- this.idx_end = temp_idx;
- }
- if (this.idx_start.col > this.idx_end.col) {
- var temp_cidx = this.idx_start.col;
- this.idx_start.col = this.idx_end.col;
- this.idx_end.col = temp_cidx;
- }
-
- return {
- "start": this.map[this.idx_start.row][this.idx_start.col].el,
- "end": this.map[this.idx_end.row][this.idx_end.col].el
- };
- },
-
- createCells: function(tag, nr, attrs) {
- var doc = this.table.ownerDocument,
- frag = doc.createDocumentFragment(),
- cell;
- for (var i = 0; i < nr; i++) {
- cell = doc.createElement(tag);
-
- if (attrs) {
- for (var attr in attrs) {
- if (attrs.hasOwnProperty(attr)) {
- cell.setAttribute(attr, attrs[attr]);
- }
- }
- }
-
- // add non breaking space
- cell.appendChild(document.createTextNode("\u00a0"));
- frag.appendChild(cell);
- }
- return frag;
- },
-
- // Returns next real cell (not part of spanned cell unless first) on row if selected index is not real. I no real cells -1 will be returned
- correctColIndexForUnreals: function(col, row) {
- var r = this.map[row],
- corrIdx = -1;
- for (var i = 0, max = col; i < col; i++) {
- if (r[i].isReal){
- corrIdx++;
- }
- }
- return corrIdx;
- },
-
- getLastNewCellOnRow: function(row, rowLimit) {
- var cells = this.getRowCells(row),
- cell, idx;
-
- for (var cidx = 0, cmax = cells.length; cidx < cmax; cidx++) {
- cell = cells[cidx];
- idx = this.getMapIndex(cell);
- if (idx === false || (typeof rowLimit != "undefined" && idx.row != rowLimit)) {
- return cell;
- }
- }
- return null;
- },
-
- removeEmptyTable: function() {
- var cells = this.table.querySelectorAll('td, th');
- if (!cells || cells.length == 0) {
- removeElement(this.table);
- return true;
- } else {
- return false;
- }
- },
-
- // Splits merged cell on row to unique cells
- splitRowToCells: function(cell) {
- if (cell.isColspan) {
- var colspan = parseInt(api.getAttribute(cell.el, 'colspan') || 1, 10),
- cType = cell.el.tagName.toLowerCase();
- if (colspan > 1) {
- var newCells = this.createCells(cType, colspan -1);
- insertAfter(cell.el, newCells);
- }
- cell.el.removeAttribute('colspan');
- }
- },
-
- getRealRowEl: function(force, idx) {
- var r = null,
- c = null;
-
- idx = idx || this.idx;
-
- for (var cidx = 0, cmax = this.map[idx.row].length; cidx < cmax; cidx++) {
- c = this.map[idx.row][cidx];
- if (c.isReal) {
- r = api.getParentElement(c.el, { query: "tr" });
- if (r) {
- return r;
- }
- }
- }
-
- if (r === null && force) {
- r = api.getParentElement(this.map[idx.row][idx.col].el, { query: "tr" }) || null;
- }
-
- return r;
- },
-
- injectRowAt: function(row, col, colspan, cType, c) {
- var r = this.getRealRowEl(false, {'row': row, 'col': col}),
- new_cells = this.createCells(cType, colspan);
-
- if (r) {
- var n_cidx = this.correctColIndexForUnreals(col, row);
- if (n_cidx >= 0) {
- insertAfter(this.getRowCells(r)[n_cidx], new_cells);
- } else {
- r.insertBefore(new_cells, r.firstChild);
- }
- } else {
- var rr = this.table.ownerDocument.createElement('tr');
- rr.appendChild(new_cells);
- insertAfter(api.getParentElement(c.el, { query: "tr" }), rr);
- }
- },
-
- canMerge: function(to) {
- this.to = to;
- this.setTableMap();
- this.idx_start = this.getMapIndex(this.cell);
- this.idx_end = this.getMapIndex(this.to);
-
- // switch indexes if start is bigger than end
- if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
- var temp_idx = this.idx_start;
- this.idx_start = this.idx_end;
- this.idx_end = temp_idx;
- }
- if (this.idx_start.col > this.idx_end.col) {
- var temp_cidx = this.idx_start.col;
- this.idx_start.col = this.idx_end.col;
- this.idx_end.col = temp_cidx;
- }
-
- for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
- for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
- if (this.map[row][col].isColspan || this.map[row][col].isRowspan) {
- return false;
- }
- }
- }
- return true;
- },
-
- decreaseCellSpan: function(cell, span) {
- var nr = parseInt(api.getAttribute(cell.el, span), 10) - 1;
- if (nr >= 1) {
- cell.el.setAttribute(span, nr);
- } else {
- cell.el.removeAttribute(span);
- if (span == 'colspan') {
- cell.isColspan = false;
- }
- if (span == 'rowspan') {
- cell.isRowspan = false;
- }
- cell.firstCol = true;
- cell.lastCol = true;
- cell.firstRow = true;
- cell.lastRow = true;
- cell.isReal = true;
- }
- },
-
- removeSurplusLines: function() {
- var row, cell, ridx, rmax, cidx, cmax, allRowspan;
-
- this.setTableMap();
- if (this.map) {
- ridx = 0;
- rmax = this.map.length;
- for (;ridx < rmax; ridx++) {
- row = this.map[ridx];
- allRowspan = true;
- cidx = 0;
- cmax = row.length;
- for (; cidx < cmax; cidx++) {
- cell = row[cidx];
- if (!(api.getAttribute(cell.el, "rowspan") && parseInt(api.getAttribute(cell.el, "rowspan"), 10) > 1 && cell.firstRow !== true)) {
- allRowspan = false;
- break;
- }
- }
- if (allRowspan) {
- cidx = 0;
- for (; cidx < cmax; cidx++) {
- this.decreaseCellSpan(row[cidx], 'rowspan');
- }
- }
- }
-
- // remove rows without cells
- var tableRows = this.getTableRows();
- ridx = 0;
- rmax = tableRows.length;
- for (;ridx < rmax; ridx++) {
- row = tableRows[ridx];
- if (row.childNodes.length == 0 && (/^\s*$/.test(row.textContent || row.innerText))) {
- removeElement(row);
- }
- }
- }
- },
-
- fillMissingCells: function() {
- var r_max = 0,
- c_max = 0,
- prevcell = null;
-
- this.setTableMap();
- if (this.map) {
-
- // find maximal dimensions of broken table
- r_max = this.map.length;
- for (var ridx = 0; ridx < r_max; ridx++) {
- if (this.map[ridx].length > c_max) { c_max = this.map[ridx].length; }
- }
-
- for (var row = 0; row < r_max; row++) {
- for (var col = 0; col < c_max; col++) {
- if (this.map[row] && !this.map[row][col]) {
- if (col > 0) {
- this.map[row][col] = new MapCell(this.createCells('td', 1));
- prevcell = this.map[row][col-1];
- if (prevcell && prevcell.el && prevcell.el.parent) { // if parent does not exist element is removed from dom
- insertAfter(this.map[row][col-1].el, this.map[row][col].el);
- }
- }
- }
- }
- }
- }
- },
-
- rectify: function() {
- if (!this.removeEmptyTable()) {
- this.removeSurplusLines();
- this.fillMissingCells();
- return true;
- } else {
- return false;
- }
- },
-
- unmerge: function() {
- if (this.rectify()) {
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
-
- if (this.idx) {
- var thisCell = this.map[this.idx.row][this.idx.col],
- colspan = (api.getAttribute(thisCell.el, "colspan")) ? parseInt(api.getAttribute(thisCell.el, "colspan"), 10) : 1,
- cType = thisCell.el.tagName.toLowerCase();
-
- if (thisCell.isRowspan) {
- var rowspan = parseInt(api.getAttribute(thisCell.el, "rowspan"), 10);
- if (rowspan > 1) {
- for (var nr = 1, maxr = rowspan - 1; nr <= maxr; nr++){
- this.injectRowAt(this.idx.row + nr, this.idx.col, colspan, cType, thisCell);
- }
- }
- thisCell.el.removeAttribute('rowspan');
- }
- this.splitRowToCells(thisCell);
- }
- }
- },
-
- // merges cells from start cell (defined in creating obj) to "to" cell
- merge: function(to) {
- if (this.rectify()) {
- if (this.canMerge(to)) {
- var rowspan = this.idx_end.row - this.idx_start.row + 1,
- colspan = this.idx_end.col - this.idx_start.col + 1;
-
- for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
- for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
-
- if (row == this.idx_start.row && col == this.idx_start.col) {
- if (rowspan > 1) {
- this.map[row][col].el.setAttribute('rowspan', rowspan);
- }
- if (colspan > 1) {
- this.map[row][col].el.setAttribute('colspan', colspan);
- }
- } else {
- // transfer content
- if (!(/^\s* \s*$/.test(this.map[row][col].el.innerHTML.toLowerCase()))) {
- this.map[this.idx_start.row][this.idx_start.col].el.innerHTML += ' ' + this.map[row][col].el.innerHTML;
- }
- removeElement(this.map[row][col].el);
- }
-
- }
- }
- this.rectify();
- } else {
- if (window.console) {
- console.log('Do not know how to merge allready merged cells.');
- }
- }
- }
- },
-
- // Decreases rowspan of a cell if it is done on first cell of rowspan row (real cell)
- // Cell is moved to next row (if it is real)
- collapseCellToNextRow: function(cell) {
- var cellIdx = this.getMapIndex(cell.el),
- newRowIdx = cellIdx.row + 1,
- newIdx = {'row': newRowIdx, 'col': cellIdx.col};
-
- if (newRowIdx < this.map.length) {
-
- var row = this.getRealRowEl(false, newIdx);
- if (row !== null) {
- var n_cidx = this.correctColIndexForUnreals(newIdx.col, newIdx.row);
- if (n_cidx >= 0) {
- insertAfter(this.getRowCells(row)[n_cidx], cell.el);
- } else {
- var lastCell = this.getLastNewCellOnRow(row, newRowIdx);
- if (lastCell !== null) {
- insertAfter(lastCell, cell.el);
- } else {
- row.insertBefore(cell.el, row.firstChild);
- }
- }
- if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
- cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
- } else {
- cell.el.removeAttribute('rowspan');
- }
- }
- }
- },
-
- // Removes a cell when removing a row
- // If is rowspan cell then decreases the rowspan
- // and moves cell to next row if needed (is first cell of rowspan)
- removeRowCell: function(cell) {
- if (cell.isReal) {
- if (cell.isRowspan) {
- this.collapseCellToNextRow(cell);
- } else {
- removeElement(cell.el);
- }
- } else {
- if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
- cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
- } else {
- cell.el.removeAttribute('rowspan');
- }
- }
- },
-
- getRowElementsByCell: function() {
- var cells = [];
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (this.idx !== false) {
- var modRow = this.map[this.idx.row];
- for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
- if (modRow[cidx].isReal) {
- cells.push(modRow[cidx].el);
- }
- }
- }
- return cells;
- },
-
- getColumnElementsByCell: function() {
- var cells = [];
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (this.idx !== false) {
- for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
- if (this.map[ridx][this.idx.col] && this.map[ridx][this.idx.col].isReal) {
- cells.push(this.map[ridx][this.idx.col].el);
- }
- }
- }
- return cells;
- },
-
- // Removes the row of selected cell
- removeRow: function() {
- var oldRow = api.getParentElement(this.cell, { query: "tr" });
- if (oldRow) {
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (this.idx !== false) {
- var modRow = this.map[this.idx.row];
- for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
- if (!modRow[cidx].modified) {
- this.setCellAsModified(modRow[cidx]);
- this.removeRowCell(modRow[cidx]);
- }
- }
- }
- removeElement(oldRow);
- }
- },
-
- removeColCell: function(cell) {
- if (cell.isColspan) {
- if (parseInt(api.getAttribute(cell.el, 'colspan'), 10) > 2) {
- cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) - 1);
- } else {
- cell.el.removeAttribute('colspan');
- }
- } else if (cell.isReal) {
- removeElement(cell.el);
- }
- },
-
- removeColumn: function() {
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (this.idx !== false) {
- for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
- if (!this.map[ridx][this.idx.col].modified) {
- this.setCellAsModified(this.map[ridx][this.idx.col]);
- this.removeColCell(this.map[ridx][this.idx.col]);
- }
- }
- }
- },
-
- // removes row or column by selected cell element
- remove: function(what) {
- if (this.rectify()) {
- switch (what) {
- case 'row':
- this.removeRow();
- break;
- case 'column':
- this.removeColumn();
- break;
- }
- this.rectify();
- }
- },
-
- addRow: function(where) {
- var doc = this.table.ownerDocument;
-
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (where == "below" && api.getAttribute(this.cell, 'rowspan')) {
- this.idx.row = this.idx.row + parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1;
- }
-
- if (this.idx !== false) {
- var modRow = this.map[this.idx.row],
- newRow = doc.createElement('tr');
-
- for (var ridx = 0, rmax = modRow.length; ridx < rmax; ridx++) {
- if (!modRow[ridx].modified) {
- this.setCellAsModified(modRow[ridx]);
- this.addRowCell(modRow[ridx], newRow, where);
- }
- }
-
- switch (where) {
- case 'below':
- insertAfter(this.getRealRowEl(true), newRow);
- break;
- case 'above':
- var cr = api.getParentElement(this.map[this.idx.row][this.idx.col].el, { query: "tr" });
- if (cr) {
- cr.parentNode.insertBefore(newRow, cr);
- }
- break;
- }
- }
- },
-
- addRowCell: function(cell, row, where) {
- var colSpanAttr = (cell.isColspan) ? {"colspan" : api.getAttribute(cell.el, 'colspan')} : null;
- if (cell.isReal) {
- if (where != 'above' && cell.isRowspan) {
- cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el,'rowspan'), 10) + 1);
- } else {
- row.appendChild(this.createCells('td', 1, colSpanAttr));
- }
- } else {
- if (where != 'above' && cell.isRowspan && cell.lastRow) {
- row.appendChild(this.createCells('td', 1, colSpanAttr));
- } else if (c.isRowspan) {
- cell.el.attr('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) + 1);
- }
- }
- },
-
- add: function(where) {
- if (this.rectify()) {
- if (where == 'below' || where == 'above') {
- this.addRow(where);
- }
- if (where == 'before' || where == 'after') {
- this.addColumn(where);
- }
- }
- },
-
- addColCell: function (cell, ridx, where) {
- var doAdd,
- cType = cell.el.tagName.toLowerCase();
-
- // defines add cell vs expand cell conditions
- // true means add
- switch (where) {
- case "before":
- doAdd = (!cell.isColspan || cell.firstCol);
- break;
- case "after":
- doAdd = (!cell.isColspan || cell.lastCol || (cell.isColspan && c.el == this.cell));
- break;
- }
-
- if (doAdd){
- // adds a cell before or after current cell element
- switch (where) {
- case "before":
- cell.el.parentNode.insertBefore(this.createCells(cType, 1), cell.el);
- break;
- case "after":
- insertAfter(cell.el, this.createCells(cType, 1));
- break;
- }
-
- // handles if cell has rowspan
- if (cell.isRowspan) {
- this.handleCellAddWithRowspan(cell, ridx+1, where);
- }
-
- } else {
- // expands cell
- cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) + 1);
- }
- },
-
- addColumn: function(where) {
- var row, modCell;
-
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (where == "after" && api.getAttribute(this.cell, 'colspan')) {
- this.idx.col = this.idx.col + parseInt(api.getAttribute(this.cell, 'colspan'), 10) - 1;
- }
-
- if (this.idx !== false) {
- for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++ ) {
- row = this.map[ridx];
- if (row[this.idx.col]) {
- modCell = row[this.idx.col];
- if (!modCell.modified) {
- this.setCellAsModified(modCell);
- this.addColCell(modCell, ridx , where);
- }
- }
- }
- }
- },
-
- handleCellAddWithRowspan: function (cell, ridx, where) {
- var addRowsNr = parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1,
- crow = api.getParentElement(cell.el, { query: "tr" }),
- cType = cell.el.tagName.toLowerCase(),
- cidx, temp_r_cells,
- doc = this.table.ownerDocument,
- nrow;
-
- for (var i = 0; i < addRowsNr; i++) {
- cidx = this.correctColIndexForUnreals(this.idx.col, (ridx + i));
- crow = nextNode(crow, 'tr');
- if (crow) {
- if (cidx > 0) {
- switch (where) {
- case "before":
- temp_r_cells = this.getRowCells(crow);
- if (cidx > 0 && this.map[ridx + i][this.idx.col].el != temp_r_cells[cidx] && cidx == temp_r_cells.length - 1) {
- insertAfter(temp_r_cells[cidx], this.createCells(cType, 1));
- } else {
- temp_r_cells[cidx].parentNode.insertBefore(this.createCells(cType, 1), temp_r_cells[cidx]);
- }
-
- break;
- case "after":
- insertAfter(this.getRowCells(crow)[cidx], this.createCells(cType, 1));
- break;
- }
- } else {
- crow.insertBefore(this.createCells(cType, 1), crow.firstChild);
- }
- } else {
- nrow = doc.createElement('tr');
- nrow.appendChild(this.createCells(cType, 1));
- this.table.appendChild(nrow);
- }
- }
- }
- };
-
- api.table = {
- getCellsBetween: function(cell1, cell2) {
- var c1 = new TableModifyerByCell(cell1);
- return c1.getMapElsTo(cell2);
- },
-
- addCells: function(cell, where) {
- var c = new TableModifyerByCell(cell);
- c.add(where);
- },
-
- removeCells: function(cell, what) {
- var c = new TableModifyerByCell(cell);
- c.remove(what);
- },
-
- mergeCellsBetween: function(cell1, cell2) {
- var c1 = new TableModifyerByCell(cell1);
- c1.merge(cell2);
- },
-
- unmergeCell: function(cell) {
- var c = new TableModifyerByCell(cell);
- c.unmerge();
- },
-
- orderSelectionEnds: function(cell, cell2) {
- var c = new TableModifyerByCell(cell);
- return c.orderSelectionEnds(cell2);
- },
-
- indexOf: function(cell) {
- var c = new TableModifyerByCell(cell);
- c.setTableMap();
- return c.getMapIndex(cell);
- },
-
- findCell: function(table, idx) {
- var c = new TableModifyerByCell(null, table);
- return c.getElementAtIndex(idx);
- },
-
- findRowByCell: function(cell) {
- var c = new TableModifyerByCell(cell);
- return c.getRowElementsByCell();
- },
-
- findColumnByCell: function(cell) {
- var c = new TableModifyerByCell(cell);
- return c.getColumnElementsByCell();
- },
-
- canMerge: function(cell1, cell2) {
- var c = new TableModifyerByCell(cell1);
- return c.canMerge(cell2);
- }
- };
-
-})(wysihtml5);
-;// does a selector query on element or array of elements
-wysihtml5.dom.query = function(elements, query) {
- var ret = [],
- q;
-
- if (elements.nodeType) {
- elements = [elements];
- }
-
- for (var e = 0, len = elements.length; e < len; e++) {
- q = elements[e].querySelectorAll(query);
- if (q) {
- for(var i = q.length; i--; ret.unshift(q[i]));
- }
- }
- return ret;
-};
-;wysihtml5.dom.compareDocumentPosition = (function() {
- var documentElement = document.documentElement;
- if (documentElement.compareDocumentPosition) {
- return function(container, element) {
- return container.compareDocumentPosition(element);
- };
- } else {
- return function( container, element ) {
- // implementation borrowed from https://github.com/tmpvar/jsdom/blob/681a8524b663281a0f58348c6129c8c184efc62c/lib/jsdom/level3/core.js // MIT license
- var thisOwner, otherOwner;
-
- if( container.nodeType === 9) // Node.DOCUMENT_NODE
- thisOwner = container;
- else
- thisOwner = container.ownerDocument;
-
- if( element.nodeType === 9) // Node.DOCUMENT_NODE
- otherOwner = element;
- else
- otherOwner = element.ownerDocument;
-
- if( container === element ) return 0;
- if( container === element.ownerDocument ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
- if( container.ownerDocument === element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
- if( thisOwner !== otherOwner ) return 1; // Node.DOCUMENT_POSITION_DISCONNECTED;
-
- // Text nodes for attributes does not have a _parentNode. So we need to find them as attribute child.
- if( container.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && container.childNodes && wysihtml5.lang.array(container.childNodes).indexOf( element ) !== -1)
- return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
-
- if( element.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && element.childNodes && wysihtml5.lang.array(element.childNodes).indexOf( container ) !== -1)
- return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
-
- var point = container;
- var parents = [ ];
- var previous = null;
- while( point ) {
- if( point == element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
- parents.push( point );
- point = point.parentNode;
- }
- point = element;
- previous = null;
- while( point ) {
- if( point == container ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
- var location_index = wysihtml5.lang.array(parents).indexOf( point );
- if( location_index !== -1) {
- var smallest_common_ancestor = parents[ location_index ];
- var this_index = wysihtml5.lang.array(smallest_common_ancestor.childNodes).indexOf( parents[location_index - 1]);//smallest_common_ancestor.childNodes.toArray().indexOf( parents[location_index - 1] );
- var other_index = wysihtml5.lang.array(smallest_common_ancestor.childNodes).indexOf( previous ); //smallest_common_ancestor.childNodes.toArray().indexOf( previous );
- if( this_index > other_index ) {
- return 2; //Node.DOCUMENT_POSITION_PRECEDING;
- }
- else {
- return 4; //Node.DOCUMENT_POSITION_FOLLOWING;
- }
- }
- previous = point;
- point = point.parentNode;
- }
- return 1; //Node.DOCUMENT_POSITION_DISCONNECTED;
- };
- }
-})();
-;/* Unwraps element and returns list of childNodes that the node contained.
- *
- * Example:
- * var childnodes = wysihtml5.dom.unwrap(document.querySelector('.unwrap-me'));
-*/
-
-wysihtml5.dom.unwrap = function(node) {
- var children = [];
- if (node.parentNode) {
- while (node.lastChild) {
- children.unshift(node.lastChild);
- wysihtml5.dom.insert(node.lastChild).after(node);
- }
- node.parentNode.removeChild(node);
- }
- return children;
-};
-;/*
- * Methods for fetching pasted html before it gets inserted into content
-**/
-
-/* Modern event.clipboardData driven approach.
- * Advantage is that it does not have to loose selection or modify dom to catch the data.
- * IE does not support though.
-**/
-wysihtml5.dom.getPastedHtml = function(event) {
- var html;
- if (wysihtml5.browser.supportsModernPaste() && event.clipboardData) {
- if (wysihtml5.lang.array(event.clipboardData.types).contains('text/html')) {
- html = event.clipboardData.getData('text/html');
- } else if (wysihtml5.lang.array(event.clipboardData.types).contains('text/plain')) {
- html = wysihtml5.lang.string(event.clipboardData.getData('text/plain')).escapeHTML(true, true);
- }
- }
- return html;
-};
-
-/* Older temprorary contenteditable as paste source catcher method for fallbacks */
-wysihtml5.dom.getPastedHtmlWithDiv = function (composer, f) {
- var selBookmark = composer.selection.getBookmark(),
- doc = composer.element.ownerDocument,
- cleanerDiv = doc.createElement('DIV'),
- scrollPos = composer.getScrollPos();
-
- doc.body.appendChild(cleanerDiv);
-
- cleanerDiv.style.width = "1px";
- cleanerDiv.style.height = "1px";
- cleanerDiv.style.overflow = "hidden";
- cleanerDiv.style.position = "absolute";
- cleanerDiv.style.top = scrollPos.y + "px";
- cleanerDiv.style.left = scrollPos.x + "px";
-
- cleanerDiv.setAttribute('contenteditable', 'true');
- cleanerDiv.focus();
-
- setTimeout(function () {
- var html;
-
- composer.selection.setBookmark(selBookmark);
- html = cleanerDiv.innerHTML;
- if (html && (/^ $/i).test(html.trim())) {
- html = false;
- }
- f(html);
- cleanerDiv.parentNode.removeChild(cleanerDiv);
- }, 0);
-};
-;wysihtml5.dom.removeInvisibleSpaces = function(node) {
- var textNodes = wysihtml5.dom.getTextNodes(node);
- for (var n = textNodes.length; n--;) {
- textNodes[n].nodeValue = textNodes[n].nodeValue.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
- }
-};
-;/**
- * Fix most common html formatting misbehaviors of browsers implementation when inserting
- * content via copy & paste contentEditable
- *
- * @author Christopher Blum
- */
-wysihtml5.quirks.cleanPastedHTML = (function() {
-
- var styleToRegex = function (styleStr) {
- var trimmedStr = wysihtml5.lang.string(styleStr).trim(),
- escapedStr = trimmedStr.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
-
- return new RegExp("^((?!^" + escapedStr + "$).)*$", "i");
- };
-
- var extendRulesWithStyleExceptions = function (rules, exceptStyles) {
- var newRules = wysihtml5.lang.object(rules).clone(true),
- tag, style;
-
- for (tag in newRules.tags) {
-
- if (newRules.tags.hasOwnProperty(tag)) {
- if (newRules.tags[tag].keep_styles) {
- for (style in newRules.tags[tag].keep_styles) {
- if (newRules.tags[tag].keep_styles.hasOwnProperty(style)) {
- if (exceptStyles[style]) {
- newRules.tags[tag].keep_styles[style] = styleToRegex(exceptStyles[style]);
- }
- }
- }
- }
- }
- }
-
- return newRules;
- };
-
- var pickRuleset = function(ruleset, html) {
- var pickedSet, defaultSet;
-
- if (!ruleset) {
- return null;
- }
-
- for (var i = 0, max = ruleset.length; i < max; i++) {
- if (!ruleset[i].condition) {
- defaultSet = ruleset[i].set;
- }
- if (ruleset[i].condition && ruleset[i].condition.test(html)) {
- return ruleset[i].set;
- }
- }
-
- return defaultSet;
- };
-
- return function(html, options) {
- var exceptStyles = {
- 'color': wysihtml5.dom.getStyle("color").from(options.referenceNode),
- 'fontSize': wysihtml5.dom.getStyle("font-size").from(options.referenceNode)
- },
- rules = extendRulesWithStyleExceptions(pickRuleset(options.rules, html) || {}, exceptStyles),
- newHtml;
-
- newHtml = wysihtml5.dom.parse(html, {
- "rules": rules,
- "cleanUp": true, // elements, empty or without attributes, should be removed/replaced with their content
- "context": options.referenceNode.ownerDocument,
- "uneditableClass": options.uneditableClass,
- "clearInternals" : true, // don't paste temprorary selection and other markings
- "unjoinNbsps" : true
- });
-
- return newHtml;
- };
-
-})();
-;/**
- * IE and Opera leave an empty paragraph in the contentEditable element after clearing it
- *
- * @param {Object} contentEditableElement The contentEditable element to observe for clearing events
- * @exaple
- * wysihtml5.quirks.ensureProperClearing(myContentEditableElement);
- */
-wysihtml5.quirks.ensureProperClearing = (function() {
- var clearIfNecessary = function() {
- var element = this;
- setTimeout(function() {
- var innerHTML = element.innerHTML.toLowerCase();
- if (innerHTML == "
" ||
- innerHTML == "
") {
- element.innerHTML = "";
- }
- }, 0);
- };
-
- return function(composer) {
- wysihtml5.dom.observe(composer.element, ["cut", "keydown"], clearIfNecessary);
- };
-})();
-;// See https://bugzilla.mozilla.org/show_bug.cgi?id=664398
-//
-// In Firefox this:
-// var d = document.createElement("div");
-// d.innerHTML =' ';
-// d.innerHTML;
-// will result in:
-//
-// which is wrong
-(function(wysihtml5) {
- var TILDE_ESCAPED = "%7E";
- wysihtml5.quirks.getCorrectInnerHTML = function(element) {
- var innerHTML = element.innerHTML;
- if (innerHTML.indexOf(TILDE_ESCAPED) === -1) {
- return innerHTML;
- }
-
- var elementsWithTilde = element.querySelectorAll("[href*='~'], [src*='~']"),
- url,
- urlToSearch,
- length,
- i;
- for (i=0, length=elementsWithTilde.length; i 0) {
- for (var i = 0; i < selectedCells.length; i++) {
- dom.removeClass(selectedCells[i], selection_class);
- }
- }
- }
- }
-
- function addSelections (cells) {
- for (var i = 0; i < cells.length; i++) {
- dom.addClass(cells[i], selection_class);
- }
- }
-
- function handleMouseMove (event) {
- var curTable = null,
- cell = dom.getParentElement(event.target, { query: "td, th" }, false, editable),
- oldEnd;
-
- if (cell && select.table && select.start) {
- curTable = dom.getParentElement(cell, { query: "table" }, false, editable);
- if (curTable && curTable === select.table) {
- removeCellSelections();
- oldEnd = select.end;
- select.end = cell;
- select.cells = dom.table.getCellsBetween(select.start, cell);
- if (select.cells.length > 1) {
- editor.composer.selection.deselect();
- }
- addSelections(select.cells);
- if (select.end !== oldEnd) {
- editor.fire("tableselectchange").fire("tableselectchange:composer");
- }
- }
- }
- }
-
- function handleMouseUp (event) {
- editable.removeEventListener("mousemove", handleMouseMove);
- editable.removeEventListener("mouseup", handleMouseUp);
- editor.fire("tableselect").fire("tableselect:composer");
- setTimeout(function() {
- bindSideclick();
- },0);
- }
-
- var sideClickHandler = function(event) {
- editable.ownerDocument.removeEventListener("click", sideClickHandler);
- if (dom.getParentElement(event.target, { query: "table" }, false, editable) != select.table) {
- removeCellSelections();
- select.table = null;
- select.start = null;
- select.end = null;
- editor.fire("tableunselect").fire("tableunselect:composer");
- }
- };
-
- function bindSideclick () {
- editable.ownerDocument.addEventListener("click", sideClickHandler);
- }
-
- function selectCells (start, end) {
- select.start = start;
- select.end = end;
- select.table = dom.getParentElement(select.start, { query: "table" }, false, editable);
- selectedCells = dom.table.getCellsBetween(select.start, select.end);
- addSelections(selectedCells);
- bindSideclick();
- editor.fire("tableselect").fire("tableselect:composer");
- }
-
- return init();
-
-};
-;(function(wysihtml5) {
-
- // List of supported color format parsing methods
- // If radix is not defined 10 is expected as default
- var colorParseMethods = {
- rgba : {
- regex: /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d\.]+)\s*\)/i,
- name: "rgba"
- },
- rgb : {
- regex: /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i,
- name: "rgb"
- },
- hex6 : {
- regex: /^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/i,
- name: "hex",
- radix: 16
- },
- hex3 : {
- regex: /^#([0-9a-f])([0-9a-f])([0-9a-f])/i,
- name: "hex",
- radix: 16
- }
- },
- // Takes a style key name as an argument and makes a regex that can be used to the match key:value pair from style string
- makeParamRegExp = function (p) {
- return new RegExp("(^|\\s|;)" + p + "\\s*:\\s*[^;$]+", "gi");
- };
-
- // Takes color string value ("#abc", "rgb(1,2,3)", ...) as an argument and returns suitable parsing method for it
- function getColorParseMethod (colorStr) {
- var prop, colorTypeConf;
-
- for (prop in colorParseMethods) {
- if (!colorParseMethods.hasOwnProperty(prop)) { continue; }
-
- colorTypeConf = colorParseMethods[prop];
-
- if (colorTypeConf.regex.test(colorStr)) {
- return colorTypeConf;
- }
- }
- }
-
- // Takes color string value ("#abc", "rgb(1,2,3)", ...) as an argument and returns the type of that color format "hex", "rgb", "rgba".
- function getColorFormat (colorStr) {
- var type = getColorParseMethod(colorStr);
-
- return type ? type.name : undefined;
- }
-
- // Public API functions for styleParser
- wysihtml5.quirks.styleParser = {
-
- // Takes color string value as an argument and returns suitable parsing method for it
- getColorParseMethod : getColorParseMethod,
-
- // Takes color string value as an argument and returns the type of that color format "hex", "rgb", "rgba".
- getColorFormat : getColorFormat,
-
- /* Parses a color string to and array of [red, green, blue, alpha].
- * paramName: optional argument to parse color value directly from style string parameter
- *
- * Examples:
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("#ABC"); // [170, 187, 204, 1]
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("#AABBCC"); // [170, 187, 204, 1]
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("rgb(1,2,3)"); // [1, 2, 3, 1]
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("rgba(1,2,3,0.5)"); // [1, 2, 3, 0.5]
- *
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("background-color: #ABC; color: #000;", "background-color"); // [170, 187, 204, 1]
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("background-color: #ABC; color: #000;", "color"); // [0, 0, 0, 1]
- */
- parseColor : function (stylesStr, paramName) {
- var paramsRegex, params, colorType, colorMatch, radix,
- colorStr = stylesStr;
-
- if (paramName) {
- paramsRegex = makeParamRegExp(paramName);
-
- if (!(params = stylesStr.match(paramsRegex))) { return false; }
-
- params = params.pop().split(":")[1];
- colorStr = wysihtml5.lang.string(params).trim();
- }
-
- if (!(colorType = getColorParseMethod(colorStr))) { return false; }
- if (!(colorMatch = colorStr.match(colorType.regex))) { return false; }
-
- radix = colorType.radix || 10;
-
- if (colorType === colorParseMethods.hex3) {
- colorMatch.shift();
- colorMatch.push(1);
- return wysihtml5.lang.array(colorMatch).map(function(d, idx) {
- return (idx < 3) ? (parseInt(d, radix) * radix) + parseInt(d, radix): parseFloat(d);
- });
- }
-
- colorMatch.shift();
-
- if (!colorMatch[3]) {
- colorMatch.push(1);
- }
-
- return wysihtml5.lang.array(colorMatch).map(function(d, idx) {
- return (idx < 3) ? parseInt(d, radix): parseFloat(d);
- });
- },
-
- /* Takes rgba color array [r,g,b,a] as a value and formats it to color string with given format type
- * If no format is given, rgba/rgb is returned based on alpha value
- *
- * Example:
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1], "hash"); // "#AABBCC"
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1], "hex"); // "AABBCC"
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1], "csv"); // "170, 187, 204, 1"
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1], "rgba"); // "rgba(170,187,204,1)"
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1], "rgb"); // "rgb(170,187,204)"
- *
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 0.5]); // "rgba(170,187,204,0.5)"
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1]); // "rgb(170,187,204)"
- */
- unparseColor: function(val, colorFormat) {
- var hexRadix = 16;
-
- if (colorFormat === "hex") {
- return (val[0].toString(hexRadix) + val[1].toString(hexRadix) + val[2].toString(hexRadix)).toUpperCase();
- } else if (colorFormat === "hash") {
- return "#" + (val[0].toString(hexRadix) + val[1].toString(hexRadix) + val[2].toString(hexRadix)).toUpperCase();
- } else if (colorFormat === "rgb") {
- return "rgb(" + val[0] + "," + val[1] + "," + val[2] + ")";
- } else if (colorFormat === "rgba") {
- return "rgba(" + val[0] + "," + val[1] + "," + val[2] + "," + val[3] + ")";
- } else if (colorFormat === "csv") {
- return val[0] + "," + val[1] + "," + val[2] + "," + val[3];
- }
-
- if (val[3] && val[3] !== 1) {
- return "rgba(" + val[0] + "," + val[1] + "," + val[2] + "," + val[3] + ")";
- } else {
- return "rgb(" + val[0] + "," + val[1] + "," + val[2] + ")";
- }
- },
-
- // Parses font size value from style string
- parseFontSize: function(stylesStr) {
- var params = stylesStr.match(makeParamRegExp("font-size"));
- if (params) {
- return wysihtml5.lang.string(params[params.length - 1].split(":")[1]).trim();
- }
- return false;
- }
- };
-
-})(wysihtml5);
-;/**
- * Selection API
- *
- * @example
- * var selection = new wysihtml5.Selection(editor);
- */
-(function(wysihtml5) {
- var dom = wysihtml5.dom;
-
- function _getCumulativeOffsetTop(element) {
- var top = 0;
- if (element.parentNode) {
- do {
- top += element.offsetTop || 0;
- element = element.offsetParent;
- } while (element);
- }
- return top;
- }
-
- // Provides the depth of ``descendant`` relative to ``ancestor``
- function getDepth(ancestor, descendant) {
- var ret = 0;
- while (descendant !== ancestor) {
- ret++;
- descendant = descendant.parentNode;
- if (!descendant)
- throw new Error("not a descendant of ancestor!");
- }
- return ret;
- }
-
- function getRangeNode(node, offset) {
- if (node.nodeType === 3) {
- return node;
- } else {
- return node.childNodes[offset] || node;
- }
- }
-
- function getWebkitSelectionFixNode(container) {
- var blankNode = document.createElement('span');
-
- var placeholderRemover = function(event) {
- // Self-destructs the caret and keeps the text inserted into it by user
- var lastChild;
-
- container.removeEventListener('mouseup', placeholderRemover);
- container.removeEventListener('keydown', placeholderRemover);
- container.removeEventListener('touchstart', placeholderRemover);
- container.removeEventListener('focus', placeholderRemover);
- container.removeEventListener('blur', placeholderRemover);
- container.removeEventListener('paste', delayedPlaceholderRemover);
- container.removeEventListener('drop', delayedPlaceholderRemover);
- container.removeEventListener('beforepaste', delayedPlaceholderRemover);
-
- if (blankNode && blankNode.parentNode) {
- blankNode.parentNode.removeChild(blankNode);
- }
- },
- delayedPlaceholderRemover = function (event) {
- if (blankNode && blankNode.parentNode) {
- setTimeout(placeholderRemover, 0);
- }
- };
-
- blankNode.appendChild(container.ownerDocument.createTextNode(wysihtml5.INVISIBLE_SPACE));
- blankNode.className = '_wysihtml5-temp-caret-fix';
- blankNode.style.display = 'block';
- blankNode.style.minWidth = '1px';
- blankNode.style.height = '0px';
-
- container.addEventListener('mouseup', placeholderRemover);
- container.addEventListener('keydown', placeholderRemover);
- container.addEventListener('touchstart', placeholderRemover);
- container.addEventListener('focus', placeholderRemover);
- container.addEventListener('blur', placeholderRemover);
- container.addEventListener('paste', delayedPlaceholderRemover);
- container.addEventListener('drop', delayedPlaceholderRemover);
- container.addEventListener('beforepaste', delayedPlaceholderRemover);
-
- return blankNode;
- }
-
- // Should fix the obtained ranges that cannot surrond contents normally to apply changes upon
- // Being considerate to firefox that sets range start start out of span and end inside on doubleclick initiated selection
- function expandRangeToSurround(range) {
- if (range.canSurroundContents()) return;
-
- var common = range.commonAncestorContainer,
- start_depth = getDepth(common, range.startContainer),
- end_depth = getDepth(common, range.endContainer);
-
- while(!range.canSurroundContents()) {
- // In the following branches, we cannot just decrement the depth variables because the setStartBefore/setEndAfter may move the start or end of the range more than one level relative to ``common``. So we need to recompute the depth.
- if (start_depth > end_depth) {
- range.setStartBefore(range.startContainer);
- start_depth = getDepth(common, range.startContainer);
- }
- else {
- range.setEndAfter(range.endContainer);
- end_depth = getDepth(common, range.endContainer);
- }
- }
- }
-
- wysihtml5.Selection = Base.extend(
- /** @scope wysihtml5.Selection.prototype */ {
- constructor: function(editor, contain, unselectableClass) {
- // Make sure that our external range library is initialized
- rangy.init();
-
- this.editor = editor;
- this.composer = editor.composer;
- this.doc = this.composer.doc;
- this.win = this.composer.win;
- this.contain = contain;
- this.unselectableClass = unselectableClass || false;
- },
-
- /**
- * Get the current selection as a bookmark to be able to later restore it
- *
- * @return {Object} An object that represents the current selection
- */
- getBookmark: function() {
- var range = this.getRange();
- return range && range.cloneRange();
- },
-
- /**
- * Restore a selection retrieved via wysihtml5.Selection.prototype.getBookmark
- *
- * @param {Object} bookmark An object that represents the current selection
- */
- setBookmark: function(bookmark) {
- if (!bookmark) {
- return;
- }
-
- this.setSelection(bookmark);
- },
-
- /**
- * Set the caret in front of the given node
- *
- * @param {Object} node The element or text node where to position the caret in front of
- * @example
- * selection.setBefore(myElement);
- */
- setBefore: function(node) {
- var range = rangy.createRange(this.doc);
- range.setStartBefore(node);
- range.setEndBefore(node);
- return this.setSelection(range);
- },
-
- // Constructs a self removing whitespace (ain absolute positioned span) for placing selection caret when normal methods fail.
- // Webkit has an issue with placing caret into places where there are no textnodes near by.
- createTemporaryCaretSpaceAfter: function (node) {
- var caretPlaceholder = this.doc.createElement('span'),
- caretPlaceholderText = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE),
- placeholderRemover = (function(event) {
- // Self-destructs the caret and keeps the text inserted into it by user
- var lastChild;
-
- this.contain.removeEventListener('mouseup', placeholderRemover);
- this.contain.removeEventListener('keydown', keyDownHandler);
- this.contain.removeEventListener('touchstart', placeholderRemover);
- this.contain.removeEventListener('focus', placeholderRemover);
- this.contain.removeEventListener('blur', placeholderRemover);
- this.contain.removeEventListener('paste', delayedPlaceholderRemover);
- this.contain.removeEventListener('drop', delayedPlaceholderRemover);
- this.contain.removeEventListener('beforepaste', delayedPlaceholderRemover);
-
- // If user inserted sth it is in the placeholder and sgould be unwrapped and stripped of invisible whitespace hack
- // Otherwise the wrapper can just be removed
- if (caretPlaceholder && caretPlaceholder.parentNode) {
- caretPlaceholder.innerHTML = caretPlaceholder.innerHTML.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
- if ((/[^\s]+/).test(caretPlaceholder.innerHTML)) {
- lastChild = caretPlaceholder.lastChild;
- wysihtml5.dom.unwrap(caretPlaceholder);
- this.setAfter(lastChild);
- } else {
- caretPlaceholder.parentNode.removeChild(caretPlaceholder);
- }
-
- }
- }).bind(this),
- delayedPlaceholderRemover = function (event) {
- if (caretPlaceholder && caretPlaceholder.parentNode) {
- setTimeout(placeholderRemover, 0);
- }
- },
- keyDownHandler = function(event) {
- if (event.which !== 8 && event.which !== 91 && event.which !== 17 && (event.which !== 86 || (!event.ctrlKey && !event.metaKey))) {
- placeholderRemover();
- }
- };
-
- caretPlaceholder.className = '_wysihtml5-temp-caret-fix';
- caretPlaceholder.style.position = 'absolute';
- caretPlaceholder.style.display = 'block';
- caretPlaceholder.style.minWidth = '1px';
- caretPlaceholder.style.zIndex = '99999';
- caretPlaceholder.appendChild(caretPlaceholderText);
-
- node.parentNode.insertBefore(caretPlaceholder, node.nextSibling);
- this.setBefore(caretPlaceholderText);
-
- // Remove the caret fix on any of the following events (some are delayed as content change happens after event)
- this.contain.addEventListener('mouseup', placeholderRemover);
- this.contain.addEventListener('keydown', keyDownHandler);
- this.contain.addEventListener('touchstart', placeholderRemover);
- this.contain.addEventListener('focus', placeholderRemover);
- this.contain.addEventListener('blur', placeholderRemover);
- this.contain.addEventListener('paste', delayedPlaceholderRemover);
- this.contain.addEventListener('drop', delayedPlaceholderRemover);
- this.contain.addEventListener('beforepaste', delayedPlaceholderRemover);
-
- return caretPlaceholder;
- },
-
- /**
- * Set the caret after the given node
- *
- * @param {Object} node The element or text node where to position the caret in front of
- * @example
- * selection.setBefore(myElement);
- * callback is an optional parameter accepting a function to execute when selection ahs been set
- */
- setAfter: function(node, notVisual, callback) {
- var win = this.win,
- range = rangy.createRange(this.doc),
- fixWebkitSelection = function() {
- // Webkit fails to add selection if there are no textnodes in that region
- // (like an uneditable container at the end of content).
- var parent = node.parentNode,
- lastSibling = parent ? parent.childNodes[parent.childNodes.length - 1] : null;
-
- if (!sel || (lastSibling === node && node.nodeType === 1 && win.getComputedStyle(node).display === "block")) {
- if (notVisual) {
- // If setAfter is used as internal between actions, self-removing caretPlaceholder has simpler implementation
- // and remove itself in call stack end instead on user interaction
- var caretPlaceholder = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
- node.parentNode.insertBefore(caretPlaceholder, node.nextSibling);
- this.selectNode(caretPlaceholder);
- setTimeout(function() {
- if (caretPlaceholder && caretPlaceholder.parentNode) {
- caretPlaceholder.parentNode.removeChild(caretPlaceholder);
- }
- }, 0);
- } else {
- this.createTemporaryCaretSpaceAfter(node);
- }
- }
- }.bind(this),
- sel;
-
- range.setStartAfter(node);
- range.setEndAfter(node);
-
- // In IE contenteditable must be focused before we can set selection
- // thus setting the focus if activeElement is not this composer
- if (!document.activeElement || document.activeElement !== this.composer.element) {
- var scrollPos = this.composer.getScrollPos();
- this.composer.element.focus();
- this.composer.setScrollPos(scrollPos);
- setTimeout(function() {
- sel = this.setSelection(range);
- fixWebkitSelection();
- if (callback) {
- callback(sel);
- }
- }.bind(this), 0);
- } else {
- sel = this.setSelection(range);
- fixWebkitSelection();
- if (callback) {
- callback(sel);
- }
- }
- },
-
- /**
- * Ability to select/mark nodes
- *
- * @param {Element} node The node/element to select
- * @example
- * selection.selectNode(document.getElementById("my-image"));
- */
- selectNode: function(node, avoidInvisibleSpace) {
- var range = rangy.createRange(this.doc),
- isElement = node.nodeType === wysihtml5.ELEMENT_NODE,
- canHaveHTML = "canHaveHTML" in node ? node.canHaveHTML : (node.nodeName !== "IMG"),
- content = isElement ? node.innerHTML : node.data,
- isEmpty = (content === "" || content === wysihtml5.INVISIBLE_SPACE),
- displayStyle = dom.getStyle("display").from(node),
- isBlockElement = (displayStyle === "block" || displayStyle === "list-item");
-
- if (isEmpty && isElement && canHaveHTML && !avoidInvisibleSpace) {
- // Make sure that caret is visible in node by inserting a zero width no breaking space
- try { node.innerHTML = wysihtml5.INVISIBLE_SPACE; } catch(e) {}
- }
- if (canHaveHTML) {
- range.selectNodeContents(node);
- } else {
- range.selectNode(node);
- }
-
- if (canHaveHTML && isEmpty && isElement) {
- range.collapse(isBlockElement);
- } else if (canHaveHTML && isEmpty) {
- range.setStartAfter(node);
- range.setEndAfter(node);
- }
-
- this.setSelection(range);
- },
-
- /**
- * Get the node which contains the selection
- *
- * @param {Boolean} [controlRange] (only IE) Whether it should return the selected ControlRange element when the selection type is a "ControlRange"
- * @return {Object} The node that contains the caret
- * @example
- * var nodeThatContainsCaret = selection.getSelectedNode();
- */
- getSelectedNode: function(controlRange) {
- var selection,
- range;
-
- if (controlRange && this.doc.selection && this.doc.selection.type === "Control") {
- range = this.doc.selection.createRange();
- if (range && range.length) {
- return range.item(0);
- }
- }
-
- selection = this.getSelection(this.doc);
- if (selection.focusNode === selection.anchorNode) {
- return selection.focusNode;
- } else {
- range = this.getRange(this.doc);
- return range ? range.commonAncestorContainer : this.doc.body;
- }
- },
-
- fixSelBorders: function() {
- var range = this.getRange();
- expandRangeToSurround(range);
- this.setSelection(range);
- },
-
- getSelectedOwnNodes: function(controlRange) {
- var selection,
- ranges = this.getOwnRanges(),
- ownNodes = [];
-
- for (var i = 0, maxi = ranges.length; i < maxi; i++) {
- ownNodes.push(ranges[i].commonAncestorContainer || this.doc.body);
- }
- return ownNodes;
- },
-
- findNodesInSelection: function(nodeTypes) {
- var ranges = this.getOwnRanges(),
- nodes = [], curNodes;
- for (var i = 0, maxi = ranges.length; i < maxi; i++) {
- curNodes = ranges[i].getNodes([1], function(node) {
- return wysihtml5.lang.array(nodeTypes).contains(node.nodeName);
- });
- nodes = nodes.concat(curNodes);
- }
- return nodes;
- },
-
- filterElements: function(filter) {
- var ranges = this.getOwnRanges(),
- nodes = [], curNodes;
-
- for (var i = 0, maxi = ranges.length; i < maxi; i++) {
- curNodes = ranges[i].getNodes([1], function(element){
- return filter(element, ranges[i]);
- });
- nodes = nodes.concat(curNodes);
- }
- return nodes;
- },
-
- containsUneditable: function() {
- var uneditables = this.getOwnUneditables(),
- selection = this.getSelection();
-
- for (var i = 0, maxi = uneditables.length; i < maxi; i++) {
- if (selection.containsNode(uneditables[i])) {
- return true;
- }
- }
-
- return false;
- },
-
- // Deletes selection contents making sure uneditables/unselectables are not partially deleted
- // Triggers wysihtml5:uneditable:delete custom event on all deleted uneditables if customevents suppoorted
- deleteContents: function() {
- var range = this.getRange();
- this.deleteRangeContents(range);
- this.setSelection(range);
- },
-
- // Makes sure all uneditable sare notified before deleting contents
- deleteRangeContents: function (range) {
- var startParent, endParent, uneditables, ev;
-
- if (this.unselectableClass) {
- if ((startParent = wysihtml5.dom.getParentElement(range.startContainer, { query: "." + this.unselectableClass }, false, this.contain))) {
- range.setStartBefore(startParent);
- }
- if ((endParent = wysihtml5.dom.getParentElement(range.endContainer, { query: "." + this.unselectableClass }, false, this.contain))) {
- range.setEndAfter(endParent);
- }
-
- // If customevents present notify uneditable elements of being deleted
- uneditables = range.getNodes([1], (function (node) {
- return wysihtml5.dom.hasClass(node, this.unselectableClass);
- }).bind(this));
- for (var i = uneditables.length; i--;) {
- try {
- ev = new CustomEvent("wysihtml5:uneditable:delete");
- uneditables[i].dispatchEvent(ev);
- } catch (err) {}
- }
- }
- range.deleteContents();
- },
-
- getCaretNode: function () {
- var selection = this.getSelection();
- return (selection && selection.anchorNode) ? getRangeNode(selection.anchorNode, selection.anchorOffset) : null;
- },
-
- getPreviousNode: function(node, ignoreEmpty) {
- var displayStyle;
- if (!node) {
- var selection = this.getSelection();
- node = (selection && selection.anchorNode) ? getRangeNode(selection.anchorNode, selection.anchorOffset) : null;
- }
-
- if (node === this.contain) {
- return false;
- }
-
- var ret = node.previousSibling,
- parent;
-
- if (ret === this.contain) {
- return false;
- }
-
- if (ret && ret.nodeType !== 3 && ret.nodeType !== 1) {
- // do not count comments and other node types
- ret = this.getPreviousNode(ret, ignoreEmpty);
- } else if (ret && ret.nodeType === 3 && (/^\s*$/).test(ret.textContent)) {
- // do not count empty textnodes as previous nodes
- ret = this.getPreviousNode(ret, ignoreEmpty);
- } else if (ignoreEmpty && ret && ret.nodeType === 1) {
- // Do not count empty nodes if param set.
- // Contenteditable tends to bypass and delete these silently when deleting with caret when element is inline-like
- displayStyle = wysihtml5.dom.getStyle("display").from(ret);
- if (
- !wysihtml5.lang.array(["BR", "HR", "IMG"]).contains(ret.nodeName) &&
- !wysihtml5.lang.array(["block", "inline-block", "flex", "list-item", "table"]).contains(displayStyle) &&
- (/^[\s]*$/).test(ret.innerHTML)
- ) {
- ret = this.getPreviousNode(ret, ignoreEmpty);
- }
- } else if (!ret && node !== this.contain) {
- parent = node.parentNode;
- if (parent !== this.contain) {
- ret = this.getPreviousNode(parent, ignoreEmpty);
- }
- }
-
- return (ret !== this.contain) ? ret : false;
- },
-
- // Gather info about caret location (caret node, previous and next node)
- getNodesNearCaret: function() {
- if (!this.isCollapsed()) {
- throw "Selection must be caret when using selection.getNodesNearCaret()";
- }
-
- var r = this.getOwnRanges(),
- caretNode, prevNode, nextNode, offset;
-
- if (r && r.length > 0) {
- if (r[0].startContainer.nodeType === 1) {
- caretNode = r[0].startContainer.childNodes[r[0].startOffset - 1];
- if (!caretNode && r[0].startOffset === 0) {
- // Is first position before all nodes
- nextNode = r[0].startContainer.childNodes[0];
- } else if (caretNode) {
- prevNode = caretNode.previousSibling;
- nextNode = caretNode.nextSibling;
- }
- } else {
- if (r[0].startOffset === 0 && r[0].startContainer.previousSibling) {
- caretNode = r[0].startContainer.previousSibling;
- if (caretNode.nodeType === 3) {
- offset = caretNode.data.length;
- }
- } else {
- caretNode = r[0].startContainer;
- offset = r[0].startOffset;
- }
- prevNode = caretNode.previousSibling;
- nextNode = caretNode.nextSibling;
- }
-
- return {
- "caretNode": caretNode,
- "prevNode": prevNode,
- "nextNode": nextNode,
- "textOffset": offset
- };
- }
-
- return null;
- },
-
- getSelectionParentsByTag: function(tagName) {
- var nodes = this.getSelectedOwnNodes(),
- curEl, parents = [];
-
- for (var i = 0, maxi = nodes.length; i < maxi; i++) {
- curEl = (nodes[i].nodeName && nodes[i].nodeName === 'LI') ? nodes[i] : wysihtml5.dom.getParentElement(nodes[i], { query: 'li'}, false, this.contain);
- if (curEl) {
- parents.push(curEl);
- }
- }
- return (parents.length) ? parents : null;
- },
-
- getRangeToNodeEnd: function() {
- if (this.isCollapsed()) {
- var range = this.getRange(),
- sNode = range.startContainer,
- pos = range.startOffset,
- lastR = rangy.createRange(this.doc);
-
- lastR.selectNodeContents(sNode);
- lastR.setStart(sNode, pos);
- return lastR;
- }
- },
-
- caretIsLastInSelection: function() {
- var r = rangy.createRange(this.doc),
- s = this.getSelection(),
- endc = this.getRangeToNodeEnd().cloneContents(),
- endtxt = endc.textContent;
-
- return (/^\s*$/).test(endtxt);
- },
-
- caretIsFirstInSelection: function(includeLineBreaks) {
- var r = rangy.createRange(this.doc),
- s = this.getSelection(),
- range = this.getRange(),
- startNode = getRangeNode(range.startContainer, range.startOffset);
-
- if (startNode) {
- if (startNode.nodeType === wysihtml5.TEXT_NODE) {
- if (!startNode.parentNode) {
- return false;
- }
- if (!this.isCollapsed() || (startNode.parentNode.firstChild !== startNode && !wysihtml5.dom.domNode(startNode.previousSibling).is.block())) {
- return false;
- }
- var ws = this.win.getComputedStyle(startNode.parentNode).whiteSpace;
- return (ws === "pre" || ws === "pre-wrap") ? range.startOffset === 0 : (/^\s*$/).test(startNode.data.substr(0,range.startOffset));
- } else if (includeLineBreaks && wysihtml5.dom.domNode(startNode).is.lineBreak()) {
- return true;
- } else {
- r.selectNodeContents(this.getRange().commonAncestorContainer);
- r.collapse(true);
- return (this.isCollapsed() && (r.startContainer === s.anchorNode || r.endContainer === s.anchorNode) && r.startOffset === s.anchorOffset);
- }
- }
- },
-
- caretIsInTheBeginnig: function(ofNode) {
- var selection = this.getSelection(),
- node = selection.anchorNode,
- offset = selection.anchorOffset;
- if (ofNode && node) {
- return (offset === 0 && (node.nodeName && node.nodeName === ofNode.toUpperCase() || wysihtml5.dom.getParentElement(node.parentNode, { query: ofNode }, 1)));
- } else if (node) {
- return (offset === 0 && !this.getPreviousNode(node, true));
- }
- },
-
- // Returns object describing node/text before selection
- // If includePrevLeaves is true returns also previous last leaf child if selection is in the beginning of current node
- getBeforeSelection: function(includePrevLeaves) {
- var sel = this.getSelection(),
- startNode = (sel.isBackwards()) ? sel.focusNode : sel.anchorNode,
- startOffset = (sel.isBackwards()) ? sel.focusOffset : sel.anchorOffset,
- rng = this.createRange(), endNode, inTmpCaret;
-
- // If start is textnode and all is whitespace before caret. Set start offset to 0
- if (startNode && startNode.nodeType === 3 && (/^\s*$/).test(startNode.data.slice(0, startOffset))) {
- startOffset = 0;
- }
-
- // Escape temproray helper nodes if selection in them
- inTmpCaret = wysihtml5.dom.getParentElement(startNode, { query: '._wysihtml5-temp-caret-fix' }, 1);
- if (inTmpCaret) {
- startNode = inTmpCaret.parentNode;
- startOffset = Array.prototype.indexOf.call(startNode.childNodes, inTmpCaret);
- }
-
- if (startNode) {
- if (startOffset > 0) {
- if (startNode.nodeType === 3) {
- rng.setStart(startNode, 0);
- rng.setEnd(startNode, startOffset);
- return {
- type: "text",
- range: rng,
- offset : startOffset,
- node: startNode
- };
- } else {
- rng.setStartBefore(startNode.childNodes[0]);
- endNode = startNode.childNodes[startOffset - 1];
- rng.setEndAfter(endNode);
- return {
- type: "element",
- range: rng,
- offset : startOffset,
- node: endNode
- };
- }
- } else {
- rng.setStartAndEnd(startNode, 0);
-
- if (includePrevLeaves) {
- var prevNode = this.getPreviousNode(startNode, true),
- prevLeaf = null;
-
- if(prevNode) {
- if (prevNode.nodeType === 1 && wysihtml5.dom.hasClass(prevNode, this.unselectableClass)) {
- prevLeaf = prevNode;
- } else {
- prevLeaf = wysihtml5.dom.domNode(prevNode).lastLeafNode();
- }
- }
-
- if (prevLeaf) {
- return {
- type: "leafnode",
- range: rng,
- offset : startOffset,
- node: prevLeaf
- };
- }
- }
-
- return {
- type: "none",
- range: rng,
- offset : startOffset,
- node: startNode
- };
- }
- }
- return null;
- },
-
- // TODO: Figure out a method from following 2 that would work universally
- executeAndRestoreRangy: function(method, restoreScrollPosition) {
- var sel = rangy.saveSelection(this.win);
- if (!sel) {
- method();
- } else {
- try {
- method();
- } catch(e) {
- setTimeout(function() { throw e; }, 0);
- }
- }
- rangy.restoreSelection(sel);
- },
-
- // TODO: has problems in chrome 12. investigate block level and uneditable area inbetween
- executeAndRestore: function(method, restoreScrollPosition) {
- var body = this.doc.body,
- oldScrollTop = restoreScrollPosition && body.scrollTop,
- oldScrollLeft = restoreScrollPosition && body.scrollLeft,
- className = "_wysihtml5-temp-placeholder",
- placeholderHtml = '' + wysihtml5.INVISIBLE_SPACE + ' ',
- range = this.getRange(true),
- caretPlaceholder,
- newCaretPlaceholder,
- nextSibling, prevSibling,
- node, node2, range2,
- newRange;
-
- // Nothing selected, execute and say goodbye
- if (!range) {
- method(body, body);
- return;
- }
-
- if (!range.collapsed) {
- range2 = range.cloneRange();
- node2 = range2.createContextualFragment(placeholderHtml);
- range2.collapse(false);
- range2.insertNode(node2);
- range2.detach();
- }
-
- node = range.createContextualFragment(placeholderHtml);
- range.insertNode(node);
-
- if (node2) {
- caretPlaceholder = this.contain.querySelectorAll("." + className);
- range.setStartBefore(caretPlaceholder[0]);
- range.setEndAfter(caretPlaceholder[caretPlaceholder.length -1]);
- }
- this.setSelection(range);
-
- // Make sure that a potential error doesn't cause our placeholder element to be left as a placeholder
- try {
- method(range.startContainer, range.endContainer);
- } catch(e) {
- setTimeout(function() { throw e; }, 0);
- }
- caretPlaceholder = this.contain.querySelectorAll("." + className);
- if (caretPlaceholder && caretPlaceholder.length) {
- newRange = rangy.createRange(this.doc);
- nextSibling = caretPlaceholder[0].nextSibling;
- if (caretPlaceholder.length > 1) {
- prevSibling = caretPlaceholder[caretPlaceholder.length -1].previousSibling;
- }
- if (prevSibling && nextSibling) {
- newRange.setStartBefore(nextSibling);
- newRange.setEndAfter(prevSibling);
- } else {
- newCaretPlaceholder = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
- dom.insert(newCaretPlaceholder).after(caretPlaceholder[0]);
- newRange.setStartBefore(newCaretPlaceholder);
- newRange.setEndAfter(newCaretPlaceholder);
- }
- this.setSelection(newRange);
- for (var i = caretPlaceholder.length; i--;) {
- caretPlaceholder[i].parentNode.removeChild(caretPlaceholder[i]);
- }
-
- } else {
- // fallback for when all hell breaks loose
- this.contain.focus();
- }
-
- if (restoreScrollPosition) {
- body.scrollTop = oldScrollTop;
- body.scrollLeft = oldScrollLeft;
- }
-
- // Remove it again, just to make sure that the placeholder is definitely out of the dom tree
- try {
- caretPlaceholder.parentNode.removeChild(caretPlaceholder);
- } catch(e2) {}
- },
-
- set: function(node, offset) {
- var newRange = rangy.createRange(this.doc);
- newRange.setStart(node, offset || 0);
- this.setSelection(newRange);
- },
-
- /**
- * Insert html at the caret or selection position and move the cursor after the inserted html
- * Replaces selection content if present
- *
- * @param {String} html HTML string to insert
- * @example
- * selection.insertHTML("foobar
");
- */
- insertHTML: function(html) {
- var range = this.getRange(),
- node = this.doc.createElement('DIV'),
- fragment = this.doc.createDocumentFragment(),
- lastChild, lastEditorElement;
-
- if (range) {
- range.deleteContents();
- node.innerHTML = html;
- lastChild = node.lastChild;
-
- while (node.firstChild) {
- fragment.appendChild(node.firstChild);
- }
- range.insertNode(fragment);
-
- lastEditorElement = this.contain.lastChild;
- while (lastEditorElement && lastEditorElement.nodeType === 3 && lastEditorElement.previousSibling && (/^\s*$/).test(lastEditorElement.data)) {
- lastEditorElement = lastEditorElement.previousSibling;
- }
-
- if (lastChild) {
- // fixes some pad cases mostly on webkit where last nr is needed
- if (lastEditorElement && lastChild === lastEditorElement && lastChild.nodeType === 1) {
- this.contain.appendChild(this.doc.createElement('br'));
- }
- this.setAfter(lastChild);
- }
- }
- },
-
- /**
- * Insert a node at the caret position and move the cursor behind it
- *
- * @param {Object} node HTML string to insert
- * @example
- * selection.insertNode(document.createTextNode("foobar"));
- */
- insertNode: function(node) {
- var range = this.getRange();
- if (range) {
- range.insertNode(node);
- }
- },
-
- canAppendChild: function (node) {
- var anchorNode, anchorNodeTagNameLower,
- voidElements = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"],
- range = this.getRange();
-
- anchorNode = node || range.startContainer;
-
- if (anchorNode) {
- anchorNodeTagNameLower = (anchorNode.tagName || anchorNode.nodeName).toLowerCase();
- }
-
- return voidElements.indexOf(anchorNodeTagNameLower) === -1;
- },
-
- splitElementAtCaret: function (element, insertNode) {
- var sel = this.getSelection(),
- range, contentAfterRangeStart,
- firstChild, lastChild, childNodes;
-
- if (sel.rangeCount > 0) {
- range = sel.getRangeAt(0).cloneRange(); // Create a copy of the selection range to work with
-
- range.setEndAfter(element); // Place the end of the range after the element
- contentAfterRangeStart = range.extractContents(); // Extract the contents of the element after the caret into a fragment
-
- childNodes = contentAfterRangeStart.childNodes;
-
- // Empty elements are cleaned up from extracted content
- for (var i = childNodes.length; i --;) {
- if (!wysihtml5.dom.domNode(childNodes[i]).is.visible()) {
- contentAfterRangeStart.removeChild(childNodes[i]);
- }
- }
-
- element.parentNode.insertBefore(contentAfterRangeStart, element.nextSibling);
-
- if (insertNode) {
- firstChild = insertNode.firstChild || insertNode;
- lastChild = insertNode.lastChild || insertNode;
-
- element.parentNode.insertBefore(insertNode, element.nextSibling);
-
- // Select inserted node contents
- if (firstChild && lastChild) {
- range.setStartBefore(firstChild);
- range.setEndAfter(lastChild);
- this.setSelection(range);
- }
- } else {
- range.setStartAfter(element);
- range.setEndAfter(element);
- }
-
- if (!wysihtml5.dom.domNode(element).is.visible()) {
- if (wysihtml5.dom.getTextContent(element) === '') {
- element.parentNode.removeChild(element);
- } else {
- element.parentNode.replaceChild(this.doc.createTextNode(" "), element);
- }
- }
-
-
- }
- },
-
- /**
- * Wraps current selection with the given node
- *
- * @param {Object} node The node to surround the selected elements with
- */
- surround: function(nodeOptions) {
- var ranges = this.getOwnRanges(),
- node, nodes = [];
- if (ranges.length == 0) {
- return nodes;
- }
-
- for (var i = ranges.length; i--;) {
- node = this.doc.createElement(nodeOptions.nodeName);
- nodes.push(node);
- if (nodeOptions.className) {
- node.className = nodeOptions.className;
- }
- if (nodeOptions.cssStyle) {
- node.setAttribute('style', nodeOptions.cssStyle);
- }
- try {
- // This only works when the range boundaries are not overlapping other elements
- ranges[i].surroundContents(node);
- this.selectNode(node);
- } catch(e) {
- // fallback
- node.appendChild(ranges[i].extractContents());
- ranges[i].insertNode(node);
- }
- }
- return nodes;
- },
-
- /**
- * Scroll the current caret position into the view
- * FIXME: This is a bit hacky, there might be a smarter way of doing this
- *
- * @example
- * selection.scrollIntoView();
- */
- scrollIntoView: function() {
- var doc = this.doc,
- tolerance = 5, // px
- hasScrollBars = doc.documentElement.scrollHeight > doc.documentElement.offsetHeight,
- tempElement = doc._wysihtml5ScrollIntoViewElement = doc._wysihtml5ScrollIntoViewElement || (function() {
- var element = doc.createElement("span");
- // The element needs content in order to be able to calculate it's position properly
- element.innerHTML = wysihtml5.INVISIBLE_SPACE;
- return element;
- })(),
- offsetTop;
-
- if (hasScrollBars) {
- this.insertNode(tempElement);
- offsetTop = _getCumulativeOffsetTop(tempElement);
- tempElement.parentNode.removeChild(tempElement);
- if (offsetTop >= (doc.body.scrollTop + doc.documentElement.offsetHeight - tolerance)) {
- doc.body.scrollTop = offsetTop;
- }
- }
- },
-
- /**
- * Select line where the caret is in
- */
- selectLine: function() {
- var r = rangy.createRange();
- if (wysihtml5.browser.supportsSelectionModify()) {
- this._selectLine_W3C();
- } else if (r.nativeRange && r.nativeRange.getBoundingClientRect) {
- // For IE Edge as it ditched the old api and did not fully implement the new one (as expected)
- this._selectLineUniversal();
- }
- },
-
- includeRangyRangeHelpers: function() {
- var s = this.getSelection(),
- r = s.getRangeAt(0),
- isHelperNode = function(node) {
- return (node && node.nodeType === 1 && node.classList.contains('rangySelectionBoundary'));
- },
- getNodeLength = function (node) {
- if (node.nodeType === 1) {
- return node.childNodes && node.childNodes.length || 0;
- } else {
- return node.data && node.data.length || 0;
- }
- },
- anode = s.anchorNode.nodeType === 1 ? s.anchorNode.childNodes[s.anchorOffset] : s.anchorNode,
- fnode = s.focusNode.nodeType === 1 ? s.focusNode.childNodes[s.focusOffset] : s.focusNode;
-
- if (fnode && s.focusOffset === getNodeLength(fnode) && fnode.nextSibling && isHelperNode(fnode.nextSibling)) {
- r.setEndAfter(fnode.nextSibling);
- }
- if (anode && s.anchorOffset === 0 && anode.previousSibling && isHelperNode(anode.previousSibling)) {
- r.setStartBefore(anode.previousSibling);
- }
- r.select();
- },
-
- /**
- * See https://developer.mozilla.org/en/DOM/Selection/modify
- */
- _selectLine_W3C: function() {
- var selection = this.win.getSelection(),
- initialBoundry = [selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset];
-
- selection.modify("move", "left", "lineboundary");
- selection.modify("extend", "right", "lineboundary");
-
- // IF lineboundary extending did not change selection try universal fallback (FF fails sometimes without a reason)
- if (selection.anchorNode === initialBoundry[0] &&
- selection.anchorOffset === initialBoundry[1] &&
- selection.focusNode === initialBoundry[2] &&
- selection.focusOffset === initialBoundry[3]
- ) {
- this._selectLineUniversal();
- } else {
- this.includeRangyRangeHelpers();
- }
- },
-
- // collapses selection to current line beginning or end
- toLineBoundary: function (location, collapse) {
- collapse = (typeof collapse === 'undefined') ? false : collapse;
- if (wysihtml5.browser.supportsSelectionModify()) {
- var selection = this.win.getSelection();
-
- selection.modify("extend", location, "lineboundary");
- if (collapse) {
- if (location === "left") {
- selection.collapseToStart();
- } else if (location === "right") {
- selection.collapseToEnd();
- }
- }
- }
- },
-
- getRangeRect: function(r) {
- var textNode = this.doc.createTextNode("i"),
- testNode = this.doc.createTextNode("i"),
- rect, cr;
-
- /*testNode.style.visibility = "hidden";
- testNode.style.width = "0px";
- testNode.style.display = "inline-block";
- testNode.style.overflow = "hidden";
- testNode.appendChild(textNode);*/
-
- if (r.collapsed) {
- r.insertNode(testNode);
- r.selectNode(testNode);
- rect = r.nativeRange.getBoundingClientRect();
- r.deleteContents();
-
- } else {
- rect = r.nativeRange.getBoundingClientRect();
- }
-
- return rect;
-
- },
-
- _selectLineUniversal: function() {
- var s = this.getSelection(),
- r = s.getRangeAt(0),
- rect,
- startRange, endRange, testRange,
- count = 0,
- amount, testRect, found,
- that = this,
- isLineBreakingElement = function(el) {
- return el && el.nodeType === 1 && (that.win.getComputedStyle(el).display === "block" || wysihtml5.lang.array(['BR', 'HR']).contains(el.nodeName));
- },
- prevNode = function(node) {
- var pnode = node;
- if (pnode) {
- while (pnode && ((pnode.nodeType === 1 && pnode.classList.contains('rangySelectionBoundary')) || (pnode.nodeType === 3 && (/^\s*$/).test(pnode.data)))) {
- pnode = pnode.previousSibling;
- }
- }
- return pnode;
- };
-
- startRange = r.cloneRange();
- endRange = r.cloneRange();
-
- if (r.collapsed) {
- // Collapsed state can not have a bounding rect. Thus need to expand it at least by 1 character first while not crossing line boundary
- // TODO: figure out a shorter and more readable way
- if (r.startContainer.nodeType === 3 && r.startOffset < r.startContainer.data.length) {
- r.moveEnd('character', 1);
- } else if (r.startContainer.nodeType === 1 && r.startContainer.childNodes[r.startOffset] && r.startContainer.childNodes[r.startOffset].nodeType === 3 && r.startContainer.childNodes[r.startOffset].data.length > 0) {
- r.moveEnd('character', 1);
- } else if (
- r.startOffset > 0 &&
- (
- r.startContainer.nodeType === 3 ||
- (
- r.startContainer.nodeType === 1 &&
- !isLineBreakingElement(prevNode(r.startContainer.childNodes[r.startOffset - 1]))
- )
- )
- ) {
- r.moveStart('character', -1);
- }
- }
- if (!r.collapsed) {
- r.insertNode(this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE));
- }
-
- // Is probably just empty line as can not be expanded
- rect = r.nativeRange.getBoundingClientRect();
- // If startnode is not line break allready move the start position of range by -1 character until clientRect top changes;
- do {
- amount = r.moveStart('character', -1);
- testRect = r.nativeRange.getBoundingClientRect();
-
- if (!testRect || Math.floor(testRect.top) !== Math.floor(rect.top)) {
- r.moveStart('character', 1);
- found = true;
- }
- count++;
- } while (amount !== 0 && !found && count < 2000);
- count = 0;
- found = false;
- rect = r.nativeRange.getBoundingClientRect();
-
- if (r.endContainer !== this.contain || (this.contain.lastChild && this.contain.childNodes[r.endOffset] !== this.contain.lastChild)) {
- do {
- amount = r.moveEnd('character', 1);
- testRect = r.nativeRange.getBoundingClientRect();
- if (!testRect || Math.floor(testRect.bottom) !== Math.floor(rect.bottom)) {
- r.moveEnd('character', -1);
-
- // Fix a IE line end marked by linebreak element although caret is before it
- // If causes problems should be changed to be applied only to IE
- if (r.endContainer && r.endContainer.nodeType === 1 && r.endContainer.childNodes[r.endOffset] && r.endContainer.childNodes[r.endOffset].nodeType === 1 && r.endContainer.childNodes[r.endOffset].nodeName === "BR" && r.endContainer.childNodes[r.endOffset].previousSibling) {
- if (r.endContainer.childNodes[r.endOffset].previousSibling.nodeType === 1) {
- r.setEnd(r.endContainer.childNodes[r.endOffset].previousSibling, r.endContainer.childNodes[r.endOffset].previousSibling.childNodes.length);
- } else if (r.endContainer.childNodes[r.endOffset].previousSibling.nodeType === 3) {
- r.setEnd(r.endContainer.childNodes[r.endOffset].previousSibling, r.endContainer.childNodes[r.endOffset].previousSibling.data.length);
- }
- }
- found = true;
- }
- count++;
- } while (amount !== 0 && !found && count < 2000);
- }
- r.select();
- this.includeRangyRangeHelpers();
- },
-
- getText: function() {
- var selection = this.getSelection();
- return selection ? selection.toString() : "";
- },
-
- getNodes: function(nodeType, filter) {
- var range = this.getRange();
- if (range) {
- return range.getNodes(Array.isArray(nodeType) ? nodeType : [nodeType], filter);
- } else {
- return [];
- }
- },
-
- // Gets all the elements in selection with nodeType
- // Ignores the elements not belonging to current editable area
- // If filter is defined nodes must pass the filter function with true to be included in list
- getOwnNodes: function(nodeType, filter, splitBounds) {
- var ranges = this.getOwnRanges(),
- nodes = [];
- for (var r = 0, rmax = ranges.length; r < rmax; r++) {
- if (ranges[r]) {
- if (splitBounds) {
- ranges[r].splitBoundaries();
- }
- nodes = nodes.concat(ranges[r].getNodes(Array.isArray(nodeType) ? nodeType : [nodeType], filter));
- }
- }
-
- return nodes;
- },
-
- fixRangeOverflow: function(range) {
- if (this.contain && this.contain.firstChild && range) {
- var containment = range.compareNode(this.contain);
- if (containment !== 2) {
- if (containment === 1) {
- range.setStartBefore(this.contain.firstChild);
- }
- if (containment === 0) {
- range.setEndAfter(this.contain.lastChild);
- }
- if (containment === 3) {
- range.setStartBefore(this.contain.firstChild);
- range.setEndAfter(this.contain.lastChild);
- }
- } else if (this._detectInlineRangeProblems(range)) {
- var previousElementSibling = range.endContainer.previousElementSibling;
- if (previousElementSibling) {
- range.setEnd(previousElementSibling, this._endOffsetForNode(previousElementSibling));
- }
- }
- }
- },
-
- _endOffsetForNode: function(node) {
- var range = document.createRange();
- range.selectNodeContents(node);
- return range.endOffset;
- },
-
- _detectInlineRangeProblems: function(range) {
- var position = dom.compareDocumentPosition(range.startContainer, range.endContainer);
- return (
- range.endOffset == 0 &&
- position & 4 //Node.DOCUMENT_POSITION_FOLLOWING
- );
- },
-
- getRange: function(dontFix) {
- var selection = this.getSelection(),
- range = selection && selection.rangeCount && selection.getRangeAt(0);
-
- if (dontFix !== true) {
- this.fixRangeOverflow(range);
- }
-
- return range;
- },
-
- getOwnUneditables: function() {
- var allUneditables = dom.query(this.contain, '.' + this.unselectableClass),
- deepUneditables = dom.query(allUneditables, '.' + this.unselectableClass);
-
- return wysihtml5.lang.array(allUneditables).without(deepUneditables);
- },
-
- // Returns an array of ranges that belong only to this editable
- // Needed as uneditable block in contenteditabel can split range into pieces
- // If manipulating content reverse loop is usually needed as manipulation can shift subsequent ranges
- getOwnRanges: function() {
- var ranges = [],
- r = this.getRange(),
- tmpRanges;
-
- if (r) { ranges.push(r); }
-
- if (this.unselectableClass && this.contain && r) {
- var uneditables = this.getOwnUneditables(),
- tmpRange;
- if (uneditables.length > 0) {
- for (var i = 0, imax = uneditables.length; i < imax; i++) {
- tmpRanges = [];
- for (var j = 0, jmax = ranges.length; j < jmax; j++) {
- if (ranges[j]) {
- switch (ranges[j].compareNode(uneditables[i])) {
- case 2:
- // all selection inside uneditable. remove
- break;
- case 3:
- //section begins before and ends after uneditable. spilt
- tmpRange = ranges[j].cloneRange();
- tmpRange.setEndBefore(uneditables[i]);
- tmpRanges.push(tmpRange);
-
- tmpRange = ranges[j].cloneRange();
- tmpRange.setStartAfter(uneditables[i]);
- tmpRanges.push(tmpRange);
- break;
- default:
- // in all other cases uneditable does not touch selection. dont modify
- tmpRanges.push(ranges[j]);
- }
- }
- ranges = tmpRanges;
- }
- }
- }
- }
- return ranges;
- },
-
- getSelection: function() {
- return rangy.getSelection(this.win);
- },
-
- // Sets selection in document to a given range
- // Set selection method detects if it fails to set any selection in document and returns null on fail
- // (especially needed in webkit where some ranges just can not create selection for no reason)
- setSelection: function(range) {
- var selection = rangy.getSelection(this.win);
- selection.setSingleRange(range);
- return (selection && selection.anchorNode && selection.focusNode) ? selection : null;
- },
-
-
-
- // Webkit has an ancient error of not selecting all contents when uneditable block element is first or last in editable area
- selectAll: function() {
- var range = this.createRange(),
- composer = this.composer,
- that = this,
- blankEndNode = getWebkitSelectionFixNode(this.composer.element),
- blankStartNode = getWebkitSelectionFixNode(this.composer.element),
- s;
-
- var doSelect = function() {
- range.setStart(composer.element, 0);
- range.setEnd(composer.element, composer.element.childNodes.length);
- s = that.setSelection(range);
- };
-
- var notSelected = function() {
- return !s || (s.nativeSelection && s.nativeSelection.type && (s.nativeSelection.type === "Caret" || s.nativeSelection.type === "None"));
- }
-
- wysihtml5.dom.removeInvisibleSpaces(this.composer.element);
- doSelect();
-
- if (this.composer.element.firstChild && notSelected()) {
- // Try fixing end
- this.composer.element.appendChild(blankEndNode);
- doSelect();
-
- if (notSelected()) {
- // Remove end fix
- blankEndNode.parentNode.removeChild(blankEndNode);
-
- // Try fixing beginning
- this.composer.element.insertBefore(blankStartNode, this.composer.element.firstChild);
- doSelect();
-
- if (notSelected()) {
- // Try fixing both
- this.composer.element.appendChild(blankEndNode);
- doSelect();
- }
- }
- }
- },
-
- createRange: function() {
- return rangy.createRange(this.doc);
- },
-
- isCollapsed: function() {
- return this.getSelection().isCollapsed;
- },
-
- getHtml: function() {
- return this.getSelection().toHtml();
- },
-
- getPlainText: function () {
- return this.getSelection().toString();
- },
-
- isEndToEndInNode: function(nodeNames) {
- var range = this.getRange(),
- parentElement = range.commonAncestorContainer,
- startNode = range.startContainer,
- endNode = range.endContainer;
-
-
- if (parentElement.nodeType === wysihtml5.TEXT_NODE) {
- parentElement = parentElement.parentNode;
- }
-
- if (startNode.nodeType === wysihtml5.TEXT_NODE && !(/^\s*$/).test(startNode.data.substr(range.startOffset))) {
- return false;
- }
-
- if (endNode.nodeType === wysihtml5.TEXT_NODE && !(/^\s*$/).test(endNode.data.substr(range.endOffset))) {
- return false;
- }
-
- while (startNode && startNode !== parentElement) {
- if (startNode.nodeType !== wysihtml5.TEXT_NODE && !wysihtml5.dom.contains(parentElement, startNode)) {
- return false;
- }
- if (wysihtml5.dom.domNode(startNode).prev({ignoreBlankTexts: true})) {
- return false;
- }
- startNode = startNode.parentNode;
- }
-
- while (endNode && endNode !== parentElement) {
- if (endNode.nodeType !== wysihtml5.TEXT_NODE && !wysihtml5.dom.contains(parentElement, endNode)) {
- return false;
- }
- if (wysihtml5.dom.domNode(endNode).next({ignoreBlankTexts: true})) {
- return false;
- }
- endNode = endNode.parentNode;
- }
-
- return (wysihtml5.lang.array(nodeNames).contains(parentElement.nodeName)) ? parentElement : false;
- },
-
- isInThisEditable: function() {
- var sel = this.getSelection(),
- fnode = sel.focusNode,
- anode = sel.anchorNode;
-
- // In IE node contains will not work for textnodes, thus taking parentNode
- if (fnode && fnode.nodeType !== 1) {
- fnode = fnode.parentNode;
- }
-
- if (anode && anode.nodeType !== 1) {
- anode = anode.parentNode;
- }
-
- return anode && fnode &&
- (wysihtml5.dom.contains(this.composer.element, fnode) || this.composer.element === fnode) &&
- (wysihtml5.dom.contains(this.composer.element, anode) || this.composer.element === anode);
- },
-
- deselect: function() {
- var sel = this.getSelection();
- sel && sel.removeAllRanges();
- }
- });
-
-})(wysihtml5);
-;/**
- * Inspired by the rangy CSS Applier module written by Tim Down and licensed under the MIT license.
- * http://code.google.com/p/rangy/
- *
- * changed in order to be able ...
- * - to use custom tags
- * - to detect and replace similar css classes via reg exp
- */
-(function(wysihtml5, rangy) {
- var defaultTagName = "span";
-
- var REG_EXP_WHITE_SPACE = /\s+/g;
-
- function hasClass(el, cssClass, regExp) {
- if (!el.className) {
- return false;
- }
-
- var matchingClassNames = el.className.match(regExp) || [];
- return matchingClassNames[matchingClassNames.length - 1] === cssClass;
- }
-
- function hasStyleAttr(el, regExp) {
- if (!el.getAttribute || !el.getAttribute('style')) {
- return false;
- }
- var matchingStyles = el.getAttribute('style').match(regExp);
- return (el.getAttribute('style').match(regExp)) ? true : false;
- }
-
- function addStyle(el, cssStyle, regExp) {
- if (el.getAttribute('style')) {
- removeStyle(el, regExp);
- if (el.getAttribute('style') && !(/^\s*$/).test(el.getAttribute('style'))) {
- el.setAttribute('style', cssStyle + ";" + el.getAttribute('style'));
- } else {
- el.setAttribute('style', cssStyle);
- }
- } else {
- el.setAttribute('style', cssStyle);
- }
- }
-
- function addClass(el, cssClass, regExp) {
- if (el.className) {
- removeClass(el, regExp);
- el.className += " " + cssClass;
- } else {
- el.className = cssClass;
- }
- }
-
- function removeClass(el, regExp) {
- if (el.className) {
- el.className = el.className.replace(regExp, "");
- }
- }
-
- function removeStyle(el, regExp) {
- var s,
- s2 = [];
- if (el.getAttribute('style')) {
- s = el.getAttribute('style').split(';');
- for (var i = s.length; i--;) {
- if (!s[i].match(regExp) && !(/^\s*$/).test(s[i])) {
- s2.push(s[i]);
- }
- }
- if (s2.length) {
- el.setAttribute('style', s2.join(';'));
- } else {
- el.removeAttribute('style');
- }
- }
- }
-
- function getMatchingStyleRegexp(el, style) {
- var regexes = [],
- sSplit = style.split(';'),
- elStyle = el.getAttribute('style');
-
- if (elStyle) {
- elStyle = elStyle.replace(/\s/gi, '').toLowerCase();
- regexes.push(new RegExp("(^|\\s|;)" + style.replace(/\s/gi, '').replace(/([\(\)])/gi, "\\$1").toLowerCase().replace(";", ";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi, "\\s?rgb\\($1,\\s?$2,\\s?$3\\)"), "gi"));
-
- for (var i = sSplit.length; i-- > 0;) {
- if (!(/^\s*$/).test(sSplit[i])) {
- regexes.push(new RegExp("(^|\\s|;)" + sSplit[i].replace(/\s/gi, '').replace(/([\(\)])/gi, "\\$1").toLowerCase().replace(";", ";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi, "\\s?rgb\\($1,\\s?$2,\\s?$3\\)"), "gi"));
- }
- }
- for (var j = 0, jmax = regexes.length; j < jmax; j++) {
- if (elStyle.match(regexes[j])) {
- return regexes[j];
- }
- }
- }
-
- return false;
- }
-
- function isMatchingAllready(node, tags, style, className) {
- if (style) {
- return getMatchingStyleRegexp(node, style);
- } else if (className) {
- return wysihtml5.dom.hasClass(node, className);
- } else {
- return rangy.dom.arrayContains(tags, node.tagName.toLowerCase());
- }
- }
-
- function areMatchingAllready(nodes, tags, style, className) {
- for (var i = nodes.length; i--;) {
- if (!isMatchingAllready(nodes[i], tags, style, className)) {
- return false;
- }
- }
- return nodes.length ? true : false;
- }
-
- function removeOrChangeStyle(el, style, regExp) {
-
- var exactRegex = getMatchingStyleRegexp(el, style);
- if (exactRegex) {
- // adding same style value on property again removes style
- removeStyle(el, exactRegex);
- return "remove";
- } else {
- // adding new style value changes value
- addStyle(el, style, regExp);
- return "change";
- }
- }
-
- function hasSameClasses(el1, el2) {
- return el1.className.replace(REG_EXP_WHITE_SPACE, " ") == el2.className.replace(REG_EXP_WHITE_SPACE, " ");
- }
-
- function replaceWithOwnChildren(el) {
- var parent = el.parentNode;
- while (el.firstChild) {
- parent.insertBefore(el.firstChild, el);
- }
- parent.removeChild(el);
- }
-
- function elementsHaveSameNonClassAttributes(el1, el2) {
- if (el1.attributes.length != el2.attributes.length) {
- return false;
- }
- for (var i = 0, len = el1.attributes.length, attr1, attr2, name; i < len; ++i) {
- attr1 = el1.attributes[i];
- name = attr1.name;
- if (name != "class") {
- attr2 = el2.attributes.getNamedItem(name);
- if (attr1.specified != attr2.specified) {
- return false;
- }
- if (attr1.specified && attr1.nodeValue !== attr2.nodeValue) {
- return false;
- }
- }
- }
- return true;
- }
-
- function isSplitPoint(node, offset) {
- if (rangy.dom.isCharacterDataNode(node)) {
- if (offset == 0) {
- return !!node.previousSibling;
- } else if (offset == node.length) {
- return !!node.nextSibling;
- } else {
- return true;
- }
- }
-
- return offset > 0 && offset < node.childNodes.length;
- }
-
- function splitNodeAt(node, descendantNode, descendantOffset, container) {
- var newNode;
- if (rangy.dom.isCharacterDataNode(descendantNode)) {
- if (descendantOffset == 0) {
- descendantOffset = rangy.dom.getNodeIndex(descendantNode);
- descendantNode = descendantNode.parentNode;
- } else if (descendantOffset == descendantNode.length) {
- descendantOffset = rangy.dom.getNodeIndex(descendantNode) + 1;
- descendantNode = descendantNode.parentNode;
- } else {
- newNode = rangy.dom.splitDataNode(descendantNode, descendantOffset);
- }
- }
- if (!newNode) {
- if (!container || descendantNode !== container) {
-
- newNode = descendantNode.cloneNode(false);
- if (newNode.id) {
- newNode.removeAttribute("id");
- }
- var child;
- while ((child = descendantNode.childNodes[descendantOffset])) {
- newNode.appendChild(child);
- }
- rangy.dom.insertAfter(newNode, descendantNode);
-
- }
- }
- return (descendantNode == node) ? newNode : splitNodeAt(node, newNode.parentNode, rangy.dom.getNodeIndex(newNode), container);
- }
-
- function Merge(firstNode) {
- this.isElementMerge = (firstNode.nodeType == wysihtml5.ELEMENT_NODE);
- this.firstTextNode = this.isElementMerge ? firstNode.lastChild : firstNode;
- this.textNodes = [this.firstTextNode];
- }
-
- Merge.prototype = {
- doMerge: function() {
- var textBits = [], textNode, parent, text;
- for (var i = 0, len = this.textNodes.length; i < len; ++i) {
- textNode = this.textNodes[i];
- parent = textNode.parentNode;
- textBits[i] = textNode.data;
- if (i) {
- parent.removeChild(textNode);
- if (!parent.hasChildNodes()) {
- parent.parentNode.removeChild(parent);
- }
- }
- }
- this.firstTextNode.data = text = textBits.join("");
- return text;
- },
-
- getLength: function() {
- var i = this.textNodes.length, len = 0;
- while (i--) {
- len += this.textNodes[i].length;
- }
- return len;
- },
-
- toString: function() {
- var textBits = [];
- for (var i = 0, len = this.textNodes.length; i < len; ++i) {
- textBits[i] = "'" + this.textNodes[i].data + "'";
- }
- return "[Merge(" + textBits.join(",") + ")]";
- }
- };
-
- function HTMLApplier(tagNames, cssClass, similarClassRegExp, normalize, cssStyle, similarStyleRegExp, container) {
- this.tagNames = tagNames || [defaultTagName];
- this.cssClass = cssClass || ((cssClass === false) ? false : "");
- this.similarClassRegExp = similarClassRegExp;
- this.cssStyle = cssStyle || "";
- this.similarStyleRegExp = similarStyleRegExp;
- this.normalize = normalize;
- this.applyToAnyTagName = false;
- this.container = container;
- }
-
- HTMLApplier.prototype = {
- getAncestorWithClass: function(node) {
- var cssClassMatch;
- while (node) {
- cssClassMatch = this.cssClass ? hasClass(node, this.cssClass, this.similarClassRegExp) : (this.cssStyle !== "") ? false : true;
- if (node.nodeType == wysihtml5.ELEMENT_NODE && node.getAttribute("contenteditable") != "false" && rangy.dom.arrayContains(this.tagNames, node.tagName.toLowerCase()) && cssClassMatch) {
- return node;
- }
- node = node.parentNode;
- }
- return false;
- },
-
- // returns parents of node with given style attribute
- getAncestorWithStyle: function(node) {
- var cssStyleMatch;
- while (node) {
- cssStyleMatch = this.cssStyle ? hasStyleAttr(node, this.similarStyleRegExp) : false;
-
- if (node.nodeType == wysihtml5.ELEMENT_NODE && node.getAttribute("contenteditable") != "false" && rangy.dom.arrayContains(this.tagNames, node.tagName.toLowerCase()) && cssStyleMatch) {
- return node;
- }
- node = node.parentNode;
- }
- return false;
- },
-
- getMatchingAncestor: function(node) {
- var ancestor = this.getAncestorWithClass(node),
- matchType = false;
-
- if (!ancestor) {
- ancestor = this.getAncestorWithStyle(node);
- if (ancestor) {
- matchType = "style";
- }
- } else {
- if (this.cssStyle) {
- matchType = "class";
- }
- }
-
- return {
- "element": ancestor,
- "type": matchType
- };
- },
-
- // Normalizes nodes after applying a CSS class to a Range.
- postApply: function(textNodes, range) {
- var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
-
- var merges = [], currentMerge;
-
- var rangeStartNode = firstNode, rangeEndNode = lastNode;
- var rangeStartOffset = 0, rangeEndOffset = lastNode.length;
-
- var textNode, precedingTextNode;
-
- for (var i = 0, len = textNodes.length; i < len; ++i) {
- textNode = textNodes[i];
- precedingTextNode = null;
- if (textNode && textNode.parentNode) {
- precedingTextNode = this.getAdjacentMergeableTextNode(textNode.parentNode, false);
- }
- if (precedingTextNode) {
- if (!currentMerge) {
- currentMerge = new Merge(precedingTextNode);
- merges.push(currentMerge);
- }
- currentMerge.textNodes.push(textNode);
- if (textNode === firstNode) {
- rangeStartNode = currentMerge.firstTextNode;
- rangeStartOffset = rangeStartNode.length;
- }
- if (textNode === lastNode) {
- rangeEndNode = currentMerge.firstTextNode;
- rangeEndOffset = currentMerge.getLength();
- }
- } else {
- currentMerge = null;
- }
- }
- // Test whether the first node after the range needs merging
- if(lastNode && lastNode.parentNode) {
- var nextTextNode = this.getAdjacentMergeableTextNode(lastNode.parentNode, true);
- if (nextTextNode) {
- if (!currentMerge) {
- currentMerge = new Merge(lastNode);
- merges.push(currentMerge);
- }
- currentMerge.textNodes.push(nextTextNode);
- }
- }
- // Do the merges
- if (merges.length) {
- for (i = 0, len = merges.length; i < len; ++i) {
- merges[i].doMerge();
- }
- // Set the range boundaries
- range.setStart(rangeStartNode, rangeStartOffset);
- range.setEnd(rangeEndNode, rangeEndOffset);
- }
- },
-
- getAdjacentMergeableTextNode: function(node, forward) {
- var isTextNode = (node.nodeType == wysihtml5.TEXT_NODE);
- var el = isTextNode ? node.parentNode : node;
- var adjacentNode;
- var propName = forward ? "nextSibling" : "previousSibling";
- if (isTextNode) {
- // Can merge if the node's previous/next sibling is a text node
- adjacentNode = node[propName];
- if (adjacentNode && adjacentNode.nodeType == wysihtml5.TEXT_NODE) {
- return adjacentNode;
- }
- } else {
- // Compare element with its sibling
- adjacentNode = el[propName];
- if (adjacentNode && this.areElementsMergeable(node, adjacentNode)) {
- return adjacentNode[forward ? "firstChild" : "lastChild"];
- }
- }
- return null;
- },
-
- areElementsMergeable: function(el1, el2) {
- return rangy.dom.arrayContains(this.tagNames, (el1.tagName || "").toLowerCase())
- && rangy.dom.arrayContains(this.tagNames, (el2.tagName || "").toLowerCase())
- && hasSameClasses(el1, el2)
- && elementsHaveSameNonClassAttributes(el1, el2);
- },
-
- createContainer: function(doc) {
- var el = doc.createElement(this.tagNames[0]);
- if (this.cssClass) {
- el.className = this.cssClass;
- }
- if (this.cssStyle) {
- el.setAttribute('style', this.cssStyle);
- }
- return el;
- },
-
- applyToTextNode: function(textNode) {
- var parent = textNode.parentNode;
- if (parent.childNodes.length == 1 && rangy.dom.arrayContains(this.tagNames, parent.tagName.toLowerCase())) {
-
- if (this.cssClass) {
- addClass(parent, this.cssClass, this.similarClassRegExp);
- }
- if (this.cssStyle) {
- addStyle(parent, this.cssStyle, this.similarStyleRegExp);
- }
- } else {
- var el = this.createContainer(rangy.dom.getDocument(textNode));
- textNode.parentNode.insertBefore(el, textNode);
- el.appendChild(textNode);
- }
- },
-
- isRemovable: function(el) {
- return rangy.dom.arrayContains(this.tagNames, el.tagName.toLowerCase()) &&
- wysihtml5.lang.string(el.className).trim() === "" &&
- (
- !el.getAttribute('style') ||
- wysihtml5.lang.string(el.getAttribute('style')).trim() === ""
- );
- },
-
- undoToTextNode: function(textNode, range, ancestorWithClass, ancestorWithStyle) {
- var styleMode = (ancestorWithClass) ? false : true,
- ancestor = ancestorWithClass || ancestorWithStyle,
- styleChanged = false;
- if (!range.containsNode(ancestor)) {
- // Split out the portion of the ancestor from which we can remove the CSS class
- var ancestorRange = range.cloneRange();
- ancestorRange.selectNode(ancestor);
-
- if (ancestorRange.isPointInRange(range.endContainer, range.endOffset) && isSplitPoint(range.endContainer, range.endOffset)) {
- splitNodeAt(ancestor, range.endContainer, range.endOffset, this.container);
- range.setEndAfter(ancestor);
- }
- if (ancestorRange.isPointInRange(range.startContainer, range.startOffset) && isSplitPoint(range.startContainer, range.startOffset)) {
- ancestor = splitNodeAt(ancestor, range.startContainer, range.startOffset, this.container);
- }
- }
-
- if (!styleMode && this.similarClassRegExp) {
- removeClass(ancestor, this.similarClassRegExp);
- }
-
- if (styleMode && this.similarStyleRegExp) {
- styleChanged = (removeOrChangeStyle(ancestor, this.cssStyle, this.similarStyleRegExp) === "change");
- }
- if (this.isRemovable(ancestor) && !styleChanged) {
- replaceWithOwnChildren(ancestor);
- }
- },
-
- applyToRange: function(range) {
- var textNodes;
- for (var ri = range.length; ri--;) {
- textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
-
- if (!textNodes.length) {
- try {
- var node = this.createContainer(range[ri].endContainer.ownerDocument);
- range[ri].surroundContents(node);
- this.selectNode(range[ri], node);
- return;
- } catch(e) {}
- }
-
- range[ri].splitBoundaries();
- textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
- if (textNodes.length) {
- var textNode;
-
- for (var i = 0, len = textNodes.length; i < len; ++i) {
- textNode = textNodes[i];
- if (!this.getMatchingAncestor(textNode).element) {
- this.applyToTextNode(textNode);
- }
- }
-
- range[ri].setStart(textNodes[0], 0);
- textNode = textNodes[textNodes.length - 1];
- range[ri].setEnd(textNode, textNode.length);
-
- if (this.normalize) {
- this.postApply(textNodes, range[ri]);
- }
- }
-
- }
- },
-
- undoToRange: function(range) {
- var textNodes, textNode, ancestorWithClass, ancestorWithStyle, ancestor;
- for (var ri = range.length; ri--;) {
-
- textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
- if (textNodes.length) {
- range[ri].splitBoundaries();
- textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
- } else {
- var doc = range[ri].endContainer.ownerDocument,
- node = doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
- range[ri].insertNode(node);
- range[ri].selectNode(node);
- textNodes = [node];
- }
-
- for (var i = 0, len = textNodes.length; i < len; ++i) {
- if (range[ri].isValid()) {
- textNode = textNodes[i];
-
- ancestor = this.getMatchingAncestor(textNode);
- if (ancestor.type === "style") {
- this.undoToTextNode(textNode, range[ri], false, ancestor.element);
- } else if (ancestor.element) {
- this.undoToTextNode(textNode, range[ri], ancestor.element);
- }
- }
- }
-
- if (len == 1) {
- this.selectNode(range[ri], textNodes[0]);
- } else {
- range[ri].setStart(textNodes[0], 0);
- textNode = textNodes[textNodes.length - 1];
- range[ri].setEnd(textNode, textNode.length);
-
- if (this.normalize) {
- this.postApply(textNodes, range[ri]);
- }
- }
-
- }
- },
-
- selectNode: function(range, node) {
- var isElement = node.nodeType === wysihtml5.ELEMENT_NODE,
- canHaveHTML = "canHaveHTML" in node ? node.canHaveHTML : true,
- content = isElement ? node.innerHTML : node.data,
- isEmpty = (content === "" || content === wysihtml5.INVISIBLE_SPACE);
-
- if (isEmpty && isElement && canHaveHTML) {
- // Make sure that caret is visible in node by inserting a zero width no breaking space
- try { node.innerHTML = wysihtml5.INVISIBLE_SPACE; } catch(e) {}
- }
- range.selectNodeContents(node);
- if (isEmpty && isElement) {
- range.collapse(false);
- } else if (isEmpty) {
- range.setStartAfter(node);
- range.setEndAfter(node);
- }
- },
-
- getTextSelectedByRange: function(textNode, range) {
- var textRange = range.cloneRange();
- textRange.selectNodeContents(textNode);
-
- var intersectionRange = textRange.intersection(range);
- var text = intersectionRange ? intersectionRange.toString() : "";
- textRange.detach();
-
- return text;
- },
-
- isAppliedToRange: function(range) {
- var ancestors = [],
- appliedType = "full",
- ancestor, styleAncestor, textNodes;
-
- for (var ri = range.length; ri--;) {
-
- textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
- if (!textNodes.length) {
- ancestor = this.getMatchingAncestor(range[ri].startContainer).element;
-
- return (ancestor) ? {
- "elements": [ancestor],
- "coverage": appliedType
- } : false;
- }
-
- for (var i = 0, len = textNodes.length, selectedText; i < len; ++i) {
- selectedText = this.getTextSelectedByRange(textNodes[i], range[ri]);
- ancestor = this.getMatchingAncestor(textNodes[i]).element;
- if (ancestor && selectedText != "") {
- ancestors.push(ancestor);
-
- if (wysihtml5.dom.getTextNodes(ancestor, true).length === 1) {
- appliedType = "full";
- } else if (appliedType === "full") {
- appliedType = "inline";
- }
- } else if (!ancestor) {
- appliedType = "partial";
- }
- }
-
- }
-
- return (ancestors.length) ? {
- "elements": ancestors,
- "coverage": appliedType
- } : false;
- },
-
- toggleRange: function(range) {
- var isApplied = this.isAppliedToRange(range),
- parentsExactMatch;
-
- if (isApplied) {
- if (isApplied.coverage === "full") {
- this.undoToRange(range);
- } else if (isApplied.coverage === "inline") {
- parentsExactMatch = areMatchingAllready(isApplied.elements, this.tagNames, this.cssStyle, this.cssClass);
- this.undoToRange(range);
- if (!parentsExactMatch) {
- this.applyToRange(range);
- }
- } else {
- // partial
- if (!areMatchingAllready(isApplied.elements, this.tagNames, this.cssStyle, this.cssClass)) {
- this.undoToRange(range);
- }
- this.applyToRange(range);
- }
- } else {
- this.applyToRange(range);
- }
- }
- };
-
- wysihtml5.selection.HTMLApplier = HTMLApplier;
-
-})(wysihtml5, rangy);
-;/**
- * Rich Text Query/Formatting Commands
- *
- * @example
- * var commands = new wysihtml5.Commands(editor);
- */
-wysihtml5.Commands = Base.extend(
- /** @scope wysihtml5.Commands.prototype */ {
- constructor: function(editor) {
- this.editor = editor;
- this.composer = editor.composer;
- this.doc = this.composer.doc;
- },
-
- /**
- * Check whether the browser supports the given command
- *
- * @param {String} command The command string which to check (eg. "bold", "italic", "insertUnorderedList")
- * @example
- * commands.supports("createLink");
- */
- support: function(command) {
- return wysihtml5.browser.supportsCommand(this.doc, command);
- },
-
- /**
- * Check whether the browser supports the given command
- *
- * @param {String} command The command string which to execute (eg. "bold", "italic", "insertUnorderedList")
- * @param {String} [value] The command value parameter, needed for some commands ("createLink", "insertImage", ...), optional for commands that don't require one ("bold", "underline", ...)
- * @example
- * commands.exec("insertImage", "http://a1.twimg.com/profile_images/113868655/schrei_twitter_reasonably_small.jpg");
- */
- exec: function(command, value) {
- var obj = wysihtml5.commands[command],
- args = wysihtml5.lang.array(arguments).get(),
- method = obj && obj.exec,
- result = null;
-
- // If composer ahs placeholder unset it before command
- // Do not apply on commands that are behavioral
- if (this.composer.hasPlaceholderSet() && !wysihtml5.lang.array(['styleWithCSS', 'enableObjectResizing', 'enableInlineTableEditing']).contains(command)) {
- this.composer.element.innerHTML = "";
- this.composer.selection.selectNode(this.composer.element);
- }
-
- this.editor.fire("beforecommand:composer");
-
- if (method) {
- args.unshift(this.composer);
- result = method.apply(obj, args);
- } else {
- try {
- // try/catch for buggy firefox
- result = this.doc.execCommand(command, false, value);
- } catch(e) {}
- }
-
- this.editor.fire("aftercommand:composer");
- return result;
- },
-
- remove: function(command, commandValue) {
- var obj = wysihtml5.commands[command],
- args = wysihtml5.lang.array(arguments).get(),
- method = obj && obj.remove;
- if (method) {
- args.unshift(this.composer);
- return method.apply(obj, args);
- }
- },
-
- /**
- * Check whether the current command is active
- * If the caret is within a bold text, then calling this with command "bold" should return true
- *
- * @param {String} command The command string which to check (eg. "bold", "italic", "insertUnorderedList")
- * @param {String} [commandValue] The command value parameter (eg. for "insertImage" the image src)
- * @return {Boolean} Whether the command is active
- * @example
- * var isCurrentSelectionBold = commands.state("bold");
- */
- state: function(command, commandValue) {
- var obj = wysihtml5.commands[command],
- args = wysihtml5.lang.array(arguments).get(),
- method = obj && obj.state;
- if (method) {
- args.unshift(this.composer);
- return method.apply(obj, args);
- } else {
- try {
- // try/catch for buggy firefox
- return this.doc.queryCommandState(command);
- } catch(e) {
- return false;
- }
- }
- },
-
- /* Get command state parsed value if command has stateValue parsing function */
- stateValue: function(command) {
- var obj = wysihtml5.commands[command],
- args = wysihtml5.lang.array(arguments).get(),
- method = obj && obj.stateValue;
- if (method) {
- args.unshift(this.composer);
- return method.apply(obj, args);
- } else {
- return false;
- }
- }
-});
-;(function(wysihtml5) {
-
- var nodeOptions = {
- nodeName: "B",
- toggle: true
- };
-
- wysihtml5.commands.bold = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.exec(composer, command, nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-
-}(wysihtml5));
-;(function(wysihtml5) {
-
- var nodeOptions = {
- nodeName: "A",
- toggle: false
- };
-
- function getOptions(value) {
- var options = typeof value === 'object' ? value : {'href': value};
- return wysihtml5.lang.object({}).merge(nodeOptions).merge({'attribute': value}).get();
- }
-
- wysihtml5.commands.createLink = {
- exec: function(composer, command, value) {
- var opts = getOptions(value);
-
- if (composer.selection.isCollapsed() && !this.state(composer, command)) {
- var textNode = composer.doc.createTextNode(opts.attribute.href);
- composer.selection.insertNode(textNode);
- composer.selection.selectNode(textNode);
- }
- wysihtml5.commands.formatInline.exec(composer, command, opts);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- nodeName: "A"
- };
-
- wysihtml5.commands.removeLink = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.remove(composer, command, nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-
-})(wysihtml5);
-;/**
- * Set font size css class
- */
-(function(wysihtml5) {
- var REG_EXP = /wysiwyg-font-size-[0-9a-z\-]+/g;
-
- wysihtml5.commands.fontSize = {
- exec: function(composer, command, size) {
- wysihtml5.commands.formatInline.exec(composer, command, {className: "wysiwyg-font-size-" + size, classRegExp: REG_EXP, toggle: true});
- },
-
- state: function(composer, command, size) {
- return wysihtml5.commands.formatInline.state(composer, command, {className: "wysiwyg-font-size-" + size});
- }
- };
-})(wysihtml5);
-;/**
- * Set font size by inline style
- */
-(function(wysihtml5) {
-
- wysihtml5.commands.fontSizeStyle = {
- exec: function(composer, command, size) {
- size = size.size || size;
- if (!(/^\s*$/).test(size)) {
- wysihtml5.commands.formatInline.exec(composer, command, {styleProperty: "fontSize", styleValue: size, toggle: false});
- }
- },
-
- state: function(composer, command, size) {
- return wysihtml5.commands.formatInline.state(composer, command, {styleProperty: "fontSize", styleValue: size || undefined});
- },
-
- remove: function(composer, command) {
- return wysihtml5.commands.formatInline.remove(composer, command, {styleProperty: "fontSize"});
- },
-
- stateValue: function(composer, command) {
- var styleStr,
- st = this.state(composer, command);
-
- if (st && wysihtml5.lang.object(st).isArray()) {
- st = st[0];
- }
- if (st) {
- styleStr = st.getAttribute("style");
- if (styleStr) {
- return wysihtml5.quirks.styleParser.parseFontSize(styleStr);
- }
- }
- return false;
- }
- };
-})(wysihtml5);
-;/**
- * Set color css class
- */
-(function(wysihtml5) {
- var REG_EXP = /wysiwyg-color-[0-9a-z]+/g;
-
- wysihtml5.commands.foreColor = {
- exec: function(composer, command, color) {
- wysihtml5.commands.formatInline.exec(composer, command, {className: "wysiwyg-color-" + color, classRegExp: REG_EXP, toggle: true});
- },
-
- state: function(composer, command, color) {
- return wysihtml5.commands.formatInline.state(composer, command, {className: "wysiwyg-color-" + color});
- }
- };
-})(wysihtml5);
-;/**
- * Sets text color by inline styles
- */
-(function(wysihtml5) {
-
- wysihtml5.commands.foreColorStyle = {
- exec: function(composer, command, color) {
- var colorVals, colString;
-
- if (!color) { return; }
-
- colorVals = wysihtml5.quirks.styleParser.parseColor("color:" + (color.color || color), "color");
-
- if (colorVals) {
- colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(", ") : "rgba(" + colorVals.join(', ')) + ')';
- wysihtml5.commands.formatInline.exec(composer, command, {styleProperty: "color", styleValue: colString});
- }
- },
-
- state: function(composer, command, color) {
- var colorVals = color ? wysihtml5.quirks.styleParser.parseColor("color:" + (color.color || color), "color") : null,
- colString;
-
-
- if (colorVals) {
- colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(", ") : "rgba(" + colorVals.join(', ')) + ')';
- }
-
- return wysihtml5.commands.formatInline.state(composer, command, {styleProperty: "color", styleValue: colString});
- },
-
- remove: function(composer, command) {
- return wysihtml5.commands.formatInline.remove(composer, command, {styleProperty: "color"});
- },
-
- stateValue: function(composer, command, props) {
- var st = this.state(composer, command),
- colorStr,
- val = false;
-
- if (st && wysihtml5.lang.object(st).isArray()) {
- st = st[0];
- }
-
- if (st) {
- colorStr = st.getAttribute("style");
- if (colorStr) {
- val = wysihtml5.quirks.styleParser.parseColor(colorStr, "color");
- return wysihtml5.quirks.styleParser.unparseColor(val, props);
- }
- }
- return false;
- }
-
- };
-})(wysihtml5);
-;/**
- * Sets text background color by inline styles
- */
-(function(wysihtml5) {
-
- wysihtml5.commands.bgColorStyle = {
- exec: function(composer, command, color) {
- var colorVals = wysihtml5.quirks.styleParser.parseColor("background-color:" + (color.color || color), "background-color"),
- colString;
-
- if (colorVals) {
- colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(', ') : "rgba(" + colorVals.join(', ')) + ')';
- wysihtml5.commands.formatInline.exec(composer, command, {styleProperty: 'backgroundColor', styleValue: colString});
- }
- },
-
- state: function(composer, command, color) {
- var colorVals = color ? wysihtml5.quirks.styleParser.parseColor("background-color:" + (color.color || color), "background-color") : null,
- colString;
-
-
- if (colorVals) {
- colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(', ') : "rgba(" + colorVals.join(', ')) + ')';
- }
-
- return wysihtml5.commands.formatInline.state(composer, command, {styleProperty: 'backgroundColor', styleValue: colString});
- },
-
- remove: function(composer, command) {
- return wysihtml5.commands.formatInline.remove(composer, command, {styleProperty: 'backgroundColor'});
- },
-
- stateValue: function(composer, command, props) {
- var st = this.state(composer, command),
- colorStr,
- val = false;
-
- if (st && wysihtml5.lang.object(st).isArray()) {
- st = st[0];
- }
-
- if (st) {
- colorStr = st.getAttribute('style');
- if (colorStr) {
- val = wysihtml5.quirks.styleParser.parseColor(colorStr, "background-color");
- return wysihtml5.quirks.styleParser.unparseColor(val, props);
- }
- }
- return false;
- }
-
- };
-})(wysihtml5);
-;/* Formatblock
- * Is used to insert block level elements
- * It tries to solve the case that some block elements should not contain other block level elements (h1-6, p, ...)
- *
-*/
-(function(wysihtml5) {
-
- var dom = wysihtml5.dom,
- // When the caret is within a H1 and the H4 is invoked, the H1 should turn into H4
- // instead of creating a H4 within a H1 which would result in semantically invalid html
- UNNESTABLE_BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre",
- BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre, div, blockquote",
- INLINE_ELEMENTS = "b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u";
-
- function correctOptionsForSimilarityCheck(options) {
- return {
- nodeName: options.nodeName || null,
- className: (!options.classRegExp) ? options.className || null : null,
- classRegExp: options.classRegExp || null,
- styleProperty: options.styleProperty || null
- };
- }
-
- function getRangeNode(node, offset) {
- if (node.nodeType === 3) {
- return node;
- } else {
- return node.childNodes[offset] || node;
- }
- }
-
- // Returns if node is a line break
- function isBr(n) {
- return n && n.nodeType === 1 && n.nodeName === "BR";
- }
-
- // Is block level element
- function isBlock(n, composer) {
- return n && n.nodeType === 1 && composer.win.getComputedStyle(n).display === "block";
- }
-
- // Returns if node is the rangy selection bookmark element (that must not be taken into account in most situatons and is removed on selection restoring)
- function isBookmark(n) {
- return n && n.nodeType === 1 && n.classList.contains('rangySelectionBoundary');
- }
-
- // Is line breaking node
- function isLineBreaking(n, composer) {
- return isBr(n) || isBlock(n, composer);
- }
-
- // Removes empty block level elements
- function cleanup(composer, newBlockElements) {
- wysihtml5.dom.removeInvisibleSpaces(composer.element);
- var container = composer.element,
- allElements = container.querySelectorAll(BLOCK_ELEMENTS),
- noEditQuery = composer.config.classNames.uneditableContainer + ([""]).concat(BLOCK_ELEMENTS.split(',')).join(", " + composer.config.classNames.uneditableContainer + ' '),
- uneditables = container.querySelectorAll(noEditQuery),
- elements = wysihtml5.lang.array(allElements).without(uneditables), // Lets not touch uneditable elements and their contents
- nbIdx;
-
- for (var i = elements.length; i--;) {
- if (elements[i].innerHTML.replace(/[\uFEFF]/g, '') === "" && (newBlockElements.length === 0 || elements[i] !== newBlockElements[newBlockElements.length - 1])) {
- // If cleanup removes some new block elements. remove them from newblocks array too
- nbIdx = wysihtml5.lang.array(newBlockElements).indexOf(elements[i]);
- if (nbIdx > -1) {
- newBlockElements.splice(nbIdx, 1);
- }
- elements[i].parentNode.removeChild(elements[i]);
- }
- }
-
- return newBlockElements;
- }
-
- function defaultNodeName(composer) {
- return composer.config.useLineBreaks ? "DIV" : "P";
- }
-
- // The outermost un-nestable block element parent of from node
- function findOuterBlock(node, container, allBlocks) {
- var n = node,
- block = null;
-
- while (n && container && n !== container) {
- if (n.nodeType === 1 && n.matches(allBlocks ? BLOCK_ELEMENTS : UNNESTABLE_BLOCK_ELEMENTS)) {
- block = n;
- }
- n = n.parentNode;
- }
-
- return block;
- }
-
- // Clone for splitting the inner inline element out of its parent inline elements context
- // For example if selection is in bold and italic, clone the outer nodes and wrap these around content and return
- function cloneOuterInlines(node, container) {
- var n = node,
- innerNode,
- parentNode,
- el = null,
- el2;
-
- while (n && container && n !== container) {
- if (n.nodeType === 1 && n.matches(INLINE_ELEMENTS)) {
- parentNode = n;
- if (el === null) {
- el = n.cloneNode(false);
- innerNode = el;
- } else {
- el2 = n.cloneNode(false);
- el2.appendChild(el);
- el = el2;
- }
- }
- n = n.parentNode;
- }
-
- return {
- parent: parentNode,
- outerNode: el,
- innerNode: innerNode
- };
- }
-
- // Formats an element according to options nodeName, className, styleProperty, styleValue
- // If element is not defined, creates new element
- // if opotions is null, remove format instead
- function applyOptionsToElement(element, options, composer) {
-
- if (!element) {
- element = composer.doc.createElement(options.nodeName || defaultNodeName(composer));
- // Add invisible space as otherwise webkit cannot set selection or range to it correctly
- element.appendChild(composer.doc.createTextNode(wysihtml5.INVISIBLE_SPACE));
- }
-
- if (options.nodeName && element.nodeName !== options.nodeName) {
- element = dom.renameElement(element, options.nodeName);
- }
-
- // Remove similar classes before applying className
- if (options.classRegExp) {
- element.className = element.className.replace(options.classRegExp, "");
- }
- if (options.className) {
- element.classList.add(options.className);
- }
-
- if (options.styleProperty && typeof options.styleValue !== "undefined") {
- element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)] = options.styleValue;
- }
-
- return element;
- }
-
- // Unsets element properties by options
- // If nodename given and matches current element, element is unwrapped or converted to default node (depending on presence of class and style attributes)
- function removeOptionsFromElement(element, options, composer) {
- var style, classes,
- prevNode = element.previousSibling,
- nextNode = element.nextSibling,
- unwrapped = false;
-
- if (options.styleProperty) {
- element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)] = '';
- }
- if (options.className) {
- element.classList.remove(options.className);
- }
-
- if (options.classRegExp) {
- element.className = element.className.replace(options.classRegExp, "");
- }
-
- // Clean up blank class attribute
- if (element.getAttribute('class') !== null && element.getAttribute('class').trim() === "") {
- element.removeAttribute('class');
- }
-
- if (options.nodeName && element.nodeName.toLowerCase() === options.nodeName.toLowerCase()) {
- style = element.getAttribute('style');
- if (!style || style.trim() === '') {
- dom.unwrap(element);
- unwrapped = true;
- } else {
- element = dom.renameElement(element, defaultNodeName(composer));
- }
- }
-
- // Clean up blank style attribute
- if (element.getAttribute('style') !== null && element.getAttribute('style').trim() === "") {
- element.removeAttribute('style');
- }
-
- if (unwrapped) {
- applySurroundingLineBreaks(prevNode, nextNode, composer);
- }
- }
-
- // Unwraps block level elements from inside content
- // Useful as not all block level elements can contain other block-levels
- function unwrapBlocksFromContent(element) {
- var blocks = element.querySelectorAll(BLOCK_ELEMENTS) || [], // Find unnestable block elements in extracted contents
- nextEl, prevEl;
-
- for (var i = blocks.length; i--;) {
- nextEl = wysihtml5.dom.domNode(blocks[i]).next({nodeTypes: [1,3], ignoreBlankTexts: true}),
- prevEl = wysihtml5.dom.domNode(blocks[i]).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
-
- if (nextEl && nextEl.nodeType !== 1 && nextEl.nodeName !== 'BR') {
- if ((blocks[i].innerHTML || blocks[i].nodeValue || '').trim() !== '') {
- blocks[i].parentNode.insertBefore(blocks[i].ownerDocument.createElement('BR'), nextEl);
- }
- }
- if (nextEl && nextEl.nodeType !== 1 && nextEl.nodeName !== 'BR') {
- if ((blocks[i].innerHTML || blocks[i].nodeValue || '').trim() !== '') {
- blocks[i].parentNode.insertBefore(blocks[i].ownerDocument.createElement('BR'), nextEl);
- }
- }
- wysihtml5.dom.unwrap(blocks[i]);
- }
- }
-
- // Fix ranges that visually cover whole block element to actually cover the block
- function fixRangeCoverage(range, composer) {
- var node,
- start = range.startContainer,
- end = range.endContainer;
-
- // If range has only one childNode and it is end to end the range, extend the range to contain the container element too
- // This ensures the wrapper node is modified and optios added to it
- if (start && start.nodeType === 1 && start === end) {
- if (start.firstChild === start.lastChild && range.endOffset === 1) {
- if (start !== composer.element && start.nodeName !== 'LI' && start.nodeName !== 'TD') {
- range.setStartBefore(start);
- range.setEndAfter(end);
- }
- }
- return;
- }
-
- // If range starts outside of node and ends inside at textrange and covers the whole node visually, extend end to cover the node end too
- if (start && start.nodeType === 1 && end.nodeType === 3) {
- if (start.firstChild === end && range.endOffset === end.data.length) {
- if (start !== composer.element && start.nodeName !== 'LI' && start.nodeName !== 'TD') {
- range.setEndAfter(start);
- }
- }
- return;
- }
-
- // If range ends outside of node and starts inside at textrange and covers the whole node visually, extend start to cover the node start too
- if (end && end.nodeType === 1 && start.nodeType === 3) {
- if (end.firstChild === start && range.startOffset === 0) {
- if (end !== composer.element && end.nodeName !== 'LI' && end.nodeName !== 'TD') {
- range.setStartBefore(end);
- }
- }
- return;
- }
-
- // If range covers a whole textnode and the textnode is the only child of node, extend range to node
- if (start && start.nodeType === 3 && start === end && start.parentNode.childNodes.length === 1) {
- if (range.endOffset == end.data.length && range.startOffset === 0) {
- node = start.parentNode;
- if (node !== composer.element && node.nodeName !== 'LI' && node.nodeName !== 'TD') {
- range.setStartBefore(node);
- range.setEndAfter(node);
- }
- }
- return;
- }
- }
-
- // Scans ranges array for insertion points that are not allowed to insert block tags fixes/splits illegal ranges
- // Some places do not allow block level elements inbetween (inside ul and outside li)
- // TODO: might need extending for other nodes besides li (maybe dd,dl,dt)
- function fixNotPermittedInsertionPoints(ranges) {
- var newRanges = [],
- lis, j, maxj, tmpRange, rangePos, closestLI;
-
- for (var i = 0, maxi = ranges.length; i < maxi; i++) {
-
- // Fixes range start and end positions if inside UL or OL element (outside of LI)
- if (ranges[i].startContainer.nodeType === 1 && ranges[i].startContainer.matches('ul, ol')) {
- ranges[i].setStart(ranges[i].startContainer.childNodes[ranges[i].startOffset], 0);
- }
- if (ranges[i].endContainer.nodeType === 1 && ranges[i].endContainer.matches('ul, ol')) {
- closestLI = ranges[i].endContainer.childNodes[Math.max(ranges[i].endOffset - 1, 0)];
- if (closestLI.childNodes) {
- ranges[i].setEnd(closestLI, closestLI.childNodes.length);
- }
- }
-
- // Get all LI eleemnts in selection (fully or partially covered)
- // And make sure ranges are either inside LI or outside UL/OL
- // Split and add new ranges as needed to cover same range content
- // TODO: Needs improvement to accept DL, DD, DT
- lis = ranges[i].getNodes([1], function(node) {
- return node.nodeName === "LI";
- });
- if (lis.length > 0) {
-
- for (j = 0, maxj = lis.length; j < maxj; j++) {
- rangePos = ranges[i].compareNode(lis[j]);
-
- // Fixes start of range that crosses LI border
- if (rangePos === ranges[i].NODE_AFTER || rangePos === ranges[i].NODE_INSIDE) {
- // Range starts before and ends inside the node
-
- tmpRange = ranges[i].cloneRange();
- closestLI = wysihtml5.dom.domNode(lis[j]).prev({nodeTypes: [1]});
-
- if (closestLI) {
- tmpRange.setEnd(closestLI, closestLI.childNodes.length);
- } else if (lis[j].closest('ul, ol')) {
- tmpRange.setEndBefore(lis[j].closest('ul, ol'));
- } else {
- tmpRange.setEndBefore(lis[j]);
- }
- newRanges.push(tmpRange);
- ranges[i].setStart(lis[j], 0);
- }
-
- // Fixes end of range that crosses li border
- if (rangePos === ranges[i].NODE_BEFORE || rangePos === ranges[i].NODE_INSIDE) {
- // Range starts inside the node and ends after node
-
- tmpRange = ranges[i].cloneRange();
- tmpRange.setEnd(lis[j], lis[j].childNodes.length);
- newRanges.push(tmpRange);
-
- // Find next LI in list and if present set range to it, else
- closestLI = wysihtml5.dom.domNode(lis[j]).next({nodeTypes: [1]});
- if (closestLI) {
- ranges[i].setStart(closestLI, 0);
- } else if (lis[j].closest('ul, ol')) {
- ranges[i].setStartAfter(lis[j].closest('ul, ol'));
- } else {
- ranges[i].setStartAfter(lis[j]);
- }
- }
- }
- newRanges.push(ranges[i]);
- } else {
- newRanges.push(ranges[i]);
- }
- }
- return newRanges;
- }
-
- // Return options object with nodeName set if original did not have any
- // Node name is set to local or global default
- function getOptionsWithNodename(options, defaultName, composer) {
- var correctedOptions = (options) ? wysihtml5.lang.object(options).clone(true) : null;
- if (correctedOptions) {
- correctedOptions.nodeName = correctedOptions.nodeName || defaultName || defaultNodeName(composer);
- }
- return correctedOptions;
- }
-
- // Injects document fragment to range ensuring outer elements are split to a place where block elements are allowed to be inserted
- // Also wraps empty clones of split parent tags around fragment to keep formatting
- // If firstOuterBlock is given assume that instead of finding outer (useful for solving cases of some blocks are allowed into others while others are not)
- function injectFragmentToRange(fragment, range, composer, firstOuterBlock) {
- var rangeStartContainer = range.startContainer,
- firstOuterBlock = firstOuterBlock || findOuterBlock(rangeStartContainer, composer.element, true),
- outerInlines, first, last, prev, next;
-
- if (firstOuterBlock) {
- // If selection starts inside un-nestable block, split-escape the unnestable point and insert node between
- first = fragment.firstChild;
- last = fragment.lastChild;
-
- composer.selection.splitElementAtCaret(firstOuterBlock, fragment);
-
- next = wysihtml5.dom.domNode(last).next({nodeTypes: [1,3], ignoreBlankTexts: true});
- prev = wysihtml5.dom.domNode(first).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
-
- if (first && !isLineBreaking(first, composer) && prev && !isLineBreaking(prev, composer)) {
- first.parentNode.insertBefore(composer.doc.createElement('br'), first);
- }
-
- if (last && !isLineBreaking(last, composer) && next && !isLineBreaking(next, composer)) {
- next.parentNode.insertBefore(composer.doc.createElement('br'), next);
- }
-
- } else {
- // Ensure node does not get inserted into an inline where it is not allowed
- outerInlines = cloneOuterInlines(rangeStartContainer, composer.element);
- if (outerInlines.outerNode && outerInlines.innerNode && outerInlines.parent) {
- if (fragment.childNodes.length === 1) {
- while(fragment.firstChild.firstChild) {
- outerInlines.innerNode.appendChild(fragment.firstChild.firstChild);
- }
- fragment.firstChild.appendChild(outerInlines.outerNode);
- }
- composer.selection.splitElementAtCaret(outerInlines.parent, fragment);
- } else {
- var fc = fragment.firstChild,
- lc = fragment.lastChild;
-
- range.insertNode(fragment);
- // restore range position as it might get lost in webkit sometimes
- range.setStartBefore(fc);
- range.setEndAfter(lc);
- }
- }
- }
-
- // Removes all block formatting from range
- function clearRangeBlockFromating(range, closestBlockName, composer) {
- var r = range.cloneRange(),
- prevNode = getRangeNode(r.startContainer, r.startOffset).previousSibling,
- nextNode = getRangeNode(r.endContainer, r.endOffset).nextSibling,
- content = r.extractContents(),
- fragment = composer.doc.createDocumentFragment(),
- children, blocks,
- first = true;
-
- while(content.firstChild) {
- // Iterate over all selection content first level childNodes
- if (content.firstChild.nodeType === 1 && content.firstChild.matches(BLOCK_ELEMENTS)) {
- // If node is a block element
- // Split block formating and add new block to wrap caret
-
- unwrapBlocksFromContent(content.firstChild);
- children = wysihtml5.dom.unwrap(content.firstChild);
-
- // Add line break before if needed
- if (children.length > 0) {
- if (
- (fragment.lastChild && (fragment.lastChild.nodeType !== 1 || !isLineBreaking(fragment.lastChild, composer))) ||
- (!fragment.lastChild && prevNode && (prevNode.nodeType !== 1 || isLineBreaking(prevNode, composer)))
- ){
- fragment.appendChild(composer.doc.createElement('BR'));
- }
- }
-
- for (var c = 0, cmax = children.length; c < cmax; c++) {
- fragment.appendChild(children[c]);
- }
-
- // Add line break after if needed
- if (children.length > 0) {
- if (fragment.lastChild.nodeType !== 1 || !isLineBreaking(fragment.lastChild, composer)) {
- if (nextNode || fragment.lastChild !== content.lastChild) {
- fragment.appendChild(composer.doc.createElement('BR'));
- }
- }
- }
-
- } else {
- fragment.appendChild(content.firstChild);
- }
-
- first = false;
- }
- blocks = wysihtml5.lang.array(fragment.childNodes).get();
- injectFragmentToRange(fragment, r, composer);
- return blocks;
- }
-
- // When block node is inserted, look surrounding nodes and remove surplous linebreak tags (as block format breaks line itself)
- function removeSurroundingLineBreaks(prevNode, nextNode, composer) {
- var prevPrev = prevNode && wysihtml5.dom.domNode(prevNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
- if (isBr(nextNode)) {
- nextNode.parentNode.removeChild(nextNode);
- }
- if (isBr(prevNode) && (!prevPrev || prevPrev.nodeType !== 1 || composer.win.getComputedStyle(prevPrev).display !== "block")) {
- prevNode.parentNode.removeChild(prevNode);
- }
- }
-
- function applySurroundingLineBreaks(prevNode, nextNode, composer) {
- var prevPrev;
-
- if (prevNode && isBookmark(prevNode)) {
- prevNode = prevNode.previousSibling;
- }
- if (nextNode && isBookmark(nextNode)) {
- nextNode = nextNode.nextSibling;
- }
-
- prevPrev = prevNode && prevNode.previousSibling;
-
- if (prevNode && (prevNode.nodeType !== 1 || (composer.win.getComputedStyle(prevNode).display !== "block" && !isBr(prevNode))) && prevNode.parentNode) {
- prevNode.parentNode.insertBefore(composer.doc.createElement('br'), prevNode.nextSibling);
- }
-
- if (nextNode && (nextNode.nodeType !== 1 || composer.win.getComputedStyle(nextNode).display !== "block") && nextNode.parentNode) {
- nextNode.parentNode.insertBefore(composer.doc.createElement('br'), nextNode);
- }
- }
-
- var isWhitespaceBefore = function (textNode, offset) {
- var str = textNode.data ? textNode.data.slice(0, offset) : "";
- return (/^\s*$/).test(str);
- }
-
- var isWhitespaceAfter = function (textNode, offset) {
- var str = textNode.data ? textNode.data.slice(offset) : "";
- return (/^\s*$/).test(str);
- }
-
- var trimBlankTextsAndBreaks = function(fragment) {
- if (fragment) {
- while (fragment.firstChild && fragment.firstChild.nodeType === 3 && (/^\s*$/).test(fragment.firstChild.data) && fragment.lastChild !== fragment.firstChild) {
- fragment.removeChild(fragment.firstChild);
- }
-
- while (fragment.lastChild && fragment.lastChild.nodeType === 3 && (/^\s*$/).test(fragment.lastChild.data) && fragment.lastChild !== fragment.firstChild) {
- fragment.removeChild(fragment.lastChild);
- }
-
- if (fragment.firstChild && fragment.firstChild.nodeType === 1 && fragment.firstChild.nodeName === "BR" && fragment.lastChild !== fragment.firstChild) {
- fragment.removeChild(fragment.firstChild);
- }
-
- if (fragment.lastChild && fragment.lastChild.nodeType === 1 && fragment.lastChild.nodeName === "BR" && fragment.lastChild !== fragment.firstChild) {
- fragment.removeChild(fragment.lastChild);
- }
- }
- }
-
- // Wrap the range with a block level element
- // If element is one of unnestable block elements (ex: h2 inside h1), split nodes and insert between so nesting does not occur
- function wrapRangeWithElement(range, options, closestBlockName, composer) {
- var similarOptions = options ? correctOptionsForSimilarityCheck(options) : null,
- r = range.cloneRange(),
- rangeStartContainer = r.startContainer,
- startNode = getRangeNode(r.startContainer, r.startOffset),
- endNode = getRangeNode(r.endContainer, r.endOffset),
- prevNode = (r.startContainer === startNode && startNode.nodeType === 3 && !isWhitespaceBefore(startNode, r.startOffset)) ? startNode : wysihtml5.dom.domNode(startNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true}),
- nextNode = (
- (
- r.endContainer.nodeType === 1 &&
- r.endContainer.childNodes[r.endOffset] === endNode &&
- (
- endNode.nodeType === 1 ||
- !isWhitespaceAfter(endNode, r.endOffset) &&
- !wysihtml5.dom.domNode(endNode).is.rangyBookmark()
- )
- ) || (
- r.endContainer === endNode &&
- endNode.nodeType === 3 &&
- !isWhitespaceAfter(endNode, r.endOffset)
- )
- ) ? endNode : wysihtml5.dom.domNode(endNode).next({nodeTypes: [1,3], ignoreBlankTexts: true}),
- content = r.extractContents(),
- fragment = composer.doc.createDocumentFragment(),
- similarOuterBlock = similarOptions ? wysihtml5.dom.getParentElement(rangeStartContainer, similarOptions, null, composer.element) : null,
- splitAllBlocks = !closestBlockName || !options || (options.nodeName === "BLOCKQUOTE" && closestBlockName === "BLOCKQUOTE"),
- firstOuterBlock = similarOuterBlock || findOuterBlock(rangeStartContainer, composer.element, splitAllBlocks), // The outermost un-nestable block element parent of selection start
- wrapper, blocks, children,
- firstc, lastC;
-
- if (wysihtml5.dom.domNode(nextNode).is.rangyBookmark()) {
- endNode = nextNode;
- nextNode = endNode.nextSibling;
- }
-
- trimBlankTextsAndBreaks(content);
-
- if (options && options.nodeName === "BLOCKQUOTE") {
-
- // If blockquote is to be inserted no quessing just add it as outermost block on line or selection
- var tmpEl = applyOptionsToElement(null, options, composer);
- tmpEl.appendChild(content);
- fragment.appendChild(tmpEl);
- blocks = [tmpEl];
-
- } else {
-
- if (!content.firstChild) {
- // IF selection is caret (can happen if line is empty) add format around tag
- fragment.appendChild(applyOptionsToElement(null, options, composer));
- } else {
-
- while(content.firstChild) {
- // Iterate over all selection content first level childNodes
-
- if (content.firstChild.nodeType == 1 && content.firstChild.matches(BLOCK_ELEMENTS)) {
-
- // If node is a block element
- // Escape(split) block formatting at caret
- applyOptionsToElement(content.firstChild, options, composer);
- if (content.firstChild.matches(UNNESTABLE_BLOCK_ELEMENTS)) {
- unwrapBlocksFromContent(content.firstChild);
- }
- fragment.appendChild(content.firstChild);
-
- } else {
-
- // Wrap subsequent non-block nodes inside new block element
- wrapper = applyOptionsToElement(null, getOptionsWithNodename(options, closestBlockName, composer), composer);
- while(content.firstChild && (content.firstChild.nodeType !== 1 || !content.firstChild.matches(BLOCK_ELEMENTS))) {
- if (content.firstChild.nodeType == 1 && wrapper.matches(UNNESTABLE_BLOCK_ELEMENTS)) {
- unwrapBlocksFromContent(content.firstChild);
- }
- wrapper.appendChild(content.firstChild);
- }
- fragment.appendChild(wrapper);
- }
- }
- }
-
- blocks = wysihtml5.lang.array(fragment.childNodes).get();
- }
- injectFragmentToRange(fragment, r, composer, firstOuterBlock);
- removeSurroundingLineBreaks(prevNode, nextNode, composer);
-
- // Fix webkit madness by inserting linebreak rangy after cursor marker to blank last block
- // (if it contains rangy bookmark, so selection can be restored later correctly)
- if (blocks.length > 0 &&
- (
- typeof blocks[blocks.length - 1].lastChild === "undefined" || wysihtml5.dom.domNode(blocks[blocks.length - 1].lastChild).is.rangyBookmark()
- )
- ) {
- blocks[blocks.length - 1].appendChild(composer.doc.createElement('br'));
- }
- return blocks;
- }
-
- // Find closest block level element
- function getParentBlockNodeName(element, composer) {
- var parentNode = wysihtml5.dom.getParentElement(element, {
- query: BLOCK_ELEMENTS
- }, null, composer.element);
-
- return (parentNode) ? parentNode.nodeName : null;
- }
-
- // Expands caret to cover the closest block that:
- // * cannot contain other block level elements (h1-6,p, etc)
- // * Has the same nodeName that is to be inserted
- // * has insertingNodeName
- // * is DIV if insertingNodeName is not present
- //
- // If nothing found selects the current line
- function expandCaretToBlock(composer, insertingNodeName) {
- var parent = wysihtml5.dom.getParentElement(composer.selection.getOwnRanges()[0].startContainer, {
- query: UNNESTABLE_BLOCK_ELEMENTS + ', ' + (insertingNodeName ? insertingNodeName.toLowerCase() : 'div'),
- }, null, composer.element),
- range;
-
- if (parent) {
- range = composer.selection.createRange();
- range.selectNode(parent);
- composer.selection.setSelection(range);
- } else if (!composer.isEmpty()) {
- composer.selection.selectLine();
- }
- }
-
- // Set selection to begin inside first created block element (beginning of it) and end inside (and after content) of last block element
- // TODO: Checking nodetype might be unnescescary as nodes inserted by formatBlock are nodetype 1 anyway
- function selectElements(newBlockElements, composer) {
- var range = composer.selection.createRange(),
- lastEl = newBlockElements[newBlockElements.length - 1],
- lastOffset = (lastEl.nodeType === 1 && lastEl.childNodes) ? lastEl.childNodes.length | 0 : lastEl.length || 0;
-
- range.setStart(newBlockElements[0], 0);
- range.setEnd(lastEl, lastOffset);
- range.select();
- }
-
- // Get all ranges from selection (takes out uneditables and out of editor parts) and apply format to each
- // Return created/modified block level elements
- // Method can be either "apply" or "remove"
- function formatSelection(method, composer, options) {
- var ranges = composer.selection.getOwnRanges(),
- newBlockElements = [],
- closestBlockName;
-
- // Some places do not allow block level elements inbetween (inside ul and outside li, inside table and outside of td/th)
- ranges = fixNotPermittedInsertionPoints(ranges);
-
- for (var i = ranges.length; i--;) {
- fixRangeCoverage(ranges[i], composer);
- closestBlockName = getParentBlockNodeName(ranges[i].startContainer, composer);
- if (method === "remove") {
- newBlockElements = newBlockElements.concat(clearRangeBlockFromating(ranges[i], closestBlockName, composer));
- } else {
- newBlockElements = newBlockElements.concat(wrapRangeWithElement(ranges[i], options, closestBlockName, composer));
- }
- }
- return newBlockElements;
- }
-
- // If properties is passed as a string, look for tag with that tagName/query
- function parseOptions(options) {
- if (typeof options === "string") {
- options = {
- nodeName: options.toUpperCase()
- };
- }
- return options;
- }
-
- function caretIsOnEmptyLine(composer) {
- var caretInfo;
- if (composer.selection.isCollapsed()) {
- caretInfo = composer.selection.getNodesNearCaret();
- if (caretInfo && caretInfo.caretNode) {
- if (
- // caret is allready breaknode
- wysihtml5.dom.domNode(caretInfo.caretNode).is.lineBreak() ||
- // caret is textnode
- (caretInfo.caretNode.nodeType === 3 && caretInfo.textOffset === 0 && (!caretInfo.prevNode || wysihtml5.dom.domNode(caretInfo.prevNode).is.lineBreak())) ||
- // Caret is temprorary rangy selection marker
- (caretInfo.caretNode.nodeType === 1 && caretInfo.caretNode.classList.contains('rangySelectionBoundary') &&
- (!caretInfo.prevNode || wysihtml5.dom.domNode(caretInfo.prevNode).is.lineBreak() || wysihtml5.dom.domNode(caretInfo.prevNode).is.block()) &&
- (!caretInfo.nextNode || wysihtml5.dom.domNode(caretInfo.nextNode).is.lineBreak() || wysihtml5.dom.domNode(caretInfo.nextNode).is.block())
- )
- ) {
- return true;
- }
- }
- }
- return false;
- }
-
- wysihtml5.commands.formatBlock = {
- exec: function(composer, command, options) {
- options = parseOptions(options);
- var newBlockElements = [],
- ranges, range, bookmark, state, closestBlockName;
-
- // Find if current format state is active if options.toggle is set as true
- // In toggle case active state elemets are formatted instead of working directly on selection
- if (options && options.toggle) {
- state = this.state(composer, command, options);
- }
- if (state) {
- // Remove format from state nodes if toggle set and state on and selection is collapsed
- bookmark = rangy.saveSelection(composer.win);
- for (var j = 0, jmax = state.length; j < jmax; j++) {
- removeOptionsFromElement(state[j], options, composer);
- }
-
- } else {
- // If selection is caret expand it to cover nearest suitable block element or row if none found
- if (composer.selection.isCollapsed()) {
- bookmark = rangy.saveSelection(composer.win);
- if (caretIsOnEmptyLine(composer)) {
- composer.selection.selectLine();
- } else {
- expandCaretToBlock(composer, options && options.nodeName ? options.nodeName.toUpperCase() : undefined);
- }
- }
- if (options) {
- newBlockElements = formatSelection("apply", composer, options);
- } else {
- // Options == null means block formatting should be removed from selection
- newBlockElements = formatSelection("remove", composer);
- }
-
- }
-
- // Remove empty block elements that may be left behind
- // Also remove them from new blocks list
- newBlockElements = cleanup(composer, newBlockElements);
-
- // Restore selection
- if (bookmark) {
- rangy.restoreSelection(bookmark);
- } else {
- selectElements(newBlockElements, composer);
- }
- },
-
- // Removes all block formatting from selection
- remove: function(composer, command, options) {
- options = parseOptions(options);
- var newBlockElements, bookmark;
-
- // If selection is caret expand it to cover nearest suitable block element or row if none found
- if (composer.selection.isCollapsed()) {
- bookmark = rangy.saveSelection(composer.win);
- expandCaretToBlock(composer, options && options.nodeName ? options.nodeName.toUpperCase() : undefined);
- }
-
- newBlockElements = formatSelection("remove", composer);
- newBlockElements = cleanup(composer, newBlockElements);
-
- // Restore selection
- if (bookmark) {
- rangy.restoreSelection(bookmark);
- } else {
- selectElements(newBlockElements, composer);
- }
- },
-
- // If options as null is passed returns status describing all block level elements
- state: function(composer, command, options) {
- options = parseOptions(options);
-
- var nodes = composer.selection.filterElements((function (element) { // Finds matching elements inside selection
- return wysihtml5.dom.domNode(element).test(options || { query: BLOCK_ELEMENTS });
- }).bind(this)),
- parentNodes = composer.selection.getSelectedOwnNodes(),
- parent;
-
- // Finds matching elements that are parents of selection and adds to nodes list
- for (var i = 0, maxi = parentNodes.length; i < maxi; i++) {
- parent = dom.getParentElement(parentNodes[i], options || { query: BLOCK_ELEMENTS }, null, composer.element);
- if (parent && nodes.indexOf(parent) === -1) {
- nodes.push(parent);
- }
- }
-
- return (nodes.length === 0) ? false : nodes;
- }
-
- };
-})(wysihtml5);
-;/* Formats block for as a
block
- * Useful in conjuction for sytax highlight utility: highlight.js
- *
- * Usage:
- *
- * editorInstance.composer.commands.exec("formatCode", "language-html");
-*/
-
-(function(wysihtml5){
- wysihtml5.commands.formatCode = {
-
- exec: function(composer, command, classname) {
- var pre = this.state(composer)[0],
- code, range, selectedNodes;
-
- if (pre) {
- // caret is already within a ...
- composer.selection.executeAndRestore(function() {
- code = pre.querySelector("code");
- wysihtml5.dom.replaceWithChildNodes(pre);
- if (code) {
- wysihtml5.dom.replaceWithChildNodes(code);
- }
- });
- } else {
- // Wrap in ...
- range = composer.selection.getRange();
- selectedNodes = range.extractContents();
- pre = composer.doc.createElement("pre");
- code = composer.doc.createElement("code");
-
- if (classname) {
- code.className = classname;
- }
-
- pre.appendChild(code);
- code.appendChild(selectedNodes);
- range.insertNode(pre);
- composer.selection.selectNode(pre);
- }
- },
-
- state: function(composer) {
- var selectedNode = composer.selection.getSelectedNode(), node;
- if (selectedNode && selectedNode.nodeName && selectedNode.nodeName == "PRE"&&
- selectedNode.firstChild && selectedNode.firstChild.nodeName && selectedNode.firstChild.nodeName == "CODE") {
- return [selectedNode];
- } else {
- node = wysihtml5.dom.getParentElement(selectedNode, { query: "pre code" });
- return node ? [node.parentNode] : false;
- }
- }
- };
-}(wysihtml5));
-;/**
- * Unifies all inline tags additions and removals
- * See https://github.com/Voog/wysihtml/pull/169 for specification of action
- */
-
-(function(wysihtml5) {
-
- var defaultTag = "SPAN",
- INLINE_ELEMENTS = "b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u",
- queryAliasMap = {
- "b": "b, strong",
- "strong": "b, strong",
- "em": "em, i",
- "i": "em, i"
- };
-
- function hasNoClass(element) {
- return (/^\s*$/).test(element.className);
- }
-
- function hasNoStyle(element) {
- return !element.getAttribute('style') || (/^\s*$/).test(element.getAttribute('style'));
- }
-
- // Associative arrays in javascript are really objects and do not have length defined
- // Thus have to check emptyness in a different way
- function hasNoAttributes(element) {
- var attr = wysihtml5.dom.getAttributes(element);
- return wysihtml5.lang.object(attr).isEmpty();
- }
-
- // compares two nodes if they are semantically the same
- // Used in cleanup to find consequent semantically similar elements for merge
- function isSameNode(element1, element2) {
- var classes1, classes2,
- attr1, attr2;
-
- if (element1.nodeType !== 1 || element2.nodeType !== 1) {
- return false;
- }
-
- if (element1.nodeName !== element2.nodeName) {
- return false;
- }
-
- classes1 = element1.className.trim().replace(/\s+/g, ' ').split(' ');
- classes2 = element2.className.trim().replace(/\s+/g, ' ').split(' ');
- if (wysihtml5.lang.array(classes1).without(classes2).length > 0) {
- return false;
- }
-
- attr1 = wysihtml5.dom.getAttributes(element1);
- attr2 = wysihtml5.dom.getAttributes(element2);
-
- if (attr1.length !== attr2.length || !wysihtml5.lang.object(wysihtml5.lang.object(attr1).difference(attr2)).isEmpty()) {
- return false;
- }
-
- return true;
- }
-
- function createWrapNode(textNode, options) {
- var nodeName = options && options.nodeName || defaultTag,
- element = textNode.ownerDocument.createElement(nodeName);
-
- // Remove similar classes before applying className
- if (options.classRegExp) {
- element.className = element.className.replace(options.classRegExp, "");
- }
-
- if (options.className) {
- element.classList.add(options.className);
- }
-
- if (options.styleProperty && typeof options.styleValue !== "undefined") {
- element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)] = options.styleValue;
- }
-
- if (options.attribute) {
- if (typeof options.attribute === "object") {
- for (var a in options.attribute) {
- if (options.attribute.hasOwnProperty(a)) {
- element.setAttribute(a, options.attribute[a]);
- }
- }
- } else if (typeof options.attributeValue !== "undefined") {
- element.setAttribute(options.attribute, options.attributeValue);
- }
- }
-
- return element;
- }
-
- // Tests if attr2 list contains all attributes present in attr1
- // Note: attr 1 can have more attributes than attr2
- function containsSameAttributes(attr1, attr2) {
- for (var a in attr1) {
- if (attr1.hasOwnProperty(a)) {
- if (typeof attr2[a] === undefined || attr2[a] !== attr1[a]) {
- return false;
- }
- }
- }
- return true;
- }
-
- // If attrbutes and values are the same > remove
- // if attributes or values
- function updateElementAttributes(element, newAttributes, toggle) {
- var attr = wysihtml5.dom.getAttributes(element),
- fullContain = containsSameAttributes(newAttributes, attr),
- attrDifference = wysihtml5.lang.object(attr).difference(newAttributes),
- a, b;
-
- if (fullContain && toggle !== false) {
- for (a in newAttributes) {
- if (newAttributes.hasOwnProperty(a)) {
- element.removeAttribute(a);
- }
- }
- } else {
-
- /*if (!wysihtml5.lang.object(attrDifference).isEmpty()) {
- for (b in attrDifference) {
- if (attrDifference.hasOwnProperty(b)) {
- element.removeAttribute(b);
- }
- }
- }*/
-
- for (a in newAttributes) {
- if (newAttributes.hasOwnProperty(a)) {
- element.setAttribute(a, newAttributes[a]);
- }
- }
- }
- }
-
- function updateFormatOfElement(element, options) {
- var attr, newNode, a, newAttributes, nodeNameQuery, nodeQueryMatch;
-
- if (options.className) {
- if (options.toggle !== false && element.classList.contains(options.className)) {
- element.classList.remove(options.className);
- } else {
- if (options.classRegExp) {
- element.className = element.className.replace(options.classRegExp, '');
- }
- element.classList.add(options.className);
- }
- if (hasNoClass(element)) {
- element.removeAttribute('class');
- }
- }
-
- // change/remove style
- if (options.styleProperty) {
- if (options.toggle !== false && element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)].trim().replace(/, /g, ",") === options.styleValue) {
- element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)] = '';
- } else {
- element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)] = options.styleValue;
- }
- }
- if (hasNoStyle(element)) {
- element.removeAttribute('style');
- }
-
- if (options.attribute) {
- if (typeof options.attribute === "object") {
- newAttributes = options.attribute;
- } else {
- newAttributes = {};
- newAttributes[options.attribute] = options.attributeValue || '';
- }
- updateElementAttributes(element, newAttributes, options.toggle);
- }
-
-
- // Handle similar semantically same elements (queryAliasMap)
- nodeNameQuery = options.nodeName ? queryAliasMap[options.nodeName.toLowerCase()] || options.nodeName.toLowerCase() : null;
- nodeQueryMatch = nodeNameQuery ? wysihtml5.dom.domNode(element).test({ query: nodeNameQuery }) : false;
-
- // Unwrap element if no attributes present and node name given
- // or no attributes and if no nodename set but node is the default
- if (!options.nodeName || options.nodeName === defaultTag || nodeQueryMatch) {
- if (
- ((options.toggle !== false && nodeQueryMatch) || (!options.nodeName && element.nodeName === defaultTag)) &&
- hasNoClass(element) && hasNoStyle(element) && hasNoAttributes(element)
- ) {
- wysihtml5.dom.unwrap(element);
- }
-
- }
- }
-
- // Fetch all textnodes in selection
- // Empty textnodes are ignored except the one containing text caret
- function getSelectedTextNodes(selection, splitBounds) {
- var textNodes = [];
-
- if (!selection.isCollapsed()) {
- textNodes = textNodes.concat(selection.getOwnNodes([3], function(node) {
- // Exclude empty nodes except caret node
- return (!wysihtml5.dom.domNode(node).is.emptyTextNode());
- }, splitBounds));
- }
-
- return textNodes;
- }
-
- function findSimilarTextNodeWrapper(textNode, options, container, exact) {
- var node = textNode,
- similarOptions = exact ? options : correctOptionsForSimilarityCheck(options);
-
- do {
- if (node.nodeType === 1 && isSimilarNode(node, similarOptions)) {
- return node;
- }
- node = node.parentNode;
- } while (node && node !== container);
-
- return null;
- }
-
- function correctOptionsForSimilarityCheck(options) {
- return {
- nodeName: options.nodeName || null,
- className: (!options.classRegExp) ? options.className || null : null,
- classRegExp: options.classRegExp || null,
- styleProperty: options.styleProperty || null
- };
- }
-
- // Finds inline node with similar nodeName/style/className
- // If nodeName is specified inline node with the same (or alias) nodeName is expected to prove similar regardless of attributes
- function isSimilarNode(node, options) {
- var o;
- if (options.nodeName) {
- var query = queryAliasMap[options.nodeName.toLowerCase()] || options.nodeName.toLowerCase();
- return wysihtml5.dom.domNode(node).test({ query: query });
- } else {
- o = wysihtml5.lang.object(options).clone();
- o.query = INLINE_ELEMENTS; // make sure only inline elements with styles and classes are counted
- return wysihtml5.dom.domNode(node).test(o);
- }
- }
-
- function selectRange(composer, range) {
- var d = document.documentElement || document.body,
- oldScrollTop = d.scrollTop,
- oldScrollLeft = d.scrollLeft,
- selection = rangy.getSelection(composer.win);
-
- rangy.getSelection(composer.win).removeAllRanges();
-
- // IE looses focus of contenteditable on removeallranges and can not set new selection unless contenteditable is focused again
- try {
- rangy.getSelection(composer.win).addRange(range);
- } catch (e) {}
- if (!composer.doc.activeElement || !wysihtml5.dom.contains(composer.element, composer.doc.activeElement)) {
- composer.element.focus();
- d.scrollTop = oldScrollTop;
- d.scrollLeft = oldScrollLeft;
- rangy.getSelection(composer.win).addRange(range);
- }
- }
-
- function selectTextNodes(textNodes, composer) {
- var range = rangy.createRange(composer.doc),
- lastText = textNodes[textNodes.length - 1];
-
- if (textNodes[0] && lastText) {
- range.setStart(textNodes[0], 0);
- range.setEnd(lastText, lastText.length);
- selectRange(composer, range);
- }
-
- }
-
- function selectTextNode(composer, node, start, end) {
- var range = rangy.createRange(composer.doc);
- if (node) {
- range.setStart(node, start);
- range.setEnd(node, typeof end !== 'undefined' ? end : start);
- selectRange(composer, range);
- }
- }
-
- function getState(composer, options, exact) {
- var searchNodes = getSelectedTextNodes(composer.selection),
- nodes = [],
- partial = false,
- node, range, caretNode;
-
- if (composer.selection.isInThisEditable()) {
-
- if (searchNodes.length === 0 && composer.selection.isCollapsed()) {
- caretNode = composer.selection.getSelection().anchorNode;
- if (!caretNode) {
- // selection not in editor
- return {
- nodes: [],
- partial: false
- };
- }
- if (caretNode.nodeType === 3) {
- searchNodes = [caretNode];
- }
- }
-
- // Handle collapsed selection caret
- if (!searchNodes.length) {
- range = composer.selection.getOwnRanges()[0];
- if (range) {
- searchNodes = [range.endContainer];
- }
- }
-
- for (var i = 0, maxi = searchNodes.length; i < maxi; i++) {
- node = findSimilarTextNodeWrapper(searchNodes[i], options, composer.element, exact);
- if (node) {
- nodes.push(node);
- } else {
- partial = true;
- }
- }
-
- }
-
- return {
- nodes: nodes,
- partial: partial
- };
- }
-
- // Returns if caret is inside a word in textnode (not on boundary)
- // If selection anchornode is not text node, returns false
- function caretIsInsideWord(selection) {
- var anchor, offset, beforeChar, afterChar;
- if (selection) {
- anchor = selection.anchorNode;
- offset = selection.anchorOffset;
- if (anchor && anchor.nodeType === 3 && offset > 0 && offset < anchor.data.length) {
- beforeChar = anchor.data[offset - 1];
- afterChar = anchor.data[offset];
- return (/\w/).test(beforeChar) && (/\w/).test(afterChar);
- }
- }
- return false;
- }
-
- // Returns a range and textnode containing object from caret position covering a whole word
- // wordOffsety describes the original position of caret in the new textNode
- // Caret has to be inside a textNode.
- function getRangeForWord(selection) {
- var anchor, offset, doc, range, offsetStart, offsetEnd, beforeChar, afterChar,
- txtNodes = [];
- if (selection) {
- anchor = selection.anchorNode;
- offset = offsetStart = offsetEnd = selection.anchorOffset;
- doc = anchor.ownerDocument;
- range = rangy.createRange(doc);
-
- if (anchor && anchor.nodeType === 3) {
-
- while (offsetStart > 0 && (/\w/).test(anchor.data[offsetStart - 1])) {
- offsetStart--;
- }
-
- while (offsetEnd < anchor.data.length && (/\w/).test(anchor.data[offsetEnd])) {
- offsetEnd++;
- }
-
- range.setStartAndEnd(anchor, offsetStart, offsetEnd);
- range.splitBoundaries();
- txtNodes = range.getNodes([3], function(node) {
- return (!wysihtml5.dom.domNode(node).is.emptyTextNode());
- });
-
- return {
- wordOffset: offset - offsetStart,
- range: range,
- textNode: txtNodes[0]
- };
-
- }
- }
- return false;
- }
-
- // Contents of 2 elements are merged to fitst element. second element is removed as consequence
- function mergeContents(element1, element2) {
- while (element2.firstChild) {
- element1.appendChild(element2.firstChild);
- }
- element2.parentNode.removeChild(element2);
- }
-
- function mergeConsequentSimilarElements(elements) {
- for (var i = elements.length; i--;) {
-
- if (elements[i] && elements[i].parentNode) { // Test if node is not allready removed in cleanup
-
- if (elements[i].nextSibling && isSameNode(elements[i], elements[i].nextSibling)) {
- mergeContents(elements[i], elements[i].nextSibling);
- }
-
- if (elements[i].previousSibling && isSameNode(elements[i] , elements[i].previousSibling)) {
- mergeContents(elements[i].previousSibling, elements[i]);
- }
-
- }
- }
- }
-
- function cleanupAndSetSelection(composer, textNodes, options) {
- if (textNodes.length > 0) {
- selectTextNodes(textNodes, composer);
- }
- mergeConsequentSimilarElements(getState(composer, options).nodes);
- if (textNodes.length > 0) {
- selectTextNodes(textNodes, composer);
- }
- }
-
- function cleanupAndSetCaret(composer, textNode, offset, options) {
- selectTextNode(composer, textNode, offset);
- mergeConsequentSimilarElements(getState(composer, options).nodes);
- selectTextNode(composer, textNode, offset);
- }
-
- // Formats a textnode with given options
- function formatTextNode(textNode, options) {
- var wrapNode = createWrapNode(textNode, options);
-
- textNode.parentNode.insertBefore(wrapNode, textNode);
- wrapNode.appendChild(textNode);
- }
-
- // Changes/toggles format of a textnode
- function unformatTextNode(textNode, composer, options) {
- var container = composer.element,
- wrapNode = findSimilarTextNodeWrapper(textNode, options, container),
- newWrapNode;
-
- if (wrapNode) {
- newWrapNode = wrapNode.cloneNode(false);
-
- wysihtml5.dom.domNode(textNode).escapeParent(wrapNode, newWrapNode);
- updateFormatOfElement(newWrapNode, options);
- }
- }
-
- // Removes the format around textnode
- function removeFormatFromTextNode(textNode, composer, options) {
- var container = composer.element,
- wrapNode = findSimilarTextNodeWrapper(textNode, options, container);
-
- if (wrapNode) {
- wysihtml5.dom.domNode(textNode).escapeParent(wrapNode);
- }
- }
-
- // Creates node around caret formated with options
- function formatTextRange(range, composer, options) {
- var wrapNode = createWrapNode(range.endContainer, options);
-
- range.surroundContents(wrapNode);
- composer.selection.selectNode(wrapNode);
- }
-
- // Changes/toggles format of whole selection
- function updateFormat(composer, textNodes, state, options) {
- var exactState = getState(composer, options, true),
- selection = composer.selection.getSelection(),
- wordObj, textNode, newNode, i;
-
- if (!textNodes.length) {
- // Selection is caret
-
-
- if (options.toggle !== false) {
- if (caretIsInsideWord(selection)) {
-
- // Unformat whole word
- wordObj = getRangeForWord(selection);
- textNode = wordObj.textNode;
- unformatTextNode(wordObj.textNode, composer, options);
- cleanupAndSetCaret(composer, wordObj.textNode, wordObj.wordOffset, options);
-
- } else {
-
- // Escape caret out of format
- textNode = composer.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
- newNode = state.nodes[0].cloneNode(false);
- newNode.appendChild(textNode);
- composer.selection.splitElementAtCaret(state.nodes[0], newNode);
- updateFormatOfElement(newNode, options);
- cleanupAndSetSelection(composer, [textNode], options);
- var s = composer.selection.getSelection();
- if (s.anchorNode && s.focusNode) {
- // Has an error in IE when collapsing selection. probably from rangy
- try {
- s.collapseToEnd();
- } catch (e) {}
- }
- }
- } else {
- // In non-toggle mode the closest state element has to be found and the state updated differently
- for (i = state.nodes.length; i--;) {
- updateFormatOfElement(state.nodes[i], options);
- }
- }
-
- } else {
-
- if (!exactState.partial && options.toggle !== false) {
-
- // If whole selection (all textnodes) are in the applied format
- // remove the format from selection
- // Non-toggle mode never removes. Remove has to be called explicitly
- for (i = textNodes.length; i--;) {
- unformatTextNode(textNodes[i], composer, options);
- }
-
- } else {
-
- // Selection is partially in format
- // change it to new if format if textnode allreafy in similar state
- // else just apply
-
- for (i = textNodes.length; i--;) {
-
- if (findSimilarTextNodeWrapper(textNodes[i], options, composer.element)) {
- unformatTextNode(textNodes[i], composer, options);
- }
-
- if (!findSimilarTextNodeWrapper(textNodes[i], options, composer.element)) {
- formatTextNode(textNodes[i], options);
- }
- }
-
- }
-
- cleanupAndSetSelection(composer, textNodes, options);
- }
- }
-
- // Removes format from selection
- function removeFormat(composer, textNodes, state, options) {
- var textNode, textOffset, newNode, i,
- selection = composer.selection.getSelection();
-
- if (!textNodes.length) {
- textNode = selection.anchorNode;
- textOffset = selection.anchorOffset;
-
- for (i = state.nodes.length; i--;) {
- wysihtml5.dom.unwrap(state.nodes[i]);
- }
-
- cleanupAndSetCaret(composer, textNode, textOffset, options);
- } else {
- for (i = textNodes.length; i--;) {
- removeFormatFromTextNode(textNodes[i], composer, options);
- }
- cleanupAndSetSelection(composer, textNodes, options);
- }
- }
-
- // Adds format to selection
- function applyFormat(composer, textNodes, options) {
- var wordObj, i,
- selection = composer.selection.getSelection();
-
- if (!textNodes.length) {
- // Handle collapsed selection caret and return
- if (caretIsInsideWord(selection)) {
-
- wordObj = getRangeForWord(selection);
- formatTextNode(wordObj.textNode, options);
- cleanupAndSetCaret(composer, wordObj.textNode, wordObj.wordOffset, options);
-
- } else {
- var r = composer.selection.getOwnRanges()[0];
- if (r) {
- formatTextRange(r, composer, options);
- }
- }
-
- } else {
- // Handle textnodes in selection and apply format
- for (i = textNodes.length; i--;) {
- formatTextNode(textNodes[i], options);
- }
- cleanupAndSetSelection(composer, textNodes, options);
- }
- }
-
- // If properties is passed as a string, correct options with that nodeName
- function fixOptions(options) {
- options = (typeof options === "string") ? { nodeName: options } : options;
- if (options.nodeName) { options.nodeName = options.nodeName.toUpperCase(); }
- return options;
- }
-
- wysihtml5.commands.formatInline = {
-
- // Basics:
- // In case of plain text or inline state not set wrap all non-empty textnodes with
- // In case a similar inline wrapper node is detected on one of textnodes, the wrapper node is changed (if fully contained) or split and changed (partially contained)
- // In case of changing mode every textnode is addressed separatly
- exec: function(composer, command, options) {
- options = fixOptions(options);
-
- // Join adjactent textnodes first
- composer.element.normalize();
-
- var textNodes = getSelectedTextNodes(composer.selection, true),
- state = getState(composer, options);
- if (state.nodes.length > 0) {
- // Text allready has the format applied
- updateFormat(composer, textNodes, state, options);
- } else {
- // Selection is not in the applied format
- applyFormat(composer, textNodes, options);
- }
- composer.element.normalize();
- },
-
- remove: function(composer, command, options) {
- options = fixOptions(options);
- composer.element.normalize();
-
- var textNodes = getSelectedTextNodes(composer.selection, true),
- state = getState(composer, options);
-
- if (state.nodes.length > 0) {
- // Text allready has the format applied
- removeFormat(composer, textNodes, state, options);
- }
-
- composer.element.normalize();
- },
-
- state: function(composer, command, options) {
- options = fixOptions(options);
- var nodes = getState(composer, options, true).nodes;
- return (nodes.length === 0) ? false : nodes;
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- nodeName: "BLOCKQUOTE",
- toggle: true
- };
-
- wysihtml5.commands.insertBlockQuote = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5){
- wysihtml5.commands.insertHTML = {
- exec: function(composer, command, html) {
- composer.selection.insertHTML(html);
- },
-
- state: function() {
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5) {
- var NODE_NAME = "IMG";
-
- wysihtml5.commands.insertImage = {
- /**
- * Inserts an
- * If selection is already an image link, it removes it
- *
- * @example
- * // either ...
- * wysihtml5.commands.insertImage.exec(composer, "insertImage", "http://www.google.de/logo.jpg");
- * // ... or ...
- * wysihtml5.commands.insertImage.exec(composer, "insertImage", { src: "http://www.google.de/logo.jpg", title: "foo" });
- */
- exec: function(composer, command, value) {
- value = typeof(value) === "object" ? value : { src: value };
-
- var doc = composer.doc,
- image = this.state(composer),
- textNode,
- parent;
-
- // If image is selected and src ie empty, set the caret before it and delete the image
- if (image && !value.src) {
- composer.selection.setBefore(image);
- parent = image.parentNode;
- parent.removeChild(image);
-
- // and it's parent too if it hasn't got any other relevant child nodes
- wysihtml5.dom.removeEmptyTextNodes(parent);
- if (parent.nodeName === "A" && !parent.firstChild) {
- composer.selection.setAfter(parent);
- parent.parentNode.removeChild(parent);
- }
-
- // firefox and ie sometimes don't remove the image handles, even though the image got removed
- wysihtml5.quirks.redraw(composer.element);
- return;
- }
-
- // If image selected change attributes accordingly
- if (image) {
- for (var key in value) {
- if (value.hasOwnProperty(key)) {
- image.setAttribute(key === "className" ? "class" : key, value[key]);
- }
- }
- return;
- }
-
- // Otherwise lets create the image
- image = doc.createElement(NODE_NAME);
-
- for (var i in value) {
- image.setAttribute(i === "className" ? "class" : i, value[i]);
- }
-
- composer.selection.insertNode(image);
- if (wysihtml5.browser.hasProblemsSettingCaretAfterImg()) {
- textNode = doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
- composer.selection.insertNode(textNode);
- composer.selection.setAfter(textNode);
- } else {
- composer.selection.setAfter(image);
- }
- },
-
- state: function(composer) {
- var doc = composer.doc,
- selectedNode,
- text,
- imagesInSelection;
-
- if (!wysihtml5.dom.hasElementWithTagName(doc, NODE_NAME)) {
- return false;
- }
-
- selectedNode = composer.selection.getSelectedNode();
- if (!selectedNode) {
- return false;
- }
-
- if (selectedNode.nodeName === NODE_NAME) {
- // This works perfectly in IE
- return selectedNode;
- }
-
- if (selectedNode.nodeType !== wysihtml5.ELEMENT_NODE) {
- return false;
- }
-
- text = composer.selection.getText();
- text = wysihtml5.lang.string(text).trim();
- if (text) {
- return false;
- }
-
- imagesInSelection = composer.selection.getNodes(wysihtml5.ELEMENT_NODE, function(node) {
- return node.nodeName === "IMG";
- });
-
- if (imagesInSelection.length !== 1) {
- return false;
- }
-
- return imagesInSelection[0];
- }
- };
-})(wysihtml5);
-;(function(wysihtml5) {
- var LINE_BREAK = " " + (wysihtml5.browser.needsSpaceAfterLineBreak() ? " " : "");
-
- wysihtml5.commands.insertLineBreak = {
- exec: function(composer, command) {
- composer.selection.insertHTML(LINE_BREAK);
- },
-
- state: function() {
- return false;
- }
- };
-})(wysihtml5);
-;(function(wysihtml5){
- wysihtml5.commands.insertOrderedList = {
- exec: function(composer, command) {
- wysihtml5.commands.insertList.exec(composer, command, "OL");
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.insertList.state(composer, command, "OL");
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.insertUnorderedList = {
- exec: function(composer, command) {
- wysihtml5.commands.insertList.exec(composer, command, "UL");
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.insertList.state(composer, command, "UL");
- }
- };
-}(wysihtml5));
-;wysihtml5.commands.insertList = (function(wysihtml5) {
-
- var isNode = function(node, name) {
- if (node && node.nodeName) {
- if (typeof name === 'string') {
- name = [name];
- }
- for (var n = name.length; n--;) {
- if (node.nodeName === name[n]) {
- return true;
- }
- }
- }
- return false;
- };
-
- var findListEl = function(node, nodeName, composer) {
- var ret = {
- el: null,
- other: false
- };
-
- if (node) {
- var parentLi = wysihtml5.dom.getParentElement(node, { query: "li" }, false, composer.element),
- otherNodeName = (nodeName === "UL") ? "OL" : "UL";
-
- if (isNode(node, nodeName)) {
- ret.el = node;
- } else if (isNode(node, otherNodeName)) {
- ret = {
- el: node,
- other: true
- };
- } else if (parentLi) {
- if (isNode(parentLi.parentNode, nodeName)) {
- ret.el = parentLi.parentNode;
- } else if (isNode(parentLi.parentNode, otherNodeName)) {
- ret = {
- el : parentLi.parentNode,
- other: true
- };
- }
- }
- }
-
- // do not count list elements outside of composer
- if (ret.el && !composer.element.contains(ret.el)) {
- ret.el = null;
- }
-
- return ret;
- };
-
- var handleSameTypeList = function(el, nodeName, composer) {
- var otherNodeName = (nodeName === "UL") ? "OL" : "UL",
- otherLists, innerLists;
- // Unwrap list
- //
- // becomes:
- // foo bar
-
- composer.selection.executeAndRestoreRangy(function() {
- otherLists = getListsInSelection(otherNodeName, composer);
- if (otherLists.length) {
- for (var l = otherLists.length; l--;) {
- wysihtml5.dom.renameElement(otherLists[l], nodeName.toLowerCase());
- }
- } else {
- innerLists = getListsInSelection(['OL', 'UL'], composer);
- for (var i = innerLists.length; i--;) {
- wysihtml5.dom.resolveList(innerLists[i], composer.config.useLineBreaks);
- }
- if (innerLists.length === 0) {
- wysihtml5.dom.resolveList(el, composer.config.useLineBreaks);
- }
- }
- });
- };
-
- var handleOtherTypeList = function(el, nodeName, composer) {
- var otherNodeName = (nodeName === "UL") ? "OL" : "UL";
- // Turn an ordered list into an unordered list
- // foo bar
- // becomes:
- //
- // Also rename other lists in selection
- composer.selection.executeAndRestoreRangy(function() {
- var renameLists = [el].concat(getListsInSelection(otherNodeName, composer));
-
- // All selection inner lists get renamed too
- for (var l = renameLists.length; l--;) {
- wysihtml5.dom.renameElement(renameLists[l], nodeName.toLowerCase());
- }
- });
- };
-
- var getListsInSelection = function(nodeName, composer) {
- var ranges = composer.selection.getOwnRanges(),
- renameLists = [];
-
- for (var r = ranges.length; r--;) {
- renameLists = renameLists.concat(ranges[r].getNodes([1], function(node) {
- return isNode(node, nodeName);
- }));
- }
-
- return renameLists;
- };
-
- var createListFallback = function(nodeName, composer) {
- var sel = rangy.saveSelection(composer.win);
-
- // Fallback for Create list
- var tempClassName = "_wysihtml5-temp-" + new Date().getTime(),
- isEmpty, list;
-
- composer.commands.exec("formatBlock", {
- "nodeName": "div",
- "className": tempClassName
- });
-
- var tempElement = composer.element.querySelector("." + tempClassName);
-
- // This space causes new lists to never break on enter
- var INVISIBLE_SPACE_REG_EXP = /\uFEFF/g;
- tempElement.innerHTML = tempElement.innerHTML.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
- if (tempElement) {
- isEmpty = (/^(\s|( ))+$/i).test(tempElement.innerHTML);
- list = wysihtml5.dom.convertToList(tempElement, nodeName.toLowerCase(), composer.parent.config.classNames.uneditableContainer);
- if (sel) {
- rangy.restoreSelection(sel);
- }
- if (isEmpty) {
- composer.selection.selectNode(list.querySelector("li"), true);
- }
- }
- };
-
- return {
- exec: function(composer, command, nodeName) {
- var doc = composer.doc,
- cmd = (nodeName === "OL") ? "insertOrderedList" : "insertUnorderedList",
- s = composer.selection.getSelection(),
- anode = s.anchorNode.nodeType === 1 && s.anchorNode.firstChild ? s.anchorNode.childNodes[s.anchorOffset] : s.anchorNode,
- fnode = s.focusNode.nodeType === 1 && s.focusNode.firstChild ? s.focusNode.childNodes[s.focusOffset] || s.focusNode.lastChild : s.focusNode,
- selectedNode, list;
-
- if (s.isBackwards()) {
- // swap variables
- anode = [fnode, fnode = anode][0];
- }
-
- if (wysihtml5.dom.domNode(fnode).is.emptyTextNode(true) && fnode) {
- fnode = wysihtml5.dom.domNode(fnode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
- }
- if (wysihtml5.dom.domNode(anode).is.emptyTextNode(true) && anode) {
- anode = wysihtml5.dom.domNode(anode).next({nodeTypes: [1,3], ignoreBlankTexts: true});
- }
-
- if (anode && fnode) {
- if (anode === fnode) {
- selectedNode = anode;
- } else {
- selectedNode = wysihtml5.dom.domNode(anode).commonAncestor(fnode, composer.element);
- }
- } else {
- selectedNode = composer.selection.getSelectedNode();
- }
-
- list = findListEl(selectedNode, nodeName, composer);
-
- if (!list.el) {
- if (composer.commands.support(cmd)) {
- doc.execCommand(cmd, false, null);
- } else {
- createListFallback(nodeName, composer);
- }
- } else if (list.other) {
- handleOtherTypeList(list.el, nodeName, composer);
- } else {
- handleSameTypeList(list.el, nodeName, composer);
- }
- },
-
- state: function(composer, command, nodeName) {
- var selectedNode = composer.selection.getSelectedNode(),
- list = findListEl(selectedNode, nodeName, composer);
-
- return (list.el && !list.other) ? list.el : false;
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5){
-
- var nodeOptions = {
- nodeName: "I",
- toggle: true
- };
-
- wysihtml5.commands.italic = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.exec(composer, command, nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-
-}(wysihtml5));
-;(function(wysihtml5) {
-
- var nodeOptions = {
- className: "wysiwyg-text-align-center",
- classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
- toggle: true
- };
-
- wysihtml5.commands.justifyCenter = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- className: "wysiwyg-text-align-left",
- classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
- toggle: true
- };
-
- wysihtml5.commands.justifyLeft = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- className: "wysiwyg-text-align-right",
- classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
- toggle: true
- };
-
- wysihtml5.commands.justifyRight = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- className: "wysiwyg-text-align-justify",
- classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
- toggle: true
- };
-
- wysihtml5.commands.justifyFull = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- styleProperty: "textAlign",
- styleValue: "right",
- toggle: true
- };
-
- wysihtml5.commands.alignRightStyle = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- styleProperty: "textAlign",
- styleValue: "left",
- toggle: true
- };
-
- wysihtml5.commands.alignLeftStyle = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- styleProperty: "textAlign",
- styleValue: "center",
- toggle: true
- };
-
- wysihtml5.commands.alignCenterStyle = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- styleProperty: "textAlign",
- styleValue: "justify",
- toggle: true
- };
-
- wysihtml5.commands.alignJustifyStyle = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-})(wysihtml5);
-;(function(wysihtml5){
- wysihtml5.commands.redo = {
- exec: function(composer) {
- return composer.undoManager.redo();
- },
-
- state: function(composer) {
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
-
- var nodeOptions = {
- nodeName: "U",
- toggle: true
- };
-
- wysihtml5.commands.underline = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.exec(composer, command, nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.undo = {
- exec: function(composer) {
- return composer.undoManager.undo();
- },
-
- state: function(composer) {
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.createTable = {
- exec: function(composer, command, value) {
- var col, row, html;
- if (value && value.cols && value.rows && parseInt(value.cols, 10) > 0 && parseInt(value.rows, 10) > 0) {
- if (value.tableStyle) {
- html = " ";
- } else {
- html = "";
- }
- html += "";
- for (row = 0; row < value.rows; row ++) {
- html += '';
- for (col = 0; col < value.cols; col ++) {
- html += " ";
- }
- html += ' ';
- }
- html += "
";
- composer.commands.exec("insertHTML", html);
- //composer.selection.insertHTML(html);
- }
- },
-
- state: function(composer, command) {
- return false;
- }
- };
-
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.mergeTableCells = {
- exec: function(composer, command) {
- if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
- if (this.state(composer, command)) {
- wysihtml5.dom.table.unmergeCell(composer.tableSelection.start);
- } else {
- wysihtml5.dom.table.mergeCellsBetween(composer.tableSelection.start, composer.tableSelection.end);
- }
- }
- },
-
- state: function(composer, command) {
- if (composer.tableSelection) {
- var start = composer.tableSelection.start,
- end = composer.tableSelection.end;
- if (start && end && start == end &&
- ((
- wysihtml5.dom.getAttribute(start, "colspan") &&
- parseInt(wysihtml5.dom.getAttribute(start, "colspan"), 10) > 1
- ) || (
- wysihtml5.dom.getAttribute(start, "rowspan") &&
- parseInt(wysihtml5.dom.getAttribute(start, "rowspan"), 10) > 1
- ))
- ) {
- return [start];
- }
- }
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.addTableCells = {
- exec: function(composer, command, value) {
- if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
-
- // switches start and end if start is bigger than end (reverse selection)
- var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end);
- if (value == "before" || value == "above") {
- wysihtml5.dom.table.addCells(tableSelect.start, value);
- } else if (value == "after" || value == "below") {
- wysihtml5.dom.table.addCells(tableSelect.end, value);
- }
- setTimeout(function() {
- composer.tableSelection.select(tableSelect.start, tableSelect.end);
- },0);
- }
- },
-
- state: function(composer, command) {
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.deleteTableCells = {
- exec: function(composer, command, value) {
- if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
- var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end),
- idx = wysihtml5.dom.table.indexOf(tableSelect.start),
- selCell,
- table = composer.tableSelection.table;
-
- wysihtml5.dom.table.removeCells(tableSelect.start, value);
- setTimeout(function() {
- // move selection to next or previous if not present
- selCell = wysihtml5.dom.table.findCell(table, idx);
-
- if (!selCell){
- if (value == "row") {
- selCell = wysihtml5.dom.table.findCell(table, {
- "row": idx.row - 1,
- "col": idx.col
- });
- }
-
- if (value == "column") {
- selCell = wysihtml5.dom.table.findCell(table, {
- "row": idx.row,
- "col": idx.col - 1
- });
- }
- }
- if (selCell) {
- composer.tableSelection.select(selCell, selCell);
- }
- }, 0);
- }
- },
-
- state: function(composer, command) {
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.indentList = {
- exec: function(composer, command, value) {
- var listEls = composer.selection.getSelectionParentsByTag('LI');
- if (listEls) {
- return this.tryToPushLiLevel(listEls, composer.selection);
- }
- return false;
- },
-
- state: function(composer, command) {
- return false;
- },
-
- tryToPushLiLevel: function(liNodes, selection) {
- var listTag, list, prevLi, liNode, prevLiList,
- found = false;
-
- selection.executeAndRestoreRangy(function() {
-
- for (var i = liNodes.length; i--;) {
- liNode = liNodes[i];
- listTag = (liNode.parentNode.nodeName === 'OL') ? 'OL' : 'UL';
- list = liNode.ownerDocument.createElement(listTag);
- prevLi = wysihtml5.dom.domNode(liNode).prev({nodeTypes: [wysihtml5.ELEMENT_NODE]});
- prevLiList = (prevLi) ? prevLi.querySelector('ul, ol') : null;
-
- if (prevLi) {
- if (prevLiList) {
- prevLiList.appendChild(liNode);
- } else {
- list.appendChild(liNode);
- prevLi.appendChild(list);
- }
- found = true;
- }
- }
-
- });
- return found;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
-
- wysihtml5.commands.outdentList = {
- exec: function(composer, command, value) {
- var listEls = composer.selection.getSelectionParentsByTag('LI');
- if (listEls) {
- return this.tryToPullLiLevel(listEls, composer);
- }
- return false;
- },
-
- state: function(composer, command) {
- return false;
- },
-
- tryToPullLiLevel: function(liNodes, composer) {
- var listNode, outerListNode, outerLiNode, list, prevLi, liNode, afterList,
- found = false,
- that = this;
-
- composer.selection.executeAndRestoreRangy(function() {
-
- for (var i = liNodes.length; i--;) {
- liNode = liNodes[i];
- if (liNode.parentNode) {
- listNode = liNode.parentNode;
-
- if (listNode.tagName === 'OL' || listNode.tagName === 'UL') {
- found = true;
-
- outerListNode = wysihtml5.dom.getParentElement(listNode.parentNode, { query: 'ol, ul' }, false, composer.element);
- outerLiNode = wysihtml5.dom.getParentElement(listNode.parentNode, { query: 'li' }, false, composer.element);
-
- if (outerListNode && outerLiNode) {
-
- if (liNode.nextSibling) {
- afterList = that.getAfterList(listNode, liNode);
- liNode.appendChild(afterList);
- }
- outerListNode.insertBefore(liNode, outerLiNode.nextSibling);
-
- } else {
-
- if (liNode.nextSibling) {
- afterList = that.getAfterList(listNode, liNode);
- liNode.appendChild(afterList);
- }
-
- for (var j = liNode.childNodes.length; j--;) {
- listNode.parentNode.insertBefore(liNode.childNodes[j], listNode.nextSibling);
- }
-
- listNode.parentNode.insertBefore(document.createElement('br'), listNode.nextSibling);
- liNode.parentNode.removeChild(liNode);
-
- }
-
- // cleanup
- if (listNode.childNodes.length === 0) {
- listNode.parentNode.removeChild(listNode);
- }
- }
- }
- }
-
- });
- return found;
- },
-
- getAfterList: function(listNode, liNode) {
- var nodeName = listNode.nodeName,
- newList = document.createElement(nodeName);
-
- while (liNode.nextSibling) {
- newList.appendChild(liNode.nextSibling);
- }
- return newList;
- }
-
- };
-}(wysihtml5));
-;(function(wysihtml5){
-
- var nodeOptions = {
- nodeName: "SUB",
- toggle: true
- };
-
- wysihtml5.commands.subscript = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.exec(composer, command, nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-}(wysihtml5));
-;(function(wysihtml5) {
-
- var nodeOptions = {
- nodeName: "SUP",
- toggle: true
- };
-
- wysihtml5.commands.superscript = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.exec(composer, command, nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-}(wysihtml5));
-;/**
- * Undo Manager for wysihtml5
- * slightly inspired by http://rniwa.com/editing/undomanager.html#the-undomanager-interface
- */
-(function(wysihtml5) {
- var Z_KEY = 90,
- Y_KEY = 89,
- BACKSPACE_KEY = 8,
- DELETE_KEY = 46,
- MAX_HISTORY_ENTRIES = 25,
- DATA_ATTR_NODE = "data-wysihtml5-selection-node",
- DATA_ATTR_OFFSET = "data-wysihtml5-selection-offset",
- UNDO_HTML = '' + wysihtml5.INVISIBLE_SPACE + ' ',
- REDO_HTML = '' + wysihtml5.INVISIBLE_SPACE + ' ',
- dom = wysihtml5.dom;
-
- function cleanTempElements(doc) {
- var tempElement;
- while (tempElement = doc.querySelector("._wysihtml5-temp")) {
- tempElement.parentNode.removeChild(tempElement);
- }
- }
-
- wysihtml5.UndoManager = wysihtml5.lang.Dispatcher.extend(
- /** @scope wysihtml5.UndoManager.prototype */ {
- constructor: function(editor) {
- this.editor = editor;
- this.composer = editor.composer;
- this.element = this.composer.element;
-
- this.position = 0;
- this.historyStr = [];
- this.historyDom = [];
-
- this.transact();
-
- this._observe();
- },
-
- _observe: function() {
- var that = this,
- doc = this.composer.sandbox.getDocument(),
- lastKey;
-
- // Catch CTRL+Z and CTRL+Y
- dom.observe(this.element, "keydown", function(event) {
- if (event.altKey || (!event.ctrlKey && !event.metaKey)) {
- return;
- }
-
- var keyCode = event.keyCode,
- isUndo = keyCode === Z_KEY && !event.shiftKey,
- isRedo = (keyCode === Z_KEY && event.shiftKey) || (keyCode === Y_KEY);
-
- if (isUndo) {
- that.undo();
- event.preventDefault();
- } else if (isRedo) {
- that.redo();
- event.preventDefault();
- }
- });
-
- // Catch delete and backspace
- dom.observe(this.element, "keydown", function(event) {
- var keyCode = event.keyCode;
- if (keyCode === lastKey) {
- return;
- }
-
- lastKey = keyCode;
-
- if (keyCode === BACKSPACE_KEY || keyCode === DELETE_KEY) {
- that.transact();
- }
- });
-
- this.editor
- .on("newword:composer", function() {
- that.transact();
- })
-
- .on("beforecommand:composer", function() {
- that.transact();
- });
- },
-
- transact: function() {
- var previousHtml = this.historyStr[this.position - 1],
- currentHtml = this.composer.getValue(false, false),
- composerIsVisible = this.element.offsetWidth > 0 && this.element.offsetHeight > 0,
- range, node, offset, element, position;
-
- if (currentHtml === previousHtml) {
- return;
- }
-
- var length = this.historyStr.length = this.historyDom.length = this.position;
- if (length > MAX_HISTORY_ENTRIES) {
- this.historyStr.shift();
- this.historyDom.shift();
- this.position--;
- }
-
- this.position++;
-
- if (composerIsVisible) {
- // Do not start saving selection if composer is not visible
- range = this.composer.selection.getRange();
- node = (range && range.startContainer) ? range.startContainer : this.element;
- offset = (range && range.startOffset) ? range.startOffset : 0;
-
- if (node.nodeType === wysihtml5.ELEMENT_NODE) {
- element = node;
- } else {
- element = node.parentNode;
- position = this.getChildNodeIndex(element, node);
- }
-
- element.setAttribute(DATA_ATTR_OFFSET, offset);
- if (typeof(position) !== "undefined") {
- element.setAttribute(DATA_ATTR_NODE, position);
- }
- }
-
- var clone = this.element.cloneNode(!!currentHtml);
- this.historyDom.push(clone);
- this.historyStr.push(currentHtml);
-
- if (element) {
- element.removeAttribute(DATA_ATTR_OFFSET);
- element.removeAttribute(DATA_ATTR_NODE);
- }
-
- },
-
- undo: function() {
- this.transact();
-
- if (!this.undoPossible()) {
- return;
- }
-
- this.set(this.historyDom[--this.position - 1]);
- this.editor.fire("undo:composer");
- },
-
- redo: function() {
- if (!this.redoPossible()) {
- return;
- }
-
- this.set(this.historyDom[++this.position - 1]);
- this.editor.fire("redo:composer");
- },
-
- undoPossible: function() {
- return this.position > 1;
- },
-
- redoPossible: function() {
- return this.position < this.historyStr.length;
- },
-
- set: function(historyEntry) {
- this.element.innerHTML = "";
-
- var i = 0,
- childNodes = historyEntry.childNodes,
- length = historyEntry.childNodes.length;
-
- for (; i";
- },
-
- getValue: function(parse, clearInternals) {
- var value = this.isEmpty() ? "" : wysihtml5.quirks.getCorrectInnerHTML(this.element);
- if (parse !== false) {
- value = this.parent.parse(value, (clearInternals === false) ? false : true);
- }
- return value;
- },
-
- setValue: function(html, parse) {
- if (parse !== false) {
- html = this.parent.parse(html);
- }
-
- try {
- this.element.innerHTML = html;
- } catch (e) {
- this.element.innerText = html;
- }
- },
-
- cleanUp: function(rules) {
- var bookmark;
- if (this.selection && this.selection.isInThisEditable()) {
- bookmark = rangy.saveSelection(this.win);
- }
- this.parent.parse(this.element, undefined, rules);
- if (bookmark) {
- rangy.restoreSelection(bookmark);
- }
- },
-
- show: function() {
- this.editableArea.style.display = this._displayStyle || "";
-
- if (!this.config.noTextarea && !this.textarea.element.disabled) {
- // Firefox needs this, otherwise contentEditable becomes uneditable
- this.disable();
- this.enable();
- }
- },
-
- hide: function() {
- this._displayStyle = dom.getStyle("display").from(this.editableArea);
- if (this._displayStyle === "none") {
- this._displayStyle = null;
- }
- this.editableArea.style.display = "none";
- },
-
- disable: function() {
- this.parent.fire("disable:composer");
- this.element.removeAttribute("contentEditable");
- },
-
- enable: function() {
- this.parent.fire("enable:composer");
- this.element.setAttribute("contentEditable", "true");
- },
-
- focus: function(setToEnd) {
- // IE 8 fires the focus event after .focus()
- // This is needed by our simulate_placeholder.js to work
- // therefore we clear it ourselves this time
- if (wysihtml5.browser.doesAsyncFocus() && this.hasPlaceholderSet()) {
- this.clear();
- }
-
- this.base();
-
- var lastChild = this.element.lastChild;
- if (setToEnd && lastChild && this.selection) {
- if (lastChild.nodeName === "BR") {
- this.selection.setBefore(this.element.lastChild);
- } else {
- this.selection.setAfter(this.element.lastChild);
- }
- }
- },
-
- getScrollPos: function() {
- if (this.doc && this.win) {
- var pos = {};
-
- if (typeof this.win.pageYOffset !== "undefined") {
- pos.y = this.win.pageYOffset;
- } else {
- pos.y = (this.doc.documentElement || this.doc.body.parentNode || this.doc.body).scrollTop;
- }
-
- if (typeof this.win.pageXOffset !== "undefined") {
- pos.x = this.win.pageXOffset;
- } else {
- pos.x = (this.doc.documentElement || this.doc.body.parentNode || this.doc.body).scrollLeft;
- }
-
- return pos;
- }
- },
-
- setScrollPos: function(pos) {
- if (pos && typeof pos.x !== "undefined" && typeof pos.y !== "undefined") {
- this.win.scrollTo(pos.x, pos.y);
- }
- },
-
- getTextContent: function() {
- return dom.getTextContent(this.element);
- },
-
- hasPlaceholderSet: function() {
- return this.getTextContent() == ((this.config.noTextarea) ? this.editableArea.getAttribute("data-placeholder") : this.textarea.element.getAttribute("placeholder")) && this.placeholderSet;
- },
-
- isEmpty: function() {
- var innerHTML = this.element.innerHTML.toLowerCase();
- return (/^(\s| |<\/br>||<\/p>)*$/i).test(innerHTML) ||
- innerHTML === "" ||
- innerHTML === " " ||
- innerHTML === "
" ||
- innerHTML === "
" ||
- this.hasPlaceholderSet();
- },
-
- _initContentEditableArea: function() {
- var that = this;
- if (this.config.noTextarea) {
- this.sandbox = new dom.ContentEditableArea(function() {
- that._create();
- }, {
- className: this.config.classNames.sandbox
- }, this.editableArea);
- } else {
- this.sandbox = new dom.ContentEditableArea(function() {
- that._create();
- }, {
- className: this.config.classNames.sandbox
- });
- this.editableArea = this.sandbox.getContentEditable();
- dom.insert(this.editableArea).after(this.textarea.element);
- this._createWysiwygFormField();
- }
- },
-
- _initSandbox: function() {
- var that = this;
- this.sandbox = new dom.Sandbox(function() {
- that._create();
- }, {
- stylesheets: this.config.stylesheets,
- className: this.config.classNames.sandbox
- });
- this.editableArea = this.sandbox.getIframe();
-
- var textareaElement = this.textarea.element;
- dom.insert(this.editableArea).after(textareaElement);
-
- this._createWysiwygFormField();
- },
-
- // Creates hidden field which tells the server after submit, that the user used an wysiwyg editor
- _createWysiwygFormField: function() {
- if (this.textarea.element.form) {
- var hiddenField = document.createElement("input");
- hiddenField.type = "hidden";
- hiddenField.name = "_wysihtml5_mode";
- hiddenField.value = 1;
- dom.insert(hiddenField).after(this.textarea.element);
- }
- },
-
- _create: function() {
- var that = this;
- this.doc = this.sandbox.getDocument();
- this.win = this.sandbox.getWindow();
- this.element = (this.config.contentEditableMode) ? this.sandbox.getContentEditable() : this.doc.body;
- if (!this.config.noTextarea) {
- this.textarea = this.parent.textarea;
- this.element.innerHTML = this.textarea.getValue(true, false);
- } else {
- this.cleanUp(); // cleans contenteditable on initiation as it may contain html
- }
-
- // Make sure our selection handler is ready
- this.selection = new wysihtml5.Selection(this.parent, this.element, this.config.classNames.uneditableContainer);
-
- // Make sure commands dispatcher is ready
- this.commands = new wysihtml5.Commands(this.parent);
-
- if (!this.config.noTextarea) {
- dom.copyAttributes([
- "className", "spellcheck", "title", "lang", "dir", "accessKey"
- ]).from(this.textarea.element).to(this.element);
- }
-
- this._initAutoLinking();
-
- dom.addClass(this.element, this.config.classNames.composer);
- //
- // Make the editor look like the original textarea, by syncing styles
- if (this.config.style && !this.config.contentEditableMode) {
- this.style();
- }
-
- this.observe();
-
- var name = this.config.name;
- if (name) {
- dom.addClass(this.element, name);
- if (!this.config.contentEditableMode) { dom.addClass(this.editableArea, name); }
- }
-
- this.enable();
-
- if (!this.config.noTextarea && this.textarea.element.disabled) {
- this.disable();
- }
-
- // Simulate html5 placeholder attribute on contentEditable element
- var placeholderText = typeof(this.config.placeholder) === "string"
- ? this.config.placeholder
- : ((this.config.noTextarea) ? this.editableArea.getAttribute("data-placeholder") : this.textarea.element.getAttribute("placeholder"));
- if (placeholderText) {
- dom.simulatePlaceholder(this.parent, this, placeholderText, this.config.classNames.placeholder);
- }
-
- // Make sure that the browser avoids using inline styles whenever possible
- this.commands.exec("styleWithCSS", false);
-
- this._initObjectResizing();
- this._initUndoManager();
- this._initLineBreaking();
-
- // Simulate html5 autofocus on contentEditable element
- // This doesn't work on IOS (5.1.1)
- if (!this.config.noTextarea && (this.textarea.element.hasAttribute("autofocus") || document.querySelector(":focus") == this.textarea.element) && !browser.isIos()) {
- setTimeout(function() { that.focus(true); }, 100);
- }
-
- // IE sometimes leaves a single paragraph, which can't be removed by the user
- if (!browser.clearsContentEditableCorrectly()) {
- wysihtml5.quirks.ensureProperClearing(this);
- }
-
- // Set up a sync that makes sure that textarea and editor have the same content
- if (this.initSync && this.config.sync) {
- this.initSync();
- }
-
- // Okay hide the textarea, we are ready to go
- if (!this.config.noTextarea) { this.textarea.hide(); }
-
- // Fire global (before-)load event
- this.parent.fire("beforeload").fire("load");
- },
-
- _initAutoLinking: function() {
- var that = this,
- supportsDisablingOfAutoLinking = browser.canDisableAutoLinking(),
- supportsAutoLinking = browser.doesAutoLinkingInContentEditable();
-
- if (supportsDisablingOfAutoLinking) {
- this.commands.exec("AutoUrlDetect", false, false);
- }
-
- if (!this.config.autoLink) {
- return;
- }
-
- // Only do the auto linking by ourselves when the browser doesn't support auto linking
- // OR when he supports auto linking but we were able to turn it off (IE9+)
- if (!supportsAutoLinking || (supportsAutoLinking && supportsDisablingOfAutoLinking)) {
- this.parent.on("newword:composer", function() {
- if (dom.getTextContent(that.element).match(dom.autoLink.URL_REG_EXP)) {
- var nodeWithSelection = that.selection.getSelectedNode(),
- uneditables = that.element.querySelectorAll("." + that.config.classNames.uneditableContainer),
- isInUneditable = false;
-
- for (var i = uneditables.length; i--;) {
- if (wysihtml5.dom.contains(uneditables[i], nodeWithSelection)) {
- isInUneditable = true;
- }
- }
-
- if (!isInUneditable) dom.autoLink(nodeWithSelection, [that.config.classNames.uneditableContainer]);
- }
- });
-
- dom.observe(this.element, "blur", function() {
- dom.autoLink(that.element, [that.config.classNames.uneditableContainer]);
- });
- }
-
- // Assuming we have the following:
- // http://www.google.de
- // If a user now changes the url in the innerHTML we want to make sure that
- // it's synchronized with the href attribute (as long as the innerHTML is still a url)
- var // Use a live NodeList to check whether there are any links in the document
- links = this.sandbox.getDocument().getElementsByTagName("a"),
- // The autoLink helper method reveals a reg exp to detect correct urls
- urlRegExp = dom.autoLink.URL_REG_EXP,
- getTextContent = function(element) {
- var textContent = wysihtml5.lang.string(dom.getTextContent(element)).trim();
- if (textContent.substr(0, 4) === "www.") {
- textContent = "http://" + textContent;
- }
- return textContent;
- };
-
- dom.observe(this.element, "keydown", function(event) {
- if (!links.length) {
- return;
- }
-
- var selectedNode = that.selection.getSelectedNode(event.target.ownerDocument),
- link = dom.getParentElement(selectedNode, { query: "a" }, 4),
- textContent;
-
- if (!link) {
- return;
- }
-
- textContent = getTextContent(link);
- // keydown is fired before the actual content is changed
- // therefore we set a timeout to change the href
- setTimeout(function() {
- var newTextContent = getTextContent(link);
- if (newTextContent === textContent) {
- return;
- }
-
- // Only set href when new href looks like a valid url
- if (newTextContent.match(urlRegExp)) {
- link.setAttribute("href", newTextContent);
- }
- }, 0);
- });
- },
-
- _initObjectResizing: function() {
- this.commands.exec("enableObjectResizing", true);
-
- // IE sets inline styles after resizing objects
- // The following lines make sure that the width/height css properties
- // are copied over to the width/height attributes
- if (browser.supportsEvent("resizeend")) {
- var properties = ["width", "height"],
- propertiesLength = properties.length,
- element = this.element;
-
- dom.observe(element, "resizeend", function(event) {
- var target = event.target || event.srcElement,
- style = target.style,
- i = 0,
- property;
-
- if (target.nodeName !== "IMG") {
- return;
- }
-
- for (; i p:first-child { margin-top: 0; }",
- "._wysihtml5-temp { display: none; }",
- wysihtml5.browser.isGecko ?
- "body.placeholder { color: graytext !important; }" :
- "body.placeholder { color: #a9a9a9 !important; }",
- // Ensure that user see's broken images and can delete them
- "img:-moz-broken { -moz-force-broken-image-icon: 1; height: 24px; width: 24px; }"
- ];
-
- /**
- * With "setActive" IE offers a smart way of focusing elements without scrolling them into view:
- * http://msdn.microsoft.com/en-us/library/ms536738(v=vs.85).aspx
- *
- * Other browsers need a more hacky way: (pssst don't tell my mama)
- * In order to prevent the element being scrolled into view when focusing it, we simply
- * move it out of the scrollable area, focus it, and reset it's position
- */
- var focusWithoutScrolling = function(element) {
- if (element.setActive) {
- // Following line could cause a js error when the textarea is invisible
- // See https://github.com/xing/wysihtml5/issues/9
- try { element.setActive(); } catch(e) {}
- } else {
- var elementStyle = element.style,
- originalScrollTop = doc.documentElement.scrollTop || doc.body.scrollTop,
- originalScrollLeft = doc.documentElement.scrollLeft || doc.body.scrollLeft,
- originalStyles = {
- position: elementStyle.position,
- top: elementStyle.top,
- left: elementStyle.left,
- WebkitUserSelect: elementStyle.WebkitUserSelect
- };
-
- dom.setStyles({
- position: "absolute",
- top: "-99999px",
- left: "-99999px",
- // Don't ask why but temporarily setting -webkit-user-select to none makes the whole thing performing smoother
- WebkitUserSelect: "none"
- }).on(element);
-
- element.focus();
-
- dom.setStyles(originalStyles).on(element);
-
- if (win.scrollTo) {
- // Some browser extensions unset this method to prevent annoyances
- // "Better PopUp Blocker" for Chrome http://code.google.com/p/betterpopupblocker/source/browse/trunk/blockStart.js#100
- // Issue: http://code.google.com/p/betterpopupblocker/issues/detail?id=1
- win.scrollTo(originalScrollLeft, originalScrollTop);
- }
- }
- };
-
-
- wysihtml5.views.Composer.prototype.style = function() {
- var that = this,
- originalActiveElement = doc.querySelector(":focus"),
- textareaElement = this.textarea.element,
- hasPlaceholder = textareaElement.hasAttribute("placeholder"),
- originalPlaceholder = hasPlaceholder && textareaElement.getAttribute("placeholder"),
- originalDisplayValue = textareaElement.style.display,
- originalDisabled = textareaElement.disabled,
- displayValueForCopying;
-
- this.focusStylesHost = HOST_TEMPLATE.cloneNode(false);
- this.blurStylesHost = HOST_TEMPLATE.cloneNode(false);
- this.disabledStylesHost = HOST_TEMPLATE.cloneNode(false);
-
- // Remove placeholder before copying (as the placeholder has an affect on the computed style)
- if (hasPlaceholder) {
- textareaElement.removeAttribute("placeholder");
- }
-
- if (textareaElement === originalActiveElement) {
- textareaElement.blur();
- }
-
- // enable for copying styles
- textareaElement.disabled = false;
-
- // set textarea to display="none" to get cascaded styles via getComputedStyle
- textareaElement.style.display = displayValueForCopying = "none";
-
- if ((textareaElement.getAttribute("rows") && dom.getStyle("height").from(textareaElement) === "auto") ||
- (textareaElement.getAttribute("cols") && dom.getStyle("width").from(textareaElement) === "auto")) {
- textareaElement.style.display = displayValueForCopying = originalDisplayValue;
- }
-
- // --------- iframe styles (has to be set before editor styles, otherwise IE9 sets wrong fontFamily on blurStylesHost) ---------
- dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.editableArea).andTo(this.blurStylesHost);
-
- // --------- editor styles ---------
- dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.element).andTo(this.blurStylesHost);
-
- // --------- apply standard rules ---------
- dom.insertCSS(ADDITIONAL_CSS_RULES).into(this.element.ownerDocument);
-
- // --------- :disabled styles ---------
- textareaElement.disabled = true;
- dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.disabledStylesHost);
- dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.disabledStylesHost);
- textareaElement.disabled = originalDisabled;
-
- // --------- :focus styles ---------
- textareaElement.style.display = originalDisplayValue;
- focusWithoutScrolling(textareaElement);
- textareaElement.style.display = displayValueForCopying;
-
- dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.focusStylesHost);
- dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.focusStylesHost);
-
- // reset textarea
- textareaElement.style.display = originalDisplayValue;
-
- dom.copyStyles(["display"]).from(textareaElement).to(this.editableArea);
-
- // Make sure that we don't change the display style of the iframe when copying styles oblur/onfocus
- // this is needed for when the change_view event is fired where the iframe is hidden and then
- // the blur event fires and re-displays it
- var boxFormattingStyles = wysihtml5.lang.array(BOX_FORMATTING).without(["display"]);
-
- // --------- restore focus ---------
- if (originalActiveElement) {
- originalActiveElement.focus();
- } else {
- textareaElement.blur();
- }
-
- // --------- restore placeholder ---------
- if (hasPlaceholder) {
- textareaElement.setAttribute("placeholder", originalPlaceholder);
- }
-
- // --------- Sync focus/blur styles ---------
- this.parent.on("focus:composer", function() {
- dom.copyStyles(boxFormattingStyles) .from(that.focusStylesHost).to(that.editableArea);
- dom.copyStyles(TEXT_FORMATTING) .from(that.focusStylesHost).to(that.element);
- });
-
- this.parent.on("blur:composer", function() {
- dom.copyStyles(boxFormattingStyles) .from(that.blurStylesHost).to(that.editableArea);
- dom.copyStyles(TEXT_FORMATTING) .from(that.blurStylesHost).to(that.element);
- });
-
- this.parent.observe("disable:composer", function() {
- dom.copyStyles(boxFormattingStyles) .from(that.disabledStylesHost).to(that.editableArea);
- dom.copyStyles(TEXT_FORMATTING) .from(that.disabledStylesHost).to(that.element);
- });
-
- this.parent.observe("enable:composer", function() {
- dom.copyStyles(boxFormattingStyles) .from(that.blurStylesHost).to(that.editableArea);
- dom.copyStyles(TEXT_FORMATTING) .from(that.blurStylesHost).to(that.element);
- });
-
- return this;
- };
-})(wysihtml5);
-;/**
- * Taking care of events
- * - Simulating 'change' event on contentEditable element
- * - Handling drag & drop logic
- * - Catch paste events
- * - Dispatch proprietary newword:composer event
- * - Keyboard shortcuts
- */
-(function(wysihtml5) {
- var dom = wysihtml5.dom,
- domNode = dom.domNode,
- browser = wysihtml5.browser,
- /**
- * Map keyCodes to query commands
- */
- shortcuts = {
- "66": "bold", // B
- "73": "italic", // I
- "85": "underline" // U
- };
-
- var actions = {
-
- // Adds multiple eventlisteners to target, bound to one callback
- // TODO: If needed elsewhere make it part of wysihtml5.dom or sth
- addListeners: function (target, events, callback) {
- for(var i = 0, max = events.length; i < max; i++) {
- target.addEventListener(events[i], callback, false);
- }
- },
-
- // Removes multiple eventlisteners from target, bound to one callback
- // TODO: If needed elsewhere make it part of wysihtml5.dom or sth
- removeListeners: function (target, events, callback) {
- for(var i = 0, max = events.length; i < max; i++) {
- target.removeEventListener(events[i], callback, false);
- }
- },
-
- // Override for giving user ability to delete last line break in table cell
- fixLastBrDeletionInTable: function(composer, force) {
- if (composer.selection.caretIsLastInSelection()) {
- var sel = composer.selection.getSelection(),
- aNode = sel.anchorNode;
- if (aNode && aNode.nodeType === 1 && (wysihtml5.dom.getParentElement(aNode, {query: 'td, th'}, false, composer.element) || force)) {
- var nextNode = aNode.childNodes[sel.anchorOffset];
- if (nextNode && nextNode.nodeType === 1 & nextNode.nodeName === "BR") {
- nextNode.parentNode.removeChild(nextNode);
- return true;
- }
- }
- }
- return false;
- },
-
- // If found an uneditable before caret then notify it before deletion
- handleUneditableDeletion: function(composer) {
- var before = composer.selection.getBeforeSelection(true);
- if (before && (before.type === "element" || before.type === "leafnode") && before.node.nodeType === 1 && before.node.classList.contains(composer.config.classNames.uneditableContainer)) {
- if (actions.fixLastBrDeletionInTable(composer, true)) {
- return true;
- }
- try {
- var ev = new CustomEvent("wysihtml5:uneditable:delete", {bubbles: true, cancelable: false});
- before.node.dispatchEvent(ev);
- } catch (err) {}
- before.node.parentNode.removeChild(before.node);
- return true;
- }
- return false;
- },
-
- // Deletion with caret in the beginning of headings and other block elvel elements needs special attention
- // Not allways does it concate text to previous block node correctly (browsers do unexpected miracles here especially webkit)
- fixDeleteInTheBeginningOfBlock: function(composer) {
- var selection = composer.selection,
- prevNode = selection.getPreviousNode();
-
- if (selection.caretIsFirstInSelection(wysihtml5.browser.usesControlRanges()) && prevNode) {
- if (prevNode.nodeType === 1 &&
- wysihtml5.dom.domNode(prevNode).is.block() &&
- !domNode(prevNode).test({
- query: "ol, ul, table, tr, dl"
- })
- ) {
- if ((/^\s*$/).test(prevNode.textContent || prevNode.innerText)) {
- // If heading is empty remove the heading node
- prevNode.parentNode.removeChild(prevNode);
- return true;
- } else {
- if (prevNode.lastChild) {
- var selNode = prevNode.lastChild,
- selectedNode = selection.getSelectedNode(),
- commonAncestorNode = domNode(prevNode).commonAncestor(selectedNode, composer.element),
- curNode = wysihtml5.dom.getParentElement(selectedNode, {
- query: "h1, h2, h3, h4, h5, h6, p, pre, div, blockquote"
- }, false, commonAncestorNode || composer.element);
-
- if (curNode) {
- domNode(curNode).transferContentTo(prevNode, true);
- selection.setAfter(selNode);
- return true;
- } else if (wysihtml5.browser.usesControlRanges()) {
- selectedNode = selection.getCaretNode();
- domNode(selectedNode).transferContentTo(prevNode, true);
- selection.setAfter(selNode);
- return true;
- }
- }
- }
- }
- }
- return false;
- },
-
- /* In IE when deleting with caret at the begining of LI, list gets broken into half instead of merging the LI with previous */
- /* This does not match other browsers an is less intuitive from UI standpoint, thus has to be fixed */
- fixDeleteInTheBeginningOfLi: function(composer) {
- if (wysihtml5.browser.hasLiDeletingProblem()) {
- var selection = composer.selection.getSelection(),
- aNode = selection.anchorNode,
- listNode, prevNode, firstNode,
- isInBeginnig = composer.selection.caretIsFirstInSelection();
-
- // Fix caret at the beginnig of first textNode in LI
- if (aNode.nodeType === 3 && selection.anchorOffset === 0 && aNode === aNode.parentNode.firstChild) {
- aNode = aNode.parentNode;
- isInBeginnig = true;
- }
-
- if (isInBeginnig && aNode && aNode.nodeType === 1 && aNode.nodeName === "LI") {
- prevNode = domNode(aNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
- if (!prevNode && aNode.parentNode && (aNode.parentNode.nodeName === "UL" || aNode.parentNode.nodeName === "OL")) {
- prevNode = domNode(aNode.parentNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
- }
- if (prevNode) {
- firstNode = aNode.firstChild;
- domNode(aNode).transferContentTo(prevNode, true);
- if (firstNode) {
- composer.selection.setBefore(firstNode);
- } else if (prevNode) {
- if (prevNode.nodeType === 1) {
- if (prevNode.lastChild) {
- composer.selection.setAfter(prevNode.lastChild);
- } else {
- composer.selection.selectNode(prevNode);
- }
- } else {
- composer.selection.setAfter(prevNode);
- }
- }
- return true;
- }
- }
- }
- return false;
- },
-
- fixDeleteInTheBeginningOfControlSelection: function(composer) {
- var selection = composer.selection,
- prevNode = selection.getPreviousNode(),
- selectedNode = selection.getSelectedNode(),
- afterCaretNode;
-
- if (selection.caretIsFirstInSelection()) {
- if (selectedNode.nodeType === 3) {
- selectedNode = selectedNode.parentNode;
- }
- afterCaretNode = selectedNode.firstChild;
- domNode(selectedNode).transferContentTo(prevNode, true);
- if (afterCaretNode) {
- composer.selection.setBefore(afterCaretNode);
- }
- return true;
- }
- return false;
- },
-
- // Table management
- // If present enableObjectResizing and enableInlineTableEditing command should be called with false to prevent native table handlers
- initTableHandling: function() {
- var hideHandlers = function() {
- window.removeEventListener('load', hideHandlers);
- this.doc.execCommand("enableObjectResizing", false, "false");
- this.doc.execCommand("enableInlineTableEditing", false, "false");
- }.bind(this),
- iframeInitiator = (function() {
- hideHandlers.call(this);
- actions.removeListeners(this.sandbox.getIframe(), ["focus", "mouseup", "mouseover"], iframeInitiator);
- }).bind(this);
-
- if( this.doc.execCommand &&
- wysihtml5.browser.supportsCommand(this.doc, "enableObjectResizing") &&
- wysihtml5.browser.supportsCommand(this.doc, "enableInlineTableEditing"))
- {
- if (this.sandbox.getIframe) {
- actions.addListeners(this.sandbox.getIframe(), ["focus", "mouseup", "mouseover"], iframeInitiator);
- } else {
- window.addEventListener('load', hideHandlers);
- }
- }
- this.tableSelection = wysihtml5.quirks.tableCellsSelection(this.element, this.parent);
- },
-
- // Fixes some misbehaviours of enters in linebreaks mode (natively a bit unsupported feature)
- // Returns true if some corrections is applied so events know when to prevent default
- doLineBreaksModeEnterWithCaret: function(composer) {
- var breakNodes = "p, pre, div, blockquote",
- caretInfo, parent, txtNode,
- ret = false;
-
- caretInfo = composer.selection.getNodesNearCaret();
- if (caretInfo) {
-
- if (caretInfo.caretNode || caretInfo.nextNode) {
- parent = dom.getParentElement(caretInfo.caretNode || caretInfo.nextNode, { query: breakNodes }, 2);
- if (parent === composer.element) {
- parent = undefined;
- }
- }
-
- if (parent && caretInfo.caretNode) {
- if (domNode(caretInfo.caretNode).is.lineBreak()) {
-
- if (composer.config.doubleLineBreakEscapesBlock) {
- // Double enter (enter on blank line) exits block element in useLineBreaks mode.
- ret = true;
- caretInfo.caretNode.parentNode.removeChild(caretInfo.caretNode);
-
- // Ensure surplous line breaks are not added to preceding element
- if (domNode(caretInfo.nextNode).is.lineBreak()) {
- caretInfo.nextNode.parentNode.removeChild(caretInfo.nextNode);
- }
-
- var brNode = composer.doc.createElement('br');
- if (domNode(caretInfo.nextNode).is.lineBreak() && caretInfo.nextNode === parent.lastChild) {
- parent.parentNode.insertBefore(brNode, parent.nextSibling);
- } else {
- composer.selection.splitElementAtCaret(parent, brNode);
- }
-
- // Ensure surplous blank lines are not added to preceding element
- if (caretInfo.nextNode && caretInfo.nextNode.nodeType === 3) {
- // Replaces blank lines at the beginning of textnode
- caretInfo.nextNode.data = caretInfo.nextNode.data.replace(/^ *[\r\n]+/, '');
- }
- composer.selection.setBefore(brNode);
- }
-
- } else if (caretInfo.caretNode.nodeType === 3 && wysihtml5.browser.hasCaretBlockElementIssue() && caretInfo.textOffset === caretInfo.caretNode.data.length && !caretInfo.nextNode) {
-
- // This fixes annoying webkit issue when you press enter at the end of a block then seemingly nothing happens.
- // in reality one line break is generated and cursor is reported after it, but when entering something cursor jumps before the br
- ret = true;
- var br1 = composer.doc.createElement('br'),
- br2 = composer.doc.createElement('br'),
- f = composer.doc.createDocumentFragment();
- f.appendChild(br1);
- f.appendChild(br2);
- composer.selection.insertNode(f);
- composer.selection.setBefore(br2);
-
- }
- }
- }
- return ret;
- }
- };
-
- var handleDeleteKeyPress = function(event, composer) {
- var selection = composer.selection,
- element = composer.element;
-
- if (selection.isCollapsed()) {
- if (actions.handleUneditableDeletion(composer)) {
- event.preventDefault();
- return;
- }
- if (actions.fixDeleteInTheBeginningOfLi(composer)) {
- event.preventDefault();
- return;
- }
- if (actions.fixDeleteInTheBeginningOfBlock(composer)) {
- event.preventDefault();
- return;
- }
- if (actions.fixLastBrDeletionInTable(composer)) {
- event.preventDefault();
- return;
- }
- if (wysihtml5.browser.usesControlRanges()) {
- if (actions.fixDeleteInTheBeginningOfControlSelection(composer)) {
- event.preventDefault();
- return;
- }
- }
- } else {
- if (selection.containsUneditable()) {
- event.preventDefault();
- selection.deleteContents();
- }
- }
- };
-
- var handleEnterKeyPress = function(event, composer) {
- if (composer.config.useLineBreaks && !event.shiftKey && !event.ctrlKey) {
- // Fixes some misbehaviours of enters in linebreaks mode (natively a bit unsupported feature)
-
- var breakNodes = "p, pre, div, blockquote",
- caretInfo, parent, txtNode;
-
- if (composer.selection.isCollapsed()) {
- if (actions.doLineBreaksModeEnterWithCaret(composer)) {
- event.preventDefault();
- }
- }
- }
- };
-
- var handleTabKeyDown = function(composer, element, shiftKey) {
- if (!composer.selection.isCollapsed()) {
- composer.selection.deleteContents();
- } else if (composer.selection.caretIsInTheBeginnig('li')) {
- if (shiftKey) {
- if (composer.commands.exec('outdentList')) return;
- } else {
- if (composer.commands.exec('indentList')) return;
- }
- }
-
- // Is close enough to tab. Could not find enough counter arguments for now.
- composer.commands.exec("insertHTML", " ");
- };
-
- var handleDomNodeRemoved = function(event) {
- if (this.domNodeRemovedInterval) {
- clearInterval(domNodeRemovedInterval);
- }
- this.parent.fire("destroy:composer");
- };
-
- // Listens to "drop", "paste", "mouseup", "focus", "keyup" events and fires
- var handleUserInteraction = function (event) {
- this.parent.fire("beforeinteraction", event).fire("beforeinteraction:composer", event);
- setTimeout((function() {
- this.parent.fire("interaction", event).fire("interaction:composer", event);
- }).bind(this), 0);
- };
-
- var handleFocus = function(event) {
- this.parent.fire("focus", event).fire("focus:composer", event);
-
- // Delay storing of state until all focus handler are fired
- // especially the one which resets the placeholder
- setTimeout((function() {
- this.focusState = this.getValue(false, false);
- }).bind(this), 0);
- };
-
- var handleBlur = function(event) {
- if (this.focusState !== this.getValue(false, false)) {
- //create change event if supported (all except IE8)
- var changeevent = event;
- if(typeof Object.create == 'function') {
- changeevent = Object.create(event, { type: { value: 'change' } });
- }
- this.parent.fire("change", changeevent).fire("change:composer", changeevent);
- }
- this.parent.fire("blur", event).fire("blur:composer", event);
- };
-
- var handlePaste = function(event) {
- this.parent.fire(event.type, event).fire(event.type + ":composer", event);
- if (event.type === "paste") {
- setTimeout((function() {
- this.parent.fire("newword:composer");
- }).bind(this), 0);
- }
- };
-
- var handleCopy = function(event) {
- if (this.config.copyedFromMarking) {
- // If supported the copied source can be based directly on selection
- // Very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection.
- if (wysihtml5.browser.supportsModernPaste()) {
- event.clipboardData.setData("text/html", this.config.copyedFromMarking + this.selection.getHtml());
- event.clipboardData.setData("text/plain", this.selection.getPlainText());
- event.preventDefault();
- }
- this.parent.fire(event.type, event).fire(event.type + ":composer", event);
- }
- };
-
- var handleKeyUp = function(event) {
- var keyCode = event.keyCode;
- if (keyCode === wysihtml5.SPACE_KEY || keyCode === wysihtml5.ENTER_KEY) {
- this.parent.fire("newword:composer");
- }
- };
-
- var handleMouseDown = function(event) {
- if (!browser.canSelectImagesInContentEditable()) {
- // Make sure that images are selected when clicking on them
- var target = event.target,
- allImages = this.element.querySelectorAll('img'),
- notMyImages = this.element.querySelectorAll('.' + this.config.classNames.uneditableContainer + ' img'),
- myImages = wysihtml5.lang.array(allImages).without(notMyImages);
-
- if (target.nodeName === "IMG" && wysihtml5.lang.array(myImages).contains(target)) {
- this.selection.selectNode(target);
- }
- }
-
- // Saves mousedown position for IE controlSelect fix
- if (wysihtml5.browser.usesControlRanges()) {
- this.selection.lastMouseDownPos = {x: event.clientX, y: event.clientY};
- setTimeout(function() {
- delete this.selection.lastMouseDownPos;
- }.bind(this), 0);
- }
- };
-
- // IE has this madness of control selects of overflowed and some other elements (weird box around element on selection and second click selects text)
- // This fix handles the second click problem by adding cursor to the right position under cursor inside when controlSelection is made
- var handleIEControlSelect = function(event) {
- var target = event.target,
- pos = this.selection.lastMouseDownPos;
- if (pos) {
- var caretPosition = document.body.createTextRange();
- setTimeout(function() {
- try {
- caretPosition.moveToPoint(pos.x, pos.y);
- caretPosition.select();
- } catch (e) {}
- }.bind(this), 0);
- }
- };
-
- var handleClick = function(event) {
- if (this.config.classNames.uneditableContainer) {
- // If uneditables is configured, makes clicking on uneditable move caret after clicked element (so it can be deleted like text)
- // If uneditable needs text selection itself event.stopPropagation can be used to prevent this behaviour
- var uneditable = wysihtml5.dom.getParentElement(event.target, { query: "." + this.config.classNames.uneditableContainer }, false, this.element);
- if (uneditable) {
- this.selection.setAfter(uneditable);
- }
- }
- };
-
- var handleDrop = function(event) {
- if (!browser.canSelectImagesInContentEditable()) {
- // TODO: if I knew how to get dropped elements list from event I could limit it to only IMG element case
- setTimeout((function() {
- this.selection.getSelection().removeAllRanges();
- }).bind(this), 0);
- }
- };
-
- var handleKeyDown = function(event) {
- var keyCode = event.keyCode,
- command = shortcuts[keyCode],
- target, parent;
-
- // Select all (meta/ctrl + a)
- if ((event.ctrlKey || event.metaKey) && !event.altKey && keyCode === 65) {
- this.selection.selectAll();
- event.preventDefault();
- return;
- }
-
- // Shortcut logic
- if ((event.ctrlKey || event.metaKey) && !event.altKey && command) {
- this.commands.exec(command);
- event.preventDefault();
- }
-
- if (keyCode === wysihtml5.BACKSPACE_KEY) {
- // Delete key override for special cases
- handleDeleteKeyPress(event, this);
- }
-
- // Make sure that when pressing backspace/delete on selected images deletes the image and it's anchor
- if (keyCode === wysihtml5.BACKSPACE_KEY || keyCode === wysihtml5.DELETE_KEY) {
- target = this.selection.getSelectedNode(true);
- if (target && target.nodeName === "IMG") {
- event.preventDefault();
- parent = target.parentNode;
- parent.removeChild(target);// delete the
- // And it's parent too if it hasn't got any other child nodes
- if (parent.nodeName === "A" && !parent.firstChild) {
- parent.parentNode.removeChild(parent);
- }
- setTimeout((function() {
- wysihtml5.quirks.redraw(this.element);
- }).bind(this), 0);
- }
- }
-
- if (this.config.handleTabKey && keyCode === wysihtml5.TAB_KEY) {
- // TAB key handling
- event.preventDefault();
- handleTabKeyDown(this, this.element, event.shiftKey);
- }
-
- if (keyCode === wysihtml5.ENTER_KEY) {
- handleEnterKeyPress(event, this);
- }
-
- };
-
- var handleIframeFocus = function(event) {
- setTimeout((function() {
- if (this.doc.querySelector(":focus") !== this.element) {
- this.focus();
- }
- }).bind(this), 0);
- };
-
- var handleIframeBlur = function(event) {
- setTimeout((function() {
- this.selection.getSelection().removeAllRanges();
- }).bind(this), 0);
- };
-
- // Testing requires actions to be accessible from out of scope
- wysihtml5.views.Composer.prototype.observeActions = actions;
-
- wysihtml5.views.Composer.prototype.observe = function() {
- var that = this,
- container = (this.sandbox.getIframe) ? this.sandbox.getIframe() : this.sandbox.getContentEditable(),
- element = this.element,
- focusBlurElement = (browser.supportsEventsInIframeCorrectly() || this.sandbox.getContentEditable) ? this.element : this.sandbox.getWindow();
-
- this.focusState = this.getValue(false, false);
-
- // --------- destroy:composer event ---------
- container.addEventListener(["DOMNodeRemoved"], handleDomNodeRemoved.bind(this), false);
-
- // DOMNodeRemoved event is not supported in IE 8
- // TODO: try to figure out a polyfill style fix, so it could be transferred to polyfills and removed if ie8 is not needed
- if (!browser.supportsMutationEvents()) {
- this.domNodeRemovedInterval = setInterval(function() {
- if (!dom.contains(document.documentElement, container)) {
- handleDomNodeRemoved.call(this);
- }
- }, 250);
- }
-
- // --------- User interactions --
- if (this.config.handleTables) {
- // If handleTables option is true, table handling functions are bound
- actions.initTableHandling.call(this);
- }
-
- actions.addListeners(focusBlurElement, ["drop", "paste", "mouseup", "focus", "keyup"], handleUserInteraction.bind(this));
- focusBlurElement.addEventListener("focus", handleFocus.bind(this), false);
- focusBlurElement.addEventListener("blur", handleBlur.bind(this), false);
-
- actions.addListeners(this.element, ["drop", "paste", "beforepaste"], handlePaste.bind(this), false);
- this.element.addEventListener("copy", handleCopy.bind(this), false);
- this.element.addEventListener("mousedown", handleMouseDown.bind(this), false);
- this.element.addEventListener("click", handleClick.bind(this), false);
- this.element.addEventListener("drop", handleDrop.bind(this), false);
- this.element.addEventListener("keyup", handleKeyUp.bind(this), false);
- this.element.addEventListener("keydown", handleKeyDown.bind(this), false);
-
- // IE controlselect madness fix
- if (wysihtml5.browser.usesControlRanges()) {
- this.element.addEventListener('mscontrolselect', handleIEControlSelect.bind(this), false);
- }
-
- this.element.addEventListener("dragenter", (function() {
- this.parent.fire("unset_placeholder");
- }).bind(this), false);
-
- };
-})(wysihtml5);
-;/**
- * Class that takes care that the value of the composer and the textarea is always in sync
- */
-(function(wysihtml5) {
- var INTERVAL = 400;
-
- wysihtml5.views.Synchronizer = Base.extend(
- /** @scope wysihtml5.views.Synchronizer.prototype */ {
-
- constructor: function(editor, textarea, composer) {
- this.editor = editor;
- this.textarea = textarea;
- this.composer = composer;
-
- this._observe();
- },
-
- /**
- * Sync html from composer to textarea
- * Takes care of placeholders
- * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the textarea
- */
- fromComposerToTextarea: function(shouldParseHtml) {
- this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue(false, false)).trim(), shouldParseHtml);
- },
-
- /**
- * Sync value of textarea to composer
- * Takes care of placeholders
- * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer
- */
- fromTextareaToComposer: function(shouldParseHtml) {
- var textareaValue = this.textarea.getValue(false, false);
- if (textareaValue) {
- this.composer.setValue(textareaValue, shouldParseHtml);
- } else {
- this.composer.clear();
- this.editor.fire("set_placeholder");
- }
- },
-
- /**
- * Invoke syncing based on view state
- * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer/textarea
- */
- sync: function(shouldParseHtml) {
- if (this.editor.currentView.name === "textarea") {
- this.fromTextareaToComposer(shouldParseHtml);
- } else {
- this.fromComposerToTextarea(shouldParseHtml);
- }
- },
-
- /**
- * Initializes interval-based syncing
- * also makes sure that on-submit the composer's content is synced with the textarea
- * immediately when the form gets submitted
- */
- _observe: function() {
- var interval,
- that = this,
- form = this.textarea.element.form,
- startInterval = function() {
- interval = setInterval(function() { that.fromComposerToTextarea(); }, INTERVAL);
- },
- stopInterval = function() {
- clearInterval(interval);
- interval = null;
- };
-
- startInterval();
-
- if (form) {
- // If the textarea is in a form make sure that after onreset and onsubmit the composer
- // has the correct state
- wysihtml5.dom.observe(form, "submit", function() {
- that.sync(true);
- });
- wysihtml5.dom.observe(form, "reset", function() {
- setTimeout(function() { that.fromTextareaToComposer(); }, 0);
- });
- }
-
- this.editor.on("change_view", function(view) {
- if (view === "composer" && !interval) {
- that.fromTextareaToComposer(true);
- startInterval();
- } else if (view === "textarea") {
- that.fromComposerToTextarea(true);
- stopInterval();
- }
- });
-
- this.editor.on("destroy:composer", stopInterval);
- }
- });
-})(wysihtml5);
-;(function(wysihtml5) {
-
- wysihtml5.views.SourceView = Base.extend(
- /** @scope wysihtml5.views.SourceView.prototype */ {
-
- constructor: function(editor, composer) {
- this.editor = editor;
- this.composer = composer;
-
- this._observe();
- },
-
- switchToTextarea: function(shouldParseHtml) {
- var composerStyles = this.composer.win.getComputedStyle(this.composer.element),
- width = parseFloat(composerStyles.width),
- height = Math.max(parseFloat(composerStyles.height), 100);
-
- if (!this.textarea) {
- this.textarea = this.composer.doc.createElement('textarea');
- this.textarea.className = "wysihtml5-source-view";
- }
- this.textarea.style.width = width + 'px';
- this.textarea.style.height = height + 'px';
- this.textarea.value = this.editor.getValue(shouldParseHtml, true);
- this.composer.element.parentNode.insertBefore(this.textarea, this.composer.element);
- this.editor.currentView = "source";
- this.composer.element.style.display = 'none';
- },
-
- switchToComposer: function(shouldParseHtml) {
- var textareaValue = this.textarea.value;
- if (textareaValue) {
- this.composer.setValue(textareaValue, shouldParseHtml);
- } else {
- this.composer.clear();
- this.editor.fire("set_placeholder");
- }
- this.textarea.parentNode.removeChild(this.textarea);
- this.editor.currentView = this.composer;
- this.composer.element.style.display = '';
- },
-
- _observe: function() {
- this.editor.on("change_view", function(view) {
- if (view === "composer") {
- this.switchToComposer(true);
- } else if (view === "textarea") {
- this.switchToTextarea(true);
- }
- }.bind(this));
- }
-
- });
-
-})(wysihtml5);
-;wysihtml5.views.Textarea = wysihtml5.views.View.extend(
- /** @scope wysihtml5.views.Textarea.prototype */ {
- name: "textarea",
-
- constructor: function(parent, textareaElement, config) {
- this.base(parent, textareaElement, config);
-
- this._observe();
- },
-
- clear: function() {
- this.element.value = "";
- },
-
- getValue: function(parse) {
- var value = this.isEmpty() ? "" : this.element.value;
- if (parse !== false) {
- value = this.parent.parse(value);
- }
- return value;
- },
-
- setValue: function(html, parse) {
- if (parse !== false) {
- html = this.parent.parse(html);
- }
- this.element.value = html;
- },
-
- cleanUp: function(rules) {
- var html = this.parent.parse(this.element.value, undefined, rules);
- this.element.value = html;
- },
-
- hasPlaceholderSet: function() {
- var supportsPlaceholder = wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),
- placeholderText = this.element.getAttribute("placeholder") || null,
- value = this.element.value,
- isEmpty = !value;
- return (supportsPlaceholder && isEmpty) || (value === placeholderText);
- },
-
- isEmpty: function() {
- return !wysihtml5.lang.string(this.element.value).trim() || this.hasPlaceholderSet();
- },
-
- _observe: function() {
- var element = this.element,
- parent = this.parent,
- eventMapping = {
- focusin: "focus",
- focusout: "blur"
- },
- /**
- * Calling focus() or blur() on an element doesn't synchronously trigger the attached focus/blur events
- * This is the case for focusin and focusout, so let's use them whenever possible, kkthxbai
- */
- events = wysihtml5.browser.supportsEvent("focusin") ? ["focusin", "focusout", "change"] : ["focus", "blur", "change"];
-
- parent.on("beforeload", function() {
- wysihtml5.dom.observe(element, events, function(event) {
- var eventName = eventMapping[event.type] || event.type;
- parent.fire(eventName).fire(eventName + ":textarea");
- });
-
- wysihtml5.dom.observe(element, ["paste", "drop"], function() {
- setTimeout(function() { parent.fire("paste").fire("paste:textarea"); }, 0);
- });
- });
- }
-});
-;/**
- * WYSIHTML5 Editor
- *
- * @param {Element} editableElement Reference to the textarea which should be turned into a rich text interface
- * @param {Object} [config] See defaultConfig object below for explanation of each individual config option
- *
- * @events
- * load
- * beforeload (for internal use only)
- * focus
- * focus:composer
- * focus:textarea
- * blur
- * blur:composer
- * blur:textarea
- * change
- * change:composer
- * change:textarea
- * paste
- * paste:composer
- * paste:textarea
- * newword:composer
- * destroy:composer
- * undo:composer
- * redo:composer
- * beforecommand:composer
- * aftercommand:composer
- * enable:composer
- * disable:composer
- * change_view
- */
-(function(wysihtml5) {
- var undef;
-
- var defaultConfig = {
- // Give the editor a name, the name will also be set as class name on the iframe and on the iframe's body
- name: undef,
- // Whether the editor should look like the textarea (by adopting styles)
- style: true,
- // Id of the toolbar element, pass falsey value if you don't want any toolbar logic
- toolbar: undef,
- // Whether toolbar is displayed after init by script automatically.
- // Can be set to false if toolobar is set to display only on editable area focus
- showToolbarAfterInit: true,
- // With default toolbar it shows dialogs in toolbar when their related text format state becomes active (click on link in text opens link dialogue)
- showToolbarDialogsOnSelection: true,
- // Whether urls, entered by the user should automatically become clickable-links
- autoLink: true,
- // Includes table editing events and cell selection tracking
- handleTables: true,
- // Tab key inserts tab into text as default behaviour. It can be disabled to regain keyboard navigation
- handleTabKey: true,
- // Object which includes parser rules to apply when html gets cleaned
- // See parser_rules/*.js for examples
- parserRules: { tags: { br: {}, span: {}, div: {}, p: {}, b: {}, i: {}, u: {} }, classes: {} },
- // Object which includes parser when the user inserts content via copy & paste. If null parserRules will be used instead
- pasteParserRulesets: null,
- // Parser method to use when the user inserts content
- parser: wysihtml5.dom.parse,
- // By default wysihtml5 will insert a for line breaks, set this to false to use
- useLineBreaks: true,
- // Double enter (enter on blank line) exits block element in useLineBreaks mode.
- // It enables a way of escaping out of block elements and splitting block elements
- doubleLineBreakEscapesBlock: true,
- // Array (or single string) of stylesheet urls to be loaded in the editor's iframe
- stylesheets: [],
- // Placeholder text to use, defaults to the placeholder attribute on the textarea element
- placeholderText: undef,
- // Whether the rich text editor should be rendered on touch devices (wysihtml5 >= 0.3.0 comes with basic support for iOS 5)
- supportTouchDevices: true,
- // Whether senseless elements (empty or without attributes) should be removed/replaced with their content
- cleanUp: true,
- // Whether to use div instead of secure iframe
- contentEditableMode: false,
- classNames: {
- // Class name which should be set on the contentEditable element in the created sandbox iframe, can be styled via the 'stylesheets' option
- composer: "wysihtml5-editor",
- // Class name to add to the body when the wysihtml5 editor is supported
- body: "wysihtml5-supported",
- // classname added to editable area element (iframe/div) on creation
- sandbox: "wysihtml5-sandbox",
- // class on editable area with placeholder
- placeholder: "wysihtml5-placeholder",
- // Classname of container that editor should not touch and pass through
- uneditableContainer: "wysihtml5-uneditable-container"
- },
- // Browsers that support copied source handling will get a marking of the origin of the copied source (for determinig code cleanup rules on paste)
- // Also copied source is based directly on selection -
- // (very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection).
- // If falsy value is passed source override is also disabled
- copyedFromMarking: ' '
- };
-
- wysihtml5.Editor = wysihtml5.lang.Dispatcher.extend(
- /** @scope wysihtml5.Editor.prototype */ {
- constructor: function(editableElement, config) {
- this.editableElement = typeof(editableElement) === "string" ? document.getElementById(editableElement) : editableElement;
- this.config = wysihtml5.lang.object({}).merge(defaultConfig).merge(config).get();
- this._isCompatible = wysihtml5.browser.supported();
-
- // merge classNames
- if (config && config.classNames) {
- wysihtml5.lang.object(this.config.classNames).merge(config.classNames);
- }
-
- if (this.editableElement.nodeName.toLowerCase() != "textarea") {
- this.config.contentEditableMode = true;
- this.config.noTextarea = true;
- }
- if (!this.config.noTextarea) {
- this.textarea = new wysihtml5.views.Textarea(this, this.editableElement, this.config);
- this.currentView = this.textarea;
- }
-
- // Sort out unsupported/unwanted browsers here
- if (!this._isCompatible || (!this.config.supportTouchDevices && wysihtml5.browser.isTouchDevice())) {
- var that = this;
- setTimeout(function() { that.fire("beforeload").fire("load"); }, 0);
- return;
- }
-
- // Add class name to body, to indicate that the editor is supported
- wysihtml5.dom.addClass(document.body, this.config.classNames.body);
-
- this.composer = new wysihtml5.views.Composer(this, this.editableElement, this.config);
- this.currentView = this.composer;
-
- if (typeof(this.config.parser) === "function") {
- this._initParser();
- }
-
- this.on("beforeload", this.handleBeforeLoad);
- },
-
- handleBeforeLoad: function() {
- if (!this.config.noTextarea) {
- this.synchronizer = new wysihtml5.views.Synchronizer(this, this.textarea, this.composer);
- } else {
- this.sourceView = new wysihtml5.views.SourceView(this, this.composer);
- }
- if (this.config.toolbar) {
- this.toolbar = new wysihtml5.toolbar.Toolbar(this, this.config.toolbar, this.config.showToolbarAfterInit);
- }
- },
-
- isCompatible: function() {
- return this._isCompatible;
- },
-
- clear: function() {
- this.currentView.clear();
- return this;
- },
-
- getValue: function(parse, clearInternals) {
- return this.currentView.getValue(parse, clearInternals);
- },
-
- setValue: function(html, parse) {
- this.fire("unset_placeholder");
-
- if (!html) {
- return this.clear();
- }
-
- this.currentView.setValue(html, parse);
- return this;
- },
-
- cleanUp: function(rules) {
- this.currentView.cleanUp(rules);
- },
-
- focus: function(setToEnd) {
- this.currentView.focus(setToEnd);
- return this;
- },
-
- /**
- * Deactivate editor (make it readonly)
- */
- disable: function() {
- this.currentView.disable();
- return this;
- },
-
- /**
- * Activate editor
- */
- enable: function() {
- this.currentView.enable();
- return this;
- },
-
- isEmpty: function() {
- return this.currentView.isEmpty();
- },
-
- hasPlaceholderSet: function() {
- return this.currentView.hasPlaceholderSet();
- },
-
- destroy: function() {
- if (this.composer && this.composer.sandbox) {
- this.composer.sandbox.destroy();
- }
- if (this.toolbar) {
- this.toolbar.destroy();
- }
- this.off();
- },
-
- parse: function(htmlOrElement, clearInternals, customRules) {
- var parseContext = (this.config.contentEditableMode) ? document : ((this.composer) ? this.composer.sandbox.getDocument() : null);
- var returnValue = this.config.parser(htmlOrElement, {
- "rules": customRules || this.config.parserRules,
- "cleanUp": this.config.cleanUp,
- "context": parseContext,
- "uneditableClass": this.config.classNames.uneditableContainer,
- "clearInternals" : clearInternals
- });
- if (typeof(htmlOrElement) === "object") {
- wysihtml5.quirks.redraw(htmlOrElement);
- }
- return returnValue;
- },
-
- /**
- * Prepare html parser logic
- * - Observes for paste and drop
- */
- _initParser: function() {
- var oldHtml;
-
- if (wysihtml5.browser.supportsModernPaste()) {
- this.on("paste:composer", function(event) {
- event.preventDefault();
- oldHtml = wysihtml5.dom.getPastedHtml(event);
- if (oldHtml) {
- this._cleanAndPaste(oldHtml);
- }
- }.bind(this));
-
- } else {
- this.on("beforepaste:composer", function(event) {
- event.preventDefault();
- var scrollPos = this.composer.getScrollPos();
-
- wysihtml5.dom.getPastedHtmlWithDiv(this.composer, function(pastedHTML) {
- if (pastedHTML) {
- this._cleanAndPaste(pastedHTML);
- }
- this.composer.setScrollPos(scrollPos);
- }.bind(this));
-
- }.bind(this));
- }
- },
-
- _cleanAndPaste: function (oldHtml) {
- var cleanHtml = wysihtml5.quirks.cleanPastedHTML(oldHtml, {
- "referenceNode": this.composer.element,
- "rules": this.config.pasteParserRulesets || [{"set": this.config.parserRules}],
- "uneditableClass": this.config.classNames.uneditableContainer
- });
- this.composer.selection.deleteContents();
- this.composer.selection.insertHTML(cleanHtml);
- }
- });
-})(wysihtml5);
-;/**
- * Toolbar Dialog
- *
- * @param {Element} link The toolbar link which causes the dialog to show up
- * @param {Element} container The dialog container
- *
- * @example
- *
- * insert an image
- *
- *
- *
- *
- * URL:
- *
- *
- * Alternative text:
- *
- *
- *
- *
- */
-(function(wysihtml5) {
- var dom = wysihtml5.dom,
- CLASS_NAME_OPENED = "wysihtml5-command-dialog-opened",
- SELECTOR_FORM_ELEMENTS = "input, select, textarea",
- SELECTOR_FIELDS = "[data-wysihtml5-dialog-field]",
- ATTRIBUTE_FIELDS = "data-wysihtml5-dialog-field";
-
-
- wysihtml5.toolbar.Dialog = wysihtml5.lang.Dispatcher.extend(
- /** @scope wysihtml5.toolbar.Dialog.prototype */ {
- constructor: function(link, container) {
- this.link = link;
- this.container = container;
- },
-
- _observe: function() {
- if (this._observed) {
- return;
- }
-
- var that = this,
- callbackWrapper = function(event) {
- var attributes = that._serialize();
- that.fire("save", attributes);
- that.hide();
- event.preventDefault();
- event.stopPropagation();
- };
-
- dom.observe(that.link, "click", function() {
- if (dom.hasClass(that.link, CLASS_NAME_OPENED)) {
- setTimeout(function() { that.hide(); }, 0);
- }
- });
-
- dom.observe(this.container, "keydown", function(event) {
- var keyCode = event.keyCode;
- if (keyCode === wysihtml5.ENTER_KEY) {
- callbackWrapper(event);
- }
- if (keyCode === wysihtml5.ESCAPE_KEY) {
- that.cancel();
- }
- });
-
- dom.delegate(this.container, "[data-wysihtml5-dialog-action=save]", "click", callbackWrapper);
-
- dom.delegate(this.container, "[data-wysihtml5-dialog-action=cancel]", "click", function(event) {
- that.cancel();
- event.preventDefault();
- event.stopPropagation();
- });
-
- this._observed = true;
- },
-
- /**
- * Grabs all fields in the dialog and puts them in key=>value style in an object which
- * then gets returned
- */
- _serialize: function() {
- var data = {},
- fields = this.container.querySelectorAll(SELECTOR_FIELDS),
- length = fields.length,
- i = 0;
-
- for (; ifoo
- *
- * and we have the following dialog:
- *
- *
- *
- * after calling _interpolate() the dialog will look like this
- *
- *
- *
- * Basically it adopted the attribute values into the corresponding input fields
- *
- */
- _interpolate: function(avoidHiddenFields) {
- var field,
- fieldName,
- newValue,
- focusedElement = document.querySelector(":focus"),
- fields = this.container.querySelectorAll(SELECTOR_FIELDS),
- length = fields.length,
- i = 0;
- for (; i= 11
- *
- * Note that it sends the recorded audio to the google speech recognition api:
- * http://stackoverflow.com/questions/4361826/does-chrome-have-buil-in-speech-recognition-for-input-type-text-x-webkit-speec
- *
- * Current HTML5 draft can be found here
- * http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html
- *
- * "Accessing Google Speech API Chrome 11"
- * http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
- */
-(function(wysihtml5) {
- var dom = wysihtml5.dom;
-
- var linkStyles = {
- position: "relative"
- };
-
- var wrapperStyles = {
- left: 0,
- margin: 0,
- opacity: 0,
- overflow: "hidden",
- padding: 0,
- position: "absolute",
- top: 0,
- zIndex: 1
- };
-
- var inputStyles = {
- cursor: "inherit",
- fontSize: "50px",
- height: "50px",
- marginTop: "-25px",
- outline: 0,
- padding: 0,
- position: "absolute",
- right: "-4px",
- top: "50%"
- };
-
- var inputAttributes = {
- "x-webkit-speech": "",
- "speech": ""
- };
-
- wysihtml5.toolbar.Speech = function(parent, link) {
- var input = document.createElement("input");
- if (!wysihtml5.browser.supportsSpeechApiOn(input)) {
- link.style.display = "none";
- return;
- }
- var lang = parent.editor.textarea.element.getAttribute("lang");
- if (lang) {
- inputAttributes.lang = lang;
- }
-
- var wrapper = document.createElement("div");
-
- wysihtml5.lang.object(wrapperStyles).merge({
- width: link.offsetWidth + "px",
- height: link.offsetHeight + "px"
- });
-
- dom.insert(input).into(wrapper);
- dom.insert(wrapper).into(link);
-
- dom.setStyles(inputStyles).on(input);
- dom.setAttributes(inputAttributes).on(input);
-
- dom.setStyles(wrapperStyles).on(wrapper);
- dom.setStyles(linkStyles).on(link);
-
- var eventName = "onwebkitspeechchange" in input ? "webkitspeechchange" : "speechchange";
- dom.observe(input, eventName, function() {
- parent.execCommand("insertText", input.value);
- input.value = "";
- });
-
- dom.observe(input, "click", function(event) {
- if (dom.hasClass(link, "wysihtml5-command-disabled")) {
- event.preventDefault();
- }
-
- event.stopPropagation();
- });
- };
-})(wysihtml5);
-;/**
- * Toolbar
- *
- * @param {Object} parent Reference to instance of Editor instance
- * @param {Element} container Reference to the toolbar container element
- *
- * @example
- *
- *
- *
- */
-(function(wysihtml5) {
- var CLASS_NAME_COMMAND_DISABLED = "wysihtml5-command-disabled",
- CLASS_NAME_COMMANDS_DISABLED = "wysihtml5-commands-disabled",
- CLASS_NAME_COMMAND_ACTIVE = "wysihtml5-command-active",
- CLASS_NAME_ACTION_ACTIVE = "wysihtml5-action-active",
- dom = wysihtml5.dom;
-
- wysihtml5.toolbar.Toolbar = Base.extend(
- /** @scope wysihtml5.toolbar.Toolbar.prototype */ {
- constructor: function(editor, container, showOnInit) {
- this.editor = editor;
- this.container = typeof(container) === "string" ? document.getElementById(container) : container;
- this.composer = editor.composer;
-
- this._getLinks("command");
- this._getLinks("action");
-
- this._observe();
- if (showOnInit) { this.show(); }
-
- if (editor.config.classNameCommandDisabled != null) {
- CLASS_NAME_COMMAND_DISABLED = editor.config.classNameCommandDisabled;
- }
- if (editor.config.classNameCommandsDisabled != null) {
- CLASS_NAME_COMMANDS_DISABLED = editor.config.classNameCommandsDisabled;
- }
- if (editor.config.classNameCommandActive != null) {
- CLASS_NAME_COMMAND_ACTIVE = editor.config.classNameCommandActive;
- }
- if (editor.config.classNameActionActive != null) {
- CLASS_NAME_ACTION_ACTIVE = editor.config.classNameActionActive;
- }
-
- var speechInputLinks = this.container.querySelectorAll("[data-wysihtml5-command=insertSpeech]"),
- length = speechInputLinks.length,
- i = 0;
- for (; i element or wrap current selection in
- * toolbar.execCommand("formatBlock", "blockquote");
- */
- execCommand: function(command, commandValue) {
- if (this.commandsDisabled) {
- return;
- }
-
- this._execCommand(command, commandValue);
- },
-
- _execCommand: function(command, commandValue) {
- // Make sure that composer is focussed (false => don't move caret to the end)
- this.editor.focus(false);
-
- this.composer.commands.exec(command, commandValue);
- this._updateLinkStates();
- },
-
- execAction: function(action) {
- var editor = this.editor;
- if (action === "change_view") {
- if (editor.currentView === editor.textarea || editor.currentView === "source") {
- editor.fire("change_view", "composer");
- } else {
- editor.fire("change_view", "textarea");
- }
- }
- if (action == "showSource") {
- editor.fire("showSource");
- }
- },
-
- _observe: function() {
- var that = this,
- editor = this.editor,
- container = this.container,
- links = this.commandLinks.concat(this.actionLinks),
- length = links.length,
- i = 0;
-
- for (; i>>0;~(c-e);d=this[--c]===a?c:d);return d}),Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e}),function(a){a.matches=a.matches||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector||a.webkitMatchesSelector||function(a){for(var b=this,c=(b.document||b.ownerDocument).querySelectorAll(a),d=0;c[d]&&c[d]!==b;)++d;return c[d]?!0:!1},a.closest=a.closest||function(a){for(var b=this;b&&!b.matches(a);)b=b.parentElement;return b}}(Element.prototype),"document"in a&&("classList"in b.createElement("_")?"DOMTokenList"in a&&!function(){"use strict";var c=b.createElement("_");if(c.classList.add("c1","c2"),!c.classList.contains("c2")){var d=function(b){var c=a.DOMTokenList.prototype[b];a.DOMTokenList.prototype[b]=function(a){var b,d=arguments.length;for(b=0;d>b;b++)a=arguments[b],c.call(this,a)}};d("add"),d("remove")}if(c.classList.toggle("c3",!1),c.classList.contains("c3")){var e=a.DOMTokenList.prototype.toggle;a.DOMTokenList.prototype.toggle=function(a,b){return 1 in arguments&&!this.contains(a)==!b?b:e.call(this,a)}}c=null}():!function(a){"use strict";if("Element"in a){var b="classList",c="prototype",d=a.Element[c],e=Object,f=String[c].trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=Array[c].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a,this.code=DOMException[a],this.message=b},i=function(a,b){if(""===b)throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return g.call(a,b)},j=function(a){for(var b=f.call(a.getAttribute("class")||""),c=b?b.split(/\s+/):[],d=0,e=c.length;e>d;d++)this.push(c[d]);this._updateClassName=function(){a.setAttribute("class",this.toString())}},k=j[c]=[],l=function(){return new j(this)};if(h[c]=Error[c],k.item=function(a){return this[a]||null},k.contains=function(a){return a+="",-1!==i(this,a)},k.add=function(){var a,b=arguments,c=0,d=b.length,e=!1;do a=b[c]+"",-1===i(this,a)&&(this.push(a),e=!0);while(++c0?c.childNodes[d]:void 0,h=b.focusNode,i=b.focusOffset,j=h&&1===h.nodeType&&i>0?h.childNodes[i-1]:void 0,k=this.ownerDocument.createRange(),l=a.shift(),m=l?a.shift():null;for(j&&3===j.nodeType&&(h=j,i=j.nodeValue.length,j=void 0),g&&3===g.nodeType&&(c=g,d=0,g=void 0),(c===h&&d>i||c!==h&&c.compareDocumentPosition(h)&Node.DOCUMENT_POSITION_PRECEDING&&!(c.compareDocumentPosition(h)&Node.DOCUMENT_POSITION_CONTAINS))&&(h=[c,c=h][0],i=[d,d=i][0]);l&&m;)m.previousSibling&&m.previousSibling===l?(c===m&&(c=l,d=l.nodeValue.length+d),h===m&&(h=l,i=l.nodeValue.length+i),l.nodeValue=l.nodeValue+m.nodeValue,m.parentNode.removeChild(m),m=a.shift()):(l=m,m=a.shift());j&&(i=Array.prototype.indexOf.call(j.parentNode.childNodes,j)+1),g&&(d=Array.prototype.indexOf.call(g.parentNode.childNodes,g)),f(this)&&c&&c.parentNode&&h&&h.parentNode&&(k.setStart(c,d),k.setEnd(h,i),b.removeAllRanges(),b.addRange(k))});Node.prototype.normalize=a},h=function(){window.removeEventListener("load",h),"Node"in window&&"normalize"in Node.prototype&&d()&&g()};"complete"!==b.readyState?window.addEventListener("load",h):h();var i=c();!function(){function c(a,c){c=c||{bubbles:!1,cancelable:!1,detail:void 0};var d=b.createEvent("CustomEvent");return d.initCustomEvent(a,c.bubbles,c.cancelable,c.detail),d}!i&&"CustomEvent"in window&&(c.prototype=a.Event.prototype,a.CustomEvent=c,i=!0)}()},wysihtml5.polyfills(window,document),function(a,b){"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"object"==typeof exports?module.exports=a():b.rangy=a()}(function(){function a(a,b){var c=typeof a[b];return c==u||!(c!=t||!a[b])||"unknown"==c}function b(a,b){return!(typeof a[b]!=t||!a[b])}function c(a,b){return typeof a[b]!=v}function d(a){return function(b,c){for(var d=c.length;d--;)if(!a(b,c[d]))return!1;return!0}}function e(a){return a&&A(a,z)&&C(a,y)}function f(a){return b(a,"body")?a.body:a.getElementsByTagName("body")[0]}function g(b){typeof console!=v&&a(console,"log")&&console.log(b)}function h(a,b){F&&b?alert(a):g(a)}function i(a){H.initialized=!0,H.supported=!1,h("Rangy is not supported in this environment. Reason: "+a,H.config.alertOnFail)}function j(a){h("Rangy warning: "+a,H.config.alertOnWarn)}function k(a){return a.message||a.description||String(a)}function l(){if(F&&!H.initialized){var b,c=!1,d=!1;a(document,"createRange")&&(b=document.createRange(),A(b,x)&&C(b,w)&&(c=!0));var h=f(document);if(!h||"body"!=h.nodeName.toLowerCase())return void i("No body element found");if(h&&a(h,"createTextRange")&&(b=h.createTextRange(),e(b)&&(d=!0)),!c&&!d)return void i("Neither Range nor TextRange are available");H.initialized=!0,H.features={implementsDomRange:c,implementsTextRange:d};var j,l;for(var m in E)(j=E[m])instanceof p&&j.init(j,H);for(var n=0,o=K.length;o>n;++n)try{K[n](H)}catch(q){l="Rangy init listener threw an exception. Continuing. Detail: "+k(q),g(l)}}}function m(a,b,c){c&&(a+=" in module "+c.name),H.warn("DEPRECATED: "+a+" is deprecated. Please use "+b+" instead.")}function n(a,b,c,d){a[b]=function(){return m(b,c,d),a[c].apply(a,G.toArray(arguments))}}function o(a){a=a||window,l();for(var b=0,c=L.length;c>b;++b)L[b](a)}function p(a,b,c){this.name=a,this.dependencies=b,this.initialized=!1,this.supported=!1,this.initializer=c}function q(a,b,c){var d=new p(a,b,function(b){if(!b.initialized){b.initialized=!0;try{c(H,b),b.supported=!0}catch(d){var e="Module '"+a+"' failed to load: "+k(d);g(e),d.stack&&g(d.stack)}}});return E[a]=d,d}function r(){}function s(){}var t="object",u="function",v="undefined",w=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],x=["setStart","setStartBefore","setStartAfter","setEnd","setEndBefore","setEndAfter","collapse","selectNode","selectNodeContents","compareBoundaryPoints","deleteContents","extractContents","cloneContents","insertNode","surroundContents","cloneRange","toString","detach"],y=["boundingHeight","boundingLeft","boundingTop","boundingWidth","htmlText","text"],z=["collapse","compareEndPoints","duplicate","moveToElementText","parentElement","select","setEndPoint","getBoundingClientRect"],A=d(a),B=d(b),C=d(c),D=[].forEach?function(a,b){a.forEach(b)}:function(a,b){for(var c=0,d=a.length;d>c;++c)b(a[c],c)},E={},F=typeof window!=v&&typeof document!=v,G={isHostMethod:a,isHostObject:b,isHostProperty:c,areHostMethods:A,areHostObjects:B,areHostProperties:C,isTextRange:e,getBody:f,forEach:D},H={version:"1.3.0",initialized:!1,isBrowser:F,supported:!0,util:G,features:{},modules:E,config:{alertOnFail:!1,alertOnWarn:!1,preferTextRange:!1,autoInitialize:typeof rangyAutoInitialize==v?!0:rangyAutoInitialize}};H.fail=i,H.warn=j;var I;({}).hasOwnProperty?(G.extend=I=function(a,b,c){var d,e;for(var f in b)b.hasOwnProperty(f)&&(d=a[f],e=b[f],c&&null!==d&&"object"==typeof d&&null!==e&&"object"==typeof e&&I(d,e,!0),a[f]=e);return b.hasOwnProperty("toString")&&(a.toString=b.toString),a},G.createOptions=function(a,b){var c={};return I(c,b),a&&I(c,a),c}):i("hasOwnProperty not supported"),F||i("Rangy can only run in a browser"),function(){var a;if(F){var b=document.createElement("div");b.appendChild(document.createElement("span"));var c=[].slice;try{1==c.call(b.childNodes,0)[0].nodeType&&(a=function(a){return c.call(a,0)})}catch(d){}}a||(a=function(a){for(var b=[],c=0,d=a.length;d>c;++c)b[c]=a[c];return b}),G.toArray=a}();var J;F&&(a(document,"addEventListener")?J=function(a,b,c){a.addEventListener(b,c,!1)}:a(document,"attachEvent")?J=function(a,b,c){a.attachEvent("on"+b,c)}:i("Document does not have required addEventListener or attachEvent method"),G.addListener=J);var K=[];G.deprecationNotice=m,G.createAliasForDeprecatedMethod=n,H.init=l,H.addInitListener=function(a){H.initialized?a(H):K.push(a)};var L=[];H.addShimListener=function(a){L.push(a)},F&&(H.shim=H.createMissingNativeApi=o,n(H,"createMissingNativeApi","shim")),p.prototype={init:function(){for(var a,b,c=this.dependencies||[],d=0,e=c.length;e>d;++d){if(b=c[d],a=E[b],!(a&&a instanceof p))throw new Error("required module '"+b+"' not found");if(a.init(),!a.supported)throw new Error("required module '"+b+"' not supported")}this.initializer(this)},fail:function(a){throw this.initialized=!0,this.supported=!1,new Error(a)},warn:function(a){H.warn("Module "+this.name+": "+a)},deprecationNotice:function(a,b){H.warn("DEPRECATED: "+a+" in module "+this.name+" is deprecated. Please use "+b+" instead")},createError:function(a){return new Error("Error in Rangy "+this.name+" module: "+a)}},H.createModule=function(a){var b,c;2==arguments.length?(b=arguments[1],c=[]):(b=arguments[2],c=arguments[1]);var d=q(a,c,b);H.initialized&&H.supported&&d.init()},H.createCoreModule=function(a,b,c){q(a,b,c)},H.RangePrototype=r,H.rangePrototype=new r,H.selectionPrototype=new s,H.createCoreModule("DomUtil",[],function(a,b){function c(a){var b;return typeof a.namespaceURI==F||null===(b=a.namespaceURI)||"http://www.w3.org/1999/xhtml"==b}function d(a){var b=a.parentNode;return 1==b.nodeType?b:null}function e(a){for(var b=0;a=a.previousSibling;)++b;return b}function f(a){switch(a.nodeType){case 7:case 10:return 0;case 3:case 8:return a.length;default:return a.childNodes.length}}function g(a,b){var c,d=[];for(c=a;c;c=c.parentNode)d.push(c);for(c=b;c;c=c.parentNode)if(K(d,c))return c;return null}function h(a,b,c){for(var d=c?b:b.parentNode;d;){if(d===a)return!0;d=d.parentNode}return!1}function i(a,b){return h(a,b,!0)}function j(a,b,c){for(var d,e=c?a:a.parentNode;e;){if(d=e.parentNode,d===b)return e;e=d}return null}function k(a){var b=a.nodeType;return 3==b||4==b||8==b}function l(a){if(!a)return!1;var b=a.nodeType;return 3==b||8==b}function m(a,b){var c=b.nextSibling,d=b.parentNode;return c?d.insertBefore(a,c):d.appendChild(a),a}function n(a,b,c){var d=a.cloneNode(!1);if(d.deleteData(0,b),a.deleteData(b,a.length-b),m(d,a),c)for(var f,g=0;f=c[g++];)f.node==a&&f.offset>b?(f.node=d,f.offset-=b):f.node==a.parentNode&&f.offset>e(a)&&++f.offset;return d}function o(a){if(9==a.nodeType)return a;if(typeof a.ownerDocument!=F)return a.ownerDocument;if(typeof a.document!=F)return a.document;if(a.parentNode)return o(a.parentNode);throw b.createError("getDocument: no document found for node")}function p(a){var c=o(a);if(typeof c.defaultView!=F)return c.defaultView;if(typeof c.parentWindow!=F)return c.parentWindow;throw b.createError("Cannot get a window object for node")}function q(a){if(typeof a.contentDocument!=F)return a.contentDocument;if(typeof a.contentWindow!=F)return a.contentWindow.document;throw b.createError("getIframeDocument: No Document object found for iframe element")}function r(a){if(typeof a.contentWindow!=F)return a.contentWindow;if(typeof a.contentDocument!=F)return a.contentDocument.defaultView;throw b.createError("getIframeWindow: No Window object found for iframe element")}function s(a){return a&&G.isHostMethod(a,"setTimeout")&&G.isHostObject(a,"document")}function t(a,b,c){var d;if(a?G.isHostProperty(a,"nodeType")?d=1==a.nodeType&&"iframe"==a.tagName.toLowerCase()?q(a):o(a):s(a)&&(d=a.document):d=document,!d)throw b.createError(c+"(): Parameter must be a Window object or DOM node");return d}function u(a){for(var b;b=a.parentNode;)a=b;return a}function v(a,c,d,f){var h,i,k,l,m;if(a==d)return c===f?0:f>c?-1:1;if(h=j(d,a,!0))return c<=e(h)?-1:1;if(h=j(a,d,!0))return e(h)[index:"+e(a)+",length:"+a.childNodes.length+"]["+(a.innerHTML||"[innerHTML not supported]").slice(0,25)+"]"}return a.nodeName}function y(a){for(var b,c=o(a).createDocumentFragment();b=a.firstChild;)c.appendChild(b);return c}function z(a,b,c){var d=H(a),e=a.createElement("div");e.contentEditable=""+!!c,b&&(e.innerHTML=b);var f=d.firstChild;return f?d.insertBefore(e,f):d.appendChild(e),e}function A(a){return a.parentNode.removeChild(a)}function B(a){this.root=a,this._next=a}function C(a){return new B(a)}function D(a,b){this.node=a,this.offset=b}function E(a){this.code=this[a],this.codeName=a,this.message="DOMException: "+this.codeName}var F="undefined",G=a.util,H=G.getBody;G.areHostMethods(document,["createDocumentFragment","createElement","createTextNode"])||b.fail("document missing a Node creation method"),G.isHostMethod(document,"getElementsByTagName")||b.fail("document missing getElementsByTagName method");var I=document.createElement("div");G.areHostMethods(I,["insertBefore","appendChild","cloneNode"]||!G.areHostObjects(I,["previousSibling","nextSibling","childNodes","parentNode"]))||b.fail("Incomplete Element implementation"),G.isHostProperty(I,"innerHTML")||b.fail("Element is missing innerHTML property");var J=document.createTextNode("test");G.areHostMethods(J,["splitText","deleteData","insertData","appendData","cloneNode"]||!G.areHostObjects(I,["previousSibling","nextSibling","childNodes","parentNode"])||!G.areHostProperties(J,["data"]))||b.fail("Incomplete Text Node implementation");var K=function(a,b){for(var c=a.length;c--;)if(a[c]===b)return!0;return!1},L=!1;!function(){var b=document.createElement("b");b.innerHTML="1";var c=b.firstChild;b.innerHTML=" ",L=w(c),a.features.crashyTextNodes=L}();var M;typeof window.getComputedStyle!=F?M=function(a,b){return p(a).getComputedStyle(a,null)[b]}:typeof document.documentElement.currentStyle!=F?M=function(a,b){return a.currentStyle?a.currentStyle[b]:""}:b.fail("No means of obtaining computed style properties found"),B.prototype={_current:null,hasNext:function(){return!!this._next},next:function(){var a,b,c=this._current=this._next;if(this._current)if(a=c.firstChild)this._next=a;else{for(b=null;c!==this.root&&!(b=c.nextSibling);)c=c.parentNode;this._next=b}return this._current},detach:function(){this._current=this._next=this.root=null}},D.prototype={equals:function(a){return!!a&&this.node===a.node&&this.offset==a.offset},inspect:function(){return"[DomPosition("+x(this.node)+":"+this.offset+")]"},toString:function(){return this.inspect()}},E.prototype={INDEX_SIZE_ERR:1,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INVALID_STATE_ERR:11,INVALID_NODE_TYPE_ERR:24},E.prototype.toString=function(){return this.message},a.dom={arrayContains:K,isHtmlNamespace:c,parentElement:d,getNodeIndex:e,getNodeLength:f,getCommonAncestor:g,isAncestorOf:h,isOrIsAncestorOf:i,getClosestAncestorIn:j,isCharacterDataNode:k,isTextOrCommentNode:l,insertAfter:m,splitDataNode:n,getDocument:o,getWindow:p,getIframeWindow:r,getIframeDocument:q,getBody:H,isWindow:s,getContentDocument:t,getRootContainer:u,comparePoints:v,isBrokenNode:w,inspectNode:x,getComputedStyleProperty:M,createTestElement:z,removeNode:A,fragmentFromNodeChildren:y,createIterator:C,DomPosition:D},a.DOMException=E}),H.createCoreModule("DomRange",["DomUtil"],function(a,b){function c(a,b){return 3!=a.nodeType&&(P(a,b.startContainer)||P(a,b.endContainer))}function d(a){return a.document||Q(a.startContainer)}function e(a){return W(a.startContainer)}function f(a){return new L(a.parentNode,O(a))}function g(a){return new L(a.parentNode,O(a)+1)}function h(a,b,c){var d=11==a.nodeType?a.firstChild:a;return N(b)?c==b.length?J.insertAfter(a,b):b.parentNode.insertBefore(a,0==c?b:S(b,c)):c>=b.childNodes.length?b.appendChild(a):b.insertBefore(a,b.childNodes[c]),d}function i(a,b,c){if(z(a),z(b),d(b)!=d(a))throw new M("WRONG_DOCUMENT_ERR");var e=R(a.startContainer,a.startOffset,b.endContainer,b.endOffset),f=R(a.endContainer,a.endOffset,b.startContainer,b.startOffset);return c?0>=e&&f>=0:0>e&&f>0}function j(a){for(var b,c,e,f=d(a.range).createDocumentFragment();c=a.next();){if(b=a.isPartiallySelectedSubtree(),c=c.cloneNode(!b),b&&(e=a.getSubtreeIterator(),c.appendChild(j(e)),e.detach()),10==c.nodeType)throw new M("HIERARCHY_REQUEST_ERR");f.appendChild(c)}return f}function k(a,b,c){var d,e;c=c||{stop:!1};for(var f,g;f=a.next();)if(a.isPartiallySelectedSubtree()){if(b(f)===!1)return void(c.stop=!0);if(g=a.getSubtreeIterator(),k(g,b,c),g.detach(),c.stop)return}else for(d=J.createIterator(f);e=d.next();)if(b(e)===!1)return void(c.stop=!0)}function l(a){for(var b;a.next();)a.isPartiallySelectedSubtree()?(b=a.getSubtreeIterator(),l(b),b.detach()):a.remove()}function m(a){for(var b,c,e=d(a.range).createDocumentFragment();b=a.next();){if(a.isPartiallySelectedSubtree()?(b=b.cloneNode(!1),c=a.getSubtreeIterator(),b.appendChild(m(c)),c.detach()):a.remove(),10==b.nodeType)throw new M("HIERARCHY_REQUEST_ERR");e.appendChild(b)}return e}function n(a,b,c){var d,e=!(!b||!b.length),f=!!c;e&&(d=new RegExp("^("+b.join("|")+")$"));var g=[];return k(new p(a,!1),function(b){if((!e||d.test(b.nodeType))&&(!f||c(b))){var h=a.startContainer;if(b!=h||!N(h)||a.startOffset!=h.length){var i=a.endContainer;b==i&&N(i)&&0==a.endOffset||g.push(b)}}}),g}function o(a){var b="undefined"==typeof a.getName?"Range":a.getName();return"["+b+"("+J.inspectNode(a.startContainer)+":"+a.startOffset+", "+J.inspectNode(a.endContainer)+":"+a.endOffset+")]"}function p(a,b){if(this.range=a,this.clonePartiallySelectedTextNodes=b,!a.collapsed){this.sc=a.startContainer,this.so=a.startOffset,this.ec=a.endContainer,this.eo=a.endOffset;var c=a.commonAncestorContainer;this.sc===this.ec&&N(this.sc)?(this.isSingleCharacterDataNode=!0,this._first=this._last=this._next=this.sc):(this._first=this._next=this.sc!==c||N(this.sc)?T(this.sc,c,!0):this.sc.childNodes[this.so],this._last=this.ec!==c||N(this.ec)?T(this.ec,c,!0):this.ec.childNodes[this.eo-1])}}function q(a){return function(b,c){for(var d,e=c?b:b.parentNode;e;){if(d=e.nodeType,V(a,d))return e;e=e.parentNode}return null}}function r(a,b){if(ea(a,b))throw new M("INVALID_NODE_TYPE_ERR")}function s(a,b){if(!V(b,a.nodeType))throw new M("INVALID_NODE_TYPE_ERR")}function t(a,b){if(0>b||b>(N(a)?a.length:a.childNodes.length))throw new M("INDEX_SIZE_ERR")}function u(a,b){if(ca(a,!0)!==ca(b,!0))throw new M("WRONG_DOCUMENT_ERR")}function v(a){if(da(a,!0))throw new M("NO_MODIFICATION_ALLOWED_ERR")}function w(a,b){if(!a)throw new M(b)}function x(a,b){return b<=(N(a)?a.length:a.childNodes.length)}function y(a){return!!a.startContainer&&!!a.endContainer&&!(X&&(J.isBrokenNode(a.startContainer)||J.isBrokenNode(a.endContainer)))&&W(a.startContainer)==W(a.endContainer)&&x(a.startContainer,a.startOffset)&&x(a.endContainer,a.endOffset)}function z(a){if(!y(a))throw new Error("Range error: Range is not valid. This usually happens after DOM mutation. Range: ("+a.inspect()+")")}function A(a,b){z(a);var c=a.startContainer,d=a.startOffset,e=a.endContainer,f=a.endOffset,g=c===e;N(e)&&f>0&&f0&&d=O(c)&&f++,d=0),a.setStartAndEnd(c,d,e,f)}function B(a){z(a);var b=a.commonAncestorContainer.parentNode.cloneNode(!1);return b.appendChild(a.cloneContents()),b.innerHTML}function C(a){a.START_TO_START=ka,a.START_TO_END=la,a.END_TO_END=ma,a.END_TO_START=na,a.NODE_BEFORE=oa,a.NODE_AFTER=pa,a.NODE_BEFORE_AND_AFTER=qa,a.NODE_INSIDE=ra}function D(a){C(a),C(a.prototype)}function E(a,b){return function(){z(this);var c,d,e=this.startContainer,f=this.startOffset,h=this.commonAncestorContainer,i=new p(this,!0);e!==h&&(c=T(e,h,!0),d=g(c),e=d.node,f=d.offset),k(i,v),i.reset();var j=a(i);return i.detach(),b(this,e,f,e,f),j}}function F(b,d){function e(a,b){return function(c){s(c,Z),s(W(c),$);var d=(a?f:g)(c);(b?h:i)(this,d.node,d.offset)}}function h(a,b,c){var e=a.endContainer,f=a.endOffset;(b!==a.startContainer||c!==a.startOffset)&&((W(b)!=W(e)||1==R(b,c,e,f))&&(e=b,f=c),d(a,b,c,e,f))}function i(a,b,c){var e=a.startContainer,f=a.startOffset;(b!==a.endContainer||c!==a.endOffset)&&((W(b)!=W(e)||-1==R(b,c,e,f))&&(e=b,f=c),d(a,e,f,b,c))}var j=function(){};j.prototype=a.rangePrototype,b.prototype=new j,K.extend(b.prototype,{setStart:function(a,b){r(a,!0),t(a,b),h(this,a,b)},setEnd:function(a,b){r(a,!0),t(a,b),i(this,a,b)},setStartAndEnd:function(){var a=arguments,b=a[0],c=a[1],e=b,f=c;switch(a.length){case 3:f=a[2];break;case 4:e=a[2],f=a[3]}d(this,b,c,e,f)},setBoundary:function(a,b,c){this["set"+(c?"Start":"End")](a,b)},setStartBefore:e(!0,!0),setStartAfter:e(!1,!0),setEndBefore:e(!0,!1),setEndAfter:e(!1,!1),collapse:function(a){z(this),a?d(this,this.startContainer,this.startOffset,this.startContainer,this.startOffset):d(this,this.endContainer,this.endOffset,this.endContainer,this.endOffset)},selectNodeContents:function(a){r(a,!0),d(this,a,0,a,U(a))},selectNode:function(a){r(a,!1),s(a,Z);var b=f(a),c=g(a);d(this,b.node,b.offset,c.node,c.offset)},extractContents:E(m,d),deleteContents:E(l,d),canSurroundContents:function(){z(this),v(this.startContainer),v(this.endContainer);var a=new p(this,!0),b=a._first&&c(a._first,this)||a._last&&c(a._last,this);return a.detach(),!b},splitBoundaries:function(){A(this)},splitBoundariesPreservingPositions:function(a){A(this,a)},normalizeBoundaries:function(){z(this);var a,b=this.startContainer,c=this.startOffset,e=this.endContainer,f=this.endOffset,g=function(a){var b=a.nextSibling;b&&b.nodeType==a.nodeType&&(e=a,f=a.length,a.appendData(b.data),Y(b))},h=function(a){var d=a.previousSibling;if(d&&d.nodeType==a.nodeType){b=a;var g=a.length;if(c=d.length,a.insertData(0,d.data),Y(d),b==e)f+=c,e=b;else if(e==a.parentNode){var h=O(a);f==h?(e=a,f=g):f>h&&f--}}},i=!0;if(N(e))f==e.length?g(e):0==f&&(a=e.previousSibling,a&&a.nodeType==e.nodeType&&(f=a.length,b==e&&(i=!1),a.appendData(e.data),Y(e),e=a));else{if(f>0){var j=e.childNodes[f-1];j&&N(j)&&g(j)}i=!this.collapsed}if(i){if(N(b))0==c?h(b):c==b.length&&(a=b.nextSibling,a&&a.nodeType==b.nodeType&&(e==a&&(e=b,f+=b.length),b.appendData(a.data),Y(a)));else if(cx",ga=3==fa.firstChild.nodeType}catch(ha){}a.features.htmlParsingConforms=ga;var ia=ga?function(a){var b=this.startContainer,c=Q(b);if(!b)throw new M("INVALID_STATE_ERR");var d=null;return 1==b.nodeType?d=b:N(b)&&(d=J.parentElement(b)),d=null===d||"HTML"==d.nodeName&&J.isHtmlNamespace(Q(d).documentElement)&&J.isHtmlNamespace(d)?c.createElement("body"):d.cloneNode(!1),d.innerHTML=a,J.fragmentFromNodeChildren(d)}:function(a){var b=d(this),c=b.createElement("body");return c.innerHTML=a,J.fragmentFromNodeChildren(c)},ja=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],ka=0,la=1,ma=2,na=3,oa=0,pa=1,qa=2,ra=3;K.extend(a.rangePrototype,{compareBoundaryPoints:function(a,b){z(this),u(this.startContainer,b.startContainer);var c,d,e,f,g=a==na||a==ka?"start":"end",h=a==la||a==ka?"start":"end";return c=this[g+"Container"],d=this[g+"Offset"],e=b[h+"Container"],f=b[h+"Offset"],R(c,d,e,f)},insertNode:function(a){if(z(this),s(a,aa),v(this.startContainer),P(a,this.startContainer))throw new M("HIERARCHY_REQUEST_ERR");var b=h(a,this.startContainer,this.startOffset);this.setStartBefore(b)},cloneContents:function(){z(this);var a,b;if(this.collapsed)return d(this).createDocumentFragment();if(this.startContainer===this.endContainer&&N(this.startContainer))return a=this.startContainer.cloneNode(!0),a.data=a.data.slice(this.startOffset,this.endOffset),b=d(this).createDocumentFragment(),b.appendChild(a),b;var c=new p(this,!0);return a=j(c),c.detach(),a},canSurroundContents:function(){z(this),v(this.startContainer),v(this.endContainer);var a=new p(this,!0),b=a._first&&c(a._first,this)||a._last&&c(a._last,this);return a.detach(),!b},surroundContents:function(a){if(s(a,ba),!this.canSurroundContents())throw new M("INVALID_STATE_ERR");var b=this.extractContents();if(a.hasChildNodes())for(;a.lastChild;)a.removeChild(a.lastChild);h(a,this.startContainer,this.startOffset),a.appendChild(b),this.selectNode(a)},cloneRange:function(){z(this);for(var a,b=new I(d(this)),c=ja.length;c--;)a=ja[c],b[a]=this[a];return b},toString:function(){z(this);var a=this.startContainer;if(a===this.endContainer&&N(a))return 3==a.nodeType||4==a.nodeType?a.data.slice(this.startOffset,this.endOffset):"";var b=[],c=new p(this,!0);return k(c,function(a){(3==a.nodeType||4==a.nodeType)&&b.push(a.data)}),c.detach(),b.join("")},compareNode:function(a){z(this);var b=a.parentNode,c=O(a);if(!b)throw new M("NOT_FOUND_ERR");var d=this.comparePoint(b,c),e=this.comparePoint(b,c+1);return 0>d?e>0?qa:oa:e>0?pa:ra},comparePoint:function(a,b){return z(this),w(a,"HIERARCHY_REQUEST_ERR"),u(a,this.startContainer),R(a,b,this.startContainer,this.startOffset)<0?-1:R(a,b,this.endContainer,this.endOffset)>0?1:0},createContextualFragment:ia,toHtml:function(){return B(this)},intersectsNode:function(a,b){if(z(this),W(a)!=e(this))return!1;var c=a.parentNode,d=O(a);if(!c)return!0;var f=R(c,d,this.endContainer,this.endOffset),g=R(c,d+1,this.startContainer,this.startOffset);return b?0>=f&&g>=0:0>f&&g>0},isPointInRange:function(a,b){return z(this),w(a,"HIERARCHY_REQUEST_ERR"),u(a,this.startContainer),R(a,b,this.startContainer,this.startOffset)>=0&&R(a,b,this.endContainer,this.endOffset)<=0},intersectsRange:function(a){return i(this,a,!1)},intersectsOrTouchesRange:function(a){return i(this,a,!0)},intersection:function(a){if(this.intersectsRange(a)){var b=R(this.startContainer,this.startOffset,a.startContainer,a.startOffset),c=R(this.endContainer,this.endOffset,a.endContainer,a.endOffset),d=this.cloneRange();return-1==b&&d.setStart(a.startContainer,a.startOffset),1==c&&d.setEnd(a.endContainer,a.endOffset),d}return null},union:function(a){if(this.intersectsOrTouchesRange(a)){var b=this.cloneRange();return-1==R(a.startContainer,a.startOffset,this.startContainer,this.startOffset)&&b.setStart(a.startContainer,a.startOffset),1==R(a.endContainer,a.endOffset,this.endContainer,this.endOffset)&&b.setEnd(a.endContainer,a.endOffset),
-b}throw new M("Ranges do not intersect")},containsNode:function(a,b){return b?this.intersectsNode(a,!1):this.compareNode(a)==ra},containsNodeContents:function(a){return this.comparePoint(a,0)>=0&&this.comparePoint(a,U(a))<=0},containsRange:function(a){var b=this.intersection(a);return null!==b&&a.equals(b)},containsNodeText:function(a){var b=this.cloneRange();b.selectNode(a);var c=b.getNodes([3]);if(c.length>0){b.setStart(c[0],0);var d=c.pop();return b.setEnd(d,d.length),this.containsRange(b)}return this.containsNodeContents(a)},getNodes:function(a,b){return z(this),n(this,a,b)},getDocument:function(){return d(this)},collapseBefore:function(a){this.setEndBefore(a),this.collapse(!1)},collapseAfter:function(a){this.setStartAfter(a),this.collapse(!0)},getBookmark:function(b){var c=d(this),e=a.createRange(c);b=b||J.getBody(c),e.selectNodeContents(b);var f=this.intersection(e),g=0,h=0;return f&&(e.setEnd(f.startContainer,f.startOffset),g=e.toString().length,h=g+f.toString().length),{start:g,end:h,containerNode:b}},moveToBookmark:function(a){var b=a.containerNode,c=0;this.setStart(b,0),this.collapse(!0);for(var d,e,f,g,h=[b],i=!1,j=!1;!j&&(d=h.pop());)if(3==d.nodeType)e=c+d.length,!i&&a.start>=c&&a.start<=e&&(this.setStart(d,a.start-c),i=!0),i&&a.end>=c&&a.end<=e&&(this.setEnd(d,a.end-c),j=!0),c=e;else for(g=d.childNodes,f=g.length;f--;)h.push(g[f])},getName:function(){return"DomRange"},equals:function(a){return I.rangesEqual(this,a)},isValid:function(){return y(this)},inspect:function(){return o(this)},detach:function(){}}),F(I,H),K.extend(I,{rangeProperties:ja,RangeIterator:p,copyComparisonConstants:D,createPrototypeRange:F,inspect:o,toHtml:B,getRangeDocument:d,rangesEqual:function(a,b){return a.startContainer===b.startContainer&&a.startOffset===b.startOffset&&a.endContainer===b.endContainer&&a.endOffset===b.endOffset}}),a.DomRange=I}),H.createCoreModule("WrappedRange",["DomRange"],function(a,b){var c,d,e=a.dom,f=a.util,g=e.DomPosition,h=a.DomRange,i=e.getBody,j=e.getContentDocument,k=e.isCharacterDataNode;if(a.features.implementsDomRange&&!function(){function d(a){for(var b,c=m.length;c--;)b=m[c],a[b]=a.nativeRange[b];a.collapsed=a.startContainer===a.endContainer&&a.startOffset===a.endOffset}function g(a,b,c,d,e){var f=a.startContainer!==b||a.startOffset!=c,g=a.endContainer!==d||a.endOffset!=e,h=!a.equals(a.nativeRange);(f||g||h)&&(a.setEnd(d,e),a.setStart(b,c))}var k,l,m=h.rangeProperties;c=function(a){if(!a)throw b.createError("WrappedRange: Range must be specified");this.nativeRange=a,d(this)},h.createPrototypeRange(c,g),k=c.prototype,k.selectNode=function(a){this.nativeRange.selectNode(a),d(this)},k.cloneContents=function(){return this.nativeRange.cloneContents()},k.surroundContents=function(a){this.nativeRange.surroundContents(a),d(this)},k.collapse=function(a){this.nativeRange.collapse(a),d(this)},k.cloneRange=function(){return new c(this.nativeRange.cloneRange())},k.refresh=function(){d(this)},k.toString=function(){return this.nativeRange.toString()};var n=document.createTextNode("test");i(document).appendChild(n);var o=document.createRange();o.setStart(n,0),o.setEnd(n,0);try{o.setStart(n,1),k.setStart=function(a,b){this.nativeRange.setStart(a,b),d(this)},k.setEnd=function(a,b){this.nativeRange.setEnd(a,b),d(this)},l=function(a){return function(b){this.nativeRange[a](b),d(this)}}}catch(p){k.setStart=function(a,b){try{this.nativeRange.setStart(a,b)}catch(c){this.nativeRange.setEnd(a,b),this.nativeRange.setStart(a,b)}d(this)},k.setEnd=function(a,b){try{this.nativeRange.setEnd(a,b)}catch(c){this.nativeRange.setStart(a,b),this.nativeRange.setEnd(a,b)}d(this)},l=function(a,b){return function(c){try{this.nativeRange[a](c)}catch(e){this.nativeRange[b](c),this.nativeRange[a](c)}d(this)}}}k.setStartBefore=l("setStartBefore","setEndBefore"),k.setStartAfter=l("setStartAfter","setEndAfter"),k.setEndBefore=l("setEndBefore","setStartBefore"),k.setEndAfter=l("setEndAfter","setStartAfter"),k.selectNodeContents=function(a){this.setStartAndEnd(a,0,e.getNodeLength(a))},o.selectNodeContents(n),o.setEnd(n,3);var q=document.createRange();q.selectNodeContents(n),q.setEnd(n,4),q.setStart(n,2),-1==o.compareBoundaryPoints(o.START_TO_END,q)&&1==o.compareBoundaryPoints(o.END_TO_START,q)?k.compareBoundaryPoints=function(a,b){return b=b.nativeRange||b,a==b.START_TO_END?a=b.END_TO_START:a==b.END_TO_START&&(a=b.START_TO_END),this.nativeRange.compareBoundaryPoints(a,b)}:k.compareBoundaryPoints=function(a,b){return this.nativeRange.compareBoundaryPoints(a,b.nativeRange||b)};var r=document.createElement("div");r.innerHTML="123";var s=r.firstChild,t=i(document);t.appendChild(r),o.setStart(s,1),o.setEnd(s,2),o.deleteContents(),"13"==s.data&&(k.deleteContents=function(){this.nativeRange.deleteContents(),d(this)},k.extractContents=function(){var a=this.nativeRange.extractContents();return d(this),a}),t.removeChild(r),t=null,f.isHostMethod(o,"createContextualFragment")&&(k.createContextualFragment=function(a){return this.nativeRange.createContextualFragment(a)}),i(document).removeChild(n),k.getName=function(){return"WrappedRange"},a.WrappedRange=c,a.createNativeRange=function(a){return a=j(a,b,"createNativeRange"),a.createRange()}}(),a.features.implementsTextRange){var l=function(a){var b=a.parentElement(),c=a.duplicate();c.collapse(!0);var d=c.parentElement();c=a.duplicate(),c.collapse(!1);var f=c.parentElement(),g=d==f?d:e.getCommonAncestor(d,f);return g==b?g:e.getCommonAncestor(b,g)},m=function(a){return 0==a.compareEndPoints("StartToEnd",a)},n=function(a,b,c,d,f){var h=a.duplicate();h.collapse(c);var i=h.parentElement();if(e.isOrIsAncestorOf(b,i)||(i=b),!i.canHaveHTML){var j=new g(i.parentNode,e.getNodeIndex(i));return{boundaryPosition:j,nodeInfo:{nodeIndex:j.offset,containerElement:j.node}}}var l=e.getDocument(i).createElement("span");l.parentNode&&e.removeNode(l);for(var m,n,o,p,q,r=c?"StartToStart":"StartToEnd",s=f&&f.containerElement==i?f.nodeIndex:0,t=i.childNodes.length,u=t,v=u;;){if(v==t?i.appendChild(l):i.insertBefore(l,i.childNodes[v]),h.moveToElementText(l),m=h.compareEndPoints(r,a),0==m||s==u)break;if(-1==m){if(u==s+1)break;s=v}else u=u==s+1?s:v;v=Math.floor((s+u)/2),i.removeChild(l)}if(q=l.nextSibling,-1==m&&q&&k(q)){h.setEndPoint(c?"EndToStart":"EndToEnd",a);var w;if(/[\r\n]/.test(q.data)){var x=h.duplicate(),y=x.text.replace(/\r\n/g,"\r").length;for(w=x.moveStart("character",y);-1==(m=x.compareEndPoints("StartToEnd",x));)w++,x.moveStart("character",1)}else w=h.text.length;p=new g(q,w)}else n=(d||!c)&&l.previousSibling,o=(d||c)&&l.nextSibling,p=o&&k(o)?new g(o,0):n&&k(n)?new g(n,n.data.length):new g(i,e.getNodeIndex(l));return e.removeNode(l),{boundaryPosition:p,nodeInfo:{nodeIndex:v,containerElement:i}}},o=function(a,b){var c,d,f,g,h=a.offset,j=e.getDocument(a.node),l=i(j).createTextRange(),m=k(a.node);return m?(c=a.node,d=c.parentNode):(g=a.node.childNodes,c=hb;++b)if(!C.isAncestorOf(a[0],a[b]))return!1;return!0}function m(a){var c=a.getNodes();if(!l(c))throw b.createError("getSingleElementFromRange: range "+a.inspect()+" did not consist of a single element");return c[0]}function n(a){return!!a&&"undefined"!=typeof a.text}function o(a,b){var c=new G(b);a._ranges=[c],h(a,c,!1),a.rangeCount=1,a.isCollapsed=c.collapsed}function p(b){if(b._ranges.length=0,"None"==b.docSelection.type)j(b);else{var c=b.docSelection.createRange();if(n(c))o(b,c);else{b.rangeCount=c.length;for(var d,e=L(c.item(0)),f=0;fh;++h)g.add(d.item(h));try{g.add(e)}catch(j){throw b.createError("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)")}g.select(),p(a)}function r(a,b,c){this.nativeSelection=a,this.docSelection=b,this._ranges=[],this.win=c,this.refresh()}function s(a){a.win=a.anchorNode=a.focusNode=a._ranges=null,a.rangeCount=a.anchorOffset=a.focusOffset=0,a.detached=!0}function t(a,b){for(var c,d,e=ba.length;e--;)if(c=ba[e],d=c.selection,"deleteAll"==b)s(d);else if(c.win==a)return"delete"==b?(ba.splice(e,1),!0):d;return"deleteAll"==b&&(ba.length=0),null}function u(a,c){for(var d,e=L(c[0].startContainer),f=M(e).createControlRange(),g=0,h=c.length;h>g;++g){d=m(c[g]);try{f.add(d)}catch(i){throw b.createError("setRanges(): Element within one of the specified Ranges could not be added to control selection (does it have layout?)")}}f.select(),p(a)}function v(a,b){if(a.win.document!=L(b))throw new H("WRONG_DOCUMENT_ERR")}function w(b){return function(c,d){var e;this.rangeCount?(e=this.getRangeAt(0),e["set"+(b?"Start":"End")](c,d)):(e=a.createRange(this.win.document),e.setStartAndEnd(c,d)),this.setSingleRange(e,this.isBackward())}}function x(a){var b=[],c=new I(a.anchorNode,a.anchorOffset),d=new I(a.focusNode,a.focusOffset),e="function"==typeof a.getName?a.getName():"Selection";if("undefined"!=typeof a.rangeCount)for(var f=0,g=a.rangeCount;g>f;++f)b[f]=F.inspect(a.getRangeAt(f));return"["+e+"(Ranges: "+b.join(", ")+")(anchor: "+c.inspect()+", focus: "+d.inspect()+"]"}a.config.checkSelectionRanges=!0;var y,z,A="boolean",B="number",C=a.dom,D=a.util,E=D.isHostMethod,F=a.DomRange,G=a.WrappedRange,H=a.DOMException,I=C.DomPosition,J=a.features,K="Control",L=C.getDocument,M=C.getBody,N=F.rangesEqual,O=E(window,"getSelection"),P=D.isHostObject(document,"selection");J.implementsWinGetSelection=O,J.implementsDocSelection=P;var Q=P&&(!O||a.config.preferTextRange);if(Q)y=f,a.isSelectionValid=function(a){var b=d(a,"isSelectionValid").document,c=b.selection;return"None"!=c.type||L(c.createRange().parentElement())==b};else{if(!O)return b.fail("Neither document.selection or window.getSelection() detected."),!1;y=e,a.isSelectionValid=function(){return!0}}a.getNativeSelection=y;var R=y();if(!R)return b.fail("Native selection was null (possibly issue 138?)"),!1;var S=a.createNativeRange(document),T=M(document),U=D.areHostProperties(R,["anchorNode","focusNode","anchorOffset","focusOffset"]);J.selectionHasAnchorAndFocus=U;var V=E(R,"extend");J.selectionHasExtend=V;var W=typeof R.rangeCount==B;J.selectionHasRangeCount=W;var X=!1,Y=!0,Z=V?function(b,c){var d=F.getRangeDocument(c),e=a.createRange(d);e.collapseToPoint(c.endContainer,c.endOffset),b.addRange(k(e)),b.extend(c.startContainer,c.startOffset)}:null;D.areHostMethods(R,["addRange","getRangeAt","removeAllRanges"])&&typeof R.rangeCount==B&&J.implementsDomRange&&!function(){var b=window.getSelection();if(b){for(var c=b.rangeCount,d=c>1,e=[],f=g(b),h=0;c>h;++h)e[h]=b.getRangeAt(h);var i=C.createTestElement(document,"",!1),j=i.appendChild(document.createTextNode("Â Â Â ")),k=document.createRange();if(k.setStart(j,1),k.collapse(!0),b.removeAllRanges(),b.addRange(k),Y=1==b.rangeCount,b.removeAllRanges(),!d){var l=window.navigator.appVersion.match(/Chrome\/(.*?) /);if(l&&parseInt(l[1])>=36)X=!1;else{var m=k.cloneRange();k.setStart(j,0),m.setEnd(j,3),m.setStart(j,2),b.addRange(k),b.addRange(m),X=2==b.rangeCount}}for(C.removeNode(i),b.removeAllRanges(),h=0;c>h;++h)0==h&&f?Z?Z(b,e[h]):(a.warn("Rangy initialization: original selection was backwards but selection has been restored forwards because the browser does not support Selection.extend"),b.addRange(e[h])):b.addRange(e[h])}}(),J.selectionSupportsMultipleRanges=X,J.collapsedNonEditableSelectionsSupported=Y;var $,_=!1;T&&E(T,"createControlRange")&&($=T.createControlRange(),D.areHostProperties($,["item","add"])&&(_=!0)),J.implementsControlRange=_,z=U?function(a){return a.anchorNode===a.focusNode&&a.anchorOffset===a.focusOffset}:function(a){return a.rangeCount?a.getRangeAt(a.rangeCount-1).collapsed:!1};var aa;E(R,"getRangeAt")?aa=function(a,b){try{return a.getRangeAt(b)}catch(c){return null}}:U&&(aa=function(b){var c=L(b.anchorNode),d=a.createRange(c);return d.setStartAndEnd(b.anchorNode,b.anchorOffset,b.focusNode,b.focusOffset),d.collapsed!==this.isCollapsed&&d.setStartAndEnd(b.focusNode,b.focusOffset,b.anchorNode,b.anchorOffset),d}),r.prototype=a.selectionPrototype;var ba=[],ca=function(a){if(a&&a instanceof r)return a.refresh(),a;a=d(a,"getNativeSelection");var b=t(a),c=y(a),e=P?f(a):null;return b?(b.nativeSelection=c,b.docSelection=e,b.refresh()):(b=new r(c,e,a),ba.push({win:a,selection:b})),b};a.getSelection=ca,D.createAliasForDeprecatedMethod(a,"getIframeSelection","getSelection");var da=r.prototype;if(!Q&&U&&D.areHostMethods(R,["removeAllRanges","addRange"])){da.removeAllRanges=function(){this.nativeSelection.removeAllRanges(),j(this)};var ea=function(a,b){Z(a.nativeSelection,b),a.refresh()};W?da.addRange=function(b,d){if(_&&P&&this.docSelection.type==K)q(this,b);else if(c(d)&&V)ea(this,b);else{var e;X?e=this.rangeCount:(this.removeAllRanges(),e=0);var f=k(b).cloneRange();try{this.nativeSelection.addRange(f)}catch(g){}if(this.rangeCount=this.nativeSelection.rangeCount,this.rangeCount==e+1){if(a.config.checkSelectionRanges){var i=aa(this.nativeSelection,this.rangeCount-1);i&&!N(i,b)&&(b=new G(i))}this._ranges[this.rangeCount-1]=b,h(this,b,ha(this.nativeSelection)),this.isCollapsed=z(this)}else this.refresh()}}:da.addRange=function(a,b){c(b)&&V?ea(this,a):(this.nativeSelection.addRange(k(a)),this.refresh())},da.setRanges=function(a){if(_&&P&&a.length>1)u(this,a);else{this.removeAllRanges();for(var b=0,c=a.length;c>b;++b)this.addRange(a[b])}}}else{if(!(E(R,"empty")&&E(S,"select")&&_&&Q))return b.fail("No means of selecting a Range or TextRange was found"),!1;da.removeAllRanges=function(){try{if(this.docSelection.empty(),"None"!=this.docSelection.type){var a;if(this.anchorNode)a=L(this.anchorNode);else if(this.docSelection.type==K){var b=this.docSelection.createRange();b.length&&(a=L(b.item(0)))}if(a){var c=M(a).createTextRange();c.select(),this.docSelection.empty()}}}catch(d){}j(this)},da.addRange=function(b){this.docSelection.type==K?q(this,b):(a.WrappedTextRange.rangeToTextRange(b).select(),this._ranges[0]=b,this.rangeCount=1,this.isCollapsed=this._ranges[0].collapsed,h(this,b,!1))},da.setRanges=function(a){this.removeAllRanges();var b=a.length;b>1?u(this,a):b&&this.addRange(a[0])}}da.getRangeAt=function(a){if(0>a||a>=this.rangeCount)throw new H("INDEX_SIZE_ERR");return this._ranges[a].cloneRange()};var fa;if(Q)fa=function(b){var c;a.isSelectionValid(b.win)?c=b.docSelection.createRange():(c=M(b.win.document).createTextRange(),c.collapse(!0)),b.docSelection.type==K?p(b):n(c)?o(b,c):j(b)};else if(E(R,"getRangeAt")&&typeof R.rangeCount==B)fa=function(b){if(_&&P&&b.docSelection.type==K)p(b);else if(b._ranges.length=b.rangeCount=b.nativeSelection.rangeCount,b.rangeCount){for(var c=0,d=b.rangeCount;d>c;++c)b._ranges[c]=new a.WrappedRange(b.nativeSelection.getRangeAt(c));h(b,b._ranges[b.rangeCount-1],ha(b.nativeSelection)),b.isCollapsed=z(b)}else j(b)};else{if(!U||typeof R.isCollapsed!=A||typeof S.collapsed!=A||!J.implementsDomRange)return b.fail("No means of obtaining a Range or TextRange from the user's selection was found"),!1;fa=function(a){var b,c=a.nativeSelection;c.anchorNode?(b=aa(c,0),a._ranges=[b],a.rangeCount=1,i(a),a.isCollapsed=z(a)):j(a)}}da.refresh=function(a){var b=a?this._ranges.slice(0):null,c=this.anchorNode,d=this.anchorOffset;if(fa(this),a){var e=b.length;if(e!=this._ranges.length)return!0;if(this.anchorNode!=c||this.anchorOffset!=d)return!0;for(;e--;)if(!N(b[e],this._ranges[e]))return!0;return!1}};var ga=function(a,b){var c=a.getAllRanges();a.removeAllRanges();for(var d=0,e=c.length;e>d;++d)N(b,c[d])||a.addRange(c[d]);a.rangeCount||j(a)};_&&P?da.removeRange=function(a){if(this.docSelection.type==K){for(var b,c=this.docSelection.createRange(),d=m(a),e=L(c.item(0)),f=M(e).createControlRange(),g=!1,h=0,i=c.length;i>h;++h)b=c.item(h),b!==d||g?f.add(c.item(h)):g=!0;f.select(),p(this)}else ga(this,a)}:da.removeRange=function(a){ga(this,a)};var ha;!Q&&U&&J.implementsDomRange?(ha=g,da.isBackward=function(){return ha(this)}):ha=da.isBackward=function(){return!1},da.isBackwards=da.isBackward,da.toString=function(){for(var a=[],b=0,c=this.rangeCount;c>b;++b)a[b]=""+this._ranges[b];return a.join("")},da.collapse=function(b,c){v(this,b);var d=a.createRange(b);d.collapseToPoint(b,c),this.setSingleRange(d),this.isCollapsed=!0},da.collapseToStart=function(){if(!this.rangeCount)throw new H("INVALID_STATE_ERR");var a=this._ranges[0];this.collapse(a.startContainer,a.startOffset)},da.collapseToEnd=function(){if(!this.rangeCount)throw new H("INVALID_STATE_ERR");var a=this._ranges[this.rangeCount-1];this.collapse(a.endContainer,a.endOffset)},da.selectAllChildren=function(b){v(this,b);var c=a.createRange(b);c.selectNodeContents(b),this.setSingleRange(c)},da.deleteFromDocument=function(){if(_&&P&&this.docSelection.type==K){for(var a,b=this.docSelection.createRange();b.length;)a=b.item(0),b.remove(a),C.removeNode(a);this.refresh()}else if(this.rangeCount){var c=this.getAllRanges();if(c.length){this.removeAllRanges();for(var d=0,e=c.length;e>d;++d)c[d].deleteContents();this.addRange(c[e-1])}}},da.eachRange=function(a,b){for(var c=0,d=this._ranges.length;d>c;++c)if(a(this.getRangeAt(c)))return b},da.getAllRanges=function(){var a=[];return this.eachRange(function(b){a.push(b)}),a},da.setSingleRange=function(a,b){this.removeAllRanges(),this.addRange(a,b)},da.callMethodOnEachRange=function(a,b){var c=[];return this.eachRange(function(d){c.push(d[a].apply(d,b||[]))}),c},da.setStart=w(!0),da.setEnd=w(!1),a.rangePrototype.select=function(a){ca(this.getDocument()).setSingleRange(this,a)},da.changeEachRange=function(a){var b=[],c=this.isBackward();this.eachRange(function(c){a(c),b.push(c)}),this.removeAllRanges(),c&&1==b.length?this.addRange(b[0],"backward"):this.setRanges(b)},da.containsNode=function(a,b){return this.eachRange(function(c){return c.containsNode(a,b)},!0)||!1},da.getBookmark=function(a){return{backward:this.isBackward(),rangeBookmarks:this.callMethodOnEachRange("getBookmark",[a])}},da.moveToBookmark=function(b){for(var c,d,e=[],f=0;c=b.rangeBookmarks[f++];)d=a.createRange(this.win),d.moveToBookmark(c),e.push(d);b.backward?this.setSingleRange(e[0],"backward"):this.setRanges(e)},da.saveRanges=function(){return{backward:this.isBackward(),ranges:this.callMethodOnEachRange("cloneRange")}},da.restoreRanges=function(a){this.removeAllRanges();for(var b,c=0;b=a.ranges[c];++c)this.addRange(b,a.backward&&0==c)},da.toHtml=function(){var a=[];return this.eachRange(function(b){a.push(F.toHtml(b))}),a.join("")},J.implementsTextRange&&(da.getNativeTextRange=function(){var c;if(c=this.docSelection){var d=c.createRange();if(n(d))return d;throw b.createError("getNativeTextRange: selection is a control selection")}if(this.rangeCount>0)return a.WrappedTextRange.rangeToTextRange(this.getRangeAt(0));throw b.createError("getNativeTextRange: selection contains no range")}),da.getName=function(){return"WrappedSelection"},da.inspect=function(){return x(this)},da.detach=function(){t(this.win,"delete"),s(this)},r.detachAll=function(){t(null,"deleteAll")},r.inspect=x,r.isDirectionBackward=c,a.Selection=r,a.selectionPrototype=da,a.addShimListener(function(a){"undefined"==typeof a.getSelection&&(a.getSelection=function(){return ca(a)}),a=null})});var M=!1,N=function(a){M||(M=!0,!H.initialized&&H.config.autoInitialize&&l())};return F&&("complete"==document.readyState?N():(a(document,"addEventListener")&&document.addEventListener("DOMContentLoaded",N,!1),J(window,"load",N))),H},this),function(a,b){"function"==typeof define&&define.amd?define(["./rangy-core"],a):"undefined"!=typeof module&&"object"==typeof exports?module.exports=a(require("rangy")):a(b.rangy)}(function(a){return a.createModule("TextRange",["WrappedSelection"],function(a,b){function c(a,b){function c(a,b,c){h.push({start:a,end:b,isWord:c})}for(var d,e,f,g=a.join(""),h=[],i=0;d=b.wordRegex.exec(g);){if(e=d.index,f=e+d[0].length,e>i&&c(i,e,!1),b.includeTrailingSpace)for(;$.test(a[f]);)++f;c(e,f,!0),i=f}return ie;++e)c[e].token=d;return d}function e(a,b,c){for(var e,f=c(a,b),g=[],h=0;e=f[h++];)g.push(d(a,e));return g}function f(a){var b=a||"",c="string"==typeof b?b.split(""):b;return c.sort(function(a,b){return a.charCodeAt(0)-b.charCodeAt(0)}),c.join("").replace(/(.)\1+/g,"$1")}function g(a){var b,c;return a?(b=a.language||_,c={},U(c,ia[b]||ia[_]),U(c,a),c):ia[_]}function h(a,b){var c=V(a,b);return b.hasOwnProperty("wordOptions")&&(c.wordOptions=g(c.wordOptions)),b.hasOwnProperty("characterOptions")&&(c.characterOptions=V(c.characterOptions,ga)),c}function i(a,b){var c=na(a,"display",b),d=a.tagName.toLowerCase();return"block"==c&&fa&&oa.hasOwnProperty(d)?oa[d]:c}function j(a){for(var b=o(a),c=0,d=b.length;d>c;++c)if(1==b[c].nodeType&&"none"==i(b[c]))return!0;return!1}function k(a){var b;return 3==a.nodeType&&(b=a.parentNode)&&"hidden"==na(b,"visibility")}function l(a){return a&&(1==a.nodeType&&!/^(inline(-block|-table)?|none)$/.test(i(a))||9==a.nodeType||11==a.nodeType)}function m(a){return S.isCharacterDataNode(a)||!/^(area|base|basefont|br|col|frame|hr|img|input|isindex|link|meta|param)$/i.test(a.nodeName)}function n(a){for(var b=[];a.parentNode;)b.unshift(a.parentNode),a=a.parentNode;return b}function o(a){return n(a).concat([a])}function p(a){for(;a&&!a.nextSibling;)a=a.parentNode;return a?a.nextSibling:null}function q(a,b){return!b&&a.hasChildNodes()?a.firstChild:p(a)}function r(a){var b=a.previousSibling;if(b){for(a=b;a.hasChildNodes();)a=a.lastChild;return a}var c=a.parentNode;return c&&1==c.nodeType?c:null}function s(a){if(!a||3!=a.nodeType)return!1;var b=a.data;if(""===b)return!0;var c=a.parentNode;if(!c||1!=c.nodeType)return!1;var d=na(a.parentNode,"whiteSpace");return/^[\t\n\r ]+$/.test(b)&&/^(normal|nowrap)$/.test(d)||/^[\t\r ]+$/.test(b)&&"pre-line"==d}function t(a){if(""===a.data)return!0;if(!s(a))return!1;var b=a.parentNode;return b?j(a)?!0:!1:!0}function u(a){var b=a.nodeType;return 7==b||8==b||j(a)||/^(script|style)$/i.test(a.nodeName)||k(a)||t(a)}function v(a,b){var c=a.nodeType;return 7==c||8==c||1==c&&"none"==i(a,b)}function w(){this.store={}}function x(a,b,c){return function(d){var e=this.cache;if(e.hasOwnProperty(a))return pa++,e[a];qa++;var f=b.call(this,c?this[c]:this,d);return e[a]=f,f}}function y(a,b){this.node=a,this.session=b,this.cache=new w,this.positions=new w}function z(a,b){this.offset=b,this.nodeWrapper=a,this.node=a.node,this.session=a.session,this.cache=new w}function A(){return"[Position("+S.inspectNode(this.node)+":"+this.offset+")]"}function B(){return D(),Da=new Ea}function C(){return Da||B()}function D(){Da&&Da.detach(),Da=null}function E(a,c,d,e){function f(){var a=null;return c?(a=h,i||(h=h.previousVisible(),i=!h||d&&h.equals(d))):i||(a=h=h.nextVisible(),i=!h||d&&h.equals(d)),i&&(h=null),a}d&&(c?u(d.node)&&(d=a.previousVisible()):u(d.node)&&(d=d.nextVisible()));var g,h=a,i=!1,j=!1;return{next:function(){if(j)return j=!1,g;for(var a,b;a=f();)if(b=a.getCharacter(e))return g=a,a;return null},rewind:function(){if(!g)throw b.createError("createCharacterIterator: cannot rewind. Only one position can be rewound.");j=!0},dispose:function(){a=d=null}}}function F(a,b,c){function d(a){for(var b,c,d=[],e=a?f:g,h=!1,i=!1;b=e.next();){if(c=b.character,Z.test(c))i&&(i=!1,h=!0);else{if(h){e.rewind();break}i=!0}d.push(b)}return d}var f=E(a,!1,null,b),g=E(a,!0,null,b),h=c.tokenizer,i=d(!0),j=d(!1).reverse(),k=e(j.concat(i),c,h),l=i.length?k.slice(Fa(k,i[0].token)):[],m=j.length?k.slice(0,Fa(k,j.pop().token)+1):[];return{nextEndToken:function(){for(var a,b;1==l.length&&!(a=l[0]).isWord&&(b=d(!0)).length>0;)l=e(a.chars.concat(b),c,h);return l.shift()},previousStartToken:function(){for(var a,b;1==m.length&&!(a=m[0]).isWord&&(b=d(!1)).length>0;)m=e(b.reverse().concat(a.chars),c,h);return m.pop()},dispose:function(){f.dispose(),g.dispose(),l=m=null}}}function G(a,b,c,d,e){var f,g,h,i,j=0,k=a,l=Math.abs(c);if(0!==c){var m=0>c;switch(b){case Q:for(g=E(a,m,null,d);(f=g.next())&&l>j;)++j,k=f;h=f,g.dispose();break;case R:for(var n=F(a,d,e),o=m?n.previousStartToken:n.nextEndToken;(i=o())&&l>j;)i.isWord&&(++j,k=m?i.chars[0]:i.chars[i.chars.length-1]);break;default:throw new Error("movePositionBy: unit '"+b+"' not implemented")}m?(k=k.previousVisible(),j=-j):k&&k.isLeadingSpace&&!k.isTrailingSpace&&(b==R&&(g=E(a,!1,null,d),h=g.next(),g.dispose()),h&&(k=h.previousVisible()))}return{position:k,unitsMoved:j}}function H(a,b,c,d){var e=a.getRangeBoundaryPosition(b,!0),f=a.getRangeBoundaryPosition(b,!1),g=d?f:e,h=d?e:f;return E(g,!!d,h,c)}function I(a,b,c){for(var d,e=[],f=H(a,b,c);d=f.next();)e.push(d);return f.dispose(),e}function J(b,c,d){var e=a.createRange(b.node);return e.setStartAndEnd(b.node,b.offset,c.node,c.offset),!e.expand("word",{wordOptions:d})}function K(a,b,c,d,e){function f(a,b){var c=p[a].previousVisible(),d=p[b-1],f=!e.wholeWordsOnly||J(c,d,e.wordOptions);return{startPos:c,endPos:d,valid:f}}for(var g,h,i,j,k,l,m=aa(e.direction),n=E(a,m,a.session.getRangeBoundaryPosition(d,m),e.characterOptions),o="",p=[],q=null;g=n.next();)if(h=g.character,c||e.caseSensitive||(h=h.toLowerCase()),m?(p.unshift(g),o=h+o):(p.push(g),o+=h),c){if(k=b.exec(o))if(i=k.index,j=i+k[0].length,l){if(!m&&j0){q=f(i,j);break}}else l=!0}else if(-1!=(i=o.indexOf(b))){q=f(i,i+b.length);break}return l&&(q=f(i,j)),n.dispose(),q}function L(a){return function(){var b=!!Da,c=C(),d=[c].concat(T.toArray(arguments)),e=a.apply(this,d);return b||D(),e}}function M(a,b){return L(function(c,d,e,f){typeof e==P&&(e=d,d=Q),f=h(f,ka);var g=a;b&&(g=e>=0,this.collapse(!g));var i=G(c.getRangeBoundaryPosition(this,g),d,e,f.characterOptions,f.wordOptions),j=i.position;return this[g?"setStart":"setEnd"](j.node,j.offset),i.unitsMoved})}function N(a){return L(function(b,c){c=V(c,ga);for(var d,e=H(b,this,c,!a),f=0;(d=e.next())&&Z.test(d.character);)++f;e.dispose();var g=f>0;return g&&this[a?"moveStart":"moveEnd"]("character",a?f:-f,{characterOptions:c}),g})}function O(a){return L(function(b,c){var d=!1;return this.changeEachRange(function(b){d=b[a](c)||d}),d})}var P="undefined",Q="character",R="word",S=a.dom,T=a.util,U=T.extend,V=T.createOptions,W=S.getBody,X=/^[ \t\f\r\n]+$/,Y=/^[ \t\f\r]+$/,Z=/^[\t-\r \u0085\u00A0\u1680\u180E\u2000-\u200B\u2028\u2029\u202F\u205F\u3000]+$/,$=/^[\t \u00A0\u1680\u180E\u2000-\u200B\u202F\u205F\u3000]+$/,_="en",aa=a.Selection.isDirectionBackward,ba=!1,ca=!1,da=!1,ea=!0;!function(){var b=S.createTestElement(document,"1
",!0),c=b.firstChild,d=a.getSelection();d.collapse(c.lastChild,2),d.setStart(c.firstChild,0),ba=1==(""+d).length,b.innerHTML="1 ",d.collapse(b,2),d.setStart(b.firstChild,0),ca=1==(""+d).length,b.innerHTML="1 1
",d.collapse(b,2),d.setStart(b.firstChild,0),da=1==(""+d).length,S.removeNode(b),d.removeAllRanges()}();var fa,ga={includeBlockContentTrailingSpace:!0,includeSpaceBeforeBr:!0,includeSpaceBeforeBlock:!0,includePreLineTrailingSpace:!0,ignoreCharacters:""},ha={includeBlockContentTrailingSpace:!ea,includeSpaceBeforeBr:!ca,includeSpaceBeforeBlock:!da,includePreLineTrailingSpace:!0},ia={en:{wordRegex:/[a-z0-9]+('[a-z0-9]+)*/gi,includeTrailingSpace:!1,tokenizer:c}},ja={caseSensitive:!1,withinRange:null,wholeWordsOnly:!1,wrap:!1,direction:"forward",wordOptions:null,characterOptions:null},ka={wordOptions:null,characterOptions:null},la={wordOptions:null,characterOptions:null,trim:!1,trimStart:!0,trimEnd:!0},ma={wordOptions:null,characterOptions:null,direction:"forward"},na=S.getComputedStyleProperty;!function(){var a=document.createElement("table"),b=W(document);b.appendChild(a),fa="block"==na(a,"display"),b.removeChild(a)}();var oa={table:"table",caption:"table-caption",colgroup:"table-column-group",col:"table-column",thead:"table-header-group",tbody:"table-row-group",tfoot:"table-footer-group",tr:"table-row",td:"table-cell",th:"table-cell"};w.prototype={get:function(a){return this.store.hasOwnProperty(a)?this.store[a]:null},set:function(a,b){return this.store[a]=b}};var pa=0,qa=0,ra={getPosition:function(a){var b=this.positions;return b.get(a)||b.set(a,new z(this,a))},toString:function(){return"[NodeWrapper("+S.inspectNode(this.node)+")]"}};y.prototype=ra;var sa="EMPTY",ta="NON_SPACE",ua="UNCOLLAPSIBLE_SPACE",va="COLLAPSIBLE_SPACE",wa="TRAILING_SPACE_BEFORE_BLOCK",xa="TRAILING_SPACE_IN_BLOCK",ya="TRAILING_SPACE_BEFORE_BR",za="PRE_LINE_TRAILING_SPACE_BEFORE_LINE_BREAK",Aa="TRAILING_LINE_BREAK_AFTER_BR",Ba="INCLUDED_TRAILING_LINE_BREAK_AFTER_BR";U(ra,{isCharacterDataNode:x("isCharacterDataNode",S.isCharacterDataNode,"node"),getNodeIndex:x("nodeIndex",S.getNodeIndex,"node"),getLength:x("nodeLength",S.getNodeLength,"node"),containsPositions:x("containsPositions",m,"node"),isWhitespace:x("isWhitespace",s,"node"),
-isCollapsedWhitespace:x("isCollapsedWhitespace",t,"node"),getComputedDisplay:x("computedDisplay",i,"node"),isCollapsed:x("collapsed",u,"node"),isIgnored:x("ignored",v,"node"),next:x("nextPos",q,"node"),previous:x("previous",r,"node"),getTextNodeInfo:x("textNodeInfo",function(a){var b=null,c=!1,d=na(a.parentNode,"whiteSpace"),e="pre-line"==d;return e?(b=Y,c=!0):("normal"==d||"nowrap"==d)&&(b=X,c=!0),{node:a,text:a.data,spaceRegex:b,collapseSpaces:c,preLine:e}},"node"),hasInnerText:x("hasInnerText",function(a,b){for(var c=this.session,d=c.getPosition(a.parentNode,this.getNodeIndex()+1),e=c.getPosition(a,0),f=b?d:e,g=b?e:d;f!==g;){if(f.prepopulateChar(),f.isDefinitelyNonEmpty())return!0;f=b?f.previousVisible():f.nextVisible()}return!1},"node"),isRenderedBlock:x("isRenderedBlock",function(a){for(var b=a.getElementsByTagName("br"),c=0,d=b.length;d>c;++c)if(!u(b[c]))return!0;return this.hasInnerText()},"node"),getTrailingSpace:x("trailingSpace",function(a){if("br"==a.tagName.toLowerCase())return"";switch(this.getComputedDisplay()){case"inline":for(var b=a.lastChild;b;){if(!v(b))return 1==b.nodeType?this.session.getNodeWrapper(b).getTrailingSpace():"";b=b.previousSibling}break;case"inline-block":case"inline-table":case"none":case"table-column":case"table-column-group":break;case"table-cell":return" ";default:return this.isRenderedBlock(!0)?"\n":""}return""},"node"),getLeadingSpace:x("leadingSpace",function(a){switch(this.getComputedDisplay()){case"inline":case"inline-block":case"inline-table":case"none":case"table-column":case"table-column-group":case"table-cell":break;default:return this.isRenderedBlock(!1)?"\n":""}return""},"node")});var Ca={character:"",characterType:sa,isBr:!1,prepopulateChar:function(){var a=this;if(!a.prepopulatedChar){var b=a.node,c=a.offset,d="",e=sa,f=!1;if(c>0)if(3==b.nodeType){var g=b.data,h=g.charAt(c-1),i=a.nodeWrapper.getTextNodeInfo(),j=i.spaceRegex;i.collapseSpaces?j.test(h)?c>1&&j.test(g.charAt(c-2))||(i.preLine&&"\n"===g.charAt(c)?(d=" ",e=za):(d=" ",e=va)):(d=h,e=ta,f=!0):(d=h,e=ua,f=!0)}else{var k=b.childNodes[c-1];if(k&&1==k.nodeType&&!u(k)&&("br"==k.tagName.toLowerCase()?(d="\n",a.isBr=!0,e=va,f=!1):a.checkForTrailingSpace=!0),!d){var l=b.childNodes[c];l&&1==l.nodeType&&!u(l)&&(a.checkForLeadingSpace=!0)}}a.prepopulatedChar=!0,a.character=d,a.characterType=e,a.isCharInvariant=f}},isDefinitelyNonEmpty:function(){var a=this.characterType;return a==ta||a==ua},resolveLeadingAndTrailingSpaces:function(){if(this.prepopulatedChar||this.prepopulateChar(),this.checkForTrailingSpace){var a=this.session.getNodeWrapper(this.node.childNodes[this.offset-1]).getTrailingSpace();a&&(this.isTrailingSpace=!0,this.character=a,this.characterType=va),this.checkForTrailingSpace=!1}if(this.checkForLeadingSpace){var b=this.session.getNodeWrapper(this.node.childNodes[this.offset]).getLeadingSpace();b&&(this.isLeadingSpace=!0,this.character=b,this.characterType=va),this.checkForLeadingSpace=!1}},getPrecedingUncollapsedPosition:function(a){for(var b,c=this;c=c.previousVisible();)if(b=c.getCharacter(a),""!==b)return c;return null},getCharacter:function(a){function b(){return n||(k=o.getPrecedingUncollapsedPosition(a),n=!0),k}this.resolveLeadingAndTrailingSpaces();var c,d=this.character,e=f(a.ignoreCharacters),g=""!==d&&e.indexOf(d)>-1;if(this.isCharInvariant)return c=g?"":d;var h=["character",a.includeSpaceBeforeBr,a.includeBlockContentTrailingSpace,a.includePreLineTrailingSpace,e].join("_"),i=this.cache.get(h);if(null!==i)return i;var j,k,l="",m=this.characterType==va,n=!1,o=this;return m&&(this.type==Ba?l="\n":" "==d&&(!b()||k.isTrailingSpace||"\n"==k.character||" "==k.character&&k.characterType==va)||("\n"==d&&this.isLeadingSpace?b()&&"\n"!=k.character&&(l="\n"):(j=this.nextUncollapsed(),j&&(j.isBr?this.type=ya:j.isTrailingSpace&&"\n"==j.character?this.type=xa:j.isLeadingSpace&&"\n"==j.character&&(this.type=wa),"\n"==j.character?(this.type!=ya||a.includeSpaceBeforeBr)&&(this.type!=wa||a.includeSpaceBeforeBlock)&&(this.type==xa&&j.isTrailingSpace&&!a.includeBlockContentTrailingSpace||(this.type!=za||j.type!=ta||a.includePreLineTrailingSpace)&&("\n"==d?j.isTrailingSpace?this.isTrailingSpace||this.isBr&&(j.type=Aa,b()&&k.isLeadingSpace&&!k.isTrailingSpace&&"\n"==k.character?j.character="":j.type=Ba):l="\n":" "==d&&(l=" "))):l=d)))),e.indexOf(l)>-1&&(l=""),this.cache.set(h,l),l},equals:function(a){return!!a&&this.node===a.node&&this.offset===a.offset},inspect:A,toString:function(){return this.character}};z.prototype=Ca,U(Ca,{next:x("nextPos",function(a){var b=a.nodeWrapper,c=a.node,d=a.offset,e=b.session;if(!c)return null;var f,g,h;return d==b.getLength()?(f=c.parentNode,g=f?b.getNodeIndex()+1:0):b.isCharacterDataNode()?(f=c,g=d+1):(h=c.childNodes[d],e.getNodeWrapper(h).containsPositions()?(f=h,g=0):(f=c,g=d+1)),f?e.getPosition(f,g):null}),previous:x("previous",function(a){var b,c,d,e=a.nodeWrapper,f=a.node,g=a.offset,h=e.session;return 0==g?(b=f.parentNode,c=b?e.getNodeIndex():0):e.isCharacterDataNode()?(b=f,c=g-1):(d=f.childNodes[g-1],h.getNodeWrapper(d).containsPositions()?(b=d,c=S.getNodeLength(d)):(b=f,c=g-1)),b?h.getPosition(b,c):null}),nextVisible:x("nextVisible",function(a){var b=a.next();if(!b)return null;var c=b.nodeWrapper,d=b.node,e=b;return c.isCollapsed()&&(e=c.session.getPosition(d.parentNode,c.getNodeIndex()+1)),e}),nextUncollapsed:x("nextUncollapsed",function(a){for(var b=a;b=b.nextVisible();)if(b.resolveLeadingAndTrailingSpaces(),""!==b.character)return b;return null}),previousVisible:x("previousVisible",function(a){var b=a.previous();if(!b)return null;var c=b.nodeWrapper,d=b.node,e=b;return c.isCollapsed()&&(e=c.session.getPosition(d.parentNode,c.getNodeIndex())),e})});var Da=null,Ea=function(){function a(a){var b=new w;return{get:function(c){var d=b.get(c[a]);if(d)for(var e,f=0;e=d[f++];)if(e.node===c)return e;return null},set:function(c){var d=c.node[a],e=b.get(d)||b.set(d,[]);e.push(c)}}}function b(){this.initCaches()}var c=T.isHostProperty(document.documentElement,"uniqueID");return b.prototype={initCaches:function(){this.elementCache=c?function(){var a=new w;return{get:function(b){return a.get(b.uniqueID)},set:function(b){a.set(b.node.uniqueID,b)}}}():a("tagName"),this.textNodeCache=a("data"),this.otherNodeCache=a("nodeName")},getNodeWrapper:function(a){var b;switch(a.nodeType){case 1:b=this.elementCache;break;case 3:b=this.textNodeCache;break;default:b=this.otherNodeCache}var c=b.get(a);return c||(c=new y(a,this),b.set(c)),c},getPosition:function(a,b){return this.getNodeWrapper(a).getPosition(b)},getRangeBoundaryPosition:function(a,b){var c=b?"start":"end";return this.getPosition(a[c+"Container"],a[c+"Offset"])},detach:function(){this.elementCache=this.textNodeCache=this.otherNodeCache=null}},b}();U(S,{nextNode:q,previousNode:r});var Fa=Array.prototype.indexOf?function(a,b){return a.indexOf(b)}:function(a,b){for(var c=0,d=a.length;d>c;++c)if(a[c]===b)return c;return-1};U(a.rangePrototype,{moveStart:M(!0,!1),moveEnd:M(!1,!1),move:M(!0,!0),trimStart:N(!0),trimEnd:N(!1),trim:L(function(a,b){var c=this.trimStart(b),d=this.trimEnd(b);return c||d}),expand:L(function(a,b,c){var d=!1;c=h(c,la);var e=c.characterOptions;if(b||(b=Q),b==R){var f,g,i=c.wordOptions,j=a.getRangeBoundaryPosition(this,!0),k=a.getRangeBoundaryPosition(this,!1),l=F(j,e,i),m=l.nextEndToken(),n=m.chars[0].previousVisible();if(this.collapsed)f=m;else{var o=F(k,e,i);f=o.previousStartToken()}return g=f.chars[f.chars.length-1],n.equals(j)||(this.setStart(n.node,n.offset),d=!0),g&&!g.equals(k)&&(this.setEnd(g.node,g.offset),d=!0),c.trim&&(c.trimStart&&(d=this.trimStart(e)||d),c.trimEnd&&(d=this.trimEnd(e)||d)),d}return this.moveEnd(Q,1,c)}),text:L(function(a,b){return this.collapsed?"":I(a,this,V(b,ga)).join("")}),selectCharacters:L(function(a,b,c,d,e){var f={characterOptions:e};b||(b=W(this.getDocument())),this.selectNodeContents(b),this.collapse(!0),this.moveStart("character",c,f),this.collapse(!0),this.moveEnd("character",d-c,f)}),toCharacterRange:L(function(a,b,c){b||(b=W(this.getDocument()));var d,e,f=b.parentNode,g=S.getNodeIndex(b),h=-1==S.comparePoints(this.startContainer,this.endContainer,f,g),i=this.cloneRange();return h?(i.setStartAndEnd(this.startContainer,this.startOffset,f,g),d=-i.text(c).length):(i.setStartAndEnd(f,g,this.startContainer,this.startOffset),d=i.text(c).length),e=d+this.text(c).length,{start:d,end:e}}),findText:L(function(b,c,d){d=h(d,ja),d.wholeWordsOnly&&(d.wordOptions.includeTrailingSpace=!1);var e=aa(d.direction),f=d.withinRange;f||(f=a.createRange(),f.selectNodeContents(this.getDocument()));var g=c,i=!1;"string"==typeof g?d.caseSensitive||(g=g.toLowerCase()):i=!0;var j=b.getRangeBoundaryPosition(this,!e),k=f.comparePoint(j.node,j.offset);-1===k?j=b.getRangeBoundaryPosition(f,!0):1===k&&(j=b.getRangeBoundaryPosition(f,!1));for(var l,m=j,n=!1;;)if(l=K(m,g,i,f,d)){if(l.valid)return this.setStartAndEnd(l.startPos.node,l.startPos.offset,l.endPos.node,l.endPos.offset),!0;m=e?l.startPos:l.endPos}else{if(!d.wrap||n)return!1;f=f.cloneRange(),m=b.getRangeBoundaryPosition(f,!e),f.setBoundary(j.node,j.offset,e),n=!0}}),pasteHtml:function(a){if(this.deleteContents(),a){var b=this.createContextualFragment(a),c=b.lastChild;this.insertNode(b),this.collapseAfter(c)}}}),U(a.selectionPrototype,{expand:L(function(a,b,c){this.changeEachRange(function(a){a.expand(b,c)})}),move:L(function(a,b,c,d){var e=0;if(this.focusNode){this.collapse(this.focusNode,this.focusOffset);var f=this.getRangeAt(0);d||(d={}),d.characterOptions=V(d.characterOptions,ha),e=f.move(b,c,d),this.setSingleRange(f)}return e}),trimStart:O("trimStart"),trimEnd:O("trimEnd"),trim:O("trim"),selectCharacters:L(function(b,c,d,e,f,g){var h=a.createRange(c);h.selectCharacters(c,d,e,g),this.setSingleRange(h,f)}),saveCharacterRanges:L(function(a,b,c){for(var d=this.getAllRanges(),e=d.length,f=[],g=1==e&&this.isBackward(),h=0,i=d.length;i>h;++h)f[h]={characterRange:d[h].toCharacterRange(b,c),backward:g,characterOptions:c};return f}),restoreCharacterRanges:L(function(b,c,d){this.removeAllRanges();for(var e,f,g,h=0,i=d.length;i>h;++h)f=d[h],g=f.characterRange,e=a.createRange(c),e.selectCharacters(c,g.start,g.end,f.characterOptions),this.addRange(e,f.backward)}),text:L(function(a,b){for(var c=[],d=0,e=this.rangeCount;e>d;++d)c[d]=this.getRangeAt(d).text(b);return c.join("")})}),a.innerText=function(b,c){var d=a.createRange(b);d.selectNodeContents(b);var e=d.text(c);return e},a.createWordIterator=function(a,b,c){var d=C();c=h(c,ma);var e=d.getPosition(a,b),f=F(e,c.characterOptions,c.wordOptions),g=aa(c.direction);return{next:function(){return g?f.previousStartToken():f.nextEndToken()},dispose:function(){f.dispose(),this.next=function(){}}}},a.noMutation=function(a){var b=C();a(b),D()},a.noMutation.createEntryPointFunction=L,a.textRange={isBlockNode:l,isCollapsedWhitespaceNode:t,createPosition:L(function(a,b,c){return a.getPosition(b,c)})}}),a},this),function(a,b){"function"==typeof define&&define.amd?define(["./rangy-core"],a):"undefined"!=typeof module&&"object"==typeof exports?module.exports=a(require("rangy")):a(b.rangy)}(function(a){return a.createModule("SaveRestore",["WrappedRange"],function(a,b){function c(a,b){return(b||document).getElementById(a)}function d(a,b){var c,d="selectionBoundary_"+ +new Date+"_"+(""+Math.random()).slice(2),e=o.getDocument(a.startContainer),f=a.cloneRange();return f.collapse(b),c=e.createElement("span"),c.id=d,c.style.lineHeight="0",c.style.display="none",c.className="rangySelectionBoundary",c.appendChild(e.createTextNode(r)),f.insertNode(c),c}function e(a,d,e,f){var g=c(e,a);g?(d[f?"setStartBefore":"setEndBefore"](g),p(g)):b.warn("Marker element has been removed. Cannot restore selection.")}function f(a,b){return b.compareBoundaryPoints(a.START_TO_START,a)}function g(b,c){var e,f,g=a.DomRange.getRangeDocument(b),h=b.toString(),i=q(c);return b.collapsed?(f=d(b,!1),{document:g,markerId:f.id,collapsed:!0}):(f=d(b,!1),e=d(b,!0),{document:g,startMarkerId:e.id,endMarkerId:f.id,collapsed:!1,backward:i,toString:function(){return"original text: '"+h+"', new text: '"+b.toString()+"'"}})}function h(d,f){var g=d.document;"undefined"==typeof f&&(f=!0);var h=a.createRange(g);if(d.collapsed){var i=c(d.markerId,g);if(i){i.style.display="inline";var j=i.previousSibling;j&&3==j.nodeType?(p(i),h.collapseToPoint(j,j.length)):(h.collapseBefore(i),p(i))}else b.warn("Marker element has been removed. Cannot restore selection.")}else e(g,h,d.startMarkerId,!0),e(g,h,d.endMarkerId,!1);return f&&h.normalizeBoundaries(),h}function i(b,d){var e,h,i=[],j=q(d);b=b.slice(0),b.sort(f);for(var k=0,l=b.length;l>k;++k)i[k]=g(b[k],j);for(k=l-1;k>=0;--k)e=b[k],h=a.DomRange.getRangeDocument(e),e.collapsed?e.collapseAfter(c(i[k].markerId,h)):(e.setEndBefore(c(i[k].endMarkerId,h)),e.setStartAfter(c(i[k].startMarkerId,h)));return i}function j(c){if(!a.isSelectionValid(c))return b.warn("Cannot save selection. This usually happens when the selection is collapsed and the selection document has lost focus."),null;var d=a.getSelection(c),e=d.getAllRanges(),f=1==e.length&&d.isBackward(),g=i(e,f);return f?d.setSingleRange(e[0],f):d.setRanges(e),{win:c,rangeInfos:g,restored:!1}}function k(a){for(var b=[],c=a.length,d=c-1;d>=0;d--)b[d]=h(a[d],!0);return b}function l(b,c){if(!b.restored){var d=b.rangeInfos,e=a.getSelection(b.win),f=k(d),g=d.length;1==g&&c&&a.features.selectionHasExtend&&d[0].backward?(e.removeAllRanges(),e.addRange(f[0],!0)):e.setRanges(f),b.restored=!0}}function m(a,b){var d=c(b,a);d&&p(d)}function n(a){for(var b,c=a.rangeInfos,d=0,e=c.length;e>d;++d)b=c[d],b.collapsed?m(a.doc,b.markerId):(m(a.doc,b.startMarkerId),m(a.doc,b.endMarkerId))}var o=a.dom,p=o.removeNode,q=a.Selection.isDirectionBackward,r="\ufeff";a.util.extend(a,{saveRange:g,restoreRange:h,saveRanges:i,restoreRanges:k,saveSelection:j,restoreSelection:l,removeMarkerElement:m,removeMarkers:n})}),a},this);var Base=function(){};Base.extend=function(a,b){var c=Base.prototype.extend;Base._prototyping=!0;var d=new this;c.call(d,a),d.base=function(){},delete Base._prototyping;var e=d.constructor,f=d.constructor=function(){if(!Base._prototyping)if(this._constructing||this.constructor==f)this._constructing=!0,e.apply(this,arguments),delete this._constructing;else if(null!=arguments[0])return(arguments[0].extend||c).call(arguments[0],d)};return f.ancestor=this,f.extend=this.extend,f.forEach=this.forEach,f.implement=this.implement,f.prototype=d,f.toString=this.toString,f.valueOf=function(a){return"object"==a?f:e.valueOf()},c.call(f,b),"function"==typeof f.init&&f.init(),f},Base.prototype={extend:function(a,b){if(arguments.length>1){var c=this[a];if(c&&"function"==typeof b&&(!c.valueOf||c.valueOf()!=b.valueOf())&&/\bbase\b/.test(b)){var d=b.valueOf();b=function(){var a=this.base||Base.prototype.base;this.base=c;var b=d.apply(this,arguments);return this.base=a,b},b.valueOf=function(a){return"object"==a?b:d},b.toString=Base.toString}this[a]=b}else if(a){var e=Base.prototype.extend;Base._prototyping||"function"==typeof this||(e=this.extend||e);for(var f={toSource:null},g=["constructor","toString","valueOf"],h=Base._prototyping?0:1;i=g[h++];)a[i]!=f[i]&&e.call(this,i,a[i]);for(var i in a)f[i]||e.call(this,i,a[i])}return this}},Base=Base.extend({constructor:function(){this.extend(arguments[0])}},{ancestor:Object,version:"1.1",forEach:function(a,b,c){for(var d in a)void 0===this.prototype[d]&&b.call(c,a[d],d,a)},implement:function(){for(var a=0;a-1?c=new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})"):/Edge\/(\d+)./i.test(navigator.userAgent)&&(c=/Edge\/(\d+)./i)),c&&null!=c.exec(navigator.userAgent)&&(d=parseFloat(RegExp.$1)),-1===d?!1:a?b?"<"===b?d>a:">"===b?a>d:"<="===b?d>=a:">="===b?a>=d:void 0:a===d:!0}var d=navigator.userAgent,e=document.createElement("div"),f=-1!==d.indexOf("Gecko")&&-1===d.indexOf("KHTML")&&!c(),g=-1!==d.indexOf("AppleWebKit/")&&!c(),h=-1!==d.indexOf("Chrome/")&&!c(),i=-1!==d.indexOf("Opera/")&&!c();return{USER_AGENT:d,supported:function(){var c=this.USER_AGENT.toLowerCase(),d="contentEditable"in e,f=document.execCommand&&document.queryCommandSupported&&document.queryCommandState,g=document.querySelector&&document.querySelectorAll,h=this.isIos()&&a(c)<5||this.isAndroid()&&b(c)<4||-1!==c.indexOf("opera mobi")||-1!==c.indexOf("hpwos/");return d&&f&&g&&!h},isTouchDevice:function(){return this.supportsEvent("touchmove")},isIos:function(){return/ipad|iphone|ipod/i.test(this.USER_AGENT)},isAndroid:function(){return-1!==this.USER_AGENT.indexOf("Android")},supportsSandboxedIframes:function(){return c()},throwsMixedContentWarningWhenIframeSrcIsEmpty:function(){return!("querySelector"in document)},displaysCaretInEmptyContentEditableCorrectly:function(){return c(12,">")},hasCurrentStyleProperty:function(){return"currentStyle"in e},insertsLineBreaksOnReturn:function(){return f},supportsPlaceholderAttributeOn:function(a){return"placeholder"in a},supportsEvent:function(a){return"on"+a in e||function(){return e.setAttribute("on"+a,"return;"),"function"==typeof e["on"+a]}()},supportsEventsInIframeCorrectly:function(){return!i},supportsHTML5Tags:function(a){var b=a.createElement("div"),c="foo ";return b.innerHTML=c,b.innerHTML.toLowerCase()===c},supportsCommand:function(){var a={formatBlock:c(10,"<="),insertUnorderedList:c(),insertOrderedList:c()},b={insertHTML:f};return function(c,d){var e=a[d];if(!e){try{return c.queryCommandSupported(d)}catch(f){}try{return c.queryCommandEnabled(d)}catch(g){return!!b[d]}}return!1}}(),doesAutoLinkingInContentEditable:function(){return c()},canDisableAutoLinking:function(){return this.supportsCommand(document,"AutoUrlDetect")},clearsContentEditableCorrectly:function(){return f||i||g},supportsGetAttributeCorrectly:function(){var a=document.createElement("td");return"1"!=a.getAttribute("rowspan")},canSelectImagesInContentEditable:function(){return f||c()||i},autoScrollsToCaret:function(){return!g},autoClosesUnclosedTags:function(){var a,b,c=e.cloneNode(!1);return c.innerHTML="
",b=c.innerHTML.toLowerCase(),a="
"===b||"
"===b,this.autoClosesUnclosedTags=function(){return a},a},supportsNativeGetElementsByClassName:function(){return-1!==String(document.getElementsByClassName).indexOf("[native code]")},supportsSelectionModify:function(){return"getSelection"in window&&"modify"in window.getSelection()},needsSpaceAfterLineBreak:function(){return i},supportsSpeechApiOn:function(a){var b=d.match(/Chrome\/(\d+)/)||[void 0,0];return b[1]>=11&&("onwebkitspeechchange"in a||"speech"in a)},crashesWhenDefineProperty:function(a){return c(9)&&("XMLHttpRequest"===a||"XDomainRequest"===a)},doesAsyncFocus:function(){return c(12,">")},hasProblemsSettingCaretAfterImg:function(){return c()},hasLiDeletingProblem:function(){return c()},hasUndoInContextMenu:function(){return f||h||i},hasInsertNodeIssue:function(){return i},hasIframeFocusIssue:function(){return c()},createsNestedInvalidMarkupAfterPaste:function(){return g},hasCaretBlockElementIssue:function(){return g},supportsMutationEvents:function(){return"MutationEvent"in window},supportsModernPaste:function(){return!c()},fixStyleKey:function(a){return"cssFloat"===a?"styleFloat"in document.createElement("div").style?"styleFloat":"cssFloat":a},usesControlRanges:function(){return document.body&&"createControlRange"in document.body}}}(),wysihtml5.lang.array=function(a){return{contains:function(b){if(Array.isArray(b)){for(var c=b.length;c--;)if(-1!==wysihtml5.lang.array(a).indexOf(b[c]))return!0;return!1}return-1!==wysihtml5.lang.array(a).indexOf(b)},indexOf:function(b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},without:function(b){b=wysihtml5.lang.array(b);for(var c=[],d=0,e=a.length;e>d;d++)b.contains(a[d])||c.push(a[d]);return c},get:function(){for(var b=0,c=a.length,d=[];c>b;b++)d.push(a[b]);return d},map:function(b,c){if(Array.prototype.map)return a.map(b,c);for(var d=a.length>>>0,e=new Array(d),f=0;d>f;f++)e[f]=b.call(c,a[f],f,a);return e},unique:function(){for(var b=[],c=a.length,d=0;c>d;)wysihtml5.lang.array(b).contains(a[d])||b.push(a[d]),d++;return b}}},wysihtml5.lang.Dispatcher=Base.extend({on:function(a,b){return this.events=this.events||{},this.events[a]=this.events[a]||[],this.events[a].push(b),this},off:function(a,b){this.events=this.events||{};var c,d,e=0;if(a){for(c=this.events[a]||[],d=[];e\t"]/g,d={"&":"&","<":"<",">":">",'"':"""," ":" "};wysihtml5.lang.string=function(e){return e=String(e),{trim:function(){return e.replace(a,"").replace(b,"")},interpolate:function(a){for(var b in a)e=this.replace("#{"+b+"}").by(a[b]);return e},replace:function(a){return{by:function(b){return e.split(a).join(b)}}},escapeHTML:function(a,b){var f=e.replace(c,function(a){return d[a]});return a&&(f=f.replace(/(?:\r\n|\r|\n)/g," ")),b&&(f=f.replace(/ /gi," ")),f}}}}(),function(a){function b(a,b){return f(a,b)?a:(a===a.ownerDocument.documentElement&&(a=a.ownerDocument.body),g(a,b))}function c(a){return a.replace(i,function(a,b){var c=(b.match(j)||[])[1]||"",d=l[c];b=b.replace(j,""),b.split(d).length>b.split(c).length&&(b+=c,c="");var e=b,f=b;return b.length>k&&(f=f.substr(0,k)+"..."),"www."===e.substr(0,4)&&(e="http://"+e),''+f+" "+c})}function d(a){var b=a._wysihtml5_tempElement;return b||(b=a._wysihtml5_tempElement=a.createElement("div")),b}function e(b){var e=b.parentNode,f=a.lang.string(b.data).escapeHTML(),g=d(e.ownerDocument);for(g.innerHTML=" "+c(f),g.removeChild(g.firstChild);g.firstChild;)e.insertBefore(g.firstChild,b);e.removeChild(b)}function f(b,c){for(var d;b.parentNode;){if(b=b.parentNode,d=b.nodeName,b.className&&a.lang.array(b.className.split(" ")).contains(c))return!0;if(h.contains(d))return!0;if("body"===d)return!1}return!1}function g(b,c){if(!(h.contains(b.nodeName)||b.className&&a.lang.array(b.className.split(" ")).contains(c))){if(b.nodeType===a.TEXT_NODE&&b.data.match(i))return void e(b);for(var d=a.lang.array(b.childNodes).get(),f=d.length,j=0;f>j;j++)g(d[j],c);return b}}var h=a.lang.array(["CODE","PRE","A","SCRIPT","HEAD","TITLE","STYLE"]),i=/((https?:\/\/|www\.)[^\s<]{3,})/gi,j=/([^\w\/\-](,?))$/i,k=100,l={")":"(","]":"[","}":"{"};a.dom.autoLink=b,a.dom.autoLink.URL_REG_EXP=i}(wysihtml5),function(a){var b=a.dom;b.addClass=function(a,c){var d=a.classList;return d?d.add(c):void(b.hasClass(a,c)||(a.className+=" "+c))},b.removeClass=function(a,b){var c=a.classList;return c?c.remove(b):void(a.className=a.className.replace(new RegExp("(^|\\s+)"+b+"(\\s+|$)")," "))},b.hasClass=function(a,b){var c=a.classList;if(c)return c.contains(b);var d=a.className;return d.length>0&&(d==b||new RegExp("(^|\\s)"+b+"(\\s|$)").test(d))}}(wysihtml5),wysihtml5.dom.contains=function(){var a=document.documentElement;return a.contains?function(a,b){if(b.nodeType!==wysihtml5.ELEMENT_NODE){if(b.parentNode===a)return!0;b=b.parentNode}return a!==b&&a.contains(b)}:a.compareDocumentPosition?function(a,b){return!!(16&a.compareDocumentPosition(b))}:void 0}(),wysihtml5.dom.convertToList=function(){function a(a,b){var c=a.createElement("li");return b.appendChild(c),c}function b(a,b){return a.createElement(b)}function c(c,d,e){if("UL"===c.nodeName||"OL"===c.nodeName||"MENU"===c.nodeName)return c;var f,g,h,i,j,k,l,m,n,o=c.ownerDocument,p=b(o,d),q=c.querySelectorAll("br"),r=q.length;for(n=0;r>n;n++)for(i=q[n];(j=i.parentNode)&&j!==c&&j.lastChild===i;){if("block"===wysihtml5.dom.getStyle("display").from(j)){j.removeChild(i);break}wysihtml5.dom.insert(i).after(i.parentNode)}for(f=wysihtml5.lang.array(c.childNodes).get(),g=f.length,n=0;g>n;n++)m=m||a(o,p),h=f[n],k="block"===wysihtml5.dom.getStyle("display").from(h),l="BR"===h.nodeName,!k||e&&wysihtml5.dom.hasClass(h,e)?l?m=m.firstChild?null:m:m.appendChild(h):(m=m.firstChild?a(o,p):m,m.appendChild(h),m=null);return 0===f.length&&a(o,p),c.parentNode.replaceChild(p,c),p}return c}(),wysihtml5.dom.copyAttributes=function(a){return{from:function(b){return{to:function(c){for(var d,e=0,f=a.length;f>e;e++)d=a[e],"undefined"!=typeof b[d]&&""!==b[d]&&(c[d]=b[d]);return{andTo:arguments.callee}}}}}},function(a){var b=["-webkit-box-sizing","-moz-box-sizing","-ms-box-sizing","box-sizing"],c=function(b){return d(b)?parseInt(a.getStyle("width").from(b),10)d;d++)if("border-box"===a.getStyle(b[d]).from(c))return b[d]};a.copyStyles=function(d){return{from:function(e){c(e)&&(d=wysihtml5.lang.array(d).without(b));for(var f,g="",h=d.length,i=0;h>i;i++)f=d[i],g+=f+":"+a.getStyle(f).from(e)+";";return{to:function(b){return a.setStyles(g).on(b),{andTo:arguments.callee}}}}}}}(wysihtml5.dom),function(a){a.dom.delegate=function(a,b,c,d){var e=function(c){for(var e=c.target,f=3===e.nodeType?e.parentNode:e,g=a.querySelectorAll(b),h=0,i=g.length;i>h;h++)g[h].contains(f)&&d.call(g[h],c)};return a.addEventListener(c,e,!1),{stop:function(){a.removeEventListener(c,e,!1)}}}}(wysihtml5),function(a){function b(a,b){for(var c=[a],d=a;b&&d&&d!==b||!b&&d;)c.unshift(d),d=d.parentNode;return c}a.dom.domNode=function(c){var d=[a.ELEMENT_NODE,a.TEXT_NODE];return{is:{emptyTextNode:function(b){var d=b?/^\s*$/g:/^[\r\n]*$/g;return c&&c.nodeType===a.TEXT_NODE&&d.test(c.data)},rangyBookmark:function(){return c&&1===c.nodeType&&c.classList.contains("rangySelectionBoundary")},visible:function(){var b=!/^\s*$/g.test(a.dom.getTextContent(c));return b||1===c.nodeType&&c.querySelector("img, br, hr, object, embed, canvas, input, textarea")&&(b=!0),b},lineBreak:function(){return c&&1===c.nodeType&&"BR"===c.nodeName},block:function(){return c&&1===c.nodeType&&"block"===c.ownerDocument.defaultView.getComputedStyle(c).display},voidElement:function(){return a.dom.domNode(c).test({query:a.VOID_ELEMENTS})}},prev:function(b){var e=c.previousSibling,f=b&&b.nodeTypes?b.nodeTypes:d;return e?a.dom.domNode(e).is.rangyBookmark()||!a.lang.array(f).contains(e.nodeType)||b&&b.ignoreBlankTexts&&a.dom.domNode(e).is.emptyTextNode(!0)?a.dom.domNode(e).prev(b):e:null},next:function(b){var e=c.nextSibling,f=b&&b.nodeTypes?b.nodeTypes:d;return e?a.dom.domNode(e).is.rangyBookmark()||!a.lang.array(f).contains(e.nodeType)||b&&b.ignoreBlankTexts&&a.dom.domNode(e).is.emptyTextNode(!0)?a.dom.domNode(e).next(b):e:null},commonAncestor:function(a,d){var e=b(c,d),f=b(a,d);if(e[0]!=f[0])return null;for(var g=0;g0)for(var f=!1,g=Array.isArray(b.styleProperty)?b.styleProperty:[b.styleProperty],h=0,i=g.length;i>h;h++){if(d=a.browser.fixStyleKey(g[h]),c.style[d]){if(!b.styleValue){f=!0;break}if(b.styleValue instanceof RegExp){if(c.style[d].trim().match(b.styleValue).length>0){f=!0;break}}else if(Array.isArray(b.styleValue)){if(b.styleValue.indexOf(c.style[d].trim())){f=!0;break}}else if(b.styleValue===c.style[d].trim().replace(/, /g,",")){f=!0;break}}if(!f)return!1}if(b.attribute){var j=a.dom.getAttributes(c),k=[],l=!1;Array.isArray(b.attribute)?k=b.attribute:k[b.attribute]=b.attributeValue;for(var m in k)if(k.hasOwnProperty(m))if("undefined"==typeof k[m]){if("undefined"!=typeof j[m]){l=!0;break}}else if(j[m]===k[m]){l=!0;break}if(!l)return!1}return!0}}}}(wysihtml5),wysihtml5.dom.getAsDom=function(){var a=function(a,b){var c=b.createElement("div");c.style.display="none",b.body.appendChild(c);try{c.innerHTML=a}catch(d){}return b.body.removeChild(c),c},b=function(a){if(!a._wysihtml5_supportsHTML5Tags){for(var b=0,d=c.length;d>b;b++)a.createElement(c[b]);a._wysihtml5_supportsHTML5Tags=!0}},c=["abbr","article","aside","audio","bdi","canvas","command","datalist","details","figcaption","figure","footer","header","hgroup","keygen","mark","meter","nav","output","progress","rp","rt","ruby","svg","section","source","summary","time","track","video","wbr"];return function(c,d){d=d||document;var e;return"object"==typeof c&&c.nodeType?(e=d.createElement("div"),e.appendChild(c)):wysihtml5.browser.supportsHTML5Tags(d)?(e=d.createElement("div"),e.innerHTML=c):(b(d),e=a(c,d)),e}}(),wysihtml5.dom.getParentElement=function(){return function(a,b,c,d){
-for(c=c||50;c--&&a&&"BODY"!==a.nodeName&&(!d||a!==d);){if(wysihtml5.dom.domNode(a).test(b))return a;a=a.parentNode}return null}}(),wysihtml5.dom.getStyle=function(){function a(a){return a.replace(c,function(a){return a.charAt(1).toUpperCase()})}var b={"float":"styleFloat"in document.createElement("div").style?"styleFloat":"cssFloat"},c=/\-[a-z]/g;return function(c){return{from:function(d){if(d.nodeType===wysihtml5.ELEMENT_NODE){var e=d.ownerDocument,f=b[c]||a(c),g=d.style,h=d.currentStyle,i=g[f];if(i)return i;if(h)try{return h[f]}catch(j){}var k,l,m=e.defaultView||e.parentWindow,n=("height"===c||"width"===c)&&"TEXTAREA"===d.nodeName;return m.getComputedStyle?(n&&(k=g.overflow,g.overflow="hidden"),l=m.getComputedStyle(d,null).getPropertyValue(c),n&&(g.overflow=k||""),l):void 0}}}}}(),wysihtml5.dom.getTextNodes=function(a,b){var c=[];for(a=a.firstChild;a;a=a.nextSibling)3==a.nodeType?b&&/^\s*$/.test(a.innerText||a.textContent)||c.push(a):c=c.concat(wysihtml5.dom.getTextNodes(a,b));return c},wysihtml5.dom.hasElementWithTagName=function(){function a(a){return a._wysihtml5_identifier||(a._wysihtml5_identifier=c++)}var b={},c=1;return function(c,d){var e=a(c)+":"+d,f=b[e];return f||(f=b[e]=c.getElementsByTagName(d)),f.length>0}}(),function(a){function b(a){return a._wysihtml5_identifier||(a._wysihtml5_identifier=d++)}var c={},d=1;a.dom.hasElementWithClassName=function(d,e){if(!a.browser.supportsNativeGetElementsByClassName())return!!d.querySelector("."+e);var f=b(d)+":"+e,g=c[f];return g||(g=c[f]=d.getElementsByClassName(e)),g.length>0}}(wysihtml5),wysihtml5.dom.insert=function(a){return{after:function(b){b.parentNode.insertBefore(a,b.nextSibling)},before:function(b){b.parentNode.insertBefore(a,b)},into:function(b){b.appendChild(a)}}},wysihtml5.dom.insertCSS=function(a){return a=a.join("\n"),{into:function(b){var c=b.createElement("style");c.type="text/css",c.styleSheet?c.styleSheet.cssText=a:c.appendChild(b.createTextNode(a));var d=b.querySelector("head link");if(d)return void d.parentNode.insertBefore(c,d);var e=b.querySelector("head");e&&e.appendChild(c)}}},function(a){a.dom.lineBreaks=function(b){function c(a){return"BR"===a.nodeName}function d(b){return c(b)?!0:"block"===a.dom.getStyle("display").from(b)?!0:!1}return{add:function(c){var e=b.ownerDocument,f=a.dom.domNode(b).next({ignoreBlankTexts:!0}),g=a.dom.domNode(b).prev({ignoreBlankTexts:!0});f&&!d(f)&&a.dom.insert(e.createElement("br")).after(b),g&&!d(g)&&a.dom.insert(e.createElement("br")).before(b)},remove:function(d){var e=a.dom.domNode(b).next({ignoreBlankTexts:!0}),f=a.dom.domNode(b).prev({ignoreBlankTexts:!0});e&&c(e)&&e.parentNode.removeChild(e),f&&c(f)&&f.parentNode.removeChild(f)}}}}(wysihtml5),wysihtml5.dom.observe=function(a,b,c){b="string"==typeof b?[b]:b;for(var d,e,f=0,g=b.length;g>f;f++)e=b[f],a.addEventListener?a.addEventListener(e,c,!1):(d=function(b){"target"in b||(b.target=b.srcElement),b.preventDefault=b.preventDefault||function(){this.returnValue=!1},b.stopPropagation=b.stopPropagation||function(){this.cancelBubble=!0},c.call(a,b)},a.attachEvent("on"+e,d));return{stop:function(){for(var e,f=0,g=b.length;g>f;f++)e=b[f],a.removeEventListener?a.removeEventListener(e,c,!1):a.detachEvent("on"+e,d)}}},wysihtml5.dom.parse=function(a,b){function c(a,b){wysihtml5.lang.object(t).merge(s).merge(b.rules).get();var c,f,g,h=b.context||a.ownerDocument||document,i=h.createDocumentFragment(),j="string"==typeof a,k=!1;for(b.clearInternals===!0&&(k=!0),c=j?wysihtml5.dom.getAsDom(a,h):a,t.selectors&&e(c,t.selectors);c.firstChild;)g=c.firstChild,f=d(g,b.cleanUp,k,b.uneditableClass),f&&i.appendChild(f),g!==f&&c.removeChild(g);if(b.unjoinNbsps)for(var l=wysihtml5.dom.getTextNodes(i),m=l.length;m--;)l[m].nodeValue=l[m].nodeValue.replace(/([\S\u00A0])\u00A0/gi,"$1 ");return c.innerHTML="",c.appendChild(i),j?wysihtml5.quirks.getCorrectInnerHTML(c):c}function d(a,b,c,e){var f,g,h,i,j=a.nodeType,k=a.childNodes,l=k.length,m=p[j],n=0;if(e&&1===j&&wysihtml5.dom.hasClass(a,e))return a;if(g=m&&m(a,c),!g){if(g===!1){for(f=a.ownerDocument.createDocumentFragment(),n=l;n--;)k[n]&&(h=d(k[n],b,c,e),h&&(k[n]===h&&n--,f.insertBefore(h,f.firstChild)));return i=wysihtml5.dom.getStyle("display").from(a),""===i&&(i=wysihtml5.lang.array(u).contains(a.tagName)?"block":""),wysihtml5.lang.array(["block","flex","table"]).contains(i)&&f.appendChild(a.ownerDocument.createElement("br")),wysihtml5.lang.array(["div","pre","p","table","td","th","ul","ol","li","dd","dl","footer","header","section","h1","h2","h3","h4","h5","h6"]).contains(a.nodeName.toLowerCase())&&a.parentNode.lastChild!==a&&(a.nextSibling&&3===a.nextSibling.nodeType&&/^\s/.test(a.nextSibling.nodeValue)||f.appendChild(a.ownerDocument.createTextNode(" "))),f.normalize&&f.normalize(),f}return null}for(n=0;l>n;n++)k[n]&&(h=d(k[n],b,c,e),h&&(k[n]===h&&n--,g.appendChild(h)));if(b&&g.nodeName.toLowerCase()===q&&(!g.childNodes.length||/^\s*$/gi.test(g.innerHTML)&&(c||"_wysihtml5-temp-placeholder"!==a.className&&"rangySelectionBoundary"!==a.className)||!g.attributes.length)){for(f=g.ownerDocument.createDocumentFragment();g.firstChild;)f.appendChild(g.firstChild);return f.normalize&&f.normalize(),f}return g.normalize&&g.normalize(),g}function e(a,b){var c,d,e;for(c in b)if(b.hasOwnProperty(c)){wysihtml5.lang.object(b[c]).isFunction()?d=b[c]:"string"==typeof b[c]&&z[b[c]]&&(d=z[b[c]]),e=a.querySelectorAll(c);for(var f=e.length;f--;)d(e[f])}}function f(a,b){var c,d,e,f=t.tags,h=a.nodeName.toLowerCase(),j=a.scopeName;if(a._wysihtml5)return null;if(a._wysihtml5=1,"wysihtml5-temp"===a.className)return null;if(j&&"HTML"!=j&&(h=j+":"+h),"outerHTML"in a&&(wysihtml5.browser.autoClosesUnclosedTags()||"P"!==a.nodeName||""===a.outerHTML.slice(-4).toLowerCase()||(h="div")),h in f){if(c=f[h],!c||c.remove)return null;if(c.unwrap)return!1;c="string"==typeof c?{rename_tag:c}:c}else{if(!a.firstChild)return null;c={rename_tag:q}}if(c.one_of_type&&!g(a,t,c.one_of_type,b)){if(!c.remove_action)return null;if("unwrap"===c.remove_action)return!1;if("rename"!==c.remove_action)return null;e=c.remove_action_rename_to||q}return d=a.ownerDocument.createElement(e||c.rename_tag||h),m(a,d,c,b),i(a,d,c),a=null,d.normalize&&d.normalize(),d}function g(a,b,c,d){var e,f;if("SPAN"===a.nodeName&&!d&&("_wysihtml5-temp-placeholder"===a.className||"rangySelectionBoundary"===a.className))return!0;for(f in c)if(c.hasOwnProperty(f)&&b.type_definitions&&b.type_definitions[f]&&(e=b.type_definitions[f],h(a,e)))return!0;return!1}function h(a,b){var c,d,e,f,g,h=a.getAttribute("class"),i=a.getAttribute("style");if(b.methods)for(var j in b.methods)if(b.methods.hasOwnProperty(j)&&y[j]&&y[j](a))return!0;if(h&&b.classes){h=h.replace(/^\s+/g,"").replace(/\s+$/g,"").split(r),c=h.length;for(var k=0;c>k;k++)if(b.classes[h[k]])return!0}if(i&&b.styles){i=i.split(";");for(d in b.styles)if(b.styles.hasOwnProperty(d))for(var l=i.length;l--;)if(g=i[l].split(":"),g[0].replace(/\s/g,"").toLowerCase()===d&&(b.styles[d]===!0||1===b.styles[d]||wysihtml5.lang.array(b.styles[d]).contains(g[1].replace(/\s/g,"").toLowerCase())))return!0}if(b.attrs)for(e in b.attrs)if(b.attrs.hasOwnProperty(e)&&(f=wysihtml5.dom.getAttribute(a,e),"string"==typeof f&&f.search(b.attrs[e])>-1))return!0;return!1}function i(a,b,c){var d,e;if(c&&c.keep_styles)for(d in c.keep_styles)if(c.keep_styles.hasOwnProperty(d)){if(e="float"===d?a.style.styleFloat||a.style.cssFloat:a.style[d],c.keep_styles[d]instanceof RegExp&&!c.keep_styles[d].test(e))continue;"float"===d?b.style[a.style.styleFloat?"styleFloat":"cssFloat"]=e:a.style[d]&&(b.style[d]=e)}}function j(a,b){var c=[];for(var d in b)b.hasOwnProperty(d)&&0===d.indexOf(a)&&c.push(d);return c}function k(a,b,c,d){var e,f=wysihtml5.lang.object(c).isFunction()?c:v[c];return f&&(e=f(b,d),"string"==typeof e)?e:!1}function l(a,b){var c,d,e,f=wysihtml5.lang.object(t.attributes||{}).clone(),g=wysihtml5.lang.object(f).merge(wysihtml5.lang.object(b||{}).clone()).get(),h={},i=wysihtml5.dom.getAttributes(a);for(c in g)if(/\*$/.test(c)){e=j(c.slice(0,-1),i);for(var l=0,m=e.length;m>l;l++)d=k(e[l],i[e[l]],g[c],a.nodeName),d!==!1&&(h[e[l]]=d)}else d=k(c,i[c],g[c],a.nodeName),d!==!1&&(h[c]=d);return h}function m(a,b,c,d){var e,f,g,h,i,j={},k=c.set_class,m=c.add_class,n=c.add_style,o=c.set_attributes,p=t.classes,q=0,s=[],u=[],v=[],y=[];if(o&&(j=wysihtml5.lang.object(o).clone()),j=wysihtml5.lang.object(j).merge(l(a,c.check_attributes)).get(),k&&s.push(k),m)for(h in m)i=x[m[h]],i&&(g=i(wysihtml5.dom.getAttribute(a,h)),"string"==typeof g&&s.push(g));if(n)for(h in n)i=w[n[h]],i&&(newStyle=i(wysihtml5.dom.getAttribute(a,h)),"string"==typeof newStyle&&u.push(newStyle));if("string"==typeof p&&"any"===p)if(a.getAttribute("class"))if(t.classes_blacklist){for(y=a.getAttribute("class"),y&&(s=s.concat(y.split(r))),e=s.length;e>q;q++)f=s[q],t.classes_blacklist[f]||v.push(f);v.length&&(j["class"]=wysihtml5.lang.array(v).unique().join(" "))}else j["class"]=a.getAttribute("class");else s&&s.length>0&&(j["class"]=wysihtml5.lang.array(s).unique().join(" "));else{for(d||(p["_wysihtml5-temp-placeholder"]=1,p._rangySelectionBoundary=1,p["wysiwyg-tmp-selected-cell"]=1),y=a.getAttribute("class"),y&&(s=s.concat(y.split(r))),e=s.length;e>q;q++)f=s[q],p[f]&&v.push(f);v.length&&(j["class"]=wysihtml5.lang.array(v).unique().join(" "))}j["class"]&&d&&(j["class"]=j["class"].replace("wysiwyg-tmp-selected-cell",""),/^\s*$/g.test(j["class"])&&delete j["class"]),u.length&&(j.style=wysihtml5.lang.array(u).unique().join(" "));for(h in j)try{b.setAttribute(h,j[h])}catch(z){}j.src&&("undefined"!=typeof j.width&&b.setAttribute("width",j.width),"undefined"!=typeof j.height&&b.setAttribute("height",j.height))}function n(a){var b=a.nextSibling;if(!b||b.nodeType!==wysihtml5.TEXT_NODE){var c=a.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"");return a.ownerDocument.createTextNode(c)}b.data=a.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"")+b.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"")}function o(a){return t.comments?a.ownerDocument.createComment(a.nodeValue):void 0}var p={1:f,3:n,8:o},q="span",r=/\s+/,s={tags:{},classes:{}},t={},u=["ADDRESS","BLOCKQUOTE","CENTER","DIR","DIV","DL","FIELDSET","FORM","H1","H2","H3","H4","H5","H6","ISINDEX","MENU","NOFRAMES","NOSCRIPT","OL","P","PRE","TABLE","UL"],v={url:function(){var a=/^https?:\/\//i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),src:function(){var a=/^(\/|https?:\/\/)/i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),href:function(){var a=/^(#|\/|https?:\/\/|mailto:|tel:)/i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),alt:function(){var a=/[^ a-z0-9_\-]/gi;return function(b,c){return b?b.replace(a,""):"IMG"===c?"":null}}(),numbers:function(){var a=/\D/g;return function(b){return b=(b||"").replace(a,""),b||null}}(),dimension:function(){var a=/\D*(\d+)(\.\d+)?\s?(%)?\D*/;return function(b){return b=(b||"").replace(a,"$1$2$3"),b||null}}(),any:function(){return function(a){return a?a:null}}()},w={align_text:function(){var a={left:"text-align: left;",right:"text-align: right;",center:"text-align: center;"};return function(b){return a[String(b).toLowerCase()]}}()},x={align_img:function(){var a={left:"wysiwyg-float-left",right:"wysiwyg-float-right"};return function(b){return a[String(b).toLowerCase()]}}(),align_text:function(){var a={left:"wysiwyg-text-align-left",right:"wysiwyg-text-align-right",center:"wysiwyg-text-align-center",justify:"wysiwyg-text-align-justify"};return function(b){return a[String(b).toLowerCase()]}}(),clear_br:function(){var a={left:"wysiwyg-clear-left",right:"wysiwyg-clear-right",both:"wysiwyg-clear-both",all:"wysiwyg-clear-both"};return function(b){return a[String(b).toLowerCase()]}}(),size_font:function(){var a={1:"wysiwyg-font-size-xx-small",2:"wysiwyg-font-size-small",3:"wysiwyg-font-size-medium",4:"wysiwyg-font-size-large",5:"wysiwyg-font-size-x-large",6:"wysiwyg-font-size-xx-large",7:"wysiwyg-font-size-xx-large","-":"wysiwyg-font-size-smaller","+":"wysiwyg-font-size-larger"};return function(b){return a[String(b).charAt(0)]}}()},y={has_visible_contet:function(){var a,b=["img","video","picture","br","script","noscript","style","table","iframe","object","embed","audio","svg","input","button","select","textarea","canvas"];return function(c){if(a=(c.innerText||c.textContent).replace(/\s/g,""),a&&a.length>0)return!0;for(var d=b.length;d--;)if(c.querySelector(b[d]))return!0;return c.offsetWidth&&c.offsetWidth>0&&c.offsetHeight&&c.offsetHeight>0?!0:!1}}()},z={unwrap:function(a){wysihtml5.dom.unwrap(a)},remove:function(a){a.parentNode.removeChild(a)}};return c(a,b)},wysihtml5.dom.removeEmptyTextNodes=function(a){for(var b,c=wysihtml5.lang.array(a.childNodes).get(),d=c.length,e=0;d>e;e++)b=c[e],b.nodeType===wysihtml5.TEXT_NODE&&/^[\n\r]*$/.test(b.data)&&b.parentNode.removeChild(b)},wysihtml5.dom.renameElement=function(a,b){for(var c,d=a.ownerDocument.createElement(b);c=a.firstChild;)d.appendChild(c);return wysihtml5.dom.copyAttributes(["align","className"]).from(a).to(d),a.parentNode&&a.parentNode.replaceChild(d,a),d},wysihtml5.dom.replaceWithChildNodes=function(a){if(a.parentNode){for(;a.firstChild;)a.parentNode.insertBefore(a.firstChild,a);a.parentNode.removeChild(a)}},function(a){function b(b){return"block"===a.getStyle("display").from(b)}function c(a){return"BR"===a.nodeName}function d(a){var b=a.ownerDocument.createElement("br");a.appendChild(b)}function e(a,e){if(a.nodeName.match(/^(MENU|UL|OL)$/)){var f,g,h,i,j,k,l,m=a.ownerDocument,n=m.createDocumentFragment(),o=wysihtml5.dom.domNode(a).prev({ignoreBlankTexts:!0}),p=wysihtml5.dom.domNode(a).next({ignoreBlankTexts:!0}),q=a.lastElementChild||a.lastChild;if(e)for(!o||b(o)||c(o)||d(n);k=a.firstElementChild||a.firstChild;){for(g=k.lastChild,l=k===q;f=k.firstChild;)h=f===g,i=(!l||p&&!b(p))&&h&&!b(f)&&!c(f),n.appendChild(f),i&&d(n);k.parentNode.removeChild(k)}else for(;k=a.firstElementChild||a.firstChild;){if(k.querySelector&&k.querySelector("div, p, ul, ol, menu, blockquote, h1, h2, h3, h4, h5, h6"))for(;f=k.firstChild;)n.appendChild(f);else{for(j=m.createElement("p");f=k.firstChild;)j.appendChild(f);n.appendChild(j)}k.parentNode.removeChild(k)}a.parentNode.replaceChild(n,a)}}a.resolveList=e}(wysihtml5.dom),function(a){var b=document,c=["parent","top","opener","frameElement","frames","localStorage","globalStorage","sessionStorage","indexedDB"],d=["open","close","openDialog","showModalDialog","alert","confirm","prompt","openDatabase","postMessage","XMLHttpRequest","XDomainRequest"],e=["referrer","write","open","close"];a.dom.Sandbox=Base.extend({constructor:function(b,c){this.callback=b||a.EMPTY_FUNCTION,this.config=a.lang.object({}).merge(c).get(),this.config.className||(this.config.className="wysihtml5-sandbox"),this.editableArea=this._createIframe()},insertInto:function(a){"string"==typeof a&&(a=b.getElementById(a)),a.appendChild(this.editableArea)},getIframe:function(){return this.editableArea},getWindow:function(){this._readyError()},getDocument:function(){this._readyError()},destroy:function(){var a=this.getIframe();a.parentNode.removeChild(a)},_readyError:function(){throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet")},_createIframe:function(){var c=this,d=b.createElement("iframe");return d.className=this.config.className,a.dom.setAttributes({security:"restricted",allowtransparency:"true",frameborder:0,width:0,height:0,marginwidth:0,marginheight:0}).on(d),a.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()&&(d.src="javascript:''"),d.onload=function(){d.onreadystatechange=d.onload=null,c._onLoadIframe(d)},d.onreadystatechange=function(){/loaded|complete/.test(d.readyState)&&(d.onreadystatechange=d.onload=null,c._onLoadIframe(d))},d},_onLoadIframe:function(f){if(a.dom.contains(b.documentElement,f)){var g=this,h=f.contentWindow,i=f.contentWindow.document,j=b.characterSet||b.charset||"utf-8",k=this._getHtml({charset:j,stylesheets:this.config.stylesheets});if(i.open("text/html","replace"),i.write(k),i.close(),this.getWindow=function(){return f.contentWindow},this.getDocument=function(){return f.contentWindow.document},h.onerror=function(a,b,c){throw new Error("wysihtml5.Sandbox: "+a,b,c)},!a.browser.supportsSandboxedIframes()){var l,m;for(l=0,m=c.length;m>l;l++)this._unset(h,c[l]);for(l=0,m=d.length;m>l;l++)this._unset(h,d[l],a.EMPTY_FUNCTION);for(l=0,m=e.length;m>l;l++)this._unset(i,e[l]);this._unset(i,"cookie","",!0)}a.polyfills&&a.polyfills(h,i),this.loaded=!0,setTimeout(function(){g.callback(g)},0)}},_getHtml:function(b){var c,d=b.stylesheets,e="",f=0;if(d="string"==typeof d?[d]:d)for(c=d.length;c>f;f++)e+=' ';return b.stylesheets=e,a.lang.string(' #{stylesheets}').interpolate(b)},_unset:function(b,c,d,e){try{b[c]=d}catch(f){}try{b.__defineGetter__(c,function(){return d})}catch(f){}if(e)try{b.__defineSetter__(c,function(){})}catch(f){}if(!a.browser.crashesWhenDefineProperty(c))try{var g={get:function(){return d}};e&&(g.set=function(){}),Object.defineProperty(b,c,g)}catch(f){}}})}(wysihtml5),function(a){var b=document;a.dom.ContentEditableArea=Base.extend({getContentEditable:function(){return this.element},getWindow:function(){return this.element.ownerDocument.defaultView||this.element.ownerDocument.parentWindow},getDocument:function(){return this.element.ownerDocument},constructor:function(b,c,d){this.callback=b||a.EMPTY_FUNCTION,this.config=a.lang.object({}).merge(c).get(),this.config.className||(this.config.className="wysihtml5-sandbox"),d?this.element=this._bindElement(d):this.element=this._createElement()},destroy:function(){},_createElement:function(){var a=b.createElement("div");return a.className=this.config.className,this._loadElement(a),a},_bindElement:function(a){return a.className=a.className?a.className+" wysihtml5-sandbox":"wysihtml5-sandbox",this._loadElement(a,!0),a},_loadElement:function(a,b){var c=this;if(!b){var d=this._getHtml();a.innerHTML=d}this.loaded=!0,setTimeout(function(){c.callback(c)},0)},_getHtml:function(a){return""}})}(wysihtml5),function(){var a={className:"class"};wysihtml5.dom.setAttributes=function(b){return{on:function(c){for(var d in b)c.setAttribute(a[d]||d,b[d])}}}}(),wysihtml5.dom.setStyles=function(a){return{on:function(b){var c=b.style;if("string"==typeof a)return void(c.cssText+=";"+a);for(var d in a)"float"===d?(c.cssFloat=a[d],c.styleFloat=a[d]):c[d]=a[d]}}},function(a){a.simulatePlaceholder=function(b,c,d,e){var f=e||"wysihtml5-placeholder",g=function(){var b=c.element.offsetWidth>0&&c.element.offsetHeight>0;c.hasPlaceholderSet()&&(c.clear(),c.element.focus(),b&&setTimeout(function(){var a=c.selection.getSelection();a.focusNode&&a.anchorNode||c.selection.selectNode(c.element.firstChild||c.element)},0)),c.placeholderSet=!1,a.removeClass(c.element,f)},h=function(){c.isEmpty()&&!c.placeholderSet&&(c.placeholderSet=!0,c.setValue(d,!1),a.addClass(c.element,f))};b.on("set_placeholder",h).on("unset_placeholder",g).on("focus:composer",g).on("paste:composer",g).on("blur:composer",h),h()}}(wysihtml5.dom),function(a){var b=document.documentElement;"textContent"in b?(a.setTextContent=function(a,b){a.textContent=b},a.getTextContent=function(a){return a.textContent}):"innerText"in b?(a.setTextContent=function(a,b){a.innerText=b},a.getTextContent=function(a){return a.innerText}):(a.setTextContent=function(a,b){a.nodeValue=b},a.getTextContent=function(a){return a.nodeValue})}(wysihtml5.dom),wysihtml5.dom.getAttribute=function(a,b){var c=!wysihtml5.browser.supportsGetAttributeCorrectly();b=b.toLowerCase();var d=a.nodeName;if("IMG"==d&&"src"==b&&wysihtml5.dom.isLoadedImage(a)===!0)return a.src;if(c&&"outerHTML"in a){var e=a.outerHTML.toLowerCase(),f=-1!=e.indexOf(" "+b+"=");return f?a.getAttribute(b):null}return a.getAttribute(b)},wysihtml5.dom.getAttributes=function(a){var b,c=!wysihtml5.browser.supportsGetAttributeCorrectly(),d=a.nodeName,e=[];for(b in a.attributes)(a.attributes.hasOwnProperty&&a.attributes.hasOwnProperty(b)||!a.attributes.hasOwnProperty&&Object.prototype.hasOwnProperty.call(a.attributes,b))&&a.attributes[b].specified&&("IMG"==d&&"src"==a.attributes[b].name.toLowerCase()&&wysihtml5.dom.isLoadedImage(a)===!0?e.src=a.src:wysihtml5.lang.array(["rowspan","colspan"]).contains(a.attributes[b].name.toLowerCase())&&c?1!==a.attributes[b].value&&(e[a.attributes[b].name]=a.attributes[b].value):e[a.attributes[b].name]=a.attributes[b].value);return e},wysihtml5.dom.isLoadedImage=function(a){try{return a.complete&&!a.mozMatchesSelector(":-moz-broken")}catch(b){if(a.complete&&"complete"===a.readyState)return!0}},function(a){function b(a,b){for(var c,d=[],e=0,f=a.length;f>e;e++)if(c=a[e].querySelectorAll(b))for(var g=c.length;g--;d.unshift(c[g]));return d}function d(a){a.parentNode.removeChild(a)}function e(a,b){a.parentNode.insertBefore(b,a.nextSibling)}function f(a,b){for(var c=a.nextSibling;1!=c.nodeType;)if(c=c.nextSibling,!b||b==c.tagName.toLowerCase())return c;return null}var g=a.dom,h=function(a){this.el=a,this.isColspan=!1,this.isRowspan=!1,this.firstCol=!0,this.lastCol=!0,this.firstRow=!0,this.lastRow=!0,this.isReal=!0,this.spanCollection=[],this.modified=!1},i=function(a,b){a?(this.cell=a,this.table=g.getParentElement(a,{query:"table"})):b&&(this.table=b,this.cell=this.table.querySelectorAll("th, td")[0])};i.prototype={addSpannedCellToMap:function(a,b,c,d,e,f){for(var g=[],i=c+(f?parseInt(f,10)-1:0),j=d+(e?parseInt(e,10)-1:0),k=c;i>=k;k++){"undefined"==typeof b[k]&&(b[k]=[]);for(var l=d;j>=l;l++)b[k][l]=new h(a),b[k][l].isColspan=e&&parseInt(e,10)>1,b[k][l].isRowspan=f&&parseInt(f,10)>1,b[k][l].firstCol=l==d,b[k][l].lastCol=l==j,b[k][l].firstRow=k==c,b[k][l].lastRow=k==i,b[k][l].isReal=l==d&&k==c,b[k][l].spanCollection=g,g.push(b[k][l])}},setCellAsModified:function(a){if(a.modified=!0,a.spanCollection.length>0)for(var b=0,c=a.spanCollection.length;c>b;b++)a.spanCollection[b].modified=!0},setTableMap:function(){var a,b,c,d,e,f,i,j,k=[],l=this.getTableRows();for(a=0;a0?a.lang.array(f).without(e):f;return g},getTableRows:function(){var c=this.table.querySelectorAll("table"),d=c?b(c,"tr"):[],e=this.table.querySelectorAll("tr"),f=d.length>0?a.lang.array(e).without(d):e;return f},getMapIndex:function(a){for(var b=this.map.length,c=this.map&&this.map[0]?this.map[0].length:0,d=0;b>d;d++)for(var e=0;c>e;e++)if(this.map[d][e].el===a)return{row:d,col:e};return!1},getElementAtIndex:function(a){return this.setTableMap(),this.map[a.row]&&this.map[a.row][a.col]&&this.map[a.row][a.col].el?this.map[a.row][a.col].el:null},getMapElsTo:function(a){var b=[];if(this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(a),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var c=this.idx_start;this.idx_start=this.idx_end,this.idx_end=c}if(this.idx_start.col>this.idx_end.col){var d=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=d}if(null!=this.idx_start&&null!=this.idx_end)for(var e=this.idx_start.row,f=this.idx_end.row;f>=e;e++)for(var g=this.idx_start.col,h=this.idx_end.col;h>=g;g++)b.push(this.map[e][g].el);return b},orderSelectionEnds:function(a){if(this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(a),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var b=this.idx_start;this.idx_start=this.idx_end,this.idx_end=b}if(this.idx_start.col>this.idx_end.col){var c=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=c}return{start:this.map[this.idx_start.row][this.idx_start.col].el,end:this.map[this.idx_end.row][this.idx_end.col].el}},createCells:function(a,b,c){for(var d,e=this.table.ownerDocument,f=e.createDocumentFragment(),g=0;b>g;g++){if(d=e.createElement(a),c)for(var h in c)c.hasOwnProperty(h)&&d.setAttribute(h,c[h]);d.appendChild(document.createTextNode("Â ")),f.appendChild(d)}return f},correctColIndexForUnreals:function(a,b){for(var c=this.map[b],d=-1,e=0;a>e;e++)c[e].isReal&&d++;return d},getLastNewCellOnRow:function(a,b){for(var c,d,e=this.getRowCells(a),f=0,g=e.length;g>f;f++)if(c=e[f],d=this.getMapIndex(c),d===!1||"undefined"!=typeof b&&d.row!=b)return c;return null},removeEmptyTable:function(){var a=this.table.querySelectorAll("td, th");return a&&0!=a.length?!1:(d(this.table),!0)},splitRowToCells:function(a){if(a.isColspan){var b=parseInt(g.getAttribute(a.el,"colspan")||1,10),c=a.el.tagName.toLowerCase();if(b>1){var d=this.createCells(c,b-1);e(a.el,d)}a.el.removeAttribute("colspan")}},getRealRowEl:function(a,b){var c=null,d=null;b=b||this.idx;for(var e=0,f=this.map[b.row].length;f>e;e++)if(d=this.map[b.row][e],d.isReal&&(c=g.getParentElement(d.el,{query:"tr"})))return c;return null===c&&a&&(c=g.getParentElement(this.map[b.row][b.col].el,{query:"tr"})||null),c},injectRowAt:function(a,b,c,d,f){var h=this.getRealRowEl(!1,{row:a,col:b}),i=this.createCells(d,c);if(h){var j=this.correctColIndexForUnreals(b,a);j>=0?e(this.getRowCells(h)[j],i):h.insertBefore(i,h.firstChild)}else{var k=this.table.ownerDocument.createElement("tr");k.appendChild(i),e(g.getParentElement(f.el,{query:"tr"}),k)}},canMerge:function(a){if(this.to=a,this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(this.to),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var b=this.idx_start;this.idx_start=this.idx_end,this.idx_end=b}if(this.idx_start.col>this.idx_end.col){var c=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=c}for(var d=this.idx_start.row,e=this.idx_end.row;e>=d;d++)for(var f=this.idx_start.col,g=this.idx_end.col;g>=f;f++)if(this.map[d][f].isColspan||this.map[d][f].isRowspan)return!1;return!0},decreaseCellSpan:function(a,b){var c=parseInt(g.getAttribute(a.el,b),10)-1;c>=1?a.el.setAttribute(b,c):(a.el.removeAttribute(b),"colspan"==b&&(a.isColspan=!1),"rowspan"==b&&(a.isRowspan=!1),a.firstCol=!0,a.lastCol=!0,a.firstRow=!0,a.lastRow=!0,a.isReal=!0)},removeSurplusLines:function(){var a,b,c,e,f,h,i;if(this.setTableMap(),this.map){for(c=0,e=this.map.length;e>c;c++){for(a=this.map[c],i=!0,f=0,h=a.length;h>f;f++)if(b=a[f],!(g.getAttribute(b.el,"rowspan")&&parseInt(g.getAttribute(b.el,"rowspan"),10)>1&&b.firstRow!==!0)){i=!1;break}if(i)for(f=0;h>f;f++)this.decreaseCellSpan(a[f],"rowspan")}var j=this.getTableRows();for(c=0,e=j.length;e>c;c++)a=j[c],0==a.childNodes.length&&/^\s*$/.test(a.textContent||a.innerText)&&d(a)}},fillMissingCells:function(){var a=0,b=0,c=null;if(this.setTableMap(),this.map){a=this.map.length;for(var d=0;a>d;d++)this.map[d].length>b&&(b=this.map[d].length);for(var f=0;a>f;f++)for(var g=0;b>g;g++)this.map[f]&&!this.map[f][g]&&g>0&&(this.map[f][g]=new h(this.createCells("td",1)),c=this.map[f][g-1],c&&c.el&&c.el.parent&&e(this.map[f][g-1].el,this.map[f][g].el))}},rectify:function(){return this.removeEmptyTable()?!1:(this.removeSurplusLines(),this.fillMissingCells(),!0)},unmerge:function(){if(this.rectify()&&(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx)){var a=this.map[this.idx.row][this.idx.col],b=g.getAttribute(a.el,"colspan")?parseInt(g.getAttribute(a.el,"colspan"),10):1,c=a.el.tagName.toLowerCase();if(a.isRowspan){var d=parseInt(g.getAttribute(a.el,"rowspan"),10);if(d>1)for(var e=1,f=d-1;f>=e;e++)this.injectRowAt(this.idx.row+e,this.idx.col,b,c,a);a.el.removeAttribute("rowspan")}this.splitRowToCells(a)}},merge:function(a){if(this.rectify())if(this.canMerge(a)){for(var b=this.idx_end.row-this.idx_start.row+1,c=this.idx_end.col-this.idx_start.col+1,e=this.idx_start.row,f=this.idx_end.row;f>=e;e++)for(var g=this.idx_start.col,h=this.idx_end.col;h>=g;g++)e==this.idx_start.row&&g==this.idx_start.col?(b>1&&this.map[e][g].el.setAttribute("rowspan",b),c>1&&this.map[e][g].el.setAttribute("colspan",c)):(/^\s* \s*$/.test(this.map[e][g].el.innerHTML.toLowerCase())||(this.map[this.idx_start.row][this.idx_start.col].el.innerHTML+=" "+this.map[e][g].el.innerHTML),d(this.map[e][g].el));this.rectify()}else window.console&&console.log("Do not know how to merge allready merged cells.")},collapseCellToNextRow:function(a){var b=this.getMapIndex(a.el),c=b.row+1,d={row:c,col:b.col};if(c=0)e(this.getRowCells(f)[h],a.el);else{var i=this.getLastNewCellOnRow(f,c);null!==i?e(i,a.el):f.insertBefore(a.el,f.firstChild)}parseInt(g.getAttribute(a.el,"rowspan"),10)>2?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)-1):a.el.removeAttribute("rowspan")}}},removeRowCell:function(a){a.isReal?a.isRowspan?this.collapseCellToNextRow(a):d(a.el):parseInt(g.getAttribute(a.el,"rowspan"),10)>2?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)-1):a.el.removeAttribute("rowspan")},getRowElementsByCell:function(){var a=[];if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=this.map[this.idx.row],c=0,d=b.length;d>c;c++)b[c].isReal&&a.push(b[c].el);return a},getColumnElementsByCell:function(){var a=[];if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=0,c=this.map.length;c>b;b++)this.map[b][this.idx.col]&&this.map[b][this.idx.col].isReal&&a.push(this.map[b][this.idx.col].el);return a},removeRow:function(){var a=g.getParentElement(this.cell,{query:"tr"});if(a){if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=this.map[this.idx.row],c=0,e=b.length;e>c;c++)b[c].modified||(this.setCellAsModified(b[c]),this.removeRowCell(b[c]));d(a)}},removeColCell:function(a){a.isColspan?parseInt(g.getAttribute(a.el,"colspan"),10)>2?a.el.setAttribute("colspan",parseInt(g.getAttribute(a.el,"colspan"),10)-1):a.el.removeAttribute("colspan"):a.isReal&&d(a.el)},removeColumn:function(){if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var a=0,b=this.map.length;b>a;a++)this.map[a][this.idx.col].modified||(this.setCellAsModified(this.map[a][this.idx.col]),this.removeColCell(this.map[a][this.idx.col]))},remove:function(a){if(this.rectify()){switch(a){case"row":this.removeRow();break;case"column":this.removeColumn()}this.rectify()}},addRow:function(a){var b=this.table.ownerDocument;if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),"below"==a&&g.getAttribute(this.cell,"rowspan")&&(this.idx.row=this.idx.row+parseInt(g.getAttribute(this.cell,"rowspan"),10)-1),this.idx!==!1){for(var c=this.map[this.idx.row],d=b.createElement("tr"),f=0,h=c.length;h>f;f++)c[f].modified||(this.setCellAsModified(c[f]),this.addRowCell(c[f],d,a));switch(a){case"below":e(this.getRealRowEl(!0),d);break;case"above":var i=g.getParentElement(this.map[this.idx.row][this.idx.col].el,{query:"tr"});i&&i.parentNode.insertBefore(d,i)}}},addRowCell:function(a,b,d){var e=a.isColspan?{colspan:g.getAttribute(a.el,"colspan")}:null;a.isReal?"above"!=d&&a.isRowspan?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)+1):b.appendChild(this.createCells("td",1,e)):"above"!=d&&a.isRowspan&&a.lastRow?b.appendChild(this.createCells("td",1,e)):c.isRowspan&&a.el.attr("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)+1)},add:function(a){this.rectify()&&(("below"==a||"above"==a)&&this.addRow(a),("before"==a||"after"==a)&&this.addColumn(a))},addColCell:function(a,b,d){
-var f,h=a.el.tagName.toLowerCase();switch(d){case"before":f=!a.isColspan||a.firstCol;break;case"after":f=!a.isColspan||a.lastCol||a.isColspan&&c.el==this.cell}if(f){switch(d){case"before":a.el.parentNode.insertBefore(this.createCells(h,1),a.el);break;case"after":e(a.el,this.createCells(h,1))}a.isRowspan&&this.handleCellAddWithRowspan(a,b+1,d)}else a.el.setAttribute("colspan",parseInt(g.getAttribute(a.el,"colspan"),10)+1)},addColumn:function(a){var b,c;if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),"after"==a&&g.getAttribute(this.cell,"colspan")&&(this.idx.col=this.idx.col+parseInt(g.getAttribute(this.cell,"colspan"),10)-1),this.idx!==!1)for(var d=0,e=this.map.length;e>d;d++)b=this.map[d],b[this.idx.col]&&(c=b[this.idx.col],c.modified||(this.setCellAsModified(c),this.addColCell(c,d,a)))},handleCellAddWithRowspan:function(a,b,c){for(var d,h,i,j=parseInt(g.getAttribute(this.cell,"rowspan"),10)-1,k=g.getParentElement(a.el,{query:"tr"}),l=a.el.tagName.toLowerCase(),m=this.table.ownerDocument,n=0;j>n;n++)if(d=this.correctColIndexForUnreals(this.idx.col,b+n),k=f(k,"tr"))if(d>0)switch(c){case"before":h=this.getRowCells(k),d>0&&this.map[b+n][this.idx.col].el!=h[d]&&d==h.length-1?e(h[d],this.createCells(l,1)):h[d].parentNode.insertBefore(this.createCells(l,1),h[d]);break;case"after":e(this.getRowCells(k)[d],this.createCells(l,1))}else k.insertBefore(this.createCells(l,1),k.firstChild);else i=m.createElement("tr"),i.appendChild(this.createCells(l,1)),this.table.appendChild(i)}},g.table={getCellsBetween:function(a,b){var c=new i(a);return c.getMapElsTo(b)},addCells:function(a,b){var c=new i(a);c.add(b)},removeCells:function(a,b){var c=new i(a);c.remove(b)},mergeCellsBetween:function(a,b){var c=new i(a);c.merge(b)},unmergeCell:function(a){var b=new i(a);b.unmerge()},orderSelectionEnds:function(a,b){var c=new i(a);return c.orderSelectionEnds(b)},indexOf:function(a){var b=new i(a);return b.setTableMap(),b.getMapIndex(a)},findCell:function(a,b){var c=new i(null,a);return c.getElementAtIndex(b)},findRowByCell:function(a){var b=new i(a);return b.getRowElementsByCell()},findColumnByCell:function(a){var b=new i(a);return b.getColumnElementsByCell()},canMerge:function(a,b){var c=new i(a);return c.canMerge(b)}}}(wysihtml5),wysihtml5.dom.query=function(a,b){var c,d=[];a.nodeType&&(a=[a]);for(var e=0,f=a.length;f>e;e++)if(c=a[e].querySelectorAll(b))for(var g=c.length;g--;d.unshift(c[g]));return d},wysihtml5.dom.compareDocumentPosition=function(){var a=document.documentElement;return a.compareDocumentPosition?function(a,b){return a.compareDocumentPosition(b)}:function(a,b){var c,d;if(c=9===a.nodeType?a:a.ownerDocument,d=9===b.nodeType?b:b.ownerDocument,a===b)return 0;if(a===b.ownerDocument)return 20;if(a.ownerDocument===b)return 10;if(c!==d)return 1;if(2===a.nodeType&&a.childNodes&&-1!==wysihtml5.lang.array(a.childNodes).indexOf(b))return 20;if(2===b.nodeType&&b.childNodes&&-1!==wysihtml5.lang.array(b.childNodes).indexOf(a))return 10;for(var e=a,f=[],g=null;e;){if(e==b)return 10;f.push(e),e=e.parentNode}for(e=b,g=null;e;){if(e==a)return 20;var h=wysihtml5.lang.array(f).indexOf(e);if(-1!==h){var i=f[h],j=wysihtml5.lang.array(i.childNodes).indexOf(f[h-1]),k=wysihtml5.lang.array(i.childNodes).indexOf(g);return j>k?2:4}g=e,e=e.parentNode}return 1}}(),wysihtml5.dom.unwrap=function(a){var b=[];if(a.parentNode){for(;a.lastChild;)b.unshift(a.lastChild),wysihtml5.dom.insert(a.lastChild).after(a);a.parentNode.removeChild(a)}return b},wysihtml5.dom.getPastedHtml=function(a){var b;return wysihtml5.browser.supportsModernPaste()&&a.clipboardData&&(wysihtml5.lang.array(a.clipboardData.types).contains("text/html")?b=a.clipboardData.getData("text/html"):wysihtml5.lang.array(a.clipboardData.types).contains("text/plain")&&(b=wysihtml5.lang.string(a.clipboardData.getData("text/plain")).escapeHTML(!0,!0))),b},wysihtml5.dom.getPastedHtmlWithDiv=function(a,b){var c=a.selection.getBookmark(),d=a.element.ownerDocument,e=d.createElement("DIV"),f=a.getScrollPos();d.body.appendChild(e),e.style.width="1px",e.style.height="1px",e.style.overflow="hidden",e.style.position="absolute",e.style.top=f.y+"px",e.style.left=f.x+"px",e.setAttribute("contenteditable","true"),e.focus(),setTimeout(function(){var d;a.selection.setBookmark(c),d=e.innerHTML,d&&/^ $/i.test(d.trim())&&(d=!1),b(d),e.parentNode.removeChild(e)},0)},wysihtml5.dom.removeInvisibleSpaces=function(a){for(var b=wysihtml5.dom.getTextNodes(a),c=b.length;c--;)b[c].nodeValue=b[c].nodeValue.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"")},wysihtml5.quirks.cleanPastedHTML=function(){var a=function(a){var b=wysihtml5.lang.string(a).trim(),c=b.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");return new RegExp("^((?!^"+c+"$).)*$","i")},b=function(b,c){var d,e,f=wysihtml5.lang.object(b).clone(!0);for(d in f.tags)if(f.tags.hasOwnProperty(d)&&f.tags[d].keep_styles)for(e in f.tags[d].keep_styles)f.tags[d].keep_styles.hasOwnProperty(e)&&c[e]&&(f.tags[d].keep_styles[e]=a(c[e]));return f},c=function(a,b){var c;if(!a)return null;for(var d=0,e=a.length;e>d;d++)if(a[d].condition||(c=a[d].set),a[d].condition&&a[d].condition.test(b))return a[d].set;return c};return function(a,d){var e,f={color:wysihtml5.dom.getStyle("color").from(d.referenceNode),fontSize:wysihtml5.dom.getStyle("font-size").from(d.referenceNode)},g=b(c(d.rules,a)||{},f);return e=wysihtml5.dom.parse(a,{rules:g,cleanUp:!0,context:d.referenceNode.ownerDocument,uneditableClass:d.uneditableClass,clearInternals:!0,unjoinNbsps:!0})}}(),wysihtml5.quirks.ensureProperClearing=function(){var a=function(){var a=this;setTimeout(function(){var b=a.innerHTML.toLowerCase();("
"==b||"
"==b)&&(a.innerHTML="")},0)};return function(b){wysihtml5.dom.observe(b.element,["cut","keydown"],a)}}(),function(a){var b="%7E";a.quirks.getCorrectInnerHTML=function(c){var d=c.innerHTML;if(-1===d.indexOf(b))return d;var e,f,g,h,i=c.querySelectorAll("[href*='~'], [src*='~']");for(h=0,g=i.length;g>h;h++)e=i[h].href||i[h].src,f=a.lang.string(e).replace("~").by(b),d=a.lang.string(d).replace(f).by(e);return d}}(wysihtml5),function(a){var b="wysihtml5-quirks-redraw";a.quirks.redraw=function(c){a.dom.addClass(c,b),a.dom.removeClass(c,b);try{var d=c.ownerDocument;d.execCommand("italic",!1,null),d.execCommand("italic",!1,null)}catch(e){}}}(wysihtml5),wysihtml5.quirks.tableCellsSelection=function(a,b){function c(){return a.addEventListener("mousedown",n),l}function d(c){l.start=c,l.end=c,l.cells=[c],l.table=k.getParentElement(l.start,{query:"table"},!1,a),l.table&&(e(),k.addClass(c,m),a.addEventListener("mousemove",g),a.addEventListener("mouseup",h),b.fire("tableselectstart").fire("tableselectstart:composer"))}function e(){if(a){var b=a.querySelectorAll("."+m);if(b.length>0)for(var c=0;c1&&b.composer.selection.deselect(),f(l.cells),l.end!==d&&b.fire("tableselectchange").fire("tableselectchange:composer")))}function h(c){a.removeEventListener("mousemove",g),a.removeEventListener("mouseup",h),b.fire("tableselect").fire("tableselect:composer"),setTimeout(function(){i()},0)}function i(){a.ownerDocument.addEventListener("click",o)}function j(c,d){l.start=c,l.end=d,l.table=k.getParentElement(l.start,{query:"table"},!1,a),selectedCells=k.table.getCellsBetween(l.start,l.end),f(selectedCells),i(),b.fire("tableselect").fire("tableselect:composer")}var k=wysihtml5.dom,l={table:null,start:null,end:null,cells:null,select:j},m="wysiwyg-tmp-selected-cell",n=function(b){var c=wysihtml5.dom.getParentElement(b.target,{query:"td, th"},!1,a);c&&d(c)},o=function(c){a.ownerDocument.removeEventListener("click",o),k.getParentElement(c.target,{query:"table"},!1,a)!=l.table&&(e(),l.table=null,l.start=null,l.end=null,b.fire("tableunselect").fire("tableunselect:composer"))};return c()},function(a){function b(a){var b,c;for(b in d)if(d.hasOwnProperty(b)&&(c=d[b],c.regex.test(a)))return c}function c(a){var c=b(a);return c?c.name:void 0}var d={rgba:{regex:/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d\.]+)\s*\)/i,name:"rgba"},rgb:{regex:/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i,name:"rgb"},hex6:{regex:/^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/i,name:"hex",radix:16},hex3:{regex:/^#([0-9a-f])([0-9a-f])([0-9a-f])/i,name:"hex",radix:16}},e=function(a){return new RegExp("(^|\\s|;)"+a+"\\s*:\\s*[^;$]+","gi")};a.quirks.styleParser={getColorParseMethod:b,getColorFormat:c,parseColor:function(c,f){var g,h,i,j,k,l=c;if(f){if(g=e(f),!(h=c.match(g)))return!1;h=h.pop().split(":")[1],l=a.lang.string(h).trim()}return(i=b(l))&&(j=l.match(i.regex))?(k=i.radix||10,i===d.hex3?(j.shift(),j.push(1),a.lang.array(j).map(function(a,b){return 3>b?parseInt(a,k)*k+parseInt(a,k):parseFloat(a)})):(j.shift(),j[3]||j.push(1),a.lang.array(j).map(function(a,b){return 3>b?parseInt(a,k):parseFloat(a)}))):!1},unparseColor:function(a,b){var c=16;return"hex"===b?(a[0].toString(c)+a[1].toString(c)+a[2].toString(c)).toUpperCase():"hash"===b?"#"+(a[0].toString(c)+a[1].toString(c)+a[2].toString(c)).toUpperCase():"rgb"===b?"rgb("+a[0]+","+a[1]+","+a[2]+")":"rgba"===b?"rgba("+a[0]+","+a[1]+","+a[2]+","+a[3]+")":"csv"===b?a[0]+","+a[1]+","+a[2]+","+a[3]:a[3]&&1!==a[3]?"rgba("+a[0]+","+a[1]+","+a[2]+","+a[3]+")":"rgb("+a[0]+","+a[1]+","+a[2]+")"},parseFontSize:function(b){var c=b.match(e("font-size"));return c?a.lang.string(c[c.length-1].split(":")[1]).trim():!1}}}(wysihtml5),function(a){function b(a){var b=0;if(a.parentNode)do b+=a.offsetTop||0,a=a.offsetParent;while(a);return b}function c(a,b){for(var c=0;b!==a;)if(c++,b=b.parentNode,!b)throw new Error("not a descendant of ancestor!");return c}function d(a,b){return 3===a.nodeType?a:a.childNodes[b]||a}function e(b){var c=document.createElement("span"),d=function(a){b.removeEventListener("mouseup",d),b.removeEventListener("keydown",d),b.removeEventListener("touchstart",d),b.removeEventListener("focus",d),b.removeEventListener("blur",d),b.removeEventListener("paste",e),b.removeEventListener("drop",e),b.removeEventListener("beforepaste",e),c&&c.parentNode&&c.parentNode.removeChild(c)},e=function(a){c&&c.parentNode&&setTimeout(d,0)};return c.appendChild(b.ownerDocument.createTextNode(a.INVISIBLE_SPACE)),c.className="_wysihtml5-temp-caret-fix",c.style.display="block",c.style.minWidth="1px",c.style.height="0px",b.addEventListener("mouseup",d),b.addEventListener("keydown",d),b.addEventListener("touchstart",d),b.addEventListener("focus",d),b.addEventListener("blur",d),b.addEventListener("paste",e),b.addEventListener("drop",e),b.addEventListener("beforepaste",e),c}function f(a){if(!a.canSurroundContents())for(var b=a.commonAncestorContainer,d=c(b,a.startContainer),e=c(b,a.endContainer);!a.canSurroundContents();)d>e?(a.setStartBefore(a.startContainer),d=c(b,a.startContainer)):(a.setEndAfter(a.endContainer),e=c(b,a.endContainer))}var g=a.dom;a.Selection=Base.extend({constructor:function(a,b,c){rangy.init(),this.editor=a,this.composer=a.composer,this.doc=this.composer.doc,this.win=this.composer.win,this.contain=b,this.unselectableClass=c||!1},getBookmark:function(){var a=this.getRange();return a&&a.cloneRange()},setBookmark:function(a){a&&this.setSelection(a)},setBefore:function(a){var b=rangy.createRange(this.doc);return b.setStartBefore(a),b.setEndBefore(a),this.setSelection(b)},createTemporaryCaretSpaceAfter:function(b){var c=this.doc.createElement("span"),d=this.doc.createTextNode(a.INVISIBLE_SPACE),e=function(b){var d;this.contain.removeEventListener("mouseup",e),this.contain.removeEventListener("keydown",g),this.contain.removeEventListener("touchstart",e),this.contain.removeEventListener("focus",e),this.contain.removeEventListener("blur",e),this.contain.removeEventListener("paste",f),this.contain.removeEventListener("drop",f),this.contain.removeEventListener("beforepaste",f),c&&c.parentNode&&(c.innerHTML=c.innerHTML.replace(a.INVISIBLE_SPACE_REG_EXP,""),/[^\s]+/.test(c.innerHTML)?(d=c.lastChild,a.dom.unwrap(c),this.setAfter(d)):c.parentNode.removeChild(c))}.bind(this),f=function(a){c&&c.parentNode&&setTimeout(e,0)},g=function(a){8===a.which||91===a.which||17===a.which||86===a.which&&(a.ctrlKey||a.metaKey)||e()};return c.className="_wysihtml5-temp-caret-fix",c.style.position="absolute",c.style.display="block",c.style.minWidth="1px",c.style.zIndex="99999",c.appendChild(d),b.parentNode.insertBefore(c,b.nextSibling),this.setBefore(d),this.contain.addEventListener("mouseup",e),this.contain.addEventListener("keydown",g),this.contain.addEventListener("touchstart",e),this.contain.addEventListener("focus",e),this.contain.addEventListener("blur",e),this.contain.addEventListener("paste",f),this.contain.addEventListener("drop",f),this.contain.addEventListener("beforepaste",f),c},setAfter:function(b,c,d){var e,f=this.win,g=rangy.createRange(this.doc),h=function(){var d=b.parentNode,g=d?d.childNodes[d.childNodes.length-1]:null;if(!e||g===b&&1===b.nodeType&&"block"===f.getComputedStyle(b).display)if(c){var h=this.doc.createTextNode(a.INVISIBLE_SPACE);b.parentNode.insertBefore(h,b.nextSibling),this.selectNode(h),setTimeout(function(){h&&h.parentNode&&h.parentNode.removeChild(h)},0)}else this.createTemporaryCaretSpaceAfter(b)}.bind(this);if(g.setStartAfter(b),g.setEndAfter(b),document.activeElement&&document.activeElement===this.composer.element)e=this.setSelection(g),h(),d&&d(e);else{var i=this.composer.getScrollPos();this.composer.element.focus(),this.composer.setScrollPos(i),setTimeout(function(){e=this.setSelection(g),h(),d&&d(e)}.bind(this),0)}},selectNode:function(b,c){var d=rangy.createRange(this.doc),e=b.nodeType===a.ELEMENT_NODE,f="canHaveHTML"in b?b.canHaveHTML:"IMG"!==b.nodeName,h=e?b.innerHTML:b.data,i=""===h||h===a.INVISIBLE_SPACE,j=g.getStyle("display").from(b),k="block"===j||"list-item"===j;if(i&&e&&f&&!c)try{b.innerHTML=a.INVISIBLE_SPACE}catch(l){}f?d.selectNodeContents(b):d.selectNode(b),f&&i&&e?d.collapse(k):f&&i&&(d.setStartAfter(b),d.setEndAfter(b)),this.setSelection(d)},getSelectedNode:function(a){var b,c;return a&&this.doc.selection&&"Control"===this.doc.selection.type&&(c=this.doc.selection.createRange(),c&&c.length)?c.item(0):(b=this.getSelection(this.doc),b.focusNode===b.anchorNode?b.focusNode:(c=this.getRange(this.doc),c?c.commonAncestorContainer:this.doc.body))},fixSelBorders:function(){var a=this.getRange();f(a),this.setSelection(a)},getSelectedOwnNodes:function(a){for(var b=this.getOwnRanges(),c=[],d=0,e=b.length;e>d;d++)c.push(b[d].commonAncestorContainer||this.doc.body);return c},findNodesInSelection:function(b){for(var c,d=this.getOwnRanges(),e=[],f=0,g=d.length;g>f;f++)c=d[f].getNodes([1],function(c){return a.lang.array(b).contains(c.nodeName)}),e=e.concat(c);return e},filterElements:function(a){for(var b,c=this.getOwnRanges(),d=[],e=0,f=c.length;f>e;e++)b=c[e].getNodes([1],function(b){return a(b,c[e])}),d=d.concat(b);return d},containsUneditable:function(){for(var a=this.getOwnUneditables(),b=this.getSelection(),c=0,d=a.length;d>c;c++)if(b.containsNode(a[c]))return!0;return!1},deleteContents:function(){var a=this.getRange();this.deleteRangeContents(a),this.setSelection(a)},deleteRangeContents:function(b){var c,d,e,f;if(this.unselectableClass){(c=a.dom.getParentElement(b.startContainer,{query:"."+this.unselectableClass},!1,this.contain))&&b.setStartBefore(c),(d=a.dom.getParentElement(b.endContainer,{query:"."+this.unselectableClass},!1,this.contain))&&b.setEndAfter(d),e=b.getNodes([1],function(b){return a.dom.hasClass(b,this.unselectableClass)}.bind(this));for(var g=e.length;g--;)try{f=new CustomEvent("wysihtml5:uneditable:delete"),e[g].dispatchEvent(f)}catch(h){}}b.deleteContents()},getCaretNode:function(){var a=this.getSelection();return a&&a.anchorNode?d(a.anchorNode,a.anchorOffset):null},getPreviousNode:function(b,c){var e;if(!b){var f=this.getSelection();b=f&&f.anchorNode?d(f.anchorNode,f.anchorOffset):null}if(b===this.contain)return!1;var g,h=b.previousSibling;return h===this.contain?!1:(h&&3!==h.nodeType&&1!==h.nodeType?h=this.getPreviousNode(h,c):h&&3===h.nodeType&&/^\s*$/.test(h.textContent)?h=this.getPreviousNode(h,c):c&&h&&1===h.nodeType?(e=a.dom.getStyle("display").from(h),a.lang.array(["BR","HR","IMG"]).contains(h.nodeName)||a.lang.array(["block","inline-block","flex","list-item","table"]).contains(e)||!/^[\s]*$/.test(h.innerHTML)||(h=this.getPreviousNode(h,c))):h||b===this.contain||(g=b.parentNode,g!==this.contain&&(h=this.getPreviousNode(g,c))),h!==this.contain?h:!1)},getNodesNearCaret:function(){if(!this.isCollapsed())throw"Selection must be caret when using selection.getNodesNearCaret()";var a,b,c,d,e=this.getOwnRanges();return e&&e.length>0?(1===e[0].startContainer.nodeType?(a=e[0].startContainer.childNodes[e[0].startOffset-1],a||0!==e[0].startOffset?a&&(b=a.previousSibling,c=a.nextSibling):c=e[0].startContainer.childNodes[0]):(0===e[0].startOffset&&e[0].startContainer.previousSibling?(a=e[0].startContainer.previousSibling,3===a.nodeType&&(d=a.data.length)):(a=e[0].startContainer,d=e[0].startOffset),b=a.previousSibling,c=a.nextSibling),{caretNode:a,prevNode:b,nextNode:c,textOffset:d}):null},getSelectionParentsByTag:function(b){for(var c,d=this.getSelectedOwnNodes(),e=[],f=0,g=d.length;g>f;f++)c=d[f].nodeName&&"LI"===d[f].nodeName?d[f]:a.dom.getParentElement(d[f],{query:"li"},!1,this.contain),c&&e.push(c);return e.length?e:null},getRangeToNodeEnd:function(){if(this.isCollapsed()){var a=this.getRange(),b=a.startContainer,c=a.startOffset,d=rangy.createRange(this.doc);return d.selectNodeContents(b),d.setStart(b,c),d}},caretIsLastInSelection:function(){var a=(rangy.createRange(this.doc),this.getSelection(),this.getRangeToNodeEnd().cloneContents()),b=a.textContent;return/^\s*$/.test(b)},caretIsFirstInSelection:function(b){var c=rangy.createRange(this.doc),e=this.getSelection(),f=this.getRange(),g=d(f.startContainer,f.startOffset);if(g){if(g.nodeType===a.TEXT_NODE){if(!g.parentNode)return!1;if(!this.isCollapsed()||g.parentNode.firstChild!==g&&!a.dom.domNode(g.previousSibling).is.block())return!1;var h=this.win.getComputedStyle(g.parentNode).whiteSpace;return"pre"===h||"pre-wrap"===h?0===f.startOffset:/^\s*$/.test(g.data.substr(0,f.startOffset))}return b&&a.dom.domNode(g).is.lineBreak()?!0:(c.selectNodeContents(this.getRange().commonAncestorContainer),c.collapse(!0),this.isCollapsed()&&(c.startContainer===e.anchorNode||c.endContainer===e.anchorNode)&&c.startOffset===e.anchorOffset)}},caretIsInTheBeginnig:function(b){var c=this.getSelection(),d=c.anchorNode,e=c.anchorOffset;return b&&d?0===e&&(d.nodeName&&d.nodeName===b.toUpperCase()||a.dom.getParentElement(d.parentNode,{query:b},1)):d?0===e&&!this.getPreviousNode(d,!0):void 0},getBeforeSelection:function(b){var c,d,e=this.getSelection(),f=e.isBackwards()?e.focusNode:e.anchorNode,g=e.isBackwards()?e.focusOffset:e.anchorOffset,h=this.createRange();if(f&&3===f.nodeType&&/^\s*$/.test(f.data.slice(0,g))&&(g=0),d=a.dom.getParentElement(f,{query:"._wysihtml5-temp-caret-fix"},1),d&&(f=d.parentNode,g=Array.prototype.indexOf.call(f.childNodes,d)),f){if(g>0)return 3===f.nodeType?(h.setStart(f,0),h.setEnd(f,g),{type:"text",range:h,offset:g,node:f}):(h.setStartBefore(f.childNodes[0]),c=f.childNodes[g-1],h.setEndAfter(c),{type:"element",range:h,offset:g,node:c});if(h.setStartAndEnd(f,0),b){var i=this.getPreviousNode(f,!0),j=null;if(i&&(j=1===i.nodeType&&a.dom.hasClass(i,this.unselectableClass)?i:a.dom.domNode(i).lastLeafNode()),j)return{type:"leafnode",range:h,offset:g,node:j}}return{type:"none",range:h,offset:g,node:f}}return null},executeAndRestoreRangy:function(a,b){var c=rangy.saveSelection(this.win);if(c)try{a()}catch(d){setTimeout(function(){throw d},0)}else a();rangy.restoreSelection(c)},executeAndRestore:function(b,c){var d,e,f,h,i,j,k,l,m=this.doc.body,n=c&&m.scrollTop,o=c&&m.scrollLeft,p="_wysihtml5-temp-placeholder",q=''+a.INVISIBLE_SPACE+" ",r=this.getRange(!0);if(!r)return void b(m,m);r.collapsed||(k=r.cloneRange(),j=k.createContextualFragment(q),k.collapse(!1),k.insertNode(j),k.detach()),i=r.createContextualFragment(q),r.insertNode(i),j&&(d=this.contain.querySelectorAll("."+p),r.setStartBefore(d[0]),r.setEndAfter(d[d.length-1])),this.setSelection(r);try{b(r.startContainer,r.endContainer)}catch(s){setTimeout(function(){throw s},0)}if(d=this.contain.querySelectorAll("."+p),d&&d.length){l=rangy.createRange(this.doc),f=d[0].nextSibling,d.length>1&&(h=d[d.length-1].previousSibling),h&&f?(l.setStartBefore(f),l.setEndAfter(h)):(e=this.doc.createTextNode(a.INVISIBLE_SPACE),g.insert(e).after(d[0]),l.setStartBefore(e),l.setEndAfter(e)),this.setSelection(l);for(var t=d.length;t--;)d[t].parentNode.removeChild(d[t])}else this.contain.focus();c&&(m.scrollTop=n,m.scrollLeft=o);try{d.parentNode.removeChild(d)}catch(u){}},set:function(a,b){var c=rangy.createRange(this.doc);c.setStart(a,b||0),this.setSelection(c)},insertHTML:function(a){var b,c,d=this.getRange(),e=this.doc.createElement("DIV"),f=this.doc.createDocumentFragment();if(d){for(d.deleteContents(),e.innerHTML=a,b=e.lastChild;e.firstChild;)f.appendChild(e.firstChild);for(d.insertNode(f),c=this.contain.lastChild;c&&3===c.nodeType&&c.previousSibling&&/^\s*$/.test(c.data);)c=c.previousSibling;b&&(c&&b===c&&1===b.nodeType&&this.contain.appendChild(this.doc.createElement("br")),this.setAfter(b))}},insertNode:function(a){var b=this.getRange();b&&b.insertNode(a)},canAppendChild:function(a){var b,c,d=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],e=this.getRange();return b=a||e.startContainer,b&&(c=(b.tagName||b.nodeName).toLowerCase()),-1===d.indexOf(c)},splitElementAtCaret:function(b,c){var d,e,f,g,h,i=this.getSelection();if(i.rangeCount>0){d=i.getRangeAt(0).cloneRange(),d.setEndAfter(b),e=d.extractContents(),h=e.childNodes;for(var j=h.length;j--;)a.dom.domNode(h[j]).is.visible()||e.removeChild(h[j]);b.parentNode.insertBefore(e,b.nextSibling),c?(f=c.firstChild||c,g=c.lastChild||c,b.parentNode.insertBefore(c,b.nextSibling),f&&g&&(d.setStartBefore(f),d.setEndAfter(g),this.setSelection(d))):(d.setStartAfter(b),d.setEndAfter(b)),a.dom.domNode(b).is.visible()||(""===a.dom.getTextContent(b)?b.parentNode.removeChild(b):b.parentNode.replaceChild(this.doc.createTextNode(" "),b))}},surround:function(a){var b,c=this.getOwnRanges(),d=[];if(0==c.length)return d;for(var e=c.length;e--;){b=this.doc.createElement(a.nodeName),d.push(b),a.className&&(b.className=a.className),a.cssStyle&&b.setAttribute("style",a.cssStyle);try{c[e].surroundContents(b),this.selectNode(b)}catch(f){b.appendChild(c[e].extractContents()),c[e].insertNode(b)}}return d},scrollIntoView:function(){var c,d=this.doc,e=5,f=d.documentElement.scrollHeight>d.documentElement.offsetHeight,g=d._wysihtml5ScrollIntoViewElement=d._wysihtml5ScrollIntoViewElement||function(){var b=d.createElement("span");return b.innerHTML=a.INVISIBLE_SPACE,b}();f&&(this.insertNode(g),c=b(g),g.parentNode.removeChild(g),c>=d.body.scrollTop+d.documentElement.offsetHeight-e&&(d.body.scrollTop=c))},selectLine:function(){var b=rangy.createRange();a.browser.supportsSelectionModify()?this._selectLine_W3C():b.nativeRange&&b.nativeRange.getBoundingClientRect&&this._selectLineUniversal()},includeRangyRangeHelpers:function(){var a=this.getSelection(),b=a.getRangeAt(0),c=function(a){return a&&1===a.nodeType&&a.classList.contains("rangySelectionBoundary")},d=function(a){return 1===a.nodeType?a.childNodes&&a.childNodes.length||0:a.data&&a.data.length||0},e=1===a.anchorNode.nodeType?a.anchorNode.childNodes[a.anchorOffset]:a.anchorNode,f=1===a.focusNode.nodeType?a.focusNode.childNodes[a.focusOffset]:a.focusNode;f&&a.focusOffset===d(f)&&f.nextSibling&&c(f.nextSibling)&&b.setEndAfter(f.nextSibling),e&&0===a.anchorOffset&&e.previousSibling&&c(e.previousSibling)&&b.setStartBefore(e.previousSibling),b.select()},_selectLine_W3C:function(){var a=this.win.getSelection(),b=[a.anchorNode,a.anchorOffset,a.focusNode,a.focusOffset];a.modify("move","left","lineboundary"),a.modify("extend","right","lineboundary"),a.anchorNode===b[0]&&a.anchorOffset===b[1]&&a.focusNode===b[2]&&a.focusOffset===b[3]?this._selectLineUniversal():this.includeRangyRangeHelpers()},toLineBoundary:function(b,c){if(c="undefined"==typeof c?!1:c,a.browser.supportsSelectionModify()){var d=this.win.getSelection();d.modify("extend",b,"lineboundary"),c&&("left"===b?d.collapseToStart():"right"===b&&d.collapseToEnd())}},getRangeRect:function(a){var b,c=(this.doc.createTextNode("i"),this.doc.createTextNode("i"));return a.collapsed?(a.insertNode(c),a.selectNode(c),b=a.nativeRange.getBoundingClientRect(),a.deleteContents()):b=a.nativeRange.getBoundingClientRect(),b},_selectLineUniversal:function(){var b,c,d,e,f,g,h=this.getSelection(),i=h.getRangeAt(0),j=0,k=this,l=function(b){return b&&1===b.nodeType&&("block"===k.win.getComputedStyle(b).display||a.lang.array(["BR","HR"]).contains(b.nodeName))},m=function(a){var b=a;if(b)for(;b&&(1===b.nodeType&&b.classList.contains("rangySelectionBoundary")||3===b.nodeType&&/^\s*$/.test(b.data));)b=b.previousSibling;return b};c=i.cloneRange(),d=i.cloneRange(),i.collapsed&&(3===i.startContainer.nodeType&&i.startOffset0?i.moveEnd("character",1):i.startOffset>0&&(3===i.startContainer.nodeType||1===i.startContainer.nodeType&&!l(m(i.startContainer.childNodes[i.startOffset-1])))&&i.moveStart("character",-1)),i.collapsed||i.insertNode(this.doc.createTextNode(a.INVISIBLE_SPACE)),b=i.nativeRange.getBoundingClientRect();do e=i.moveStart("character",-1),f=i.nativeRange.getBoundingClientRect(),f&&Math.floor(f.top)===Math.floor(b.top)||(i.moveStart("character",1),g=!0),j++;while(0!==e&&!g&&2e3>j);if(j=0,g=!1,b=i.nativeRange.getBoundingClientRect(),i.endContainer!==this.contain||this.contain.lastChild&&this.contain.childNodes[i.endOffset]!==this.contain.lastChild)do e=i.moveEnd("character",1),f=i.nativeRange.getBoundingClientRect(),f&&Math.floor(f.bottom)===Math.floor(b.bottom)||(i.moveEnd("character",-1),i.endContainer&&1===i.endContainer.nodeType&&i.endContainer.childNodes[i.endOffset]&&1===i.endContainer.childNodes[i.endOffset].nodeType&&"BR"===i.endContainer.childNodes[i.endOffset].nodeName&&i.endContainer.childNodes[i.endOffset].previousSibling&&(1===i.endContainer.childNodes[i.endOffset].previousSibling.nodeType?i.setEnd(i.endContainer.childNodes[i.endOffset].previousSibling,i.endContainer.childNodes[i.endOffset].previousSibling.childNodes.length):3===i.endContainer.childNodes[i.endOffset].previousSibling.nodeType&&i.setEnd(i.endContainer.childNodes[i.endOffset].previousSibling,i.endContainer.childNodes[i.endOffset].previousSibling.data.length)),g=!0),j++;while(0!==e&&!g&&2e3>j);i.select(),this.includeRangyRangeHelpers()},getText:function(){var a=this.getSelection();return a?a.toString():""},getNodes:function(a,b){var c=this.getRange();return c?c.getNodes(Array.isArray(a)?a:[a],b):[]},getOwnNodes:function(a,b,c){for(var d=this.getOwnRanges(),e=[],f=0,g=d.length;g>f;f++)d[f]&&(c&&d[f].splitBoundaries(),e=e.concat(d[f].getNodes(Array.isArray(a)?a:[a],b)));return e},fixRangeOverflow:function(a){if(this.contain&&this.contain.firstChild&&a){var b=a.compareNode(this.contain);if(2!==b)1===b&&a.setStartBefore(this.contain.firstChild),0===b&&a.setEndAfter(this.contain.lastChild),3===b&&(a.setStartBefore(this.contain.firstChild),a.setEndAfter(this.contain.lastChild));else if(this._detectInlineRangeProblems(a)){var c=a.endContainer.previousElementSibling;c&&a.setEnd(c,this._endOffsetForNode(c))}}},_endOffsetForNode:function(a){var b=document.createRange();return b.selectNodeContents(a),b.endOffset},_detectInlineRangeProblems:function(a){var b=g.compareDocumentPosition(a.startContainer,a.endContainer);return 0==a.endOffset&&4&b},getRange:function(a){var b=this.getSelection(),c=b&&b.rangeCount&&b.getRangeAt(0);return a!==!0&&this.fixRangeOverflow(c),c},getOwnUneditables:function(){var b=g.query(this.contain,"."+this.unselectableClass),c=g.query(b,"."+this.unselectableClass);return a.lang.array(b).without(c)},getOwnRanges:function(){var a,b=[],c=this.getRange();if(c&&b.push(c),this.unselectableClass&&this.contain&&c){var d,e=this.getOwnUneditables();if(e.length>0)for(var f=0,g=e.length;g>f;f++){a=[];for(var h=0,i=b.length;i>h;h++){if(b[h])switch(b[h].compareNode(e[f])){case 2:break;case 3:d=b[h].cloneRange(),d.setEndBefore(e[f]),a.push(d),d=b[h].cloneRange(),d.setStartAfter(e[f]),a.push(d);break;default:a.push(b[h])}b=a}}}return b},getSelection:function(){return rangy.getSelection(this.win)},setSelection:function(a){var b=rangy.getSelection(this.win);return b.setSingleRange(a),b&&b.anchorNode&&b.focusNode?b:null},selectAll:function(){var b,c=this.createRange(),d=this.composer,f=this,g=e(this.composer.element),h=e(this.composer.element),i=function(){c.setStart(d.element,0),c.setEnd(d.element,d.element.childNodes.length),b=f.setSelection(c)},j=function(){return!b||b.nativeSelection&&b.nativeSelection.type&&("Caret"===b.nativeSelection.type||"None"===b.nativeSelection.type)};a.dom.removeInvisibleSpaces(this.composer.element),i(),this.composer.element.firstChild&&j()&&(this.composer.element.appendChild(g),i(),j()&&(g.parentNode.removeChild(g),this.composer.element.insertBefore(h,this.composer.element.firstChild),i(),j()&&(this.composer.element.appendChild(g),i())))},createRange:function(){return rangy.createRange(this.doc)},isCollapsed:function(){return this.getSelection().isCollapsed},getHtml:function(){return this.getSelection().toHtml()},getPlainText:function(){return this.getSelection().toString()},isEndToEndInNode:function(b){var c=this.getRange(),d=c.commonAncestorContainer,e=c.startContainer,f=c.endContainer;if(d.nodeType===a.TEXT_NODE&&(d=d.parentNode),e.nodeType===a.TEXT_NODE&&!/^\s*$/.test(e.data.substr(c.startOffset)))return!1;if(f.nodeType===a.TEXT_NODE&&!/^\s*$/.test(f.data.substr(c.endOffset)))return!1;for(;e&&e!==d;){if(e.nodeType!==a.TEXT_NODE&&!a.dom.contains(d,e))return!1;if(a.dom.domNode(e).prev({ignoreBlankTexts:!0}))return!1;e=e.parentNode}for(;f&&f!==d;){if(f.nodeType!==a.TEXT_NODE&&!a.dom.contains(d,f))return!1;if(a.dom.domNode(f).next({ignoreBlankTexts:!0}))return!1;f=f.parentNode}return a.lang.array(b).contains(d.nodeName)?d:!1},isInThisEditable:function(){var b=this.getSelection(),c=b.focusNode,d=b.anchorNode;return c&&1!==c.nodeType&&(c=c.parentNode),d&&1!==d.nodeType&&(d=d.parentNode),d&&c&&(a.dom.contains(this.composer.element,c)||this.composer.element===c)&&(a.dom.contains(this.composer.element,d)||this.composer.element===d)},deselect:function(){var a=this.getSelection();a&&a.removeAllRanges()}})}(wysihtml5),function(a,b){function c(a,b,c){if(!a.className)return!1;var d=a.className.match(c)||[];return d[d.length-1]===b}function d(a,b){if(!a.getAttribute||!a.getAttribute("style"))return!1;a.getAttribute("style").match(b);return a.getAttribute("style").match(b)?!0:!1}function e(a,b,c){a.getAttribute("style")?(h(a,c),a.getAttribute("style")&&!/^\s*$/.test(a.getAttribute("style"))?a.setAttribute("style",b+";"+a.getAttribute("style")):a.setAttribute("style",b)):a.setAttribute("style",b)}function f(a,b,c){a.className?(g(a,c),a.className+=" "+b):a.className=b}function g(a,b){a.className&&(a.className=a.className.replace(b,""))}function h(a,b){var c,d=[];if(a.getAttribute("style")){c=a.getAttribute("style").split(";");for(var e=c.length;e--;)c[e].match(b)||/^\s*$/.test(c[e])||d.push(c[e]);d.length?a.setAttribute("style",d.join(";")):a.removeAttribute("style")}}function i(a,b){var c=[],d=b.split(";"),e=a.getAttribute("style");if(e){e=e.replace(/\s/gi,"").toLowerCase(),
-c.push(new RegExp("(^|\\s|;)"+b.replace(/\s/gi,"").replace(/([\(\)])/gi,"\\$1").toLowerCase().replace(";",";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi,"\\s?rgb\\($1,\\s?$2,\\s?$3\\)"),"gi"));for(var f=d.length;f-->0;)/^\s*$/.test(d[f])||c.push(new RegExp("(^|\\s|;)"+d[f].replace(/\s/gi,"").replace(/([\(\)])/gi,"\\$1").toLowerCase().replace(";",";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi,"\\s?rgb\\($1,\\s?$2,\\s?$3\\)"),"gi"));for(var g=0,h=c.length;h>g;g++)if(e.match(c[g]))return c[g]}return!1}function j(c,d,e,f){return e?i(c,e):f?a.dom.hasClass(c,f):b.dom.arrayContains(d,c.tagName.toLowerCase())}function k(a,b,c,d){for(var e=a.length;e--;)if(!j(a[e],b,c,d))return!1;return a.length?!0:!1}function l(a,b,c){var d=i(a,b);return d?(h(a,d),"remove"):(e(a,b,c),"change")}function m(a,b){return a.className.replace(u," ")==b.className.replace(u," ")}function n(a){for(var b=a.parentNode;a.firstChild;)b.insertBefore(a.firstChild,a);b.removeChild(a)}function o(a,b){if(a.attributes.length!=b.attributes.length)return!1;for(var c,d,e,f=0,g=a.attributes.length;g>f;++f)if(c=a.attributes[f],e=c.name,"class"!=e){if(d=b.attributes.getNamedItem(e),c.specified!=d.specified)return!1;if(c.specified&&c.nodeValue!==d.nodeValue)return!1}return!0}function p(a,c){return b.dom.isCharacterDataNode(a)?0==c?!!a.previousSibling:c==a.length?!!a.nextSibling:!0:c>0&&ce;++e)a=this.textNodes[e],b=a.parentNode,d[e]=a.data,e&&(b.removeChild(a),b.hasChildNodes()||b.parentNode.removeChild(b));return this.firstTextNode.data=c=d.join(""),c},getLength:function(){for(var a=this.textNodes.length,b=0;a--;)b+=this.textNodes[a].length;return b},toString:function(){for(var a=[],b=0,c=this.textNodes.length;c>b;++b)a[b]="'"+this.textNodes[b].data+"'";return"[Merge("+a.join(",")+")]"}},s.prototype={getAncestorWithClass:function(d){for(var e;d;){if(e=this.cssClass?c(d,this.cssClass,this.similarClassRegExp):""!==this.cssStyle?!1:!0,d.nodeType==a.ELEMENT_NODE&&"false"!=d.getAttribute("contenteditable")&&b.dom.arrayContains(this.tagNames,d.tagName.toLowerCase())&&e)return d;d=d.parentNode}return!1},getAncestorWithStyle:function(c){for(var e;c;){if(e=this.cssStyle?d(c,this.similarStyleRegExp):!1,c.nodeType==a.ELEMENT_NODE&&"false"!=c.getAttribute("contenteditable")&&b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase())&&e)return c;c=c.parentNode}return!1},getMatchingAncestor:function(a){var b=this.getAncestorWithClass(a),c=!1;return b?this.cssStyle&&(c="class"):(b=this.getAncestorWithStyle(a),b&&(c="style")),{element:b,type:c}},postApply:function(a,b){for(var c,d,e,f=a[0],g=a[a.length-1],h=[],i=f,j=g,k=0,l=g.length,m=0,n=a.length;n>m;++m)d=a[m],e=null,d&&d.parentNode&&(e=this.getAdjacentMergeableTextNode(d.parentNode,!1)),e?(c||(c=new r(e),h.push(c)),c.textNodes.push(d),d===f&&(i=c.firstTextNode,k=i.length),d===g&&(j=c.firstTextNode,l=c.getLength())):c=null;if(g&&g.parentNode){var o=this.getAdjacentMergeableTextNode(g.parentNode,!0);o&&(c||(c=new r(g),h.push(c)),c.textNodes.push(o))}if(h.length){for(m=0,n=h.length;n>m;++m)h[m].doMerge();b.setStart(i,k),b.setEnd(j,l)}},getAdjacentMergeableTextNode:function(b,c){var d,e=b.nodeType==a.TEXT_NODE,f=e?b.parentNode:b,g=c?"nextSibling":"previousSibling";if(e){if(d=b[g],d&&d.nodeType==a.TEXT_NODE)return d}else if(d=f[g],d&&this.areElementsMergeable(b,d))return d[c?"firstChild":"lastChild"];return null},areElementsMergeable:function(a,c){return b.dom.arrayContains(this.tagNames,(a.tagName||"").toLowerCase())&&b.dom.arrayContains(this.tagNames,(c.tagName||"").toLowerCase())&&m(a,c)&&o(a,c)},createContainer:function(a){var b=a.createElement(this.tagNames[0]);return this.cssClass&&(b.className=this.cssClass),this.cssStyle&&b.setAttribute("style",this.cssStyle),b},applyToTextNode:function(a){var c=a.parentNode;if(1==c.childNodes.length&&b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase()))this.cssClass&&f(c,this.cssClass,this.similarClassRegExp),this.cssStyle&&e(c,this.cssStyle,this.similarStyleRegExp);else{var d=this.createContainer(b.dom.getDocument(a));a.parentNode.insertBefore(d,a),d.appendChild(a)}},isRemovable:function(c){return b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase())&&""===a.lang.string(c.className).trim()&&(!c.getAttribute("style")||""===a.lang.string(c.getAttribute("style")).trim())},undoToTextNode:function(a,b,c,d){var e=c?!1:!0,f=c||d,h=!1;if(!b.containsNode(f)){var i=b.cloneRange();i.selectNode(f),i.isPointInRange(b.endContainer,b.endOffset)&&p(b.endContainer,b.endOffset)&&(q(f,b.endContainer,b.endOffset,this.container),b.setEndAfter(f)),i.isPointInRange(b.startContainer,b.startOffset)&&p(b.startContainer,b.startOffset)&&(f=q(f,b.startContainer,b.startOffset,this.container))}!e&&this.similarClassRegExp&&g(f,this.similarClassRegExp),e&&this.similarStyleRegExp&&(h="change"===l(f,this.cssStyle,this.similarStyleRegExp)),this.isRemovable(f)&&!h&&n(f)},applyToRange:function(b){for(var c,d=b.length;d--;){if(c=b[d].getNodes([a.TEXT_NODE]),!c.length)try{var e=this.createContainer(b[d].endContainer.ownerDocument);return b[d].surroundContents(e),void this.selectNode(b[d],e)}catch(f){}if(b[d].splitBoundaries(),c=b[d].getNodes([a.TEXT_NODE]),c.length){for(var g,h=0,i=c.length;i>h;++h)g=c[h],this.getMatchingAncestor(g).element||this.applyToTextNode(g);b[d].setStart(c[0],0),g=c[c.length-1],b[d].setEnd(g,g.length),this.normalize&&this.postApply(c,b[d])}}},undoToRange:function(b){for(var c,d,e,f=b.length;f--;){if(c=b[f].getNodes([a.TEXT_NODE]),c.length)b[f].splitBoundaries(),c=b[f].getNodes([a.TEXT_NODE]);else{var g=b[f].endContainer.ownerDocument,h=g.createTextNode(a.INVISIBLE_SPACE);b[f].insertNode(h),b[f].selectNode(h),c=[h]}for(var i=0,j=c.length;j>i;++i)b[f].isValid()&&(d=c[i],e=this.getMatchingAncestor(d),"style"===e.type?this.undoToTextNode(d,b[f],!1,e.element):e.element&&this.undoToTextNode(d,b[f],e.element));1==j?this.selectNode(b[f],c[0]):(b[f].setStart(c[0],0),d=c[c.length-1],b[f].setEnd(d,d.length),this.normalize&&this.postApply(c,b[f]))}},selectNode:function(b,c){var d=c.nodeType===a.ELEMENT_NODE,e="canHaveHTML"in c?c.canHaveHTML:!0,f=d?c.innerHTML:c.data,g=""===f||f===a.INVISIBLE_SPACE;if(g&&d&&e)try{c.innerHTML=a.INVISIBLE_SPACE}catch(h){}b.selectNodeContents(c),g&&d?b.collapse(!1):g&&(b.setStartAfter(c),b.setEndAfter(c))},getTextSelectedByRange:function(a,b){var c=b.cloneRange();c.selectNodeContents(a);var d=c.intersection(b),e=d?d.toString():"";return c.detach(),e},isAppliedToRange:function(b){for(var c,d,e=[],f="full",g=b.length;g--;){if(d=b[g].getNodes([a.TEXT_NODE]),!d.length)return c=this.getMatchingAncestor(b[g].startContainer).element,c?{elements:[c],coverage:f}:!1;for(var h,i=0,j=d.length;j>i;++i)h=this.getTextSelectedByRange(d[i],b[g]),c=this.getMatchingAncestor(d[i]).element,c&&""!=h?(e.push(c),1===a.dom.getTextNodes(c,!0).length?f="full":"full"===f&&(f="inline")):c||(f="partial")}return e.length?{elements:e,coverage:f}:!1},toggleRange:function(a){var b,c=this.isAppliedToRange(a);c?"full"===c.coverage?this.undoToRange(a):"inline"===c.coverage?(b=k(c.elements,this.tagNames,this.cssStyle,this.cssClass),this.undoToRange(a),b||this.applyToRange(a)):(k(c.elements,this.tagNames,this.cssStyle,this.cssClass)||this.undoToRange(a),this.applyToRange(a)):this.applyToRange(a)}},a.selection.HTMLApplier=s}(wysihtml5,rangy),wysihtml5.Commands=Base.extend({constructor:function(a){this.editor=a,this.composer=a.composer,this.doc=this.composer.doc},support:function(a){return wysihtml5.browser.supportsCommand(this.doc,a)},exec:function(a,b){var c=wysihtml5.commands[a],d=wysihtml5.lang.array(arguments).get(),e=c&&c.exec,f=null;if(this.composer.hasPlaceholderSet()&&!wysihtml5.lang.array(["styleWithCSS","enableObjectResizing","enableInlineTableEditing"]).contains(a)&&(this.composer.element.innerHTML="",this.composer.selection.selectNode(this.composer.element)),this.editor.fire("beforecommand:composer"),e)d.unshift(this.composer),f=e.apply(c,d);else try{f=this.doc.execCommand(a,!1,b)}catch(g){}return this.editor.fire("aftercommand:composer"),f},remove:function(a,b){var c=wysihtml5.commands[a],d=wysihtml5.lang.array(arguments).get(),e=c&&c.remove;return e?(d.unshift(this.composer),e.apply(c,d)):void 0},state:function(a,b){var c=wysihtml5.commands[a],d=wysihtml5.lang.array(arguments).get(),e=c&&c.state;if(e)return d.unshift(this.composer),e.apply(c,d);try{return this.doc.queryCommandState(a)}catch(f){return!1}},stateValue:function(a){var b=wysihtml5.commands[a],c=wysihtml5.lang.array(arguments).get(),d=b&&b.stateValue;return d?(c.unshift(this.composer),d.apply(b,c)):!1}}),function(a){var b={nodeName:"B",toggle:!0};a.commands.bold={exec:function(c,d){a.commands.formatInline.exec(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){function b(b){return a.lang.object({}).merge(c).merge({attribute:b}).get()}var c={nodeName:"A",toggle:!1};a.commands.createLink={exec:function(c,d,e){var f=b(e);if(c.selection.isCollapsed()&&!this.state(c,d)){var g=c.doc.createTextNode(f.attribute.href);c.selection.insertNode(g),c.selection.selectNode(g)}a.commands.formatInline.exec(c,d,f)},state:function(b,d){return a.commands.formatInline.state(b,d,c)}}}(wysihtml5),function(a){var b={nodeName:"A"};a.commands.removeLink={exec:function(c,d){a.commands.formatInline.remove(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){var b=/wysiwyg-font-size-[0-9a-z\-]+/g;a.commands.fontSize={exec:function(c,d,e){a.commands.formatInline.exec(c,d,{className:"wysiwyg-font-size-"+e,classRegExp:b,toggle:!0})},state:function(b,c,d){return a.commands.formatInline.state(b,c,{className:"wysiwyg-font-size-"+d})}}}(wysihtml5),function(a){a.commands.fontSizeStyle={exec:function(b,c,d){d=d.size||d,/^\s*$/.test(d)||a.commands.formatInline.exec(b,c,{styleProperty:"fontSize",styleValue:d,toggle:!1})},state:function(b,c,d){return a.commands.formatInline.state(b,c,{styleProperty:"fontSize",styleValue:d||void 0})},remove:function(b,c){return a.commands.formatInline.remove(b,c,{styleProperty:"fontSize"})},stateValue:function(b,c){var d,e=this.state(b,c);return e&&a.lang.object(e).isArray()&&(e=e[0]),e&&(d=e.getAttribute("style"))?a.quirks.styleParser.parseFontSize(d):!1}}}(wysihtml5),function(a){var b=/wysiwyg-color-[0-9a-z]+/g;a.commands.foreColor={exec:function(c,d,e){a.commands.formatInline.exec(c,d,{className:"wysiwyg-color-"+e,classRegExp:b,toggle:!0})},state:function(b,c,d){return a.commands.formatInline.state(b,c,{className:"wysiwyg-color-"+d})}}}(wysihtml5),function(a){a.commands.foreColorStyle={exec:function(b,c,d){var e,f;d&&(e=a.quirks.styleParser.parseColor("color:"+(d.color||d),"color"),e&&(f=(1===e[3]?"rgb("+[e[0],e[1],e[2]].join(", "):"rgba("+e.join(", "))+")",a.commands.formatInline.exec(b,c,{styleProperty:"color",styleValue:f})))},state:function(b,c,d){var e,f=d?a.quirks.styleParser.parseColor("color:"+(d.color||d),"color"):null;return f&&(e=(1===f[3]?"rgb("+[f[0],f[1],f[2]].join(", "):"rgba("+f.join(", "))+")"),a.commands.formatInline.state(b,c,{styleProperty:"color",styleValue:e})},remove:function(b,c){return a.commands.formatInline.remove(b,c,{styleProperty:"color"})},stateValue:function(b,c,d){var e,f=this.state(b,c),g=!1;return f&&a.lang.object(f).isArray()&&(f=f[0]),f&&(e=f.getAttribute("style"))?(g=a.quirks.styleParser.parseColor(e,"color"),a.quirks.styleParser.unparseColor(g,d)):!1}}}(wysihtml5),function(a){a.commands.bgColorStyle={exec:function(b,c,d){var e,f=a.quirks.styleParser.parseColor("background-color:"+(d.color||d),"background-color");f&&(e=(1===f[3]?"rgb("+[f[0],f[1],f[2]].join(", "):"rgba("+f.join(", "))+")",a.commands.formatInline.exec(b,c,{styleProperty:"backgroundColor",styleValue:e}))},state:function(b,c,d){var e,f=d?a.quirks.styleParser.parseColor("background-color:"+(d.color||d),"background-color"):null;return f&&(e=(1===f[3]?"rgb("+[f[0],f[1],f[2]].join(", "):"rgba("+f.join(", "))+")"),a.commands.formatInline.state(b,c,{styleProperty:"backgroundColor",styleValue:e})},remove:function(b,c){return a.commands.formatInline.remove(b,c,{styleProperty:"backgroundColor"})},stateValue:function(b,c,d){var e,f=this.state(b,c),g=!1;return f&&a.lang.object(f).isArray()&&(f=f[0]),f&&(e=f.getAttribute("style"))?(g=a.quirks.styleParser.parseColor(e,"background-color"),a.quirks.styleParser.unparseColor(g,d)):!1}}}(wysihtml5),function(a){function b(a){return{nodeName:a.nodeName||null,className:a.classRegExp?null:a.className||null,classRegExp:a.classRegExp||null,styleProperty:a.styleProperty||null}}function c(a,b){return 3===a.nodeType?a:a.childNodes[b]||a}function d(a){return a&&1===a.nodeType&&"BR"===a.nodeName}function e(a,b){return a&&1===a.nodeType&&"block"===b.win.getComputedStyle(a).display}function f(a){return a&&1===a.nodeType&&a.classList.contains("rangySelectionBoundary")}function g(a,b){return d(a)||e(a,b)}function h(b,c){a.dom.removeInvisibleSpaces(b.element);for(var d,e=b.element,f=e.querySelectorAll(E),g=b.config.classNames.uneditableContainer+[""].concat(E.split(",")).join(", "+b.config.classNames.uneditableContainer+" "),h=e.querySelectorAll(g),i=a.lang.array(f).without(h),j=i.length;j--;)""!==i[j].innerHTML.replace(/[\uFEFF]/g,"")||0!==c.length&&i[j]===c[c.length-1]||(d=a.lang.array(c).indexOf(i[j]),d>-1&&c.splice(d,1),i[j].parentNode.removeChild(i[j]));return c}function i(a){return a.config.useLineBreaks?"DIV":"P"}function j(a,b,c){for(var d=a,e=null;d&&b&&d!==b;)1===d.nodeType&&d.matches(c?E:D)&&(e=d),d=d.parentNode;return e}function k(a,b){for(var c,d,e,f=a,g=null;f&&b&&f!==b;)1===f.nodeType&&f.matches(F)&&(d=f,null===g?(g=f.cloneNode(!1),c=g):(e=f.cloneNode(!1),e.appendChild(g),g=e)),f=f.parentNode;return{parent:d,outerNode:g,innerNode:c}}function l(b,c,d){return b||(b=d.doc.createElement(c.nodeName||i(d)),b.appendChild(d.doc.createTextNode(a.INVISIBLE_SPACE))),c.nodeName&&b.nodeName!==c.nodeName&&(b=C.renameElement(b,c.nodeName)),c.classRegExp&&(b.className=b.className.replace(c.classRegExp,"")),c.className&&b.classList.add(c.className),c.styleProperty&&"undefined"!=typeof c.styleValue&&(b.style[a.browser.fixStyleKey(c.styleProperty)]=c.styleValue),b}function m(b,c,d){var e,f=b.previousSibling,g=b.nextSibling,h=!1;c.styleProperty&&(b.style[a.browser.fixStyleKey(c.styleProperty)]=""),c.className&&b.classList.remove(c.className),c.classRegExp&&(b.className=b.className.replace(c.classRegExp,"")),null!==b.getAttribute("class")&&""===b.getAttribute("class").trim()&&b.removeAttribute("class"),c.nodeName&&b.nodeName.toLowerCase()===c.nodeName.toLowerCase()&&(e=b.getAttribute("style"),e&&""!==e.trim()?b=C.renameElement(b,i(d)):(C.unwrap(b),h=!0)),null!==b.getAttribute("style")&&""===b.getAttribute("style").trim()&&b.removeAttribute("style"),h&&u(f,g,d)}function n(b){for(var c,d,e=b.querySelectorAll(E)||[],f=e.length;f--;)c=a.dom.domNode(e[f]).next({nodeTypes:[1,3],ignoreBlankTexts:!0}),d=a.dom.domNode(e[f]).prev({nodeTypes:[1,3],ignoreBlankTexts:!0}),c&&1!==c.nodeType&&"BR"!==c.nodeName&&""!==(e[f].innerHTML||e[f].nodeValue||"").trim()&&e[f].parentNode.insertBefore(e[f].ownerDocument.createElement("BR"),c),c&&1!==c.nodeType&&"BR"!==c.nodeName&&""!==(e[f].innerHTML||e[f].nodeValue||"").trim()&&e[f].parentNode.insertBefore(e[f].ownerDocument.createElement("BR"),c),a.dom.unwrap(e[f])}function o(a,b){var c,d=a.startContainer,e=a.endContainer;return d&&1===d.nodeType&&d===e?void(d.firstChild===d.lastChild&&1===a.endOffset&&d!==b.element&&"LI"!==d.nodeName&&"TD"!==d.nodeName&&(a.setStartBefore(d),a.setEndAfter(e))):d&&1===d.nodeType&&3===e.nodeType?void(d.firstChild===e&&a.endOffset===e.data.length&&d!==b.element&&"LI"!==d.nodeName&&"TD"!==d.nodeName&&a.setEndAfter(d)):e&&1===e.nodeType&&3===d.nodeType?void(e.firstChild===d&&0===a.startOffset&&e!==b.element&&"LI"!==e.nodeName&&"TD"!==e.nodeName&&a.setStartBefore(e)):d&&3===d.nodeType&&d===e&&1===d.parentNode.childNodes.length?void(a.endOffset==e.data.length&&0===a.startOffset&&(c=d.parentNode,c!==b.element&&"LI"!==c.nodeName&&"TD"!==c.nodeName&&(a.setStartBefore(c),a.setEndAfter(c)))):void 0}function p(b){for(var c,d,e,f,g,h,i=[],j=0,k=b.length;k>j;j++)if(1===b[j].startContainer.nodeType&&b[j].startContainer.matches("ul, ol")&&b[j].setStart(b[j].startContainer.childNodes[b[j].startOffset],0),1===b[j].endContainer.nodeType&&b[j].endContainer.matches("ul, ol")&&(h=b[j].endContainer.childNodes[Math.max(b[j].endOffset-1,0)],h.childNodes&&b[j].setEnd(h,h.childNodes.length)),c=b[j].getNodes([1],function(a){return"LI"===a.nodeName}),c.length>0){for(d=0,e=c.length;e>d;d++)g=b[j].compareNode(c[d]),(g===b[j].NODE_AFTER||g===b[j].NODE_INSIDE)&&(f=b[j].cloneRange(),h=a.dom.domNode(c[d]).prev({nodeTypes:[1]}),h?f.setEnd(h,h.childNodes.length):c[d].closest("ul, ol")?f.setEndBefore(c[d].closest("ul, ol")):f.setEndBefore(c[d]),i.push(f),b[j].setStart(c[d],0)),(g===b[j].NODE_BEFORE||g===b[j].NODE_INSIDE)&&(f=b[j].cloneRange(),f.setEnd(c[d],c[d].childNodes.length),i.push(f),h=a.dom.domNode(c[d]).next({nodeTypes:[1]}),h?b[j].setStart(h,0):c[d].closest("ul, ol")?b[j].setStartAfter(c[d].closest("ul, ol")):b[j].setStartAfter(c[d]));i.push(b[j])}else i.push(b[j]);return i}function q(b,c,d){var e=b?a.lang.object(b).clone(!0):null;return e&&(e.nodeName=e.nodeName||c||i(d)),e}function r(b,c,d,e){var f,h,i,l,m,n=c.startContainer,e=e||j(n,d.element,!0);if(e)h=b.firstChild,i=b.lastChild,d.selection.splitElementAtCaret(e,b),m=a.dom.domNode(i).next({nodeTypes:[1,3],ignoreBlankTexts:!0}),l=a.dom.domNode(h).prev({nodeTypes:[1,3],ignoreBlankTexts:!0}),h&&!g(h,d)&&l&&!g(l,d)&&h.parentNode.insertBefore(d.doc.createElement("br"),h),i&&!g(i,d)&&m&&!g(m,d)&&m.parentNode.insertBefore(d.doc.createElement("br"),m);else if(f=k(n,d.element),f.outerNode&&f.innerNode&&f.parent){if(1===b.childNodes.length){for(;b.firstChild.firstChild;)f.innerNode.appendChild(b.firstChild.firstChild);b.firstChild.appendChild(f.outerNode)}d.selection.splitElementAtCaret(f.parent,b)}else{var o=b.firstChild,p=b.lastChild;c.insertNode(b),c.setStartBefore(o),c.setEndAfter(p)}}function s(b,d,e){for(var f,h,i=b.cloneRange(),j=c(i.startContainer,i.startOffset).previousSibling,k=c(i.endContainer,i.endOffset).nextSibling,l=i.extractContents(),m=e.doc.createDocumentFragment(),o=!0;l.firstChild;){if(1===l.firstChild.nodeType&&l.firstChild.matches(E)){n(l.firstChild),f=a.dom.unwrap(l.firstChild),f.length>0&&(m.lastChild&&(1!==m.lastChild.nodeType||!g(m.lastChild,e))||!m.lastChild&&j&&(1!==j.nodeType||g(j,e)))&&m.appendChild(e.doc.createElement("BR"));for(var p=0,q=f.length;q>p;p++)m.appendChild(f[p]);f.length>0&&(1===m.lastChild.nodeType&&g(m.lastChild,e)||(k||m.lastChild!==l.lastChild)&&m.appendChild(e.doc.createElement("BR")))}else m.appendChild(l.firstChild);o=!1}return h=a.lang.array(m.childNodes).get(),r(m,i,e),h}function t(b,c,e){var f=b&&a.dom.domNode(b).prev({nodeTypes:[1,3],ignoreBlankTexts:!0});d(c)&&c.parentNode.removeChild(c),!d(b)||f&&1===f.nodeType&&"block"===e.win.getComputedStyle(f).display||b.parentNode.removeChild(b)}function u(a,b,c){var e;a&&f(a)&&(a=a.previousSibling),b&&f(b)&&(b=b.nextSibling),e=a&&a.previousSibling,a&&(1!==a.nodeType||"block"!==c.win.getComputedStyle(a).display&&!d(a))&&a.parentNode&&a.parentNode.insertBefore(c.doc.createElement("br"),a.nextSibling),b&&(1!==b.nodeType||"block"!==c.win.getComputedStyle(b).display)&&b.parentNode&&b.parentNode.insertBefore(c.doc.createElement("br"),b)}function v(d,e,f,g){var h,i,k=e?b(e):null,m=d.cloneRange(),o=m.startContainer,p=c(m.startContainer,m.startOffset),s=c(m.endContainer,m.endOffset),u=m.startContainer!==p||3!==p.nodeType||G(p,m.startOffset)?a.dom.domNode(p).prev({nodeTypes:[1,3],ignoreBlankTexts:!0}):p,v=1===m.endContainer.nodeType&&m.endContainer.childNodes[m.endOffset]===s&&(1===s.nodeType||!H(s,m.endOffset)&&!a.dom.domNode(s).is.rangyBookmark())||m.endContainer===s&&3===s.nodeType&&!H(s,m.endOffset)?s:a.dom.domNode(s).next({nodeTypes:[1,3],ignoreBlankTexts:!0}),w=m.extractContents(),x=g.doc.createDocumentFragment(),y=k?a.dom.getParentElement(o,k,null,g.element):null,z=!f||!e||"BLOCKQUOTE"===e.nodeName&&"BLOCKQUOTE"===f,A=y||j(o,g.element,z);if(a.dom.domNode(v).is.rangyBookmark()&&(s=v,v=s.nextSibling),I(w),e&&"BLOCKQUOTE"===e.nodeName){var B=l(null,e,g);B.appendChild(w),x.appendChild(B),i=[B]}else{if(w.firstChild)for(;w.firstChild;)if(1==w.firstChild.nodeType&&w.firstChild.matches(E))l(w.firstChild,e,g),w.firstChild.matches(D)&&n(w.firstChild),x.appendChild(w.firstChild);else{for(h=l(null,q(e,f,g),g);w.firstChild&&(1!==w.firstChild.nodeType||!w.firstChild.matches(E));)1==w.firstChild.nodeType&&h.matches(D)&&n(w.firstChild),h.appendChild(w.firstChild);x.appendChild(h)}else x.appendChild(l(null,e,g));i=a.lang.array(x.childNodes).get()}return r(x,m,g,A),t(u,v,g),i.length>0&&("undefined"==typeof i[i.length-1].lastChild||a.dom.domNode(i[i.length-1].lastChild).is.rangyBookmark())&&i[i.length-1].appendChild(g.doc.createElement("br")),i}function w(b,c){var d=a.dom.getParentElement(b,{query:E},null,c.element);return d?d.nodeName:null}function x(b,c){var d,e=a.dom.getParentElement(b.selection.getOwnRanges()[0].startContainer,{query:D+", "+(c?c.toLowerCase():"div")},null,b.element);e?(d=b.selection.createRange(),d.selectNode(e),b.selection.setSelection(d)):b.isEmpty()||b.selection.selectLine()}function y(a,b){var c=b.selection.createRange(),d=a[a.length-1],e=1===d.nodeType&&d.childNodes?0|d.childNodes.length:d.length||0;c.setStart(a[0],0),c.setEnd(d,e),c.select()}function z(a,b,c){var d,e=b.selection.getOwnRanges(),f=[];e=p(e);for(var g=e.length;g--;)o(e[g],b),d=w(e[g].startContainer,b),f="remove"===a?f.concat(s(e[g],d,b)):f.concat(v(e[g],c,d,b));return f}function A(a){return"string"==typeof a&&(a={nodeName:a.toUpperCase()}),a}function B(b){var c;return b.selection.isCollapsed()&&(c=b.selection.getNodesNearCaret(),c&&c.caretNode&&(a.dom.domNode(c.caretNode).is.lineBreak()||3===c.caretNode.nodeType&&0===c.textOffset&&(!c.prevNode||a.dom.domNode(c.prevNode).is.lineBreak())||1===c.caretNode.nodeType&&c.caretNode.classList.contains("rangySelectionBoundary")&&(!c.prevNode||a.dom.domNode(c.prevNode).is.lineBreak()||a.dom.domNode(c.prevNode).is.block())&&(!c.nextNode||a.dom.domNode(c.nextNode).is.lineBreak()||a.dom.domNode(c.nextNode).is.block())))?!0:!1}var C=a.dom,D="h1, h2, h3, h4, h5, h6, p, pre",E="h1, h2, h3, h4, h5, h6, p, pre, div, blockquote",F="b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u",G=function(a,b){var c=a.data?a.data.slice(0,b):"";return/^\s*$/.test(c)},H=function(a,b){var c=a.data?a.data.slice(b):"";return/^\s*$/.test(c)},I=function(a){if(a){for(;a.firstChild&&3===a.firstChild.nodeType&&/^\s*$/.test(a.firstChild.data)&&a.lastChild!==a.firstChild;)a.removeChild(a.firstChild);for(;a.lastChild&&3===a.lastChild.nodeType&&/^\s*$/.test(a.lastChild.data)&&a.lastChild!==a.firstChild;)a.removeChild(a.lastChild);a.firstChild&&1===a.firstChild.nodeType&&"BR"===a.firstChild.nodeName&&a.lastChild!==a.firstChild&&a.removeChild(a.firstChild),a.lastChild&&1===a.lastChild.nodeType&&"BR"===a.lastChild.nodeName&&a.lastChild!==a.firstChild&&a.removeChild(a.lastChild)}};a.commands.formatBlock={exec:function(a,b,c){c=A(c);var d,e,f=[];if(c&&c.toggle&&(e=this.state(a,b,c)),e){d=rangy.saveSelection(a.win);for(var g=0,i=e.length;i>g;g++)m(e[g],c,a)}else a.selection.isCollapsed()&&(d=rangy.saveSelection(a.win),B(a)?a.selection.selectLine():x(a,c&&c.nodeName?c.nodeName.toUpperCase():void 0)),f=c?z("apply",a,c):z("remove",a);f=h(a,f),d?rangy.restoreSelection(d):y(f,a)},remove:function(a,b,c){c=A(c);var d,e;a.selection.isCollapsed()&&(e=rangy.saveSelection(a.win),x(a,c&&c.nodeName?c.nodeName.toUpperCase():void 0)),d=z("remove",a),d=h(a,d),e?rangy.restoreSelection(e):y(d,a)},state:function(b,c,d){d=A(d);for(var e,f=b.selection.filterElements(function(b){return a.dom.domNode(b).test(d||{query:E})}.bind(this)),g=b.selection.getSelectedOwnNodes(),h=0,i=g.length;i>h;h++)e=C.getParentElement(g[h],d||{query:E},null,b.element),e&&-1===f.indexOf(e)&&f.push(e);return 0===f.length?!1:f}}}(wysihtml5),function(a){a.commands.formatCode={exec:function(b,c,d){var e,f,g,h=this.state(b)[0];h?b.selection.executeAndRestore(function(){e=h.querySelector("code"),a.dom.replaceWithChildNodes(h),e&&a.dom.replaceWithChildNodes(e)}):(f=b.selection.getRange(),g=f.extractContents(),h=b.doc.createElement("pre"),e=b.doc.createElement("code"),d&&(e.className=d),h.appendChild(e),e.appendChild(g),f.insertNode(h),b.selection.selectNode(h))},state:function(b){var c,d=b.selection.getSelectedNode();return d&&d.nodeName&&"PRE"==d.nodeName&&d.firstChild&&d.firstChild.nodeName&&"CODE"==d.firstChild.nodeName?[d]:(c=a.dom.getParentElement(d,{query:"pre code"}),c?[c.parentNode]:!1)}}}(wysihtml5),function(a){function b(a){return/^\s*$/.test(a.className)}function c(a){return!a.getAttribute("style")||/^\s*$/.test(a.getAttribute("style"))}function d(b){var c=a.dom.getAttributes(b);return a.lang.object(c).isEmpty()}function e(b,c){var d,e,f,g;return 1!==b.nodeType||1!==c.nodeType?!1:b.nodeName!==c.nodeName?!1:(d=b.className.trim().replace(/\s+/g," ").split(" "),e=c.className.trim().replace(/\s+/g," ").split(" "),a.lang.array(d).without(e).length>0?!1:(f=a.dom.getAttributes(b),g=a.dom.getAttributes(c),f.length===g.length&&a.lang.object(a.lang.object(f).difference(g)).isEmpty()?!0:!1))}function f(b,c){var d=c&&c.nodeName||F,e=b.ownerDocument.createElement(d);if(c.classRegExp&&(e.className=e.className.replace(c.classRegExp,"")),c.className&&e.classList.add(c.className),c.styleProperty&&"undefined"!=typeof c.styleValue&&(e.style[a.browser.fixStyleKey(c.styleProperty)]=c.styleValue),c.attribute)if("object"==typeof c.attribute)for(var f in c.attribute)c.attribute.hasOwnProperty(f)&&e.setAttribute(f,c.attribute[f]);else"undefined"!=typeof c.attributeValue&&e.setAttribute(c.attribute,c.attributeValue);return e}function g(a,b){for(var c in a)if(a.hasOwnProperty(c)&&(void 0===typeof b[c]||b[c]!==a[c]))return!1;return!0}function h(b,c,d){var e,f=a.dom.getAttributes(b),h=g(c,f);a.lang.object(f).difference(c);if(h&&d!==!1)for(e in c)c.hasOwnProperty(e)&&b.removeAttribute(e);else for(e in c)c.hasOwnProperty(e)&&b.setAttribute(e,c[e])}function i(e,f){var g,i,j;f.className&&(f.toggle!==!1&&e.classList.contains(f.className)?e.classList.remove(f.className):(f.classRegExp&&(e.className=e.className.replace(f.classRegExp,"")),e.classList.add(f.className)),b(e)&&e.removeAttribute("class")),f.styleProperty&&(f.toggle!==!1&&e.style[a.browser.fixStyleKey(f.styleProperty)].trim().replace(/, /g,",")===f.styleValue?e.style[a.browser.fixStyleKey(f.styleProperty)]="":e.style[a.browser.fixStyleKey(f.styleProperty)]=f.styleValue),c(e)&&e.removeAttribute("style"),f.attribute&&("object"==typeof f.attribute?g=f.attribute:(g={},g[f.attribute]=f.attributeValue||""),h(e,g,f.toggle)),i=f.nodeName?H[f.nodeName.toLowerCase()]||f.nodeName.toLowerCase():null,j=i?a.dom.domNode(e).test({query:i}):!1,(!f.nodeName||f.nodeName===F||j)&&(f.toggle!==!1&&j||!f.nodeName&&e.nodeName===F)&&b(e)&&c(e)&&d(e)&&a.dom.unwrap(e)}function j(b,c){var d=[];return b.isCollapsed()||(d=d.concat(b.getOwnNodes([3],function(b){return!a.dom.domNode(b).is.emptyTextNode()},c))),d}function k(a,b,c,d){var e=a,f=d?b:l(b);do{if(1===e.nodeType&&m(e,f))return e;e=e.parentNode}while(e&&e!==c);return null}function l(a){return{nodeName:a.nodeName||null,className:a.classRegExp?null:a.className||null,classRegExp:a.classRegExp||null,styleProperty:a.styleProperty||null}}function m(b,c){var d;if(c.nodeName){var e=H[c.nodeName.toLowerCase()]||c.nodeName.toLowerCase();return a.dom.domNode(b).test({query:e})}return d=a.lang.object(c).clone(),d.query=G,a.dom.domNode(b).test(d)}function n(b,c){var d=document.documentElement||document.body,e=d.scrollTop,f=d.scrollLeft;rangy.getSelection(b.win);rangy.getSelection(b.win).removeAllRanges();try{rangy.getSelection(b.win).addRange(c)}catch(g){}b.doc.activeElement&&a.dom.contains(b.element,b.doc.activeElement)||(b.element.focus(),d.scrollTop=e,d.scrollLeft=f,rangy.getSelection(b.win).addRange(c))}function o(a,b){var c=rangy.createRange(b.doc),d=a[a.length-1];a[0]&&d&&(c.setStart(a[0],0),c.setEnd(d,d.length),n(b,c))}function p(a,b,c,d){var e=rangy.createRange(a.doc);b&&(e.setStart(b,c),e.setEnd(b,"undefined"!=typeof d?d:c),n(a,e))}function q(a,b,c){var d,e,f,g=j(a.selection),h=[],i=!1;if(a.selection.isInThisEditable()){if(0===g.length&&a.selection.isCollapsed()){if(f=a.selection.getSelection().anchorNode,!f)return{nodes:[],partial:!1};3===f.nodeType&&(g=[f])}g.length||(e=a.selection.getOwnRanges()[0],e&&(g=[e.endContainer]));for(var l=0,m=g.length;m>l;l++)d=k(g[l],b,a.element,c),d?h.push(d):i=!0}return{nodes:h,partial:i}}function r(a){var b,c,d,e;return a&&(b=a.anchorNode,c=a.anchorOffset,b&&3===b.nodeType&&c>0&&c0&&/\w/.test(c.data[g-1]);)g--;for(;h0&&o(b,a),u(q(a,c).nodes),b.length>0&&o(b,a)}function w(a,b,c,d){p(a,b,c),u(q(a,d).nodes),p(a,b,c)}function x(a,b){var c=f(a,b);a.parentNode.insertBefore(c,a),c.appendChild(a)}function y(b,c,d){var e,f=c.element,g=k(b,d,f);g&&(e=g.cloneNode(!1),a.dom.domNode(b).escapeParent(g,e),i(e,d))}function z(b,c,d){var e=c.element,f=k(b,d,e);f&&a.dom.domNode(b).escapeParent(f)}function A(a,b,c){var d=f(a.endContainer,c);a.surroundContents(d),b.selection.selectNode(d)}function B(b,c,d,e){var f,g,h,j,l=q(b,e,!0),m=b.selection.getSelection();if(c.length){if(l.partial||e.toggle===!1)for(j=c.length;j--;)k(c[j],e,b.element)&&y(c[j],b,e),k(c[j],e,b.element)||x(c[j],e);else for(j=c.length;j--;)y(c[j],b,e);v(b,c,e)}else if(e.toggle!==!1)if(r(m))f=s(m),g=f.textNode,y(f.textNode,b,e),w(b,f.textNode,f.wordOffset,e);else{g=b.doc.createTextNode(a.INVISIBLE_SPACE),h=d.nodes[0].cloneNode(!1),h.appendChild(g),b.selection.splitElementAtCaret(d.nodes[0],h),i(h,e),v(b,[g],e);var n=b.selection.getSelection();if(n.anchorNode&&n.focusNode)try{n.collapseToEnd()}catch(o){}}else for(j=d.nodes.length;j--;)i(d.nodes[j],e)}function C(b,c,d,e){var f,g,h,i=b.selection.getSelection();if(c.length){for(h=c.length;h--;)z(c[h],b,e);v(b,c,e)}else{for(f=i.anchorNode,g=i.anchorOffset,h=d.nodes.length;h--;)a.dom.unwrap(d.nodes[h]);w(b,f,g,e)}}function D(a,b,c){var d,e,f=a.selection.getSelection();if(b.length){for(e=b.length;e--;)x(b[e],c);v(a,b,c)}else if(r(f))d=s(f),x(d.textNode,c),w(a,d.textNode,d.wordOffset,c);else{var g=a.selection.getOwnRanges()[0];g&&A(g,a,c)}}function E(a){
-return a="string"==typeof a?{nodeName:a}:a,a.nodeName&&(a.nodeName=a.nodeName.toUpperCase()),a}var F="SPAN",G="b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u",H={b:"b, strong",strong:"b, strong",em:"em, i",i:"em, i"};a.commands.formatInline={exec:function(a,b,c){c=E(c),a.element.normalize();var d=j(a.selection,!0),e=q(a,c);e.nodes.length>0?B(a,d,e,c):D(a,d,c),a.element.normalize()},remove:function(a,b,c){c=E(c),a.element.normalize();var d=j(a.selection,!0),e=q(a,c);e.nodes.length>0&&C(a,d,e,c),a.element.normalize()},state:function(a,b,c){c=E(c);var d=q(a,c,!0).nodes;return 0===d.length?!1:d}}}(wysihtml5),function(a){var b={nodeName:"BLOCKQUOTE",toggle:!0};a.commands.insertBlockQuote={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){a.commands.insertHTML={exec:function(a,b,c){a.selection.insertHTML(c)},state:function(){return!1}}}(wysihtml5),function(a){var b="IMG";a.commands.insertImage={exec:function(c,d,e){e="object"==typeof e?e:{src:e};var f,g,h=c.doc,i=this.state(c);if(i&&!e.src)return c.selection.setBefore(i),g=i.parentNode,g.removeChild(i),a.dom.removeEmptyTextNodes(g),"A"!==g.nodeName||g.firstChild||(c.selection.setAfter(g),g.parentNode.removeChild(g)),void a.quirks.redraw(c.element);if(i)for(var j in e)e.hasOwnProperty(j)&&i.setAttribute("className"===j?"class":j,e[j]);else{i=h.createElement(b);for(var k in e)i.setAttribute("className"===k?"class":k,e[k]);c.selection.insertNode(i),a.browser.hasProblemsSettingCaretAfterImg()?(f=h.createTextNode(a.INVISIBLE_SPACE),c.selection.insertNode(f),c.selection.setAfter(f)):c.selection.setAfter(i)}},state:function(c){var d,e,f,g=c.doc;return a.dom.hasElementWithTagName(g,b)&&(d=c.selection.getSelectedNode())?d.nodeName===b?d:d.nodeType!==a.ELEMENT_NODE?!1:(e=c.selection.getText(),(e=a.lang.string(e).trim())?!1:(f=c.selection.getNodes(a.ELEMENT_NODE,function(a){return"IMG"===a.nodeName}),1!==f.length?!1:f[0])):!1}}}(wysihtml5),function(a){var b=" "+(a.browser.needsSpaceAfterLineBreak()?" ":"");a.commands.insertLineBreak={exec:function(a,c){a.selection.insertHTML(b)},state:function(){return!1}}}(wysihtml5),function(a){a.commands.insertOrderedList={exec:function(b,c){a.commands.insertList.exec(b,c,"OL")},state:function(b,c){return a.commands.insertList.state(b,c,"OL")}}}(wysihtml5),function(a){a.commands.insertUnorderedList={exec:function(b,c){a.commands.insertList.exec(b,c,"UL")},state:function(b,c){return a.commands.insertList.state(b,c,"UL")}}}(wysihtml5),wysihtml5.commands.insertList=function(a){var b=function(a,b){if(a&&a.nodeName){"string"==typeof b&&(b=[b]);for(var c=b.length;c--;)if(a.nodeName===b[c])return!0}return!1},c=function(c,d,e){var f={el:null,other:!1};if(c){var g=a.dom.getParentElement(c,{query:"li"},!1,e.element),h="UL"===d?"OL":"UL";b(c,d)?f.el=c:b(c,h)?f={el:c,other:!0}:g&&(b(g.parentNode,d)?f.el=g.parentNode:b(g.parentNode,h)&&(f={el:g.parentNode,other:!0}))}return f.el&&!e.element.contains(f.el)&&(f.el=null),f},d=function(b,c,d){var e,g,h="UL"===c?"OL":"UL";d.selection.executeAndRestoreRangy(function(){if(e=f(h,d),e.length)for(var i=e.length;i--;)a.dom.renameElement(e[i],c.toLowerCase());else{g=f(["OL","UL"],d);for(var j=g.length;j--;)a.dom.resolveList(g[j],d.config.useLineBreaks);0===g.length&&a.dom.resolveList(b,d.config.useLineBreaks)}})},e=function(b,c,d){var e="UL"===c?"OL":"UL";d.selection.executeAndRestoreRangy(function(){for(var g=[b].concat(f(e,d)),h=g.length;h--;)a.dom.renameElement(g[h],c.toLowerCase())})},f=function(a,c){for(var d=c.selection.getOwnRanges(),e=[],f=d.length;f--;)e=e.concat(d[f].getNodes([1],function(c){return b(c,a)}));return e},g=function(b,c){var d,e,f=rangy.saveSelection(c.win),g="_wysihtml5-temp-"+(new Date).getTime();c.commands.exec("formatBlock",{nodeName:"div",className:g});var h=c.element.querySelector("."+g);h.innerHTML=h.innerHTML.replace(a.INVISIBLE_SPACE_REG_EXP,""),h&&(d=/^(\s|( ))+$/i.test(h.innerHTML),e=a.dom.convertToList(h,b.toLowerCase(),c.parent.config.classNames.uneditableContainer),f&&rangy.restoreSelection(f),d&&c.selection.selectNode(e.querySelector("li"),!0))};return{exec:function(b,f,h){var i,j,k=b.doc,l="OL"===h?"insertOrderedList":"insertUnorderedList",m=b.selection.getSelection(),n=1===m.anchorNode.nodeType&&m.anchorNode.firstChild?m.anchorNode.childNodes[m.anchorOffset]:m.anchorNode,o=1===m.focusNode.nodeType&&m.focusNode.firstChild?m.focusNode.childNodes[m.focusOffset]||m.focusNode.lastChild:m.focusNode;m.isBackwards()&&(n=[o,o=n][0]),a.dom.domNode(o).is.emptyTextNode(!0)&&o&&(o=a.dom.domNode(o).prev({nodeTypes:[1,3],ignoreBlankTexts:!0})),a.dom.domNode(n).is.emptyTextNode(!0)&&n&&(n=a.dom.domNode(n).next({nodeTypes:[1,3],ignoreBlankTexts:!0})),i=n&&o?n===o?n:a.dom.domNode(n).commonAncestor(o,b.element):b.selection.getSelectedNode(),j=c(i,h,b),j.el?j.other?e(j.el,h,b):d(j.el,h,b):b.commands.support(l)?k.execCommand(l,!1,null):g(h,b)},state:function(a,b,d){var e=a.selection.getSelectedNode(),f=c(e,d,a);return f.el&&!f.other?f.el:!1}}}(wysihtml5),function(a){var b={nodeName:"I",toggle:!0};a.commands.italic={exec:function(c,d){a.commands.formatInline.exec(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){var b={className:"wysiwyg-text-align-center",classRegExp:/wysiwyg-text-align-[0-9a-z]+/g,toggle:!0};a.commands.justifyCenter={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={className:"wysiwyg-text-align-left",classRegExp:/wysiwyg-text-align-[0-9a-z]+/g,toggle:!0};a.commands.justifyLeft={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={className:"wysiwyg-text-align-right",classRegExp:/wysiwyg-text-align-[0-9a-z]+/g,toggle:!0};a.commands.justifyRight={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={className:"wysiwyg-text-align-justify",classRegExp:/wysiwyg-text-align-[0-9a-z]+/g,toggle:!0};a.commands.justifyFull={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={styleProperty:"textAlign",styleValue:"right",toggle:!0};a.commands.alignRightStyle={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={styleProperty:"textAlign",styleValue:"left",toggle:!0};a.commands.alignLeftStyle={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={styleProperty:"textAlign",styleValue:"center",toggle:!0};a.commands.alignCenterStyle={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={styleProperty:"textAlign",styleValue:"justify",toggle:!0};a.commands.alignJustifyStyle={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){a.commands.redo={exec:function(a){return a.undoManager.redo()},state:function(a){return!1}}}(wysihtml5),function(a){var b={nodeName:"U",toggle:!0};a.commands.underline={exec:function(c,d){a.commands.formatInline.exec(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){a.commands.undo={exec:function(a){return a.undoManager.undo()},state:function(a){return!1}}}(wysihtml5),function(a){a.commands.createTable={exec:function(a,b,c){var d,e,f;if(c&&c.cols&&c.rows&&parseInt(c.cols,10)>0&&parseInt(c.rows,10)>0){for(f=c.tableStyle?'':"",f+="",e=0;e",d=0;d ";f+=""}f+="
",a.commands.exec("insertHTML",f)}},state:function(a,b){return!1}}}(wysihtml5),function(a){a.commands.mergeTableCells={exec:function(b,c){b.tableSelection&&b.tableSelection.start&&b.tableSelection.end&&(this.state(b,c)?a.dom.table.unmergeCell(b.tableSelection.start):a.dom.table.mergeCellsBetween(b.tableSelection.start,b.tableSelection.end))},state:function(b,c){if(b.tableSelection){var d=b.tableSelection.start,e=b.tableSelection.end;if(d&&e&&d==e&&(a.dom.getAttribute(d,"colspan")&&parseInt(a.dom.getAttribute(d,"colspan"),10)>1||a.dom.getAttribute(d,"rowspan")&&parseInt(a.dom.getAttribute(d,"rowspan"),10)>1))return[d]}return!1}}}(wysihtml5),function(a){a.commands.addTableCells={exec:function(b,c,d){if(b.tableSelection&&b.tableSelection.start&&b.tableSelection.end){var e=a.dom.table.orderSelectionEnds(b.tableSelection.start,b.tableSelection.end);"before"==d||"above"==d?a.dom.table.addCells(e.start,d):("after"==d||"below"==d)&&a.dom.table.addCells(e.end,d),setTimeout(function(){b.tableSelection.select(e.start,e.end)},0)}},state:function(a,b){return!1}}}(wysihtml5),function(a){a.commands.deleteTableCells={exec:function(b,c,d){if(b.tableSelection&&b.tableSelection.start&&b.tableSelection.end){var e,f=a.dom.table.orderSelectionEnds(b.tableSelection.start,b.tableSelection.end),g=a.dom.table.indexOf(f.start),h=b.tableSelection.table;a.dom.table.removeCells(f.start,d),setTimeout(function(){e=a.dom.table.findCell(h,g),e||("row"==d&&(e=a.dom.table.findCell(h,{row:g.row-1,col:g.col})),"column"==d&&(e=a.dom.table.findCell(h,{row:g.row,col:g.col-1}))),e&&b.tableSelection.select(e,e)},0)}},state:function(a,b){return!1}}}(wysihtml5),function(a){a.commands.indentList={exec:function(a,b,c){var d=a.selection.getSelectionParentsByTag("LI");return d?this.tryToPushLiLevel(d,a.selection):!1},state:function(a,b){return!1},tryToPushLiLevel:function(b,c){var d,e,f,g,h,i=!1;return c.executeAndRestoreRangy(function(){for(var c=b.length;c--;)g=b[c],d="OL"===g.parentNode.nodeName?"OL":"UL",e=g.ownerDocument.createElement(d),f=a.dom.domNode(g).prev({nodeTypes:[a.ELEMENT_NODE]}),h=f?f.querySelector("ul, ol"):null,f&&(h?h.appendChild(g):(e.appendChild(g),f.appendChild(e)),i=!0)}),i}}}(wysihtml5),function(a){a.commands.outdentList={exec:function(a,b,c){var d=a.selection.getSelectionParentsByTag("LI");return d?this.tryToPullLiLevel(d,a):!1},state:function(a,b){return!1},tryToPullLiLevel:function(b,c){var d,e,f,g,h,i=!1,j=this;return c.selection.executeAndRestoreRangy(function(){for(var k=b.length;k--;)if(g=b[k],g.parentNode&&(d=g.parentNode,"OL"===d.tagName||"UL"===d.tagName)){if(i=!0,e=a.dom.getParentElement(d.parentNode,{query:"ol, ul"},!1,c.element),f=a.dom.getParentElement(d.parentNode,{query:"li"},!1,c.element),e&&f)g.nextSibling&&(h=j.getAfterList(d,g),g.appendChild(h)),e.insertBefore(g,f.nextSibling);else{g.nextSibling&&(h=j.getAfterList(d,g),g.appendChild(h));for(var l=g.childNodes.length;l--;)d.parentNode.insertBefore(g.childNodes[l],d.nextSibling);d.parentNode.insertBefore(document.createElement("br"),d.nextSibling),g.parentNode.removeChild(g)}0===d.childNodes.length&&d.parentNode.removeChild(d)}}),i},getAfterList:function(a,b){for(var c=a.nodeName,d=document.createElement(c);b.nextSibling;)d.appendChild(b.nextSibling);return d}}}(wysihtml5),function(a){var b={nodeName:"SUB",toggle:!0};a.commands.subscript={exec:function(c,d){a.commands.formatInline.exec(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){var b={nodeName:"SUP",toggle:!0};a.commands.superscript={exec:function(c,d){a.commands.formatInline.exec(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){var b=90,c=89,d=8,e=46,f=25,g="data-wysihtml5-selection-node",h="data-wysihtml5-selection-offset",i=(''+a.INVISIBLE_SPACE+" ",''+a.INVISIBLE_SPACE+" ",a.dom);a.UndoManager=a.lang.Dispatcher.extend({constructor:function(a){this.editor=a,this.composer=a.composer,this.element=this.composer.element,this.position=0,this.historyStr=[],this.historyDom=[],this.transact(),this._observe()},_observe:function(){var a,f=this;this.composer.sandbox.getDocument();i.observe(this.element,"keydown",function(a){if(!a.altKey&&(a.ctrlKey||a.metaKey)){var d=a.keyCode,e=d===b&&!a.shiftKey,g=d===b&&a.shiftKey||d===c;e?(f.undo(),a.preventDefault()):g&&(f.redo(),a.preventDefault())}}),i.observe(this.element,"keydown",function(b){var c=b.keyCode;c!==a&&(a=c,(c===d||c===e)&&f.transact())}),this.editor.on("newword:composer",function(){f.transact()}).on("beforecommand:composer",function(){f.transact()})},transact:function(){var b,c,d,e,i,j=this.historyStr[this.position-1],k=this.composer.getValue(!1,!1),l=this.element.offsetWidth>0&&this.element.offsetHeight>0;if(k!==j){var m=this.historyStr.length=this.historyDom.length=this.position;m>f&&(this.historyStr.shift(),this.historyDom.shift(),this.position--),this.position++,l&&(b=this.composer.selection.getRange(),c=b&&b.startContainer?b.startContainer:this.element,d=b&&b.startOffset?b.startOffset:0,c.nodeType===a.ELEMENT_NODE?e=c:(e=c.parentNode,i=this.getChildNodeIndex(e,c)),e.setAttribute(h,d),"undefined"!=typeof i&&e.setAttribute(g,i));var n=this.element.cloneNode(!!k);this.historyDom.push(n),this.historyStr.push(k),e&&(e.removeAttribute(h),e.removeAttribute(g))}},undo:function(){this.transact(),this.undoPossible()&&(this.set(this.historyDom[--this.position-1]),this.editor.fire("undo:composer"))},redo:function(){this.redoPossible()&&(this.set(this.historyDom[++this.position-1]),this.editor.fire("redo:composer"))},undoPossible:function(){return this.position>1},redoPossible:function(){return this.positionb;b++)this.element.appendChild(c[b].cloneNode(!0));var e,f,i;a.hasAttribute(h)?(e=a.getAttribute(h),i=a.getAttribute(g),f=this.element):(f=this.element.querySelector("["+h+"]")||this.element,e=f.getAttribute(h),i=f.getAttribute(g),f.removeAttribute(h),f.removeAttribute(g)),null!==i&&(f=this.getChildNodeByIndex(f,+i)),this.composer.selection.set(f,e)},getChildNodeIndex:function(a,b){for(var c=0,d=a.childNodes,e=d.length;e>c;c++)if(d[c]===b)return c},getChildNodeByIndex:function(a,b){return a.childNodes[b]}})}(wysihtml5),wysihtml5.views.View=Base.extend({constructor:function(a,b,c){this.parent=a,this.element=b,this.config=c,this.config.noTextarea||this._observeViewChange()},_observeViewChange:function(){var a=this;this.parent.on("beforeload",function(){a.parent.on("change_view",function(b){b===a.name?(a.parent.currentView=a,a.show(),setTimeout(function(){a.focus()},0)):a.hide()})})},focus:function(){if(!this.element||!this.element.ownerDocument||this.element.ownerDocument.querySelector(":focus")!==this.element)try{this.element&&this.element.focus()}catch(a){}},hide:function(){this.element.style.display="none"},show:function(){this.element.style.display=""},disable:function(){this.element.setAttribute("disabled","disabled")},enable:function(){this.element.removeAttribute("disabled")}}),function(a){var b=a.dom,c=a.browser;a.views.Composer=a.views.View.extend({name:"composer",constructor:function(a,b,c){this.base(a,b,c),this.config.noTextarea?this.editableArea=b:this.textarea=this.parent.textarea,this.config.contentEditableMode?this._initContentEditableArea():this._initSandbox()},clear:function(){this.element.innerHTML=c.displaysCaretInEmptyContentEditableCorrectly()?"":" "},getValue:function(b,c){var d=this.isEmpty()?"":a.quirks.getCorrectInnerHTML(this.element);return b!==!1&&(d=this.parent.parse(d,c===!1?!1:!0)),d},setValue:function(a,b){b!==!1&&(a=this.parent.parse(a));try{this.element.innerHTML=a}catch(c){this.element.innerText=a}},cleanUp:function(a){var b;this.selection&&this.selection.isInThisEditable()&&(b=rangy.saveSelection(this.win)),this.parent.parse(this.element,void 0,a),b&&rangy.restoreSelection(b)},show:function(){this.editableArea.style.display=this._displayStyle||"",this.config.noTextarea||this.textarea.element.disabled||(this.disable(),this.enable())},hide:function(){this._displayStyle=b.getStyle("display").from(this.editableArea),"none"===this._displayStyle&&(this._displayStyle=null),this.editableArea.style.display="none"},disable:function(){this.parent.fire("disable:composer"),this.element.removeAttribute("contentEditable")},enable:function(){this.parent.fire("enable:composer"),this.element.setAttribute("contentEditable","true")},focus:function(b){a.browser.doesAsyncFocus()&&this.hasPlaceholderSet()&&this.clear(),this.base();var c=this.element.lastChild;b&&c&&this.selection&&("BR"===c.nodeName?this.selection.setBefore(this.element.lastChild):this.selection.setAfter(this.element.lastChild))},getScrollPos:function(){if(this.doc&&this.win){var a={};return"undefined"!=typeof this.win.pageYOffset?a.y=this.win.pageYOffset:a.y=(this.doc.documentElement||this.doc.body.parentNode||this.doc.body).scrollTop,"undefined"!=typeof this.win.pageXOffset?a.x=this.win.pageXOffset:a.x=(this.doc.documentElement||this.doc.body.parentNode||this.doc.body).scrollLeft,a}},setScrollPos:function(a){a&&"undefined"!=typeof a.x&&"undefined"!=typeof a.y&&this.win.scrollTo(a.x,a.y)},getTextContent:function(){return b.getTextContent(this.element)},hasPlaceholderSet:function(){return this.getTextContent()==(this.config.noTextarea?this.editableArea.getAttribute("data-placeholder"):this.textarea.element.getAttribute("placeholder"))&&this.placeholderSet},isEmpty:function(){var a=this.element.innerHTML.toLowerCase();return/^(\s| |<\/br>||<\/p>)*$/i.test(a)||""===a||" "===a||"
"===a||"
"===a||this.hasPlaceholderSet()},_initContentEditableArea:function(){var a=this;this.config.noTextarea?this.sandbox=new b.ContentEditableArea(function(){a._create()},{className:this.config.classNames.sandbox},this.editableArea):(this.sandbox=new b.ContentEditableArea(function(){a._create()},{className:this.config.classNames.sandbox}),this.editableArea=this.sandbox.getContentEditable(),b.insert(this.editableArea).after(this.textarea.element),this._createWysiwygFormField())},_initSandbox:function(){var a=this;this.sandbox=new b.Sandbox(function(){a._create()},{stylesheets:this.config.stylesheets,className:this.config.classNames.sandbox}),this.editableArea=this.sandbox.getIframe();var c=this.textarea.element;b.insert(this.editableArea).after(c),this._createWysiwygFormField()},_createWysiwygFormField:function(){if(this.textarea.element.form){var a=document.createElement("input");a.type="hidden",a.name="_wysihtml5_mode",a.value=1,b.insert(a).after(this.textarea.element)}},_create:function(){var d=this;this.doc=this.sandbox.getDocument(),this.win=this.sandbox.getWindow(),this.element=this.config.contentEditableMode?this.sandbox.getContentEditable():this.doc.body,this.config.noTextarea?this.cleanUp():(this.textarea=this.parent.textarea,this.element.innerHTML=this.textarea.getValue(!0,!1)),this.selection=new a.Selection(this.parent,this.element,this.config.classNames.uneditableContainer),this.commands=new a.Commands(this.parent),this.config.noTextarea||b.copyAttributes(["className","spellcheck","title","lang","dir","accessKey"]).from(this.textarea.element).to(this.element),this._initAutoLinking(),b.addClass(this.element,this.config.classNames.composer),this.config.style&&!this.config.contentEditableMode&&this.style(),this.observe();var e=this.config.name;e&&(b.addClass(this.element,e),this.config.contentEditableMode||b.addClass(this.editableArea,e)),this.enable(),!this.config.noTextarea&&this.textarea.element.disabled&&this.disable();var f="string"==typeof this.config.placeholder?this.config.placeholder:this.config.noTextarea?this.editableArea.getAttribute("data-placeholder"):this.textarea.element.getAttribute("placeholder");f&&b.simulatePlaceholder(this.parent,this,f,this.config.classNames.placeholder),this.commands.exec("styleWithCSS",!1),this._initObjectResizing(),this._initUndoManager(),this._initLineBreaking(),this.config.noTextarea||!this.textarea.element.hasAttribute("autofocus")&&document.querySelector(":focus")!=this.textarea.element||c.isIos()||setTimeout(function(){d.focus(!0)},100),c.clearsContentEditableCorrectly()||a.quirks.ensureProperClearing(this),this.initSync&&this.config.sync&&this.initSync(),this.config.noTextarea||this.textarea.hide(),this.parent.fire("beforeload").fire("load")},_initAutoLinking:function(){var d=this,e=c.canDisableAutoLinking(),f=c.doesAutoLinkingInContentEditable();if(e&&this.commands.exec("AutoUrlDetect",!1,!1),this.config.autoLink){(!f||f&&e)&&(this.parent.on("newword:composer",function(){if(b.getTextContent(d.element).match(b.autoLink.URL_REG_EXP)){for(var c=d.selection.getSelectedNode(),e=d.element.querySelectorAll("."+d.config.classNames.uneditableContainer),f=!1,g=e.length;g--;)a.dom.contains(e[g],c)&&(f=!0);f||b.autoLink(c,[d.config.classNames.uneditableContainer])}}),b.observe(this.element,"blur",function(){b.autoLink(d.element,[d.config.classNames.uneditableContainer])}));var g=this.sandbox.getDocument().getElementsByTagName("a"),h=b.autoLink.URL_REG_EXP,i=function(c){var d=a.lang.string(b.getTextContent(c)).trim();return"www."===d.substr(0,4)&&(d="http://"+d),d};b.observe(this.element,"keydown",function(a){if(g.length){var c,e=d.selection.getSelectedNode(a.target.ownerDocument),f=b.getParentElement(e,{query:"a"},4);f&&(c=i(f),setTimeout(function(){var a=i(f);a!==c&&a.match(h)&&f.setAttribute("href",a)},0))}})}},_initObjectResizing:function(){if(this.commands.exec("enableObjectResizing",!0),c.supportsEvent("resizeend")){var d=["width","height"],e=d.length,f=this.element;b.observe(f,"resizeend",function(b){var c,g=b.target||b.srcElement,h=g.style,i=0;if("IMG"===g.nodeName){for(;e>i;i++)c=d[i],h[c]&&(g.setAttribute(c,parseInt(h[c],10)),h[c]="");a.quirks.redraw(f)}})}},_initUndoManager:function(){this.undoManager=new a.UndoManager(this.parent)},_initLineBreaking:function(){function d(a){var c=b.getParentElement(a,{query:"p, div"},2);c&&b.contains(e.element,c)&&e.selection.executeAndRestoreRangy(function(){e.config.useLineBreaks?((!c.firstChild||c.firstChild===c.lastChild&&1===c.firstChild.nodeType&&c.firstChild.classList.contains("rangySelectionBoundary"))&&c.appendChild(e.doc.createElement("br")),b.replaceWithChildNodes(c)):"P"!==c.nodeName&&b.renameElement(c,"p")})}var e=this,f="li, p, h1, h2, h3, h4, h5, h6",g="ul, ol, menu";this.config.useLineBreaks||b.observe(this.element,["focus"],function(){e.isEmpty()&&setTimeout(function(){var a=e.doc.createElement("P");e.element.innerHTML="",e.element.appendChild(a),c.displaysCaretInEmptyContentEditableCorrectly()?e.selection.selectNode(a,!0):(a.innerHTML=" ",e.selection.setBefore(a.firstChild))},0)}),b.observe(this.element,"keydown",function(c){var h=c.keyCode;if(!(c.shiftKey||c.ctrlKey||c.defaultPrevented||h!==a.ENTER_KEY&&h!==a.BACKSPACE_KEY)){var i=b.getParentElement(e.selection.getSelectedNode(),{query:f},4);return i?void setTimeout(function(){var c,f=e.selection.getSelectedNode();if("LI"===i.nodeName){if(!f)return;c=b.getParentElement(f,{query:g},2),c||d(f)}h===a.ENTER_KEY&&i.nodeName.match(/^H[1-6]$/)&&d(f)},0):void(e.config.useLineBreaks&&h===a.ENTER_KEY&&!a.browser.insertsLineBreaksOnReturn()&&(c.preventDefault(),e.commands.exec("insertLineBreak")))}})}})}(wysihtml5),function(a){var b=a.dom,c=document,d=window,e=c.createElement("div"),f=["background-color","color","cursor","font-family","font-size","font-style","font-variant","font-weight","line-height","letter-spacing","text-align","text-decoration","text-indent","text-rendering","word-break","word-wrap","word-spacing"],g=["background-color","border-collapse","border-bottom-color","border-bottom-style","border-bottom-width","border-left-color","border-left-style","border-left-width","border-right-color","border-right-style","border-right-width","border-top-color","border-top-style","border-top-width","clear","display","float","margin-bottom","margin-left","margin-right","margin-top","outline-color","outline-offset","outline-width","outline-style","padding-left","padding-right","padding-top","padding-bottom","position","top","left","right","bottom","z-index","vertical-align","text-align","-webkit-box-sizing","-moz-box-sizing","-ms-box-sizing","box-sizing","-webkit-box-shadow","-moz-box-shadow","-ms-box-shadow","box-shadow","-webkit-border-top-right-radius","-moz-border-radius-topright","border-top-right-radius","-webkit-border-bottom-right-radius","-moz-border-radius-bottomright","border-bottom-right-radius","-webkit-border-bottom-left-radius","-moz-border-radius-bottomleft","border-bottom-left-radius","-webkit-border-top-left-radius","-moz-border-radius-topleft","border-top-left-radius","width","height"],h=["html { height: 100%; }","body { height: 100%; padding: 1px 0 0 0; margin: -1px 0 0 0; }","body > p:first-child { margin-top: 0; }","._wysihtml5-temp { display: none; }",a.browser.isGecko?"body.placeholder { color: graytext !important; }":"body.placeholder { color: #a9a9a9 !important; }","img:-moz-broken { -moz-force-broken-image-icon: 1; height: 24px; width: 24px; }"],i=function(a){if(a.setActive)try{a.setActive()}catch(e){}else{var f=a.style,g=c.documentElement.scrollTop||c.body.scrollTop,h=c.documentElement.scrollLeft||c.body.scrollLeft,i={position:f.position,top:f.top,left:f.left,WebkitUserSelect:f.WebkitUserSelect};b.setStyles({position:"absolute",top:"-99999px",left:"-99999px",WebkitUserSelect:"none"}).on(a),a.focus(),b.setStyles(i).on(a),d.scrollTo&&d.scrollTo(h,g)}};a.views.Composer.prototype.style=function(){var d,j=this,k=c.querySelector(":focus"),l=this.textarea.element,m=l.hasAttribute("placeholder"),n=m&&l.getAttribute("placeholder"),o=l.style.display,p=l.disabled;this.focusStylesHost=e.cloneNode(!1),this.blurStylesHost=e.cloneNode(!1),this.disabledStylesHost=e.cloneNode(!1),m&&l.removeAttribute("placeholder"),l===k&&l.blur(),l.disabled=!1,l.style.display=d="none",(l.getAttribute("rows")&&"auto"===b.getStyle("height").from(l)||l.getAttribute("cols")&&"auto"===b.getStyle("width").from(l))&&(l.style.display=d=o),b.copyStyles(g).from(l).to(this.editableArea).andTo(this.blurStylesHost),b.copyStyles(f).from(l).to(this.element).andTo(this.blurStylesHost),b.insertCSS(h).into(this.element.ownerDocument),l.disabled=!0,b.copyStyles(g).from(l).to(this.disabledStylesHost),b.copyStyles(f).from(l).to(this.disabledStylesHost),l.disabled=p,l.style.display=o,i(l),l.style.display=d,b.copyStyles(g).from(l).to(this.focusStylesHost),b.copyStyles(f).from(l).to(this.focusStylesHost),l.style.display=o,b.copyStyles(["display"]).from(l).to(this.editableArea);var q=a.lang.array(g).without(["display"]);return k?k.focus():l.blur(),m&&l.setAttribute("placeholder",n),this.parent.on("focus:composer",function(){b.copyStyles(q).from(j.focusStylesHost).to(j.editableArea),b.copyStyles(f).from(j.focusStylesHost).to(j.element)}),this.parent.on("blur:composer",function(){b.copyStyles(q).from(j.blurStylesHost).to(j.editableArea),b.copyStyles(f).from(j.blurStylesHost).to(j.element)}),this.parent.observe("disable:composer",function(){b.copyStyles(q).from(j.disabledStylesHost).to(j.editableArea),b.copyStyles(f).from(j.disabledStylesHost).to(j.element)}),this.parent.observe("enable:composer",function(){b.copyStyles(q).from(j.blurStylesHost).to(j.editableArea),b.copyStyles(f).from(j.blurStylesHost).to(j.element)}),this}}(wysihtml5),function(a){var b=a.dom,c=b.domNode,d=a.browser,e={66:"bold",73:"italic",85:"underline"},f={addListeners:function(a,b,c){for(var d=0,e=b.length;e>d;d++)a.addEventListener(b[d],c,!1)},removeListeners:function(a,b,c){for(var d=0,e=b.length;e>d;d++)a.removeEventListener(b[d],c,!1)},fixLastBrDeletionInTable:function(b,c){if(b.selection.caretIsLastInSelection()){var d=b.selection.getSelection(),e=d.anchorNode;if(e&&1===e.nodeType&&(a.dom.getParentElement(e,{query:"td, th"},!1,b.element)||c)){var f=e.childNodes[d.anchorOffset];if(f&&1===f.nodeType&"BR"===f.nodeName)return f.parentNode.removeChild(f),!0}}return!1},handleUneditableDeletion:function(a){var b=a.selection.getBeforeSelection(!0);if(b&&("element"===b.type||"leafnode"===b.type)&&1===b.node.nodeType&&b.node.classList.contains(a.config.classNames.uneditableContainer)){if(f.fixLastBrDeletionInTable(a,!0))return!0;try{var c=new CustomEvent("wysihtml5:uneditable:delete",{bubbles:!0,cancelable:!1});b.node.dispatchEvent(c)}catch(d){}return b.node.parentNode.removeChild(b.node),!0}return!1},fixDeleteInTheBeginningOfBlock:function(b){var d=b.selection,e=d.getPreviousNode();if(d.caretIsFirstInSelection(a.browser.usesControlRanges())&&e&&1===e.nodeType&&a.dom.domNode(e).is.block()&&!c(e).test({query:"ol, ul, table, tr, dl"})){if(/^\s*$/.test(e.textContent||e.innerText))return e.parentNode.removeChild(e),!0;if(e.lastChild){var f=e.lastChild,g=d.getSelectedNode(),h=c(e).commonAncestor(g,b.element),i=a.dom.getParentElement(g,{query:"h1, h2, h3, h4, h5, h6, p, pre, div, blockquote"},!1,h||b.element);if(i)return c(i).transferContentTo(e,!0),d.setAfter(f),!0;if(a.browser.usesControlRanges())return g=d.getCaretNode(),c(g).transferContentTo(e,!0),d.setAfter(f),!0}}return!1},fixDeleteInTheBeginningOfLi:function(b){if(a.browser.hasLiDeletingProblem()){var d,e,f=b.selection.getSelection(),g=f.anchorNode,h=b.selection.caretIsFirstInSelection();if(3===g.nodeType&&0===f.anchorOffset&&g===g.parentNode.firstChild&&(g=g.parentNode,h=!0),h&&g&&1===g.nodeType&&"LI"===g.nodeName&&(d=c(g).prev({nodeTypes:[1,3],ignoreBlankTexts:!0}),d||!g.parentNode||"UL"!==g.parentNode.nodeName&&"OL"!==g.parentNode.nodeName||(d=c(g.parentNode).prev({nodeTypes:[1,3],ignoreBlankTexts:!0})),d))return e=g.firstChild,c(g).transferContentTo(d,!0),e?b.selection.setBefore(e):d&&(1===d.nodeType?d.lastChild?b.selection.setAfter(d.lastChild):b.selection.selectNode(d):b.selection.setAfter(d)),!0}return!1},fixDeleteInTheBeginningOfControlSelection:function(a){var b,d=a.selection,e=d.getPreviousNode(),f=d.getSelectedNode();return d.caretIsFirstInSelection()?(3===f.nodeType&&(f=f.parentNode),b=f.firstChild,c(f).transferContentTo(e,!0),b&&a.selection.setBefore(b),!0):!1},initTableHandling:function(){var b=function(){window.removeEventListener("load",b),this.doc.execCommand("enableObjectResizing",!1,"false"),this.doc.execCommand("enableInlineTableEditing",!1,"false")}.bind(this),c=function(){b.call(this),f.removeListeners(this.sandbox.getIframe(),["focus","mouseup","mouseover"],c)}.bind(this);this.doc.execCommand&&a.browser.supportsCommand(this.doc,"enableObjectResizing")&&a.browser.supportsCommand(this.doc,"enableInlineTableEditing")&&(this.sandbox.getIframe?f.addListeners(this.sandbox.getIframe(),["focus","mouseup","mouseover"],c):window.addEventListener("load",b)),this.tableSelection=a.quirks.tableCellsSelection(this.element,this.parent)},doLineBreaksModeEnterWithCaret:function(d){var e,f,g="p, pre, div, blockquote",h=!1;if(e=d.selection.getNodesNearCaret(),e&&((e.caretNode||e.nextNode)&&(f=b.getParentElement(e.caretNode||e.nextNode,{query:g},2),f===d.element&&(f=void 0)),f&&e.caretNode))if(c(e.caretNode).is.lineBreak()){if(d.config.doubleLineBreakEscapesBlock){h=!0,e.caretNode.parentNode.removeChild(e.caretNode),c(e.nextNode).is.lineBreak()&&e.nextNode.parentNode.removeChild(e.nextNode);var i=d.doc.createElement("br");c(e.nextNode).is.lineBreak()&&e.nextNode===f.lastChild?f.parentNode.insertBefore(i,f.nextSibling):d.selection.splitElementAtCaret(f,i),e.nextNode&&3===e.nextNode.nodeType&&(e.nextNode.data=e.nextNode.data.replace(/^ *[\r\n]+/,"")),
-d.selection.setBefore(i)}}else if(3===e.caretNode.nodeType&&a.browser.hasCaretBlockElementIssue()&&e.textOffset===e.caretNode.data.length&&!e.nextNode){h=!0;var j=d.doc.createElement("br"),k=d.doc.createElement("br"),l=d.doc.createDocumentFragment();l.appendChild(j),l.appendChild(k),d.selection.insertNode(l),d.selection.setBefore(k)}return h}},g=function(b,c){var d=c.selection;c.element;if(d.isCollapsed()){if(f.handleUneditableDeletion(c))return void b.preventDefault();if(f.fixDeleteInTheBeginningOfLi(c))return void b.preventDefault();if(f.fixDeleteInTheBeginningOfBlock(c))return void b.preventDefault();if(f.fixLastBrDeletionInTable(c))return void b.preventDefault();if(a.browser.usesControlRanges()&&f.fixDeleteInTheBeginningOfControlSelection(c))return void b.preventDefault()}else d.containsUneditable()&&(b.preventDefault(),d.deleteContents())},h=function(a,b){if(b.config.useLineBreaks&&!a.shiftKey&&!a.ctrlKey){b.selection.isCollapsed()&&f.doLineBreaksModeEnterWithCaret(b)&&a.preventDefault()}},i=function(a,b,c){if(a.selection.isCollapsed()){if(a.selection.caretIsInTheBeginnig("li"))if(c){if(a.commands.exec("outdentList"))return}else if(a.commands.exec("indentList"))return}else a.selection.deleteContents();a.commands.exec("insertHTML"," ")},j=function(a){this.domNodeRemovedInterval&&clearInterval(domNodeRemovedInterval),this.parent.fire("destroy:composer")},k=function(a){this.parent.fire("beforeinteraction",a).fire("beforeinteraction:composer",a),setTimeout(function(){this.parent.fire("interaction",a).fire("interaction:composer",a)}.bind(this),0)},l=function(a){this.parent.fire("focus",a).fire("focus:composer",a),setTimeout(function(){this.focusState=this.getValue(!1,!1)}.bind(this),0)},m=function(a){if(this.focusState!==this.getValue(!1,!1)){var b=a;"function"==typeof Object.create&&(b=Object.create(a,{type:{value:"change"}})),this.parent.fire("change",b).fire("change:composer",b)}this.parent.fire("blur",a).fire("blur:composer",a)},n=function(a){this.parent.fire(a.type,a).fire(a.type+":composer",a),"paste"===a.type&&setTimeout(function(){this.parent.fire("newword:composer")}.bind(this),0)},o=function(b){this.config.copyedFromMarking&&(a.browser.supportsModernPaste()&&(b.clipboardData.setData("text/html",this.config.copyedFromMarking+this.selection.getHtml()),b.clipboardData.setData("text/plain",this.selection.getPlainText()),b.preventDefault()),this.parent.fire(b.type,b).fire(b.type+":composer",b))},p=function(b){var c=b.keyCode;(c===a.SPACE_KEY||c===a.ENTER_KEY)&&this.parent.fire("newword:composer")},q=function(b){if(!d.canSelectImagesInContentEditable()){var c=b.target,e=this.element.querySelectorAll("img"),f=this.element.querySelectorAll("."+this.config.classNames.uneditableContainer+" img"),g=a.lang.array(e).without(f);"IMG"===c.nodeName&&a.lang.array(g).contains(c)&&this.selection.selectNode(c)}a.browser.usesControlRanges()&&(this.selection.lastMouseDownPos={x:b.clientX,y:b.clientY},setTimeout(function(){delete this.selection.lastMouseDownPos}.bind(this),0))},r=function(a){var b=(a.target,this.selection.lastMouseDownPos);if(b){var c=document.body.createTextRange();setTimeout(function(){try{c.moveToPoint(b.x,b.y),c.select()}catch(a){}}.bind(this),0)}},s=function(b){if(this.config.classNames.uneditableContainer){var c=a.dom.getParentElement(b.target,{query:"."+this.config.classNames.uneditableContainer},!1,this.element);c&&this.selection.setAfter(c)}},t=function(a){d.canSelectImagesInContentEditable()||setTimeout(function(){this.selection.getSelection().removeAllRanges()}.bind(this),0)},u=function(b){var c,d,f=b.keyCode,j=e[f];return!b.ctrlKey&&!b.metaKey||b.altKey||65!==f?((b.ctrlKey||b.metaKey)&&!b.altKey&&j&&(this.commands.exec(j),b.preventDefault()),f===a.BACKSPACE_KEY&&g(b,this),(f===a.BACKSPACE_KEY||f===a.DELETE_KEY)&&(c=this.selection.getSelectedNode(!0),c&&"IMG"===c.nodeName&&(b.preventDefault(),d=c.parentNode,d.removeChild(c),"A"!==d.nodeName||d.firstChild||d.parentNode.removeChild(d),setTimeout(function(){a.quirks.redraw(this.element)}.bind(this),0))),this.config.handleTabKey&&f===a.TAB_KEY&&(b.preventDefault(),i(this,this.element,b.shiftKey)),void(f===a.ENTER_KEY&&h(b,this))):(this.selection.selectAll(),void b.preventDefault())};a.views.Composer.prototype.observeActions=f,a.views.Composer.prototype.observe=function(){var c=this.sandbox.getIframe?this.sandbox.getIframe():this.sandbox.getContentEditable(),e=(this.element,d.supportsEventsInIframeCorrectly()||this.sandbox.getContentEditable?this.element:this.sandbox.getWindow());this.focusState=this.getValue(!1,!1),c.addEventListener(["DOMNodeRemoved"],j.bind(this),!1),d.supportsMutationEvents()||(this.domNodeRemovedInterval=setInterval(function(){b.contains(document.documentElement,c)||j.call(this)},250)),this.config.handleTables&&f.initTableHandling.call(this),f.addListeners(e,["drop","paste","mouseup","focus","keyup"],k.bind(this)),e.addEventListener("focus",l.bind(this),!1),e.addEventListener("blur",m.bind(this),!1),f.addListeners(this.element,["drop","paste","beforepaste"],n.bind(this),!1),this.element.addEventListener("copy",o.bind(this),!1),this.element.addEventListener("mousedown",q.bind(this),!1),this.element.addEventListener("click",s.bind(this),!1),this.element.addEventListener("drop",t.bind(this),!1),this.element.addEventListener("keyup",p.bind(this),!1),this.element.addEventListener("keydown",u.bind(this),!1),a.browser.usesControlRanges()&&this.element.addEventListener("mscontrolselect",r.bind(this),!1),this.element.addEventListener("dragenter",function(){this.parent.fire("unset_placeholder")}.bind(this),!1)}}(wysihtml5),function(a){var b=400;a.views.Synchronizer=Base.extend({constructor:function(a,b,c){this.editor=a,this.textarea=b,this.composer=c,this._observe()},fromComposerToTextarea:function(b){this.textarea.setValue(a.lang.string(this.composer.getValue(!1,!1)).trim(),b)},fromTextareaToComposer:function(a){var b=this.textarea.getValue(!1,!1);b?this.composer.setValue(b,a):(this.composer.clear(),this.editor.fire("set_placeholder"))},sync:function(a){"textarea"===this.editor.currentView.name?this.fromTextareaToComposer(a):this.fromComposerToTextarea(a)},_observe:function(){var c,d=this,e=this.textarea.element.form,f=function(){c=setInterval(function(){d.fromComposerToTextarea()},b)},g=function(){clearInterval(c),c=null};f(),e&&(a.dom.observe(e,"submit",function(){d.sync(!0)}),a.dom.observe(e,"reset",function(){setTimeout(function(){d.fromTextareaToComposer()},0)})),this.editor.on("change_view",function(a){"composer"!==a||c?"textarea"===a&&(d.fromComposerToTextarea(!0),g()):(d.fromTextareaToComposer(!0),f())}),this.editor.on("destroy:composer",g)}})}(wysihtml5),function(a){a.views.SourceView=Base.extend({constructor:function(a,b){this.editor=a,this.composer=b,this._observe()},switchToTextarea:function(a){var b=this.composer.win.getComputedStyle(this.composer.element),c=parseFloat(b.width),d=Math.max(parseFloat(b.height),100);this.textarea||(this.textarea=this.composer.doc.createElement("textarea"),this.textarea.className="wysihtml5-source-view"),this.textarea.style.width=c+"px",this.textarea.style.height=d+"px",this.textarea.value=this.editor.getValue(a,!0),this.composer.element.parentNode.insertBefore(this.textarea,this.composer.element),this.editor.currentView="source",this.composer.element.style.display="none"},switchToComposer:function(a){var b=this.textarea.value;b?this.composer.setValue(b,a):(this.composer.clear(),this.editor.fire("set_placeholder")),this.textarea.parentNode.removeChild(this.textarea),this.editor.currentView=this.composer,this.composer.element.style.display=""},_observe:function(){this.editor.on("change_view",function(a){"composer"===a?this.switchToComposer(!0):"textarea"===a&&this.switchToTextarea(!0)}.bind(this))}})}(wysihtml5),wysihtml5.views.Textarea=wysihtml5.views.View.extend({name:"textarea",constructor:function(a,b,c){this.base(a,b,c),this._observe()},clear:function(){this.element.value=""},getValue:function(a){var b=this.isEmpty()?"":this.element.value;return a!==!1&&(b=this.parent.parse(b)),b},setValue:function(a,b){b!==!1&&(a=this.parent.parse(a)),this.element.value=a},cleanUp:function(a){var b=this.parent.parse(this.element.value,void 0,a);this.element.value=b},hasPlaceholderSet:function(){var a=wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),b=this.element.getAttribute("placeholder")||null,c=this.element.value,d=!c;return a&&d||c===b},isEmpty:function(){return!wysihtml5.lang.string(this.element.value).trim()||this.hasPlaceholderSet()},_observe:function(){var a=this.element,b=this.parent,c={focusin:"focus",focusout:"blur"},d=wysihtml5.browser.supportsEvent("focusin")?["focusin","focusout","change"]:["focus","blur","change"];b.on("beforeload",function(){wysihtml5.dom.observe(a,d,function(a){var d=c[a.type]||a.type;b.fire(d).fire(d+":textarea")}),wysihtml5.dom.observe(a,["paste","drop"],function(){setTimeout(function(){b.fire("paste").fire("paste:textarea")},0)})})}}),function(a){var b,c={name:b,style:!0,toolbar:b,showToolbarAfterInit:!0,showToolbarDialogsOnSelection:!0,autoLink:!0,handleTables:!0,handleTabKey:!0,parserRules:{tags:{br:{},span:{},div:{},p:{},b:{},i:{},u:{}},classes:{}},pasteParserRulesets:null,parser:a.dom.parse,useLineBreaks:!0,doubleLineBreakEscapesBlock:!0,stylesheets:[],placeholderText:b,supportTouchDevices:!0,cleanUp:!0,contentEditableMode:!1,classNames:{composer:"wysihtml5-editor",body:"wysihtml5-supported",sandbox:"wysihtml5-sandbox",placeholder:"wysihtml5-placeholder",uneditableContainer:"wysihtml5-uneditable-container"},copyedFromMarking:' '};a.Editor=a.lang.Dispatcher.extend({constructor:function(b,d){if(this.editableElement="string"==typeof b?document.getElementById(b):b,this.config=a.lang.object({}).merge(c).merge(d).get(),this._isCompatible=a.browser.supported(),d&&d.classNames&&a.lang.object(this.config.classNames).merge(d.classNames),"textarea"!=this.editableElement.nodeName.toLowerCase()&&(this.config.contentEditableMode=!0,this.config.noTextarea=!0),this.config.noTextarea||(this.textarea=new a.views.Textarea(this,this.editableElement,this.config),this.currentView=this.textarea),!this._isCompatible||!this.config.supportTouchDevices&&a.browser.isTouchDevice()){var e=this;return void setTimeout(function(){e.fire("beforeload").fire("load")},0)}a.dom.addClass(document.body,this.config.classNames.body),this.composer=new a.views.Composer(this,this.editableElement,this.config),this.currentView=this.composer,"function"==typeof this.config.parser&&this._initParser(),this.on("beforeload",this.handleBeforeLoad)},handleBeforeLoad:function(){this.config.noTextarea?this.sourceView=new a.views.SourceView(this,this.composer):this.synchronizer=new a.views.Synchronizer(this,this.textarea,this.composer),this.config.toolbar&&(this.toolbar=new a.toolbar.Toolbar(this,this.config.toolbar,this.config.showToolbarAfterInit))},isCompatible:function(){return this._isCompatible},clear:function(){return this.currentView.clear(),this},getValue:function(a,b){return this.currentView.getValue(a,b)},setValue:function(a,b){return this.fire("unset_placeholder"),a?(this.currentView.setValue(a,b),this):this.clear()},cleanUp:function(a){this.currentView.cleanUp(a)},focus:function(a){return this.currentView.focus(a),this},disable:function(){return this.currentView.disable(),this},enable:function(){return this.currentView.enable(),this},isEmpty:function(){return this.currentView.isEmpty()},hasPlaceholderSet:function(){return this.currentView.hasPlaceholderSet()},destroy:function(){this.composer&&this.composer.sandbox&&this.composer.sandbox.destroy(),this.toolbar&&this.toolbar.destroy(),this.off()},parse:function(b,c,d){var e=this.config.contentEditableMode?document:this.composer?this.composer.sandbox.getDocument():null,f=this.config.parser(b,{rules:d||this.config.parserRules,cleanUp:this.config.cleanUp,context:e,uneditableClass:this.config.classNames.uneditableContainer,clearInternals:c});return"object"==typeof b&&a.quirks.redraw(b),f},_initParser:function(){var b;a.browser.supportsModernPaste()?this.on("paste:composer",function(c){c.preventDefault(),b=a.dom.getPastedHtml(c),b&&this._cleanAndPaste(b)}.bind(this)):this.on("beforepaste:composer",function(b){b.preventDefault();var c=this.composer.getScrollPos();a.dom.getPastedHtmlWithDiv(this.composer,function(a){a&&this._cleanAndPaste(a),this.composer.setScrollPos(c)}.bind(this))}.bind(this))},_cleanAndPaste:function(b){var c=a.quirks.cleanPastedHTML(b,{referenceNode:this.composer.element,rules:this.config.pasteParserRulesets||[{set:this.config.parserRules}],uneditableClass:this.config.classNames.uneditableContainer});this.composer.selection.deleteContents(),this.composer.selection.insertHTML(c)}})}(wysihtml5),function(a){var b=a.dom,c="wysihtml5-command-dialog-opened",d="input, select, textarea",e="[data-wysihtml5-dialog-field]",f="data-wysihtml5-dialog-field";a.toolbar.Dialog=a.lang.Dispatcher.extend({constructor:function(a,b){this.link=a,this.container=b},_observe:function(){if(!this._observed){var d=this,e=function(a){var b=d._serialize();d.fire("save",b),d.hide(),a.preventDefault(),a.stopPropagation()};b.observe(d.link,"click",function(){b.hasClass(d.link,c)&&setTimeout(function(){d.hide()},0)}),b.observe(this.container,"keydown",function(b){var c=b.keyCode;c===a.ENTER_KEY&&e(b),c===a.ESCAPE_KEY&&d.cancel()}),b.delegate(this.container,"[data-wysihtml5-dialog-action=save]","click",e),b.delegate(this.container,"[data-wysihtml5-dialog-action=cancel]","click",function(a){d.cancel(),a.preventDefault(),a.stopPropagation()}),this._observed=!0}},_serialize:function(){for(var a={},b=this.container.querySelectorAll(e),c=b.length,d=0;c>d;d++)a[b[d].getAttribute(f)]=b[d].value;return a},_interpolate:function(a){for(var b,c,d,g=document.querySelector(":focus"),h=this.container.querySelectorAll(e),i=h.length,j=0;i>j;j++)b=h[j],b!==g&&(a&&"hidden"===b.type||(c=b.getAttribute(f),d=this.elementToChange&&"boolean"!=typeof this.elementToChange?this.elementToChange.getAttribute(c)||"":b.defaultValue,b.value=d))},update:function(a){this.elementToChange=a?a:this.elementToChange,this._interpolate()},show:function(a){var e=this.container.querySelector(d);if(this._observe(),this.update(a),b.addClass(this.link,c),this.container.style.display="",this.isOpen=!0,this.fire("show"),e&&!a)try{e.focus()}catch(f){}},_hide:function(a){this.elementToChange=null,b.removeClass(this.link,c),this.container.style.display="none",this.isOpen=!1},hide:function(){this._hide(),this.fire("hide")},cancel:function(){this._hide(),this.fire("cancel")}})}(wysihtml5),function(a){var b=a.dom,c={position:"relative"},d={left:0,margin:0,opacity:0,overflow:"hidden",padding:0,position:"absolute",top:0,zIndex:1},e={cursor:"inherit",fontSize:"50px",height:"50px",marginTop:"-25px",outline:0,padding:0,position:"absolute",right:"-4px",top:"50%"},f={"x-webkit-speech":"",speech:""};a.toolbar.Speech=function(g,h){var i=document.createElement("input");if(!a.browser.supportsSpeechApiOn(i))return void(h.style.display="none");var j=g.editor.textarea.element.getAttribute("lang");j&&(f.lang=j);var k=document.createElement("div");a.lang.object(d).merge({width:h.offsetWidth+"px",height:h.offsetHeight+"px"}),b.insert(i).into(k),b.insert(k).into(h),b.setStyles(e).on(i),b.setAttributes(f).on(i),b.setStyles(d).on(k),b.setStyles(c).on(h);var l="onwebkitspeechchange"in i?"webkitspeechchange":"speechchange";b.observe(i,l,function(){g.execCommand("insertText",i.value),i.value=""}),b.observe(i,"click",function(a){b.hasClass(h,"wysihtml5-command-disabled")&&a.preventDefault(),a.stopPropagation()})}}(wysihtml5),function(a){function b(b,c){var d=b.commands.state(c.name,c.value);return!c.dialog.multiselect&&a.lang.object(d).isArray()&&(d=1===d.length?d[0]:!0),d}var c="wysihtml5-command-disabled",d="wysihtml5-commands-disabled",e="wysihtml5-command-active",f="wysihtml5-action-active",g=a.dom;a.toolbar.Toolbar=Base.extend({constructor:function(b,g,h){this.editor=b,this.container="string"==typeof g?document.getElementById(g):g,this.composer=b.composer,this._getLinks("command"),this._getLinks("action"),this._observe(),h&&this.show(),null!=b.config.classNameCommandDisabled&&(c=b.config.classNameCommandDisabled),null!=b.config.classNameCommandsDisabled&&(d=b.config.classNameCommandsDisabled),null!=b.config.classNameCommandActive&&(e=b.config.classNameCommandActive),null!=b.config.classNameActionActive&&(f=b.config.classNameActionActive);for(var i=this.container.querySelectorAll("[data-wysihtml5-command=insertSpeech]"),j=i.length,k=0;j>k;k++)new a.toolbar.Speech(this,i[k])},_getLinks:function(b){for(var c,d,e,f,g,h,i=this[b+"Links"]=a.lang.array(this.container.querySelectorAll("[data-wysihtml5-"+b+"]")).get(),j=i.length,k=0,l=this[b+"Mapping"]={};j>k;k++)c=i[k],e=c.getAttribute("data-wysihtml5-"+b),f=c.getAttribute("data-wysihtml5-"+b+"-value"),h=c.getAttribute("data-wysihtml5-"+b+"-blank-value"),d=this.container.querySelector("[data-wysihtml5-"+b+"-group='"+e+"']"),g=this._getDialog(c,e),l[e+":"+f]={link:c,group:d,name:e,value:f,tracksBlankValue:h,dialog:g,state:!1}},_getDialog:function(b,c){var d,e,f=this,g=this.container.querySelector("[data-wysihtml5-dialog='"+c+"']");return g&&(d=a.toolbar["Dialog_"+c]?new a.toolbar["Dialog_"+c](b,g):new a.toolbar.Dialog(b,g),d.on("show",function(){e=f.composer.selection.getBookmark(),f.editor.fire("show:dialog",{command:c,dialogContainer:g,commandLink:b})}),d.on("save",function(a){e&&f.composer.selection.setBookmark(e),f._execCommand(c,a),f.editor.fire("save:dialog",{command:c,dialogContainer:g,commandLink:b}),f._hideAllDialogs(),f._preventInstantFocus(),e=void 0}),d.on("cancel",function(){e&&f.composer.selection.setBookmark(e),f.editor.fire("cancel:dialog",{command:c,dialogContainer:g,commandLink:b}),e=void 0,f._preventInstantFocus()}),d.on("hide",function(){f.editor.fire("hide:dialog",{command:c,dialogContainer:g,commandLink:b}),e=void 0})),d},execCommand:function(a,b){this.commandsDisabled||this._execCommand(a,b)},_execCommand:function(a,b){this.editor.focus(!1),this.composer.commands.exec(a,b),this._updateLinkStates()},execAction:function(a){var b=this.editor;"change_view"===a&&(b.currentView===b.textarea||"source"===b.currentView?b.fire("change_view","composer"):b.fire("change_view","textarea")),"showSource"==a&&b.fire("showSource")},_observe:function(){for(var c=this,e=this.editor,f=this.container,h=this.commandLinks.concat(this.actionLinks),i=h.length,j=0;i>j;j++)"A"===h[j].nodeName?g.setAttributes({href:"javascript:;",unselectable:"on"}).on(h[j]):g.setAttributes({unselectable:"on"}).on(h[j]);g.delegate(f,"[data-wysihtml5-command], [data-wysihtml5-action]","mousedown",function(a){a.preventDefault()}),g.delegate(f,"[data-wysihtml5-command]","click",function(a){var d,e=this,f=e.getAttribute("data-wysihtml5-command"),g=e.getAttribute("data-wysihtml5-command-value"),h=c.commandMapping[f+":"+g];g||!h.dialog?c.execCommand(f,g):(d=b(c.composer,h),h.dialog.show(d)),a.preventDefault()}),g.delegate(f,"[data-wysihtml5-action]","click",function(a){var b=this.getAttribute("data-wysihtml5-action");c.execAction(b),a.preventDefault()}),e.on("interaction:composer",function(a){c.preventFocus||c._updateLinkStates()}),this._ownerDocumentClick=function(b){a.dom.contains(c.container,b.target)||a.dom.contains(c.composer.element,b.target)||(c._updateLinkStates(),c._preventInstantFocus())},this.container.ownerDocument.addEventListener("click",this._ownerDocumentClick,!1),this.editor.on("destroy:composer",this.destroy.bind(this)),this.editor.config.handleTables&&(e.on("tableselect:composer",function(){c.container.querySelectorAll('[data-wysihtml5-hiddentools="table"]')[0].style.display=""}),e.on("tableunselect:composer",function(){c.container.querySelectorAll('[data-wysihtml5-hiddentools="table"]')[0].style.display="none"})),e.on("change_view",function(a){setTimeout(function(){c.commandsDisabled="composer"!==a,c._updateLinkStates(),c.commandsDisabled?g.addClass(f,d):g.removeClass(f,d)},0)})},destroy:function(){this.container.ownerDocument.removeEventListener("click",this._ownerDocumentClick,!1)},_hideAllDialogs:function(){var a=this.commandMapping;for(var b in a)a[b].dialog&&a[b].dialog.hide()},_preventInstantFocus:function(){this.preventFocus=!0,setTimeout(function(){this.preventFocus=!1}.bind(this),0)},_updateLinkStates:function(){var a,d,h,i,j,k=this.commandMapping,l=this.composer,m=this.actionMapping;for(a in k)i=k[a],this.commandsDisabled?(d=!1,g.removeClass(i.link,e),i.group&&g.removeClass(i.group,e),i.dialog&&i.dialog.hide()):(d=this.composer.commands.state(i.name,i.value),g.removeClass(i.link,c),i.group&&g.removeClass(i.group,c)),(i.state!==d||i.tracksBlankValue)&&(i.state=d,d?i.tracksBlankValue?g.removeClass(i.link,e):(g.addClass(i.link,e),i.group&&g.addClass(i.group,e),!i.dialog||"undefined"!=typeof i.value&&null!==i.value||(d&&"object"==typeof d?(d=b(l,i),i.state=d,j=i.dialog.container.dataset?i.dialog.container.dataset.showdialogonselection:!1,l.config.showToolbarDialogsOnSelection||j?i.dialog.show(d):i.dialog.update(d)):i.dialog.hide())):i.tracksBlankValue?g.addClass(i.link,e):(g.removeClass(i.link,e),i.group&&g.removeClass(i.group,e),i.dialog&&!i.value&&i.dialog.hide()));for(a in m)h=m[a],"change_view"===h.name&&(h.state=this.editor.currentView===this.editor.textarea||"source"===this.editor.currentView,h.state?g.addClass(h.link,f):g.removeClass(h.link,f))},show:function(){this.container.style.display=""},hide:function(){this.container.style.display="none"}})}(wysihtml5),function(a){a.toolbar.Dialog_createTable=a.toolbar.Dialog.extend({show:function(a){this.base(a)}})}(wysihtml5),function(a){var b="[data-wysihtml5-dialog-field]",c="data-wysihtml5-dialog-field";a.toolbar.Dialog_foreColorStyle=a.toolbar.Dialog.extend({multiselect:!0,_serialize:function(){for(var a={},d=this.container.querySelectorAll(b),e=d.length,f=0;e>f;f++)a[d[f].getAttribute(c)]=d[f].value;return a},_interpolate:function(d){for(var e,f,g=a.quirks.styleParser,h=document.querySelector(":focus"),i=this.container.querySelectorAll(b),j=i.length,k=0,l=this.elementToChange?a.lang.object(this.elementToChange).isArray()?this.elementToChange[0]:this.elementToChange:null,m=l?l.getAttribute("style"):null,n=m?g.parseColor(m,"color"):null;j>k;k++)e=i[k],e!==h&&(d&&"hidden"===e.type||"color"===e.getAttribute(c)&&(f=(e.dataset.colormode||"rgb").toLowerCase(),f="hex"===f?"hash":f,n?e.value=g.unparseColor(n,f):e.value=g.unparseColor([0,0,0],f)))}})}(wysihtml5),function(a){a.dom;a.toolbar.Dialog_fontSizeStyle=a.toolbar.Dialog.extend({multiselect:!0,_serialize:function(){return{size:this.container.querySelector('[data-wysihtml5-dialog-field="size"]').value}},_interpolate:function(b){var c=document.querySelector(":focus"),d=this.container.querySelector("[data-wysihtml5-dialog-field='size']"),e=this.elementToChange?a.lang.object(this.elementToChange).isArray()?this.elementToChange[0]:this.elementToChange:null,f=e?e.getAttribute("style"):null,g=f?a.quirks.styleParser.parseFontSize(f):null;d&&d!==c&&g&&!/^\s*$/.test(g)&&(d.value=g)}})}(wysihtml5);
-//# sourceMappingURL=wysihtml-toolbar.min.map
\ No newline at end of file
diff --git a/dist/wysihtml-toolbar.min.map b/dist/wysihtml-toolbar.min.map
deleted file mode 100644
index 87738fa..0000000
--- a/dist/wysihtml-toolbar.min.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"wysihtml-toolbar.min.js","sources":["wysihtml-toolbar.js"],"names":["wysihtml5","version","commands","dom","quirks","toolbar","lang","selection","views","INVISIBLE_SPACE","INVISIBLE_SPACE_REG_EXP","VOID_ELEMENTS","EMPTY_FUNCTION","ELEMENT_NODE","TEXT_NODE","BACKSPACE_KEY","ENTER_KEY","ESCAPE_KEY","SPACE_KEY","TAB_KEY","DELETE_KEY","polyfills","win","doc","nativeCustomEventSupported","p","CustomEvent","detail","foo","type","e","String","prototype","trim","rtrim","this","replace","s_add","s_rem","Element","on","fn","self","attachEvent","event","target","srcElement","preventDefault","returnValue","stopPropagation","cancelBubble","which","button","keyCode","call","detachEvent","Object","defineProperty","getOwnPropertyDescriptor","get","innerText","set","s","Array","isArray","arg","toString","indexOf","a","f","c","length","r","d","Function","bind","oThis","TypeError","aArgs","slice","arguments","fToBind","fNOP","fBound","apply","concat","ELEMENT","matches","mozMatchesSelector","msMatchesSelector","oMatchesSelector","webkitMatchesSelector","selector","element","elements","document","ownerDocument","querySelectorAll","index","closest","parentElement","createElement","testElement","classList","add","contains","createMethod","method","original","DOMTokenList","token","i","len","toggle","_toggle","force","view","classListProp","protoProp","elemCtrProto","objCtr","strTrim","arrIndexOf","item","DOMEx","message","name","code","DOMException","checkTokenAndGetIndex","test","ClassList","elem","trimmedClasses","getAttribute","classes","split","push","_updateClassName","setAttribute","classListProto","classListGetter","Error","tokens","l","updated","remove","splice","result","join","classListPropDesc","enumerable","configurable","ex","number","__defineGetter__","normalizeHasCaretError","window","ret","t1","createTextNode","t2","t3","createRange","appendChild","body","setStart","setEnd","getSelection","removeAllRanges","addRange","normalize","childNodes","anchorNode","firstChild","anchorOffset","parentNode","removeChild","getTextNodes","node","all","nextSibling","nodeType","isInDom","n","normalizeFix","nf","Node","texts","defaultView","anode","aoffset","aelement","undefined","fnode","focusNode","foffset","focusOffset","felement","prevTxt","shift","curText","nodeValue","compareDocumentPosition","DOCUMENT_POSITION_PRECEDING","DOCUMENT_POSITION_CONTAINS","previousSibling","F","removeEventListener","readyState","addEventListener","customEventSupported","params","bubbles","cancelable","evt","createEvent","initCustomEvent","Event","factory","root","define","amd","module","exports","rangy","isHostMethod","o","t","FUNCTION","OBJECT","isHostObject","isHostProperty","UNDEFINED","createMultiplePropertyTest","testFunc","props","isTextRange","range","areHostMethods","textRangeMethods","areHostProperties","textRangeProperties","getBody","getElementsByTagName","consoleLog","msg","console","log","alertOrLog","shouldAlert","isBrowser","alert","fail","reason","api","initialized","supported","config","alertOnFail","warn","alertOnWarn","getErrorDesc","description","init","testRange","implementsDomRange","implementsTextRange","domRangeMethods","domRangeProperties","nodeName","toLowerCase","createTextRange","features","errorMessage","moduleName","modules","Module","initListeners","deprecationNotice","deprecated","replacement","createAliasForDeprecatedMethod","owner","util","toArray","shim","shimListeners","dependencies","initializer","createModule","initFunc","newModule","stack","RangePrototype","SelectionPrototype","areHostObjects","forEach","arr","func","preferTextRange","autoInitialize","rangyAutoInitialize","extend","hasOwnProperty","obj","deep","createOptions","optionsParam","defaults","options","el","arrayLike","addListener","eventType","listener","addInitListener","addShimListener","createMissingNativeApi","requiredModule","requiredModuleNames","createError","createCoreModule","rangePrototype","selectionPrototype","isHtmlNamespace","ns","namespaceURI","UNDEF","parent","getNodeIndex","getNodeLength","getCommonAncestor","node1","node2","ancestors","arrayContains","isAncestorOf","ancestor","descendant","selfIsAncestor","isOrIsAncestorOf","getClosestAncestorIn","isCharacterDataNode","isTextOrCommentNode","insertAfter","precedingNode","nextNode","insertBefore","splitDataNode","positionsToPreserve","newNode","cloneNode","deleteData","position","offset","getDocument","getWindow","parentWindow","getIframeDocument","iframeEl","contentDocument","contentWindow","getIframeWindow","isWindow","getContentDocument","methodName","tagName","getRootContainer","comparePoints","nodeA","offsetA","nodeB","offsetB","nodeC","childA","childB","isBrokenNode","inspectNode","crashyTextNodes","data","idAttr","id","innerHTML","fragmentFromNodeChildren","child","fragment","createDocumentFragment","createTestElement","html","contentEditable","bodyFirstChild","removeNode","NodeIterator","_next","createIterator","DomPosition","codeName","textNode","val","getComputedStyleProperty","getComputedStyle","propName","documentElement","currentStyle","_current","hasNext","next","detach","equals","pos","inspect","INDEX_SIZE_ERR","HIERARCHY_REQUEST_ERR","WRONG_DOCUMENT_ERR","NO_MODIFICATION_ALLOWED_ERR","NOT_FOUND_ERR","NOT_SUPPORTED_ERR","INVALID_STATE_ERR","INVALID_NODE_TYPE_ERR","isNonTextPartiallySelected","startContainer","endContainer","getRangeDocument","getRangeRoot","getBoundaryBeforeNode","getBoundaryAfterNode","insertNodeAtPosition","firstNodeInserted","rangesIntersect","rangeA","rangeB","touchingIsIntersecting","assertRangeValid","startComparison","startOffset","endOffset","endComparison","cloneSubtree","iterator","partiallySelected","subIterator","frag","isPartiallySelectedSubtree","getSubtreeIterator","iterateSubtree","rangeIterator","iteratorState","it","stop","subRangeIterator","deleteSubtree","extractSubtree","getNodesInRange","nodeTypes","filter","regex","filterNodeTypes","filterExists","RegExp","nodes","RangeIterator","sc","ec","getName","clonePartiallySelectedTextNodes","collapsed","so","eo","commonAncestorContainer","isSingleCharacterDataNode","_first","_last","createAncestorFinder","assertNoDocTypeNotationEntityAncestor","allowSelf","getDocTypeNotationEntityAncestor","assertValidNodeType","invalidTypes","assertValidOffset","assertSameDocumentOrFragment","getDocumentOrFragmentContainer","assertNodeNotReadOnly","getReadonlyAncestor","assertNode","isValidOffset","isRangeValid","splitRangeBoundaries","startEndSame","setStartAndEnd","rangeToHtml","container","cloneContents","copyComparisonConstantsToObject","START_TO_START","s2s","START_TO_END","s2e","END_TO_END","e2e","END_TO_START","e2s","NODE_BEFORE","n_b","NODE_AFTER","n_a","NODE_BEFORE_AND_AFTER","n_b_a","NODE_INSIDE","n_i","copyComparisonConstants","constructor","createRangeContentRemover","remover","boundaryUpdater","boundary","reset","createPrototypeRange","createBeforeAfterNodeSetter","isBefore","isStart","beforeAfterNodeTypes","rootContainerNodeTypes","setRangeStart","setRangeEnd","args","setBoundary","setStartBefore","setStartAfter","setEndBefore","setEndAfter","collapse","selectNodeContents","selectNode","start","end","extractContents","deleteContents","canSurroundContents","boundariesInvalid","splitBoundaries","splitBoundariesPreservingPositions","normalizeBoundaries","sibling","mergeForward","appendData","mergeBackward","nodeLength","insertData","nodeIndex","normalizeStart","endNode","startNode","collapseToPoint","updateCollapsedAndCommonAncestor","updateBoundaries","Range","current","subRange","cloneRange","readonlyNodeTypes","insertableNodeTypes","surroundNodeTypes","styleEl","htmlParsingConforms","createContextualFragment","fragmentStr","rangeProperties","compareBoundaryPoints","how","prefixA","prefixB","insertNode","clone","surroundContents","content","hasChildNodes","lastChild","prop","textParts","compareNode","comparePoint","toHtml","intersectsNode","isPointInRange","intersectsRange","intersectsOrTouchesRange","intersection","intersectionRange","union","unionRange","containsNode","allowPartial","containsNodeContents","containsRange","containsNodeText","nodeRange","textNodes","getNodes","lastTextNode","pop","collapseBefore","collapseAfter","getBookmark","containerNode","preSelectionRange","moveToBookmark","bookmark","charIndex","nextCharIndex","nodeStack","foundStart","rangesEqual","isValid","r1","r2","DomRange","WrappedRange","WrappedTextRange","updateRangeProperties","nativeRange","updateNativeRange","startMoved","endMoved","nativeRangeDifferent","rangeProto","refresh","testTextNode","oppositeName","range2","createNativeRange","getTextRangeContainerElement","textRange","parentEl","duplicate","startEl","endEl","startEndContainer","textRangeIsCollapsed","compareEndPoints","getTextRangeBoundaryPosition","wholeRangeContainerElement","isCollapsed","startInfo","workingRange","containerElement","canHaveHTML","boundaryPosition","nodeInfo","workingNode","comparison","previousNode","boundaryNode","workingComparisonType","childNodeCount","moveToElementText","Math","floor","setEndPoint","tempRange","rangeLength","text","moveStart","createBoundaryTextRange","boundaryParent","boundaryOffset","nodeIsDataNode","startBoundary","rangeContainerElement","rangeToTextRange","startRange","endRange","toTextRange","globalObj","createRangyRange","isDirectionBackward","dir","WrappedSelection","getWinSelection","winParam","getDocSelection","winSelectionIsBackward","sel","backward","updateAnchorAndFocusFromRange","anchorPrefix","focusPrefix","updateAnchorAndFocusFromNativeSelection","nativeSel","nativeSelection","updateEmptySelection","rangeCount","_ranges","getNativeRange","rangeContainsSingleElement","rangeNodes","getSingleElementFromRange","updateFromTextRange","wrappedRange","updateControlSelection","docSelection","controlRange","addRangeToControlSelection","rangeElement","newControlRange","createControlRange","select","deleteProperties","detached","actOnCachedSelection","action","cached","cachedRangySelections","createControlSelection","ranges","assertNodeInSameDocument","createStartOrEndSetter","getRangeAt","setSingleRange","isBackward","rangeInspects","anchor","focus","checkSelectionRanges","getNativeSelection","selectionIsCollapsed","BOOLEAN","NUMBER","CONTROL","implementsWinGetSelection","implementsDocSelection","useDocumentSelection","isSelectionValid","testSelection","selectionHasAnchorAndFocus","selectionHasExtend","selectionHasRangeCount","selectionSupportsMultipleRanges","collapsedNonEditableSelectionsSupported","addRangeBackwardToNative","originalSelectionRangeCount","selectionHasMultipleRanges","originalSelectionRanges","originalSelectionBackward","testEl","chromeMatch","navigator","appVersion","match","parseInt","testControlRange","implementsControlRange","getSelectionRangeAt","docSel","selProto","addRangeBackward","direction","previousRangeCount","clonedNativeRange","selectionIsBackward","setRanges","empty","refreshSelection","checkForChanges","oldRanges","oldAnchorNode","oldAnchorOffset","removeRangeManually","getAllRanges","removeRange","removed","isBackwards","rangeTexts","collapseToStart","collapseToEnd","selectAllChildren","deleteFromDocument","eachRange","callMethodOnEachRange","results","changeEachRange","rangeBookmarks","rangeBookmark","selRanges","saveRanges","restoreRanges","rangeHtmls","getNativeTextRange","detachAll","Selection","docReady","loadHandler","require","defaultTokenizer","chars","wordOptions","createTokenRange","isWord","tokenRanges","wordStart","wordEnd","word","lastWordEnd","wordRegex","exec","includeTrailingSpace","nonLineBreakWhiteSpaceRegex","convertCharRangeToToken","tokenRange","tokenChars","tokenize","tokenizer","normalizeIgnoredCharacters","ignoredCharacters","ignoredChars","ignoredCharsArray","sort","char1","char2","charCodeAt","createWordOptions","language","defaultLanguage","defaultWordOptions","createNestedOptions","characterOptions","defaultCharacterOptions","getComputedDisplay","display","tableCssDisplayBlock","defaultDisplayValueForTag","isHidden","getAncestorsAndSelf","isVisibilityHiddenTextNode","isBlockNode","containsPositions","getAncestors","unshift","nextNodeDescendants","excludeChildren","previous","isWhitespaceNode","computedWhiteSpace","isCollapsedWhitespaceNode","isCollapsedNode","isIgnoredNode","Cache","store","createCachingGetter","objProperty","cache","cachedCount","uncachedCount","value","NodeWrapper","session","positions","Position","nodeWrapper","inspectPosition","startSession","endSession","currentSession","Session","getSession","createCharacterIterator","startPos","endPos","charPos","finished","previousVisible","nextVisible","previousTextPos","returnPreviousTextPos","character","getCharacter","rewind","dispose","createTokenizedTextProvider","consumeWord","forward","textChar","newChars","forwardIterator","backwardIterator","passedWordBoundary","insideWord","allWhiteSpaceRegex","forwardChars","backwardChars","reverse","forwardTokensBuffer","arrayIndexOf","backwardTokensBuffer","nextEndToken","lastToken","previousStartToken","movePositionBy","unit","count","currentPos","charIterator","nextPos","unitsMoved","newPos","absCount","abs","CHARACTER","WORD","tokenizedTextProvider","isLeadingSpace","isTrailingSpace","createRangeCharacterIterator","rangeStart","getRangeBoundaryPosition","rangeEnd","itStart","itEnd","getRangeCharacters","isWholeWord","expand","findTextFromPosition","initialPos","searchTerm","isRegex","searchScopeRange","findOptions","handleMatch","startIndex","endIndex","valid","wholeWordsOnly","currentChar","matchStartIndex","matchEndIndex","insideRegexMatch","caseSensitive","createEntryPointFunction","sessionRunning","createRangeBoundaryMover","moveOptions","defaultMoveOptions","boundaryIsStart","moveResult","createRangeTrimmer","trimCharCount","trimmed","createSelectionTrimmer","spacesRegex","spacesMinusLineBreaksRegex","trailingSpaceInBlockCollapses","trailingSpaceBeforeBrCollapses","trailingSpaceBeforeBlockCollapses","trailingSpaceBeforeLineBreakInPreLineCollapses","includeBlockContentTrailingSpace","includeSpaceBeforeBr","includeSpaceBeforeBlock","includePreLineTrailingSpace","ignoreCharacters","defaultCaretCharacterOptions","en","defaultFindOptions","withinRange","wrap","defaultExpandOptions","trimStart","trimEnd","defaultWordIteratorOptions","table","caption","colgroup","col","thead","tbody","tfoot","tr","td","th","key","nodeProto","getPosition","EMPTY","NON_SPACE","UNCOLLAPSIBLE_SPACE","COLLAPSIBLE_SPACE","TRAILING_SPACE_BEFORE_BLOCK","TRAILING_SPACE_IN_BLOCK","TRAILING_SPACE_BEFORE_BR","PRE_LINE_TRAILING_SPACE_BEFORE_LINE_BREAK","TRAILING_LINE_BREAK_AFTER_BR","INCLUDED_TRAILING_LINE_BREAK_AFTER_BR","getLength","isWhitespace","isCollapsedWhitespace","isIgnored","getTextNodeInfo","spaceRegex","collapseSpaces","cssWhitespace","preLine","hasInnerText","posAfterEl","firstPosInEl","prepopulateChar","isDefinitelyNonEmpty","isRenderedBlock","brs","getTrailingSpace","getNodeWrapper","getLeadingSpace","positionProto","characterType","isBr","prepopulatedChar","visibleChar","charType","finalizedChar","charAt","nodePassed","checkForTrailingSpace","checkForLeadingSpace","isCharInvariant","resolveLeadingAndTrailingSpaces","trailingSpace","leadingSpace","getPrecedingUncollapsedPosition","getPreviousPos","gotPreviousPos","previousPos","returnChar","thisChar","isIgnoredCharacter","cacheKey","cachedChar","collapsible","nextUncollapsed","nextOffset","previousOffset","createWrapperCache","nodeProperty","wrappersByProperty","wrapper","property","initCaches","uniqueIDSupported","elementCache","elementsCache","uniqueID","elWrapper","textNodeCache","otherNodeCache","wrapperCache","prefix","moveEnd","move","startTrimmed","endTrimmed","expandOptions","moved","endToken","newEndPos","startTokenizedTextProvider","startToken","newStartPos","endTokenizedTextProvider","selectCharacters","toCharacterRange","rangeStartsBeforeNode","rangeBetween","findText","searchTermParam","findResult","wrappedAround","pasteHtml","saveCharacterRanges","rangeInfos","characterRange","restoreCharacterRanges","saved","rangeInfo","createWordIterator","iteratorOptions","noMutation","createPosition","gEBI","getElementById","insertRangeBoundaryMarker","atStart","markerEl","markerId","Date","random","boundaryRange","style","lineHeight","className","markerTextChar","setRangeBoundary","compareRanges","saveRange","startMarkerId","endMarkerId","restoreRange","saveSelection","restored","restoreSelection","savedSelection","preserveDirection","removeMarkerElement","removeMarkers","Base","_instance","_static","_prototyping","proto","base","klass","_constructing","implement","valueOf","source","toSource","hidden","object","block","context","browser","iosVersion","userAgent","androidVersion","isIE","equation","re","rv","appName","parseFloat","$1","isGecko","isWebKit","isChrome","isOpera","USER_AGENT","hasContentEditableSupport","hasEditingApiSupport","execCommand","queryCommandSupported","queryCommandState","hasQuerySelectorSupport","querySelector","isIncompatibleMobileBrowser","isIos","isAndroid","isTouchDevice","supportsEvent","supportsSandboxedIframes","throwsMixedContentWarningWhenIframeSrcIsEmpty","displaysCaretInEmptyContentEditableCorrectly","hasCurrentStyleProperty","insertsLineBreaksOnReturn","supportsPlaceholderAttributeOn","eventName","supportsEventsInIframeCorrectly","supportsHTML5Tags","html5","supportsCommand","buggyCommands","formatBlock","insertUnorderedList","insertOrderedList","insertHTML","command","isBuggy","e1","queryCommandEnabled","e2","doesAutoLinkingInContentEditable","canDisableAutoLinking","clearsContentEditableCorrectly","supportsGetAttributeCorrectly","canSelectImagesInContentEditable","autoScrollsToCaret","autoClosesUnclosedTags","clonedTestElement","supportsNativeGetElementsByClassName","getElementsByClassName","supportsSelectionModify","needsSpaceAfterLineBreak","supportsSpeechApiOn","input","chromeVersion","crashesWhenDefineProperty","doesAsyncFocus","hasProblemsSettingCaretAfterImg","hasLiDeletingProblem","hasUndoInContextMenu","hasInsertNodeIssue","hasIframeFocusIssue","createsNestedInvalidMarkupAfterPaste","hasCaretBlockElementIssue","supportsMutationEvents","supportsModernPaste","fixStyleKey","usesControlRanges","array","needle","without","arrayToSubstract","newArr","newArray","map","callback","thisArg","A","unique","vals","max","idx","Dispatcher","handler","events","off","handlers","newHandlers","fire","payload","observe","stopObserving","merge","otherObj","isPlainObject","difference","diffObj","newObj","isFunction","Text","isEmpty","WHITE_SPACE_START","WHITE_SPACE_END","ENTITY_REG_EXP","ENTITY_MAP","&","<",">","\"","\t","string","str","interpolate","vars","by","search","escapeHTML","linebreaks","convertSpaces","autoLink","ignoreInClasses","_hasParentThatShouldBeIgnored","_parseNode","_convertUrlsToLinks","URL_REG_EXP","url","punctuation","TRAILING_CHAR_REG_EXP","opening","BRACKETS","realUrl","displayUrl","MAX_DISPLAY_LENGTH","substr","_getTempElement","tempElement","_wysihtml5_tempElement","_wrapMatchesInNode","IGNORE_URLS_IN","childNodesLength",")","]","}","addClass","hasClass","removeClass","elementClassName","convertToList","_createListItem","list","listItem","_createList","listType","uneditableClass","childNode","lineBreak","isBlockElement","isLineBreak","currentListItem","lineBreaks","lineBreaksLength","getStyle","from","insert","after","replaceChild","copyAttributes","attributesToCopy","elementToCopyFrom","to","elementToCopyTo","attribute","andTo","callee","BOX_SIZING_PROPERTIES","shouldIgnoreBoxSizingBorderBox","hasBoxSizingBorderBox","offsetWidth","copyStyles","stylesToCopy","cssText","setStyles","delegate","parents","domNode","defaultNodeTypes","is","emptyTextNode","ignoreWhitespace","regx","rangyBookmark","visible","isVisible","getTextContent","voidElement","query","prev","prevNode","types","ignoreBlankTexts","commonAncestor","parents1","parents2","lastLeafNode","leafClasses","escapeParent","newWrapper","split2","nodeWrap","curNode","transferContentTo","targetNode","removeOldWrapper","properties","classRegExp","styleProperty","hasOneStyle","styles","j","maxStyleP","styleValue","attr","getAttributes","attrList","hasOneAttribute","attributeValue","getAsDom","_innerHTMLShiv","_ensureHTML5Compatibility","_wysihtml5_supportsHTML5Tags","HTML5_ELEMENTS","getParentElement","levels","camelize","REG_EXP_CAMELIZE","toUpperCase","stylePropertyMapping","float","camelizedProperty","originalOverflow","needsOverflowReset","overflow","getPropertyValue","ingoreEmpty","textContent","hasElementWithTagName","_getDocumentIdentifier","_wysihtml5_identifier","DOCUMENT_IDENTIFIER","LIVE_CACHE","cacheEntry","hasElementWithClassName","elementToInsert","before","into","insertCSS","rules","styleElement","styleSheet","link","head","_isLineBreak","_isLineBreakOrBlockElement","eventNames","handlerWrapper","parse","elementOrHtml_current","config_current","elementOrHtml","currentRules","defaultRules","isString","clearInternals","selectors","_applySelectorRules","_convert","cleanUp","unjoinNbsps","txtnodes","getCorrectInnerHTML","oldNode","newChild","nodeDisplay","oldNodeType","oldChilds","oldChildsLength","NODE_TYPE_MAPPING","blockElements","DEFAULT_NODE_NAME","attributes","selectorRules","els","elementHandlingMethods","_handleElement","rule","renameTag","tagRules","tags","scopeName","_wysihtml5","outerHTML","unwrap","rename_tag","one_of_type","_testTypes","remove_action","remove_action_rename_to","_handleAttributes","_handleStyles","definition","type_definitions","_testType","classesLength","styleProp","nodeClasses","nodeStyles","methods","m","typeCeckMethods","WHITE_SPACE_REG_EXP","sp","attrs","v","keep_styles","styleFloat","cssFloat","_getAttributesBeginningWith","beginning","returnAttributes","_checkAttribute","attributeName","newAttributeValue","attributeCheckMethods","_checkAttributes","local_attributes","newValue","matchingAttributes","globalAttributes","checkAttributes","oldAttributes","imax","currentClass","newClass","setClass","set_class","add_class","addStyle","add_style","setAttributes","set_attributes","allowedClasses","newClasses","oldClasses","check_attributes","addClassMethods","addStyleMethods","newStyle","classes_blacklist","src","width","height","_handleText","_handleComment","comments","createComment","1","3","8","REG_EXP","href","alt","numbers","dimension","any","align_text","mapping","left","right","center","align_img","justify","clear_br","both","size_font","2","4","5","6","7","-","+","has_visible_contet","txt","visibleElements","offsetHeight","removeEmptyTextNodes","renameElement","newNodeName","newElement","replaceWithChildNodes","_isBlockElement","_appendLineBreak","resolveList","useLineBreaks","isLastChild","shouldAppendLineBreak","paragraph","isLastItem","lastListItem","lastElementChild","firstElementChild","windowProperties","windowProperties2","documentProperties","Sandbox","readyCallback","editableArea","_createIframe","insertInto","getIframe","_readyError","destroy","iframe","that","security","allowtransparency","frameborder","marginwidth","marginheight","onload","onreadystatechange","_onLoadIframe","iframeWindow","iframeDocument","charset","characterSet","sandboxHtml","_getHtml","stylesheets","open","write","close","onerror","fileName","lineNumber","_unset","loaded","setTimeout","templateVars","setter","__defineSetter__","ContentEditableArea","getContentEditable","_bindElement","_createElement","_loadElement","contentExists","innerHtml","simulatePlaceholder","editor","placeholderText","placeholderClassName","CLASS_NAME","unset","composerIsVisible","hasPlaceholderSet","clear","placeholderSet","setValue","setTextContent","HAS_GET_ATTRIBUTE_BUG","isLoadedImage","hasAttribute","specified","complete","queryInList","q","removeElement","referenceNode","tag","MapCell","cell","isColspan","isRowspan","firstCol","lastCol","firstRow","lastRow","isReal","spanCollection","modified","TableModifyerByCell","addSpannedCellToMap","cspan","rspan","spanCollect","rmax","cmax","rr","cc","setCellAsModified","smax","setTableMap","ridx","row","cells","cidx","tableRows","getTableRows","getRowCells","inlineTables","inlineCells","allCells","tableCells","inlineRows","allRows","getMapIndex","r_length","c_length","r_idx","c_idx","getElementAtIndex","getMapElsTo","to_cell","idx_start","idx_end","temp_idx","temp_cidx","maxr","maxc","orderSelectionEnds","secondcell","createCells","nr","correctColIndexForUnreals","corrIdx","getLastNewCellOnRow","rowLimit","removeEmptyTable","splitRowToCells","colspan","cType","newCells","removeAttribute","getRealRowEl","injectRowAt","new_cells","n_cidx","canMerge","decreaseCellSpan","span","removeSurplusLines","allRowspan","fillMissingCells","r_max","c_max","prevcell","rectify","unmerge","thisCell","rowspan","collapseCellToNextRow","cellIdx","newRowIdx","newIdx","lastCell","removeRowCell","getRowElementsByCell","modRow","getColumnElementsByCell","removeRow","oldRow","removeColCell","removeColumn","what","addRow","where","newRow","addRowCell","cr","colSpanAttr","addColumn","addColCell","doAdd","handleCellAddWithRowspan","modCell","temp_r_cells","nrow","addRowsNr","crow","getCellsBetween","cell1","cell2","c1","addCells","removeCells","mergeCellsBetween","unmergeCell","findCell","findRowByCell","findColumnByCell","thisOwner","otherOwner","point","location_index","smallest_common_ancestor","this_index","other_index","children","getPastedHtml","clipboardData","getData","getPastedHtmlWithDiv","composer","selBookmark","cleanerDiv","scrollPos","getScrollPos","top","y","x","setBookmark","removeInvisibleSpaces","cleanPastedHTML","styleToRegex","styleStr","trimmedStr","escapedStr","extendRulesWithStyleExceptions","exceptStyles","newRules","pickRuleset","ruleset","defaultSet","condition","newHtml","color","fontSize","ensureProperClearing","clearIfNecessary","TILDE_ESCAPED","urlToSearch","elementsWithTilde","redraw","tableCellsSelection","editable","handleMouseDown","handleSelectionMousedown","removeCellSelections","selection_class","handleMouseMove","handleMouseUp","selectedCells","addSelections","oldEnd","curTable","deselect","bindSideclick","sideClickHandler","selectCells","getColorParseMethod","colorStr","colorTypeConf","colorParseMethods","getColorFormat","rgba","rgb","hex6","radix","hex3","makeParamRegExp","styleParser","parseColor","stylesStr","paramName","paramsRegex","colorType","colorMatch","unparseColor","colorFormat","hexRadix","parseFontSize","_getCumulativeOffsetTop","offsetTop","offsetParent","getDepth","getRangeNode","getWebkitSelectionFixNode","blankNode","placeholderRemover","delayedPlaceholderRemover","minWidth","expandRangeToSurround","common","start_depth","end_depth","contain","unselectableClass","getRange","setSelection","setBefore","createTemporaryCaretSpaceAfter","caretPlaceholder","caretPlaceholderText","keyDownHandler","setAfter","ctrlKey","metaKey","zIndex","notVisual","fixWebkitSelection","lastSibling","activeElement","setScrollPos","avoidInvisibleSpace","isElement","displayStyle","getSelectedNode","fixSelBorders","getSelectedOwnNodes","getOwnRanges","ownNodes","maxi","findNodesInSelection","curNodes","filterElements","containsUneditable","uneditables","getOwnUneditables","deleteRangeContents","startParent","endParent","ev","dispatchEvent","err","getCaretNode","getPreviousNode","ignoreEmpty","getNodesNearCaret","caretNode","textOffset","getSelectionParentsByTag","curEl","getRangeToNodeEnd","sNode","lastR","caretIsLastInSelection","endc","endtxt","caretIsFirstInSelection","includeLineBreaks","ws","whiteSpace","caretIsInTheBeginnig","ofNode","getBeforeSelection","includePrevLeaves","inTmpCaret","rng","prevLeaf","executeAndRestoreRangy","restoreScrollPosition","executeAndRestore","newCaretPlaceholder","prevSibling","newRange","oldScrollTop","scrollTop","oldScrollLeft","scrollLeft","placeholderHtml","lastEditorElement","canAppendChild","anchorNodeTagNameLower","voidElements","splitElementAtCaret","contentAfterRangeStart","surround","nodeOptions","cssStyle","scrollIntoView","tolerance","hasScrollBars","scrollHeight","_wysihtml5ScrollIntoViewElement","selectLine","_selectLine_W3C","getBoundingClientRect","_selectLineUniversal","includeRangyRangeHelpers","isHelperNode","initialBoundry","modify","toLineBoundary","location","getRangeRect","rect","testNode","amount","testRect","found","isLineBreakingElement","pnode","bottom","getText","getOwnNodes","splitBounds","fixRangeOverflow","containment","_detectInlineRangeProblems","previousElementSibling","_endOffsetForNode","dontFix","allUneditables","deepUneditables","tmpRanges","tmpRange","jmax","selectAll","blankEndNode","blankStartNode","doSelect","notSelected","getHtml","getPlainText","isEndToEndInNode","nodeNames","isInThisEditable","cssClass","regExp","matchingClassNames","hasStyleAttr","removeStyle","s2","getMatchingStyleRegexp","regexes","sSplit","elStyle","isMatchingAllready","areMatchingAllready","removeOrChangeStyle","exactRegex","hasSameClasses","el1","el2","REG_EXP_WHITE_SPACE","replaceWithOwnChildren","elementsHaveSameNonClassAttributes","attr1","attr2","getNamedItem","isSplitPoint","splitNodeAt","descendantNode","descendantOffset","Merge","firstNode","isElementMerge","firstTextNode","HTMLApplier","tagNames","similarClassRegExp","similarStyleRegExp","defaultTagName","applyToAnyTagName","doMerge","textBits","getAncestorWithClass","cssClassMatch","getAncestorWithStyle","cssStyleMatch","getMatchingAncestor","matchType","postApply","currentMerge","precedingTextNode","lastNode","merges","rangeStartNode","rangeEndNode","rangeStartOffset","rangeEndOffset","getAdjacentMergeableTextNode","nextTextNode","adjacentNode","isTextNode","areElementsMergeable","createContainer","applyToTextNode","isRemovable","undoToTextNode","ancestorWithClass","ancestorWithStyle","styleMode","styleChanged","ancestorRange","applyToRange","ri","undoToRange","getTextSelectedByRange","isAppliedToRange","appliedType","coverage","selectedText","toggleRange","parentsExactMatch","isApplied","Commands","support","commandValue","state","stateValue","bold","formatInline","getOptions","createLink","opts","removeLink","size","fontSizeStyle","st","foreColor","foreColorStyle","colorVals","colString","bgColorStyle","correctOptionsForSimilarityCheck","isBlock","isBookmark","isLineBreaking","cleanup","newBlockElements","nbIdx","allElements","BLOCK_ELEMENTS","noEditQuery","classNames","uneditableContainer","defaultNodeName","findOuterBlock","allBlocks","UNNESTABLE_BLOCK_ELEMENTS","cloneOuterInlines","innerNode","INLINE_ELEMENTS","outerNode","applyOptionsToElement","removeOptionsFromElement","unwrapped","applySurroundingLineBreaks","unwrapBlocksFromContent","nextEl","prevEl","blocks","fixRangeCoverage","fixNotPermittedInsertionPoints","lis","maxj","rangePos","closestLI","newRanges","getOptionsWithNodename","defaultName","correctedOptions","injectFragmentToRange","firstOuterBlock","outerInlines","first","last","rangeStartContainer","fc","lc","clearRangeBlockFromating","closestBlockName","removeSurroundingLineBreaks","prevPrev","wrapRangeWithElement","similarOptions","isWhitespaceBefore","isWhitespaceAfter","similarOuterBlock","splitAllBlocks","trimBlankTextsAndBreaks","tmpEl","getParentBlockNodeName","expandCaretToBlock","insertingNodeName","selectElements","lastEl","lastOffset","formatSelection","parseOptions","caretIsOnEmptyLine","caretInfo","parentNodes","formatCode","classname","selectedNodes","pre","selectedNode","hasNoClass","hasNoStyle","hasNoAttributes","isSameNode","element1","element2","classes1","classes2","createWrapNode","defaultTag","containsSameAttributes","updateElementAttributes","newAttributes","fullContain","updateFormatOfElement","nodeNameQuery","nodeQueryMatch","queryAliasMap","getSelectedTextNodes","findSimilarTextNodeWrapper","exact","isSimilarNode","selectRange","selectTextNodes","lastText","selectTextNode","getState","searchNodes","partial","caretIsInsideWord","beforeChar","afterChar","getRangeForWord","offsetStart","offsetEnd","txtNodes","wordOffset","mergeContents","mergeConsequentSimilarElements","cleanupAndSetSelection","cleanupAndSetCaret","formatTextNode","wrapNode","unformatTextNode","newWrapNode","removeFormatFromTextNode","formatTextRange","updateFormat","wordObj","exactState","removeFormat","applyFormat","fixOptions","b","strong","em","insertBlockQuote","NODE_NAME","insertImage","image","imagesInSelection","LINE_BREAK","insertLineBreak","insertList","isNode","findListEl","other","parentLi","otherNodeName","handleSameTypeList","otherLists","innerLists","getListsInSelection","handleOtherTypeList","renameLists","createListFallback","tempClassName","getTime","cmd","italic","justifyCenter","justifyLeft","justifyRight","justifyFull","alignRightStyle","alignLeftStyle","alignCenterStyle","alignJustifyStyle","redo","undoManager","underline","undo","createTable","cols","rows","tableStyle","mergeTableCells","tableSelection","addTableCells","tableSelect","deleteTableCells","selCell","indentList","listEls","tryToPushLiLevel","liNodes","listTag","prevLi","liNode","prevLiList","outdentList","tryToPullLiLevel","listNode","outerListNode","outerLiNode","afterList","getAfterList","newList","subscript","superscript","Z_KEY","Y_KEY","MAX_HISTORY_ENTRIES","DATA_ATTR_NODE","DATA_ATTR_OFFSET","UndoManager","historyStr","historyDom","transact","_observe","lastKey","sandbox","altKey","isUndo","shiftKey","isRedo","previousHtml","currentHtml","getValue","getChildNodeIndex","undoPossible","redoPossible","historyEntry","getChildNodeByIndex","View","textareaElement","noTextarea","_observeViewChange","currentView","show","hide","disable","enable","Composer","editableElement","textarea","contentEditableMode","_initContentEditableArea","_initSandbox","_displayStyle","disabled","setToEnd","pageYOffset","pageXOffset","scrollTo","_create","_createWysiwygFormField","form","hiddenField","_initAutoLinking","placeholder","_initObjectResizing","_initUndoManager","_initLineBreaking","initSync","sync","supportsDisablingOfAutoLinking","supportsAutoLinking","nodeWithSelection","isInUneditable","links","urlRegExp","newTextContent","propertiesLength","adjust","USE_NATIVE_LINE_BREAK_INSIDE_TAGS","LIST_TAGS","defaultPrevented","blockElement","HOST_TEMPLATE","TEXT_FORMATTING","BOX_FORMATTING","ADDITIONAL_CSS_RULES","focusWithoutScrolling","setActive","elementStyle","originalScrollTop","originalScrollLeft","originalStyles","WebkitUserSelect","displayValueForCopying","originalActiveElement","hasPlaceholder","originalPlaceholder","originalDisplayValue","originalDisabled","focusStylesHost","blurStylesHost","disabledStylesHost","blur","boxFormattingStyles","shortcuts","66","73","85","actions","addListeners","removeListeners","fixLastBrDeletionInTable","aNode","handleUneditableDeletion","fixDeleteInTheBeginningOfBlock","selNode","commonAncestorNode","fixDeleteInTheBeginningOfLi","isInBeginnig","fixDeleteInTheBeginningOfControlSelection","afterCaretNode","initTableHandling","hideHandlers","iframeInitiator","doLineBreaksModeEnterWithCaret","breakNodes","doubleLineBreakEscapesBlock","brNode","br1","br2","handleDeleteKeyPress","handleEnterKeyPress","handleTabKeyDown","handleDomNodeRemoved","domNodeRemovedInterval","clearInterval","handleUserInteraction","handleFocus","focusState","handleBlur","changeevent","create","handlePaste","handleCopy","copyedFromMarking","setData","handleKeyUp","allImages","notMyImages","myImages","lastMouseDownPos","clientX","clientY","handleIEControlSelect","caretPosition","moveToPoint","handleClick","uneditable","handleDrop","handleKeyDown","handleTabKey","observeActions","focusBlurElement","setInterval","handleTables","INTERVAL","Synchronizer","fromComposerToTextarea","shouldParseHtml","fromTextareaToComposer","textareaValue","interval","startInterval","stopInterval","SourceView","switchToTextarea","composerStyles","switchToComposer","Textarea","supportsPlaceholder","eventMapping","focusin","focusout","undef","defaultConfig","showToolbarAfterInit","showToolbarDialogsOnSelection","parserRules","br","div","u","pasteParserRulesets","parser","supportTouchDevices","Editor","_isCompatible","_initParser","handleBeforeLoad","sourceView","synchronizer","Toolbar","isCompatible","htmlOrElement","customRules","parseContext","oldHtml","_cleanAndPaste","pastedHTML","cleanHtml","CLASS_NAME_OPENED","SELECTOR_FORM_ELEMENTS","SELECTOR_FIELDS","ATTRIBUTE_FIELDS","Dialog","_observed","callbackWrapper","_serialize","cancel","fields","_interpolate","avoidHiddenFields","field","fieldName","focusedElement","elementToChange","defaultValue","update","firstField","isOpen","_hide","linkStyles","wrapperStyles","margin","opacity","padding","inputStyles","cursor","marginTop","outline","inputAttributes","x-webkit-speech","speech","Speech","getCommandState","dialog","multiselect","CLASS_NAME_COMMAND_DISABLED","CLASS_NAME_COMMANDS_DISABLED","CLASS_NAME_COMMAND_ACTIVE","CLASS_NAME_ACTION_ACTIVE","showOnInit","_getLinks","classNameCommandDisabled","classNameCommandsDisabled","classNameCommandActive","classNameActionActive","speechInputLinks","group","tracksBlankValue","_getDialog","caretBookmark","dialogElement","dialogContainer","commandLink","_execCommand","_hideAllDialogs","_preventInstantFocus","commandsDisabled","_updateLinkStates","execAction","commandLinks","actionLinks","unselectable","commandObj","commandMapping","preventFocus","_ownerDocumentClick","displayDialogAttributeValue","actionMapping","dataset","showdialogonselection","Dialog_createTable","Dialog_foreColorStyle","colourMode","firstElement","colourStr","colour","colormode","Dialog_fontSizeStyle"],"mappings":";;AAWA,GAAIA,YACFC,QAAS,QAGTC,YACAC,OACAC,UACAC,WACAC,QACAC,aACAC,SAEAC,gBAAiB,SACjBC,wBAAyB,UAEzBC,cAAe,4FAEfC,eAAgB,aAEhBC,aAAc,EACdC,UAAc,EAEdC,cAAgB,EAChBC,UAAgB,GAChBC,WAAgB,GAChBC,UAAgB,GAChBC,QAAgB,EAChBC,WAAgB,GAEjBpB,WAAUqB,UAAY,SAASC,EAAKC,GAkenC,QAASC,KACP,IACE,GAAIC,GAAI,GAAIC,aAAY,OAAQC,QAASC,IAAK,QAC9C,OAAQ,QAAUH,EAAEI,MAAQ,QAAUJ,EAAEE,OAAOC,IAC/C,MAAOE,IACT,OAAO,EA/dJC,OAAOC,UAAUC,OACpB,WAEE,GAAIC,GAAQ,oCACZH,QAAOC,UAAUC,KAAO,WACtB,MAAOE,MAAKC,QAAQF,EAAO,QAMjC,WACE,GAAIG,GAAQ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9D,EAAM1kD,MAAQy7B,EAAYO,cAAc,EAAG,EAAG,GAAIwsB,SAO3D79E,WACF,SAAUA,GACqBA,EAAUG,GAIxCH,GAAUK,QAAQ69E,qBAAuBl+E,EAAUK,QAAQk5E,OAAOxmE,QAChEwoE,aAAa,EAEb7B,WAAY,WACV,OAAQrZ,KAASl+D,KAAKwc,UAAUipB,cAAc,wCAAwCvS,QAGxFwkD,aAAc,SAASC,GACrB,GAAIG,GAAiBl0E,SAAS6hC,cAAc,UACxCmyC,EAAiB53E,KAAKwc,UAAUipB,cAAc,wCAC9Ck2C,EAAkB37E,KAAoB,gBAAMnC,EAAUM,KAAK6lC,OAAOhkC,KAAK+3E,iBAAiBl2E,UAAa7B,KAAK+3E,gBAAgB,GAAK/3E,KAAK+3E,gBAAmB,KACvJlsB,EAAiB,EAAiB8vB,EAAax1E,aAAa,SAAW,KACvE+3D,EAAiB,EAAargE,EAAUI,OAAO0wD,YAAYU,cAAcxD,GAAY,IAErF+rB,IAASA,IAAUE,GAAkB5Z,IAAS,QAAUn4D,KAAKm4D,KAC/D0Z,EAAM1kD,MAAQgrC,OAInBrgE"}
\ No newline at end of file
diff --git a/dist/wysihtml.all-commands.js b/dist/wysihtml.all-commands.js
new file mode 100644
index 0000000..e2f9515
--- /dev/null
+++ b/dist/wysihtml.all-commands.js
@@ -0,0 +1,602 @@
+wysihtml.commands.alignCenterStyle = (function() {
+ var nodeOptions = {
+ styleProperty: "textAlign",
+ styleValue: "center",
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
+ }
+ };
+})();
+
+wysihtml.commands.alignJustifyStyle = (function() {
+ var nodeOptions = {
+ styleProperty: "textAlign",
+ styleValue: "justify",
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
+ }
+ };
+})();
+
+wysihtml.commands.alignLeftStyle = (function() {
+ var nodeOptions = {
+ styleProperty: "textAlign",
+ styleValue: "left",
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
+ }
+ };
+})();
+
+wysihtml.commands.alignRightStyle = (function() {
+ var nodeOptions = {
+ styleProperty: "textAlign",
+ styleValue: "right",
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
+ }
+ };
+})();
+
+/* Sets text background color by inline styles */
+wysihtml.commands.bgColorStyle = (function() {
+ return {
+ exec: function(composer, command, color) {
+ var colorVals = wysihtml.quirks.styleParser.parseColor("background-color:" + (color.color || color), "background-color"),
+ colString;
+
+ if (colorVals) {
+ colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(', ') : "rgba(" + colorVals.join(', ')) + ')';
+ wysihtml.commands.formatInline.exec(composer, command, {styleProperty: 'backgroundColor', styleValue: colString});
+ }
+ },
+
+ state: function(composer, command, color) {
+ var colorVals = color ? wysihtml.quirks.styleParser.parseColor("background-color:" + (color.color || color), "background-color") : null,
+ colString;
+
+ if (colorVals) {
+ colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(', ') : "rgba(" + colorVals.join(', ')) + ')';
+ }
+
+ return wysihtml.commands.formatInline.state(composer, command, {styleProperty: 'backgroundColor', styleValue: colString});
+ },
+
+ remove: function(composer, command) {
+ return wysihtml.commands.formatInline.remove(composer, command, {styleProperty: 'backgroundColor'});
+ },
+
+ stateValue: function(composer, command, props) {
+ var st = this.state(composer, command),
+ colorStr,
+ val = false;
+
+ if (st && wysihtml.lang.object(st).isArray()) {
+ st = st[0];
+ }
+
+ if (st) {
+ colorStr = st.getAttribute('style');
+ if (colorStr) {
+ val = wysihtml.quirks.styleParser.parseColor(colorStr, "background-color");
+ return wysihtml.quirks.styleParser.unparseColor(val, props);
+ }
+ }
+ return false;
+ }
+ };
+})();
+
+wysihtml.commands.bold = (function() {
+ var nodeOptions = {
+ nodeName: "B",
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ wysihtml.commands.formatInline.exec(composer, command, nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatInline.state(composer, command, nodeOptions);
+ }
+ };
+})();
+
+/* Formats block for as a
block
+ * Useful in conjuction for sytax highlight utility: highlight.js
+ *
+ * Usage:
+ *
+ * editorInstance.composer.commands.exec("formatCode", "language-html");
+*/
+wysihtml.commands.formatCode = (function() {
+ return {
+ exec: function(composer, command, classname) {
+ var pre = this.state(composer)[0],
+ code, range, selectedNodes;
+
+ if (pre) {
+ // caret is already within a ...
+ composer.selection.executeAndRestore(function() {
+ code = pre.querySelector("code");
+ wysihtml.dom.replaceWithChildNodes(pre);
+ if (code) {
+ wysihtml.dom.replaceWithChildNodes(code);
+ }
+ });
+ } else {
+ // Wrap in ...
+ range = composer.selection.getRange();
+ selectedNodes = range.extractContents();
+ pre = composer.doc.createElement("pre");
+ code = composer.doc.createElement("code");
+
+ if (classname) {
+ code.className = classname;
+ }
+
+ pre.appendChild(code);
+ code.appendChild(selectedNodes);
+ range.insertNode(pre);
+ composer.selection.selectNode(pre);
+ }
+ },
+
+ state: function(composer) {
+ var selectedNode = composer.selection.getSelectedNode(), node;
+ if (selectedNode && selectedNode.nodeName && selectedNode.nodeName == "PRE"&&
+ selectedNode.firstChild && selectedNode.firstChild.nodeName && selectedNode.firstChild.nodeName == "CODE") {
+ return [selectedNode];
+ } else {
+ node = wysihtml.dom.getParentElement(selectedNode, { query: "pre code" });
+ return node ? [node.parentNode] : false;
+ }
+ }
+ };
+})();
+
+/**
+ * Inserts an
+ * If selection is already an image link, it removes it
+ *
+ * @example
+ * // either ...
+ * wysihtml.commands.insertImage.exec(composer, "insertImage", "http://www.google.de/logo.jpg");
+ * // ... or ...
+ * wysihtml.commands.insertImage.exec(composer, "insertImage", { src: "http://www.google.de/logo.jpg", title: "foo" });
+ */
+wysihtml.commands.insertImage = (function() {
+ var NODE_NAME = "IMG";
+ return {
+ exec: function(composer, command, value) {
+ value = typeof(value) === "object" ? value : { src: value };
+
+ var doc = composer.doc,
+ image = this.state(composer),
+ textNode,
+ parent;
+
+ // If image is selected and src ie empty, set the caret before it and delete the image
+ if (image && !value.src) {
+ composer.selection.setBefore(image);
+ parent = image.parentNode;
+ parent.removeChild(image);
+
+ // and it's parent too if it hasn't got any other relevant child nodes
+ wysihtml.dom.removeEmptyTextNodes(parent);
+ if (parent.nodeName === "A" && !parent.firstChild) {
+ composer.selection.setAfter(parent);
+ parent.parentNode.removeChild(parent);
+ }
+
+ // firefox and ie sometimes don't remove the image handles, even though the image got removed
+ wysihtml.quirks.redraw(composer.element);
+ return;
+ }
+
+ // If image selected change attributes accordingly
+ if (image) {
+ for (var key in value) {
+ if (value.hasOwnProperty(key)) {
+ image.setAttribute(key === "className" ? "class" : key, value[key]);
+ }
+ }
+ return;
+ }
+
+ // Otherwise lets create the image
+ image = doc.createElement(NODE_NAME);
+
+ for (var i in value) {
+ image.setAttribute(i === "className" ? "class" : i, value[i]);
+ }
+
+ composer.selection.insertNode(image);
+ if (wysihtml.browser.hasProblemsSettingCaretAfterImg()) {
+ textNode = doc.createTextNode(wysihtml.INVISIBLE_SPACE);
+ composer.selection.insertNode(textNode);
+ composer.selection.setAfter(textNode);
+ } else {
+ composer.selection.setAfter(image);
+ }
+ },
+
+ state: function(composer) {
+ var doc = composer.doc,
+ selectedNode,
+ text,
+ imagesInSelection;
+
+ if (!wysihtml.dom.hasElementWithTagName(doc, NODE_NAME)) {
+ return false;
+ }
+
+ selectedNode = composer.selection.getSelectedNode();
+ if (!selectedNode) {
+ return false;
+ }
+
+ if (selectedNode.nodeName === NODE_NAME) {
+ // This works perfectly in IE
+ return selectedNode;
+ }
+
+ if (selectedNode.nodeType !== wysihtml.ELEMENT_NODE) {
+ return false;
+ }
+
+ text = composer.selection.getText();
+ text = wysihtml.lang.string(text).trim();
+ if (text) {
+ return false;
+ }
+
+ imagesInSelection = composer.selection.getNodes(wysihtml.ELEMENT_NODE, function(node) {
+ return node.nodeName === "IMG";
+ });
+
+ if (imagesInSelection.length !== 1) {
+ return false;
+ }
+
+ return imagesInSelection[0];
+ }
+ };
+})();
+
+wysihtml.commands.fontSize = (function() {
+ var REG_EXP = /wysiwyg-font-size-[0-9a-z\-]+/g;
+
+ return {
+ exec: function(composer, command, size) {
+ wysihtml.commands.formatInline.exec(composer, command, {className: "wysiwyg-font-size-" + size, classRegExp: REG_EXP, toggle: true});
+ },
+
+ state: function(composer, command, size) {
+ return wysihtml.commands.formatInline.state(composer, command, {className: "wysiwyg-font-size-" + size});
+ }
+ };
+})();
+
+/* Set font size by inline style */
+wysihtml.commands.fontSizeStyle = (function() {
+ return {
+ exec: function(composer, command, size) {
+ size = size.size || size;
+ if (!(/^\s*$/).test(size)) {
+ wysihtml.commands.formatInline.exec(composer, command, {styleProperty: "fontSize", styleValue: size, toggle: false});
+ }
+ },
+
+ state: function(composer, command, size) {
+ return wysihtml.commands.formatInline.state(composer, command, {styleProperty: "fontSize", styleValue: size || undefined});
+ },
+
+ remove: function(composer, command) {
+ return wysihtml.commands.formatInline.remove(composer, command, {styleProperty: "fontSize"});
+ },
+
+ stateValue: function(composer, command) {
+ var styleStr,
+ st = this.state(composer, command);
+
+ if (st && wysihtml.lang.object(st).isArray()) {
+ st = st[0];
+ }
+ if (st) {
+ styleStr = st.getAttribute("style");
+ if (styleStr) {
+ return wysihtml.quirks.styleParser.parseFontSize(styleStr);
+ }
+ }
+ return false;
+ }
+ };
+})();
+
+wysihtml.commands.foreColor = (function() {
+ var REG_EXP = /wysiwyg-color-[0-9a-z]+/g;
+
+ return {
+ exec: function(composer, command, color) {
+ wysihtml.commands.formatInline.exec(composer, command, {className: "wysiwyg-color-" + color, classRegExp: REG_EXP, toggle: true});
+ },
+
+ state: function(composer, command, color) {
+ return wysihtml.commands.formatInline.state(composer, command, {className: "wysiwyg-color-" + color});
+ }
+ };
+})();
+
+/* Sets text color by inline styles */
+wysihtml.commands.foreColorStyle = (function() {
+ return {
+ exec: function(composer, command, color) {
+ var colorVals, colString;
+
+ if (!color) { return; }
+
+ colorVals = wysihtml.quirks.styleParser.parseColor("color:" + (color.color || color), "color");
+
+ if (colorVals) {
+ colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(", ") : "rgba(" + colorVals.join(', ')) + ')';
+ wysihtml.commands.formatInline.exec(composer, command, {styleProperty: "color", styleValue: colString});
+ }
+ },
+
+ state: function(composer, command, color) {
+ var colorVals = color ? wysihtml.quirks.styleParser.parseColor("color:" + (color.color || color), "color") : null,
+ colString;
+
+
+ if (colorVals) {
+ colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(", ") : "rgba(" + colorVals.join(', ')) + ')';
+ }
+
+ return wysihtml.commands.formatInline.state(composer, command, {styleProperty: "color", styleValue: colString});
+ },
+
+ remove: function(composer, command) {
+ return wysihtml.commands.formatInline.remove(composer, command, {styleProperty: "color"});
+ },
+
+ stateValue: function(composer, command, props) {
+ var st = this.state(composer, command),
+ colorStr,
+ val = false;
+
+ if (st && wysihtml.lang.object(st).isArray()) {
+ st = st[0];
+ }
+
+ if (st) {
+ colorStr = st.getAttribute("style");
+ if (colorStr) {
+ val = wysihtml.quirks.styleParser.parseColor(colorStr, "color");
+ return wysihtml.quirks.styleParser.unparseColor(val, props);
+ }
+ }
+ return false;
+ }
+ };
+})();
+
+wysihtml.commands.insertBlockQuote = (function() {
+ var nodeOptions = {
+ nodeName: "BLOCKQUOTE",
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
+ }
+ };
+})();
+
+wysihtml.commands.insertOrderedList = (function() {
+ return {
+ exec: function(composer, command) {
+ wysihtml.commands.insertList.exec(composer, command, "OL");
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.insertList.state(composer, command, "OL");
+ }
+ };
+})();
+
+wysihtml.commands.insertUnorderedList = (function() {
+ return {
+ exec: function(composer, command) {
+ wysihtml.commands.insertList.exec(composer, command, "UL");
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.insertList.state(composer, command, "UL");
+ }
+ };
+})();
+
+wysihtml.commands.italic = (function() {
+ var nodeOptions = {
+ nodeName: "I",
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ wysihtml.commands.formatInline.exec(composer, command, nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatInline.state(composer, command, nodeOptions);
+ }
+ };
+
+})();
+
+wysihtml.commands.justifyCenter = (function() {
+ var nodeOptions = {
+ className: "wysiwyg-text-align-center",
+ classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
+ }
+ };
+
+})();
+
+wysihtml.commands.justifyFull = (function() {
+ var nodeOptions = {
+ className: "wysiwyg-text-align-justify",
+ classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
+ }
+ };
+})();
+
+wysihtml.commands.justifyLeft = (function() {
+ var nodeOptions = {
+ className: "wysiwyg-text-align-left",
+ classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
+ }
+ };
+})();
+
+wysihtml.commands.justifyRight = (function() {
+ var nodeOptions = {
+ className: "wysiwyg-text-align-right",
+ classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ return wysihtml.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
+ }
+ };
+})();
+
+wysihtml.commands.subscript = (function() {
+ var nodeOptions = {
+ nodeName: "SUB",
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ wysihtml.commands.formatInline.exec(composer, command, nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatInline.state(composer, command, nodeOptions);
+ }
+ };
+
+})();
+
+wysihtml.commands.superscript = (function() {
+ var nodeOptions = {
+ nodeName: "SUP",
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ wysihtml.commands.formatInline.exec(composer, command, nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatInline.state(composer, command, nodeOptions);
+ }
+ };
+
+})();
+
+wysihtml.commands.underline = (function() {
+ var nodeOptions = {
+ nodeName: "U",
+ toggle: true
+ };
+
+ return {
+ exec: function(composer, command) {
+ wysihtml.commands.formatInline.exec(composer, command, nodeOptions);
+ },
+
+ state: function(composer, command) {
+ return wysihtml.commands.formatInline.state(composer, command, nodeOptions);
+ }
+ };
+
+})();
diff --git a/dist/wysihtml.js b/dist/wysihtml.js
index 716cadc..de933d7 100644
--- a/dist/wysihtml.js
+++ b/dist/wysihtml.js
@@ -1,5 +1,5 @@
/**
- * @license wysihtml v0.5.5
+ * @license wysihtml v0.6.beta
* https://github.com/Voog/wysihtml
*
* Author: Christopher Blum (https://github.com/tiff)
@@ -9,8 +9,8 @@
* Licensed under the MIT license (MIT)
*
*/
-var wysihtml5 = {
- version: "0.5.5",
+var wysihtml = {
+ version: "0.6.beta",
// namespaces
commands: {},
@@ -21,6 +21,11 @@ var wysihtml5 = {
selection: {},
views: {},
+ editorExtenders: [],
+ extendEditor: function(extender) {
+ this.editorExtenders.push(extender);
+ },
+
INVISIBLE_SPACE: "\uFEFF",
INVISIBLE_SPACE_REG_EXP: /\uFEFF/g,
@@ -38,104 +43,12 @@ var wysihtml5 = {
TAB_KEY: 9,
DELETE_KEY: 46
};
-;wysihtml5.polyfills = function(win, doc) {
-
- // TODO: in future try to replace most inline compability checks with polyfills for code readability
-
- // IE8 SUPPORT BLOCK
- // You can compile without all this if IE8 is not needed
-
- // String trim for ie8
- if (!String.prototype.trim) {
- (function() {
- // Make sure we trim BOM and NBSP
- var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
- String.prototype.trim = function() {
- return this.replace(rtrim, '');
- };
- })();
- }
-
- // addEventListener, removeEventListener
- (function() {
- var s_add = 'addEventListener',
- s_rem = 'removeEventListener';
- if( doc[s_add] ) return;
- win.Element.prototype[ s_add ] = win[ s_add ] = doc[ s_add ] = function( on, fn, self ) {
- return (self = this).attachEvent( 'on' + on, function(e){
- var e = e || win.event;
- e.target = e.target || e.srcElement;
- e.preventDefault = e.preventDefault || function(){e.returnValue = false};
- e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true};
- e.which = e.button ? ( e.button === 2 ? 3 : e.button === 4 ? 2 : e.button ) : e.keyCode;
- fn.call(self, e);
- });
- };
- win.Element.prototype[ s_rem ] = win[ s_rem ] = doc[ s_rem ] = function( on, fn ) {
- return this.detachEvent( 'on' + on, fn );
- };
- })();
-
- // element.textContent polyfill.
- if (Object.defineProperty && Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(win.Element.prototype, "textContent") && !Object.getOwnPropertyDescriptor(win.Element.prototype, "textContent").get) {
- (function() {
- var innerText = Object.getOwnPropertyDescriptor(win.Element.prototype, "innerText");
- Object.defineProperty(win.Element.prototype, "textContent",
- {
- get: function() {
- return innerText.get.call(this);
- },
- set: function(s) {
- return innerText.set.call(this, s);
- }
- }
- );
- })();
- }
-
- // isArray polyfill for ie8
- if(!Array.isArray) {
- Array.isArray = function(arg) {
- return Object.prototype.toString.call(arg) === '[object Array]';
- };
- }
-
- // Array indexOf for ie8
- if (!Array.prototype.indexOf) {
- Array.prototype.indexOf = function(a,f) {
- for(var c=this.length,r=-1,d=f>>>0; ~(c-d); r=this[--c]===a?c:r);
- return r;
- };
- }
- // Function.prototype.bind()
- // TODO: clean the code from variable 'that' as it can be confusing
- if (!Function.prototype.bind) {
- Function.prototype.bind = function(oThis) {
- if (typeof this !== 'function') {
- // closest thing possible to the ECMAScript 5
- // internal IsCallable function
- throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
- }
-
- var aArgs = Array.prototype.slice.call(arguments, 1),
- fToBind = this,
- fNOP = function() {},
- fBound = function() {
- return fToBind.apply(this instanceof fNOP && oThis
- ? this
- : oThis,
- aArgs.concat(Array.prototype.slice.call(arguments)));
- };
-
- fNOP.prototype = this.prototype;
- fBound.prototype = new fNOP();
+wysihtml.polyfills = function(win, doc) {
- return fBound;
- };
- }
+ // TODO: in future try to replace most inline compability checks with polyfills for code readability
- // closest and matches polyfill
+ // closest, matches, and remove polyfill
// https://github.com/jonathantneal/closest
(function (ELEMENT) {
ELEMENT.matches = ELEMENT.matches || ELEMENT.mozMatchesSelector || ELEMENT.msMatchesSelector || ELEMENT.oMatchesSelector || ELEMENT.webkitMatchesSelector || function matches(selector) {
@@ -164,245 +77,86 @@ var wysihtml5 = {
return element;
};
- }(Element.prototype));
-
- // Element.classList for ie8-9 (toggle all IE)
- // source http://purl.eligrey.com/github/classList.js/blob/master/classList.js
-
- if ("document" in win) {
- // Full polyfill for browsers with no classList support
- if (!("classList" in doc.createElement("_"))) {
- (function(view) {
- "use strict";
- if (!('Element' in view)) return;
-
- var
- classListProp = "classList",
- protoProp = "prototype",
- elemCtrProto = view.Element[protoProp],
- objCtr = Object,
- strTrim = String[protoProp].trim || function() {
- return this.replace(/^\s+|\s+$/g, "");
- },
- arrIndexOf = Array[protoProp].indexOf || function(item) {
- var
- i = 0,
- len = this.length;
- for (; i < len; i++) {
- if (i in this && this[i] === item) {
- return i;
- }
- }
- return -1;
- }, // Vendors: please allow content code to instantiate DOMExceptions
- DOMEx = function(type, message) {
- this.name = type;
- this.code = DOMException[type];
- this.message = message;
- },
- checkTokenAndGetIndex = function(classList, token) {
- if (token === "") {
- throw new DOMEx(
- "SYNTAX_ERR", "An invalid or illegal string was specified"
- );
- }
- if (/\s/.test(token)) {
- throw new DOMEx(
- "INVALID_CHARACTER_ERR", "String contains an invalid character"
- );
- }
- return arrIndexOf.call(classList, token);
- },
- ClassList = function(elem) {
- var
- trimmedClasses = strTrim.call(elem.getAttribute("class") || ""),
- classes = trimmedClasses ? trimmedClasses.split(/\s+/) : [],
- i = 0,
- len = classes.length;
- for (; i < len; i++) {
- this.push(classes[i]);
- }
- this._updateClassName = function() {
- elem.setAttribute("class", this.toString());
- };
- },
- classListProto = ClassList[protoProp] = [],
- classListGetter = function() {
- return new ClassList(this);
- };
- // Most DOMException implementations don't allow calling DOMException's toString()
- // on non-DOMExceptions. Error's toString() is sufficient here.
- DOMEx[protoProp] = Error[protoProp];
- classListProto.item = function(i) {
- return this[i] || null;
- };
- classListProto.contains = function(token) {
- token += "";
- return checkTokenAndGetIndex(this, token) !== -1;
- };
- classListProto.add = function() {
- var
- tokens = arguments,
- i = 0,
- l = tokens.length,
- token, updated = false;
- do {
- token = tokens[i] + "";
- if (checkTokenAndGetIndex(this, token) === -1) {
- this.push(token);
- updated = true;
- }
- }
- while (++i < l);
-
- if (updated) {
- this._updateClassName();
- }
- };
- classListProto.remove = function() {
- var
- tokens = arguments,
- i = 0,
- l = tokens.length,
- token, updated = false,
- index;
- do {
- token = tokens[i] + "";
- index = checkTokenAndGetIndex(this, token);
- while (index !== -1) {
- this.splice(index, 1);
- updated = true;
- index = checkTokenAndGetIndex(this, token);
- }
- }
- while (++i < l);
-
- if (updated) {
- this._updateClassName();
- }
- };
- classListProto.toggle = function(token, force) {
- token += "";
- var
- result = this.contains(token),
- method = result ?
- force !== true && "remove" :
- force !== false && "add";
+ ELEMENT.remove = ELEMENT.remove || function remove() {
+ if (this.parentNode) {
+ this.parentNode.removeChild(this);
+ }
+ };
- if (method) {
- this[method](token);
- }
+ }(win.Element.prototype));
- if (force === true || force === false) {
- return force;
- } else {
- return !result;
- }
- };
- classListProto.toString = function() {
- return this.join(" ");
- };
+ if (!('classList' in doc.documentElement) && win.Object.defineProperty && typeof HTMLElement !== 'undefined') {
+ win.Object.defineProperty(HTMLElement.prototype, 'classList', {
+ get: function() {
+ var self = this;
+ function update(fn) {
+ return function(value) {
+ var classes = self.className.split(/\s+/),
+ index = classes.indexOf(value);
- if (objCtr.defineProperty) {
- var classListPropDesc = {
- get: classListGetter,
- enumerable: true,
- configurable: true
+ fn(classes, index, value);
+ self.className = classes.join(' ');
};
- try {
- objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
- } catch (ex) { // IE 8 doesn't support enumerable:true
- if (ex.number === -0x7FF5EC54) {
- classListPropDesc.enumerable = false;
- objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
- }
- }
- } else if (objCtr[protoProp].__defineGetter__) {
- elemCtrProto.__defineGetter__(classListProp, classListGetter);
}
- }(win));
-
- } else if ("DOMTokenList" in win) {
- // There is full or partial native classList support, so just check if we need
- // to normalize the add/remove and toggle APIs.
- // DOMTokenList is expected to exist (removes conflicts with multiple polyfills present on site)
-
- (function() {
- "use strict";
-
- var testElement = doc.createElement("_");
-
- testElement.classList.add("c1", "c2");
-
- // Polyfill for IE 10/11 and Firefox <26, where classList.add and
- // classList.remove exist but support only one argument at a time.
- if (!testElement.classList.contains("c2")) {
- var createMethod = function(method) {
- var original = win.DOMTokenList.prototype[method];
-
- win.DOMTokenList.prototype[method] = function(token) {
- var i, len = arguments.length;
+ var ret = {
+ add: update(function(classes, index, value) {
+ ~index || classes.push(value);
+ }),
- for (i = 0; i < len; i++) {
- token = arguments[i];
- original.call(this, token);
- }
- };
- };
- createMethod('add');
- createMethod('remove');
- }
+ remove: update(function(classes, index) {
+ ~index && classes.splice(index, 1);
+ }),
- testElement.classList.toggle("c3", false);
+ toggle: update(function(classes, index, value) {
+ ~index ? classes.splice(index, 1) : classes.push(value);
+ }),
- // Polyfill for IE 10 and Firefox <24, where classList.toggle does not
- // support the second argument.
- if (testElement.classList.contains("c3")) {
- var _toggle = win.DOMTokenList.prototype.toggle;
+ contains: function(value) {
+ return !!~self.className.split(/\s+/).indexOf(value);
+ },
- win.DOMTokenList.prototype.toggle = function(token, force) {
- if (1 in arguments && !this.contains(token) === !force) {
- return force;
- } else {
- return _toggle.call(this, token);
+ item: function(i) {
+ return self.className.split(/\s+/)[i] || null;
}
};
- }
-
- testElement = null;
- }());
-
- }
+ win.Object.defineProperty(ret, 'length', {
+ get: function() {
+ return self.className.split(/\s+/).length;
+ }
+ });
+ return ret;
+ }
+ });
}
// Safary has a bug of not restoring selection after node.normalize correctly.
// Detects the misbegaviour and patches it
var normalizeHasCaretError = function() {
- if ("createRange" in document && "getSelection" in window) {
- var e = document.createElement('div'),
- t1 = document.createTextNode('a'),
- t2 = document.createTextNode('a'),
- t3 = document.createTextNode('a'),
- r = document.createRange(),
+ if ("createRange" in doc && "getSelection" in win) {
+ var e = doc.createElement('div'),
+ t1 = doc.createTextNode('a'),
+ t2 = doc.createTextNode('a'),
+ t3 = doc.createTextNode('a'),
+ r = doc.createRange(),
s, ret;
e.setAttribute('contenteditable', 'true');
e.appendChild(t1);
e.appendChild(t2);
e.appendChild(t3);
- document.body.appendChild(e);
+ doc.body.appendChild(e);
r.setStart(t2, 1);
r.setEnd(t2, 1);
- s = window.getSelection();
+ s = win.getSelection();
s.removeAllRanges();
s.addRange(r);
e.normalize();
- s = window.getSelection();
+ s = win.getSelection();
ret = (e.childNodes.length !== 1 || s.anchorNode !== e.firstChild || s.anchorOffset !== 2);
e.parentNode.removeChild(e);
@@ -438,7 +192,7 @@ var wysihtml5 = {
};
var normalizeFix = function() {
- var f = Node.prototype.normalize;
+ var f = win.Node.prototype.normalize;
var nf = function() {
var texts = getTextNodes(this),
s = this.ownerDocument.defaultView.getSelection(),
@@ -464,7 +218,7 @@ var wysihtml5 = {
aelement = undefined;
}
- if ((anode === fnode && foffset < aoffset) || (anode !== fnode && (anode.compareDocumentPosition(fnode) & Node.DOCUMENT_POSITION_PRECEDING) && !(anode.compareDocumentPosition(fnode) & Node.DOCUMENT_POSITION_CONTAINS))) {
+ if ((anode === fnode && foffset < aoffset) || (anode !== fnode && (anode.compareDocumentPosition(fnode) & win.Node.DOCUMENT_POSITION_PRECEDING) && !(anode.compareDocumentPosition(fnode) & win.Node.DOCUMENT_POSITION_CONTAINS))) {
fnode = [anode, anode = fnode][0];
foffset = [aoffset, aoffset = foffset][0];
}
@@ -503,18 +257,18 @@ var wysihtml5 = {
s.addRange(r);
}
};
- Node.prototype.normalize = nf;
+ win.Node.prototype.normalize = nf;
};
var F = function() {
- window.removeEventListener("load", F);
- if ("Node" in window && "normalize" in Node.prototype && normalizeHasCaretError()) {
+ win.removeEventListener("load", F);
+ if ("Node" in win && "normalize" in win.Node.prototype && normalizeHasCaretError()) {
normalizeFix();
}
};
if (doc.readyState !== "complete") {
- window.addEventListener("load", F);
+ win.addEventListener("load", F);
} else {
F();
}
@@ -531,7 +285,7 @@ var wysihtml5 = {
// Polyfills CustomEvent object for IE9 and up
(function() {
- if (!customEventSupported && "CustomEvent" in window) {
+ if (!customEventSupported && "CustomEvent" in win) {
function CustomEvent(event, params) {
params = params || {bubbles: false, cancelable: false, detail: undefined};
var evt = doc.createEvent('CustomEvent');
@@ -545,2453 +299,2584 @@ var wysihtml5 = {
})();
};
-wysihtml5.polyfills(window, document);
-;/**
- * Rangy, a cross-browser JavaScript range and selection library
- * https://github.com/timdown/rangy
- *
- * Copyright 2015, Tim Down
- * Licensed under the MIT license.
- * Version: 1.3.0
- * Build date: 10 May 2015
- */
-
-(function(factory, root) {
- if (typeof define == "function" && define.amd) {
- // AMD. Register as an anonymous module.
- define(factory);
- } else if (typeof module != "undefined" && typeof exports == "object") {
- // Node/CommonJS style
- module.exports = factory();
- } else {
- // No AMD or CommonJS support so we place Rangy in (probably) the global variable
- root.rangy = factory();
- }
-})(function() {
-
- var OBJECT = "object", FUNCTION = "function", UNDEFINED = "undefined";
-
- // Minimal set of properties required for DOM Level 2 Range compliance. Comparison constants such as START_TO_START
- // are omitted because ranges in KHTML do not have them but otherwise work perfectly well. See issue 113.
- var domRangeProperties = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed",
- "commonAncestorContainer"];
-
- // Minimal set of methods required for DOM Level 2 Range compliance
- var domRangeMethods = ["setStart", "setStartBefore", "setStartAfter", "setEnd", "setEndBefore",
- "setEndAfter", "collapse", "selectNode", "selectNodeContents", "compareBoundaryPoints", "deleteContents",
- "extractContents", "cloneContents", "insertNode", "surroundContents", "cloneRange", "toString", "detach"];
-
- var textRangeProperties = ["boundingHeight", "boundingLeft", "boundingTop", "boundingWidth", "htmlText", "text"];
-
- // Subset of TextRange's full set of methods that we're interested in
- var textRangeMethods = ["collapse", "compareEndPoints", "duplicate", "moveToElementText", "parentElement", "select",
- "setEndPoint", "getBoundingClientRect"];
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Trio of functions taken from Peter Michaux's article:
- // http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting
- function isHostMethod(o, p) {
- var t = typeof o[p];
- return t == FUNCTION || (!!(t == OBJECT && o[p])) || t == "unknown";
- }
-
- function isHostObject(o, p) {
- return !!(typeof o[p] == OBJECT && o[p]);
- }
-
- function isHostProperty(o, p) {
- return typeof o[p] != UNDEFINED;
- }
-
- // Creates a convenience function to save verbose repeated calls to tests functions
- function createMultiplePropertyTest(testFunc) {
- return function(o, props) {
- var i = props.length;
- while (i--) {
- if (!testFunc(o, props[i])) {
- return false;
- }
- }
- return true;
- };
- }
-
- // Next trio of functions are a convenience to save verbose repeated calls to previous two functions
- var areHostMethods = createMultiplePropertyTest(isHostMethod);
- var areHostObjects = createMultiplePropertyTest(isHostObject);
- var areHostProperties = createMultiplePropertyTest(isHostProperty);
-
- function isTextRange(range) {
- return range && areHostMethods(range, textRangeMethods) && areHostProperties(range, textRangeProperties);
- }
-
- function getBody(doc) {
- return isHostObject(doc, "body") ? doc.body : doc.getElementsByTagName("body")[0];
- }
-
- var forEach = [].forEach ?
- function(arr, func) {
- arr.forEach(func);
- } :
- function(arr, func) {
- for (var i = 0, len = arr.length; i < len; ++i) {
- func(arr[i], i);
- }
- };
-
- var modules = {};
-
- var isBrowser = (typeof window != UNDEFINED && typeof document != UNDEFINED);
-
- var util = {
- isHostMethod: isHostMethod,
- isHostObject: isHostObject,
- isHostProperty: isHostProperty,
- areHostMethods: areHostMethods,
- areHostObjects: areHostObjects,
- areHostProperties: areHostProperties,
- isTextRange: isTextRange,
- getBody: getBody,
- forEach: forEach
- };
-
- var api = {
- version: "1.3.0",
- initialized: false,
- isBrowser: isBrowser,
- supported: true,
- util: util,
- features: {},
- modules: modules,
- config: {
- alertOnFail: false,
- alertOnWarn: false,
- preferTextRange: false,
- autoInitialize: (typeof rangyAutoInitialize == UNDEFINED) ? true : rangyAutoInitialize
- }
- };
-
- function consoleLog(msg) {
- if (typeof console != UNDEFINED && isHostMethod(console, "log")) {
- console.log(msg);
- }
- }
-
- function alertOrLog(msg, shouldAlert) {
- if (isBrowser && shouldAlert) {
- alert(msg);
- } else {
- consoleLog(msg);
- }
- }
-
- function fail(reason) {
- api.initialized = true;
- api.supported = false;
- alertOrLog("Rangy is not supported in this environment. Reason: " + reason, api.config.alertOnFail);
- }
-
- api.fail = fail;
-
- function warn(msg) {
- alertOrLog("Rangy warning: " + msg, api.config.alertOnWarn);
- }
-
- api.warn = warn;
-
- // Add utility extend() method
- var extend;
- if ({}.hasOwnProperty) {
- util.extend = extend = function(obj, props, deep) {
- var o, p;
- for (var i in props) {
- if (props.hasOwnProperty(i)) {
- o = obj[i];
- p = props[i];
- if (deep && o !== null && typeof o == "object" && p !== null && typeof p == "object") {
- extend(o, p, true);
- }
- obj[i] = p;
- }
- }
- // Special case for toString, which does not show up in for...in loops in IE <= 8
- if (props.hasOwnProperty("toString")) {
- obj.toString = props.toString;
- }
- return obj;
- };
-
- util.createOptions = function(optionsParam, defaults) {
- var options = {};
- extend(options, defaults);
- if (optionsParam) {
- extend(options, optionsParam);
- }
- return options;
- };
- } else {
- fail("hasOwnProperty not supported");
- }
-
- // Test whether we're in a browser and bail out if not
- if (!isBrowser) {
- fail("Rangy can only run in a browser");
- }
-
- // Test whether Array.prototype.slice can be relied on for NodeLists and use an alternative toArray() if not
- (function() {
- var toArray;
-
- if (isBrowser) {
- var el = document.createElement("div");
- el.appendChild(document.createElement("span"));
- var slice = [].slice;
- try {
- if (slice.call(el.childNodes, 0)[0].nodeType == 1) {
- toArray = function(arrayLike) {
- return slice.call(arrayLike, 0);
- };
- }
- } catch (e) {}
- }
-
- if (!toArray) {
- toArray = function(arrayLike) {
- var arr = [];
- for (var i = 0, len = arrayLike.length; i < len; ++i) {
- arr[i] = arrayLike[i];
- }
- return arr;
- };
- }
-
- util.toArray = toArray;
- })();
-
- // Very simple event handler wrapper function that doesn't attempt to solve issues such as "this" handling or
- // normalization of event properties
- var addListener;
- if (isBrowser) {
- if (isHostMethod(document, "addEventListener")) {
- addListener = function(obj, eventType, listener) {
- obj.addEventListener(eventType, listener, false);
- };
- } else if (isHostMethod(document, "attachEvent")) {
- addListener = function(obj, eventType, listener) {
- obj.attachEvent("on" + eventType, listener);
- };
- } else {
- fail("Document does not have required addEventListener or attachEvent method");
- }
-
- util.addListener = addListener;
- }
-
- var initListeners = [];
-
- function getErrorDesc(ex) {
- return ex.message || ex.description || String(ex);
- }
-
- // Initialization
- function init() {
- if (!isBrowser || api.initialized) {
- return;
- }
- var testRange;
- var implementsDomRange = false, implementsTextRange = false;
-
- // First, perform basic feature tests
-
- if (isHostMethod(document, "createRange")) {
- testRange = document.createRange();
- if (areHostMethods(testRange, domRangeMethods) && areHostProperties(testRange, domRangeProperties)) {
- implementsDomRange = true;
- }
- }
-
- var body = getBody(document);
- if (!body || body.nodeName.toLowerCase() != "body") {
- fail("No body element found");
- return;
- }
-
- if (body && isHostMethod(body, "createTextRange")) {
- testRange = body.createTextRange();
- if (isTextRange(testRange)) {
- implementsTextRange = true;
- }
- }
-
- if (!implementsDomRange && !implementsTextRange) {
- fail("Neither Range nor TextRange are available");
- return;
- }
-
- api.initialized = true;
- api.features = {
- implementsDomRange: implementsDomRange,
- implementsTextRange: implementsTextRange
- };
-
- // Initialize modules
- var module, errorMessage;
- for (var moduleName in modules) {
- if ( (module = modules[moduleName]) instanceof Module ) {
- module.init(module, api);
- }
- }
-
- // Call init listeners
- for (var i = 0, len = initListeners.length; i < len; ++i) {
- try {
- initListeners[i](api);
- } catch (ex) {
- errorMessage = "Rangy init listener threw an exception. Continuing. Detail: " + getErrorDesc(ex);
- consoleLog(errorMessage);
- }
- }
- }
-
- function deprecationNotice(deprecated, replacement, module) {
- if (module) {
- deprecated += " in module " + module.name;
- }
- api.warn("DEPRECATED: " + deprecated + " is deprecated. Please use " +
- replacement + " instead.");
- }
-
- function createAliasForDeprecatedMethod(owner, deprecated, replacement, module) {
- owner[deprecated] = function() {
- deprecationNotice(deprecated, replacement, module);
- return owner[replacement].apply(owner, util.toArray(arguments));
- };
- }
-
- util.deprecationNotice = deprecationNotice;
- util.createAliasForDeprecatedMethod = createAliasForDeprecatedMethod;
-
- // Allow external scripts to initialize this library in case it's loaded after the document has loaded
- api.init = init;
-
- // Execute listener immediately if already initialized
- api.addInitListener = function(listener) {
- if (api.initialized) {
- listener(api);
- } else {
- initListeners.push(listener);
- }
- };
-
- var shimListeners = [];
-
- api.addShimListener = function(listener) {
- shimListeners.push(listener);
- };
-
- function shim(win) {
- win = win || window;
- init();
-
- // Notify listeners
- for (var i = 0, len = shimListeners.length; i < len; ++i) {
- shimListeners[i](win);
- }
- }
-
- if (isBrowser) {
- api.shim = api.createMissingNativeApi = shim;
- createAliasForDeprecatedMethod(api, "createMissingNativeApi", "shim");
- }
-
- function Module(name, dependencies, initializer) {
- this.name = name;
- this.dependencies = dependencies;
- this.initialized = false;
- this.supported = false;
- this.initializer = initializer;
- }
-
- Module.prototype = {
- init: function() {
- var requiredModuleNames = this.dependencies || [];
- for (var i = 0, len = requiredModuleNames.length, requiredModule, moduleName; i < len; ++i) {
- moduleName = requiredModuleNames[i];
-
- requiredModule = modules[moduleName];
- if (!requiredModule || !(requiredModule instanceof Module)) {
- throw new Error("required module '" + moduleName + "' not found");
- }
-
- requiredModule.init();
-
- if (!requiredModule.supported) {
- throw new Error("required module '" + moduleName + "' not supported");
- }
- }
-
- // Now run initializer
- this.initializer(this);
- },
-
- fail: function(reason) {
- this.initialized = true;
- this.supported = false;
- throw new Error(reason);
- },
-
- warn: function(msg) {
- api.warn("Module " + this.name + ": " + msg);
- },
-
- deprecationNotice: function(deprecated, replacement) {
- api.warn("DEPRECATED: " + deprecated + " in module " + this.name + " is deprecated. Please use " +
- replacement + " instead");
- },
-
- createError: function(msg) {
- return new Error("Error in Rangy " + this.name + " module: " + msg);
- }
- };
-
- function createModule(name, dependencies, initFunc) {
- var newModule = new Module(name, dependencies, function(module) {
- if (!module.initialized) {
- module.initialized = true;
- try {
- initFunc(api, module);
- module.supported = true;
- } catch (ex) {
- var errorMessage = "Module '" + name + "' failed to load: " + getErrorDesc(ex);
- consoleLog(errorMessage);
- if (ex.stack) {
- consoleLog(ex.stack);
- }
- }
- }
- });
- modules[name] = newModule;
- return newModule;
- }
-
- api.createModule = function(name) {
- // Allow 2 or 3 arguments (second argument is an optional array of dependencies)
- var initFunc, dependencies;
- if (arguments.length == 2) {
- initFunc = arguments[1];
- dependencies = [];
- } else {
- initFunc = arguments[2];
- dependencies = arguments[1];
- }
-
- var module = createModule(name, dependencies, initFunc);
-
- // Initialize the module immediately if the core is already initialized
- if (api.initialized && api.supported) {
- module.init();
- }
- };
-
- api.createCoreModule = function(name, dependencies, initFunc) {
- createModule(name, dependencies, initFunc);
- };
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Ensure rangy.rangePrototype and rangy.selectionPrototype are available immediately
-
- function RangePrototype() {}
- api.RangePrototype = RangePrototype;
- api.rangePrototype = new RangePrototype();
-
- function SelectionPrototype() {}
- api.selectionPrototype = new SelectionPrototype();
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // DOM utility methods used by Rangy
- api.createCoreModule("DomUtil", [], function(api, module) {
- var UNDEF = "undefined";
- var util = api.util;
- var getBody = util.getBody;
-
- // Perform feature tests
- if (!util.areHostMethods(document, ["createDocumentFragment", "createElement", "createTextNode"])) {
- module.fail("document missing a Node creation method");
- }
-
- if (!util.isHostMethod(document, "getElementsByTagName")) {
- module.fail("document missing getElementsByTagName method");
- }
-
- var el = document.createElement("div");
- if (!util.areHostMethods(el, ["insertBefore", "appendChild", "cloneNode"] ||
- !util.areHostObjects(el, ["previousSibling", "nextSibling", "childNodes", "parentNode"]))) {
- module.fail("Incomplete Element implementation");
- }
-
- // innerHTML is required for Range's createContextualFragment method
- if (!util.isHostProperty(el, "innerHTML")) {
- module.fail("Element is missing innerHTML property");
- }
-
- var textNode = document.createTextNode("test");
- if (!util.areHostMethods(textNode, ["splitText", "deleteData", "insertData", "appendData", "cloneNode"] ||
- !util.areHostObjects(el, ["previousSibling", "nextSibling", "childNodes", "parentNode"]) ||
- !util.areHostProperties(textNode, ["data"]))) {
- module.fail("Incomplete Text Node implementation");
- }
+wysihtml.polyfills(window, document);
- /*----------------------------------------------------------------------------------------------------------------*/
+/*
+ Base.js, version 1.1a
+ Copyright 2006-2010, Dean Edwards
+ License: http://www.opensource.org/licenses/mit-license.php
+*/
- // Removed use of indexOf because of a bizarre bug in Opera that is thrown in one of the Acid3 tests. I haven't been
- // able to replicate it outside of the test. The bug is that indexOf returns -1 when called on an Array that
- // contains just the document as a single element and the value searched for is the document.
- var arrayContains = /*Array.prototype.indexOf ?
- function(arr, val) {
- return arr.indexOf(val) > -1;
- }:*/
+var Base = function() {
+ // dummy
+};
- function(arr, val) {
- var i = arr.length;
- while (i--) {
- if (arr[i] === val) {
- return true;
- }
- }
- return false;
- };
+Base.extend = function(_instance, _static) { // subclass
+ var extend = Base.prototype.extend;
+
+ // build the prototype
+ Base._prototyping = true;
+ var proto = new this;
+ extend.call(proto, _instance);
+ proto.base = function() {
+ // call this method from any other method to invoke that method's ancestor
+ };
+ delete Base._prototyping;
+
+ // create the wrapper for the constructor function
+ //var constructor = proto.constructor.valueOf(); //-dean
+ var constructor = proto.constructor;
+ var klass = proto.constructor = function() {
+ if (!Base._prototyping) {
+ if (this._constructing || this.constructor == klass) { // instantiation
+ this._constructing = true;
+ constructor.apply(this, arguments);
+ delete this._constructing;
+ } else if (arguments[0] != null) { // casting
+ return (arguments[0].extend || extend).call(arguments[0], proto);
+ }
+ }
+ };
+
+ // build the class interface
+ klass.ancestor = this;
+ klass.extend = this.extend;
+ klass.forEach = this.forEach;
+ klass.implement = this.implement;
+ klass.prototype = proto;
+ klass.toString = this.toString;
+ klass.valueOf = function(type) {
+ //return (type == "object") ? klass : constructor; //-dean
+ return (type == "object") ? klass : constructor.valueOf();
+ };
+ extend.call(klass, _static);
+ // class initialisation
+ if (typeof klass.init == "function") klass.init();
+ return klass;
+};
- // Opera 11 puts HTML elements in the null namespace, it seems, and IE 7 has undefined namespaceURI
- function isHtmlNamespace(node) {
- var ns;
- return typeof node.namespaceURI == UNDEF || ((ns = node.namespaceURI) === null || ns == "http://www.w3.org/1999/xhtml");
- }
+Base.prototype = {
+ extend: function(source, value) {
+ if (arguments.length > 1) { // extending with a name/value pair
+ var ancestor = this[source];
+ if (ancestor && (typeof value == "function") && // overriding a method?
+ // the valueOf() comparison is to avoid circular references
+ (!ancestor.valueOf || ancestor.valueOf() != value.valueOf()) &&
+ /\bbase\b/.test(value)) {
+ // get the underlying method
+ var method = value.valueOf();
+ // override
+ value = function() {
+ var previous = this.base || Base.prototype.base;
+ this.base = ancestor;
+ var returnValue = method.apply(this, arguments);
+ this.base = previous;
+ return returnValue;
+ };
+ // point to the underlying method
+ value.valueOf = function(type) {
+ return (type == "object") ? value : method;
+ };
+ value.toString = Base.toString;
+ }
+ this[source] = value;
+ } else if (source) { // extending with an object literal
+ var extend = Base.prototype.extend;
+ // if this object has a customised extend method then use it
+ if (!Base._prototyping && typeof this != "function") {
+ extend = this.extend || extend;
+ }
+ var proto = {toSource: null};
+ // do the "toString" and other methods manually
+ var hidden = ["constructor", "toString", "valueOf"];
+ // if we are prototyping then include the constructor
+ var i = Base._prototyping ? 0 : 1;
+ while (key = hidden[i++]) {
+ if (source[key] != proto[key]) {
+ extend.call(this, key, source[key]);
- function parentElement(node) {
- var parent = node.parentNode;
- return (parent.nodeType == 1) ? parent : null;
- }
+ }
+ }
+ // copy each of the source object's properties to this object
+ for (var key in source) {
+ if (!proto[key]) extend.call(this, key, source[key]);
+ }
+ }
+ return this;
+ }
+};
- function getNodeIndex(node) {
- var i = 0;
- while( (node = node.previousSibling) ) {
- ++i;
- }
- return i;
- }
+// initialise
+Base = Base.extend({
+ constructor: function() {
+ this.extend(arguments[0]);
+ }
+}, {
+ ancestor: Object,
+ version: "1.1",
+
+ forEach: function(object, block, context) {
+ for (var key in object) {
+ if (this.prototype[key] === undefined) {
+ block.call(context, object[key], key, object);
+ }
+ }
+ },
+
+ implement: function() {
+ for (var i = 0; i < arguments.length; i++) {
+ if (typeof arguments[i] == "function") {
+ // if it's a function, call it
+ arguments[i](this.prototype);
+ } else {
+ // add the interface using the extend method
+ this.prototype.extend(arguments[i]);
+ }
+ }
+ return this;
+ },
+
+ toString: function() {
+ return String(this.valueOf());
+ }
+});
+/**
+ * Rangy, a cross-browser JavaScript range and selection library
+ * https://github.com/timdown/rangy
+ *
+ * Copyright 2015, Tim Down
+ * Licensed under the MIT license.
+ * Version: 1.3.1-dev
+ * Build date: 20 May 2015
+ *
+ * NOTE: UMD wrapper removed manually for bundling (Oliver Pulges)
+ */
+var rangy;
- function getNodeLength(node) {
- switch (node.nodeType) {
- case 7:
- case 10:
- return 0;
- case 3:
- case 8:
- return node.length;
- default:
- return node.childNodes.length;
- }
- }
+(function() {
+ var OBJECT = "object", FUNCTION = "function", UNDEFINED = "undefined";
- function getCommonAncestor(node1, node2) {
- var ancestors = [], n;
- for (n = node1; n; n = n.parentNode) {
- ancestors.push(n);
- }
+ // Minimal set of properties required for DOM Level 2 Range compliance. Comparison constants such as START_TO_START
+ // are omitted because ranges in KHTML do not have them but otherwise work perfectly well. See issue 113.
+ var domRangeProperties = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed",
+ "commonAncestorContainer"];
- for (n = node2; n; n = n.parentNode) {
- if (arrayContains(ancestors, n)) {
- return n;
- }
- }
+ // Minimal set of methods required for DOM Level 2 Range compliance
+ var domRangeMethods = ["setStart", "setStartBefore", "setStartAfter", "setEnd", "setEndBefore",
+ "setEndAfter", "collapse", "selectNode", "selectNodeContents", "compareBoundaryPoints", "deleteContents",
+ "extractContents", "cloneContents", "insertNode", "surroundContents", "cloneRange", "toString", "detach"];
- return null;
- }
+ var textRangeProperties = ["boundingHeight", "boundingLeft", "boundingTop", "boundingWidth", "htmlText", "text"];
- function isAncestorOf(ancestor, descendant, selfIsAncestor) {
- var n = selfIsAncestor ? descendant : descendant.parentNode;
- while (n) {
- if (n === ancestor) {
- return true;
- } else {
- n = n.parentNode;
+ // Subset of TextRange's full set of methods that we're interested in
+ var textRangeMethods = ["collapse", "compareEndPoints", "duplicate", "moveToElementText", "parentElement", "select",
+ "setEndPoint", "getBoundingClientRect"];
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Trio of functions taken from Peter Michaux's article:
+ // http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting
+ function isHostMethod(o, p) {
+ var t = typeof o[p];
+ return t == FUNCTION || (!!(t == OBJECT && o[p])) || t == "unknown";
+ }
+
+ function isHostObject(o, p) {
+ return !!(typeof o[p] == OBJECT && o[p]);
+ }
+
+ function isHostProperty(o, p) {
+ return typeof o[p] != UNDEFINED;
+ }
+
+ // Creates a convenience function to save verbose repeated calls to tests functions
+ function createMultiplePropertyTest(testFunc) {
+ return function(o, props) {
+ var i = props.length;
+ while (i--) {
+ if (!testFunc(o, props[i])) {
+ return false;
}
}
- return false;
- }
+ return true;
+ };
+ }
- function isOrIsAncestorOf(ancestor, descendant) {
- return isAncestorOf(ancestor, descendant, true);
- }
+ // Next trio of functions are a convenience to save verbose repeated calls to previous two functions
+ var areHostMethods = createMultiplePropertyTest(isHostMethod);
+ var areHostObjects = createMultiplePropertyTest(isHostObject);
+ var areHostProperties = createMultiplePropertyTest(isHostProperty);
- function getClosestAncestorIn(node, ancestor, selfIsAncestor) {
- var p, n = selfIsAncestor ? node : node.parentNode;
- while (n) {
- p = n.parentNode;
- if (p === ancestor) {
- return n;
- }
- n = p;
+ function isTextRange(range) {
+ return range && areHostMethods(range, textRangeMethods) && areHostProperties(range, textRangeProperties);
+ }
+
+ function getBody(doc) {
+ return isHostObject(doc, "body") ? doc.body : doc.getElementsByTagName("body")[0];
+ }
+
+ var forEach = [].forEach ?
+ function(arr, func) {
+ arr.forEach(func);
+ } :
+ function(arr, func) {
+ for (var i = 0, len = arr.length; i < len; ++i) {
+ func(arr[i], i);
}
- return null;
- }
+ };
- function isCharacterDataNode(node) {
- var t = node.nodeType;
- return t == 3 || t == 4 || t == 8 ; // Text, CDataSection or Comment
+ var modules = {};
+
+ var isBrowser = (typeof window != UNDEFINED && typeof document != UNDEFINED);
+
+ var util = {
+ isHostMethod: isHostMethod,
+ isHostObject: isHostObject,
+ isHostProperty: isHostProperty,
+ areHostMethods: areHostMethods,
+ areHostObjects: areHostObjects,
+ areHostProperties: areHostProperties,
+ isTextRange: isTextRange,
+ getBody: getBody,
+ forEach: forEach
+ };
+
+ var api = {
+ version: "1.3.1-dev",
+ initialized: false,
+ isBrowser: isBrowser,
+ supported: true,
+ util: util,
+ features: {},
+ modules: modules,
+ config: {
+ alertOnFail: false,
+ alertOnWarn: false,
+ preferTextRange: false,
+ autoInitialize: (typeof rangyAutoInitialize == UNDEFINED) ? true : rangyAutoInitialize
}
+ };
- function isTextOrCommentNode(node) {
- if (!node) {
- return false;
- }
- var t = node.nodeType;
- return t == 3 || t == 8 ; // Text or Comment
+ function consoleLog(msg) {
+ if (typeof console != UNDEFINED && isHostMethod(console, "log")) {
+ console.log(msg);
}
+ }
- function insertAfter(node, precedingNode) {
- var nextNode = precedingNode.nextSibling, parent = precedingNode.parentNode;
- if (nextNode) {
- parent.insertBefore(node, nextNode);
- } else {
- parent.appendChild(node);
- }
- return node;
+ function alertOrLog(msg, shouldAlert) {
+ if (isBrowser && shouldAlert) {
+ alert(msg);
+ } else {
+ consoleLog(msg);
}
+ }
- // Note that we cannot use splitText() because it is bugridden in IE 9.
- function splitDataNode(node, index, positionsToPreserve) {
- var newNode = node.cloneNode(false);
- newNode.deleteData(0, index);
- node.deleteData(index, node.length - index);
- insertAfter(newNode, node);
+ function fail(reason) {
+ api.initialized = true;
+ api.supported = false;
+ alertOrLog("Rangy is not supported in this environment. Reason: " + reason, api.config.alertOnFail);
+ }
- // Preserve positions
- if (positionsToPreserve) {
- for (var i = 0, position; position = positionsToPreserve[i++]; ) {
- // Handle case where position was inside the portion of node after the split point
- if (position.node == node && position.offset > index) {
- position.node = newNode;
- position.offset -= index;
- }
- // Handle the case where the position is a node offset within node's parent
- else if (position.node == node.parentNode && position.offset > getNodeIndex(node)) {
- ++position.offset;
+ api.fail = fail;
+
+ function warn(msg) {
+ alertOrLog("Rangy warning: " + msg, api.config.alertOnWarn);
+ }
+
+ api.warn = warn;
+
+ // Add utility extend() method
+ var extend;
+ if ({}.hasOwnProperty) {
+ util.extend = extend = function(obj, props, deep) {
+ var o, p;
+ for (var i in props) {
+ if (props.hasOwnProperty(i)) {
+ o = obj[i];
+ p = props[i];
+ if (deep && o !== null && typeof o == "object" && p !== null && typeof p == "object") {
+ extend(o, p, true);
}
+ obj[i] = p;
}
}
- return newNode;
- }
-
- function getDocument(node) {
- if (node.nodeType == 9) {
- return node;
- } else if (typeof node.ownerDocument != UNDEF) {
- return node.ownerDocument;
- } else if (typeof node.document != UNDEF) {
- return node.document;
- } else if (node.parentNode) {
- return getDocument(node.parentNode);
- } else {
- throw module.createError("getDocument: no document found for node");
+ // Special case for toString, which does not show up in for...in loops in IE <= 8
+ if (props.hasOwnProperty("toString")) {
+ obj.toString = props.toString;
}
- }
+ return obj;
+ };
- function getWindow(node) {
- var doc = getDocument(node);
- if (typeof doc.defaultView != UNDEF) {
- return doc.defaultView;
- } else if (typeof doc.parentWindow != UNDEF) {
- return doc.parentWindow;
- } else {
- throw module.createError("Cannot get a window object for node");
+ util.createOptions = function(optionsParam, defaults) {
+ var options = {};
+ extend(options, defaults);
+ if (optionsParam) {
+ extend(options, optionsParam);
}
+ return options;
+ };
+ } else {
+ fail("hasOwnProperty not supported");
+ }
+
+ // Test whether we're in a browser and bail out if not
+ if (!isBrowser) {
+ fail("Rangy can only run in a browser");
+ }
+
+ // Test whether Array.prototype.slice can be relied on for NodeLists and use an alternative toArray() if not
+ (function() {
+ var toArray;
+
+ if (isBrowser) {
+ var el = document.createElement("div");
+ el.appendChild(document.createElement("span"));
+ var slice = [].slice;
+ try {
+ if (slice.call(el.childNodes, 0)[0].nodeType == 1) {
+ toArray = function(arrayLike) {
+ return slice.call(arrayLike, 0);
+ };
+ }
+ } catch (e) {}
}
- function getIframeDocument(iframeEl) {
- if (typeof iframeEl.contentDocument != UNDEF) {
- return iframeEl.contentDocument;
- } else if (typeof iframeEl.contentWindow != UNDEF) {
- return iframeEl.contentWindow.document;
- } else {
- throw module.createError("getIframeDocument: No Document object found for iframe element");
- }
+ if (!toArray) {
+ toArray = function(arrayLike) {
+ var arr = [];
+ for (var i = 0, len = arrayLike.length; i < len; ++i) {
+ arr[i] = arrayLike[i];
+ }
+ return arr;
+ };
}
- function getIframeWindow(iframeEl) {
- if (typeof iframeEl.contentWindow != UNDEF) {
- return iframeEl.contentWindow;
- } else if (typeof iframeEl.contentDocument != UNDEF) {
- return iframeEl.contentDocument.defaultView;
- } else {
- throw module.createError("getIframeWindow: No Window object found for iframe element");
- }
+ util.toArray = toArray;
+ })();
+
+ // Very simple event handler wrapper function that doesn't attempt to solve issues such as "this" handling or
+ // normalization of event properties
+ var addListener;
+ if (isBrowser) {
+ if (isHostMethod(document, "addEventListener")) {
+ addListener = function(obj, eventType, listener) {
+ obj.addEventListener(eventType, listener, false);
+ };
+ } else if (isHostMethod(document, "attachEvent")) {
+ addListener = function(obj, eventType, listener) {
+ obj.attachEvent("on" + eventType, listener);
+ };
+ } else {
+ fail("Document does not have required addEventListener or attachEvent method");
}
- // This looks bad. Is it worth it?
- function isWindow(obj) {
- return obj && util.isHostMethod(obj, "setTimeout") && util.isHostObject(obj, "document");
+ util.addListener = addListener;
+ }
+
+ var initListeners = [];
+
+ function getErrorDesc(ex) {
+ return ex.message || ex.description || String(ex);
+ }
+
+ // Initialization
+ function init() {
+ if (!isBrowser || api.initialized) {
+ return;
}
+ var testRange;
+ var implementsDomRange = false, implementsTextRange = false;
- function getContentDocument(obj, module, methodName) {
- var doc;
+ // First, perform basic feature tests
- if (!obj) {
- doc = document;
+ if (isHostMethod(document, "createRange")) {
+ testRange = document.createRange();
+ if (areHostMethods(testRange, domRangeMethods) && areHostProperties(testRange, domRangeProperties)) {
+ implementsDomRange = true;
}
+ }
- // Test if a DOM node has been passed and obtain a document object for it if so
- else if (util.isHostProperty(obj, "nodeType")) {
- doc = (obj.nodeType == 1 && obj.tagName.toLowerCase() == "iframe") ?
- getIframeDocument(obj) : getDocument(obj);
- }
+ var body = getBody(document);
+ if (!body || body.nodeName.toLowerCase() != "body") {
+ fail("No body element found");
+ return;
+ }
- // Test if the doc parameter appears to be a Window object
- else if (isWindow(obj)) {
- doc = obj.document;
+ if (body && isHostMethod(body, "createTextRange")) {
+ testRange = body.createTextRange();
+ if (isTextRange(testRange)) {
+ implementsTextRange = true;
}
+ }
- if (!doc) {
- throw module.createError(methodName + "(): Parameter must be a Window object or DOM node");
- }
+ if (!implementsDomRange && !implementsTextRange) {
+ fail("Neither Range nor TextRange are available");
+ return;
+ }
- return doc;
+ api.initialized = true;
+ api.features = {
+ implementsDomRange: implementsDomRange,
+ implementsTextRange: implementsTextRange
+ };
+
+ // Initialize modules
+ var module, errorMessage;
+ for (var moduleName in modules) {
+ if ( (module = modules[moduleName]) instanceof Module ) {
+ module.init(module, api);
+ }
}
- function getRootContainer(node) {
- var parent;
- while ( (parent = node.parentNode) ) {
- node = parent;
+ // Call init listeners
+ for (var i = 0, len = initListeners.length; i < len; ++i) {
+ try {
+ initListeners[i](api);
+ } catch (ex) {
+ errorMessage = "Rangy init listener threw an exception. Continuing. Detail: " + getErrorDesc(ex);
+ consoleLog(errorMessage);
}
- return node;
}
+ }
- function comparePoints(nodeA, offsetA, nodeB, offsetB) {
- // See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-Comparing
- var nodeC, root, childA, childB, n;
- if (nodeA == nodeB) {
- // Case 1: nodes are the same
- return offsetA === offsetB ? 0 : (offsetA < offsetB) ? -1 : 1;
- } else if ( (nodeC = getClosestAncestorIn(nodeB, nodeA, true)) ) {
- // Case 2: node C (container B or an ancestor) is a child node of A
- return offsetA <= getNodeIndex(nodeC) ? -1 : 1;
- } else if ( (nodeC = getClosestAncestorIn(nodeA, nodeB, true)) ) {
- // Case 3: node C (container A or an ancestor) is a child node of B
- return getNodeIndex(nodeC) < offsetB ? -1 : 1;
- } else {
- root = getCommonAncestor(nodeA, nodeB);
- if (!root) {
- throw new Error("comparePoints error: nodes have no common ancestor");
- }
+ function deprecationNotice(deprecated, replacement, module) {
+ if (module) {
+ deprecated += " in module " + module.name;
+ }
+ api.warn("DEPRECATED: " + deprecated + " is deprecated. Please use " +
+ replacement + " instead.");
+ }
- // Case 4: containers are siblings or descendants of siblings
- childA = (nodeA === root) ? root : getClosestAncestorIn(nodeA, root, true);
- childB = (nodeB === root) ? root : getClosestAncestorIn(nodeB, root, true);
+ function createAliasForDeprecatedMethod(owner, deprecated, replacement, module) {
+ owner[deprecated] = function() {
+ deprecationNotice(deprecated, replacement, module);
+ return owner[replacement].apply(owner, util.toArray(arguments));
+ };
+ }
- if (childA === childB) {
- // This shouldn't be possible
- throw module.createError("comparePoints got to case 4 and childA and childB are the same!");
- } else {
- n = root.firstChild;
- while (n) {
- if (n === childA) {
- return -1;
- } else if (n === childB) {
- return 1;
- }
- n = n.nextSibling;
- }
- }
- }
+ util.deprecationNotice = deprecationNotice;
+ util.createAliasForDeprecatedMethod = createAliasForDeprecatedMethod;
+
+ // Allow external scripts to initialize this library in case it's loaded after the document has loaded
+ api.init = init;
+
+ // Execute listener immediately if already initialized
+ api.addInitListener = function(listener) {
+ if (api.initialized) {
+ listener(api);
+ } else {
+ initListeners.push(listener);
}
+ };
- /*----------------------------------------------------------------------------------------------------------------*/
+ var shimListeners = [];
- // Test for IE's crash (IE 6/7) or exception (IE >= 8) when a reference to garbage-collected text node is queried
- var crashyTextNodes = false;
+ api.addShimListener = function(listener) {
+ shimListeners.push(listener);
+ };
- function isBrokenNode(node) {
- var n;
- try {
- n = node.parentNode;
- return false;
- } catch (e) {
- return true;
- }
+ function shim(win) {
+ win = win || window;
+ init();
+
+ // Notify listeners
+ for (var i = 0, len = shimListeners.length; i < len; ++i) {
+ shimListeners[i](win);
}
+ }
- (function() {
- var el = document.createElement("b");
- el.innerHTML = "1";
- var textNode = el.firstChild;
- el.innerHTML = " ";
- crashyTextNodes = isBrokenNode(textNode);
+ if (isBrowser) {
+ api.shim = api.createMissingNativeApi = shim;
+ createAliasForDeprecatedMethod(api, "createMissingNativeApi", "shim");
+ }
- api.features.crashyTextNodes = crashyTextNodes;
- })();
+ function Module(name, dependencies, initializer) {
+ this.name = name;
+ this.dependencies = dependencies;
+ this.initialized = false;
+ this.supported = false;
+ this.initializer = initializer;
+ }
- /*----------------------------------------------------------------------------------------------------------------*/
+ Module.prototype = {
+ init: function() {
+ var requiredModuleNames = this.dependencies || [];
+ for (var i = 0, len = requiredModuleNames.length, requiredModule, moduleName; i < len; ++i) {
+ moduleName = requiredModuleNames[i];
- function inspectNode(node) {
- if (!node) {
- return "[No node]";
- }
- if (crashyTextNodes && isBrokenNode(node)) {
- return "[Broken node]";
- }
- if (isCharacterDataNode(node)) {
- return '"' + node.data + '"';
- }
- if (node.nodeType == 1) {
- var idAttr = node.id ? ' id="' + node.id + '"' : "";
- return "<" + node.nodeName + idAttr + ">[index:" + getNodeIndex(node) + ",length:" + node.childNodes.length + "][" + (node.innerHTML || "[innerHTML not supported]").slice(0, 25) + "]";
+ requiredModule = modules[moduleName];
+ if (!requiredModule || !(requiredModule instanceof Module)) {
+ throw new Error("required module '" + moduleName + "' not found");
+ }
+
+ requiredModule.init();
+
+ if (!requiredModule.supported) {
+ throw new Error("required module '" + moduleName + "' not supported");
+ }
}
- return node.nodeName;
+
+ // Now run initializer
+ this.initializer(this);
+ },
+
+ fail: function(reason) {
+ this.initialized = true;
+ this.supported = false;
+ throw new Error(reason);
+ },
+
+ warn: function(msg) {
+ api.warn("Module " + this.name + ": " + msg);
+ },
+
+ deprecationNotice: function(deprecated, replacement) {
+ api.warn("DEPRECATED: " + deprecated + " in module " + this.name + " is deprecated. Please use " +
+ replacement + " instead");
+ },
+
+ createError: function(msg) {
+ return new Error("Error in Rangy " + this.name + " module: " + msg);
}
+ };
- function fragmentFromNodeChildren(node) {
- var fragment = getDocument(node).createDocumentFragment(), child;
- while ( (child = node.firstChild) ) {
- fragment.appendChild(child);
+ function createModule(name, dependencies, initFunc) {
+ var newModule = new Module(name, dependencies, function(module) {
+ if (!module.initialized) {
+ module.initialized = true;
+ try {
+ initFunc(api, module);
+ module.supported = true;
+ } catch (ex) {
+ var errorMessage = "Module '" + name + "' failed to load: " + getErrorDesc(ex);
+ consoleLog(errorMessage);
+ if (ex.stack) {
+ consoleLog(ex.stack);
+ }
+ }
}
- return fragment;
- }
+ });
+ modules[name] = newModule;
+ return newModule;
+ }
- var getComputedStyleProperty;
- if (typeof window.getComputedStyle != UNDEF) {
- getComputedStyleProperty = function(el, propName) {
- return getWindow(el).getComputedStyle(el, null)[propName];
- };
- } else if (typeof document.documentElement.currentStyle != UNDEF) {
- getComputedStyleProperty = function(el, propName) {
- return el.currentStyle ? el.currentStyle[propName] : "";
- };
+ api.createModule = function(name) {
+ // Allow 2 or 3 arguments (second argument is an optional array of dependencies)
+ var initFunc, dependencies;
+ if (arguments.length == 2) {
+ initFunc = arguments[1];
+ dependencies = [];
} else {
- module.fail("No means of obtaining computed style properties found");
+ initFunc = arguments[2];
+ dependencies = arguments[1];
}
- function createTestElement(doc, html, contentEditable) {
- var body = getBody(doc);
- var el = doc.createElement("div");
- el.contentEditable = "" + !!contentEditable;
- if (html) {
- el.innerHTML = html;
- }
+ var module = createModule(name, dependencies, initFunc);
- // Insert the test element at the start of the body to prevent scrolling to the bottom in iOS (issue #292)
- var bodyFirstChild = body.firstChild;
- if (bodyFirstChild) {
- body.insertBefore(el, bodyFirstChild);
- } else {
- body.appendChild(el);
- }
+ // Initialize the module immediately if the core is already initialized
+ if (api.initialized && api.supported) {
+ module.init();
+ }
+ };
- return el;
+ api.createCoreModule = function(name, dependencies, initFunc) {
+ createModule(name, dependencies, initFunc);
+ };
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Ensure rangy.rangePrototype and rangy.selectionPrototype are available immediately
+
+ function RangePrototype() {}
+ api.RangePrototype = RangePrototype;
+ api.rangePrototype = new RangePrototype();
+
+ function SelectionPrototype() {}
+ api.selectionPrototype = new SelectionPrototype();
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // DOM utility methods used by Rangy
+ api.createCoreModule("DomUtil", [], function(api, module) {
+ var UNDEF = "undefined";
+ var util = api.util;
+ var getBody = util.getBody;
+
+ // Perform feature tests
+ if (!util.areHostMethods(document, ["createDocumentFragment", "createElement", "createTextNode"])) {
+ module.fail("document missing a Node creation method");
}
- function removeNode(node) {
- return node.parentNode.removeChild(node);
+ if (!util.isHostMethod(document, "getElementsByTagName")) {
+ module.fail("document missing getElementsByTagName method");
}
- function NodeIterator(root) {
- this.root = root;
- this._next = root;
+ var el = document.createElement("div");
+ if (!util.areHostMethods(el, ["insertBefore", "appendChild", "cloneNode"] ||
+ !util.areHostObjects(el, ["previousSibling", "nextSibling", "childNodes", "parentNode"]))) {
+ module.fail("Incomplete Element implementation");
}
- NodeIterator.prototype = {
- _current: null,
+ // innerHTML is required for Range's createContextualFragment method
+ if (!util.isHostProperty(el, "innerHTML")) {
+ module.fail("Element is missing innerHTML property");
+ }
- hasNext: function() {
- return !!this._next;
- },
+ var textNode = document.createTextNode("test");
+ if (!util.areHostMethods(textNode, ["splitText", "deleteData", "insertData", "appendData", "cloneNode"] ||
+ !util.areHostObjects(el, ["previousSibling", "nextSibling", "childNodes", "parentNode"]) ||
+ !util.areHostProperties(textNode, ["data"]))) {
+ module.fail("Incomplete Text Node implementation");
+ }
- next: function() {
- var n = this._current = this._next;
- var child, next;
- if (this._current) {
- child = n.firstChild;
- if (child) {
- this._next = child;
- } else {
- next = null;
- while ((n !== this.root) && !(next = n.nextSibling)) {
- n = n.parentNode;
- }
- this._next = next;
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Removed use of indexOf because of a bizarre bug in Opera that is thrown in one of the Acid3 tests. I haven't been
+ // able to replicate it outside of the test. The bug is that indexOf returns -1 when called on an Array that
+ // contains just the document as a single element and the value searched for is the document.
+ var arrayContains = /*Array.prototype.indexOf ?
+ function(arr, val) {
+ return arr.indexOf(val) > -1;
+ }:*/
+
+ function(arr, val) {
+ var i = arr.length;
+ while (i--) {
+ if (arr[i] === val) {
+ return true;
}
}
- return this._current;
- },
-
- detach: function() {
- this._current = this._next = this.root = null;
- }
- };
+ return false;
+ };
- function createIterator(root) {
- return new NodeIterator(root);
+ // Opera 11 puts HTML elements in the null namespace, it seems, and IE 7 has undefined namespaceURI
+ function isHtmlNamespace(node) {
+ var ns;
+ return typeof node.namespaceURI == UNDEF || ((ns = node.namespaceURI) === null || ns == "http://www.w3.org/1999/xhtml");
}
- function DomPosition(node, offset) {
- this.node = node;
- this.offset = offset;
+ function parentElement(node) {
+ var parent = node.parentNode;
+ return (parent.nodeType == 1) ? parent : null;
}
- DomPosition.prototype = {
- equals: function(pos) {
- return !!pos && this.node === pos.node && this.offset == pos.offset;
- },
-
- inspect: function() {
- return "[DomPosition(" + inspectNode(this.node) + ":" + this.offset + ")]";
- },
-
- toString: function() {
- return this.inspect();
+ function getNodeIndex(node) {
+ var i = 0;
+ while( (node = node.previousSibling) ) {
+ ++i;
}
- };
-
- function DOMException(codeName) {
- this.code = this[codeName];
- this.codeName = codeName;
- this.message = "DOMException: " + this.codeName;
+ return i;
}
- DOMException.prototype = {
- INDEX_SIZE_ERR: 1,
- HIERARCHY_REQUEST_ERR: 3,
- WRONG_DOCUMENT_ERR: 4,
- NO_MODIFICATION_ALLOWED_ERR: 7,
- NOT_FOUND_ERR: 8,
- NOT_SUPPORTED_ERR: 9,
- INVALID_STATE_ERR: 11,
- INVALID_NODE_TYPE_ERR: 24
- };
-
- DOMException.prototype.toString = function() {
- return this.message;
- };
-
- api.dom = {
- arrayContains: arrayContains,
- isHtmlNamespace: isHtmlNamespace,
- parentElement: parentElement,
- getNodeIndex: getNodeIndex,
- getNodeLength: getNodeLength,
- getCommonAncestor: getCommonAncestor,
- isAncestorOf: isAncestorOf,
- isOrIsAncestorOf: isOrIsAncestorOf,
- getClosestAncestorIn: getClosestAncestorIn,
- isCharacterDataNode: isCharacterDataNode,
- isTextOrCommentNode: isTextOrCommentNode,
- insertAfter: insertAfter,
- splitDataNode: splitDataNode,
- getDocument: getDocument,
- getWindow: getWindow,
- getIframeWindow: getIframeWindow,
- getIframeDocument: getIframeDocument,
- getBody: getBody,
- isWindow: isWindow,
- getContentDocument: getContentDocument,
- getRootContainer: getRootContainer,
- comparePoints: comparePoints,
- isBrokenNode: isBrokenNode,
- inspectNode: inspectNode,
- getComputedStyleProperty: getComputedStyleProperty,
- createTestElement: createTestElement,
- removeNode: removeNode,
- fragmentFromNodeChildren: fragmentFromNodeChildren,
- createIterator: createIterator,
- DomPosition: DomPosition
- };
-
- api.DOMException = DOMException;
- });
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Pure JavaScript implementation of DOM Range
- api.createCoreModule("DomRange", ["DomUtil"], function(api, module) {
- var dom = api.dom;
- var util = api.util;
- var DomPosition = dom.DomPosition;
- var DOMException = api.DOMException;
-
- var isCharacterDataNode = dom.isCharacterDataNode;
- var getNodeIndex = dom.getNodeIndex;
- var isOrIsAncestorOf = dom.isOrIsAncestorOf;
- var getDocument = dom.getDocument;
- var comparePoints = dom.comparePoints;
- var splitDataNode = dom.splitDataNode;
- var getClosestAncestorIn = dom.getClosestAncestorIn;
- var getNodeLength = dom.getNodeLength;
- var arrayContains = dom.arrayContains;
- var getRootContainer = dom.getRootContainer;
- var crashyTextNodes = api.features.crashyTextNodes;
+ function getNodeLength(node) {
+ switch (node.nodeType) {
+ case 7:
+ case 10:
+ return 0;
+ case 3:
+ case 8:
+ return node.length;
+ default:
+ return node.childNodes.length;
+ }
+ }
- var removeNode = dom.removeNode;
+ function getCommonAncestor(node1, node2) {
+ var ancestors = [], n;
+ for (n = node1; n; n = n.parentNode) {
+ ancestors.push(n);
+ }
- /*----------------------------------------------------------------------------------------------------------------*/
+ for (n = node2; n; n = n.parentNode) {
+ if (arrayContains(ancestors, n)) {
+ return n;
+ }
+ }
- // Utility functions
+ return null;
+ }
- function isNonTextPartiallySelected(node, range) {
- return (node.nodeType != 3) &&
- (isOrIsAncestorOf(node, range.startContainer) || isOrIsAncestorOf(node, range.endContainer));
+ function isAncestorOf(ancestor, descendant, selfIsAncestor) {
+ var n = selfIsAncestor ? descendant : descendant.parentNode;
+ while (n) {
+ if (n === ancestor) {
+ return true;
+ } else {
+ n = n.parentNode;
+ }
+ }
+ return false;
}
- function getRangeDocument(range) {
- return range.document || getDocument(range.startContainer);
+ function isOrIsAncestorOf(ancestor, descendant) {
+ return isAncestorOf(ancestor, descendant, true);
}
- function getRangeRoot(range) {
- return getRootContainer(range.startContainer);
+ function getClosestAncestorIn(node, ancestor, selfIsAncestor) {
+ var p, n = selfIsAncestor ? node : node.parentNode;
+ while (n) {
+ p = n.parentNode;
+ if (p === ancestor) {
+ return n;
+ }
+ n = p;
+ }
+ return null;
}
- function getBoundaryBeforeNode(node) {
- return new DomPosition(node.parentNode, getNodeIndex(node));
+ function isCharacterDataNode(node) {
+ var t = node.nodeType;
+ return t == 3 || t == 4 || t == 8 ; // Text, CDataSection or Comment
}
- function getBoundaryAfterNode(node) {
- return new DomPosition(node.parentNode, getNodeIndex(node) + 1);
+ function isTextOrCommentNode(node) {
+ if (!node) {
+ return false;
+ }
+ var t = node.nodeType;
+ return t == 3 || t == 8 ; // Text or Comment
}
- function insertNodeAtPosition(node, n, o) {
- var firstNodeInserted = node.nodeType == 11 ? node.firstChild : node;
- if (isCharacterDataNode(n)) {
- if (o == n.length) {
- dom.insertAfter(node, n);
- } else {
- n.parentNode.insertBefore(node, o == 0 ? n : splitDataNode(n, o));
- }
- } else if (o >= n.childNodes.length) {
- n.appendChild(node);
+ function insertAfter(node, precedingNode) {
+ var nextNode = precedingNode.nextSibling, parent = precedingNode.parentNode;
+ if (nextNode) {
+ parent.insertBefore(node, nextNode);
} else {
- n.insertBefore(node, n.childNodes[o]);
+ parent.appendChild(node);
}
- return firstNodeInserted;
+ return node;
}
- function rangesIntersect(rangeA, rangeB, touchingIsIntersecting) {
- assertRangeValid(rangeA);
- assertRangeValid(rangeB);
+ // Note that we cannot use splitText() because it is bugridden in IE 9.
+ function splitDataNode(node, index, positionsToPreserve) {
+ var newNode = node.cloneNode(false);
+ newNode.deleteData(0, index);
+ node.deleteData(index, node.length - index);
+ insertAfter(newNode, node);
- if (getRangeDocument(rangeB) != getRangeDocument(rangeA)) {
- throw new DOMException("WRONG_DOCUMENT_ERR");
+ // Preserve positions
+ if (positionsToPreserve) {
+ for (var i = 0, position; position = positionsToPreserve[i++]; ) {
+ // Handle case where position was inside the portion of node after the split point
+ if (position.node == node && position.offset > index) {
+ position.node = newNode;
+ position.offset -= index;
+ }
+ // Handle the case where the position is a node offset within node's parent
+ else if (position.node == node.parentNode && position.offset > getNodeIndex(node)) {
+ ++position.offset;
+ }
+ }
}
-
- var startComparison = comparePoints(rangeA.startContainer, rangeA.startOffset, rangeB.endContainer, rangeB.endOffset),
- endComparison = comparePoints(rangeA.endContainer, rangeA.endOffset, rangeB.startContainer, rangeB.startOffset);
-
- return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
+ return newNode;
}
- function cloneSubtree(iterator) {
- var partiallySelected;
- for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
- partiallySelected = iterator.isPartiallySelectedSubtree();
- node = node.cloneNode(!partiallySelected);
- if (partiallySelected) {
- subIterator = iterator.getSubtreeIterator();
- node.appendChild(cloneSubtree(subIterator));
- subIterator.detach();
- }
-
- if (node.nodeType == 10) { // DocumentType
- throw new DOMException("HIERARCHY_REQUEST_ERR");
- }
- frag.appendChild(node);
+ function getDocument(node) {
+ if (node.nodeType == 9) {
+ return node;
+ } else if (typeof node.ownerDocument != UNDEF) {
+ return node.ownerDocument;
+ } else if (typeof node.document != UNDEF) {
+ return node.document;
+ } else if (node.parentNode) {
+ return getDocument(node.parentNode);
+ } else {
+ throw module.createError("getDocument: no document found for node");
}
- return frag;
}
- function iterateSubtree(rangeIterator, func, iteratorState) {
- var it, n;
- iteratorState = iteratorState || { stop: false };
- for (var node, subRangeIterator; node = rangeIterator.next(); ) {
- if (rangeIterator.isPartiallySelectedSubtree()) {
- if (func(node) === false) {
- iteratorState.stop = true;
- return;
- } else {
- // The node is partially selected by the Range, so we can use a new RangeIterator on the portion of
- // the node selected by the Range.
- subRangeIterator = rangeIterator.getSubtreeIterator();
- iterateSubtree(subRangeIterator, func, iteratorState);
- subRangeIterator.detach();
- if (iteratorState.stop) {
- return;
- }
- }
- } else {
- // The whole node is selected, so we can use efficient DOM iteration to iterate over the node and its
- // descendants
- it = dom.createIterator(node);
- while ( (n = it.next()) ) {
- if (func(n) === false) {
- iteratorState.stop = true;
- return;
- }
- }
- }
+ function getWindow(node) {
+ var doc = getDocument(node);
+ if (typeof doc.defaultView != UNDEF) {
+ return doc.defaultView;
+ } else if (typeof doc.parentWindow != UNDEF) {
+ return doc.parentWindow;
+ } else {
+ throw module.createError("Cannot get a window object for node");
}
}
- function deleteSubtree(iterator) {
- var subIterator;
- while (iterator.next()) {
- if (iterator.isPartiallySelectedSubtree()) {
- subIterator = iterator.getSubtreeIterator();
- deleteSubtree(subIterator);
- subIterator.detach();
- } else {
- iterator.remove();
- }
+ function getIframeDocument(iframeEl) {
+ if (typeof iframeEl.contentDocument != UNDEF) {
+ return iframeEl.contentDocument;
+ } else if (typeof iframeEl.contentWindow != UNDEF) {
+ return iframeEl.contentWindow.document;
+ } else {
+ throw module.createError("getIframeDocument: No Document object found for iframe element");
}
}
- function extractSubtree(iterator) {
- for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
+ function getIframeWindow(iframeEl) {
+ if (typeof iframeEl.contentWindow != UNDEF) {
+ return iframeEl.contentWindow;
+ } else if (typeof iframeEl.contentDocument != UNDEF) {
+ return iframeEl.contentDocument.defaultView;
+ } else {
+ throw module.createError("getIframeWindow: No Window object found for iframe element");
+ }
+ }
- if (iterator.isPartiallySelectedSubtree()) {
- node = node.cloneNode(false);
- subIterator = iterator.getSubtreeIterator();
- node.appendChild(extractSubtree(subIterator));
- subIterator.detach();
- } else {
- iterator.remove();
- }
- if (node.nodeType == 10) { // DocumentType
- throw new DOMException("HIERARCHY_REQUEST_ERR");
- }
- frag.appendChild(node);
+ // This looks bad. Is it worth it?
+ function isWindow(obj) {
+ return obj && util.isHostMethod(obj, "setTimeout") && util.isHostObject(obj, "document");
+ }
+
+ function getContentDocument(obj, module, methodName) {
+ var doc;
+
+ if (!obj) {
+ doc = document;
}
- return frag;
+
+ // Test if a DOM node has been passed and obtain a document object for it if so
+ else if (util.isHostProperty(obj, "nodeType")) {
+ doc = (obj.nodeType == 1 && obj.tagName.toLowerCase() == "iframe") ?
+ getIframeDocument(obj) : getDocument(obj);
+ }
+
+ // Test if the doc parameter appears to be a Window object
+ else if (isWindow(obj)) {
+ doc = obj.document;
+ }
+
+ if (!doc) {
+ throw module.createError(methodName + "(): Parameter must be a Window object or DOM node");
+ }
+
+ return doc;
}
- function getNodesInRange(range, nodeTypes, filter) {
- var filterNodeTypes = !!(nodeTypes && nodeTypes.length), regex;
- var filterExists = !!filter;
- if (filterNodeTypes) {
- regex = new RegExp("^(" + nodeTypes.join("|") + ")$");
+ function getRootContainer(node) {
+ var parent;
+ while ( (parent = node.parentNode) ) {
+ node = parent;
}
+ return node;
+ }
- var nodes = [];
- iterateSubtree(new RangeIterator(range, false), function(node) {
- if (filterNodeTypes && !regex.test(node.nodeType)) {
- return;
- }
- if (filterExists && !filter(node)) {
- return;
- }
- // Don't include a boundary container if it is a character data node and the range does not contain any
- // of its character data. See issue 190.
- var sc = range.startContainer;
- if (node == sc && isCharacterDataNode(sc) && range.startOffset == sc.length) {
- return;
+ function comparePoints(nodeA, offsetA, nodeB, offsetB) {
+ // See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-Comparing
+ var nodeC, root, childA, childB, n;
+ if (nodeA == nodeB) {
+ // Case 1: nodes are the same
+ return offsetA === offsetB ? 0 : (offsetA < offsetB) ? -1 : 1;
+ } else if ( (nodeC = getClosestAncestorIn(nodeB, nodeA, true)) ) {
+ // Case 2: node C (container B or an ancestor) is a child node of A
+ return offsetA <= getNodeIndex(nodeC) ? -1 : 1;
+ } else if ( (nodeC = getClosestAncestorIn(nodeA, nodeB, true)) ) {
+ // Case 3: node C (container A or an ancestor) is a child node of B
+ return getNodeIndex(nodeC) < offsetB ? -1 : 1;
+ } else {
+ root = getCommonAncestor(nodeA, nodeB);
+ if (!root) {
+ throw new Error("comparePoints error: nodes have no common ancestor");
}
- var ec = range.endContainer;
- if (node == ec && isCharacterDataNode(ec) && range.endOffset == 0) {
- return;
- }
+ // Case 4: containers are siblings or descendants of siblings
+ childA = (nodeA === root) ? root : getClosestAncestorIn(nodeA, root, true);
+ childB = (nodeB === root) ? root : getClosestAncestorIn(nodeB, root, true);
- nodes.push(node);
- });
- return nodes;
+ if (childA === childB) {
+ // This shouldn't be possible
+ throw module.createError("comparePoints got to case 4 and childA and childB are the same!");
+ } else {
+ n = root.firstChild;
+ while (n) {
+ if (n === childA) {
+ return -1;
+ } else if (n === childB) {
+ return 1;
+ }
+ n = n.nextSibling;
+ }
+ }
+ }
}
- function inspect(range) {
- var name = (typeof range.getName == "undefined") ? "Range" : range.getName();
- return "[" + name + "(" + dom.inspectNode(range.startContainer) + ":" + range.startOffset + ", " +
- dom.inspectNode(range.endContainer) + ":" + range.endOffset + ")]";
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Test for IE's crash (IE 6/7) or exception (IE >= 8) when a reference to garbage-collected text node is queried
+ var crashyTextNodes = false;
+
+ function isBrokenNode(node) {
+ var n;
+ try {
+ n = node.parentNode;
+ return false;
+ } catch (e) {
+ return true;
+ }
}
+ (function() {
+ var el = document.createElement("b");
+ el.innerHTML = "1";
+ var textNode = el.firstChild;
+ el.innerHTML = " ";
+ crashyTextNodes = isBrokenNode(textNode);
+
+ api.features.crashyTextNodes = crashyTextNodes;
+ })();
+
/*----------------------------------------------------------------------------------------------------------------*/
- // RangeIterator code partially borrows from IERange by Tim Ryan (http://github.com/timcameronryan/IERange)
+ function inspectNode(node) {
+ if (!node) {
+ return "[No node]";
+ }
+ if (crashyTextNodes && isBrokenNode(node)) {
+ return "[Broken node]";
+ }
+ if (isCharacterDataNode(node)) {
+ return '"' + node.data + '"';
+ }
+ if (node.nodeType == 1) {
+ var idAttr = node.id ? ' id="' + node.id + '"' : "";
+ return "<" + node.nodeName + idAttr + ">[index:" + getNodeIndex(node) + ",length:" + node.childNodes.length + "][" + (node.innerHTML || "[innerHTML not supported]").slice(0, 25) + "]";
+ }
+ return node.nodeName;
+ }
- function RangeIterator(range, clonePartiallySelectedTextNodes) {
- this.range = range;
- this.clonePartiallySelectedTextNodes = clonePartiallySelectedTextNodes;
+ function fragmentFromNodeChildren(node) {
+ var fragment = getDocument(node).createDocumentFragment(), child;
+ while ( (child = node.firstChild) ) {
+ fragment.appendChild(child);
+ }
+ return fragment;
+ }
+ var getComputedStyleProperty;
+ if (typeof window.getComputedStyle != UNDEF) {
+ getComputedStyleProperty = function(el, propName) {
+ return getWindow(el).getComputedStyle(el, null)[propName];
+ };
+ } else if (typeof document.documentElement.currentStyle != UNDEF) {
+ getComputedStyleProperty = function(el, propName) {
+ return el.currentStyle ? el.currentStyle[propName] : "";
+ };
+ } else {
+ module.fail("No means of obtaining computed style properties found");
+ }
- if (!range.collapsed) {
- this.sc = range.startContainer;
- this.so = range.startOffset;
- this.ec = range.endContainer;
- this.eo = range.endOffset;
- var root = range.commonAncestorContainer;
+ function createTestElement(doc, html, contentEditable) {
+ var body = getBody(doc);
+ var el = doc.createElement("div");
+ el.contentEditable = "" + !!contentEditable;
+ if (html) {
+ el.innerHTML = html;
+ }
- if (this.sc === this.ec && isCharacterDataNode(this.sc)) {
- this.isSingleCharacterDataNode = true;
- this._first = this._last = this._next = this.sc;
- } else {
- this._first = this._next = (this.sc === root && !isCharacterDataNode(this.sc)) ?
- this.sc.childNodes[this.so] : getClosestAncestorIn(this.sc, root, true);
- this._last = (this.ec === root && !isCharacterDataNode(this.ec)) ?
- this.ec.childNodes[this.eo - 1] : getClosestAncestorIn(this.ec, root, true);
- }
+ // Insert the test element at the start of the body to prevent scrolling to the bottom in iOS (issue #292)
+ var bodyFirstChild = body.firstChild;
+ if (bodyFirstChild) {
+ body.insertBefore(el, bodyFirstChild);
+ } else {
+ body.appendChild(el);
}
+
+ return el;
}
- RangeIterator.prototype = {
- _current: null,
- _next: null,
- _first: null,
- _last: null,
- isSingleCharacterDataNode: false,
+ function removeNode(node) {
+ return node.parentNode.removeChild(node);
+ }
- reset: function() {
- this._current = null;
- this._next = this._first;
- },
+ function NodeIterator(root) {
+ this.root = root;
+ this._next = root;
+ }
+
+ NodeIterator.prototype = {
+ _current: null,
hasNext: function() {
return !!this._next;
},
next: function() {
- // Move to next node
- var current = this._current = this._next;
- if (current) {
- this._next = (current !== this._last) ? current.nextSibling : null;
-
- // Check for partially selected text nodes
- if (isCharacterDataNode(current) && this.clonePartiallySelectedTextNodes) {
- if (current === this.ec) {
- (current = current.cloneNode(true)).deleteData(this.eo, current.length - this.eo);
- }
- if (this._current === this.sc) {
- (current = current.cloneNode(true)).deleteData(0, this.so);
+ var n = this._current = this._next;
+ var child, next;
+ if (this._current) {
+ child = n.firstChild;
+ if (child) {
+ this._next = child;
+ } else {
+ next = null;
+ while ((n !== this.root) && !(next = n.nextSibling)) {
+ n = n.parentNode;
}
+ this._next = next;
}
}
+ return this._current;
+ },
- return current;
- },
+ detach: function() {
+ this._current = this._next = this.root = null;
+ }
+ };
- remove: function() {
- var current = this._current, start, end;
+ function createIterator(root) {
+ return new NodeIterator(root);
+ }
- if (isCharacterDataNode(current) && (current === this.sc || current === this.ec)) {
- start = (current === this.sc) ? this.so : 0;
- end = (current === this.ec) ? this.eo : current.length;
- if (start != end) {
- current.deleteData(start, end - start);
- }
- } else {
- if (current.parentNode) {
- removeNode(current);
- } else {
- }
- }
+ function DomPosition(node, offset) {
+ this.node = node;
+ this.offset = offset;
+ }
+
+ DomPosition.prototype = {
+ equals: function(pos) {
+ return !!pos && this.node === pos.node && this.offset == pos.offset;
},
- // Checks if the current node is partially selected
- isPartiallySelectedSubtree: function() {
- var current = this._current;
- return isNonTextPartiallySelected(current, this.range);
+ inspect: function() {
+ return "[DomPosition(" + inspectNode(this.node) + ":" + this.offset + ")]";
},
- getSubtreeIterator: function() {
- var subRange;
- if (this.isSingleCharacterDataNode) {
- subRange = this.range.cloneRange();
- subRange.collapse(false);
- } else {
- subRange = new Range(getRangeDocument(this.range));
- var current = this._current;
- var startContainer = current, startOffset = 0, endContainer = current, endOffset = getNodeLength(current);
+ toString: function() {
+ return this.inspect();
+ }
+ };
- if (isOrIsAncestorOf(current, this.sc)) {
- startContainer = this.sc;
- startOffset = this.so;
- }
- if (isOrIsAncestorOf(current, this.ec)) {
- endContainer = this.ec;
- endOffset = this.eo;
- }
+ function DOMException(codeName) {
+ this.code = this[codeName];
+ this.codeName = codeName;
+ this.message = "DOMException: " + this.codeName;
+ }
- updateBoundaries(subRange, startContainer, startOffset, endContainer, endOffset);
- }
- return new RangeIterator(subRange, this.clonePartiallySelectedTextNodes);
- },
+ DOMException.prototype = {
+ INDEX_SIZE_ERR: 1,
+ HIERARCHY_REQUEST_ERR: 3,
+ WRONG_DOCUMENT_ERR: 4,
+ NO_MODIFICATION_ALLOWED_ERR: 7,
+ NOT_FOUND_ERR: 8,
+ NOT_SUPPORTED_ERR: 9,
+ INVALID_STATE_ERR: 11,
+ INVALID_NODE_TYPE_ERR: 24
+ };
- detach: function() {
- this.range = this._current = this._next = this._first = this._last = this.sc = this.so = this.ec = this.eo = null;
- }
+ DOMException.prototype.toString = function() {
+ return this.message;
};
- /*----------------------------------------------------------------------------------------------------------------*/
+ api.dom = {
+ arrayContains: arrayContains,
+ isHtmlNamespace: isHtmlNamespace,
+ parentElement: parentElement,
+ getNodeIndex: getNodeIndex,
+ getNodeLength: getNodeLength,
+ getCommonAncestor: getCommonAncestor,
+ isAncestorOf: isAncestorOf,
+ isOrIsAncestorOf: isOrIsAncestorOf,
+ getClosestAncestorIn: getClosestAncestorIn,
+ isCharacterDataNode: isCharacterDataNode,
+ isTextOrCommentNode: isTextOrCommentNode,
+ insertAfter: insertAfter,
+ splitDataNode: splitDataNode,
+ getDocument: getDocument,
+ getWindow: getWindow,
+ getIframeWindow: getIframeWindow,
+ getIframeDocument: getIframeDocument,
+ getBody: getBody,
+ isWindow: isWindow,
+ getContentDocument: getContentDocument,
+ getRootContainer: getRootContainer,
+ comparePoints: comparePoints,
+ isBrokenNode: isBrokenNode,
+ inspectNode: inspectNode,
+ getComputedStyleProperty: getComputedStyleProperty,
+ createTestElement: createTestElement,
+ removeNode: removeNode,
+ fragmentFromNodeChildren: fragmentFromNodeChildren,
+ createIterator: createIterator,
+ DomPosition: DomPosition
+ };
- var beforeAfterNodeTypes = [1, 3, 4, 5, 7, 8, 10];
- var rootContainerNodeTypes = [2, 9, 11];
- var readonlyNodeTypes = [5, 6, 10, 12];
- var insertableNodeTypes = [1, 3, 4, 5, 7, 8, 10, 11];
- var surroundNodeTypes = [1, 3, 4, 5, 7, 8];
+ api.DOMException = DOMException;
+ });
- function createAncestorFinder(nodeTypes) {
- return function(node, selfIsAncestor) {
- var t, n = selfIsAncestor ? node : node.parentNode;
- while (n) {
- t = n.nodeType;
- if (arrayContains(nodeTypes, t)) {
- return n;
- }
- n = n.parentNode;
- }
- return null;
- };
- }
+ /*----------------------------------------------------------------------------------------------------------------*/
- var getDocumentOrFragmentContainer = createAncestorFinder( [9, 11] );
- var getReadonlyAncestor = createAncestorFinder(readonlyNodeTypes);
- var getDocTypeNotationEntityAncestor = createAncestorFinder( [6, 10, 12] );
+ // Pure JavaScript implementation of DOM Range
+ api.createCoreModule("DomRange", ["DomUtil"], function(api, module) {
+ var dom = api.dom;
+ var util = api.util;
+ var DomPosition = dom.DomPosition;
+ var DOMException = api.DOMException;
- function assertNoDocTypeNotationEntityAncestor(node, allowSelf) {
- if (getDocTypeNotationEntityAncestor(node, allowSelf)) {
- throw new DOMException("INVALID_NODE_TYPE_ERR");
- }
- }
+ var isCharacterDataNode = dom.isCharacterDataNode;
+ var getNodeIndex = dom.getNodeIndex;
+ var isOrIsAncestorOf = dom.isOrIsAncestorOf;
+ var getDocument = dom.getDocument;
+ var comparePoints = dom.comparePoints;
+ var splitDataNode = dom.splitDataNode;
+ var getClosestAncestorIn = dom.getClosestAncestorIn;
+ var getNodeLength = dom.getNodeLength;
+ var arrayContains = dom.arrayContains;
+ var getRootContainer = dom.getRootContainer;
+ var crashyTextNodes = api.features.crashyTextNodes;
- function assertValidNodeType(node, invalidTypes) {
- if (!arrayContains(invalidTypes, node.nodeType)) {
- throw new DOMException("INVALID_NODE_TYPE_ERR");
- }
- }
+ var removeNode = dom.removeNode;
- function assertValidOffset(node, offset) {
- if (offset < 0 || offset > (isCharacterDataNode(node) ? node.length : node.childNodes.length)) {
- throw new DOMException("INDEX_SIZE_ERR");
- }
- }
+ /*----------------------------------------------------------------------------------------------------------------*/
- function assertSameDocumentOrFragment(node1, node2) {
- if (getDocumentOrFragmentContainer(node1, true) !== getDocumentOrFragmentContainer(node2, true)) {
- throw new DOMException("WRONG_DOCUMENT_ERR");
- }
+ // Utility functions
+
+ function isNonTextPartiallySelected(node, range) {
+ return (node.nodeType != 3) &&
+ (isOrIsAncestorOf(node, range.startContainer) || isOrIsAncestorOf(node, range.endContainer));
}
- function assertNodeNotReadOnly(node) {
- if (getReadonlyAncestor(node, true)) {
- throw new DOMException("NO_MODIFICATION_ALLOWED_ERR");
- }
+ function getRangeDocument(range) {
+ return range.document || getDocument(range.startContainer);
}
- function assertNode(node, codeName) {
- if (!node) {
- throw new DOMException(codeName);
- }
+ function getRangeRoot(range) {
+ return getRootContainer(range.startContainer);
}
- function isValidOffset(node, offset) {
- return offset <= (isCharacterDataNode(node) ? node.length : node.childNodes.length);
+ function getBoundaryBeforeNode(node) {
+ return new DomPosition(node.parentNode, getNodeIndex(node));
}
- function isRangeValid(range) {
- return (!!range.startContainer && !!range.endContainer &&
- !(crashyTextNodes && (dom.isBrokenNode(range.startContainer) || dom.isBrokenNode(range.endContainer))) &&
- getRootContainer(range.startContainer) == getRootContainer(range.endContainer) &&
- isValidOffset(range.startContainer, range.startOffset) &&
- isValidOffset(range.endContainer, range.endOffset));
+ function getBoundaryAfterNode(node) {
+ return new DomPosition(node.parentNode, getNodeIndex(node) + 1);
}
- function assertRangeValid(range) {
- if (!isRangeValid(range)) {
- throw new Error("Range error: Range is not valid. This usually happens after DOM mutation. Range: (" + range.inspect() + ")");
+ function insertNodeAtPosition(node, n, o) {
+ var firstNodeInserted = node.nodeType == 11 ? node.firstChild : node;
+ if (isCharacterDataNode(n)) {
+ if (o == n.length) {
+ dom.insertAfter(node, n);
+ } else {
+ n.parentNode.insertBefore(node, o == 0 ? n : splitDataNode(n, o));
+ }
+ } else if (o >= n.childNodes.length) {
+ n.appendChild(node);
+ } else {
+ n.insertBefore(node, n.childNodes[o]);
}
+ return firstNodeInserted;
}
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Test the browser's innerHTML support to decide how to implement createContextualFragment
- var styleEl = document.createElement("style");
- var htmlParsingConforms = false;
- try {
- styleEl.innerHTML = "x ";
- htmlParsingConforms = (styleEl.firstChild.nodeType == 3); // Opera incorrectly creates an element node
- } catch (e) {
- // IE 6 and 7 throw
- }
+ function rangesIntersect(rangeA, rangeB, touchingIsIntersecting) {
+ assertRangeValid(rangeA);
+ assertRangeValid(rangeB);
- api.features.htmlParsingConforms = htmlParsingConforms;
+ if (getRangeDocument(rangeB) != getRangeDocument(rangeA)) {
+ throw new DOMException("WRONG_DOCUMENT_ERR");
+ }
- var createContextualFragment = htmlParsingConforms ?
+ var startComparison = comparePoints(rangeA.startContainer, rangeA.startOffset, rangeB.endContainer, rangeB.endOffset),
+ endComparison = comparePoints(rangeA.endContainer, rangeA.endOffset, rangeB.startContainer, rangeB.startOffset);
- // Implementation as per HTML parsing spec, trusting in the browser's implementation of innerHTML. See
- // discussion and base code for this implementation at issue 67.
- // Spec: http://html5.org/specs/dom-parsing.html#extensions-to-the-range-interface
- // Thanks to Aleks Williams.
- function(fragmentStr) {
- // "Let node the context object's start's node."
- var node = this.startContainer;
- var doc = getDocument(node);
+ return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
+ }
- // "If the context object's start's node is null, raise an INVALID_STATE_ERR
- // exception and abort these steps."
- if (!node) {
- throw new DOMException("INVALID_STATE_ERR");
+ function cloneSubtree(iterator) {
+ var partiallySelected;
+ for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
+ partiallySelected = iterator.isPartiallySelectedSubtree();
+ node = node.cloneNode(!partiallySelected);
+ if (partiallySelected) {
+ subIterator = iterator.getSubtreeIterator();
+ node.appendChild(cloneSubtree(subIterator));
+ subIterator.detach();
}
- // "Let element be as follows, depending on node's interface:"
- // Document, Document Fragment: null
- var el = null;
+ if (node.nodeType == 10) { // DocumentType
+ throw new DOMException("HIERARCHY_REQUEST_ERR");
+ }
+ frag.appendChild(node);
+ }
+ return frag;
+ }
- // "Element: node"
- if (node.nodeType == 1) {
- el = node;
+ function iterateSubtree(rangeIterator, func, iteratorState) {
+ var it, n;
+ iteratorState = iteratorState || { stop: false };
+ for (var node, subRangeIterator; node = rangeIterator.next(); ) {
+ if (rangeIterator.isPartiallySelectedSubtree()) {
+ if (func(node) === false) {
+ iteratorState.stop = true;
+ return;
+ } else {
+ // The node is partially selected by the Range, so we can use a new RangeIterator on the portion of
+ // the node selected by the Range.
+ subRangeIterator = rangeIterator.getSubtreeIterator();
+ iterateSubtree(subRangeIterator, func, iteratorState);
+ subRangeIterator.detach();
+ if (iteratorState.stop) {
+ return;
+ }
+ }
+ } else {
+ // The whole node is selected, so we can use efficient DOM iteration to iterate over the node and its
+ // descendants
+ it = dom.createIterator(node);
+ while ( (n = it.next()) ) {
+ if (func(n) === false) {
+ iteratorState.stop = true;
+ return;
+ }
+ }
+ }
+ }
+ }
- // "Text, Comment: node's parentElement"
- } else if (isCharacterDataNode(node)) {
- el = dom.parentElement(node);
+ function deleteSubtree(iterator) {
+ var subIterator;
+ while (iterator.next()) {
+ if (iterator.isPartiallySelectedSubtree()) {
+ subIterator = iterator.getSubtreeIterator();
+ deleteSubtree(subIterator);
+ subIterator.detach();
+ } else {
+ iterator.remove();
}
+ }
+ }
- // "If either element is null or element's ownerDocument is an HTML document
- // and element's local name is "html" and element's namespace is the HTML
- // namespace"
- if (el === null || (
- el.nodeName == "HTML" &&
- dom.isHtmlNamespace(getDocument(el).documentElement) &&
- dom.isHtmlNamespace(el)
- )) {
+ function extractSubtree(iterator) {
+ for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
- // "let element be a new Element with "body" as its local name and the HTML
- // namespace as its namespace.""
- el = doc.createElement("body");
+ if (iterator.isPartiallySelectedSubtree()) {
+ node = node.cloneNode(false);
+ subIterator = iterator.getSubtreeIterator();
+ node.appendChild(extractSubtree(subIterator));
+ subIterator.detach();
} else {
- el = el.cloneNode(false);
+ iterator.remove();
+ }
+ if (node.nodeType == 10) { // DocumentType
+ throw new DOMException("HIERARCHY_REQUEST_ERR");
}
+ frag.appendChild(node);
+ }
+ return frag;
+ }
- // "If the node's document is an HTML document: Invoke the HTML fragment parsing algorithm."
- // "If the node's document is an XML document: Invoke the XML fragment parsing algorithm."
- // "In either case, the algorithm must be invoked with fragment as the input
- // and element as the context element."
- el.innerHTML = fragmentStr;
+ function getNodesInRange(range, nodeTypes, filter) {
+ var filterNodeTypes = !!(nodeTypes && nodeTypes.length), regex;
+ var filterExists = !!filter;
+ if (filterNodeTypes) {
+ regex = new RegExp("^(" + nodeTypes.join("|") + ")$");
+ }
- // "If this raises an exception, then abort these steps. Otherwise, let new
- // children be the nodes returned."
+ var nodes = [];
+ iterateSubtree(new RangeIterator(range, false), function(node) {
+ if (filterNodeTypes && !regex.test(node.nodeType)) {
+ return;
+ }
+ if (filterExists && !filter(node)) {
+ return;
+ }
+ // Don't include a boundary container if it is a character data node and the range does not contain any
+ // of its character data. See issue 190.
+ var sc = range.startContainer;
+ if (node == sc && isCharacterDataNode(sc) && range.startOffset == sc.length) {
+ return;
+ }
- // "Let fragment be a new DocumentFragment."
- // "Append all new children to fragment."
- // "Return fragment."
- return dom.fragmentFromNodeChildren(el);
- } :
+ var ec = range.endContainer;
+ if (node == ec && isCharacterDataNode(ec) && range.endOffset == 0) {
+ return;
+ }
- // In this case, innerHTML cannot be trusted, so fall back to a simpler, non-conformant implementation that
- // previous versions of Rangy used (with the exception of using a body element rather than a div)
- function(fragmentStr) {
- var doc = getRangeDocument(this);
- var el = doc.createElement("body");
- el.innerHTML = fragmentStr;
+ nodes.push(node);
+ });
+ return nodes;
+ }
- return dom.fragmentFromNodeChildren(el);
- };
+ function inspect(range) {
+ var name = (typeof range.getName == "undefined") ? "Range" : range.getName();
+ return "[" + name + "(" + dom.inspectNode(range.startContainer) + ":" + range.startOffset + ", " +
+ dom.inspectNode(range.endContainer) + ":" + range.endOffset + ")]";
+ }
- function splitRangeBoundaries(range, positionsToPreserve) {
- assertRangeValid(range);
+ /*----------------------------------------------------------------------------------------------------------------*/
- var sc = range.startContainer, so = range.startOffset, ec = range.endContainer, eo = range.endOffset;
- var startEndSame = (sc === ec);
+ // RangeIterator code partially borrows from IERange by Tim Ryan (http://github.com/timcameronryan/IERange)
- if (isCharacterDataNode(ec) && eo > 0 && eo < ec.length) {
- splitDataNode(ec, eo, positionsToPreserve);
- }
+ function RangeIterator(range, clonePartiallySelectedTextNodes) {
+ this.range = range;
+ this.clonePartiallySelectedTextNodes = clonePartiallySelectedTextNodes;
- if (isCharacterDataNode(sc) && so > 0 && so < sc.length) {
- sc = splitDataNode(sc, so, positionsToPreserve);
- if (startEndSame) {
- eo -= so;
- ec = sc;
- } else if (ec == sc.parentNode && eo >= getNodeIndex(sc)) {
- eo++;
+
+ if (!range.collapsed) {
+ this.sc = range.startContainer;
+ this.so = range.startOffset;
+ this.ec = range.endContainer;
+ this.eo = range.endOffset;
+ var root = range.commonAncestorContainer;
+
+ if (this.sc === this.ec && isCharacterDataNode(this.sc)) {
+ this.isSingleCharacterDataNode = true;
+ this._first = this._last = this._next = this.sc;
+ } else {
+ this._first = this._next = (this.sc === root && !isCharacterDataNode(this.sc)) ?
+ this.sc.childNodes[this.so] : getClosestAncestorIn(this.sc, root, true);
+ this._last = (this.ec === root && !isCharacterDataNode(this.ec)) ?
+ this.ec.childNodes[this.eo - 1] : getClosestAncestorIn(this.ec, root, true);
}
- so = 0;
}
- range.setStartAndEnd(sc, so, ec, eo);
}
- function rangeToHtml(range) {
- assertRangeValid(range);
- var container = range.commonAncestorContainer.parentNode.cloneNode(false);
- container.appendChild( range.cloneContents() );
- return container.innerHTML;
- }
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- var rangeProperties = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed",
- "commonAncestorContainer"];
-
- var s2s = 0, s2e = 1, e2e = 2, e2s = 3;
- var n_b = 0, n_a = 1, n_b_a = 2, n_i = 3;
+ RangeIterator.prototype = {
+ _current: null,
+ _next: null,
+ _first: null,
+ _last: null,
+ isSingleCharacterDataNode: false,
- util.extend(api.rangePrototype, {
- compareBoundaryPoints: function(how, range) {
- assertRangeValid(this);
- assertSameDocumentOrFragment(this.startContainer, range.startContainer);
+ reset: function() {
+ this._current = null;
+ this._next = this._first;
+ },
- var nodeA, offsetA, nodeB, offsetB;
- var prefixA = (how == e2s || how == s2s) ? "start" : "end";
- var prefixB = (how == s2e || how == s2s) ? "start" : "end";
- nodeA = this[prefixA + "Container"];
- offsetA = this[prefixA + "Offset"];
- nodeB = range[prefixB + "Container"];
- offsetB = range[prefixB + "Offset"];
- return comparePoints(nodeA, offsetA, nodeB, offsetB);
+ hasNext: function() {
+ return !!this._next;
},
- insertNode: function(node) {
- assertRangeValid(this);
- assertValidNodeType(node, insertableNodeTypes);
- assertNodeNotReadOnly(this.startContainer);
+ next: function() {
+ // Move to next node
+ var current = this._current = this._next;
+ if (current) {
+ this._next = (current !== this._last) ? current.nextSibling : null;
- if (isOrIsAncestorOf(node, this.startContainer)) {
- throw new DOMException("HIERARCHY_REQUEST_ERR");
+ // Check for partially selected text nodes
+ if (isCharacterDataNode(current) && this.clonePartiallySelectedTextNodes) {
+ if (current === this.ec) {
+ (current = current.cloneNode(true)).deleteData(this.eo, current.length - this.eo);
+ }
+ if (this._current === this.sc) {
+ (current = current.cloneNode(true)).deleteData(0, this.so);
+ }
+ }
}
- // No check for whether the container of the start of the Range is of a type that does not allow
- // children of the type of node: the browser's DOM implementation should do this for us when we attempt
- // to add the node
-
- var firstNodeInserted = insertNodeAtPosition(node, this.startContainer, this.startOffset);
- this.setStartBefore(firstNodeInserted);
+ return current;
},
- cloneContents: function() {
- assertRangeValid(this);
+ remove: function() {
+ var current = this._current, start, end;
- var clone, frag;
- if (this.collapsed) {
- return getRangeDocument(this).createDocumentFragment();
+ if (isCharacterDataNode(current) && (current === this.sc || current === this.ec)) {
+ start = (current === this.sc) ? this.so : 0;
+ end = (current === this.ec) ? this.eo : current.length;
+ if (start != end) {
+ current.deleteData(start, end - start);
+ }
} else {
- if (this.startContainer === this.endContainer && isCharacterDataNode(this.startContainer)) {
- clone = this.startContainer.cloneNode(true);
- clone.data = clone.data.slice(this.startOffset, this.endOffset);
- frag = getRangeDocument(this).createDocumentFragment();
- frag.appendChild(clone);
- return frag;
+ if (current.parentNode) {
+ removeNode(current);
} else {
- var iterator = new RangeIterator(this, true);
- clone = cloneSubtree(iterator);
- iterator.detach();
}
- return clone;
}
},
- canSurroundContents: function() {
- assertRangeValid(this);
- assertNodeNotReadOnly(this.startContainer);
- assertNodeNotReadOnly(this.endContainer);
-
- // Check if the contents can be surrounded. Specifically, this means whether the range partially selects
- // no non-text nodes.
- var iterator = new RangeIterator(this, true);
- var boundariesInvalid = (iterator._first && (isNonTextPartiallySelected(iterator._first, this)) ||
- (iterator._last && isNonTextPartiallySelected(iterator._last, this)));
- iterator.detach();
- return !boundariesInvalid;
+ // Checks if the current node is partially selected
+ isPartiallySelectedSubtree: function() {
+ var current = this._current;
+ return isNonTextPartiallySelected(current, this.range);
},
- surroundContents: function(node) {
- assertValidNodeType(node, surroundNodeTypes);
+ getSubtreeIterator: function() {
+ var subRange;
+ if (this.isSingleCharacterDataNode) {
+ subRange = this.range.cloneRange();
+ subRange.collapse(false);
+ } else {
+ subRange = new Range(getRangeDocument(this.range));
+ var current = this._current;
+ var startContainer = current, startOffset = 0, endContainer = current, endOffset = getNodeLength(current);
- if (!this.canSurroundContents()) {
- throw new DOMException("INVALID_STATE_ERR");
+ if (isOrIsAncestorOf(current, this.sc)) {
+ startContainer = this.sc;
+ startOffset = this.so;
+ }
+ if (isOrIsAncestorOf(current, this.ec)) {
+ endContainer = this.ec;
+ endOffset = this.eo;
+ }
+
+ updateBoundaries(subRange, startContainer, startOffset, endContainer, endOffset);
}
+ return new RangeIterator(subRange, this.clonePartiallySelectedTextNodes);
+ },
- // Extract the contents
- var content = this.extractContents();
+ detach: function() {
+ this.range = this._current = this._next = this._first = this._last = this.sc = this.so = this.ec = this.eo = null;
+ }
+ };
- // Clear the children of the node
- if (node.hasChildNodes()) {
- while (node.lastChild) {
- node.removeChild(node.lastChild);
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ var beforeAfterNodeTypes = [1, 3, 4, 5, 7, 8, 10];
+ var rootContainerNodeTypes = [2, 9, 11];
+ var readonlyNodeTypes = [5, 6, 10, 12];
+ var insertableNodeTypes = [1, 3, 4, 5, 7, 8, 10, 11];
+ var surroundNodeTypes = [1, 3, 4, 5, 7, 8];
+
+ function createAncestorFinder(nodeTypes) {
+ return function(node, selfIsAncestor) {
+ var t, n = selfIsAncestor ? node : node.parentNode;
+ while (n) {
+ t = n.nodeType;
+ if (arrayContains(nodeTypes, t)) {
+ return n;
}
+ n = n.parentNode;
}
+ return null;
+ };
+ }
- // Insert the new node and add the extracted contents
- insertNodeAtPosition(node, this.startContainer, this.startOffset);
- node.appendChild(content);
+ var getDocumentOrFragmentContainer = createAncestorFinder( [9, 11] );
+ var getReadonlyAncestor = createAncestorFinder(readonlyNodeTypes);
+ var getDocTypeNotationEntityAncestor = createAncestorFinder( [6, 10, 12] );
- this.selectNode(node);
- },
+ function assertNoDocTypeNotationEntityAncestor(node, allowSelf) {
+ if (getDocTypeNotationEntityAncestor(node, allowSelf)) {
+ throw new DOMException("INVALID_NODE_TYPE_ERR");
+ }
+ }
- cloneRange: function() {
- assertRangeValid(this);
- var range = new Range(getRangeDocument(this));
- var i = rangeProperties.length, prop;
- while (i--) {
- prop = rangeProperties[i];
- range[prop] = this[prop];
- }
- return range;
- },
+ function assertValidNodeType(node, invalidTypes) {
+ if (!arrayContains(invalidTypes, node.nodeType)) {
+ throw new DOMException("INVALID_NODE_TYPE_ERR");
+ }
+ }
- toString: function() {
- assertRangeValid(this);
- var sc = this.startContainer;
- if (sc === this.endContainer && isCharacterDataNode(sc)) {
- return (sc.nodeType == 3 || sc.nodeType == 4) ? sc.data.slice(this.startOffset, this.endOffset) : "";
- } else {
- var textParts = [], iterator = new RangeIterator(this, true);
- iterateSubtree(iterator, function(node) {
- // Accept only text or CDATA nodes, not comments
- if (node.nodeType == 3 || node.nodeType == 4) {
- textParts.push(node.data);
- }
- });
- iterator.detach();
- return textParts.join("");
- }
- },
+ function assertValidOffset(node, offset) {
+ if (offset < 0 || offset > (isCharacterDataNode(node) ? node.length : node.childNodes.length)) {
+ throw new DOMException("INDEX_SIZE_ERR");
+ }
+ }
- // The methods below are all non-standard. The following batch were introduced by Mozilla but have since
- // been removed from Mozilla.
+ function assertSameDocumentOrFragment(node1, node2) {
+ if (getDocumentOrFragmentContainer(node1, true) !== getDocumentOrFragmentContainer(node2, true)) {
+ throw new DOMException("WRONG_DOCUMENT_ERR");
+ }
+ }
- compareNode: function(node) {
- assertRangeValid(this);
+ function assertNodeNotReadOnly(node) {
+ if (getReadonlyAncestor(node, true)) {
+ throw new DOMException("NO_MODIFICATION_ALLOWED_ERR");
+ }
+ }
- var parent = node.parentNode;
- var nodeIndex = getNodeIndex(node);
+ function assertNode(node, codeName) {
+ if (!node) {
+ throw new DOMException(codeName);
+ }
+ }
- if (!parent) {
- throw new DOMException("NOT_FOUND_ERR");
- }
+ function isValidOffset(node, offset) {
+ return offset <= (isCharacterDataNode(node) ? node.length : node.childNodes.length);
+ }
- var startComparison = this.comparePoint(parent, nodeIndex),
- endComparison = this.comparePoint(parent, nodeIndex + 1);
+ function isRangeValid(range) {
+ return (!!range.startContainer && !!range.endContainer &&
+ !(crashyTextNodes && (dom.isBrokenNode(range.startContainer) || dom.isBrokenNode(range.endContainer))) &&
+ getRootContainer(range.startContainer) == getRootContainer(range.endContainer) &&
+ isValidOffset(range.startContainer, range.startOffset) &&
+ isValidOffset(range.endContainer, range.endOffset));
+ }
- if (startComparison < 0) { // Node starts before
- return (endComparison > 0) ? n_b_a : n_b;
- } else {
- return (endComparison > 0) ? n_a : n_i;
- }
- },
+ function assertRangeValid(range) {
+ if (!isRangeValid(range)) {
+ throw new Error("Range error: Range is not valid. This usually happens after DOM mutation. Range: (" + range.inspect() + ")");
+ }
+ }
- comparePoint: function(node, offset) {
- assertRangeValid(this);
- assertNode(node, "HIERARCHY_REQUEST_ERR");
- assertSameDocumentOrFragment(node, this.startContainer);
+ /*----------------------------------------------------------------------------------------------------------------*/
- if (comparePoints(node, offset, this.startContainer, this.startOffset) < 0) {
- return -1;
- } else if (comparePoints(node, offset, this.endContainer, this.endOffset) > 0) {
- return 1;
- }
- return 0;
- },
+ // Test the browser's innerHTML support to decide how to implement createContextualFragment
+ var styleEl = document.createElement("style");
+ var htmlParsingConforms = false;
+ try {
+ styleEl.innerHTML = "x ";
+ htmlParsingConforms = (styleEl.firstChild.nodeType == 3); // Opera incorrectly creates an element node
+ } catch (e) {
+ // IE 6 and 7 throw
+ }
- createContextualFragment: createContextualFragment,
+ api.features.htmlParsingConforms = htmlParsingConforms;
- toHtml: function() {
- return rangeToHtml(this);
- },
+ var createContextualFragment = htmlParsingConforms ?
- // touchingIsIntersecting determines whether this method considers a node that borders a range intersects
- // with it (as in WebKit) or not (as in Gecko pre-1.9, and the default)
- intersectsNode: function(node, touchingIsIntersecting) {
- assertRangeValid(this);
- if (getRootContainer(node) != getRangeRoot(this)) {
- return false;
- }
+ // Implementation as per HTML parsing spec, trusting in the browser's implementation of innerHTML. See
+ // discussion and base code for this implementation at issue 67.
+ // Spec: http://html5.org/specs/dom-parsing.html#extensions-to-the-range-interface
+ // Thanks to Aleks Williams.
+ function(fragmentStr) {
+ // "Let node the context object's start's node."
+ var node = this.startContainer;
+ var doc = getDocument(node);
- var parent = node.parentNode, offset = getNodeIndex(node);
- if (!parent) {
- return true;
+ // "If the context object's start's node is null, raise an INVALID_STATE_ERR
+ // exception and abort these steps."
+ if (!node) {
+ throw new DOMException("INVALID_STATE_ERR");
}
- var startComparison = comparePoints(parent, offset, this.endContainer, this.endOffset),
- endComparison = comparePoints(parent, offset + 1, this.startContainer, this.startOffset);
-
- return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
- },
+ // "Let element be as follows, depending on node's interface:"
+ // Document, Document Fragment: null
+ var el = null;
- isPointInRange: function(node, offset) {
- assertRangeValid(this);
- assertNode(node, "HIERARCHY_REQUEST_ERR");
- assertSameDocumentOrFragment(node, this.startContainer);
+ // "Element: node"
+ if (node.nodeType == 1) {
+ el = node;
- return (comparePoints(node, offset, this.startContainer, this.startOffset) >= 0) &&
- (comparePoints(node, offset, this.endContainer, this.endOffset) <= 0);
- },
+ // "Text, Comment: node's parentElement"
+ } else if (isCharacterDataNode(node)) {
+ el = dom.parentElement(node);
+ }
- // The methods below are non-standard and invented by me.
+ // "If either element is null or element's ownerDocument is an HTML document
+ // and element's local name is "html" and element's namespace is the HTML
+ // namespace"
+ if (el === null || (
+ el.nodeName == "HTML" &&
+ dom.isHtmlNamespace(getDocument(el).documentElement) &&
+ dom.isHtmlNamespace(el)
+ )) {
- // Sharing a boundary start-to-end or end-to-start does not count as intersection.
- intersectsRange: function(range) {
- return rangesIntersect(this, range, false);
- },
+ // "let element be a new Element with "body" as its local name and the HTML
+ // namespace as its namespace.""
+ el = doc.createElement("body");
+ } else {
+ el = el.cloneNode(false);
+ }
- // Sharing a boundary start-to-end or end-to-start does count as intersection.
- intersectsOrTouchesRange: function(range) {
- return rangesIntersect(this, range, true);
- },
+ // "If the node's document is an HTML document: Invoke the HTML fragment parsing algorithm."
+ // "If the node's document is an XML document: Invoke the XML fragment parsing algorithm."
+ // "In either case, the algorithm must be invoked with fragment as the input
+ // and element as the context element."
+ el.innerHTML = fragmentStr;
- intersection: function(range) {
- if (this.intersectsRange(range)) {
- var startComparison = comparePoints(this.startContainer, this.startOffset, range.startContainer, range.startOffset),
- endComparison = comparePoints(this.endContainer, this.endOffset, range.endContainer, range.endOffset);
+ // "If this raises an exception, then abort these steps. Otherwise, let new
+ // children be the nodes returned."
- var intersectionRange = this.cloneRange();
- if (startComparison == -1) {
- intersectionRange.setStart(range.startContainer, range.startOffset);
- }
- if (endComparison == 1) {
- intersectionRange.setEnd(range.endContainer, range.endOffset);
- }
- return intersectionRange;
- }
- return null;
- },
+ // "Let fragment be a new DocumentFragment."
+ // "Append all new children to fragment."
+ // "Return fragment."
+ return dom.fragmentFromNodeChildren(el);
+ } :
- union: function(range) {
- if (this.intersectsOrTouchesRange(range)) {
- var unionRange = this.cloneRange();
- if (comparePoints(range.startContainer, range.startOffset, this.startContainer, this.startOffset) == -1) {
- unionRange.setStart(range.startContainer, range.startOffset);
- }
- if (comparePoints(range.endContainer, range.endOffset, this.endContainer, this.endOffset) == 1) {
- unionRange.setEnd(range.endContainer, range.endOffset);
- }
- return unionRange;
- } else {
- throw new DOMException("Ranges do not intersect");
- }
- },
+ // In this case, innerHTML cannot be trusted, so fall back to a simpler, non-conformant implementation that
+ // previous versions of Rangy used (with the exception of using a body element rather than a div)
+ function(fragmentStr) {
+ var doc = getRangeDocument(this);
+ var el = doc.createElement("body");
+ el.innerHTML = fragmentStr;
- containsNode: function(node, allowPartial) {
- if (allowPartial) {
- return this.intersectsNode(node, false);
- } else {
- return this.compareNode(node) == n_i;
- }
- },
+ return dom.fragmentFromNodeChildren(el);
+ };
- containsNodeContents: function(node) {
- return this.comparePoint(node, 0) >= 0 && this.comparePoint(node, getNodeLength(node)) <= 0;
- },
+ function splitRangeBoundaries(range, positionsToPreserve) {
+ assertRangeValid(range);
- containsRange: function(range) {
- var intersection = this.intersection(range);
- return intersection !== null && range.equals(intersection);
- },
+ var sc = range.startContainer, so = range.startOffset, ec = range.endContainer, eo = range.endOffset;
+ var startEndSame = (sc === ec);
- containsNodeText: function(node) {
- var nodeRange = this.cloneRange();
- nodeRange.selectNode(node);
- var textNodes = nodeRange.getNodes([3]);
- if (textNodes.length > 0) {
- nodeRange.setStart(textNodes[0], 0);
- var lastTextNode = textNodes.pop();
- nodeRange.setEnd(lastTextNode, lastTextNode.length);
- return this.containsRange(nodeRange);
- } else {
- return this.containsNodeContents(node);
+ if (isCharacterDataNode(ec) && eo > 0 && eo < ec.length) {
+ splitDataNode(ec, eo, positionsToPreserve);
+ }
+
+ if (isCharacterDataNode(sc) && so > 0 && so < sc.length) {
+ sc = splitDataNode(sc, so, positionsToPreserve);
+ if (startEndSame) {
+ eo -= so;
+ ec = sc;
+ } else if (ec == sc.parentNode && eo >= getNodeIndex(sc)) {
+ eo++;
}
- },
+ so = 0;
+ }
+ range.setStartAndEnd(sc, so, ec, eo);
+ }
- getNodes: function(nodeTypes, filter) {
- assertRangeValid(this);
- return getNodesInRange(this, nodeTypes, filter);
- },
+ function rangeToHtml(range) {
+ assertRangeValid(range);
+ var container = range.commonAncestorContainer.parentNode.cloneNode(false);
+ container.appendChild( range.cloneContents() );
+ return container.innerHTML;
+ }
- getDocument: function() {
- return getRangeDocument(this);
- },
+ /*----------------------------------------------------------------------------------------------------------------*/
- collapseBefore: function(node) {
- this.setEndBefore(node);
- this.collapse(false);
- },
+ var rangeProperties = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed",
+ "commonAncestorContainer"];
- collapseAfter: function(node) {
- this.setStartAfter(node);
- this.collapse(true);
+ var s2s = 0, s2e = 1, e2e = 2, e2s = 3;
+ var n_b = 0, n_a = 1, n_b_a = 2, n_i = 3;
+
+ util.extend(api.rangePrototype, {
+ compareBoundaryPoints: function(how, range) {
+ assertRangeValid(this);
+ assertSameDocumentOrFragment(this.startContainer, range.startContainer);
+
+ var nodeA, offsetA, nodeB, offsetB;
+ var prefixA = (how == e2s || how == s2s) ? "start" : "end";
+ var prefixB = (how == s2e || how == s2s) ? "start" : "end";
+ nodeA = this[prefixA + "Container"];
+ offsetA = this[prefixA + "Offset"];
+ nodeB = range[prefixB + "Container"];
+ offsetB = range[prefixB + "Offset"];
+ return comparePoints(nodeA, offsetA, nodeB, offsetB);
},
- getBookmark: function(containerNode) {
- var doc = getRangeDocument(this);
- var preSelectionRange = api.createRange(doc);
- containerNode = containerNode || dom.getBody(doc);
- preSelectionRange.selectNodeContents(containerNode);
- var range = this.intersection(preSelectionRange);
- var start = 0, end = 0;
- if (range) {
- preSelectionRange.setEnd(range.startContainer, range.startOffset);
- start = preSelectionRange.toString().length;
- end = start + range.toString().length;
+ insertNode: function(node) {
+ assertRangeValid(this);
+ assertValidNodeType(node, insertableNodeTypes);
+ assertNodeNotReadOnly(this.startContainer);
+
+ if (isOrIsAncestorOf(node, this.startContainer)) {
+ throw new DOMException("HIERARCHY_REQUEST_ERR");
}
- return {
- start: start,
- end: end,
- containerNode: containerNode
- };
+ // No check for whether the container of the start of the Range is of a type that does not allow
+ // children of the type of node: the browser's DOM implementation should do this for us when we attempt
+ // to add the node
+
+ var firstNodeInserted = insertNodeAtPosition(node, this.startContainer, this.startOffset);
+ this.setStartBefore(firstNodeInserted);
},
- moveToBookmark: function(bookmark) {
- var containerNode = bookmark.containerNode;
- var charIndex = 0;
- this.setStart(containerNode, 0);
- this.collapse(true);
- var nodeStack = [containerNode], node, foundStart = false, stop = false;
- var nextCharIndex, i, childNodes;
+ cloneContents: function() {
+ assertRangeValid(this);
- while (!stop && (node = nodeStack.pop())) {
- if (node.nodeType == 3) {
- nextCharIndex = charIndex + node.length;
- if (!foundStart && bookmark.start >= charIndex && bookmark.start <= nextCharIndex) {
- this.setStart(node, bookmark.start - charIndex);
- foundStart = true;
- }
- if (foundStart && bookmark.end >= charIndex && bookmark.end <= nextCharIndex) {
- this.setEnd(node, bookmark.end - charIndex);
- stop = true;
- }
- charIndex = nextCharIndex;
+ var clone, frag;
+ if (this.collapsed) {
+ return getRangeDocument(this).createDocumentFragment();
+ } else {
+ if (this.startContainer === this.endContainer && isCharacterDataNode(this.startContainer)) {
+ clone = this.startContainer.cloneNode(true);
+ clone.data = clone.data.slice(this.startOffset, this.endOffset);
+ frag = getRangeDocument(this).createDocumentFragment();
+ frag.appendChild(clone);
+ return frag;
} else {
- childNodes = node.childNodes;
- i = childNodes.length;
- while (i--) {
- nodeStack.push(childNodes[i]);
- }
+ var iterator = new RangeIterator(this, true);
+ clone = cloneSubtree(iterator);
+ iterator.detach();
}
+ return clone;
}
},
- getName: function() {
- return "DomRange";
- },
+ canSurroundContents: function() {
+ assertRangeValid(this);
+ assertNodeNotReadOnly(this.startContainer);
+ assertNodeNotReadOnly(this.endContainer);
- equals: function(range) {
- return Range.rangesEqual(this, range);
+ // Check if the contents can be surrounded. Specifically, this means whether the range partially selects
+ // no non-text nodes.
+ var iterator = new RangeIterator(this, true);
+ var boundariesInvalid = (iterator._first && (isNonTextPartiallySelected(iterator._first, this)) ||
+ (iterator._last && isNonTextPartiallySelected(iterator._last, this)));
+ iterator.detach();
+ return !boundariesInvalid;
},
- isValid: function() {
- return isRangeValid(this);
- },
+ surroundContents: function(node) {
+ assertValidNodeType(node, surroundNodeTypes);
- inspect: function() {
- return inspect(this);
- },
+ if (!this.canSurroundContents()) {
+ throw new DOMException("INVALID_STATE_ERR");
+ }
- detach: function() {
- // In DOM4, detach() is now a no-op.
- }
- });
+ // Extract the contents
+ var content = this.extractContents();
- function copyComparisonConstantsToObject(obj) {
- obj.START_TO_START = s2s;
- obj.START_TO_END = s2e;
- obj.END_TO_END = e2e;
- obj.END_TO_START = e2s;
+ // Clear the children of the node
+ if (node.hasChildNodes()) {
+ while (node.lastChild) {
+ node.removeChild(node.lastChild);
+ }
+ }
- obj.NODE_BEFORE = n_b;
- obj.NODE_AFTER = n_a;
- obj.NODE_BEFORE_AND_AFTER = n_b_a;
- obj.NODE_INSIDE = n_i;
- }
+ // Insert the new node and add the extracted contents
+ insertNodeAtPosition(node, this.startContainer, this.startOffset);
+ node.appendChild(content);
- function copyComparisonConstants(constructor) {
- copyComparisonConstantsToObject(constructor);
- copyComparisonConstantsToObject(constructor.prototype);
- }
+ this.selectNode(node);
+ },
- function createRangeContentRemover(remover, boundaryUpdater) {
- return function() {
+ cloneRange: function() {
assertRangeValid(this);
+ var range = new Range(getRangeDocument(this));
+ var i = rangeProperties.length, prop;
+ while (i--) {
+ prop = rangeProperties[i];
+ range[prop] = this[prop];
+ }
+ return range;
+ },
- var sc = this.startContainer, so = this.startOffset, root = this.commonAncestorContainer;
-
- var iterator = new RangeIterator(this, true);
-
- // Work out where to position the range after content removal
- var node, boundary;
- if (sc !== root) {
- node = getClosestAncestorIn(sc, root, true);
- boundary = getBoundaryAfterNode(node);
- sc = boundary.node;
- so = boundary.offset;
+ toString: function() {
+ assertRangeValid(this);
+ var sc = this.startContainer;
+ if (sc === this.endContainer && isCharacterDataNode(sc)) {
+ return (sc.nodeType == 3 || sc.nodeType == 4) ? sc.data.slice(this.startOffset, this.endOffset) : "";
+ } else {
+ var textParts = [], iterator = new RangeIterator(this, true);
+ iterateSubtree(iterator, function(node) {
+ // Accept only text or CDATA nodes, not comments
+ if (node.nodeType == 3 || node.nodeType == 4) {
+ textParts.push(node.data);
+ }
+ });
+ iterator.detach();
+ return textParts.join("");
}
+ },
- // Check none of the range is read-only
- iterateSubtree(iterator, assertNodeNotReadOnly);
+ // The methods below are all non-standard. The following batch were introduced by Mozilla but have since
+ // been removed from Mozilla.
- iterator.reset();
+ compareNode: function(node) {
+ assertRangeValid(this);
- // Remove the content
- var returnValue = remover(iterator);
- iterator.detach();
+ var parent = node.parentNode;
+ var nodeIndex = getNodeIndex(node);
- // Move to the new position
- boundaryUpdater(this, sc, so, sc, so);
+ if (!parent) {
+ throw new DOMException("NOT_FOUND_ERR");
+ }
- return returnValue;
- };
- }
+ var startComparison = this.comparePoint(parent, nodeIndex),
+ endComparison = this.comparePoint(parent, nodeIndex + 1);
- function createPrototypeRange(constructor, boundaryUpdater) {
- function createBeforeAfterNodeSetter(isBefore, isStart) {
- return function(node) {
- assertValidNodeType(node, beforeAfterNodeTypes);
- assertValidNodeType(getRootContainer(node), rootContainerNodeTypes);
+ if (startComparison < 0) { // Node starts before
+ return (endComparison > 0) ? n_b_a : n_b;
+ } else {
+ return (endComparison > 0) ? n_a : n_i;
+ }
+ },
- var boundary = (isBefore ? getBoundaryBeforeNode : getBoundaryAfterNode)(node);
- (isStart ? setRangeStart : setRangeEnd)(this, boundary.node, boundary.offset);
- };
- }
+ comparePoint: function(node, offset) {
+ assertRangeValid(this);
+ assertNode(node, "HIERARCHY_REQUEST_ERR");
+ assertSameDocumentOrFragment(node, this.startContainer);
- function setRangeStart(range, node, offset) {
- var ec = range.endContainer, eo = range.endOffset;
- if (node !== range.startContainer || offset !== range.startOffset) {
- // Check the root containers of the range and the new boundary, and also check whether the new boundary
- // is after the current end. In either case, collapse the range to the new position
- if (getRootContainer(node) != getRootContainer(ec) || comparePoints(node, offset, ec, eo) == 1) {
- ec = node;
- eo = offset;
- }
- boundaryUpdater(range, node, offset, ec, eo);
+ if (comparePoints(node, offset, this.startContainer, this.startOffset) < 0) {
+ return -1;
+ } else if (comparePoints(node, offset, this.endContainer, this.endOffset) > 0) {
+ return 1;
}
- }
+ return 0;
+ },
- function setRangeEnd(range, node, offset) {
- var sc = range.startContainer, so = range.startOffset;
- if (node !== range.endContainer || offset !== range.endOffset) {
- // Check the root containers of the range and the new boundary, and also check whether the new boundary
- // is after the current end. In either case, collapse the range to the new position
- if (getRootContainer(node) != getRootContainer(sc) || comparePoints(node, offset, sc, so) == -1) {
- sc = node;
- so = offset;
- }
- boundaryUpdater(range, sc, so, node, offset);
- }
- }
+ createContextualFragment: createContextualFragment,
- // Set up inheritance
- var F = function() {};
- F.prototype = api.rangePrototype;
- constructor.prototype = new F();
+ toHtml: function() {
+ return rangeToHtml(this);
+ },
- util.extend(constructor.prototype, {
- setStart: function(node, offset) {
- assertNoDocTypeNotationEntityAncestor(node, true);
- assertValidOffset(node, offset);
+ // touchingIsIntersecting determines whether this method considers a node that borders a range intersects
+ // with it (as in WebKit) or not (as in Gecko pre-1.9, and the default)
+ intersectsNode: function(node, touchingIsIntersecting) {
+ assertRangeValid(this);
+ if (getRootContainer(node) != getRangeRoot(this)) {
+ return false;
+ }
- setRangeStart(this, node, offset);
- },
+ var parent = node.parentNode, offset = getNodeIndex(node);
+ if (!parent) {
+ return true;
+ }
- setEnd: function(node, offset) {
- assertNoDocTypeNotationEntityAncestor(node, true);
- assertValidOffset(node, offset);
+ var startComparison = comparePoints(parent, offset, this.endContainer, this.endOffset),
+ endComparison = comparePoints(parent, offset + 1, this.startContainer, this.startOffset);
- setRangeEnd(this, node, offset);
- },
+ return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
+ },
- /**
- * Convenience method to set a range's start and end boundaries. Overloaded as follows:
- * - Two parameters (node, offset) creates a collapsed range at that position
- * - Three parameters (node, startOffset, endOffset) creates a range contained with node starting at
- * startOffset and ending at endOffset
- * - Four parameters (startNode, startOffset, endNode, endOffset) creates a range starting at startOffset in
- * startNode and ending at endOffset in endNode
- */
- setStartAndEnd: function() {
- var args = arguments;
- var sc = args[0], so = args[1], ec = sc, eo = so;
+ isPointInRange: function(node, offset) {
+ assertRangeValid(this);
+ assertNode(node, "HIERARCHY_REQUEST_ERR");
+ assertSameDocumentOrFragment(node, this.startContainer);
- switch (args.length) {
- case 3:
- eo = args[2];
- break;
- case 4:
- ec = args[2];
- eo = args[3];
- break;
- }
+ return (comparePoints(node, offset, this.startContainer, this.startOffset) >= 0) &&
+ (comparePoints(node, offset, this.endContainer, this.endOffset) <= 0);
+ },
- boundaryUpdater(this, sc, so, ec, eo);
- },
+ // The methods below are non-standard and invented by me.
- setBoundary: function(node, offset, isStart) {
- this["set" + (isStart ? "Start" : "End")](node, offset);
- },
+ // Sharing a boundary start-to-end or end-to-start does not count as intersection.
+ intersectsRange: function(range) {
+ return rangesIntersect(this, range, false);
+ },
- setStartBefore: createBeforeAfterNodeSetter(true, true),
- setStartAfter: createBeforeAfterNodeSetter(false, true),
- setEndBefore: createBeforeAfterNodeSetter(true, false),
- setEndAfter: createBeforeAfterNodeSetter(false, false),
+ // Sharing a boundary start-to-end or end-to-start does count as intersection.
+ intersectsOrTouchesRange: function(range) {
+ return rangesIntersect(this, range, true);
+ },
- collapse: function(isStart) {
- assertRangeValid(this);
- if (isStart) {
- boundaryUpdater(this, this.startContainer, this.startOffset, this.startContainer, this.startOffset);
- } else {
- boundaryUpdater(this, this.endContainer, this.endOffset, this.endContainer, this.endOffset);
- }
- },
+ intersection: function(range) {
+ if (this.intersectsRange(range)) {
+ var startComparison = comparePoints(this.startContainer, this.startOffset, range.startContainer, range.startOffset),
+ endComparison = comparePoints(this.endContainer, this.endOffset, range.endContainer, range.endOffset);
- selectNodeContents: function(node) {
- assertNoDocTypeNotationEntityAncestor(node, true);
+ var intersectionRange = this.cloneRange();
+ if (startComparison == -1) {
+ intersectionRange.setStart(range.startContainer, range.startOffset);
+ }
+ if (endComparison == 1) {
+ intersectionRange.setEnd(range.endContainer, range.endOffset);
+ }
+ return intersectionRange;
+ }
+ return null;
+ },
- boundaryUpdater(this, node, 0, node, getNodeLength(node));
- },
+ union: function(range) {
+ if (this.intersectsOrTouchesRange(range)) {
+ var unionRange = this.cloneRange();
+ if (comparePoints(range.startContainer, range.startOffset, this.startContainer, this.startOffset) == -1) {
+ unionRange.setStart(range.startContainer, range.startOffset);
+ }
+ if (comparePoints(range.endContainer, range.endOffset, this.endContainer, this.endOffset) == 1) {
+ unionRange.setEnd(range.endContainer, range.endOffset);
+ }
+ return unionRange;
+ } else {
+ throw new DOMException("Ranges do not intersect");
+ }
+ },
- selectNode: function(node) {
- assertNoDocTypeNotationEntityAncestor(node, false);
- assertValidNodeType(node, beforeAfterNodeTypes);
+ containsNode: function(node, allowPartial) {
+ if (allowPartial) {
+ return this.intersectsNode(node, false);
+ } else {
+ return this.compareNode(node) == n_i;
+ }
+ },
- var start = getBoundaryBeforeNode(node), end = getBoundaryAfterNode(node);
- boundaryUpdater(this, start.node, start.offset, end.node, end.offset);
- },
+ containsNodeContents: function(node) {
+ return this.comparePoint(node, 0) >= 0 && this.comparePoint(node, getNodeLength(node)) <= 0;
+ },
- extractContents: createRangeContentRemover(extractSubtree, boundaryUpdater),
+ containsRange: function(range) {
+ var intersection = this.intersection(range);
+ return intersection !== null && range.equals(intersection);
+ },
- deleteContents: createRangeContentRemover(deleteSubtree, boundaryUpdater),
+ containsNodeText: function(node) {
+ var nodeRange = this.cloneRange();
+ nodeRange.selectNode(node);
+ var textNodes = nodeRange.getNodes([3]);
+ if (textNodes.length > 0) {
+ nodeRange.setStart(textNodes[0], 0);
+ var lastTextNode = textNodes.pop();
+ nodeRange.setEnd(lastTextNode, lastTextNode.length);
+ return this.containsRange(nodeRange);
+ } else {
+ return this.containsNodeContents(node);
+ }
+ },
- canSurroundContents: function() {
- assertRangeValid(this);
- assertNodeNotReadOnly(this.startContainer);
- assertNodeNotReadOnly(this.endContainer);
+ getNodes: function(nodeTypes, filter) {
+ assertRangeValid(this);
+ return getNodesInRange(this, nodeTypes, filter);
+ },
- // Check if the contents can be surrounded. Specifically, this means whether the range partially selects
- // no non-text nodes.
- var iterator = new RangeIterator(this, true);
- var boundariesInvalid = (iterator._first && isNonTextPartiallySelected(iterator._first, this) ||
- (iterator._last && isNonTextPartiallySelected(iterator._last, this)));
- iterator.detach();
- return !boundariesInvalid;
- },
+ getDocument: function() {
+ return getRangeDocument(this);
+ },
- splitBoundaries: function() {
- splitRangeBoundaries(this);
- },
+ collapseBefore: function(node) {
+ this.setEndBefore(node);
+ this.collapse(false);
+ },
- splitBoundariesPreservingPositions: function(positionsToPreserve) {
- splitRangeBoundaries(this, positionsToPreserve);
- },
+ collapseAfter: function(node) {
+ this.setStartAfter(node);
+ this.collapse(true);
+ },
- normalizeBoundaries: function() {
- assertRangeValid(this);
+ getBookmark: function(containerNode) {
+ var doc = getRangeDocument(this);
+ var preSelectionRange = api.createRange(doc);
+ containerNode = containerNode || dom.getBody(doc);
+ preSelectionRange.selectNodeContents(containerNode);
+ var range = this.intersection(preSelectionRange);
+ var start = 0, end = 0;
+ if (range) {
+ preSelectionRange.setEnd(range.startContainer, range.startOffset);
+ start = preSelectionRange.toString().length;
+ end = start + range.toString().length;
+ }
- var sc = this.startContainer, so = this.startOffset, ec = this.endContainer, eo = this.endOffset;
+ return {
+ start: start,
+ end: end,
+ containerNode: containerNode
+ };
+ },
- var mergeForward = function(node) {
- var sibling = node.nextSibling;
- if (sibling && sibling.nodeType == node.nodeType) {
- ec = node;
- eo = node.length;
- node.appendData(sibling.data);
- removeNode(sibling);
- }
- };
+ moveToBookmark: function(bookmark) {
+ var containerNode = bookmark.containerNode;
+ var charIndex = 0;
+ this.setStart(containerNode, 0);
+ this.collapse(true);
+ var nodeStack = [containerNode], node, foundStart = false, stop = false;
+ var nextCharIndex, i, childNodes;
- var mergeBackward = function(node) {
- var sibling = node.previousSibling;
- if (sibling && sibling.nodeType == node.nodeType) {
- sc = node;
- var nodeLength = node.length;
- so = sibling.length;
- node.insertData(0, sibling.data);
- removeNode(sibling);
- if (sc == ec) {
- eo += so;
- ec = sc;
- } else if (ec == node.parentNode) {
- var nodeIndex = getNodeIndex(node);
- if (eo == nodeIndex) {
- ec = node;
- eo = nodeLength;
- } else if (eo > nodeIndex) {
- eo--;
- }
- }
+ while (!stop && (node = nodeStack.pop())) {
+ if (node.nodeType == 3) {
+ nextCharIndex = charIndex + node.length;
+ if (!foundStart && bookmark.start >= charIndex && bookmark.start <= nextCharIndex) {
+ this.setStart(node, bookmark.start - charIndex);
+ foundStart = true;
}
- };
-
- var normalizeStart = true;
- var sibling;
-
- if (isCharacterDataNode(ec)) {
- if (eo == ec.length) {
- mergeForward(ec);
- } else if (eo == 0) {
- sibling = ec.previousSibling;
- if (sibling && sibling.nodeType == ec.nodeType) {
- eo = sibling.length;
- if (sc == ec) {
- normalizeStart = false;
- }
- sibling.appendData(ec.data);
- removeNode(ec);
- ec = sibling;
- }
+ if (foundStart && bookmark.end >= charIndex && bookmark.end <= nextCharIndex) {
+ this.setEnd(node, bookmark.end - charIndex);
+ stop = true;
}
+ charIndex = nextCharIndex;
} else {
- if (eo > 0) {
- var endNode = ec.childNodes[eo - 1];
- if (endNode && isCharacterDataNode(endNode)) {
- mergeForward(endNode);
- }
- }
- normalizeStart = !this.collapsed;
- }
-
- if (normalizeStart) {
- if (isCharacterDataNode(sc)) {
- if (so == 0) {
- mergeBackward(sc);
- } else if (so == sc.length) {
- sibling = sc.nextSibling;
- if (sibling && sibling.nodeType == sc.nodeType) {
- if (ec == sibling) {
- ec = sc;
- eo += sc.length;
- }
- sc.appendData(sibling.data);
- removeNode(sibling);
- }
- }
- } else {
- if (so < sc.childNodes.length) {
- var startNode = sc.childNodes[so];
- if (startNode && isCharacterDataNode(startNode)) {
- mergeBackward(startNode);
- }
- }
+ childNodes = node.childNodes;
+ i = childNodes.length;
+ while (i--) {
+ nodeStack.push(childNodes[i]);
}
- } else {
- sc = ec;
- so = eo;
}
+ }
+ },
- boundaryUpdater(this, sc, so, ec, eo);
- },
+ getName: function() {
+ return "DomRange";
+ },
- collapseToPoint: function(node, offset) {
- assertNoDocTypeNotationEntityAncestor(node, true);
- assertValidOffset(node, offset);
- this.setStartAndEnd(node, offset);
- }
- });
+ equals: function(range) {
+ return Range.rangesEqual(this, range);
+ },
- copyComparisonConstants(constructor);
- }
+ isValid: function() {
+ return isRangeValid(this);
+ },
- /*----------------------------------------------------------------------------------------------------------------*/
+ inspect: function() {
+ return inspect(this);
+ },
- // Updates commonAncestorContainer and collapsed after boundary change
- function updateCollapsedAndCommonAncestor(range) {
- range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
- range.commonAncestorContainer = range.collapsed ?
- range.startContainer : dom.getCommonAncestor(range.startContainer, range.endContainer);
- }
+ detach: function() {
+ // In DOM4, detach() is now a no-op.
+ }
+ });
- function updateBoundaries(range, startContainer, startOffset, endContainer, endOffset) {
- range.startContainer = startContainer;
- range.startOffset = startOffset;
- range.endContainer = endContainer;
- range.endOffset = endOffset;
- range.document = dom.getDocument(startContainer);
+ function copyComparisonConstantsToObject(obj) {
+ obj.START_TO_START = s2s;
+ obj.START_TO_END = s2e;
+ obj.END_TO_END = e2e;
+ obj.END_TO_START = e2s;
- updateCollapsedAndCommonAncestor(range);
+ obj.NODE_BEFORE = n_b;
+ obj.NODE_AFTER = n_a;
+ obj.NODE_BEFORE_AND_AFTER = n_b_a;
+ obj.NODE_INSIDE = n_i;
}
- function Range(doc) {
- this.startContainer = doc;
- this.startOffset = 0;
- this.endContainer = doc;
- this.endOffset = 0;
- this.document = doc;
- updateCollapsedAndCommonAncestor(this);
+ function copyComparisonConstants(constructor) {
+ copyComparisonConstantsToObject(constructor);
+ copyComparisonConstantsToObject(constructor.prototype);
}
- createPrototypeRange(Range, updateBoundaries);
+ function createRangeContentRemover(remover, boundaryUpdater) {
+ return function() {
+ assertRangeValid(this);
- util.extend(Range, {
- rangeProperties: rangeProperties,
- RangeIterator: RangeIterator,
- copyComparisonConstants: copyComparisonConstants,
- createPrototypeRange: createPrototypeRange,
- inspect: inspect,
- toHtml: rangeToHtml,
- getRangeDocument: getRangeDocument,
- rangesEqual: function(r1, r2) {
- return r1.startContainer === r2.startContainer &&
- r1.startOffset === r2.startOffset &&
- r1.endContainer === r2.endContainer &&
- r1.endOffset === r2.endOffset;
- }
- });
+ var sc = this.startContainer, so = this.startOffset, root = this.commonAncestorContainer;
- api.DomRange = Range;
- });
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Wrappers for the browser's native DOM Range and/or TextRange implementation
- api.createCoreModule("WrappedRange", ["DomRange"], function(api, module) {
- var WrappedRange, WrappedTextRange;
- var dom = api.dom;
- var util = api.util;
- var DomPosition = dom.DomPosition;
- var DomRange = api.DomRange;
- var getBody = dom.getBody;
- var getContentDocument = dom.getContentDocument;
- var isCharacterDataNode = dom.isCharacterDataNode;
+ var iterator = new RangeIterator(this, true);
+
+ // Work out where to position the range after content removal
+ var node, boundary;
+ if (sc !== root) {
+ node = getClosestAncestorIn(sc, root, true);
+ boundary = getBoundaryAfterNode(node);
+ sc = boundary.node;
+ so = boundary.offset;
+ }
+ // Check none of the range is read-only
+ iterateSubtree(iterator, assertNodeNotReadOnly);
- /*----------------------------------------------------------------------------------------------------------------*/
+ iterator.reset();
- if (api.features.implementsDomRange) {
- // This is a wrapper around the browser's native DOM Range. It has two aims:
- // - Provide workarounds for specific browser bugs
- // - provide convenient extensions, which are inherited from Rangy's DomRange
+ // Remove the content
+ var returnValue = remover(iterator);
+ iterator.detach();
- (function() {
- var rangeProto;
- var rangeProperties = DomRange.rangeProperties;
+ // Move to the new position
+ boundaryUpdater(this, sc, so, sc, so);
- function updateRangeProperties(range) {
- var i = rangeProperties.length, prop;
- while (i--) {
- prop = rangeProperties[i];
- range[prop] = range.nativeRange[prop];
+ return returnValue;
+ };
+ }
+
+ function createPrototypeRange(constructor, boundaryUpdater) {
+ function createBeforeAfterNodeSetter(isBefore, isStart) {
+ return function(node) {
+ assertValidNodeType(node, beforeAfterNodeTypes);
+ assertValidNodeType(getRootContainer(node), rootContainerNodeTypes);
+
+ var boundary = (isBefore ? getBoundaryBeforeNode : getBoundaryAfterNode)(node);
+ (isStart ? setRangeStart : setRangeEnd)(this, boundary.node, boundary.offset);
+ };
+ }
+
+ function setRangeStart(range, node, offset) {
+ var ec = range.endContainer, eo = range.endOffset;
+ if (node !== range.startContainer || offset !== range.startOffset) {
+ // Check the root containers of the range and the new boundary, and also check whether the new boundary
+ // is after the current end. In either case, collapse the range to the new position
+ if (getRootContainer(node) != getRootContainer(ec) || comparePoints(node, offset, ec, eo) == 1) {
+ ec = node;
+ eo = offset;
}
- // Fix for broken collapsed property in IE 9.
- range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
+ boundaryUpdater(range, node, offset, ec, eo);
}
+ }
- function updateNativeRange(range, startContainer, startOffset, endContainer, endOffset) {
- var startMoved = (range.startContainer !== startContainer || range.startOffset != startOffset);
- var endMoved = (range.endContainer !== endContainer || range.endOffset != endOffset);
- var nativeRangeDifferent = !range.equals(range.nativeRange);
-
- // Always set both boundaries for the benefit of IE9 (see issue 35)
- if (startMoved || endMoved || nativeRangeDifferent) {
- range.setEnd(endContainer, endOffset);
- range.setStart(startContainer, startOffset);
+ function setRangeEnd(range, node, offset) {
+ var sc = range.startContainer, so = range.startOffset;
+ if (node !== range.endContainer || offset !== range.endOffset) {
+ // Check the root containers of the range and the new boundary, and also check whether the new boundary
+ // is after the current end. In either case, collapse the range to the new position
+ if (getRootContainer(node) != getRootContainer(sc) || comparePoints(node, offset, sc, so) == -1) {
+ sc = node;
+ so = offset;
}
+ boundaryUpdater(range, sc, so, node, offset);
}
+ }
- var createBeforeAfterNodeSetter;
+ // Set up inheritance
+ var F = function() {};
+ F.prototype = api.rangePrototype;
+ constructor.prototype = new F();
- WrappedRange = function(range) {
- if (!range) {
- throw module.createError("WrappedRange: Range must be specified");
- }
- this.nativeRange = range;
- updateRangeProperties(this);
- };
+ util.extend(constructor.prototype, {
+ setStart: function(node, offset) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+ assertValidOffset(node, offset);
- DomRange.createPrototypeRange(WrappedRange, updateNativeRange);
+ setRangeStart(this, node, offset);
+ },
- rangeProto = WrappedRange.prototype;
+ setEnd: function(node, offset) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+ assertValidOffset(node, offset);
- rangeProto.selectNode = function(node) {
- this.nativeRange.selectNode(node);
- updateRangeProperties(this);
- };
+ setRangeEnd(this, node, offset);
+ },
- rangeProto.cloneContents = function() {
- return this.nativeRange.cloneContents();
- };
+ /**
+ * Convenience method to set a range's start and end boundaries. Overloaded as follows:
+ * - Two parameters (node, offset) creates a collapsed range at that position
+ * - Three parameters (node, startOffset, endOffset) creates a range contained with node starting at
+ * startOffset and ending at endOffset
+ * - Four parameters (startNode, startOffset, endNode, endOffset) creates a range starting at startOffset in
+ * startNode and ending at endOffset in endNode
+ */
+ setStartAndEnd: function() {
+ var args = arguments;
+ var sc = args[0], so = args[1], ec = sc, eo = so;
- // Due to a long-standing Firefox bug that I have not been able to find a reliable way to detect,
- // insertNode() is never delegated to the native range.
+ switch (args.length) {
+ case 3:
+ eo = args[2];
+ break;
+ case 4:
+ ec = args[2];
+ eo = args[3];
+ break;
+ }
- rangeProto.surroundContents = function(node) {
- this.nativeRange.surroundContents(node);
- updateRangeProperties(this);
- };
+ boundaryUpdater(this, sc, so, ec, eo);
+ },
- rangeProto.collapse = function(isStart) {
- this.nativeRange.collapse(isStart);
- updateRangeProperties(this);
- };
+ setBoundary: function(node, offset, isStart) {
+ this["set" + (isStart ? "Start" : "End")](node, offset);
+ },
- rangeProto.cloneRange = function() {
- return new WrappedRange(this.nativeRange.cloneRange());
- };
+ setStartBefore: createBeforeAfterNodeSetter(true, true),
+ setStartAfter: createBeforeAfterNodeSetter(false, true),
+ setEndBefore: createBeforeAfterNodeSetter(true, false),
+ setEndAfter: createBeforeAfterNodeSetter(false, false),
- rangeProto.refresh = function() {
- updateRangeProperties(this);
- };
+ collapse: function(isStart) {
+ assertRangeValid(this);
+ if (isStart) {
+ boundaryUpdater(this, this.startContainer, this.startOffset, this.startContainer, this.startOffset);
+ } else {
+ boundaryUpdater(this, this.endContainer, this.endOffset, this.endContainer, this.endOffset);
+ }
+ },
- rangeProto.toString = function() {
- return this.nativeRange.toString();
- };
+ selectNodeContents: function(node) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
- // Create test range and node for feature detection
+ boundaryUpdater(this, node, 0, node, getNodeLength(node));
+ },
- var testTextNode = document.createTextNode("test");
- getBody(document).appendChild(testTextNode);
- var range = document.createRange();
+ selectNode: function(node) {
+ assertNoDocTypeNotationEntityAncestor(node, false);
+ assertValidNodeType(node, beforeAfterNodeTypes);
- /*--------------------------------------------------------------------------------------------------------*/
+ var start = getBoundaryBeforeNode(node), end = getBoundaryAfterNode(node);
+ boundaryUpdater(this, start.node, start.offset, end.node, end.offset);
+ },
- // Test for Firefox 2 bug that prevents moving the start of a Range to a point after its current end and
- // correct for it
+ extractContents: createRangeContentRemover(extractSubtree, boundaryUpdater),
- range.setStart(testTextNode, 0);
- range.setEnd(testTextNode, 0);
+ deleteContents: createRangeContentRemover(deleteSubtree, boundaryUpdater),
- try {
- range.setStart(testTextNode, 1);
+ canSurroundContents: function() {
+ assertRangeValid(this);
+ assertNodeNotReadOnly(this.startContainer);
+ assertNodeNotReadOnly(this.endContainer);
- rangeProto.setStart = function(node, offset) {
- this.nativeRange.setStart(node, offset);
- updateRangeProperties(this);
- };
+ // Check if the contents can be surrounded. Specifically, this means whether the range partially selects
+ // no non-text nodes.
+ var iterator = new RangeIterator(this, true);
+ var boundariesInvalid = (iterator._first && isNonTextPartiallySelected(iterator._first, this) ||
+ (iterator._last && isNonTextPartiallySelected(iterator._last, this)));
+ iterator.detach();
+ return !boundariesInvalid;
+ },
- rangeProto.setEnd = function(node, offset) {
- this.nativeRange.setEnd(node, offset);
- updateRangeProperties(this);
- };
+ splitBoundaries: function() {
+ splitRangeBoundaries(this);
+ },
- createBeforeAfterNodeSetter = function(name) {
- return function(node) {
- this.nativeRange[name](node);
- updateRangeProperties(this);
- };
- };
+ splitBoundariesPreservingPositions: function(positionsToPreserve) {
+ splitRangeBoundaries(this, positionsToPreserve);
+ },
- } catch(ex) {
+ normalizeBoundaries: function() {
+ assertRangeValid(this);
- rangeProto.setStart = function(node, offset) {
- try {
- this.nativeRange.setStart(node, offset);
- } catch (ex) {
- this.nativeRange.setEnd(node, offset);
- this.nativeRange.setStart(node, offset);
- }
- updateRangeProperties(this);
- };
+ var sc = this.startContainer, so = this.startOffset, ec = this.endContainer, eo = this.endOffset;
- rangeProto.setEnd = function(node, offset) {
- try {
- this.nativeRange.setEnd(node, offset);
- } catch (ex) {
- this.nativeRange.setStart(node, offset);
- this.nativeRange.setEnd(node, offset);
+ var mergeForward = function(node) {
+ var sibling = node.nextSibling;
+ if (sibling && sibling.nodeType == node.nodeType) {
+ ec = node;
+ eo = node.length;
+ node.appendData(sibling.data);
+ removeNode(sibling);
}
- updateRangeProperties(this);
};
- createBeforeAfterNodeSetter = function(name, oppositeName) {
- return function(node) {
- try {
- this.nativeRange[name](node);
- } catch (ex) {
- this.nativeRange[oppositeName](node);
- this.nativeRange[name](node);
+ var mergeBackward = function(node) {
+ var sibling = node.previousSibling;
+ if (sibling && sibling.nodeType == node.nodeType) {
+ sc = node;
+ var nodeLength = node.length;
+ so = sibling.length;
+ node.insertData(0, sibling.data);
+ removeNode(sibling);
+ if (sc == ec) {
+ eo += so;
+ ec = sc;
+ } else if (ec == node.parentNode) {
+ var nodeIndex = getNodeIndex(node);
+ if (eo == nodeIndex) {
+ ec = node;
+ eo = nodeLength;
+ } else if (eo > nodeIndex) {
+ eo--;
+ }
}
- updateRangeProperties(this);
- };
+ }
};
- }
- rangeProto.setStartBefore = createBeforeAfterNodeSetter("setStartBefore", "setEndBefore");
- rangeProto.setStartAfter = createBeforeAfterNodeSetter("setStartAfter", "setEndAfter");
- rangeProto.setEndBefore = createBeforeAfterNodeSetter("setEndBefore", "setStartBefore");
- rangeProto.setEndAfter = createBeforeAfterNodeSetter("setEndAfter", "setStartAfter");
-
- /*--------------------------------------------------------------------------------------------------------*/
+ var normalizeStart = true;
+ var sibling;
- // Always use DOM4-compliant selectNodeContents implementation: it's simpler and less code than testing
- // whether the native implementation can be trusted
- rangeProto.selectNodeContents = function(node) {
- this.setStartAndEnd(node, 0, dom.getNodeLength(node));
- };
+ if (isCharacterDataNode(ec)) {
+ if (eo == ec.length) {
+ mergeForward(ec);
+ } else if (eo == 0) {
+ sibling = ec.previousSibling;
+ if (sibling && sibling.nodeType == ec.nodeType) {
+ eo = sibling.length;
+ if (sc == ec) {
+ normalizeStart = false;
+ }
+ sibling.appendData(ec.data);
+ removeNode(ec);
+ ec = sibling;
+ }
+ }
+ } else {
+ if (eo > 0) {
+ var endNode = ec.childNodes[eo - 1];
+ if (endNode && isCharacterDataNode(endNode)) {
+ mergeForward(endNode);
+ }
+ }
+ normalizeStart = !this.collapsed;
+ }
- /*--------------------------------------------------------------------------------------------------------*/
+ if (normalizeStart) {
+ if (isCharacterDataNode(sc)) {
+ if (so == 0) {
+ mergeBackward(sc);
+ } else if (so == sc.length) {
+ sibling = sc.nextSibling;
+ if (sibling && sibling.nodeType == sc.nodeType) {
+ if (ec == sibling) {
+ ec = sc;
+ eo += sc.length;
+ }
+ sc.appendData(sibling.data);
+ removeNode(sibling);
+ }
+ }
+ } else {
+ if (so < sc.childNodes.length) {
+ var startNode = sc.childNodes[so];
+ if (startNode && isCharacterDataNode(startNode)) {
+ mergeBackward(startNode);
+ }
+ }
+ }
+ } else {
+ sc = ec;
+ so = eo;
+ }
- // Test for and correct WebKit bug that has the behaviour of compareBoundaryPoints round the wrong way for
- // constants START_TO_END and END_TO_START: https://bugs.webkit.org/show_bug.cgi?id=20738
+ boundaryUpdater(this, sc, so, ec, eo);
+ },
- range.selectNodeContents(testTextNode);
- range.setEnd(testTextNode, 3);
+ collapseToPoint: function(node, offset) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+ assertValidOffset(node, offset);
+ this.setStartAndEnd(node, offset);
+ }
+ });
- var range2 = document.createRange();
- range2.selectNodeContents(testTextNode);
- range2.setEnd(testTextNode, 4);
- range2.setStart(testTextNode, 2);
+ copyComparisonConstants(constructor);
+ }
- if (range.compareBoundaryPoints(range.START_TO_END, range2) == -1 &&
- range.compareBoundaryPoints(range.END_TO_START, range2) == 1) {
- // This is the wrong way round, so correct for it
+ /*----------------------------------------------------------------------------------------------------------------*/
- rangeProto.compareBoundaryPoints = function(type, range) {
- range = range.nativeRange || range;
- if (type == range.START_TO_END) {
- type = range.END_TO_START;
- } else if (type == range.END_TO_START) {
- type = range.START_TO_END;
- }
- return this.nativeRange.compareBoundaryPoints(type, range);
- };
- } else {
- rangeProto.compareBoundaryPoints = function(type, range) {
- return this.nativeRange.compareBoundaryPoints(type, range.nativeRange || range);
- };
- }
+ // Updates commonAncestorContainer and collapsed after boundary change
+ function updateCollapsedAndCommonAncestor(range) {
+ range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
+ range.commonAncestorContainer = range.collapsed ?
+ range.startContainer : dom.getCommonAncestor(range.startContainer, range.endContainer);
+ }
- /*--------------------------------------------------------------------------------------------------------*/
+ function updateBoundaries(range, startContainer, startOffset, endContainer, endOffset) {
+ range.startContainer = startContainer;
+ range.startOffset = startOffset;
+ range.endContainer = endContainer;
+ range.endOffset = endOffset;
+ range.document = dom.getDocument(startContainer);
- // Test for IE deleteContents() and extractContents() bug and correct it. See issue 107.
+ updateCollapsedAndCommonAncestor(range);
+ }
- var el = document.createElement("div");
- el.innerHTML = "123";
- var textNode = el.firstChild;
- var body = getBody(document);
- body.appendChild(el);
+ function Range(doc) {
+ this.startContainer = doc;
+ this.startOffset = 0;
+ this.endContainer = doc;
+ this.endOffset = 0;
+ this.document = doc;
+ updateCollapsedAndCommonAncestor(this);
+ }
- range.setStart(textNode, 1);
- range.setEnd(textNode, 2);
- range.deleteContents();
+ createPrototypeRange(Range, updateBoundaries);
- if (textNode.data == "13") {
- // Behaviour is correct per DOM4 Range so wrap the browser's implementation of deleteContents() and
- // extractContents()
- rangeProto.deleteContents = function() {
- this.nativeRange.deleteContents();
- updateRangeProperties(this);
- };
+ util.extend(Range, {
+ rangeProperties: rangeProperties,
+ RangeIterator: RangeIterator,
+ copyComparisonConstants: copyComparisonConstants,
+ createPrototypeRange: createPrototypeRange,
+ inspect: inspect,
+ toHtml: rangeToHtml,
+ getRangeDocument: getRangeDocument,
+ rangesEqual: function(r1, r2) {
+ return r1.startContainer === r2.startContainer &&
+ r1.startOffset === r2.startOffset &&
+ r1.endContainer === r2.endContainer &&
+ r1.endOffset === r2.endOffset;
+ }
+ });
- rangeProto.extractContents = function() {
- var frag = this.nativeRange.extractContents();
- updateRangeProperties(this);
- return frag;
- };
- } else {
- }
+ api.DomRange = Range;
+ });
- body.removeChild(el);
- body = null;
+ /*----------------------------------------------------------------------------------------------------------------*/
- /*--------------------------------------------------------------------------------------------------------*/
+ // Wrappers for the browser's native DOM Range and/or TextRange implementation
+ api.createCoreModule("WrappedRange", ["DomRange"], function(api, module) {
+ var WrappedRange, WrappedTextRange;
+ var dom = api.dom;
+ var util = api.util;
+ var DomPosition = dom.DomPosition;
+ var DomRange = api.DomRange;
+ var getBody = dom.getBody;
+ var getContentDocument = dom.getContentDocument;
+ var isCharacterDataNode = dom.isCharacterDataNode;
- // Test for existence of createContextualFragment and delegate to it if it exists
- if (util.isHostMethod(range, "createContextualFragment")) {
- rangeProto.createContextualFragment = function(fragmentStr) {
- return this.nativeRange.createContextualFragment(fragmentStr);
- };
- }
- /*--------------------------------------------------------------------------------------------------------*/
+ /*----------------------------------------------------------------------------------------------------------------*/
- // Clean up
- getBody(document).removeChild(testTextNode);
+ if (api.features.implementsDomRange) {
+ // This is a wrapper around the browser's native DOM Range. It has two aims:
+ // - Provide workarounds for specific browser bugs
+ // - provide convenient extensions, which are inherited from Rangy's DomRange
- rangeProto.getName = function() {
- return "WrappedRange";
- };
+ (function() {
+ var rangeProto;
+ var rangeProperties = DomRange.rangeProperties;
- api.WrappedRange = WrappedRange;
+ function updateRangeProperties(range) {
+ var i = rangeProperties.length, prop;
+ while (i--) {
+ prop = rangeProperties[i];
+ range[prop] = range.nativeRange[prop];
+ }
+ // Fix for broken collapsed property in IE 9.
+ range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
+ }
+
+ function updateNativeRange(range, startContainer, startOffset, endContainer, endOffset) {
+ var startMoved = (range.startContainer !== startContainer || range.startOffset != startOffset);
+ var endMoved = (range.endContainer !== endContainer || range.endOffset != endOffset);
+ var nativeRangeDifferent = !range.equals(range.nativeRange);
+
+ // Always set both boundaries for the benefit of IE9 (see issue 35)
+ if (startMoved || endMoved || nativeRangeDifferent) {
+ range.setEnd(endContainer, endOffset);
+ range.setStart(startContainer, startOffset);
+ }
+ }
+
+ var createBeforeAfterNodeSetter;
+
+ WrappedRange = function(range) {
+ if (!range) {
+ throw module.createError("WrappedRange: Range must be specified");
+ }
+ this.nativeRange = range;
+ updateRangeProperties(this);
+ };
+
+ DomRange.createPrototypeRange(WrappedRange, updateNativeRange);
+
+ rangeProto = WrappedRange.prototype;
+
+ rangeProto.selectNode = function(node) {
+ this.nativeRange.selectNode(node);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.cloneContents = function() {
+ return this.nativeRange.cloneContents();
+ };
+
+ // Due to a long-standing Firefox bug that I have not been able to find a reliable way to detect,
+ // insertNode() is never delegated to the native range.
+
+ rangeProto.surroundContents = function(node) {
+ this.nativeRange.surroundContents(node);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.collapse = function(isStart) {
+ this.nativeRange.collapse(isStart);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.cloneRange = function() {
+ return new WrappedRange(this.nativeRange.cloneRange());
+ };
+
+ rangeProto.refresh = function() {
+ updateRangeProperties(this);
+ };
+
+ rangeProto.toString = function() {
+ return this.nativeRange.toString();
+ };
+
+ // Create test range and node for feature detection
+
+ var testTextNode = document.createTextNode("test");
+ getBody(document).appendChild(testTextNode);
+ var range = document.createRange();
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for Firefox 2 bug that prevents moving the start of a Range to a point after its current end and
+ // correct for it
+
+ range.setStart(testTextNode, 0);
+ range.setEnd(testTextNode, 0);
+
+ try {
+ range.setStart(testTextNode, 1);
+
+ rangeProto.setStart = function(node, offset) {
+ this.nativeRange.setStart(node, offset);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.setEnd = function(node, offset) {
+ this.nativeRange.setEnd(node, offset);
+ updateRangeProperties(this);
+ };
+
+ createBeforeAfterNodeSetter = function(name) {
+ return function(node) {
+ this.nativeRange[name](node);
+ updateRangeProperties(this);
+ };
+ };
+
+ } catch(ex) {
+
+ rangeProto.setStart = function(node, offset) {
+ try {
+ this.nativeRange.setStart(node, offset);
+ } catch (ex) {
+ this.nativeRange.setEnd(node, offset);
+ this.nativeRange.setStart(node, offset);
+ }
+ updateRangeProperties(this);
+ };
+
+ rangeProto.setEnd = function(node, offset) {
+ try {
+ this.nativeRange.setEnd(node, offset);
+ } catch (ex) {
+ this.nativeRange.setStart(node, offset);
+ this.nativeRange.setEnd(node, offset);
+ }
+ updateRangeProperties(this);
+ };
+
+ createBeforeAfterNodeSetter = function(name, oppositeName) {
+ return function(node) {
+ try {
+ this.nativeRange[name](node);
+ } catch (ex) {
+ this.nativeRange[oppositeName](node);
+ this.nativeRange[name](node);
+ }
+ updateRangeProperties(this);
+ };
+ };
+ }
+
+ rangeProto.setStartBefore = createBeforeAfterNodeSetter("setStartBefore", "setEndBefore");
+ rangeProto.setStartAfter = createBeforeAfterNodeSetter("setStartAfter", "setEndAfter");
+ rangeProto.setEndBefore = createBeforeAfterNodeSetter("setEndBefore", "setStartBefore");
+ rangeProto.setEndAfter = createBeforeAfterNodeSetter("setEndAfter", "setStartAfter");
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Always use DOM4-compliant selectNodeContents implementation: it's simpler and less code than testing
+ // whether the native implementation can be trusted
+ rangeProto.selectNodeContents = function(node) {
+ this.setStartAndEnd(node, 0, dom.getNodeLength(node));
+ };
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for and correct WebKit bug that has the behaviour of compareBoundaryPoints round the wrong way for
+ // constants START_TO_END and END_TO_START: https://bugs.webkit.org/show_bug.cgi?id=20738
+
+ range.selectNodeContents(testTextNode);
+ range.setEnd(testTextNode, 3);
+
+ var range2 = document.createRange();
+ range2.selectNodeContents(testTextNode);
+ range2.setEnd(testTextNode, 4);
+ range2.setStart(testTextNode, 2);
+
+ if (range.compareBoundaryPoints(range.START_TO_END, range2) == -1 &&
+ range.compareBoundaryPoints(range.END_TO_START, range2) == 1) {
+ // This is the wrong way round, so correct for it
+
+ rangeProto.compareBoundaryPoints = function(type, range) {
+ range = range.nativeRange || range;
+ if (type == range.START_TO_END) {
+ type = range.END_TO_START;
+ } else if (type == range.END_TO_START) {
+ type = range.START_TO_END;
+ }
+ return this.nativeRange.compareBoundaryPoints(type, range);
+ };
+ } else {
+ rangeProto.compareBoundaryPoints = function(type, range) {
+ return this.nativeRange.compareBoundaryPoints(type, range.nativeRange || range);
+ };
+ }
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for IE deleteContents() and extractContents() bug and correct it. See issue 107.
+
+ var el = document.createElement("div");
+ el.innerHTML = "123";
+ var textNode = el.firstChild;
+ var body = getBody(document);
+ body.appendChild(el);
+
+ range.setStart(textNode, 1);
+ range.setEnd(textNode, 2);
+ range.deleteContents();
+
+ if (textNode.data == "13") {
+ // Behaviour is correct per DOM4 Range so wrap the browser's implementation of deleteContents() and
+ // extractContents()
+ rangeProto.deleteContents = function() {
+ this.nativeRange.deleteContents();
+ updateRangeProperties(this);
+ };
+
+ rangeProto.extractContents = function() {
+ var frag = this.nativeRange.extractContents();
+ updateRangeProperties(this);
+ return frag;
+ };
+ } else {
+ }
+
+ body.removeChild(el);
+ body = null;
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for existence of createContextualFragment and delegate to it if it exists
+ if (util.isHostMethod(range, "createContextualFragment")) {
+ rangeProto.createContextualFragment = function(fragmentStr) {
+ return this.nativeRange.createContextualFragment(fragmentStr);
+ };
+ }
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Clean up
+ getBody(document).removeChild(testTextNode);
+
+ rangeProto.getName = function() {
+ return "WrappedRange";
+ };
+
+ api.WrappedRange = WrappedRange;
api.createNativeRange = function(doc) {
doc = getContentDocument(doc, module, "createNativeRange");
@@ -3336,10 +3221,10 @@ wysihtml5.polyfills(window, document);
}
doc = win = null;
});
- });
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
+ });
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
// This module creates a selection object wrapper that conforms as closely as possible to the Selection specification
// in the HTML Editing spec (http://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#selections)
api.createCoreModule("WrappedSelection", ["DomRange", "WrappedRange"], function(api, module) {
@@ -4359,2360 +4244,2201 @@ wysihtml5.polyfills(window, document);
win = null;
});
});
-
-
- /*----------------------------------------------------------------------------------------------------------------*/
-
- // Wait for document to load before initializing
- var docReady = false;
-
- var loadHandler = function(e) {
- if (!docReady) {
- docReady = true;
- if (!api.initialized && api.config.autoInitialize) {
- init();
- }
- }
- };
-
- if (isBrowser) {
- // Test whether the document has already been loaded and initialize immediately if so
- if (document.readyState == "complete") {
- loadHandler();
- } else {
- if (isHostMethod(document, "addEventListener")) {
- document.addEventListener("DOMContentLoaded", loadHandler, false);
- }
-
- // Add a fallback in case the DOMContentLoaded event isn't supported
- addListener(window, "load", loadHandler);
- }
- }
-
- return api;
-}, this);
-;/**
- * Text range module for Rangy.
- * Text-based manipulation and searching of ranges and selections.
- *
- * Features
- *
- * - Ability to move range boundaries by character or word offsets
- * - Customizable word tokenizer
- * - Ignores text nodes inside
+ *
*/
-(function(wysihtml5) {
+(function(wysihtml) {
var /**
* Don't auto-link urls that are contained in the following elements:
*/
- IGNORE_URLS_IN = wysihtml5.lang.array(["CODE", "PRE", "A", "SCRIPT", "HEAD", "TITLE", "STYLE"]),
+ IGNORE_URLS_IN = wysihtml.lang.array(["CODE", "PRE", "A", "SCRIPT", "HEAD", "TITLE", "STYLE"]),
/**
* revision 1:
* /(\S+\.{1}[^\s\,\.\!]+)/g
@@ -7556,9 +7287,9 @@ wysihtml5.browser = (function() {
* for the given document object
*/
function _getTempElement(context) {
- var tempElement = context._wysihtml5_tempElement;
+ var tempElement = context._wysihtml_tempElement;
if (!tempElement) {
- tempElement = context._wysihtml5_tempElement = context.createElement("div");
+ tempElement = context._wysihtml_tempElement = context.createElement("div");
}
return tempElement;
}
@@ -7568,7 +7299,7 @@ wysihtml5.browser = (function() {
*/
function _wrapMatchesInNode(textNode) {
var parentNode = textNode.parentNode,
- nodeValue = wysihtml5.lang.string(textNode.data).escapeHTML(),
+ nodeValue = wysihtml.lang.string(textNode.data).escapeHTML(),
tempElement = _getTempElement(parentNode.ownerDocument);
// We need to insert an empty/temporary to fix IE quirks
@@ -7588,7 +7319,7 @@ wysihtml5.browser = (function() {
while (node.parentNode) {
node = node.parentNode;
nodeName = node.nodeName;
- if (node.className && wysihtml5.lang.array(node.className.split(' ')).contains(ignoreInClasses)) {
+ if (node.className && wysihtml.lang.array(node.className.split(' ')).contains(ignoreInClasses)) {
return true;
}
if (IGNORE_URLS_IN.contains(nodeName)) {
@@ -7605,16 +7336,16 @@ wysihtml5.browser = (function() {
return;
}
- if (element.className && wysihtml5.lang.array(element.className.split(' ')).contains(ignoreInClasses)) {
+ if (element.className && wysihtml.lang.array(element.className.split(' ')).contains(ignoreInClasses)) {
return;
}
- if (element.nodeType === wysihtml5.TEXT_NODE && element.data.match(URL_REG_EXP)) {
+ if (element.nodeType === wysihtml.TEXT_NODE && element.data.match(URL_REG_EXP)) {
_wrapMatchesInNode(element);
return;
}
- var childNodes = wysihtml5.lang.array(element.childNodes).get(),
+ var childNodes = wysihtml.lang.array(element.childNodes).get(),
childNodesLength = childNodes.length,
i = 0;
@@ -7625,13 +7356,14 @@ wysihtml5.browser = (function() {
return element;
}
- wysihtml5.dom.autoLink = autoLink;
+ wysihtml.dom.autoLink = autoLink;
// Reveal url reg exp to the outside
- wysihtml5.dom.autoLink.URL_REG_EXP = URL_REG_EXP;
-})(wysihtml5);
-;(function(wysihtml5) {
- var api = wysihtml5.dom;
+ wysihtml.dom.autoLink.URL_REG_EXP = URL_REG_EXP;
+})(wysihtml);
+
+(function(wysihtml) {
+ var api = wysihtml.dom;
api.addClass = function(element, className) {
var classList = element.classList;
@@ -7662,62 +7394,196 @@ wysihtml5.browser = (function() {
var elementClassName = element.className;
return (elementClassName.length > 0 && (elementClassName == className || new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
};
-})(wysihtml5);
-;wysihtml5.dom.contains = (function() {
+})(wysihtml);
+
+wysihtml.dom.compareDocumentPosition = (function() {
var documentElement = document.documentElement;
- if (documentElement.contains) {
- return function(container, element) {
- if (element.nodeType !== wysihtml5.ELEMENT_NODE) {
- if (element.parentNode === container) {
- return true;
- }
- element = element.parentNode;
- }
- return container !== element && container.contains(element);
- };
- } else if (documentElement.compareDocumentPosition) {
+ if (documentElement.compareDocumentPosition) {
return function(container, element) {
- // https://developer.mozilla.org/en/DOM/Node.compareDocumentPosition
- return !!(container.compareDocumentPosition(element) & 16);
+ return container.compareDocumentPosition(element);
};
- }
-})();
-;/**
- * Converts an HTML fragment/element into a unordered/ordered list
- *
- * @param {Element} element The element which should be turned into a list
- * @param {String} listType The list type in which to convert the tree (either "ul" or "ol")
- * @return {Element} The created list
- *
- * @example
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- *
- *
- *
- *
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- *
- */
-wysihtml5.dom.convertToList = (function() {
- function _createListItem(doc, list) {
- var listItem = doc.createElement("li");
- list.appendChild(listItem);
- return listItem;
- }
+ } else {
+ return function( container, element ) {
+ // implementation borrowed from https://github.com/tmpvar/jsdom/blob/681a8524b663281a0f58348c6129c8c184efc62c/lib/jsdom/level3/core.js // MIT license
+ var thisOwner, otherOwner;
- function _createList(doc, type) {
- return doc.createElement(type);
- }
+ if( container.nodeType === 9) // Node.DOCUMENT_NODE
+ thisOwner = container;
+ else
+ thisOwner = container.ownerDocument;
+
+ if( element.nodeType === 9) // Node.DOCUMENT_NODE
+ otherOwner = element;
+ else
+ otherOwner = element.ownerDocument;
+
+ if( container === element ) return 0;
+ if( container === element.ownerDocument ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+ if( container.ownerDocument === element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+ if( thisOwner !== otherOwner ) return 1; // Node.DOCUMENT_POSITION_DISCONNECTED;
+
+ // Text nodes for attributes does not have a _parentNode. So we need to find them as attribute child.
+ if( container.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && container.childNodes && wysihtml.lang.array(container.childNodes).indexOf( element ) !== -1)
+ return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+
+ if( element.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && element.childNodes && wysihtml.lang.array(element.childNodes).indexOf( container ) !== -1)
+ return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+
+ var point = container;
+ var parents = [ ];
+ var previous = null;
+ while( point ) {
+ if( point == element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+ parents.push( point );
+ point = point.parentNode;
+ }
+ point = element;
+ previous = null;
+ while( point ) {
+ if( point == container ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+ var location_index = wysihtml.lang.array(parents).indexOf( point );
+ if( location_index !== -1) {
+ var smallest_common_ancestor = parents[ location_index ];
+ var this_index = wysihtml.lang.array(smallest_common_ancestor.childNodes).indexOf( parents[location_index - 1]);//smallest_common_ancestor.childNodes.toArray().indexOf( parents[location_index - 1] );
+ var other_index = wysihtml.lang.array(smallest_common_ancestor.childNodes).indexOf( previous ); //smallest_common_ancestor.childNodes.toArray().indexOf( previous );
+ if( this_index > other_index ) {
+ return 2; //Node.DOCUMENT_POSITION_PRECEDING;
+ }
+ else {
+ return 4; //Node.DOCUMENT_POSITION_FOLLOWING;
+ }
+ }
+ previous = point;
+ point = point.parentNode;
+ }
+ return 1; //Node.DOCUMENT_POSITION_DISCONNECTED;
+ };
+ }
+})();
+
+wysihtml.dom.contains = (function() {
+ var documentElement = document.documentElement;
+ if (documentElement.contains) {
+ return function(container, element) {
+ if (element.nodeType !== wysihtml.ELEMENT_NODE) {
+ if (element.parentNode === container) {
+ return true;
+ }
+ element = element.parentNode;
+ }
+ return container !== element && container.contains(element);
+ };
+ } else if (documentElement.compareDocumentPosition) {
+ return function(container, element) {
+ // https://developer.mozilla.org/en/DOM/Node.compareDocumentPosition
+ return !!(container.compareDocumentPosition(element) & 16);
+ };
+ }
+})();
+
+(function(wysihtml) {
+ var doc = document;
+ wysihtml.dom.ContentEditableArea = Base.extend({
+ getContentEditable: function() {
+ return this.element;
+ },
+
+ getWindow: function() {
+ return this.element.ownerDocument.defaultView || this.element.ownerDocument.parentWindow;
+ },
+
+ getDocument: function() {
+ return this.element.ownerDocument;
+ },
+
+ constructor: function(readyCallback, config, contentEditable) {
+ this.callback = readyCallback || wysihtml.EMPTY_FUNCTION;
+ this.config = wysihtml.lang.object({}).merge(config).get();
+ if (!this.config.className) {
+ this.config.className = "wysihtml-sandbox";
+ }
+ if (contentEditable) {
+ this.element = this._bindElement(contentEditable);
+ } else {
+ this.element = this._createElement();
+ }
+ },
+
+ destroy: function() {
+
+ },
+
+ // creates a new contenteditable and initiates it
+ _createElement: function() {
+ var element = doc.createElement("div");
+ element.className = this.config.className;
+ this._loadElement(element);
+ return element;
+ },
+
+ // initiates an allready existent contenteditable
+ _bindElement: function(contentEditable) {
+ contentEditable.className = contentEditable.className ? contentEditable.className + " wysihtml-sandbox" : "wysihtml-sandbox";
+ this._loadElement(contentEditable, true);
+ return contentEditable;
+ },
+
+ _loadElement: function(element, contentExists) {
+ var that = this;
+
+ if (!contentExists) {
+ var innerHtml = this._getHtml();
+ element.innerHTML = innerHtml;
+ }
+
+ this.loaded = true;
+ // Trigger the callback
+ setTimeout(function() { that.callback(that); }, 0);
+ },
+
+ _getHtml: function(templateVars) {
+ return '';
+ }
+
+ });
+})(wysihtml);
+
+/**
+ * Converts an HTML fragment/element into a unordered/ordered list
+ *
+ * @param {Element} element The element which should be turned into a list
+ * @param {String} listType The list type in which to convert the tree (either "ul" or "ol")
+ * @return {Element} The created list
+ *
+ * @example
+ *
+ *
+ * eminem
+ * dr. dre
+ * 50 Cent
+ *
+ *
+ *
+ *
+ *
+ *
+ * eminem
+ * dr. dre
+ * 50 Cent
+ *
+ */
+wysihtml.dom.convertToList = (function() {
+ function _createListItem(doc, list) {
+ var listItem = doc.createElement("li");
+ list.appendChild(listItem);
+ return listItem;
+ }
+
+ function _createList(doc, type) {
+ return doc.createElement(type);
+ }
function convertToList(element, listType, uneditableClass) {
if (element.nodeName === "UL" || element.nodeName === "OL" || element.nodeName === "MENU") {
@@ -7743,25 +7609,25 @@ wysihtml5.dom.convertToList = (function() {
for (i=0; i if empty, otherwise create a new one
currentListItem = currentListItem.firstChild ? _createListItem(doc, list) : currentListItem;
currentListItem.appendChild(childNode);
@@ -7788,7 +7654,8 @@ wysihtml5.dom.convertToList = (function() {
return convertToList;
})();
-;/**
+
+/**
* Copy a set of attributes from one element to another
*
* @param {Array} attributesToCopy List of attributes which should be copied
@@ -7800,10 +7667,10 @@ wysihtml5.dom.convertToList = (function() {
* var textarea = document.querySelector("textarea"),
* div = document.querySelector("div[contenteditable=true]"),
* anotherDiv = document.querySelector("div.preview");
- * wysihtml5.dom.copyAttributes(["spellcheck", "value", "placeholder"]).from(textarea).to(div).andTo(anotherDiv);
+ * wysihtml.dom.copyAttributes(["spellcheck", "value", "placeholder"]).from(textarea).to(div).andTo(anotherDiv);
*
*/
-wysihtml5.dom.copyAttributes = function(attributesToCopy) {
+wysihtml.dom.copyAttributes = function(attributesToCopy) {
return {
from: function(elementToCopyFrom) {
return {
@@ -7823,7 +7690,8 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
}
};
};
-;/**
+
+/**
* Copy a set of styles from one element to another
* Please note that this only works properly across browsers when the element from which to copy the styles
* is in the dom
@@ -7839,7 +7707,7 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
* var textarea = document.querySelector("textarea"),
* div = document.querySelector("div[contenteditable=true]"),
* anotherDiv = document.querySelector("div.preview");
- * wysihtml5.dom.copyStyles(["overflow-y", "width", "height"]).from(textarea).to(div).andTo(anotherDiv);
+ * wysihtml.dom.copyStyles(["overflow-y", "width", "height"]).from(textarea).to(div).andTo(anotherDiv);
*
*/
(function(dom) {
@@ -7874,7 +7742,7 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
return {
from: function(element) {
if (shouldIgnoreBoxSizingBorderBox(element)) {
- stylesToCopy = wysihtml5.lang.array(stylesToCopy).without(BOX_SIZING_PROPERTIES);
+ stylesToCopy = wysihtml.lang.array(stylesToCopy).without(BOX_SIZING_PROPERTIES);
}
var cssText = "",
@@ -7895,17 +7763,18 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
}
};
};
-})(wysihtml5.dom);
-;/**
+})(wysihtml.dom);
+
+/**
* Event Delegation
*
* @example
- * wysihtml5.dom.delegate(document.body, "a", "click", function() {
+ * wysihtml.dom.delegate(document.body, "a", "click", function() {
* // foo
* });
*/
-(function(wysihtml5) {
- wysihtml5.dom.delegate = function(container, selector, eventName, handler) {
+(function(wysihtml) {
+ wysihtml.dom.delegate = function(container, selector, eventName, handler) {
var callback = function(event) {
var target = event.target,
element = (target.nodeType === 3) ? target.parentNode : target, // IE has .contains only seeing elements not textnodes
@@ -7925,9 +7794,10 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
}
};
};
-})(wysihtml5);
-;// TODO: Refactor dom tree traversing here
-(function(wysihtml5) {
+})(wysihtml);
+
+// TODO: Refactor dom tree traversing here
+(function(wysihtml) {
// Finds parents of a node, returning the outermost node first in Array
// if contain node is given parents search is stopped at the container
@@ -7942,15 +7812,15 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
return nodes;
}
- wysihtml5.dom.domNode = function(node) {
- var defaultNodeTypes = [wysihtml5.ELEMENT_NODE, wysihtml5.TEXT_NODE];
+ wysihtml.dom.domNode = function(node) {
+ var defaultNodeTypes = [wysihtml.ELEMENT_NODE, wysihtml.TEXT_NODE];
return {
is: {
emptyTextNode: function(ignoreWhitespace) {
var regx = ignoreWhitespace ? (/^\s*$/g) : (/^[\r\n]*$/g);
- return node && node.nodeType === wysihtml5.TEXT_NODE && (regx).test(node.data);
+ return node && node.nodeType === wysihtml.TEXT_NODE && (regx).test(node.data);
},
// Returns if node is the rangy selection bookmark element (that must not be taken into account in most situatons and is removed on selection restoring)
@@ -7959,7 +7829,7 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
},
visible: function() {
- var isVisible = !(/^\s*$/g).test(wysihtml5.dom.getTextContent(node));
+ var isVisible = !(/^\s*$/g).test(wysihtml.dom.getTextContent(node));
if (!isVisible) {
if (node.nodeType === 1 && node.querySelector('img, br, hr, object, embed, canvas, input, textarea')) {
@@ -7978,13 +7848,13 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
// In most cases browsers should solve the cases for you when you try to insert content into those,
// but IE does not and it is not nice to do so anyway.
voidElement: function() {
- return wysihtml5.dom.domNode(node).test({
- query: wysihtml5.VOID_ELEMENTS
+ return wysihtml.dom.domNode(node).test({
+ query: wysihtml.VOID_ELEMENTS
});
}
},
- // var node = wysihtml5.dom.domNode(element).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
+ // var node = wysihtml.dom.domNode(element).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
prev: function(options) {
var prevNode = node.previousSibling,
types = (options && options.nodeTypes) ? options.nodeTypes : defaultNodeTypes;
@@ -7994,17 +7864,17 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
}
if (
- wysihtml5.dom.domNode(prevNode).is.rangyBookmark() || // is Rangy temporary boomark element (bypass)
- (!wysihtml5.lang.array(types).contains(prevNode.nodeType)) || // nodeTypes check.
- (options && options.ignoreBlankTexts && wysihtml5.dom.domNode(prevNode).is.emptyTextNode(true)) // Blank text nodes bypassed if set
+ wysihtml.dom.domNode(prevNode).is.rangyBookmark() || // is Rangy temporary boomark element (bypass)
+ (!wysihtml.lang.array(types).contains(prevNode.nodeType)) || // nodeTypes check.
+ (options && options.ignoreBlankTexts && wysihtml.dom.domNode(prevNode).is.emptyTextNode(true)) // Blank text nodes bypassed if set
) {
- return wysihtml5.dom.domNode(prevNode).prev(options);
+ return wysihtml.dom.domNode(prevNode).prev(options);
}
return prevNode;
},
- // var node = wysihtml5.dom.domNode(element).next({nodeTypes: [1,3], ignoreBlankTexts: true});
+ // var node = wysihtml.dom.domNode(element).next({nodeTypes: [1,3], ignoreBlankTexts: true});
next: function(options) {
var nextNode = node.nextSibling,
types = (options && options.nodeTypes) ? options.nodeTypes : defaultNodeTypes;
@@ -8014,11 +7884,11 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
}
if (
- wysihtml5.dom.domNode(nextNode).is.rangyBookmark() || // is Rangy temporary boomark element (bypass)
- (!wysihtml5.lang.array(types).contains(nextNode.nodeType)) || // nodeTypes check.
- (options && options.ignoreBlankTexts && wysihtml5.dom.domNode(nextNode).is.emptyTextNode(true)) // blank text nodes bypassed if set
+ wysihtml.dom.domNode(nextNode).is.rangyBookmark() || // is Rangy temporary boomark element (bypass)
+ (!wysihtml.lang.array(types).contains(nextNode.nodeType)) || // nodeTypes check.
+ (options && options.ignoreBlankTexts && wysihtml.dom.domNode(nextNode).is.emptyTextNode(true)) // blank text nodes bypassed if set
) {
- return wysihtml5.dom.domNode(nextNode).next(options);
+ return wysihtml.dom.domNode(nextNode).next(options);
}
return nextNode;
@@ -8027,7 +7897,7 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
// Finds the common acnestor container of two nodes
// If container given stops search at the container
// If no common ancestor found returns null
- // var node = wysihtml5.dom.domNode(element).commonAncestor(node2, container);
+ // var node = wysihtml.dom.domNode(element).commonAncestor(node2, container);
commonAncestor: function(node2, container) {
var parents1 = parents(node, container),
parents2 = parents(node2, container);
@@ -8068,24 +7938,24 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
// Returns if element is of of options.leafClasses leaf
if (options && options.leafClasses) {
for (var i = options.leafClasses.length; i--;) {
- if (wysihtml5.dom.hasClass(node, options.leafClasses[i])) {
+ if (wysihtml.dom.hasClass(node, options.leafClasses[i])) {
return node;
}
}
}
- return wysihtml5.dom.domNode(lastChild).lastLeafNode(options);
+ return wysihtml.dom.domNode(lastChild).lastLeafNode(options);
},
// Splits element at childnode and extracts the childNode out of the element context
// Example:
- // var node = wysihtml5.dom.domNode(node).escapeParent(parentNode);
+ // var node = wysihtml.dom.domNode(node).escapeParent(parentNode);
escapeParent: function(element, newWrapper) {
var parent, split2, nodeWrap,
curNode = node;
// Stop if node is not a descendant of element
- if (!wysihtml5.dom.contains(element, node)) {
+ if (!wysihtml.dom.contains(element, node)) {
throw new Error("Child is not a descendant of node.");
}
@@ -8140,7 +8010,7 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
transferContentTo: function(targetNode, removeOldWrapper) {
if (node.nodeType === 1) {
- if (wysihtml5.dom.domNode(targetNode).is.voidElement() || targetNode.nodeType === 3) {
+ if (wysihtml.dom.domNode(targetNode).is.voidElement() || targetNode.nodeType === 3) {
while (node.lastChild) {
targetNode.parentNode.insertBefore(node.lastChild, targetNode.nextSibling);
}
@@ -8153,7 +8023,7 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
node.parentNode.removeChild(node);
}
} else if (node.nodeType === 3 || node.nodeType === 8){
- if (wysihtml5.dom.domNode(targetNode).is.voidElement()) {
+ if (wysihtml.dom.domNode(targetNode).is.voidElement()) {
targetNode.parentNode.insertBefore(node, targetNode.nextSibling);
} else {
targetNode.appendChild(node);
@@ -8178,12 +8048,12 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
}
Example:
- var node = wysihtml5.dom.domNode(element).test({})
+ var node = wysihtml.dom.domNode(element).test({})
*/
test: function(properties) {
var prop;
- // retuern false if properties object is not defined
+ // return false if properties object is not defined
if (!properties) {
return false;
}
@@ -8221,7 +8091,7 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
styles = (Array.isArray(properties.styleProperty)) ? properties.styleProperty : [properties.styleProperty];
for (var j = 0, maxStyleP = styles.length; j < maxStyleP; j++) {
// Some old IE-s have different property name for cssFloat
- prop = wysihtml5.browser.fixStyleKey(styles[j]);
+ prop = wysihtml.browser.fixStyleKey(styles[j]);
if (node.style[prop]) {
if (properties.styleValue) {
// Style value as additional parameter
@@ -8256,7 +8126,7 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
}
if (properties.attribute) {
- var attr = wysihtml5.dom.getAttributes(node),
+ var attr = wysihtml.dom.getAttributes(node),
attrList = [],
hasOneAttribute = false;
@@ -8291,8 +8161,9 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
};
};
-})(wysihtml5);
-;/**
+})(wysihtml);
+
+/**
* Returns the given html wrapped in a div element
*
* Fixing IE's inability to treat unknown elements (HTML5 section, article, ...) correctly
@@ -8302,9 +8173,9 @@ wysihtml5.dom.copyAttributes = function(attributesToCopy) {
* @param {Obejct} [context] Document object of the context the html belongs to
*
* @example
- * wysihtml5.dom.getAsDom("foo ");
+ * wysihtml.dom.getAsDom("foo ");
*/
-wysihtml5.dom.getAsDom = (function() {
+wysihtml.dom.getAsDom = (function() {
var _innerHTMLShiv = function(html, context) {
var tempElement = context.createElement("div");
@@ -8320,13 +8191,13 @@ wysihtml5.dom.getAsDom = (function() {
* Make sure IE supports HTML5 tags, which is accomplished by simply creating one instance of each element
*/
var _ensureHTML5Compatibility = function(context) {
- if (context._wysihtml5_supportsHTML5Tags) {
+ if (context._wysihtml_supportsHTML5Tags) {
return;
}
for (var i=0, length=HTML5_ELEMENTS.length; i "1" in IE
+ *
+ * Therefore we have to check the element's outerHTML for the attribute
+*/
+
+wysihtml.dom.getAttribute = function(node, attributeName) {
+ var HAS_GET_ATTRIBUTE_BUG = !wysihtml.browser.supportsGetAttributeCorrectly();
+ attributeName = attributeName.toLowerCase();
+ var nodeName = node.nodeName;
+ if (nodeName == "IMG" && attributeName == "src" && wysihtml.dom.isLoadedImage(node) === true) {
+ // Get 'src' attribute value via object property since this will always contain the
+ // full absolute url (http://...)
+ // this fixes a very annoying bug in firefox (ver 3.6 & 4) and IE 8 where images copied from the same host
+ // will have relative paths, which the sanitizer strips out (see attributeCheckMethods.url)
+ return node.src;
+ } else if (HAS_GET_ATTRIBUTE_BUG && "outerHTML" in node) {
+ // Don't trust getAttribute/hasAttribute in IE 6-8, instead check the element's outerHTML
+ var outerHTML = node.outerHTML.toLowerCase(),
+ // TODO: This might not work for attributes without value:
+ hasAttribute = outerHTML.indexOf(" " + attributeName + "=") != -1;
+
+ return hasAttribute ? node.getAttribute(attributeName) : null;
+ } else{
+ return node.getAttribute(attributeName);
+ }
+};
+
+/**
+ * Get all attributes of an element
+ *
+ * IE gives wrong results for hasAttribute/getAttribute, for example:
+ * var td = document.createElement("td");
+ * td.getAttribute("rowspan"); // => "1" in IE
+ *
+ * Therefore we have to check the element's outerHTML for the attribute
+*/
+
+wysihtml.dom.getAttributes = function(node) {
+ var HAS_GET_ATTRIBUTE_BUG = !wysihtml.browser.supportsGetAttributeCorrectly(),
+ nodeName = node.nodeName,
+ attributes = [],
+ attr;
+
+ for (attr in node.attributes) {
+ if ((node.attributes.hasOwnProperty && node.attributes.hasOwnProperty(attr)) || (!node.attributes.hasOwnProperty && Object.prototype.hasOwnProperty.call(node.attributes, attr))) {
+ if (node.attributes[attr].specified) {
+ if (nodeName == "IMG" && node.attributes[attr].name.toLowerCase() == "src" && wysihtml.dom.isLoadedImage(node) === true) {
+ attributes['src'] = node.src;
+ } else if (wysihtml.lang.array(['rowspan', 'colspan']).contains(node.attributes[attr].name.toLowerCase()) && HAS_GET_ATTRIBUTE_BUG) {
+ if (node.attributes[attr].value !== 1) {
+ attributes[node.attributes[attr].name] = node.attributes[attr].value;
+ }
+ } else {
+ attributes[node.attributes[attr].name] = node.attributes[attr].value;
+ }
+ }
+ }
+ }
+ return attributes;
+};
+
+/**
* Walks the dom tree from the given node up until it finds a match
*
* @param {Element} node The from which to check the parent nodes
@@ -8373,12 +8311,12 @@ wysihtml5.dom.getAsDom = (function() {
* @return {null|Element} Returns the first element that matched the desiredNodeName(s)
*/
-wysihtml5.dom.getParentElement = (function() {
+wysihtml.dom.getParentElement = (function() {
return function(node, properties, levels, container) {
levels = levels || 50;
while (levels-- && node && node.nodeName !== "BODY" && (!container || node !== container)) {
- if (wysihtml5.dom.domNode(node).test(properties)) {
+ if (wysihtml.dom.domNode(node).test(properties)) {
return node;
}
node = node.parentNode;
@@ -8387,32 +8325,85 @@ wysihtml5.dom.getParentElement = (function() {
};
})();
-;/**
- * Get element's style for a specific css property
- *
- * @param {Element} element The element on which to retrieve the style
- * @param {String} property The CSS property to retrieve ("float", "display", "text-align", ...)
- *
- * @example
- * wysihtml5.dom.getStyle("display").from(document.body);
- * // => "block"
- */
-wysihtml5.dom.getStyle = (function() {
- var stylePropertyMapping = {
- "float": ("styleFloat" in document.createElement("div").style) ? "styleFloat" : "cssFloat"
- },
- REG_EXP_CAMELIZE = /\-[a-z]/g;
- function camelize(str) {
- return str.replace(REG_EXP_CAMELIZE, function(match) {
- return match.charAt(1).toUpperCase();
- });
+/*
+ * Methods for fetching pasted html before it gets inserted into content
+**/
+
+/* Modern event.clipboardData driven approach.
+ * Advantage is that it does not have to loose selection or modify dom to catch the data.
+ * IE does not support though.
+**/
+wysihtml.dom.getPastedHtml = function(event) {
+ var html;
+ if (wysihtml.browser.supportsModernPaste() && event.clipboardData) {
+ if (wysihtml.lang.array(event.clipboardData.types).contains('text/html')) {
+ html = event.clipboardData.getData('text/html');
+ } else if (wysihtml.lang.array(event.clipboardData.types).contains('text/plain')) {
+ html = wysihtml.lang.string(event.clipboardData.getData('text/plain')).escapeHTML(true, true);
+ }
}
+ return html;
+};
- return function(property) {
+/* Older temprorary contenteditable as paste source catcher method for fallbacks */
+wysihtml.dom.getPastedHtmlWithDiv = function (composer, f) {
+ var selBookmark = composer.selection.getBookmark(),
+ doc = composer.element.ownerDocument,
+ cleanerDiv = doc.createElement('DIV'),
+ scrollPos = composer.getScrollPos();
+
+ doc.body.appendChild(cleanerDiv);
+
+ cleanerDiv.style.width = "1px";
+ cleanerDiv.style.height = "1px";
+ cleanerDiv.style.overflow = "hidden";
+ cleanerDiv.style.position = "absolute";
+ cleanerDiv.style.top = scrollPos.y + "px";
+ cleanerDiv.style.left = scrollPos.x + "px";
+
+ cleanerDiv.setAttribute('contenteditable', 'true');
+ cleanerDiv.focus();
+
+ setTimeout(function () {
+ var html;
+
+ composer.selection.setBookmark(selBookmark);
+ html = cleanerDiv.innerHTML;
+ if (html && (/^ $/i).test(html.trim())) {
+ html = false;
+ }
+ f(html);
+ cleanerDiv.parentNode.removeChild(cleanerDiv);
+ }, 0);
+};
+
+/**
+ * Get element's style for a specific css property
+ *
+ * @param {Element} element The element on which to retrieve the style
+ * @param {String} property The CSS property to retrieve ("float", "display", "text-align", ...)
+ *
+ * @example
+ * wysihtml.dom.getStyle("display").from(document.body);
+ * // => "block"
+ */
+wysihtml.dom.getStyle = (function() {
+ var stylePropertyMapping = {
+ "float": ("styleFloat" in document.createElement("div").style) ? "styleFloat" : "cssFloat"
+ },
+ REG_EXP_CAMELIZE = /\-[a-z]/g;
+
+ function camelize(str) {
+ return str.replace(REG_EXP_CAMELIZE, function(match) {
+ return match.charAt(1).toUpperCase();
+ });
+ }
+
+ return function(property) {
return {
from: function(element) {
- if (element.nodeType !== wysihtml5.ELEMENT_NODE) {
+ if (element.nodeType !== wysihtml.ELEMENT_NODE) {
return;
}
@@ -8460,7 +8451,8 @@ wysihtml5.dom.getStyle = (function() {
};
};
})();
-;wysihtml5.dom.getTextNodes = function(node, ingoreEmpty){
+
+wysihtml.dom.getTextNodes = function(node, ingoreEmpty){
var all = [];
for (node=node.firstChild;node;node=node.nextSibling){
if (node.nodeType == 3) {
@@ -8468,74 +8460,77 @@ wysihtml5.dom.getStyle = (function() {
all.push(node);
}
} else {
- all = all.concat(wysihtml5.dom.getTextNodes(node, ingoreEmpty));
+ all = all.concat(wysihtml.dom.getTextNodes(node, ingoreEmpty));
}
}
return all;
};
-;/**
- * High performant way to check whether an element with a specific tag name is in the given document
+
+/**
+ * High performant way to check whether an element with a specific class name is in the given document
* Optimized for being heavily executed
* Unleashes the power of live node lists
*
* @param {Object} doc The document object of the context where to check
* @param {String} tagName Upper cased tag name
* @example
- * wysihtml5.dom.hasElementWithTagName(document, "IMG");
+ * wysihtml.dom.hasElementWithClassName(document, "foobar");
*/
-wysihtml5.dom.hasElementWithTagName = (function() {
+(function(wysihtml) {
var LIVE_CACHE = {},
DOCUMENT_IDENTIFIER = 1;
function _getDocumentIdentifier(doc) {
- return doc._wysihtml5_identifier || (doc._wysihtml5_identifier = DOCUMENT_IDENTIFIER++);
+ return doc._wysihtml_identifier || (doc._wysihtml_identifier = DOCUMENT_IDENTIFIER++);
}
- return function(doc, tagName) {
- var key = _getDocumentIdentifier(doc) + ":" + tagName,
+ wysihtml.dom.hasElementWithClassName = function(doc, className) {
+ // getElementsByClassName is not supported by IE<9
+ // but is sometimes mocked via library code (which then doesn't return live node lists)
+ if (!wysihtml.browser.supportsNativeGetElementsByClassName()) {
+ return !!doc.querySelector("." + className);
+ }
+
+ var key = _getDocumentIdentifier(doc) + ":" + className,
cacheEntry = LIVE_CACHE[key];
if (!cacheEntry) {
- cacheEntry = LIVE_CACHE[key] = doc.getElementsByTagName(tagName);
+ cacheEntry = LIVE_CACHE[key] = doc.getElementsByClassName(className);
}
return cacheEntry.length > 0;
};
-})();
-;/**
- * High performant way to check whether an element with a specific class name is in the given document
+})(wysihtml);
+
+/**
+ * High performant way to check whether an element with a specific tag name is in the given document
* Optimized for being heavily executed
* Unleashes the power of live node lists
*
* @param {Object} doc The document object of the context where to check
* @param {String} tagName Upper cased tag name
* @example
- * wysihtml5.dom.hasElementWithClassName(document, "foobar");
+ * wysihtml.dom.hasElementWithTagName(document, "IMG");
*/
-(function(wysihtml5) {
+wysihtml.dom.hasElementWithTagName = (function() {
var LIVE_CACHE = {},
DOCUMENT_IDENTIFIER = 1;
function _getDocumentIdentifier(doc) {
- return doc._wysihtml5_identifier || (doc._wysihtml5_identifier = DOCUMENT_IDENTIFIER++);
+ return doc._wysihtml_identifier || (doc._wysihtml_identifier = DOCUMENT_IDENTIFIER++);
}
- wysihtml5.dom.hasElementWithClassName = function(doc, className) {
- // getElementsByClassName is not supported by IE<9
- // but is sometimes mocked via library code (which then doesn't return live node lists)
- if (!wysihtml5.browser.supportsNativeGetElementsByClassName()) {
- return !!doc.querySelector("." + className);
- }
-
- var key = _getDocumentIdentifier(doc) + ":" + className,
+ return function(doc, tagName) {
+ var key = _getDocumentIdentifier(doc) + ":" + tagName,
cacheEntry = LIVE_CACHE[key];
if (!cacheEntry) {
- cacheEntry = LIVE_CACHE[key] = doc.getElementsByClassName(className);
+ cacheEntry = LIVE_CACHE[key] = doc.getElementsByTagName(tagName);
}
return cacheEntry.length > 0;
};
-})(wysihtml5);
-;wysihtml5.dom.insert = function(elementToInsert) {
+})();
+
+wysihtml.dom.insert = function(elementToInsert) {
return {
after: function(element) {
element.parentNode.insertBefore(elementToInsert, element.nextSibling);
@@ -8550,7 +8545,8 @@ wysihtml5.dom.hasElementWithTagName = (function() {
}
};
};
-;wysihtml5.dom.insertCSS = function(rules) {
+
+wysihtml.dom.insertCSS = function(rules) {
rules = rules.join("\n");
return {
@@ -8577,9 +8573,25 @@ wysihtml5.dom.hasElementWithTagName = (function() {
}
};
};
-;// TODO: Refactor dom tree traversing here
-(function(wysihtml5) {
- wysihtml5.dom.lineBreaks = function(node) {
+
+/**
+ * Check whether the given node is a proper loaded image
+ * FIXME: Returns undefined when unknown (Chrome, Safari)
+*/
+
+wysihtml.dom.isLoadedImage = function (node) {
+ try {
+ return node.complete && !node.mozMatchesSelector(":-moz-broken");
+ } catch(e) {
+ if (node.complete && node.readyState === "complete") {
+ return true;
+ }
+ }
+};
+
+// TODO: Refactor dom tree traversing here
+(function(wysihtml) {
+ wysihtml.dom.lineBreaks = function(node) {
function _isLineBreak(n) {
return n.nodeName === "BR";
@@ -8594,7 +8606,7 @@ wysihtml5.dom.hasElementWithTagName = (function() {
return true;
}
- if (wysihtml5.dom.getStyle("display").from(element) === "block") {
+ if (wysihtml.dom.getStyle("display").from(element) === "block") {
return true;
}
@@ -8603,31 +8615,31 @@ wysihtml5.dom.hasElementWithTagName = (function() {
return {
- /* wysihtml5.dom.lineBreaks(element).add();
+ /* wysihtml.dom.lineBreaks(element).add();
*
* Adds line breaks before and after the given node if the previous and next siblings
* aren't already causing a visual line break (block element or )
*/
add: function(options) {
var doc = node.ownerDocument,
- nextSibling = wysihtml5.dom.domNode(node).next({ignoreBlankTexts: true}),
- previousSibling = wysihtml5.dom.domNode(node).prev({ignoreBlankTexts: true});
+ nextSibling = wysihtml.dom.domNode(node).next({ignoreBlankTexts: true}),
+ previousSibling = wysihtml.dom.domNode(node).prev({ignoreBlankTexts: true});
if (nextSibling && !_isLineBreakOrBlockElement(nextSibling)) {
- wysihtml5.dom.insert(doc.createElement("br")).after(node);
+ wysihtml.dom.insert(doc.createElement("br")).after(node);
}
if (previousSibling && !_isLineBreakOrBlockElement(previousSibling)) {
- wysihtml5.dom.insert(doc.createElement("br")).before(node);
+ wysihtml.dom.insert(doc.createElement("br")).before(node);
}
},
- /* wysihtml5.dom.lineBreaks(element).remove();
+ /* wysihtml.dom.lineBreaks(element).remove();
*
* Removes line breaks before and after the given node
*/
remove: function(options) {
- var nextSibling = wysihtml5.dom.domNode(node).next({ignoreBlankTexts: true}),
- previousSibling = wysihtml5.dom.domNode(node).prev({ignoreBlankTexts: true});
+ var nextSibling = wysihtml.dom.domNode(node).next({ignoreBlankTexts: true}),
+ previousSibling = wysihtml.dom.domNode(node).prev({ignoreBlankTexts: true});
if (nextSibling && _isLineBreak(nextSibling)) {
nextSibling.parentNode.removeChild(nextSibling);
@@ -8638,13 +8650,14 @@ wysihtml5.dom.hasElementWithTagName = (function() {
}
};
};
-})(wysihtml5);;/**
+})(wysihtml);
+/**
* Method to set dom events
*
* @example
- * wysihtml5.dom.observe(iframe.contentWindow.document.body, ["focus", "blur"], function() { ... });
+ * wysihtml.dom.observe(iframe.contentWindow.document.body, ["focus", "blur"], function() { ... });
*/
-wysihtml5.dom.observe = function(element, eventNames, handler) {
+wysihtml.dom.observe = function(element, eventNames, handler) {
eventNames = typeof(eventNames) === "string" ? [eventNames] : eventNames;
var handlerWrapper,
@@ -8689,7 +8702,8 @@ wysihtml5.dom.observe = function(element, eventNames, handler) {
}
};
};
-;/**
+
+/**
* HTML Sanitizer
* Rewrites the HTML based on given rules
*
@@ -8703,7 +8717,7 @@ wysihtml5.dom.observe = function(element, eventNames, handler) {
*
* @example
* var userHTML = '';
- * wysihtml5.dom.parse(userHTML, {
+ * wysihtml.dom.parse(userHTML, {
* tags {
* p: "div", // Rename p tags to div tags
* font: "span" // Rename font tags to span tags
@@ -8714,11 +8728,11 @@ wysihtml5.dom.observe = function(element, eventNames, handler) {
* // =>
*
* var userHTML = '';
- * wysihtml5.dom.parse(userHTML);
+ * wysihtml.dom.parse(userHTML);
* // => 'I'm a table! '
*
* var userHTML = 'foobar foobar
';
- * wysihtml5.dom.parse(userHTML, {
+ * wysihtml.dom.parse(userHTML, {
* tags: {
* div: undefined,
* br: true
@@ -8727,7 +8741,7 @@ wysihtml5.dom.observe = function(element, eventNames, handler) {
* // => ''
*
* var userHTML = 'foo
bar
';
- * wysihtml5.dom.parse(userHTML, {
+ * wysihtml.dom.parse(userHTML, {
* classes: {
* red: 1,
* green: 1
@@ -8741,7 +8755,7 @@ wysihtml5.dom.observe = function(element, eventNames, handler) {
* // => 'foo
bar
'
*/
-wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
+wysihtml.dom.parse = function(elementOrHtml_current, config_current) {
/* TODO: Currently escaped module pattern as otherwise folloowing default swill be shared among multiple editors.
* Refactor whole code as this method while workind is kind of awkward too */
@@ -8771,7 +8785,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
* which later replaces the entire body content
*/
function parse(elementOrHtml, config) {
- wysihtml5.lang.object(currentRules).merge(defaultRules).merge(config.rules).get();
+ wysihtml.lang.object(currentRules).merge(defaultRules).merge(config.rules).get();
var context = config.context || elementOrHtml.ownerDocument || document,
fragment = context.createDocumentFragment(),
@@ -8786,7 +8800,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
}
if (isString) {
- element = wysihtml5.dom.getAsDom(elementOrHtml, context);
+ element = wysihtml.dom.getAsDom(elementOrHtml, context);
} else {
element = elementOrHtml;
}
@@ -8808,7 +8822,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
if (config.unjoinNbsps) {
// replace joined non-breakable spaces with unjoined
- var txtnodes = wysihtml5.dom.getTextNodes(fragment);
+ var txtnodes = wysihtml.dom.getTextNodes(fragment);
for (var n = txtnodes.length; n--;) {
txtnodes[n].nodeValue = txtnodes[n].nodeValue.replace(/([\S\u00A0])\u00A0/gi, "$1 ");
}
@@ -8820,7 +8834,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
// Insert new DOM tree
element.appendChild(fragment);
- return isString ? wysihtml5.quirks.getCorrectInnerHTML(element) : element;
+ return isString ? wysihtml.quirks.getCorrectInnerHTML(element) : element;
}
function _convert(oldNode, cleanUp, clearInternals, uneditableClass) {
@@ -8835,7 +8849,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
nodeDisplay;
// Passes directly elemets with uneditable class
- if (uneditableClass && oldNodeType === 1 && wysihtml5.dom.hasClass(oldNode, uneditableClass)) {
+ if (uneditableClass && oldNodeType === 1 && wysihtml.dom.hasClass(oldNode, uneditableClass)) {
return oldNode;
}
@@ -8859,18 +8873,18 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
}
}
- nodeDisplay = wysihtml5.dom.getStyle("display").from(oldNode);
+ nodeDisplay = wysihtml.dom.getStyle("display").from(oldNode);
if (nodeDisplay === '') {
// Handle display style when element not in dom
- nodeDisplay = wysihtml5.lang.array(blockElements).contains(oldNode.tagName) ? "block" : "";
+ nodeDisplay = wysihtml.lang.array(blockElements).contains(oldNode.tagName) ? "block" : "";
}
- if (wysihtml5.lang.array(["block", "flex", "table"]).contains(nodeDisplay)) {
+ if (wysihtml.lang.array(["block", "flex", "table"]).contains(nodeDisplay)) {
fragment.appendChild(oldNode.ownerDocument.createElement("br"));
}
// TODO: try to minimize surplus spaces
- if (wysihtml5.lang.array([
+ if (wysihtml.lang.array([
"div", "pre", "p",
"table", "td", "th",
"ul", "ol", "li",
@@ -8911,7 +8925,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
if (cleanUp &&
newNode.nodeName.toLowerCase() === DEFAULT_NODE_NAME &&
(!newNode.childNodes.length ||
- ((/^\s*$/gi).test(newNode.innerHTML) && (clearInternals || (oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary"))) ||
+ ((/^\s*$/gi).test(newNode.innerHTML) && (clearInternals || (oldNode.className !== "_wysihtml-temp-placeholder" && oldNode.className !== "rangySelectionBoundary"))) ||
!newNode.attributes.length)
) {
fragment = newNode.ownerDocument.createDocumentFragment();
@@ -8935,7 +8949,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
for (sel in selectorRules) {
if (selectorRules.hasOwnProperty(sel)) {
- if (wysihtml5.lang.object(selectorRules[sel]).isFunction()) {
+ if (wysihtml.lang.object(selectorRules[sel]).isFunction()) {
method = selectorRules[sel];
} else if (typeof(selectorRules[sel]) === "string" && elementHandlingMethods[selectorRules[sel]]) {
method = elementHandlingMethods[selectorRules[sel]];
@@ -8960,12 +8974,12 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
* We already parsed that element
* ignore it! (yes, this sometimes happens in IE8 when the html is invalid)
*/
- if (oldNode._wysihtml5) {
+ if (oldNode._wysihtml) {
return null;
}
- oldNode._wysihtml5 = 1;
+ oldNode._wysihtml = 1;
- if (oldNode.className === "wysihtml5-temp") {
+ if (oldNode.className === "wysihtml-temp") {
return null;
}
@@ -8984,7 +8998,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
* A doesn't need to be closed according HTML4-5 spec, we simply replace it with a
to preserve its content and layout
*/
if ("outerHTML" in oldNode) {
- if (!wysihtml5.browser.autoClosesUnclosedTags() &&
+ if (!wysihtml.browser.autoClosesUnclosedTags() &&
oldNode.nodeName === "P" &&
oldNode.outerHTML.slice(-4).toLowerCase() !== "") {
nodeName = "div";
@@ -9035,7 +9049,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
var definition, type;
// do not interfere with placeholder span or pasting caret position is not maintained
- if (oldNode.nodeName === "SPAN" && !clearInternals && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
+ if (oldNode.nodeName === "SPAN" && !clearInternals && (oldNode.className === "_wysihtml-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
return true;
}
@@ -9099,7 +9113,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
styleProp = nodeStyles[sp].split(':');
if (styleProp[0].replace(/\s/g, '').toLowerCase() === s) {
- if (definition.styles[s] === true || definition.styles[s] === 1 || wysihtml5.lang.array(definition.styles[s]).contains(styleProp[1].replace(/\s/g, '').toLowerCase()) ) {
+ if (definition.styles[s] === true || definition.styles[s] === 1 || wysihtml.lang.array(definition.styles[s]).contains(styleProp[1].replace(/\s/g, '').toLowerCase()) ) {
return true;
}
}
@@ -9112,7 +9126,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
if (definition.attrs) {
for (a in definition.attrs) {
if (definition.attrs.hasOwnProperty(a)) {
- attr = wysihtml5.dom.getAttribute(oldNode, a);
+ attr = wysihtml.dom.getAttribute(oldNode, a);
if (typeof(attr) === "string") {
if (attr.search(definition.attrs[a]) > -1) {
return true;
@@ -9156,7 +9170,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
}
function _checkAttribute(attributeName, attributeValue, methodName, nodeName) {
- var method = wysihtml5.lang.object(methodName).isFunction() ? methodName : attributeCheckMethods[methodName],
+ var method = wysihtml.lang.object(methodName).isFunction() ? methodName : attributeCheckMethods[methodName],
newAttributeValue;
if (method) {
@@ -9170,10 +9184,10 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
}
function _checkAttributes(oldNode, local_attributes) {
- var globalAttributes = wysihtml5.lang.object(currentRules.attributes || {}).clone(), // global values for check/convert values of attributes
- checkAttributes = wysihtml5.lang.object(globalAttributes).merge( wysihtml5.lang.object(local_attributes || {}).clone()).get(),
+ var globalAttributes = wysihtml.lang.object(currentRules.attributes || {}).clone(), // global values for check/convert values of attributes
+ checkAttributes = wysihtml.lang.object(globalAttributes).merge( wysihtml.lang.object(local_attributes || {}).clone()).get(),
attributes = {},
- oldAttributes = wysihtml5.dom.getAttributes(oldNode),
+ oldAttributes = wysihtml.dom.getAttributes(oldNode),
attributeName, newValue, matchingAttributes;
for (attributeName in checkAttributes) {
@@ -9219,11 +9233,11 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
method;
if (setAttributes) {
- attributes = wysihtml5.lang.object(setAttributes).clone();
+ attributes = wysihtml.lang.object(setAttributes).clone();
}
// check/convert values of attributes
- attributes = wysihtml5.lang.object(attributes).merge(_checkAttributes(oldNode, rule.check_attributes)).get();
+ attributes = wysihtml.lang.object(attributes).merge(_checkAttributes(oldNode, rule.check_attributes)).get();
if (setClass) {
classes.push(setClass);
@@ -9235,7 +9249,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
if (!method) {
continue;
}
- newClass = method(wysihtml5.dom.getAttribute(oldNode, attributeName));
+ newClass = method(wysihtml.dom.getAttribute(oldNode, attributeName));
if (typeof(newClass) === "string") {
classes.push(newClass);
}
@@ -9249,7 +9263,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
continue;
}
- newStyle = method(wysihtml5.dom.getAttribute(oldNode, attributeName));
+ newStyle = method(wysihtml.dom.getAttribute(oldNode, attributeName));
if (typeof(newStyle) === "string") {
styles.push(newStyle);
}
@@ -9274,7 +9288,7 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
}
if (newClasses.length) {
- attributes["class"] = wysihtml5.lang.array(newClasses).unique().join(" ");
+ attributes["class"] = wysihtml.lang.array(newClasses).unique().join(" ");
}
} else {
@@ -9282,13 +9296,13 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
}
} else {
if(classes && classes.length > 0) {
- attributes["class"] = wysihtml5.lang.array(classes).unique().join(" ");
+ attributes["class"] = wysihtml.lang.array(classes).unique().join(" ");
}
}
} else {
- // make sure that wysihtml5 temp class doesn't get stripped out
+ // make sure that wysihtml temp class doesn't get stripped out
if (!clearInternals) {
- allowedClasses["_wysihtml5-temp-placeholder"] = 1;
+ allowedClasses["_wysihtml-temp-placeholder"] = 1;
allowedClasses["_rangySelectionBoundary"] = 1;
allowedClasses["wysiwyg-tmp-selected-cell"] = 1;
}
@@ -9296,2010 +9310,888 @@ wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
// add old classes last
oldClasses = oldNode.getAttribute("class");
if (oldClasses) {
- classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
- }
- classesLength = classes.length;
- for (; i
under https when it's new attribute value is non-https
- // TODO: Investigate this further and check for smarter handling
- try {
- newNode.setAttribute(attributeName, attributes[attributeName]);
- } catch(e) {}
- }
-
- // IE8 sometimes loses the width/height attributes when those are set before the "src"
- // so we make sure to set them again
- if (attributes.src) {
- if (typeof(attributes.width) !== "undefined") {
- newNode.setAttribute("width", attributes.width);
- }
- if (typeof(attributes.height) !== "undefined") {
- newNode.setAttribute("height", attributes.height);
- }
- }
- }
-
- function _handleText(oldNode) {
- var nextSibling = oldNode.nextSibling;
- if (nextSibling && nextSibling.nodeType === wysihtml5.TEXT_NODE) {
- // Concatenate text nodes
- nextSibling.data = oldNode.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "") + nextSibling.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
- } else {
- // \uFEFF = wysihtml5.INVISIBLE_SPACE (used as a hack in certain rich text editing situations)
- var data = oldNode.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
- return oldNode.ownerDocument.createTextNode(data);
- }
- }
-
- function _handleComment(oldNode) {
- if (currentRules.comments) {
- return oldNode.ownerDocument.createComment(oldNode.nodeValue);
- }
- }
-
- // ------------ attribute checks ------------ \\
- var attributeCheckMethods = {
- url: (function() {
- var REG_EXP = /^https?:\/\//i;
- return function(attributeValue) {
- if (!attributeValue || !attributeValue.match(REG_EXP)) {
- return null;
- }
- return attributeValue.replace(REG_EXP, function(match) {
- return match.toLowerCase();
- });
- };
- })(),
-
- src: (function() {
- var REG_EXP = /^(\/|https?:\/\/)/i;
- return function(attributeValue) {
- if (!attributeValue || !attributeValue.match(REG_EXP)) {
- return null;
- }
- return attributeValue.replace(REG_EXP, function(match) {
- return match.toLowerCase();
- });
- };
- })(),
-
- href: (function() {
- var REG_EXP = /^(#|\/|https?:\/\/|mailto:|tel:)/i;
- return function(attributeValue) {
- if (!attributeValue || !attributeValue.match(REG_EXP)) {
- return null;
- }
- return attributeValue.replace(REG_EXP, function(match) {
- return match.toLowerCase();
- });
- };
- })(),
-
- alt: (function() {
- var REG_EXP = /[^ a-z0-9_\-]/gi;
- return function(attributeValue, nodeName) {
- if (!attributeValue) {
- if (nodeName === "IMG") {
- return "";
- } else {
- return null;
- }
- }
- return attributeValue.replace(REG_EXP, "");
- };
- })(),
-
- // Integers. Does not work with floating point numbers and units
- numbers: (function() {
- var REG_EXP = /\D/g;
- return function(attributeValue) {
- attributeValue = (attributeValue || "").replace(REG_EXP, "");
- return attributeValue || null;
- };
- })(),
-
- // Useful for with/height attributes where floating points and percentages are allowed
- dimension: (function() {
- var REG_EXP = /\D*(\d+)(\.\d+)?\s?(%)?\D*/;
- return function(attributeValue) {
- attributeValue = (attributeValue || "").replace(REG_EXP, "$1$2$3");
- return attributeValue || null;
- };
- })(),
-
- any: (function() {
- return function(attributeValue) {
- if (!attributeValue) {
- return null;
- }
- return attributeValue;
- };
- })()
- };
-
- // ------------ style converter (converts an html attribute to a style) ------------ \\
- var addStyleMethods = {
- align_text: (function() {
- var mapping = {
- left: "text-align: left;",
- right: "text-align: right;",
- center: "text-align: center;"
- };
- return function(attributeValue) {
- return mapping[String(attributeValue).toLowerCase()];
- };
- })(),
- };
-
- // ------------ class converter (converts an html attribute to a class name) ------------ \\
- var addClassMethods = {
- align_img: (function() {
- var mapping = {
- left: "wysiwyg-float-left",
- right: "wysiwyg-float-right"
- };
- return function(attributeValue) {
- return mapping[String(attributeValue).toLowerCase()];
- };
- })(),
-
- align_text: (function() {
- var mapping = {
- left: "wysiwyg-text-align-left",
- right: "wysiwyg-text-align-right",
- center: "wysiwyg-text-align-center",
- justify: "wysiwyg-text-align-justify"
- };
- return function(attributeValue) {
- return mapping[String(attributeValue).toLowerCase()];
- };
- })(),
-
- clear_br: (function() {
- var mapping = {
- left: "wysiwyg-clear-left",
- right: "wysiwyg-clear-right",
- both: "wysiwyg-clear-both",
- all: "wysiwyg-clear-both"
- };
- return function(attributeValue) {
- return mapping[String(attributeValue).toLowerCase()];
- };
- })(),
-
- size_font: (function() {
- var mapping = {
- "1": "wysiwyg-font-size-xx-small",
- "2": "wysiwyg-font-size-small",
- "3": "wysiwyg-font-size-medium",
- "4": "wysiwyg-font-size-large",
- "5": "wysiwyg-font-size-x-large",
- "6": "wysiwyg-font-size-xx-large",
- "7": "wysiwyg-font-size-xx-large",
- "-": "wysiwyg-font-size-smaller",
- "+": "wysiwyg-font-size-larger"
- };
- return function(attributeValue) {
- return mapping[String(attributeValue).charAt(0)];
- };
- })()
- };
-
- // checks if element is possibly visible
- var typeCeckMethods = {
- has_visible_contet: (function() {
- var txt,
- isVisible = false,
- visibleElements = ['img', 'video', 'picture', 'br', 'script', 'noscript',
- 'style', 'table', 'iframe', 'object', 'embed', 'audio',
- 'svg', 'input', 'button', 'select','textarea', 'canvas'];
-
- return function(el) {
-
- // has visible innertext. so is visible
- txt = (el.innerText || el.textContent).replace(/\s/g, '');
- if (txt && txt.length > 0) {
- return true;
- }
-
- // matches list of visible dimensioned elements
- for (var i = visibleElements.length; i--;) {
- if (el.querySelector(visibleElements[i])) {
- return true;
- }
- }
-
- // try to measure dimesions in last resort. (can find only of elements in dom)
- if (el.offsetWidth && el.offsetWidth > 0 && el.offsetHeight && el.offsetHeight > 0) {
- return true;
- }
-
- return false;
- };
- })()
- };
-
- var elementHandlingMethods = {
- unwrap: function (element) {
- wysihtml5.dom.unwrap(element);
- },
-
- remove: function (element) {
- element.parentNode.removeChild(element);
- }
- };
-
- return parse(elementOrHtml_current, config_current);
-};
-;/**
- * Checks for empty text node childs and removes them
- *
- * @param {Element} node The element in which to cleanup
- * @example
- * wysihtml5.dom.removeEmptyTextNodes(element);
- */
-wysihtml5.dom.removeEmptyTextNodes = function(node) {
- var childNode,
- childNodes = wysihtml5.lang.array(node.childNodes).get(),
- childNodesLength = childNodes.length,
- i = 0;
-
- for (; i to a ) and keeps its childs
- *
- * @param {Element} element The list element which should be renamed
- * @param {Element} newNodeName The desired tag name
- *
- * @example
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- *
- *
- *
- *
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- *
- */
-wysihtml5.dom.renameElement = function(element, newNodeName) {
- var newElement = element.ownerDocument.createElement(newNodeName),
- firstChild;
- while (firstChild = element.firstChild) {
- newElement.appendChild(firstChild);
- }
- wysihtml5.dom.copyAttributes(["align", "className"]).from(element).to(newElement);
-
- if (element.parentNode) {
- element.parentNode.replaceChild(newElement, element);
- }
-
- return newElement;
-};
-;/**
- * Takes an element, removes it and replaces it with it's childs
- *
- * @param {Object} node The node which to replace with it's child nodes
- * @example
- *
- * hello
- *
- *
- */
-wysihtml5.dom.replaceWithChildNodes = function(node) {
- if (!node.parentNode) {
- return;
- }
-
- while (node.firstChild) {
- node.parentNode.insertBefore(node.firstChild, node);
- }
- node.parentNode.removeChild(node);
-};
-;/**
- * Unwraps an unordered/ordered list
- *
- * @param {Element} element The list element which should be unwrapped
- *
- * @example
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- *
- *
- *
- *
- *
- * eminem
- * dr. dre
- * 50 Cent
- */
-(function(dom) {
- function _isBlockElement(node) {
- return dom.getStyle("display").from(node) === "block";
- }
-
- function _isLineBreak(node) {
- return node.nodeName === "BR";
- }
-
- function _appendLineBreak(element) {
- var lineBreak = element.ownerDocument.createElement("br");
- element.appendChild(lineBreak);
- }
-
- function resolveList(list, useLineBreaks) {
- if (!list.nodeName.match(/^(MENU|UL|OL)$/)) {
- return;
- }
-
- var doc = list.ownerDocument,
- fragment = doc.createDocumentFragment(),
- previousSibling = wysihtml5.dom.domNode(list).prev({ignoreBlankTexts: true}),
- nextSibling = wysihtml5.dom.domNode(list).next({ignoreBlankTexts: true}),
- firstChild,
- lastChild,
- isLastChild,
- shouldAppendLineBreak,
- paragraph,
- listItem,
- lastListItem = list.lastElementChild || list.lastChild,
- isLastItem;
-
- if (useLineBreaks) {
- // Insert line break if list is after a non-block element
- if (previousSibling && !_isBlockElement(previousSibling) && !_isLineBreak(previousSibling)) {
- _appendLineBreak(fragment);
- }
-
- while (listItem = (list.firstElementChild || list.firstChild)) {
- lastChild = listItem.lastChild;
- isLastItem = listItem === lastListItem;
- while (firstChild = listItem.firstChild) {
- isLastChild = firstChild === lastChild;
- // This needs to be done before appending it to the fragment, as it otherwise will lose style information
- shouldAppendLineBreak = (!isLastItem || (nextSibling && !_isBlockElement(nextSibling))) && isLastChild && !_isBlockElement(firstChild) && !_isLineBreak(firstChild);
- fragment.appendChild(firstChild);
- if (shouldAppendLineBreak) {
- _appendLineBreak(fragment);
- }
- }
-
- listItem.parentNode.removeChild(listItem);
- }
- } else {
- while (listItem = (list.firstElementChild || list.firstChild)) {
- if (listItem.querySelector && listItem.querySelector("div, p, ul, ol, menu, blockquote, h1, h2, h3, h4, h5, h6")) {
- while (firstChild = listItem.firstChild) {
- fragment.appendChild(firstChild);
- }
- } else {
- paragraph = doc.createElement("p");
- while (firstChild = listItem.firstChild) {
- paragraph.appendChild(firstChild);
- }
- fragment.appendChild(paragraph);
- }
- listItem.parentNode.removeChild(listItem);
- }
- }
-
- list.parentNode.replaceChild(fragment, list);
- }
-
- dom.resolveList = resolveList;
-})(wysihtml5.dom);
-;/**
- * Sandbox for executing javascript, parsing css styles and doing dom operations in a secure way
- *
- * Browser Compatibility:
- * - Secure in MSIE 6+, but only when the user hasn't made changes to his security level "restricted"
- * - Partially secure in other browsers (Firefox, Opera, Safari, Chrome, ...)
- *
- * Please note that this class can't benefit from the HTML5 sandbox attribute for the following reasons:
- * - sandboxing doesn't work correctly with inlined content (src="javascript:'...'")
- * - sandboxing of physical documents causes that the dom isn't accessible anymore from the outside (iframe.contentWindow, ...)
- * - setting the "allow-same-origin" flag would fix that, but then still javascript and dom events refuse to fire
- * - therefore the "allow-scripts" flag is needed, which then would deactivate any security, as the js executed inside the iframe
- * can do anything as if the sandbox attribute wasn't set
- *
- * @param {Function} [readyCallback] Method that gets invoked when the sandbox is ready
- * @param {Object} [config] Optional parameters
- *
- * @example
- * new wysihtml5.dom.Sandbox(function(sandbox) {
- * sandbox.getWindow().document.body.innerHTML = ' ';
- * });
- */
-(function(wysihtml5) {
- var /**
- * Default configuration
- */
- doc = document,
- /**
- * Properties to unset/protect on the window object
- */
- windowProperties = [
- "parent", "top", "opener", "frameElement", "frames",
- "localStorage", "globalStorage", "sessionStorage", "indexedDB"
- ],
- /**
- * Properties on the window object which are set to an empty function
- */
- windowProperties2 = [
- "open", "close", "openDialog", "showModalDialog",
- "alert", "confirm", "prompt",
- "openDatabase", "postMessage",
- "XMLHttpRequest", "XDomainRequest"
- ],
- /**
- * Properties to unset/protect on the document object
- */
- documentProperties = [
- "referrer",
- "write", "open", "close"
- ];
-
- wysihtml5.dom.Sandbox = Base.extend(
- /** @scope wysihtml5.dom.Sandbox.prototype */ {
-
- constructor: function(readyCallback, config) {
- this.callback = readyCallback || wysihtml5.EMPTY_FUNCTION;
- this.config = wysihtml5.lang.object({}).merge(config).get();
- if (!this.config.className) {
- this.config.className = "wysihtml5-sandbox";
- }
- this.editableArea = this._createIframe();
- },
-
- insertInto: function(element) {
- if (typeof(element) === "string") {
- element = doc.getElementById(element);
- }
-
- element.appendChild(this.editableArea);
- },
-
- getIframe: function() {
- return this.editableArea;
- },
-
- getWindow: function() {
- this._readyError();
- },
-
- getDocument: function() {
- this._readyError();
- },
-
- destroy: function() {
- var iframe = this.getIframe();
- iframe.parentNode.removeChild(iframe);
- },
-
- _readyError: function() {
- throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet");
- },
-
- /**
- * Creates the sandbox iframe
- *
- * Some important notes:
- * - We can't use HTML5 sandbox for now:
- * setting it causes that the iframe's dom can't be accessed from the outside
- * Therefore we need to set the "allow-same-origin" flag which enables accessing the iframe's dom
- * But then there's another problem, DOM events (focus, blur, change, keypress, ...) aren't fired.
- * In order to make this happen we need to set the "allow-scripts" flag.
- * A combination of allow-scripts and allow-same-origin is almost the same as setting no sandbox attribute at all.
- * - Chrome & Safari, doesn't seem to support sandboxing correctly when the iframe's html is inlined (no physical document)
- * - IE needs to have the security="restricted" attribute set before the iframe is
- * inserted into the dom tree
- * - Believe it or not but in IE "security" in document.createElement("iframe") is false, even
- * though it supports it
- * - When an iframe has security="restricted", in IE eval() & execScript() don't work anymore
- * - IE doesn't fire the onload event when the content is inlined in the src attribute, therefore we rely
- * on the onreadystatechange event
- */
- _createIframe: function() {
- var that = this,
- iframe = doc.createElement("iframe");
- iframe.className = this.config.className;
- wysihtml5.dom.setAttributes({
- "security": "restricted",
- "allowtransparency": "true",
- "frameborder": 0,
- "width": 0,
- "height": 0,
- "marginwidth": 0,
- "marginheight": 0
- }).on(iframe);
-
- // Setting the src like this prevents ssl warnings in IE6
- if (wysihtml5.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()) {
- iframe.src = "javascript:''";
- }
-
- iframe.onload = function() {
- iframe.onreadystatechange = iframe.onload = null;
- that._onLoadIframe(iframe);
- };
-
- iframe.onreadystatechange = function() {
- if (/loaded|complete/.test(iframe.readyState)) {
- iframe.onreadystatechange = iframe.onload = null;
- that._onLoadIframe(iframe);
- }
- };
-
- return iframe;
- },
-
- /**
- * Callback for when the iframe has finished loading
- */
- _onLoadIframe: function(iframe) {
- // don't resume when the iframe got unloaded (eg. by removing it from the dom)
- if (!wysihtml5.dom.contains(doc.documentElement, iframe)) {
- return;
- }
-
- var that = this,
- iframeWindow = iframe.contentWindow,
- iframeDocument = iframe.contentWindow.document,
- charset = doc.characterSet || doc.charset || "utf-8",
- sandboxHtml = this._getHtml({
- charset: charset,
- stylesheets: this.config.stylesheets
- });
-
- // Create the basic dom tree including proper DOCTYPE and charset
- iframeDocument.open("text/html", "replace");
- iframeDocument.write(sandboxHtml);
- iframeDocument.close();
-
- this.getWindow = function() { return iframe.contentWindow; };
- this.getDocument = function() { return iframe.contentWindow.document; };
-
- // Catch js errors and pass them to the parent's onerror event
- // addEventListener("error") doesn't work properly in some browsers
- // TODO: apparently this doesn't work in IE9!
- iframeWindow.onerror = function(errorMessage, fileName, lineNumber) {
- throw new Error("wysihtml5.Sandbox: " + errorMessage, fileName, lineNumber);
- };
-
- if (!wysihtml5.browser.supportsSandboxedIframes()) {
- // Unset a bunch of sensitive variables
- // Please note: This isn't hack safe!
- // It more or less just takes care of basic attacks and prevents accidental theft of sensitive information
- // IE is secure though, which is the most important thing, since IE is the only browser, who
- // takes over scripts & styles into contentEditable elements when copied from external websites
- // or applications (Microsoft Word, ...)
- var i, length;
- for (i=0, length=windowProperties.length; i';
- }
- }
- templateVars.stylesheets = html;
-
- return wysihtml5.lang.string(
- ''
- + ' #{stylesheets}'
- + ''
- ).interpolate(templateVars);
- },
-
- /**
- * Method to unset/override existing variables
- * @example
- * // Make cookie unreadable and unwritable
- * this._unset(document, "cookie", "", true);
- */
- _unset: function(object, property, value, setter) {
- try { object[property] = value; } catch(e) {}
-
- try { object.__defineGetter__(property, function() { return value; }); } catch(e) {}
- if (setter) {
- try { object.__defineSetter__(property, function() {}); } catch(e) {}
- }
-
- if (!wysihtml5.browser.crashesWhenDefineProperty(property)) {
- try {
- var config = {
- get: function() { return value; }
- };
- if (setter) {
- config.set = function() {};
- }
- Object.defineProperty(object, property, config);
- } catch(e) {}
- }
- }
- });
-})(wysihtml5);
-;(function(wysihtml5) {
- var doc = document;
- wysihtml5.dom.ContentEditableArea = Base.extend({
- getContentEditable: function() {
- return this.element;
- },
-
- getWindow: function() {
- return this.element.ownerDocument.defaultView || this.element.ownerDocument.parentWindow;
- },
-
- getDocument: function() {
- return this.element.ownerDocument;
- },
-
- constructor: function(readyCallback, config, contentEditable) {
- this.callback = readyCallback || wysihtml5.EMPTY_FUNCTION;
- this.config = wysihtml5.lang.object({}).merge(config).get();
- if (!this.config.className) {
- this.config.className = "wysihtml5-sandbox";
- }
- if (contentEditable) {
- this.element = this._bindElement(contentEditable);
- } else {
- this.element = this._createElement();
- }
- },
-
- destroy: function() {
-
- },
-
- // creates a new contenteditable and initiates it
- _createElement: function() {
- var element = doc.createElement("div");
- element.className = this.config.className;
- this._loadElement(element);
- return element;
- },
-
- // initiates an allready existent contenteditable
- _bindElement: function(contentEditable) {
- contentEditable.className = contentEditable.className ? contentEditable.className + " wysihtml5-sandbox" : "wysihtml5-sandbox";
- this._loadElement(contentEditable, true);
- return contentEditable;
- },
-
- _loadElement: function(element, contentExists) {
- var that = this;
-
- if (!contentExists) {
- var innerHtml = this._getHtml();
- element.innerHTML = innerHtml;
- }
-
- this.loaded = true;
- // Trigger the callback
- setTimeout(function() { that.callback(that); }, 0);
- },
-
- _getHtml: function(templateVars) {
- return '';
- }
-
- });
-})(wysihtml5);
-;(function() {
- var mapping = {
- "className": "class"
- };
- wysihtml5.dom.setAttributes = function(attributes) {
- return {
- on: function(element) {
- for (var i in attributes) {
- element.setAttribute(mapping[i] || i, attributes[i]);
- }
- }
- };
- };
-})();
-;wysihtml5.dom.setStyles = function(styles) {
- return {
- on: function(element) {
- var style = element.style;
- if (typeof(styles) === "string") {
- style.cssText += ";" + styles;
- return;
- }
- for (var i in styles) {
- if (i === "float") {
- style.cssFloat = styles[i];
- style.styleFloat = styles[i];
- } else {
- style[i] = styles[i];
- }
- }
- }
- };
-};
-;/**
- * Simulate HTML5 placeholder attribute
- *
- * Needed since
- * - div[contentEditable] elements don't support it
- * - older browsers (such as IE8 and Firefox 3.6) don't support it at all
- *
- * @param {Object} parent Instance of main wysihtml5.Editor class
- * @param {Element} view Instance of wysihtml5.views.* class
- * @param {String} placeholderText
- *
- * @example
- * wysihtml.dom.simulatePlaceholder(this, composer, "Foobar");
- */
-(function(dom) {
- dom.simulatePlaceholder = function(editor, view, placeholderText, placeholderClassName) {
- var CLASS_NAME = placeholderClassName || "wysihtml5-placeholder",
- unset = function() {
- var composerIsVisible = view.element.offsetWidth > 0 && view.element.offsetHeight > 0;
- if (view.hasPlaceholderSet()) {
- view.clear();
- view.element.focus();
- if (composerIsVisible ) {
- setTimeout(function() {
- var sel = view.selection.getSelection();
- if (!sel.focusNode || !sel.anchorNode) {
- view.selection.selectNode(view.element.firstChild || view.element);
- }
- }, 0);
- }
- }
- view.placeholderSet = false;
- dom.removeClass(view.element, CLASS_NAME);
- },
- set = function() {
- if (view.isEmpty() && !view.placeholderSet) {
- view.placeholderSet = true;
- view.setValue(placeholderText, false);
- dom.addClass(view.element, CLASS_NAME);
- }
- };
-
- editor
- .on("set_placeholder", set)
- .on("unset_placeholder", unset)
- .on("focus:composer", unset)
- .on("paste:composer", unset)
- .on("blur:composer", set);
-
- set();
- };
-})(wysihtml5.dom);
-;(function(dom) {
- var documentElement = document.documentElement;
- if ("textContent" in documentElement) {
- dom.setTextContent = function(element, text) {
- element.textContent = text;
- };
-
- dom.getTextContent = function(element) {
- return element.textContent;
- };
- } else if ("innerText" in documentElement) {
- dom.setTextContent = function(element, text) {
- element.innerText = text;
- };
-
- dom.getTextContent = function(element) {
- return element.innerText;
- };
- } else {
- dom.setTextContent = function(element, text) {
- element.nodeValue = text;
- };
-
- dom.getTextContent = function(element) {
- return element.nodeValue;
- };
- }
-})(wysihtml5.dom);
-;/**
- * Get a set of attribute from one element
- *
- * IE gives wrong results for hasAttribute/getAttribute, for example:
- * var td = document.createElement("td");
- * td.getAttribute("rowspan"); // => "1" in IE
- *
- * Therefore we have to check the element's outerHTML for the attribute
-*/
-
-wysihtml5.dom.getAttribute = function(node, attributeName) {
- var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly();
- attributeName = attributeName.toLowerCase();
- var nodeName = node.nodeName;
- if (nodeName == "IMG" && attributeName == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
- // Get 'src' attribute value via object property since this will always contain the
- // full absolute url (http://...)
- // this fixes a very annoying bug in firefox (ver 3.6 & 4) and IE 8 where images copied from the same host
- // will have relative paths, which the sanitizer strips out (see attributeCheckMethods.url)
- return node.src;
- } else if (HAS_GET_ATTRIBUTE_BUG && "outerHTML" in node) {
- // Don't trust getAttribute/hasAttribute in IE 6-8, instead check the element's outerHTML
- var outerHTML = node.outerHTML.toLowerCase(),
- // TODO: This might not work for attributes without value:
- hasAttribute = outerHTML.indexOf(" " + attributeName + "=") != -1;
-
- return hasAttribute ? node.getAttribute(attributeName) : null;
- } else{
- return node.getAttribute(attributeName);
- }
-};
-;/**
- * Get all attributes of an element
- *
- * IE gives wrong results for hasAttribute/getAttribute, for example:
- * var td = document.createElement("td");
- * td.getAttribute("rowspan"); // => "1" in IE
- *
- * Therefore we have to check the element's outerHTML for the attribute
-*/
-
-wysihtml5.dom.getAttributes = function(node) {
- var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly(),
- nodeName = node.nodeName,
- attributes = [],
- attr;
-
- for (attr in node.attributes) {
- if ((node.attributes.hasOwnProperty && node.attributes.hasOwnProperty(attr)) || (!node.attributes.hasOwnProperty && Object.prototype.hasOwnProperty.call(node.attributes, attr))) {
- if (node.attributes[attr].specified) {
- if (nodeName == "IMG" && node.attributes[attr].name.toLowerCase() == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
- attributes['src'] = node.src;
- } else if (wysihtml5.lang.array(['rowspan', 'colspan']).contains(node.attributes[attr].name.toLowerCase()) && HAS_GET_ATTRIBUTE_BUG) {
- if (node.attributes[attr].value !== 1) {
- attributes[node.attributes[attr].name] = node.attributes[attr].value;
- }
- } else {
- attributes[node.attributes[attr].name] = node.attributes[attr].value;
+ classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
+ }
+ classesLength = classes.length;
+ for (; i under https when it's new attribute value is non-https
+ // TODO: Investigate this further and check for smarter handling
+ try {
+ newNode.setAttribute(attributeName, attributes[attributeName]);
+ } catch(e) {}
}
- return ret;
- }
- function removeElement(el) {
- el.parentNode.removeChild(el);
+ // IE8 sometimes loses the width/height attributes when those are set before the "src"
+ // so we make sure to set them again
+ if (attributes.src) {
+ if (typeof(attributes.width) !== "undefined") {
+ newNode.setAttribute("width", attributes.width);
+ }
+ if (typeof(attributes.height) !== "undefined") {
+ newNode.setAttribute("height", attributes.height);
+ }
+ }
}
- function insertAfter(referenceNode, newNode) {
- referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
+ function _handleText(oldNode) {
+ var nextSibling = oldNode.nextSibling;
+ if (nextSibling && nextSibling.nodeType === wysihtml.TEXT_NODE) {
+ // Concatenate text nodes
+ nextSibling.data = oldNode.data.replace(wysihtml.INVISIBLE_SPACE_REG_EXP, "") + nextSibling.data.replace(wysihtml.INVISIBLE_SPACE_REG_EXP, "");
+ } else {
+ // \uFEFF = wysihtml.INVISIBLE_SPACE (used as a hack in certain rich text editing situations)
+ var data = oldNode.data.replace(wysihtml.INVISIBLE_SPACE_REG_EXP, "");
+ return oldNode.ownerDocument.createTextNode(data);
+ }
}
- function nextNode(node, tag) {
- var element = node.nextSibling;
- while (element.nodeType !=1) {
- element = element.nextSibling;
- if (!tag || tag == element.tagName.toLowerCase()) {
- return element;
- }
+ function _handleComment(oldNode) {
+ if (currentRules.comments) {
+ return oldNode.ownerDocument.createComment(oldNode.nodeValue);
}
- return null;
}
- TableModifyerByCell.prototype = {
-
- addSpannedCellToMap: function(cell, map, r, c, cspan, rspan) {
- var spanCollect = [],
- rmax = r + ((rspan) ? parseInt(rspan, 10) - 1 : 0),
- cmax = c + ((cspan) ? parseInt(cspan, 10) - 1 : 0);
-
- for (var rr = r; rr <= rmax; rr++) {
- if (typeof map[rr] == "undefined") { map[rr] = []; }
- for (var cc = c; cc <= cmax; cc++) {
- map[rr][cc] = new MapCell(cell);
- map[rr][cc].isColspan = (cspan && parseInt(cspan, 10) > 1);
- map[rr][cc].isRowspan = (rspan && parseInt(rspan, 10) > 1);
- map[rr][cc].firstCol = cc == c;
- map[rr][cc].lastCol = cc == cmax;
- map[rr][cc].firstRow = rr == r;
- map[rr][cc].lastRow = rr == rmax;
- map[rr][cc].isReal = cc == c && rr == r;
- map[rr][cc].spanCollection = spanCollect;
+ // ------------ attribute checks ------------ \\
+ var attributeCheckMethods = {
+ url: (function() {
+ var REG_EXP = /^https?:\/\//i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
+ }
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
- spanCollect.push(map[rr][cc]);
+ src: (function() {
+ var REG_EXP = /^(\/|https?:\/\/)/i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
}
- }
- },
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
- setCellAsModified: function(cell) {
- cell.modified = true;
- if (cell.spanCollection.length > 0) {
- for (var s = 0, smax = cell.spanCollection.length; s < smax; s++) {
- cell.spanCollection[s].modified = true;
+ href: (function() {
+ var REG_EXP = /^(#|\/|https?:\/\/|mailto:|tel:)/i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
}
- }
- },
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
- setTableMap: function() {
- var map = [];
- var tableRows = this.getTableRows(),
- ridx, row, cells, cidx, cell,
- c,
- cspan, rspan;
-
- for (ridx = 0; ridx < tableRows.length; ridx++) {
- row = tableRows[ridx];
- cells = this.getRowCells(row);
- c = 0;
- if (typeof map[ridx] == "undefined") { map[ridx] = []; }
- for (cidx = 0; cidx < cells.length; cidx++) {
- cell = cells[cidx];
-
- // If cell allready set means it is set by col or rowspan,
- // so increase cols index until free col is found
- while (typeof map[ridx][c] != "undefined") { c++; }
-
- cspan = api.getAttribute(cell, 'colspan');
- rspan = api.getAttribute(cell, 'rowspan');
-
- if (cspan || rspan) {
- this.addSpannedCellToMap(cell, map, ridx, c, cspan, rspan);
- c = c + ((cspan) ? parseInt(cspan, 10) : 1);
+ alt: (function() {
+ var REG_EXP = /[^ a-z0-9_\-]/gi;
+ return function(attributeValue, nodeName) {
+ if (!attributeValue) {
+ if (nodeName === "IMG") {
+ return "";
} else {
- map[ridx][c] = new MapCell(cell);
- c++;
+ return null;
}
}
- }
- this.map = map;
- return map;
- },
+ return attributeValue.replace(REG_EXP, "");
+ };
+ })(),
- getRowCells: function(row) {
- var inlineTables = this.table.querySelectorAll('table'),
- inlineCells = (inlineTables) ? queryInList(inlineTables, 'th, td') : [],
- allCells = row.querySelectorAll('th, td'),
- tableCells = (inlineCells.length > 0) ? wysihtml5.lang.array(allCells).without(inlineCells) : allCells;
+ // Integers. Does not work with floating point numbers and units
+ numbers: (function() {
+ var REG_EXP = /\D/g;
+ return function(attributeValue) {
+ attributeValue = (attributeValue || "").replace(REG_EXP, "");
+ return attributeValue || null;
+ };
+ })(),
- return tableCells;
- },
+ // Useful for with/height attributes where floating points and percentages are allowed
+ dimension: (function() {
+ var REG_EXP = /\D*(\d+)(\.\d+)?\s?(%)?\D*/;
+ return function(attributeValue) {
+ attributeValue = (attributeValue || "").replace(REG_EXP, "$1$2$3");
+ return attributeValue || null;
+ };
+ })(),
- getTableRows: function() {
- var inlineTables = this.table.querySelectorAll('table'),
- inlineRows = (inlineTables) ? queryInList(inlineTables, 'tr') : [],
- allRows = this.table.querySelectorAll('tr'),
- tableRows = (inlineRows.length > 0) ? wysihtml5.lang.array(allRows).without(inlineRows) : allRows;
+ any: (function() {
+ return function(attributeValue) {
+ if (!attributeValue) {
+ return null;
+ }
+ return attributeValue;
+ };
+ })()
+ };
- return tableRows;
- },
+ // ------------ style converter (converts an html attribute to a style) ------------ \\
+ var addStyleMethods = {
+ align_text: (function() {
+ var mapping = {
+ left: "text-align: left;",
+ right: "text-align: right;",
+ center: "text-align: center;"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+ };
- getMapIndex: function(cell) {
- var r_length = this.map.length,
- c_length = (this.map && this.map[0]) ? this.map[0].length : 0;
+ // ------------ class converter (converts an html attribute to a class name) ------------ \\
+ var addClassMethods = {
+ align_img: (function() {
+ var mapping = {
+ left: "wysiwyg-float-left",
+ right: "wysiwyg-float-right"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
- for (var r_idx = 0;r_idx < r_length; r_idx++) {
- for (var c_idx = 0;c_idx < c_length; c_idx++) {
- if (this.map[r_idx][c_idx].el === cell) {
- return {'row': r_idx, 'col': c_idx};
- }
- }
- }
- return false;
- },
+ align_text: (function() {
+ var mapping = {
+ left: "wysiwyg-text-align-left",
+ right: "wysiwyg-text-align-right",
+ center: "wysiwyg-text-align-center",
+ justify: "wysiwyg-text-align-justify"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
- getElementAtIndex: function(idx) {
- this.setTableMap();
- if (this.map[idx.row] && this.map[idx.row][idx.col] && this.map[idx.row][idx.col].el) {
- return this.map[idx.row][idx.col].el;
- }
- return null;
- },
+ clear_br: (function() {
+ var mapping = {
+ left: "wysiwyg-clear-left",
+ right: "wysiwyg-clear-right",
+ both: "wysiwyg-clear-both",
+ all: "wysiwyg-clear-both"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
- getMapElsTo: function(to_cell) {
- var els = [];
- this.setTableMap();
- this.idx_start = this.getMapIndex(this.cell);
- this.idx_end = this.getMapIndex(to_cell);
+ size_font: (function() {
+ var mapping = {
+ "1": "wysiwyg-font-size-xx-small",
+ "2": "wysiwyg-font-size-small",
+ "3": "wysiwyg-font-size-medium",
+ "4": "wysiwyg-font-size-large",
+ "5": "wysiwyg-font-size-x-large",
+ "6": "wysiwyg-font-size-xx-large",
+ "7": "wysiwyg-font-size-xx-large",
+ "-": "wysiwyg-font-size-smaller",
+ "+": "wysiwyg-font-size-larger"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).charAt(0)];
+ };
+ })()
+ };
- // switch indexes if start is bigger than end
- if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
- var temp_idx = this.idx_start;
- this.idx_start = this.idx_end;
- this.idx_end = temp_idx;
- }
- if (this.idx_start.col > this.idx_end.col) {
- var temp_cidx = this.idx_start.col;
- this.idx_start.col = this.idx_end.col;
- this.idx_end.col = temp_cidx;
- }
+ // checks if element is possibly visible
+ var typeCeckMethods = {
+ has_visible_contet: (function() {
+ var txt,
+ isVisible = false,
+ visibleElements = ['img', 'video', 'picture', 'br', 'script', 'noscript',
+ 'style', 'table', 'iframe', 'object', 'embed', 'audio',
+ 'svg', 'input', 'button', 'select','textarea', 'canvas'];
+
+ return function(el) {
+
+ // has visible innertext. so is visible
+ txt = (el.innerText || el.textContent).replace(/\s/g, '');
+ if (txt && txt.length > 0) {
+ return true;
+ }
- if (this.idx_start != null && this.idx_end != null) {
- for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
- for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
- els.push(this.map[row][col].el);
+ // matches list of visible dimensioned elements
+ for (var i = visibleElements.length; i--;) {
+ if (el.querySelector(visibleElements[i])) {
+ return true;
}
}
- }
- return els;
- },
- orderSelectionEnds: function(secondcell) {
- this.setTableMap();
- this.idx_start = this.getMapIndex(this.cell);
- this.idx_end = this.getMapIndex(secondcell);
+ // try to measure dimesions in last resort. (can find only of elements in dom)
+ if (el.offsetWidth && el.offsetWidth > 0 && el.offsetHeight && el.offsetHeight > 0) {
+ return true;
+ }
+
+ return false;
+ };
+ })()
+ };
+
+ var elementHandlingMethods = {
+ unwrap: function (element) {
+ wysihtml.dom.unwrap(element);
+ },
- // switch indexes if start is bigger than end
- if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
- var temp_idx = this.idx_start;
- this.idx_start = this.idx_end;
- this.idx_end = temp_idx;
- }
- if (this.idx_start.col > this.idx_end.col) {
- var temp_cidx = this.idx_start.col;
- this.idx_start.col = this.idx_end.col;
- this.idx_end.col = temp_cidx;
- }
+ remove: function (element) {
+ element.parentNode.removeChild(element);
+ }
+ };
- return {
- "start": this.map[this.idx_start.row][this.idx_start.col].el,
- "end": this.map[this.idx_end.row][this.idx_end.col].el
- };
- },
+ return parse(elementOrHtml_current, config_current);
+};
- createCells: function(tag, nr, attrs) {
- var doc = this.table.ownerDocument,
- frag = doc.createDocumentFragment(),
- cell;
- for (var i = 0; i < nr; i++) {
- cell = doc.createElement(tag);
-
- if (attrs) {
- for (var attr in attrs) {
- if (attrs.hasOwnProperty(attr)) {
- cell.setAttribute(attr, attrs[attr]);
- }
- }
- }
+// does a selector query on element or array of elements
+wysihtml.dom.query = function(elements, query) {
+ var ret = [],
+ q;
- // add non breaking space
- cell.appendChild(document.createTextNode("\u00a0"));
- frag.appendChild(cell);
- }
- return frag;
- },
+ if (elements.nodeType) {
+ elements = [elements];
+ }
- // Returns next real cell (not part of spanned cell unless first) on row if selected index is not real. I no real cells -1 will be returned
- correctColIndexForUnreals: function(col, row) {
- var r = this.map[row],
- corrIdx = -1;
- for (var i = 0, max = col; i < col; i++) {
- if (r[i].isReal){
- corrIdx++;
+ for (var e = 0, len = elements.length; e < len; e++) {
+ q = elements[e].querySelectorAll(query);
+ if (q) {
+ for(var i = q.length; i--; ret.unshift(q[i]));
}
- }
- return corrIdx;
- },
+ }
+ return ret;
+};
- getLastNewCellOnRow: function(row, rowLimit) {
- var cells = this.getRowCells(row),
- cell, idx;
+/**
+ * Checks for empty text node childs and removes them
+ *
+ * @param {Element} node The element in which to cleanup
+ * @example
+ * wysihtml.dom.removeEmptyTextNodes(element);
+ */
+wysihtml.dom.removeEmptyTextNodes = function(node) {
+ var childNode,
+ childNodes = wysihtml.lang.array(node.childNodes).get(),
+ childNodesLength = childNodes.length,
+ i = 0;
- for (var cidx = 0, cmax = cells.length; cidx < cmax; cidx++) {
- cell = cells[cidx];
- idx = this.getMapIndex(cell);
- if (idx === false || (typeof rowLimit != "undefined" && idx.row != rowLimit)) {
- return cell;
- }
- }
- return null;
- },
+ for (; i 1) {
- var newCells = this.createCells(cType, colspan -1);
- insertAfter(cell.el, newCells);
- }
- cell.el.removeAttribute('colspan');
- }
- },
+/**
+ * Renames an element (eg. a to a
) and keeps its childs
+ *
+ * @param {Element} element The list element which should be renamed
+ * @param {Element} newNodeName The desired tag name
+ *
+ * @example
+ *
+ *
+ * eminem
+ * dr. dre
+ * 50 Cent
+ *
+ *
+ *
+ *
+ *
+ *
+ * eminem
+ * dr. dre
+ * 50 Cent
+ *
+ */
+wysihtml.dom.renameElement = function(element, newNodeName) {
+ var newElement = element.ownerDocument.createElement(newNodeName),
+ firstChild;
+ while (firstChild = element.firstChild) {
+ newElement.appendChild(firstChild);
+ }
+ wysihtml.dom.copyAttributes(["align", "className"]).from(element).to(newElement);
+
+ if (element.parentNode) {
+ element.parentNode.replaceChild(newElement, element);
+ }
- getRealRowEl: function(force, idx) {
- var r = null,
- c = null;
+ return newElement;
+};
- idx = idx || this.idx;
+/**
+ * Takes an element, removes it and replaces it with it's childs
+ *
+ * @param {Object} node The node which to replace with it's child nodes
+ * @example
+ *
+ * hello
+ *
+ *
+ */
+wysihtml.dom.replaceWithChildNodes = function(node) {
+ if (!node.parentNode) {
+ return;
+ }
- for (var cidx = 0, cmax = this.map[idx.row].length; cidx < cmax; cidx++) {
- c = this.map[idx.row][cidx];
- if (c.isReal) {
- r = api.getParentElement(c.el, { query: "tr" });
- if (r) {
- return r;
- }
- }
- }
+ while (node.firstChild) {
+ node.parentNode.insertBefore(node.firstChild, node);
+ }
+ node.parentNode.removeChild(node);
+};
- if (r === null && force) {
- r = api.getParentElement(this.map[idx.row][idx.col].el, { query: "tr" }) || null;
- }
+/**
+ * Unwraps an unordered/ordered list
+ *
+ * @param {Element} element The list element which should be unwrapped
+ *
+ * @example
+ *
+ *
+ * eminem
+ * dr. dre
+ * 50 Cent
+ *
+ *
+ *
+ *
+ *
+ * eminem
+ * dr. dre
+ * 50 Cent
+ */
+(function(dom) {
+ function _isBlockElement(node) {
+ return dom.getStyle("display").from(node) === "block";
+ }
- return r;
- },
+ function _isLineBreak(node) {
+ return node.nodeName === "BR";
+ }
- injectRowAt: function(row, col, colspan, cType, c) {
- var r = this.getRealRowEl(false, {'row': row, 'col': col}),
- new_cells = this.createCells(cType, colspan);
+ function _appendLineBreak(element) {
+ var lineBreak = element.ownerDocument.createElement("br");
+ element.appendChild(lineBreak);
+ }
- if (r) {
- var n_cidx = this.correctColIndexForUnreals(col, row);
- if (n_cidx >= 0) {
- insertAfter(this.getRowCells(r)[n_cidx], new_cells);
- } else {
- r.insertBefore(new_cells, r.firstChild);
- }
- } else {
- var rr = this.table.ownerDocument.createElement('tr');
- rr.appendChild(new_cells);
- insertAfter(api.getParentElement(c.el, { query: "tr" }), rr);
- }
- },
+ function resolveList(list, useLineBreaks) {
+ if (!list.nodeName.match(/^(MENU|UL|OL)$/)) {
+ return;
+ }
- canMerge: function(to) {
- this.to = to;
- this.setTableMap();
- this.idx_start = this.getMapIndex(this.cell);
- this.idx_end = this.getMapIndex(this.to);
+ var doc = list.ownerDocument,
+ fragment = doc.createDocumentFragment(),
+ previousSibling = wysihtml.dom.domNode(list).prev({ignoreBlankTexts: true}),
+ nextSibling = wysihtml.dom.domNode(list).next({ignoreBlankTexts: true}),
+ firstChild,
+ lastChild,
+ isLastChild,
+ shouldAppendLineBreak,
+ paragraph,
+ listItem,
+ lastListItem = list.lastElementChild || list.lastChild,
+ isLastItem;
- // switch indexes if start is bigger than end
- if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
- var temp_idx = this.idx_start;
- this.idx_start = this.idx_end;
- this.idx_end = temp_idx;
- }
- if (this.idx_start.col > this.idx_end.col) {
- var temp_cidx = this.idx_start.col;
- this.idx_start.col = this.idx_end.col;
- this.idx_end.col = temp_cidx;
+ if (useLineBreaks) {
+ // Insert line break if list is after a non-block element
+ if (previousSibling && !_isBlockElement(previousSibling) && !_isLineBreak(previousSibling)) {
+ _appendLineBreak(fragment);
}
- for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
- for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
- if (this.map[row][col].isColspan || this.map[row][col].isRowspan) {
- return false;
+ while (listItem = (list.firstElementChild || list.firstChild)) {
+ lastChild = listItem.lastChild;
+ isLastItem = listItem === lastListItem;
+ while (firstChild = listItem.firstChild) {
+ isLastChild = firstChild === lastChild;
+ // This needs to be done before appending it to the fragment, as it otherwise will lose style information
+ shouldAppendLineBreak = (!isLastItem || (nextSibling && !_isBlockElement(nextSibling))) && isLastChild && !_isBlockElement(firstChild) && !_isLineBreak(firstChild);
+ fragment.appendChild(firstChild);
+ if (shouldAppendLineBreak) {
+ _appendLineBreak(fragment);
}
}
- }
- return true;
- },
- decreaseCellSpan: function(cell, span) {
- var nr = parseInt(api.getAttribute(cell.el, span), 10) - 1;
- if (nr >= 1) {
- cell.el.setAttribute(span, nr);
- } else {
- cell.el.removeAttribute(span);
- if (span == 'colspan') {
- cell.isColspan = false;
- }
- if (span == 'rowspan') {
- cell.isRowspan = false;
- }
- cell.firstCol = true;
- cell.lastCol = true;
- cell.firstRow = true;
- cell.lastRow = true;
- cell.isReal = true;
+ listItem.parentNode.removeChild(listItem);
}
- },
-
- removeSurplusLines: function() {
- var row, cell, ridx, rmax, cidx, cmax, allRowspan;
-
- this.setTableMap();
- if (this.map) {
- ridx = 0;
- rmax = this.map.length;
- for (;ridx < rmax; ridx++) {
- row = this.map[ridx];
- allRowspan = true;
- cidx = 0;
- cmax = row.length;
- for (; cidx < cmax; cidx++) {
- cell = row[cidx];
- if (!(api.getAttribute(cell.el, "rowspan") && parseInt(api.getAttribute(cell.el, "rowspan"), 10) > 1 && cell.firstRow !== true)) {
- allRowspan = false;
- break;
- }
- }
- if (allRowspan) {
- cidx = 0;
- for (; cidx < cmax; cidx++) {
- this.decreaseCellSpan(row[cidx], 'rowspan');
- }
+ } else {
+ while (listItem = (list.firstElementChild || list.firstChild)) {
+ if (listItem.querySelector && listItem.querySelector("div, p, ul, ol, menu, blockquote, h1, h2, h3, h4, h5, h6")) {
+ while (firstChild = listItem.firstChild) {
+ fragment.appendChild(firstChild);
}
- }
-
- // remove rows without cells
- var tableRows = this.getTableRows();
- ridx = 0;
- rmax = tableRows.length;
- for (;ridx < rmax; ridx++) {
- row = tableRows[ridx];
- if (row.childNodes.length == 0 && (/^\s*$/.test(row.textContent || row.innerText))) {
- removeElement(row);
+ } else {
+ paragraph = doc.createElement("p");
+ while (firstChild = listItem.firstChild) {
+ paragraph.appendChild(firstChild);
}
+ fragment.appendChild(paragraph);
}
+ listItem.parentNode.removeChild(listItem);
}
- },
+ }
+
+ list.parentNode.replaceChild(fragment, list);
+ }
- fillMissingCells: function() {
- var r_max = 0,
- c_max = 0,
- prevcell = null;
+ dom.resolveList = resolveList;
+})(wysihtml.dom);
- this.setTableMap();
- if (this.map) {
+/**
+ * Sandbox for executing javascript, parsing css styles and doing dom operations in a secure way
+ *
+ * Browser Compatibility:
+ * - Secure in MSIE 6+, but only when the user hasn't made changes to his security level "restricted"
+ * - Partially secure in other browsers (Firefox, Opera, Safari, Chrome, ...)
+ *
+ * Please note that this class can't benefit from the HTML5 sandbox attribute for the following reasons:
+ * - sandboxing doesn't work correctly with inlined content (src="javascript:'...'")
+ * - sandboxing of physical documents causes that the dom isn't accessible anymore from the outside (iframe.contentWindow, ...)
+ * - setting the "allow-same-origin" flag would fix that, but then still javascript and dom events refuse to fire
+ * - therefore the "allow-scripts" flag is needed, which then would deactivate any security, as the js executed inside the iframe
+ * can do anything as if the sandbox attribute wasn't set
+ *
+ * @param {Function} [readyCallback] Method that gets invoked when the sandbox is ready
+ * @param {Object} [config] Optional parameters
+ *
+ * @example
+ * new wysihtml.dom.Sandbox(function(sandbox) {
+ * sandbox.getWindow().document.body.innerHTML = '
';
+ * });
+ */
+(function(wysihtml) {
+ var /**
+ * Default configuration
+ */
+ doc = document,
+ /**
+ * Properties to unset/protect on the window object
+ */
+ windowProperties = [
+ "parent", "top", "opener", "frameElement", "frames",
+ "localStorage", "globalStorage", "sessionStorage", "indexedDB"
+ ],
+ /**
+ * Properties on the window object which are set to an empty function
+ */
+ windowProperties2 = [
+ "open", "close", "openDialog", "showModalDialog",
+ "alert", "confirm", "prompt",
+ "openDatabase", "postMessage",
+ "XMLHttpRequest", "XDomainRequest"
+ ],
+ /**
+ * Properties to unset/protect on the document object
+ */
+ documentProperties = [
+ "referrer",
+ "write", "open", "close"
+ ];
- // find maximal dimensions of broken table
- r_max = this.map.length;
- for (var ridx = 0; ridx < r_max; ridx++) {
- if (this.map[ridx].length > c_max) { c_max = this.map[ridx].length; }
- }
+ wysihtml.dom.Sandbox = Base.extend(
+ /** @scope wysihtml.dom.Sandbox.prototype */ {
- for (var row = 0; row < r_max; row++) {
- for (var col = 0; col < c_max; col++) {
- if (this.map[row] && !this.map[row][col]) {
- if (col > 0) {
- this.map[row][col] = new MapCell(this.createCells('td', 1));
- prevcell = this.map[row][col-1];
- if (prevcell && prevcell.el && prevcell.el.parent) { // if parent does not exist element is removed from dom
- insertAfter(this.map[row][col-1].el, this.map[row][col].el);
- }
- }
- }
- }
- }
+ constructor: function(readyCallback, config) {
+ this.callback = readyCallback || wysihtml.EMPTY_FUNCTION;
+ this.config = wysihtml.lang.object({}).merge(config).get();
+ if (!this.config.className) {
+ this.config.className = "wysihtml-sandbox";
}
+ this.editableArea = this._createIframe();
},
- rectify: function() {
- if (!this.removeEmptyTable()) {
- this.removeSurplusLines();
- this.fillMissingCells();
- return true;
- } else {
- return false;
+ insertInto: function(element) {
+ if (typeof(element) === "string") {
+ element = doc.getElementById(element);
}
- },
- unmerge: function() {
- if (this.rectify()) {
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
-
- if (this.idx) {
- var thisCell = this.map[this.idx.row][this.idx.col],
- colspan = (api.getAttribute(thisCell.el, "colspan")) ? parseInt(api.getAttribute(thisCell.el, "colspan"), 10) : 1,
- cType = thisCell.el.tagName.toLowerCase();
-
- if (thisCell.isRowspan) {
- var rowspan = parseInt(api.getAttribute(thisCell.el, "rowspan"), 10);
- if (rowspan > 1) {
- for (var nr = 1, maxr = rowspan - 1; nr <= maxr; nr++){
- this.injectRowAt(this.idx.row + nr, this.idx.col, colspan, cType, thisCell);
- }
- }
- thisCell.el.removeAttribute('rowspan');
- }
- this.splitRowToCells(thisCell);
- }
- }
+ element.appendChild(this.editableArea);
},
- // merges cells from start cell (defined in creating obj) to "to" cell
- merge: function(to) {
- if (this.rectify()) {
- if (this.canMerge(to)) {
- var rowspan = this.idx_end.row - this.idx_start.row + 1,
- colspan = this.idx_end.col - this.idx_start.col + 1;
-
- for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
- for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
-
- if (row == this.idx_start.row && col == this.idx_start.col) {
- if (rowspan > 1) {
- this.map[row][col].el.setAttribute('rowspan', rowspan);
- }
- if (colspan > 1) {
- this.map[row][col].el.setAttribute('colspan', colspan);
- }
- } else {
- // transfer content
- if (!(/^\s*
\s*$/.test(this.map[row][col].el.innerHTML.toLowerCase()))) {
- this.map[this.idx_start.row][this.idx_start.col].el.innerHTML += ' ' + this.map[row][col].el.innerHTML;
- }
- removeElement(this.map[row][col].el);
- }
-
- }
- }
- this.rectify();
- } else {
- if (window.console) {
- console.log('Do not know how to merge allready merged cells.');
- }
- }
- }
+ getIframe: function() {
+ return this.editableArea;
},
- // Decreases rowspan of a cell if it is done on first cell of rowspan row (real cell)
- // Cell is moved to next row (if it is real)
- collapseCellToNextRow: function(cell) {
- var cellIdx = this.getMapIndex(cell.el),
- newRowIdx = cellIdx.row + 1,
- newIdx = {'row': newRowIdx, 'col': cellIdx.col};
-
- if (newRowIdx < this.map.length) {
-
- var row = this.getRealRowEl(false, newIdx);
- if (row !== null) {
- var n_cidx = this.correctColIndexForUnreals(newIdx.col, newIdx.row);
- if (n_cidx >= 0) {
- insertAfter(this.getRowCells(row)[n_cidx], cell.el);
- } else {
- var lastCell = this.getLastNewCellOnRow(row, newRowIdx);
- if (lastCell !== null) {
- insertAfter(lastCell, cell.el);
- } else {
- row.insertBefore(cell.el, row.firstChild);
- }
- }
- if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
- cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
- } else {
- cell.el.removeAttribute('rowspan');
- }
- }
- }
+ getWindow: function() {
+ this._readyError();
},
- // Removes a cell when removing a row
- // If is rowspan cell then decreases the rowspan
- // and moves cell to next row if needed (is first cell of rowspan)
- removeRowCell: function(cell) {
- if (cell.isReal) {
- if (cell.isRowspan) {
- this.collapseCellToNextRow(cell);
- } else {
- removeElement(cell.el);
- }
- } else {
- if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
- cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
- } else {
- cell.el.removeAttribute('rowspan');
- }
- }
+ getDocument: function() {
+ this._readyError();
},
- getRowElementsByCell: function() {
- var cells = [];
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (this.idx !== false) {
- var modRow = this.map[this.idx.row];
- for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
- if (modRow[cidx].isReal) {
- cells.push(modRow[cidx].el);
- }
- }
- }
- return cells;
+ destroy: function() {
+ var iframe = this.getIframe();
+ iframe.parentNode.removeChild(iframe);
},
- getColumnElementsByCell: function() {
- var cells = [];
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (this.idx !== false) {
- for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
- if (this.map[ridx][this.idx.col] && this.map[ridx][this.idx.col].isReal) {
- cells.push(this.map[ridx][this.idx.col].el);
- }
- }
- }
- return cells;
+ _readyError: function() {
+ throw new Error("wysihtml.Sandbox: Sandbox iframe isn't loaded yet");
},
- // Removes the row of selected cell
- removeRow: function() {
- var oldRow = api.getParentElement(this.cell, { query: "tr" });
- if (oldRow) {
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (this.idx !== false) {
- var modRow = this.map[this.idx.row];
- for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
- if (!modRow[cidx].modified) {
- this.setCellAsModified(modRow[cidx]);
- this.removeRowCell(modRow[cidx]);
- }
- }
- }
- removeElement(oldRow);
- }
- },
+ /**
+ * Creates the sandbox iframe
+ *
+ * Some important notes:
+ * - We can't use HTML5 sandbox for now:
+ * setting it causes that the iframe's dom can't be accessed from the outside
+ * Therefore we need to set the "allow-same-origin" flag which enables accessing the iframe's dom
+ * But then there's another problem, DOM events (focus, blur, change, keypress, ...) aren't fired.
+ * In order to make this happen we need to set the "allow-scripts" flag.
+ * A combination of allow-scripts and allow-same-origin is almost the same as setting no sandbox attribute at all.
+ * - Chrome & Safari, doesn't seem to support sandboxing correctly when the iframe's html is inlined (no physical document)
+ * - IE needs to have the security="restricted" attribute set before the iframe is
+ * inserted into the dom tree
+ * - Believe it or not but in IE "security" in document.createElement("iframe") is false, even
+ * though it supports it
+ * - When an iframe has security="restricted", in IE eval() & execScript() don't work anymore
+ * - IE doesn't fire the onload event when the content is inlined in the src attribute, therefore we rely
+ * on the onreadystatechange event
+ */
+ _createIframe: function() {
+ var that = this,
+ iframe = doc.createElement("iframe");
+ iframe.className = this.config.className;
+ wysihtml.dom.setAttributes({
+ "security": "restricted",
+ "allowtransparency": "true",
+ "frameborder": 0,
+ "width": 0,
+ "height": 0,
+ "marginwidth": 0,
+ "marginheight": 0
+ }).on(iframe);
- removeColCell: function(cell) {
- if (cell.isColspan) {
- if (parseInt(api.getAttribute(cell.el, 'colspan'), 10) > 2) {
- cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) - 1);
- } else {
- cell.el.removeAttribute('colspan');
- }
- } else if (cell.isReal) {
- removeElement(cell.el);
+ // Setting the src like this prevents ssl warnings in IE6
+ if (wysihtml.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()) {
+ iframe.src = "javascript:''";
}
- },
- removeColumn: function() {
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (this.idx !== false) {
- for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
- if (!this.map[ridx][this.idx.col].modified) {
- this.setCellAsModified(this.map[ridx][this.idx.col]);
- this.removeColCell(this.map[ridx][this.idx.col]);
- }
+ iframe.onload = function() {
+ iframe.onreadystatechange = iframe.onload = null;
+ that._onLoadIframe(iframe);
+ };
+
+ iframe.onreadystatechange = function() {
+ if (/loaded|complete/.test(iframe.readyState)) {
+ iframe.onreadystatechange = iframe.onload = null;
+ that._onLoadIframe(iframe);
}
- }
+ };
+
+ return iframe;
},
- // removes row or column by selected cell element
- remove: function(what) {
- if (this.rectify()) {
- switch (what) {
- case 'row':
- this.removeRow();
- break;
- case 'column':
- this.removeColumn();
- break;
- }
- this.rectify();
+ /**
+ * Callback for when the iframe has finished loading
+ */
+ _onLoadIframe: function(iframe) {
+ // don't resume when the iframe got unloaded (eg. by removing it from the dom)
+ if (!wysihtml.dom.contains(doc.documentElement, iframe)) {
+ return;
}
- },
- addRow: function(where) {
- var doc = this.table.ownerDocument;
+ var that = this,
+ iframeWindow = iframe.contentWindow,
+ iframeDocument = iframe.contentWindow.document,
+ charset = doc.characterSet || doc.charset || "utf-8",
+ sandboxHtml = this._getHtml({
+ charset: charset,
+ stylesheets: this.config.stylesheets
+ });
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (where == "below" && api.getAttribute(this.cell, 'rowspan')) {
- this.idx.row = this.idx.row + parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1;
- }
+ // Create the basic dom tree including proper DOCTYPE and charset
+ iframeDocument.open("text/html", "replace");
+ iframeDocument.write(sandboxHtml);
+ iframeDocument.close();
- if (this.idx !== false) {
- var modRow = this.map[this.idx.row],
- newRow = doc.createElement('tr');
+ this.getWindow = function() { return iframe.contentWindow; };
+ this.getDocument = function() { return iframe.contentWindow.document; };
- for (var ridx = 0, rmax = modRow.length; ridx < rmax; ridx++) {
- if (!modRow[ridx].modified) {
- this.setCellAsModified(modRow[ridx]);
- this.addRowCell(modRow[ridx], newRow, where);
- }
- }
+ // Catch js errors and pass them to the parent's onerror event
+ // addEventListener("error") doesn't work properly in some browsers
+ // TODO: apparently this doesn't work in IE9!
+ iframeWindow.onerror = function(errorMessage, fileName, lineNumber) {
+ throw new Error("wysihtml.Sandbox: " + errorMessage, fileName, lineNumber);
+ };
- switch (where) {
- case 'below':
- insertAfter(this.getRealRowEl(true), newRow);
- break;
- case 'above':
- var cr = api.getParentElement(this.map[this.idx.row][this.idx.col].el, { query: "tr" });
- if (cr) {
- cr.parentNode.insertBefore(newRow, cr);
- }
- break;
+ if (!wysihtml.browser.supportsSandboxedIframes()) {
+ // Unset a bunch of sensitive variables
+ // Please note: This isn't hack safe!
+ // It more or less just takes care of basic attacks and prevents accidental theft of sensitive information
+ // IE is secure though, which is the most important thing, since IE is the only browser, who
+ // takes over scripts & styles into contentEditable elements when copied from external websites
+ // or applications (Microsoft Word, ...)
+ var i, length;
+ for (i=0, length=windowProperties.length; i
';
+ }
}
+ templateVars.stylesheets = html;
+
+ return wysihtml.lang.string(
+ ''
+ + ' #{stylesheets}'
+ + ''
+ ).interpolate(templateVars);
},
- addColumn: function(where) {
- var row, modCell;
+ /**
+ * Method to unset/override existing variables
+ * @example
+ * // Make cookie unreadable and unwritable
+ * this._unset(document, "cookie", "", true);
+ */
+ _unset: function(object, property, value, setter) {
+ try { object[property] = value; } catch(e) {}
- this.setTableMap();
- this.idx = this.getMapIndex(this.cell);
- if (where == "after" && api.getAttribute(this.cell, 'colspan')) {
- this.idx.col = this.idx.col + parseInt(api.getAttribute(this.cell, 'colspan'), 10) - 1;
+ try { object.__defineGetter__(property, function() { return value; }); } catch(e) {}
+ if (setter) {
+ try { object.__defineSetter__(property, function() {}); } catch(e) {}
}
- if (this.idx !== false) {
- for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++ ) {
- row = this.map[ridx];
- if (row[this.idx.col]) {
- modCell = row[this.idx.col];
- if (!modCell.modified) {
- this.setCellAsModified(modCell);
- this.addColCell(modCell, ridx , where);
- }
+ if (!wysihtml.browser.crashesWhenDefineProperty(property)) {
+ try {
+ var config = {
+ get: function() { return value; }
+ };
+ if (setter) {
+ config.set = function() {};
}
+ Object.defineProperty(object, property, config);
+ } catch(e) {}
+ }
+ }
+ });
+})(wysihtml);
+
+(function() {
+ var mapping = {
+ "className": "class"
+ };
+ wysihtml.dom.setAttributes = function(attributes) {
+ return {
+ on: function(element) {
+ for (var i in attributes) {
+ element.setAttribute(mapping[i] || i, attributes[i]);
}
}
- },
-
- handleCellAddWithRowspan: function (cell, ridx, where) {
- var addRowsNr = parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1,
- crow = api.getParentElement(cell.el, { query: "tr" }),
- cType = cell.el.tagName.toLowerCase(),
- cidx, temp_r_cells,
- doc = this.table.ownerDocument,
- nrow;
-
- for (var i = 0; i < addRowsNr; i++) {
- cidx = this.correctColIndexForUnreals(this.idx.col, (ridx + i));
- crow = nextNode(crow, 'tr');
- if (crow) {
- if (cidx > 0) {
- switch (where) {
- case "before":
- temp_r_cells = this.getRowCells(crow);
- if (cidx > 0 && this.map[ridx + i][this.idx.col].el != temp_r_cells[cidx] && cidx == temp_r_cells.length - 1) {
- insertAfter(temp_r_cells[cidx], this.createCells(cType, 1));
- } else {
- temp_r_cells[cidx].parentNode.insertBefore(this.createCells(cType, 1), temp_r_cells[cidx]);
- }
-
- break;
- case "after":
- insertAfter(this.getRowCells(crow)[cidx], this.createCells(cType, 1));
- break;
- }
- } else {
- crow.insertBefore(this.createCells(cType, 1), crow.firstChild);
- }
+ };
+ };
+})();
+
+wysihtml.dom.setStyles = function(styles) {
+ return {
+ on: function(element) {
+ var style = element.style;
+ if (typeof(styles) === "string") {
+ style.cssText += ";" + styles;
+ return;
+ }
+ for (var i in styles) {
+ if (i === "float") {
+ style.cssFloat = styles[i];
+ style.styleFloat = styles[i];
} else {
- nrow = doc.createElement('tr');
- nrow.appendChild(this.createCells(cType, 1));
- this.table.appendChild(nrow);
+ style[i] = styles[i];
}
}
}
};
+};
- api.table = {
- getCellsBetween: function(cell1, cell2) {
- var c1 = new TableModifyerByCell(cell1);
- return c1.getMapElsTo(cell2);
- },
-
- addCells: function(cell, where) {
- var c = new TableModifyerByCell(cell);
- c.add(where);
- },
-
- removeCells: function(cell, what) {
- var c = new TableModifyerByCell(cell);
- c.remove(what);
- },
-
- mergeCellsBetween: function(cell1, cell2) {
- var c1 = new TableModifyerByCell(cell1);
- c1.merge(cell2);
- },
-
- unmergeCell: function(cell) {
- var c = new TableModifyerByCell(cell);
- c.unmerge();
- },
-
- orderSelectionEnds: function(cell, cell2) {
- var c = new TableModifyerByCell(cell);
- return c.orderSelectionEnds(cell2);
- },
-
- indexOf: function(cell) {
- var c = new TableModifyerByCell(cell);
- c.setTableMap();
- return c.getMapIndex(cell);
- },
-
- findCell: function(table, idx) {
- var c = new TableModifyerByCell(null, table);
- return c.getElementAtIndex(idx);
- },
-
- findRowByCell: function(cell) {
- var c = new TableModifyerByCell(cell);
- return c.getRowElementsByCell();
- },
+/**
+ * Simulate HTML5 placeholder attribute
+ *
+ * Needed since
+ * - div[contentEditable] elements don't support it
+ * - older browsers (such as IE8 and Firefox 3.6) don't support it at all
+ *
+ * @param {Object} parent Instance of main wysihtml.Editor class
+ * @param {Element} view Instance of wysihtml.views.* class
+ * @param {String} placeholderText
+ *
+ * @example
+ * wysihtml.dom.simulatePlaceholder(this, composer, "Foobar");
+ */
+(function(dom) {
+ dom.simulatePlaceholder = function(editor, view, placeholderText, placeholderClassName) {
+ var CLASS_NAME = placeholderClassName || "wysihtml-placeholder",
+ unset = function() {
+ var composerIsVisible = view.element.offsetWidth > 0 && view.element.offsetHeight > 0;
+ if (view.hasPlaceholderSet()) {
+ view.clear();
+ view.element.focus();
+ if (composerIsVisible ) {
+ setTimeout(function() {
+ var sel = view.selection.getSelection();
+ if (!sel.focusNode || !sel.anchorNode) {
+ view.selection.selectNode(view.element.firstChild || view.element);
+ }
+ }, 0);
+ }
+ }
+ view.placeholderSet = false;
+ dom.removeClass(view.element, CLASS_NAME);
+ },
+ set = function() {
+ if (view.isEmpty() && !view.placeholderSet) {
+ view.placeholderSet = true;
+ view.setValue(placeholderText, false);
+ dom.addClass(view.element, CLASS_NAME);
+ }
+ };
- findColumnByCell: function(cell) {
- var c = new TableModifyerByCell(cell);
- return c.getColumnElementsByCell();
- },
+ editor
+ .on("set_placeholder", set)
+ .on("unset_placeholder", unset)
+ .on("focus:composer", unset)
+ .on("paste:composer", unset)
+ .on("blur:composer", set);
- canMerge: function(cell1, cell2) {
- var c = new TableModifyerByCell(cell1);
- return c.canMerge(cell2);
- }
+ set();
};
+})(wysihtml.dom);
-})(wysihtml5);
-;// does a selector query on element or array of elements
-wysihtml5.dom.query = function(elements, query) {
- var ret = [],
- q;
-
- if (elements.nodeType) {
- elements = [elements];
- }
-
- for (var e = 0, len = elements.length; e < len; e++) {
- q = elements[e].querySelectorAll(query);
- if (q) {
- for(var i = q.length; i--; ret.unshift(q[i]));
- }
- }
- return ret;
-};
-;wysihtml5.dom.compareDocumentPosition = (function() {
+(function(dom) {
var documentElement = document.documentElement;
- if (documentElement.compareDocumentPosition) {
- return function(container, element) {
- return container.compareDocumentPosition(element);
+ if ("textContent" in documentElement) {
+ dom.setTextContent = function(element, text) {
+ element.textContent = text;
};
- } else {
- return function( container, element ) {
- // implementation borrowed from https://github.com/tmpvar/jsdom/blob/681a8524b663281a0f58348c6129c8c184efc62c/lib/jsdom/level3/core.js // MIT license
- var thisOwner, otherOwner;
-
- if( container.nodeType === 9) // Node.DOCUMENT_NODE
- thisOwner = container;
- else
- thisOwner = container.ownerDocument;
-
- if( element.nodeType === 9) // Node.DOCUMENT_NODE
- otherOwner = element;
- else
- otherOwner = element.ownerDocument;
-
- if( container === element ) return 0;
- if( container === element.ownerDocument ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
- if( container.ownerDocument === element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
- if( thisOwner !== otherOwner ) return 1; // Node.DOCUMENT_POSITION_DISCONNECTED;
- // Text nodes for attributes does not have a _parentNode. So we need to find them as attribute child.
- if( container.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && container.childNodes && wysihtml5.lang.array(container.childNodes).indexOf( element ) !== -1)
- return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+ dom.getTextContent = function(element) {
+ return element.textContent;
+ };
+ } else if ("innerText" in documentElement) {
+ dom.setTextContent = function(element, text) {
+ element.innerText = text;
+ };
- if( element.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && element.childNodes && wysihtml5.lang.array(element.childNodes).indexOf( container ) !== -1)
- return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+ dom.getTextContent = function(element) {
+ return element.innerText;
+ };
+ } else {
+ dom.setTextContent = function(element, text) {
+ element.nodeValue = text;
+ };
- var point = container;
- var parents = [ ];
- var previous = null;
- while( point ) {
- if( point == element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
- parents.push( point );
- point = point.parentNode;
- }
- point = element;
- previous = null;
- while( point ) {
- if( point == container ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
- var location_index = wysihtml5.lang.array(parents).indexOf( point );
- if( location_index !== -1) {
- var smallest_common_ancestor = parents[ location_index ];
- var this_index = wysihtml5.lang.array(smallest_common_ancestor.childNodes).indexOf( parents[location_index - 1]);//smallest_common_ancestor.childNodes.toArray().indexOf( parents[location_index - 1] );
- var other_index = wysihtml5.lang.array(smallest_common_ancestor.childNodes).indexOf( previous ); //smallest_common_ancestor.childNodes.toArray().indexOf( previous );
- if( this_index > other_index ) {
- return 2; //Node.DOCUMENT_POSITION_PRECEDING;
- }
- else {
- return 4; //Node.DOCUMENT_POSITION_FOLLOWING;
- }
- }
- previous = point;
- point = point.parentNode;
- }
- return 1; //Node.DOCUMENT_POSITION_DISCONNECTED;
+ dom.getTextContent = function(element) {
+ return element.nodeValue;
};
}
-})();
-;/* Unwraps element and returns list of childNodes that the node contained.
+})(wysihtml.dom);
+
+/* Unwraps element and returns list of childNodes that the node contained.
*
* Example:
- * var childnodes = wysihtml5.dom.unwrap(document.querySelector('.unwrap-me'));
+ * var childnodes = wysihtml.dom.unwrap(document.querySelector('.unwrap-me'));
*/
-wysihtml5.dom.unwrap = function(node) {
+wysihtml.dom.unwrap = function(node) {
var children = [];
if (node.parentNode) {
while (node.lastChild) {
children.unshift(node.lastChild);
- wysihtml5.dom.insert(node.lastChild).after(node);
+ wysihtml.dom.insert(node.lastChild).after(node);
}
node.parentNode.removeChild(node);
}
return children;
};
-;/*
- * Methods for fetching pasted html before it gets inserted into content
-**/
-
-/* Modern event.clipboardData driven approach.
- * Advantage is that it does not have to loose selection or modify dom to catch the data.
- * IE does not support though.
-**/
-wysihtml5.dom.getPastedHtml = function(event) {
- var html;
- if (wysihtml5.browser.supportsModernPaste() && event.clipboardData) {
- if (wysihtml5.lang.array(event.clipboardData.types).contains('text/html')) {
- html = event.clipboardData.getData('text/html');
- } else if (wysihtml5.lang.array(event.clipboardData.types).contains('text/plain')) {
- html = wysihtml5.lang.string(event.clipboardData.getData('text/plain')).escapeHTML(true, true);
- }
- }
- return html;
-};
-
-/* Older temprorary contenteditable as paste source catcher method for fallbacks */
-wysihtml5.dom.getPastedHtmlWithDiv = function (composer, f) {
- var selBookmark = composer.selection.getBookmark(),
- doc = composer.element.ownerDocument,
- cleanerDiv = doc.createElement('DIV'),
- scrollPos = composer.getScrollPos();
-
- doc.body.appendChild(cleanerDiv);
-
- cleanerDiv.style.width = "1px";
- cleanerDiv.style.height = "1px";
- cleanerDiv.style.overflow = "hidden";
- cleanerDiv.style.position = "absolute";
- cleanerDiv.style.top = scrollPos.y + "px";
- cleanerDiv.style.left = scrollPos.x + "px";
-
- cleanerDiv.setAttribute('contenteditable', 'true');
- cleanerDiv.focus();
- setTimeout(function () {
- var html;
-
- composer.selection.setBookmark(selBookmark);
- html = cleanerDiv.innerHTML;
- if (html && (/^ $/i).test(html.trim())) {
- html = false;
- }
- f(html);
- cleanerDiv.parentNode.removeChild(cleanerDiv);
- }, 0);
-};
-;wysihtml5.dom.removeInvisibleSpaces = function(node) {
- var textNodes = wysihtml5.dom.getTextNodes(node);
- for (var n = textNodes.length; n--;) {
- textNodes[n].nodeValue = textNodes[n].nodeValue.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
- }
-};
-;/**
+/**
* Fix most common html formatting misbehaviors of browsers implementation when inserting
* content via copy & paste contentEditable
*
* @author Christopher Blum
*/
-wysihtml5.quirks.cleanPastedHTML = (function() {
+wysihtml.quirks.cleanPastedHTML = (function() {
var styleToRegex = function (styleStr) {
- var trimmedStr = wysihtml5.lang.string(styleStr).trim(),
+ var trimmedStr = wysihtml.lang.string(styleStr).trim(),
escapedStr = trimmedStr.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
return new RegExp("^((?!^" + escapedStr + "$).)*$", "i");
};
var extendRulesWithStyleExceptions = function (rules, exceptStyles) {
- var newRules = wysihtml5.lang.object(rules).clone(true),
+ var newRules = wysihtml.lang.object(rules).clone(true),
tag, style;
for (tag in newRules.tags) {
@@ -11341,13 +10233,13 @@ wysihtml5.quirks.cleanPastedHTML = (function() {
return function(html, options) {
var exceptStyles = {
- 'color': wysihtml5.dom.getStyle("color").from(options.referenceNode),
- 'fontSize': wysihtml5.dom.getStyle("font-size").from(options.referenceNode)
+ 'color': wysihtml.dom.getStyle("color").from(options.referenceNode),
+ 'fontSize': wysihtml.dom.getStyle("font-size").from(options.referenceNode)
},
rules = extendRulesWithStyleExceptions(pickRuleset(options.rules, html) || {}, exceptStyles),
newHtml;
- newHtml = wysihtml5.dom.parse(html, {
+ newHtml = wysihtml.dom.parse(html, {
"rules": rules,
"cleanUp": true, // elements, empty or without attributes, should be removed/replaced with their content
"context": options.referenceNode.ownerDocument,
@@ -11360,14 +10252,15 @@ wysihtml5.quirks.cleanPastedHTML = (function() {
};
})();
-;/**
+
+/**
* IE and Opera leave an empty paragraph in the contentEditable element after clearing it
*
* @param {Object} contentEditableElement The contentEditable element to observe for clearing events
* @exaple
- * wysihtml5.quirks.ensureProperClearing(myContentEditableElement);
+ * wysihtml.quirks.ensureProperClearing(myContentEditableElement);
*/
-wysihtml5.quirks.ensureProperClearing = (function() {
+wysihtml.quirks.ensureProperClearing = (function() {
var clearIfNecessary = function() {
var element = this;
setTimeout(function() {
@@ -11380,10 +10273,11 @@ wysihtml5.quirks.ensureProperClearing = (function() {
};
return function(composer) {
- wysihtml5.dom.observe(composer.element, ["cut", "keydown"], clearIfNecessary);
+ wysihtml.dom.observe(composer.element, ["cut", "keydown"], clearIfNecessary);
};
})();
-;// See https://bugzilla.mozilla.org/show_bug.cgi?id=664398
+
+// See https://bugzilla.mozilla.org/show_bug.cgi?id=664398
//
// In Firefox this:
// var d = document.createElement("div");
@@ -11392,9 +10286,9 @@ wysihtml5.quirks.ensureProperClearing = (function() {
// will result in:
//
// which is wrong
-(function(wysihtml5) {
+(function(wysihtml) {
var TILDE_ESCAPED = "%7E";
- wysihtml5.quirks.getCorrectInnerHTML = function(element) {
+ wysihtml.quirks.getCorrectInnerHTML = function(element) {
var innerHTML = element.innerHTML;
if (innerHTML.indexOf(TILDE_ESCAPED) === -1) {
return innerHTML;
@@ -11407,26 +10301,27 @@ wysihtml5.quirks.ensureProperClearing = (function() {
i;
for (i=0, length=elementsWithTilde.length; i 0) {
- for (var i = 0; i < selectedCells.length; i++) {
- dom.removeClass(selectedCells[i], selection_class);
- }
- }
- }
- }
-
- function addSelections (cells) {
- for (var i = 0; i < cells.length; i++) {
- dom.addClass(cells[i], selection_class);
- }
- }
-
- function handleMouseMove (event) {
- var curTable = null,
- cell = dom.getParentElement(event.target, { query: "td, th" }, false, editable),
- oldEnd;
-
- if (cell && select.table && select.start) {
- curTable = dom.getParentElement(cell, { query: "table" }, false, editable);
- if (curTable && curTable === select.table) {
- removeCellSelections();
- oldEnd = select.end;
- select.end = cell;
- select.cells = dom.table.getCellsBetween(select.start, cell);
- if (select.cells.length > 1) {
- editor.composer.selection.deselect();
- }
- addSelections(select.cells);
- if (select.end !== oldEnd) {
- editor.fire("tableselectchange").fire("tableselectchange:composer");
- }
- }
- }
- }
-
- function handleMouseUp (event) {
- editable.removeEventListener("mousemove", handleMouseMove);
- editable.removeEventListener("mouseup", handleMouseUp);
- editor.fire("tableselect").fire("tableselect:composer");
- setTimeout(function() {
- bindSideclick();
- },0);
- }
-
- var sideClickHandler = function(event) {
- editable.ownerDocument.removeEventListener("click", sideClickHandler);
- if (dom.getParentElement(event.target, { query: "table" }, false, editable) != select.table) {
- removeCellSelections();
- select.table = null;
- select.start = null;
- select.end = null;
- editor.fire("tableunselect").fire("tableunselect:composer");
- }
- };
-
- function bindSideclick () {
- editable.ownerDocument.addEventListener("click", sideClickHandler);
- }
-
- function selectCells (start, end) {
- select.start = start;
- select.end = end;
- select.table = dom.getParentElement(select.start, { query: "table" }, false, editable);
- selectedCells = dom.table.getCellsBetween(select.start, select.end);
- addSelections(selectedCells);
- bindSideclick();
- editor.fire("tableselect").fire("tableselect:composer");
- }
-
- return init();
-
-};
-;(function(wysihtml5) {
+(function(wysihtml) {
// List of supported color format parsing methods
// If radix is not defined 10 is expected as default
@@ -11605,7 +10384,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
}
// Public API functions for styleParser
- wysihtml5.quirks.styleParser = {
+ wysihtml.quirks.styleParser = {
// Takes color string value as an argument and returns suitable parsing method for it
getColorParseMethod : getColorParseMethod,
@@ -11617,13 +10396,13 @@ wysihtml5.quirks.ensureProperClearing = (function() {
* paramName: optional argument to parse color value directly from style string parameter
*
* Examples:
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("#ABC"); // [170, 187, 204, 1]
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("#AABBCC"); // [170, 187, 204, 1]
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("rgb(1,2,3)"); // [1, 2, 3, 1]
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("rgba(1,2,3,0.5)"); // [1, 2, 3, 0.5]
+ * var colorArray = wysihtml.quirks.styleParser.parseColor("#ABC"); // [170, 187, 204, 1]
+ * var colorArray = wysihtml.quirks.styleParser.parseColor("#AABBCC"); // [170, 187, 204, 1]
+ * var colorArray = wysihtml.quirks.styleParser.parseColor("rgb(1,2,3)"); // [1, 2, 3, 1]
+ * var colorArray = wysihtml.quirks.styleParser.parseColor("rgba(1,2,3,0.5)"); // [1, 2, 3, 0.5]
*
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("background-color: #ABC; color: #000;", "background-color"); // [170, 187, 204, 1]
- * var colorArray = wysihtml5.quirks.styleParser.parseColor("background-color: #ABC; color: #000;", "color"); // [0, 0, 0, 1]
+ * var colorArray = wysihtml.quirks.styleParser.parseColor("background-color: #ABC; color: #000;", "background-color"); // [170, 187, 204, 1]
+ * var colorArray = wysihtml.quirks.styleParser.parseColor("background-color: #ABC; color: #000;", "color"); // [0, 0, 0, 1]
*/
parseColor : function (stylesStr, paramName) {
var paramsRegex, params, colorType, colorMatch, radix,
@@ -11635,7 +10414,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
if (!(params = stylesStr.match(paramsRegex))) { return false; }
params = params.pop().split(":")[1];
- colorStr = wysihtml5.lang.string(params).trim();
+ colorStr = wysihtml.lang.string(params).trim();
}
if (!(colorType = getColorParseMethod(colorStr))) { return false; }
@@ -11646,7 +10425,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
if (colorType === colorParseMethods.hex3) {
colorMatch.shift();
colorMatch.push(1);
- return wysihtml5.lang.array(colorMatch).map(function(d, idx) {
+ return wysihtml.lang.array(colorMatch).map(function(d, idx) {
return (idx < 3) ? (parseInt(d, radix) * radix) + parseInt(d, radix): parseFloat(d);
});
}
@@ -11657,7 +10436,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
colorMatch.push(1);
}
- return wysihtml5.lang.array(colorMatch).map(function(d, idx) {
+ return wysihtml.lang.array(colorMatch).map(function(d, idx) {
return (idx < 3) ? parseInt(d, radix): parseFloat(d);
});
},
@@ -11666,14 +10445,14 @@ wysihtml5.quirks.ensureProperClearing = (function() {
* If no format is given, rgba/rgb is returned based on alpha value
*
* Example:
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1], "hash"); // "#AABBCC"
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1], "hex"); // "AABBCC"
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1], "csv"); // "170, 187, 204, 1"
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1], "rgba"); // "rgba(170,187,204,1)"
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1], "rgb"); // "rgb(170,187,204)"
+ * var colorStr = wysihtml.quirks.styleParser.unparseColor([170, 187, 204, 1], "hash"); // "#AABBCC"
+ * var colorStr = wysihtml.quirks.styleParser.unparseColor([170, 187, 204, 1], "hex"); // "AABBCC"
+ * var colorStr = wysihtml.quirks.styleParser.unparseColor([170, 187, 204, 1], "csv"); // "170, 187, 204, 1"
+ * var colorStr = wysihtml.quirks.styleParser.unparseColor([170, 187, 204, 1], "rgba"); // "rgba(170,187,204,1)"
+ * var colorStr = wysihtml.quirks.styleParser.unparseColor([170, 187, 204, 1], "rgb"); // "rgb(170,187,204)"
*
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 0.5]); // "rgba(170,187,204,0.5)"
- * var colorStr = wysihtml5.quirks.styleParser.unparseColor([170, 187, 204, 1]); // "rgb(170,187,204)"
+ * var colorStr = wysihtml.quirks.styleParser.unparseColor([170, 187, 204, 0.5]); // "rgba(170,187,204,0.5)"
+ * var colorStr = wysihtml.quirks.styleParser.unparseColor([170, 187, 204, 1]); // "rgb(170,187,204)"
*/
unparseColor: function(val, colorFormat) {
var hexRadix = 16;
@@ -11701,21 +10480,22 @@ wysihtml5.quirks.ensureProperClearing = (function() {
parseFontSize: function(stylesStr) {
var params = stylesStr.match(makeParamRegExp("font-size"));
if (params) {
- return wysihtml5.lang.string(params[params.length - 1].split(":")[1]).trim();
+ return wysihtml.lang.string(params[params.length - 1].split(":")[1]).trim();
}
return false;
}
};
-})(wysihtml5);
-;/**
+})(wysihtml);
+
+/**
* Selection API
*
* @example
- * var selection = new wysihtml5.Selection(editor);
+ * var selection = new wysihtml.Selection(editor);
*/
-(function(wysihtml5) {
- var dom = wysihtml5.dom;
+(function(wysihtml) {
+ var dom = wysihtml.dom;
function _getCumulativeOffsetTop(element) {
var top = 0;
@@ -11774,8 +10554,8 @@ wysihtml5.quirks.ensureProperClearing = (function() {
}
};
- blankNode.appendChild(container.ownerDocument.createTextNode(wysihtml5.INVISIBLE_SPACE));
- blankNode.className = '_wysihtml5-temp-caret-fix';
+ blankNode.appendChild(container.ownerDocument.createTextNode(wysihtml.INVISIBLE_SPACE));
+ blankNode.className = '_wysihtml-temp-caret-fix';
blankNode.style.display = 'block';
blankNode.style.minWidth = '1px';
blankNode.style.height = '0px';
@@ -11814,8 +10594,8 @@ wysihtml5.quirks.ensureProperClearing = (function() {
}
}
- wysihtml5.Selection = Base.extend(
- /** @scope wysihtml5.Selection.prototype */ {
+ wysihtml.Selection = Base.extend(
+ /** @scope wysihtml.Selection.prototype */ {
constructor: function(editor, contain, unselectableClass) {
// Make sure that our external range library is initialized
rangy.init();
@@ -11839,7 +10619,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
},
/**
- * Restore a selection retrieved via wysihtml5.Selection.prototype.getBookmark
+ * Restore a selection retrieved via wysihtml.Selection.prototype.getBookmark
*
* @param {Object} bookmark An object that represents the current selection
*/
@@ -11869,7 +10649,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
// Webkit has an issue with placing caret into places where there are no textnodes near by.
createTemporaryCaretSpaceAfter: function (node) {
var caretPlaceholder = this.doc.createElement('span'),
- caretPlaceholderText = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE),
+ caretPlaceholderText = this.doc.createTextNode(wysihtml.INVISIBLE_SPACE),
placeholderRemover = (function(event) {
// Self-destructs the caret and keeps the text inserted into it by user
var lastChild;
@@ -11886,10 +10666,10 @@ wysihtml5.quirks.ensureProperClearing = (function() {
// If user inserted sth it is in the placeholder and sgould be unwrapped and stripped of invisible whitespace hack
// Otherwise the wrapper can just be removed
if (caretPlaceholder && caretPlaceholder.parentNode) {
- caretPlaceholder.innerHTML = caretPlaceholder.innerHTML.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+ caretPlaceholder.innerHTML = caretPlaceholder.innerHTML.replace(wysihtml.INVISIBLE_SPACE_REG_EXP, "");
if ((/[^\s]+/).test(caretPlaceholder.innerHTML)) {
lastChild = caretPlaceholder.lastChild;
- wysihtml5.dom.unwrap(caretPlaceholder);
+ wysihtml.dom.unwrap(caretPlaceholder);
this.setAfter(lastChild);
} else {
caretPlaceholder.parentNode.removeChild(caretPlaceholder);
@@ -11908,7 +10688,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
}
};
- caretPlaceholder.className = '_wysihtml5-temp-caret-fix';
+ caretPlaceholder.className = '_wysihtml-temp-caret-fix';
caretPlaceholder.style.position = 'absolute';
caretPlaceholder.style.display = 'block';
caretPlaceholder.style.minWidth = '1px';
@@ -11952,7 +10732,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
if (notVisual) {
// If setAfter is used as internal between actions, self-removing caretPlaceholder has simpler implementation
// and remove itself in call stack end instead on user interaction
- var caretPlaceholder = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ var caretPlaceholder = this.doc.createTextNode(wysihtml.INVISIBLE_SPACE);
node.parentNode.insertBefore(caretPlaceholder, node.nextSibling);
this.selectNode(caretPlaceholder);
setTimeout(function() {
@@ -12001,16 +10781,16 @@ wysihtml5.quirks.ensureProperClearing = (function() {
*/
selectNode: function(node, avoidInvisibleSpace) {
var range = rangy.createRange(this.doc),
- isElement = node.nodeType === wysihtml5.ELEMENT_NODE,
+ isElement = node.nodeType === wysihtml.ELEMENT_NODE,
canHaveHTML = "canHaveHTML" in node ? node.canHaveHTML : (node.nodeName !== "IMG"),
content = isElement ? node.innerHTML : node.data,
- isEmpty = (content === "" || content === wysihtml5.INVISIBLE_SPACE),
+ isEmpty = (content === "" || content === wysihtml.INVISIBLE_SPACE),
displayStyle = dom.getStyle("display").from(node),
isBlockElement = (displayStyle === "block" || displayStyle === "list-item");
if (isEmpty && isElement && canHaveHTML && !avoidInvisibleSpace) {
// Make sure that caret is visible in node by inserting a zero width no breaking space
- try { node.innerHTML = wysihtml5.INVISIBLE_SPACE; } catch(e) {}
+ try { node.innerHTML = wysihtml.INVISIBLE_SPACE; } catch(e) {}
}
if (canHaveHTML) {
range.selectNodeContents(node);
@@ -12078,7 +10858,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
nodes = [], curNodes;
for (var i = 0, maxi = ranges.length; i < maxi; i++) {
curNodes = ranges[i].getNodes([1], function(node) {
- return wysihtml5.lang.array(nodeTypes).contains(node.nodeName);
+ return wysihtml.lang.array(nodeTypes).contains(node.nodeName);
});
nodes = nodes.concat(curNodes);
}
@@ -12112,7 +10892,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
},
// Deletes selection contents making sure uneditables/unselectables are not partially deleted
- // Triggers wysihtml5:uneditable:delete custom event on all deleted uneditables if customevents suppoorted
+ // Triggers wysihtml:uneditable:delete custom event on all deleted uneditables if customevents suppoorted
deleteContents: function() {
var range = this.getRange();
this.deleteRangeContents(range);
@@ -12124,20 +10904,20 @@ wysihtml5.quirks.ensureProperClearing = (function() {
var startParent, endParent, uneditables, ev;
if (this.unselectableClass) {
- if ((startParent = wysihtml5.dom.getParentElement(range.startContainer, { query: "." + this.unselectableClass }, false, this.contain))) {
+ if ((startParent = wysihtml.dom.getParentElement(range.startContainer, { query: "." + this.unselectableClass }, false, this.contain))) {
range.setStartBefore(startParent);
}
- if ((endParent = wysihtml5.dom.getParentElement(range.endContainer, { query: "." + this.unselectableClass }, false, this.contain))) {
+ if ((endParent = wysihtml.dom.getParentElement(range.endContainer, { query: "." + this.unselectableClass }, false, this.contain))) {
range.setEndAfter(endParent);
}
// If customevents present notify uneditable elements of being deleted
uneditables = range.getNodes([1], (function (node) {
- return wysihtml5.dom.hasClass(node, this.unselectableClass);
+ return wysihtml.dom.hasClass(node, this.unselectableClass);
}).bind(this));
for (var i = uneditables.length; i--;) {
try {
- ev = new CustomEvent("wysihtml5:uneditable:delete");
+ ev = new CustomEvent("wysihtml:uneditable:delete");
uneditables[i].dispatchEvent(ev);
} catch (err) {}
}
@@ -12177,10 +10957,10 @@ wysihtml5.quirks.ensureProperClearing = (function() {
} else if (ignoreEmpty && ret && ret.nodeType === 1) {
// Do not count empty nodes if param set.
// Contenteditable tends to bypass and delete these silently when deleting with caret when element is inline-like
- displayStyle = wysihtml5.dom.getStyle("display").from(ret);
+ displayStyle = wysihtml.dom.getStyle("display").from(ret);
if (
- !wysihtml5.lang.array(["BR", "HR", "IMG"]).contains(ret.nodeName) &&
- !wysihtml5.lang.array(["block", "inline-block", "flex", "list-item", "table"]).contains(displayStyle) &&
+ !wysihtml.lang.array(["BR", "HR", "IMG"]).contains(ret.nodeName) &&
+ !wysihtml.lang.array(["block", "inline-block", "flex", "list-item", "table"]).contains(displayStyle) &&
(/^[\s]*$/).test(ret.innerHTML)
) {
ret = this.getPreviousNode(ret, ignoreEmpty);
@@ -12244,7 +11024,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
curEl, parents = [];
for (var i = 0, maxi = nodes.length; i < maxi; i++) {
- curEl = (nodes[i].nodeName && nodes[i].nodeName === 'LI') ? nodes[i] : wysihtml5.dom.getParentElement(nodes[i], { query: 'li'}, false, this.contain);
+ curEl = (nodes[i].nodeName && nodes[i].nodeName === 'LI') ? nodes[i] : wysihtml.dom.getParentElement(nodes[i], { query: 'li'}, false, this.contain);
if (curEl) {
parents.push(curEl);
}
@@ -12281,16 +11061,16 @@ wysihtml5.quirks.ensureProperClearing = (function() {
startNode = getRangeNode(range.startContainer, range.startOffset);
if (startNode) {
- if (startNode.nodeType === wysihtml5.TEXT_NODE) {
+ if (startNode.nodeType === wysihtml.TEXT_NODE) {
if (!startNode.parentNode) {
return false;
}
- if (!this.isCollapsed() || (startNode.parentNode.firstChild !== startNode && !wysihtml5.dom.domNode(startNode.previousSibling).is.block())) {
+ if (!this.isCollapsed() || (startNode.parentNode.firstChild !== startNode && !wysihtml.dom.domNode(startNode.previousSibling).is.block())) {
return false;
}
var ws = this.win.getComputedStyle(startNode.parentNode).whiteSpace;
return (ws === "pre" || ws === "pre-wrap") ? range.startOffset === 0 : (/^\s*$/).test(startNode.data.substr(0,range.startOffset));
- } else if (includeLineBreaks && wysihtml5.dom.domNode(startNode).is.lineBreak()) {
+ } else if (includeLineBreaks && wysihtml.dom.domNode(startNode).is.lineBreak()) {
return true;
} else {
r.selectNodeContents(this.getRange().commonAncestorContainer);
@@ -12305,7 +11085,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
node = selection.anchorNode,
offset = selection.anchorOffset;
if (ofNode && node) {
- return (offset === 0 && (node.nodeName && node.nodeName === ofNode.toUpperCase() || wysihtml5.dom.getParentElement(node.parentNode, { query: ofNode }, 1)));
+ return (offset === 0 && (node.nodeName && node.nodeName === ofNode.toUpperCase() || wysihtml.dom.getParentElement(node.parentNode, { query: ofNode }, 1)));
} else if (node) {
return (offset === 0 && !this.getPreviousNode(node, true));
}
@@ -12325,7 +11105,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
}
// Escape temproray helper nodes if selection in them
- inTmpCaret = wysihtml5.dom.getParentElement(startNode, { query: '._wysihtml5-temp-caret-fix' }, 1);
+ inTmpCaret = wysihtml.dom.getParentElement(startNode, { query: '._wysihtml-temp-caret-fix' }, 1);
if (inTmpCaret) {
startNode = inTmpCaret.parentNode;
startOffset = Array.prototype.indexOf.call(startNode.childNodes, inTmpCaret);
@@ -12361,10 +11141,10 @@ wysihtml5.quirks.ensureProperClearing = (function() {
prevLeaf = null;
if(prevNode) {
- if (prevNode.nodeType === 1 && wysihtml5.dom.hasClass(prevNode, this.unselectableClass)) {
+ if (prevNode.nodeType === 1 && wysihtml.dom.hasClass(prevNode, this.unselectableClass)) {
prevLeaf = prevNode;
} else {
- prevLeaf = wysihtml5.dom.domNode(prevNode).lastLeafNode();
+ prevLeaf = wysihtml.dom.domNode(prevNode).lastLeafNode();
}
}
@@ -12409,8 +11189,8 @@ wysihtml5.quirks.ensureProperClearing = (function() {
var body = this.doc.body,
oldScrollTop = restoreScrollPosition && body.scrollTop,
oldScrollLeft = restoreScrollPosition && body.scrollLeft,
- className = "_wysihtml5-temp-placeholder",
- placeholderHtml = '' + wysihtml5.INVISIBLE_SPACE + ' ',
+ className = "_wysihtml-temp-placeholder",
+ placeholderHtml = '' + wysihtml.INVISIBLE_SPACE + ' ',
range = this.getRange(true),
caretPlaceholder,
newCaretPlaceholder,
@@ -12459,7 +11239,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
newRange.setStartBefore(nextSibling);
newRange.setEndAfter(prevSibling);
} else {
- newCaretPlaceholder = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ newCaretPlaceholder = this.doc.createTextNode(wysihtml.INVISIBLE_SPACE);
dom.insert(newCaretPlaceholder).after(caretPlaceholder[0]);
newRange.setStartBefore(newCaretPlaceholder);
newRange.setEndAfter(newCaretPlaceholder);
@@ -12573,7 +11353,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
// Empty elements are cleaned up from extracted content
for (var i = childNodes.length; i --;) {
- if (!wysihtml5.dom.domNode(childNodes[i]).is.visible()) {
+ if (!wysihtml.dom.domNode(childNodes[i]).is.visible()) {
contentAfterRangeStart.removeChild(childNodes[i]);
}
}
@@ -12597,8 +11377,8 @@ wysihtml5.quirks.ensureProperClearing = (function() {
range.setEndAfter(element);
}
- if (!wysihtml5.dom.domNode(element).is.visible()) {
- if (wysihtml5.dom.getTextContent(element) === '') {
+ if (!wysihtml.dom.domNode(element).is.visible()) {
+ if (wysihtml.dom.getTextContent(element) === '') {
element.parentNode.removeChild(element);
} else {
element.parentNode.replaceChild(this.doc.createTextNode(" "), element);
@@ -12654,10 +11434,10 @@ wysihtml5.quirks.ensureProperClearing = (function() {
var doc = this.doc,
tolerance = 5, // px
hasScrollBars = doc.documentElement.scrollHeight > doc.documentElement.offsetHeight,
- tempElement = doc._wysihtml5ScrollIntoViewElement = doc._wysihtml5ScrollIntoViewElement || (function() {
+ tempElement = doc._wysihtmlScrollIntoViewElement = doc._wysihtmlScrollIntoViewElement || (function() {
var element = doc.createElement("span");
// The element needs content in order to be able to calculate it's position properly
- element.innerHTML = wysihtml5.INVISIBLE_SPACE;
+ element.innerHTML = wysihtml.INVISIBLE_SPACE;
return element;
})(),
offsetTop;
@@ -12677,7 +11457,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
*/
selectLine: function() {
var r = rangy.createRange();
- if (wysihtml5.browser.supportsSelectionModify()) {
+ if (wysihtml.browser.supportsSelectionModify()) {
this._selectLine_W3C();
} else if (r.nativeRange && r.nativeRange.getBoundingClientRect) {
// For IE Edge as it ditched the old api and did not fully implement the new one (as expected)
@@ -12735,7 +11515,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
// collapses selection to current line beginning or end
toLineBoundary: function (location, collapse) {
collapse = (typeof collapse === 'undefined') ? false : collapse;
- if (wysihtml5.browser.supportsSelectionModify()) {
+ if (wysihtml.browser.supportsSelectionModify()) {
var selection = this.win.getSelection();
selection.modify("extend", location, "lineboundary");
@@ -12783,7 +11563,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
amount, testRect, found,
that = this,
isLineBreakingElement = function(el) {
- return el && el.nodeType === 1 && (that.win.getComputedStyle(el).display === "block" || wysihtml5.lang.array(['BR', 'HR']).contains(el.nodeName));
+ return el && el.nodeType === 1 && (that.win.getComputedStyle(el).display === "block" || wysihtml.lang.array(['BR', 'HR']).contains(el.nodeName));
},
prevNode = function(node) {
var pnode = node;
@@ -12819,7 +11599,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
}
}
if (!r.collapsed) {
- r.insertNode(this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE));
+ r.insertNode(this.doc.createTextNode(wysihtml.INVISIBLE_SPACE));
}
// Is probably just empty line as can not be expanded
@@ -12948,7 +11728,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
var allUneditables = dom.query(this.contain, '.' + this.unselectableClass),
deepUneditables = dom.query(allUneditables, '.' + this.unselectableClass);
- return wysihtml5.lang.array(allUneditables).without(deepUneditables);
+ return wysihtml.lang.array(allUneditables).without(deepUneditables);
},
// Returns an array of ranges that belong only to this editable
@@ -13030,7 +11810,7 @@ wysihtml5.quirks.ensureProperClearing = (function() {
return !s || (s.nativeSelection && s.nativeSelection.type && (s.nativeSelection.type === "Caret" || s.nativeSelection.type === "None"));
}
- wysihtml5.dom.removeInvisibleSpaces(this.composer.element);
+ wysihtml.dom.removeInvisibleSpaces(this.composer.element);
doSelect();
if (this.composer.element.firstChild && notSelected()) {
@@ -13056,741 +11836,98 @@ wysihtml5.quirks.ensureProperClearing = (function() {
},
createRange: function() {
- return rangy.createRange(this.doc);
- },
-
- isCollapsed: function() {
- return this.getSelection().isCollapsed;
- },
-
- getHtml: function() {
- return this.getSelection().toHtml();
- },
-
- getPlainText: function () {
- return this.getSelection().toString();
- },
-
- isEndToEndInNode: function(nodeNames) {
- var range = this.getRange(),
- parentElement = range.commonAncestorContainer,
- startNode = range.startContainer,
- endNode = range.endContainer;
-
-
- if (parentElement.nodeType === wysihtml5.TEXT_NODE) {
- parentElement = parentElement.parentNode;
- }
-
- if (startNode.nodeType === wysihtml5.TEXT_NODE && !(/^\s*$/).test(startNode.data.substr(range.startOffset))) {
- return false;
- }
-
- if (endNode.nodeType === wysihtml5.TEXT_NODE && !(/^\s*$/).test(endNode.data.substr(range.endOffset))) {
- return false;
- }
-
- while (startNode && startNode !== parentElement) {
- if (startNode.nodeType !== wysihtml5.TEXT_NODE && !wysihtml5.dom.contains(parentElement, startNode)) {
- return false;
- }
- if (wysihtml5.dom.domNode(startNode).prev({ignoreBlankTexts: true})) {
- return false;
- }
- startNode = startNode.parentNode;
- }
-
- while (endNode && endNode !== parentElement) {
- if (endNode.nodeType !== wysihtml5.TEXT_NODE && !wysihtml5.dom.contains(parentElement, endNode)) {
- return false;
- }
- if (wysihtml5.dom.domNode(endNode).next({ignoreBlankTexts: true})) {
- return false;
- }
- endNode = endNode.parentNode;
- }
-
- return (wysihtml5.lang.array(nodeNames).contains(parentElement.nodeName)) ? parentElement : false;
- },
-
- isInThisEditable: function() {
- var sel = this.getSelection(),
- fnode = sel.focusNode,
- anode = sel.anchorNode;
-
- // In IE node contains will not work for textnodes, thus taking parentNode
- if (fnode && fnode.nodeType !== 1) {
- fnode = fnode.parentNode;
- }
-
- if (anode && anode.nodeType !== 1) {
- anode = anode.parentNode;
- }
-
- return anode && fnode &&
- (wysihtml5.dom.contains(this.composer.element, fnode) || this.composer.element === fnode) &&
- (wysihtml5.dom.contains(this.composer.element, anode) || this.composer.element === anode);
- },
-
- deselect: function() {
- var sel = this.getSelection();
- sel && sel.removeAllRanges();
- }
- });
-
-})(wysihtml5);
-;/**
- * Inspired by the rangy CSS Applier module written by Tim Down and licensed under the MIT license.
- * http://code.google.com/p/rangy/
- *
- * changed in order to be able ...
- * - to use custom tags
- * - to detect and replace similar css classes via reg exp
- */
-(function(wysihtml5, rangy) {
- var defaultTagName = "span";
-
- var REG_EXP_WHITE_SPACE = /\s+/g;
-
- function hasClass(el, cssClass, regExp) {
- if (!el.className) {
- return false;
- }
-
- var matchingClassNames = el.className.match(regExp) || [];
- return matchingClassNames[matchingClassNames.length - 1] === cssClass;
- }
-
- function hasStyleAttr(el, regExp) {
- if (!el.getAttribute || !el.getAttribute('style')) {
- return false;
- }
- var matchingStyles = el.getAttribute('style').match(regExp);
- return (el.getAttribute('style').match(regExp)) ? true : false;
- }
-
- function addStyle(el, cssStyle, regExp) {
- if (el.getAttribute('style')) {
- removeStyle(el, regExp);
- if (el.getAttribute('style') && !(/^\s*$/).test(el.getAttribute('style'))) {
- el.setAttribute('style', cssStyle + ";" + el.getAttribute('style'));
- } else {
- el.setAttribute('style', cssStyle);
- }
- } else {
- el.setAttribute('style', cssStyle);
- }
- }
-
- function addClass(el, cssClass, regExp) {
- if (el.className) {
- removeClass(el, regExp);
- el.className += " " + cssClass;
- } else {
- el.className = cssClass;
- }
- }
-
- function removeClass(el, regExp) {
- if (el.className) {
- el.className = el.className.replace(regExp, "");
- }
- }
-
- function removeStyle(el, regExp) {
- var s,
- s2 = [];
- if (el.getAttribute('style')) {
- s = el.getAttribute('style').split(';');
- for (var i = s.length; i--;) {
- if (!s[i].match(regExp) && !(/^\s*$/).test(s[i])) {
- s2.push(s[i]);
- }
- }
- if (s2.length) {
- el.setAttribute('style', s2.join(';'));
- } else {
- el.removeAttribute('style');
- }
- }
- }
-
- function getMatchingStyleRegexp(el, style) {
- var regexes = [],
- sSplit = style.split(';'),
- elStyle = el.getAttribute('style');
-
- if (elStyle) {
- elStyle = elStyle.replace(/\s/gi, '').toLowerCase();
- regexes.push(new RegExp("(^|\\s|;)" + style.replace(/\s/gi, '').replace(/([\(\)])/gi, "\\$1").toLowerCase().replace(";", ";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi, "\\s?rgb\\($1,\\s?$2,\\s?$3\\)"), "gi"));
-
- for (var i = sSplit.length; i-- > 0;) {
- if (!(/^\s*$/).test(sSplit[i])) {
- regexes.push(new RegExp("(^|\\s|;)" + sSplit[i].replace(/\s/gi, '').replace(/([\(\)])/gi, "\\$1").toLowerCase().replace(";", ";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi, "\\s?rgb\\($1,\\s?$2,\\s?$3\\)"), "gi"));
- }
- }
- for (var j = 0, jmax = regexes.length; j < jmax; j++) {
- if (elStyle.match(regexes[j])) {
- return regexes[j];
- }
- }
- }
-
- return false;
- }
-
- function isMatchingAllready(node, tags, style, className) {
- if (style) {
- return getMatchingStyleRegexp(node, style);
- } else if (className) {
- return wysihtml5.dom.hasClass(node, className);
- } else {
- return rangy.dom.arrayContains(tags, node.tagName.toLowerCase());
- }
- }
-
- function areMatchingAllready(nodes, tags, style, className) {
- for (var i = nodes.length; i--;) {
- if (!isMatchingAllready(nodes[i], tags, style, className)) {
- return false;
- }
- }
- return nodes.length ? true : false;
- }
-
- function removeOrChangeStyle(el, style, regExp) {
-
- var exactRegex = getMatchingStyleRegexp(el, style);
- if (exactRegex) {
- // adding same style value on property again removes style
- removeStyle(el, exactRegex);
- return "remove";
- } else {
- // adding new style value changes value
- addStyle(el, style, regExp);
- return "change";
- }
- }
-
- function hasSameClasses(el1, el2) {
- return el1.className.replace(REG_EXP_WHITE_SPACE, " ") == el2.className.replace(REG_EXP_WHITE_SPACE, " ");
- }
-
- function replaceWithOwnChildren(el) {
- var parent = el.parentNode;
- while (el.firstChild) {
- parent.insertBefore(el.firstChild, el);
- }
- parent.removeChild(el);
- }
-
- function elementsHaveSameNonClassAttributes(el1, el2) {
- if (el1.attributes.length != el2.attributes.length) {
- return false;
- }
- for (var i = 0, len = el1.attributes.length, attr1, attr2, name; i < len; ++i) {
- attr1 = el1.attributes[i];
- name = attr1.name;
- if (name != "class") {
- attr2 = el2.attributes.getNamedItem(name);
- if (attr1.specified != attr2.specified) {
- return false;
- }
- if (attr1.specified && attr1.nodeValue !== attr2.nodeValue) {
- return false;
- }
- }
- }
- return true;
- }
-
- function isSplitPoint(node, offset) {
- if (rangy.dom.isCharacterDataNode(node)) {
- if (offset == 0) {
- return !!node.previousSibling;
- } else if (offset == node.length) {
- return !!node.nextSibling;
- } else {
- return true;
- }
- }
-
- return offset > 0 && offset < node.childNodes.length;
- }
-
- function splitNodeAt(node, descendantNode, descendantOffset, container) {
- var newNode;
- if (rangy.dom.isCharacterDataNode(descendantNode)) {
- if (descendantOffset == 0) {
- descendantOffset = rangy.dom.getNodeIndex(descendantNode);
- descendantNode = descendantNode.parentNode;
- } else if (descendantOffset == descendantNode.length) {
- descendantOffset = rangy.dom.getNodeIndex(descendantNode) + 1;
- descendantNode = descendantNode.parentNode;
- } else {
- newNode = rangy.dom.splitDataNode(descendantNode, descendantOffset);
- }
- }
- if (!newNode) {
- if (!container || descendantNode !== container) {
-
- newNode = descendantNode.cloneNode(false);
- if (newNode.id) {
- newNode.removeAttribute("id");
- }
- var child;
- while ((child = descendantNode.childNodes[descendantOffset])) {
- newNode.appendChild(child);
- }
- rangy.dom.insertAfter(newNode, descendantNode);
-
- }
- }
- return (descendantNode == node) ? newNode : splitNodeAt(node, newNode.parentNode, rangy.dom.getNodeIndex(newNode), container);
- }
-
- function Merge(firstNode) {
- this.isElementMerge = (firstNode.nodeType == wysihtml5.ELEMENT_NODE);
- this.firstTextNode = this.isElementMerge ? firstNode.lastChild : firstNode;
- this.textNodes = [this.firstTextNode];
- }
-
- Merge.prototype = {
- doMerge: function() {
- var textBits = [], textNode, parent, text;
- for (var i = 0, len = this.textNodes.length; i < len; ++i) {
- textNode = this.textNodes[i];
- parent = textNode.parentNode;
- textBits[i] = textNode.data;
- if (i) {
- parent.removeChild(textNode);
- if (!parent.hasChildNodes()) {
- parent.parentNode.removeChild(parent);
- }
- }
- }
- this.firstTextNode.data = text = textBits.join("");
- return text;
- },
-
- getLength: function() {
- var i = this.textNodes.length, len = 0;
- while (i--) {
- len += this.textNodes[i].length;
- }
- return len;
- },
-
- toString: function() {
- var textBits = [];
- for (var i = 0, len = this.textNodes.length; i < len; ++i) {
- textBits[i] = "'" + this.textNodes[i].data + "'";
- }
- return "[Merge(" + textBits.join(",") + ")]";
- }
- };
-
- function HTMLApplier(tagNames, cssClass, similarClassRegExp, normalize, cssStyle, similarStyleRegExp, container) {
- this.tagNames = tagNames || [defaultTagName];
- this.cssClass = cssClass || ((cssClass === false) ? false : "");
- this.similarClassRegExp = similarClassRegExp;
- this.cssStyle = cssStyle || "";
- this.similarStyleRegExp = similarStyleRegExp;
- this.normalize = normalize;
- this.applyToAnyTagName = false;
- this.container = container;
- }
-
- HTMLApplier.prototype = {
- getAncestorWithClass: function(node) {
- var cssClassMatch;
- while (node) {
- cssClassMatch = this.cssClass ? hasClass(node, this.cssClass, this.similarClassRegExp) : (this.cssStyle !== "") ? false : true;
- if (node.nodeType == wysihtml5.ELEMENT_NODE && node.getAttribute("contenteditable") != "false" && rangy.dom.arrayContains(this.tagNames, node.tagName.toLowerCase()) && cssClassMatch) {
- return node;
- }
- node = node.parentNode;
- }
- return false;
- },
-
- // returns parents of node with given style attribute
- getAncestorWithStyle: function(node) {
- var cssStyleMatch;
- while (node) {
- cssStyleMatch = this.cssStyle ? hasStyleAttr(node, this.similarStyleRegExp) : false;
-
- if (node.nodeType == wysihtml5.ELEMENT_NODE && node.getAttribute("contenteditable") != "false" && rangy.dom.arrayContains(this.tagNames, node.tagName.toLowerCase()) && cssStyleMatch) {
- return node;
- }
- node = node.parentNode;
- }
- return false;
- },
-
- getMatchingAncestor: function(node) {
- var ancestor = this.getAncestorWithClass(node),
- matchType = false;
-
- if (!ancestor) {
- ancestor = this.getAncestorWithStyle(node);
- if (ancestor) {
- matchType = "style";
- }
- } else {
- if (this.cssStyle) {
- matchType = "class";
- }
- }
-
- return {
- "element": ancestor,
- "type": matchType
- };
- },
-
- // Normalizes nodes after applying a CSS class to a Range.
- postApply: function(textNodes, range) {
- var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
-
- var merges = [], currentMerge;
-
- var rangeStartNode = firstNode, rangeEndNode = lastNode;
- var rangeStartOffset = 0, rangeEndOffset = lastNode.length;
-
- var textNode, precedingTextNode;
-
- for (var i = 0, len = textNodes.length; i < len; ++i) {
- textNode = textNodes[i];
- precedingTextNode = null;
- if (textNode && textNode.parentNode) {
- precedingTextNode = this.getAdjacentMergeableTextNode(textNode.parentNode, false);
- }
- if (precedingTextNode) {
- if (!currentMerge) {
- currentMerge = new Merge(precedingTextNode);
- merges.push(currentMerge);
- }
- currentMerge.textNodes.push(textNode);
- if (textNode === firstNode) {
- rangeStartNode = currentMerge.firstTextNode;
- rangeStartOffset = rangeStartNode.length;
- }
- if (textNode === lastNode) {
- rangeEndNode = currentMerge.firstTextNode;
- rangeEndOffset = currentMerge.getLength();
- }
- } else {
- currentMerge = null;
- }
- }
- // Test whether the first node after the range needs merging
- if(lastNode && lastNode.parentNode) {
- var nextTextNode = this.getAdjacentMergeableTextNode(lastNode.parentNode, true);
- if (nextTextNode) {
- if (!currentMerge) {
- currentMerge = new Merge(lastNode);
- merges.push(currentMerge);
- }
- currentMerge.textNodes.push(nextTextNode);
- }
- }
- // Do the merges
- if (merges.length) {
- for (i = 0, len = merges.length; i < len; ++i) {
- merges[i].doMerge();
- }
- // Set the range boundaries
- range.setStart(rangeStartNode, rangeStartOffset);
- range.setEnd(rangeEndNode, rangeEndOffset);
- }
- },
-
- getAdjacentMergeableTextNode: function(node, forward) {
- var isTextNode = (node.nodeType == wysihtml5.TEXT_NODE);
- var el = isTextNode ? node.parentNode : node;
- var adjacentNode;
- var propName = forward ? "nextSibling" : "previousSibling";
- if (isTextNode) {
- // Can merge if the node's previous/next sibling is a text node
- adjacentNode = node[propName];
- if (adjacentNode && adjacentNode.nodeType == wysihtml5.TEXT_NODE) {
- return adjacentNode;
- }
- } else {
- // Compare element with its sibling
- adjacentNode = el[propName];
- if (adjacentNode && this.areElementsMergeable(node, adjacentNode)) {
- return adjacentNode[forward ? "firstChild" : "lastChild"];
- }
- }
- return null;
- },
-
- areElementsMergeable: function(el1, el2) {
- return rangy.dom.arrayContains(this.tagNames, (el1.tagName || "").toLowerCase())
- && rangy.dom.arrayContains(this.tagNames, (el2.tagName || "").toLowerCase())
- && hasSameClasses(el1, el2)
- && elementsHaveSameNonClassAttributes(el1, el2);
- },
-
- createContainer: function(doc) {
- var el = doc.createElement(this.tagNames[0]);
- if (this.cssClass) {
- el.className = this.cssClass;
- }
- if (this.cssStyle) {
- el.setAttribute('style', this.cssStyle);
- }
- return el;
- },
-
- applyToTextNode: function(textNode) {
- var parent = textNode.parentNode;
- if (parent.childNodes.length == 1 && rangy.dom.arrayContains(this.tagNames, parent.tagName.toLowerCase())) {
-
- if (this.cssClass) {
- addClass(parent, this.cssClass, this.similarClassRegExp);
- }
- if (this.cssStyle) {
- addStyle(parent, this.cssStyle, this.similarStyleRegExp);
- }
- } else {
- var el = this.createContainer(rangy.dom.getDocument(textNode));
- textNode.parentNode.insertBefore(el, textNode);
- el.appendChild(textNode);
- }
- },
-
- isRemovable: function(el) {
- return rangy.dom.arrayContains(this.tagNames, el.tagName.toLowerCase()) &&
- wysihtml5.lang.string(el.className).trim() === "" &&
- (
- !el.getAttribute('style') ||
- wysihtml5.lang.string(el.getAttribute('style')).trim() === ""
- );
- },
-
- undoToTextNode: function(textNode, range, ancestorWithClass, ancestorWithStyle) {
- var styleMode = (ancestorWithClass) ? false : true,
- ancestor = ancestorWithClass || ancestorWithStyle,
- styleChanged = false;
- if (!range.containsNode(ancestor)) {
- // Split out the portion of the ancestor from which we can remove the CSS class
- var ancestorRange = range.cloneRange();
- ancestorRange.selectNode(ancestor);
-
- if (ancestorRange.isPointInRange(range.endContainer, range.endOffset) && isSplitPoint(range.endContainer, range.endOffset)) {
- splitNodeAt(ancestor, range.endContainer, range.endOffset, this.container);
- range.setEndAfter(ancestor);
- }
- if (ancestorRange.isPointInRange(range.startContainer, range.startOffset) && isSplitPoint(range.startContainer, range.startOffset)) {
- ancestor = splitNodeAt(ancestor, range.startContainer, range.startOffset, this.container);
- }
- }
-
- if (!styleMode && this.similarClassRegExp) {
- removeClass(ancestor, this.similarClassRegExp);
- }
-
- if (styleMode && this.similarStyleRegExp) {
- styleChanged = (removeOrChangeStyle(ancestor, this.cssStyle, this.similarStyleRegExp) === "change");
- }
- if (this.isRemovable(ancestor) && !styleChanged) {
- replaceWithOwnChildren(ancestor);
- }
+ return rangy.createRange(this.doc);
},
- applyToRange: function(range) {
- var textNodes;
- for (var ri = range.length; ri--;) {
- textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ isCollapsed: function() {
+ return this.getSelection().isCollapsed;
+ },
- if (!textNodes.length) {
- try {
- var node = this.createContainer(range[ri].endContainer.ownerDocument);
- range[ri].surroundContents(node);
- this.selectNode(range[ri], node);
- return;
- } catch(e) {}
- }
+ getHtml: function() {
+ return this.getSelection().toHtml();
+ },
- range[ri].splitBoundaries();
- textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
- if (textNodes.length) {
- var textNode;
+ getPlainText: function () {
+ return this.getSelection().toString();
+ },
- for (var i = 0, len = textNodes.length; i < len; ++i) {
- textNode = textNodes[i];
- if (!this.getMatchingAncestor(textNode).element) {
- this.applyToTextNode(textNode);
- }
- }
+ isEndToEndInNode: function(nodeNames) {
+ var range = this.getRange(),
+ parentElement = range.commonAncestorContainer,
+ startNode = range.startContainer,
+ endNode = range.endContainer;
- range[ri].setStart(textNodes[0], 0);
- textNode = textNodes[textNodes.length - 1];
- range[ri].setEnd(textNode, textNode.length);
- if (this.normalize) {
- this.postApply(textNodes, range[ri]);
- }
+ if (parentElement.nodeType === wysihtml.TEXT_NODE) {
+ parentElement = parentElement.parentNode;
}
- }
- },
+ if (startNode.nodeType === wysihtml.TEXT_NODE && !(/^\s*$/).test(startNode.data.substr(range.startOffset))) {
+ return false;
+ }
- undoToRange: function(range) {
- var textNodes, textNode, ancestorWithClass, ancestorWithStyle, ancestor;
- for (var ri = range.length; ri--;) {
+ if (endNode.nodeType === wysihtml.TEXT_NODE && !(/^\s*$/).test(endNode.data.substr(range.endOffset))) {
+ return false;
+ }
- textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
- if (textNodes.length) {
- range[ri].splitBoundaries();
- textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
- } else {
- var doc = range[ri].endContainer.ownerDocument,
- node = doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
- range[ri].insertNode(node);
- range[ri].selectNode(node);
- textNodes = [node];
- }
-
- for (var i = 0, len = textNodes.length; i < len; ++i) {
- if (range[ri].isValid()) {
- textNode = textNodes[i];
-
- ancestor = this.getMatchingAncestor(textNode);
- if (ancestor.type === "style") {
- this.undoToTextNode(textNode, range[ri], false, ancestor.element);
- } else if (ancestor.element) {
- this.undoToTextNode(textNode, range[ri], ancestor.element);
- }
+ while (startNode && startNode !== parentElement) {
+ if (startNode.nodeType !== wysihtml.TEXT_NODE && !wysihtml.dom.contains(parentElement, startNode)) {
+ return false;
}
+ if (wysihtml.dom.domNode(startNode).prev({ignoreBlankTexts: true})) {
+ return false;
+ }
+ startNode = startNode.parentNode;
}
- if (len == 1) {
- this.selectNode(range[ri], textNodes[0]);
- } else {
- range[ri].setStart(textNodes[0], 0);
- textNode = textNodes[textNodes.length - 1];
- range[ri].setEnd(textNode, textNode.length);
-
- if (this.normalize) {
- this.postApply(textNodes, range[ri]);
+ while (endNode && endNode !== parentElement) {
+ if (endNode.nodeType !== wysihtml.TEXT_NODE && !wysihtml.dom.contains(parentElement, endNode)) {
+ return false;
+ }
+ if (wysihtml.dom.domNode(endNode).next({ignoreBlankTexts: true})) {
+ return false;
}
+ endNode = endNode.parentNode;
}
- }
+ return (wysihtml.lang.array(nodeNames).contains(parentElement.nodeName)) ? parentElement : false;
},
- selectNode: function(range, node) {
- var isElement = node.nodeType === wysihtml5.ELEMENT_NODE,
- canHaveHTML = "canHaveHTML" in node ? node.canHaveHTML : true,
- content = isElement ? node.innerHTML : node.data,
- isEmpty = (content === "" || content === wysihtml5.INVISIBLE_SPACE);
+ isInThisEditable: function() {
+ var sel = this.getSelection(),
+ fnode = sel.focusNode,
+ anode = sel.anchorNode;
- if (isEmpty && isElement && canHaveHTML) {
- // Make sure that caret is visible in node by inserting a zero width no breaking space
- try { node.innerHTML = wysihtml5.INVISIBLE_SPACE; } catch(e) {}
- }
- range.selectNodeContents(node);
- if (isEmpty && isElement) {
- range.collapse(false);
- } else if (isEmpty) {
- range.setStartAfter(node);
- range.setEndAfter(node);
+ // In IE node contains will not work for textnodes, thus taking parentNode
+ if (fnode && fnode.nodeType !== 1) {
+ fnode = fnode.parentNode;
}
- },
-
- getTextSelectedByRange: function(textNode, range) {
- var textRange = range.cloneRange();
- textRange.selectNodeContents(textNode);
-
- var intersectionRange = textRange.intersection(range);
- var text = intersectionRange ? intersectionRange.toString() : "";
- textRange.detach();
-
- return text;
- },
-
- isAppliedToRange: function(range) {
- var ancestors = [],
- appliedType = "full",
- ancestor, styleAncestor, textNodes;
-
- for (var ri = range.length; ri--;) {
-
- textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
- if (!textNodes.length) {
- ancestor = this.getMatchingAncestor(range[ri].startContainer).element;
-
- return (ancestor) ? {
- "elements": [ancestor],
- "coverage": appliedType
- } : false;
- }
-
- for (var i = 0, len = textNodes.length, selectedText; i < len; ++i) {
- selectedText = this.getTextSelectedByRange(textNodes[i], range[ri]);
- ancestor = this.getMatchingAncestor(textNodes[i]).element;
- if (ancestor && selectedText != "") {
- ancestors.push(ancestor);
-
- if (wysihtml5.dom.getTextNodes(ancestor, true).length === 1) {
- appliedType = "full";
- } else if (appliedType === "full") {
- appliedType = "inline";
- }
- } else if (!ancestor) {
- appliedType = "partial";
- }
- }
+ if (anode && anode.nodeType !== 1) {
+ anode = anode.parentNode;
}
- return (ancestors.length) ? {
- "elements": ancestors,
- "coverage": appliedType
- } : false;
+ return anode && fnode &&
+ (wysihtml.dom.contains(this.composer.element, fnode) || this.composer.element === fnode) &&
+ (wysihtml.dom.contains(this.composer.element, anode) || this.composer.element === anode);
},
- toggleRange: function(range) {
- var isApplied = this.isAppliedToRange(range),
- parentsExactMatch;
-
- if (isApplied) {
- if (isApplied.coverage === "full") {
- this.undoToRange(range);
- } else if (isApplied.coverage === "inline") {
- parentsExactMatch = areMatchingAllready(isApplied.elements, this.tagNames, this.cssStyle, this.cssClass);
- this.undoToRange(range);
- if (!parentsExactMatch) {
- this.applyToRange(range);
- }
- } else {
- // partial
- if (!areMatchingAllready(isApplied.elements, this.tagNames, this.cssStyle, this.cssClass)) {
- this.undoToRange(range);
- }
- this.applyToRange(range);
- }
- } else {
- this.applyToRange(range);
- }
+ deselect: function() {
+ var sel = this.getSelection();
+ sel && sel.removeAllRanges();
}
- };
+ });
- wysihtml5.selection.HTMLApplier = HTMLApplier;
+})(wysihtml);
-})(wysihtml5, rangy);
-;/**
+/**
* Rich Text Query/Formatting Commands
*
* @example
- * var commands = new wysihtml5.Commands(editor);
+ * var commands = new wysihtml.Commands(editor);
*/
-wysihtml5.Commands = Base.extend(
- /** @scope wysihtml5.Commands.prototype */ {
+wysihtml.Commands = Base.extend(
+ /** @scope wysihtml.Commands.prototype */ {
constructor: function(editor) {
this.editor = editor;
this.composer = editor.composer;
@@ -13805,7 +11942,7 @@ wysihtml5.Commands = Base.extend(
* commands.supports("createLink");
*/
support: function(command) {
- return wysihtml5.browser.supportsCommand(this.doc, command);
+ return wysihtml.browser.supportsCommand(this.doc, command);
},
/**
@@ -13817,14 +11954,14 @@ wysihtml5.Commands = Base.extend(
* commands.exec("insertImage", "http://a1.twimg.com/profile_images/113868655/schrei_twitter_reasonably_small.jpg");
*/
exec: function(command, value) {
- var obj = wysihtml5.commands[command],
- args = wysihtml5.lang.array(arguments).get(),
+ var obj = wysihtml.commands[command],
+ args = wysihtml.lang.array(arguments).get(),
method = obj && obj.exec,
result = null;
// If composer ahs placeholder unset it before command
// Do not apply on commands that are behavioral
- if (this.composer.hasPlaceholderSet() && !wysihtml5.lang.array(['styleWithCSS', 'enableObjectResizing', 'enableInlineTableEditing']).contains(command)) {
+ if (this.composer.hasPlaceholderSet() && !wysihtml.lang.array(['styleWithCSS', 'enableObjectResizing', 'enableInlineTableEditing']).contains(command)) {
this.composer.element.innerHTML = "";
this.composer.selection.selectNode(this.composer.element);
}
@@ -13846,8 +11983,8 @@ wysihtml5.Commands = Base.extend(
},
remove: function(command, commandValue) {
- var obj = wysihtml5.commands[command],
- args = wysihtml5.lang.array(arguments).get(),
+ var obj = wysihtml.commands[command],
+ args = wysihtml.lang.array(arguments).get(),
method = obj && obj.remove;
if (method) {
args.unshift(this.composer);
@@ -13866,8 +12003,8 @@ wysihtml5.Commands = Base.extend(
* var isCurrentSelectionBold = commands.state("bold");
*/
state: function(command, commandValue) {
- var obj = wysihtml5.commands[command],
- args = wysihtml5.lang.array(arguments).get(),
+ var obj = wysihtml.commands[command],
+ args = wysihtml.lang.array(arguments).get(),
method = obj && obj.state;
if (method) {
args.unshift(this.composer);
@@ -13884,8 +12021,8 @@ wysihtml5.Commands = Base.extend(
/* Get command state parsed value if command has stateValue parsing function */
stateValue: function(command) {
- var obj = wysihtml5.commands[command],
- args = wysihtml5.lang.array(arguments).get(),
+ var obj = wysihtml.commands[command],
+ args = wysihtml.lang.array(arguments).get(),
method = obj && obj.stateValue;
if (method) {
args.unshift(this.composer);
@@ -13895,25 +12032,8 @@ wysihtml5.Commands = Base.extend(
}
}
});
-;(function(wysihtml5) {
-
- var nodeOptions = {
- nodeName: "B",
- toggle: true
- };
-
- wysihtml5.commands.bold = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.exec(composer, command, nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-}(wysihtml5));
-;(function(wysihtml5) {
+(function(wysihtml) {
var nodeOptions = {
nodeName: "A",
@@ -13922,10 +12042,10 @@ wysihtml5.Commands = Base.extend(
function getOptions(value) {
var options = typeof value === 'object' ? value : {'href': value};
- return wysihtml5.lang.object({}).merge(nodeOptions).merge({'attribute': value}).get();
+ return wysihtml.lang.object({}).merge(nodeOptions).merge({'attribute': value}).get();
}
- wysihtml5.commands.createLink = {
+ wysihtml.commands.createLink = {
exec: function(composer, command, value) {
var opts = getOptions(value);
@@ -13934,219 +12054,24 @@ wysihtml5.Commands = Base.extend(
composer.selection.insertNode(textNode);
composer.selection.selectNode(textNode);
}
- wysihtml5.commands.formatInline.exec(composer, command, opts);
+ wysihtml.commands.formatInline.exec(composer, command, opts);
},
state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- nodeName: "A"
- };
-
- wysihtml5.commands.removeLink = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.remove(composer, command, nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-
-})(wysihtml5);
-;/**
- * Set font size css class
- */
-(function(wysihtml5) {
- var REG_EXP = /wysiwyg-font-size-[0-9a-z\-]+/g;
-
- wysihtml5.commands.fontSize = {
- exec: function(composer, command, size) {
- wysihtml5.commands.formatInline.exec(composer, command, {className: "wysiwyg-font-size-" + size, classRegExp: REG_EXP, toggle: true});
- },
-
- state: function(composer, command, size) {
- return wysihtml5.commands.formatInline.state(composer, command, {className: "wysiwyg-font-size-" + size});
- }
- };
-})(wysihtml5);
-;/**
- * Set font size by inline style
- */
-(function(wysihtml5) {
-
- wysihtml5.commands.fontSizeStyle = {
- exec: function(composer, command, size) {
- size = size.size || size;
- if (!(/^\s*$/).test(size)) {
- wysihtml5.commands.formatInline.exec(composer, command, {styleProperty: "fontSize", styleValue: size, toggle: false});
- }
- },
-
- state: function(composer, command, size) {
- return wysihtml5.commands.formatInline.state(composer, command, {styleProperty: "fontSize", styleValue: size || undefined});
- },
-
- remove: function(composer, command) {
- return wysihtml5.commands.formatInline.remove(composer, command, {styleProperty: "fontSize"});
- },
-
- stateValue: function(composer, command) {
- var styleStr,
- st = this.state(composer, command);
-
- if (st && wysihtml5.lang.object(st).isArray()) {
- st = st[0];
- }
- if (st) {
- styleStr = st.getAttribute("style");
- if (styleStr) {
- return wysihtml5.quirks.styleParser.parseFontSize(styleStr);
- }
- }
- return false;
- }
- };
-})(wysihtml5);
-;/**
- * Set color css class
- */
-(function(wysihtml5) {
- var REG_EXP = /wysiwyg-color-[0-9a-z]+/g;
-
- wysihtml5.commands.foreColor = {
- exec: function(composer, command, color) {
- wysihtml5.commands.formatInline.exec(composer, command, {className: "wysiwyg-color-" + color, classRegExp: REG_EXP, toggle: true});
- },
-
- state: function(composer, command, color) {
- return wysihtml5.commands.formatInline.state(composer, command, {className: "wysiwyg-color-" + color});
- }
- };
-})(wysihtml5);
-;/**
- * Sets text color by inline styles
- */
-(function(wysihtml5) {
-
- wysihtml5.commands.foreColorStyle = {
- exec: function(composer, command, color) {
- var colorVals, colString;
-
- if (!color) { return; }
-
- colorVals = wysihtml5.quirks.styleParser.parseColor("color:" + (color.color || color), "color");
-
- if (colorVals) {
- colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(", ") : "rgba(" + colorVals.join(', ')) + ')';
- wysihtml5.commands.formatInline.exec(composer, command, {styleProperty: "color", styleValue: colString});
- }
- },
-
- state: function(composer, command, color) {
- var colorVals = color ? wysihtml5.quirks.styleParser.parseColor("color:" + (color.color || color), "color") : null,
- colString;
-
-
- if (colorVals) {
- colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(", ") : "rgba(" + colorVals.join(', ')) + ')';
- }
-
- return wysihtml5.commands.formatInline.state(composer, command, {styleProperty: "color", styleValue: colString});
- },
-
- remove: function(composer, command) {
- return wysihtml5.commands.formatInline.remove(composer, command, {styleProperty: "color"});
- },
-
- stateValue: function(composer, command, props) {
- var st = this.state(composer, command),
- colorStr,
- val = false;
-
- if (st && wysihtml5.lang.object(st).isArray()) {
- st = st[0];
- }
-
- if (st) {
- colorStr = st.getAttribute("style");
- if (colorStr) {
- val = wysihtml5.quirks.styleParser.parseColor(colorStr, "color");
- return wysihtml5.quirks.styleParser.unparseColor(val, props);
- }
- }
- return false;
+ return wysihtml.commands.formatInline.state(composer, command, nodeOptions);
}
-
};
-})(wysihtml5);
-;/**
- * Sets text background color by inline styles
- */
-(function(wysihtml5) {
-
- wysihtml5.commands.bgColorStyle = {
- exec: function(composer, command, color) {
- var colorVals = wysihtml5.quirks.styleParser.parseColor("background-color:" + (color.color || color), "background-color"),
- colString;
-
- if (colorVals) {
- colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(', ') : "rgba(" + colorVals.join(', ')) + ')';
- wysihtml5.commands.formatInline.exec(composer, command, {styleProperty: 'backgroundColor', styleValue: colString});
- }
- },
-
- state: function(composer, command, color) {
- var colorVals = color ? wysihtml5.quirks.styleParser.parseColor("background-color:" + (color.color || color), "background-color") : null,
- colString;
-
-
- if (colorVals) {
- colString = (colorVals[3] === 1 ? "rgb(" + [colorVals[0], colorVals[1], colorVals[2]].join(', ') : "rgba(" + colorVals.join(', ')) + ')';
- }
-
- return wysihtml5.commands.formatInline.state(composer, command, {styleProperty: 'backgroundColor', styleValue: colString});
- },
-
- remove: function(composer, command) {
- return wysihtml5.commands.formatInline.remove(composer, command, {styleProperty: 'backgroundColor'});
- },
-
- stateValue: function(composer, command, props) {
- var st = this.state(composer, command),
- colorStr,
- val = false;
- if (st && wysihtml5.lang.object(st).isArray()) {
- st = st[0];
- }
-
- if (st) {
- colorStr = st.getAttribute('style');
- if (colorStr) {
- val = wysihtml5.quirks.styleParser.parseColor(colorStr, "background-color");
- return wysihtml5.quirks.styleParser.unparseColor(val, props);
- }
- }
- return false;
- }
+})(wysihtml);
- };
-})(wysihtml5);
-;/* Formatblock
+/* Formatblock
* Is used to insert block level elements
* It tries to solve the case that some block elements should not contain other block level elements (h1-6, p, ...)
*
*/
-(function(wysihtml5) {
+(function(wysihtml) {
- var dom = wysihtml5.dom,
+ var dom = wysihtml.dom,
// When the caret is within a H1 and the H4 is invoked, the H1 should turn into H4
// instead of creating a H4 within a H1 which would result in semantically invalid html
UNNESTABLE_BLOCK_ELEMENTS = "h1, h2, h3, h4, h5, h6, p, pre",
@@ -14192,18 +12117,18 @@ wysihtml5.Commands = Base.extend(
// Removes empty block level elements
function cleanup(composer, newBlockElements) {
- wysihtml5.dom.removeInvisibleSpaces(composer.element);
+ wysihtml.dom.removeInvisibleSpaces(composer.element);
var container = composer.element,
allElements = container.querySelectorAll(BLOCK_ELEMENTS),
noEditQuery = composer.config.classNames.uneditableContainer + ([""]).concat(BLOCK_ELEMENTS.split(',')).join(", " + composer.config.classNames.uneditableContainer + ' '),
uneditables = container.querySelectorAll(noEditQuery),
- elements = wysihtml5.lang.array(allElements).without(uneditables), // Lets not touch uneditable elements and their contents
+ elements = wysihtml.lang.array(allElements).without(uneditables), // Lets not touch uneditable elements and their contents
nbIdx;
for (var i = elements.length; i--;) {
if (elements[i].innerHTML.replace(/[\uFEFF]/g, '') === "" && (newBlockElements.length === 0 || elements[i] !== newBlockElements[newBlockElements.length - 1])) {
// If cleanup removes some new block elements. remove them from newblocks array too
- nbIdx = wysihtml5.lang.array(newBlockElements).indexOf(elements[i]);
+ nbIdx = wysihtml.lang.array(newBlockElements).indexOf(elements[i]);
if (nbIdx > -1) {
newBlockElements.splice(nbIdx, 1);
}
@@ -14272,7 +12197,7 @@ wysihtml5.Commands = Base.extend(
if (!element) {
element = composer.doc.createElement(options.nodeName || defaultNodeName(composer));
// Add invisible space as otherwise webkit cannot set selection or range to it correctly
- element.appendChild(composer.doc.createTextNode(wysihtml5.INVISIBLE_SPACE));
+ element.appendChild(composer.doc.createTextNode(wysihtml.INVISIBLE_SPACE));
}
if (options.nodeName && element.nodeName !== options.nodeName) {
@@ -14288,7 +12213,7 @@ wysihtml5.Commands = Base.extend(
}
if (options.styleProperty && typeof options.styleValue !== "undefined") {
- element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)] = options.styleValue;
+ element.style[wysihtml.browser.fixStyleKey(options.styleProperty)] = options.styleValue;
}
return element;
@@ -14303,7 +12228,7 @@ wysihtml5.Commands = Base.extend(
unwrapped = false;
if (options.styleProperty) {
- element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)] = '';
+ element.style[wysihtml.browser.fixStyleKey(options.styleProperty)] = '';
}
if (options.className) {
element.classList.remove(options.className);
@@ -14345,8 +12270,8 @@ wysihtml5.Commands = Base.extend(
nextEl, prevEl;
for (var i = blocks.length; i--;) {
- nextEl = wysihtml5.dom.domNode(blocks[i]).next({nodeTypes: [1,3], ignoreBlankTexts: true}),
- prevEl = wysihtml5.dom.domNode(blocks[i]).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
+ nextEl = wysihtml.dom.domNode(blocks[i]).next({nodeTypes: [1,3], ignoreBlankTexts: true}),
+ prevEl = wysihtml.dom.domNode(blocks[i]).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
if (nextEl && nextEl.nodeType !== 1 && nextEl.nodeName !== 'BR') {
if ((blocks[i].innerHTML || blocks[i].nodeValue || '').trim() !== '') {
@@ -14358,7 +12283,7 @@ wysihtml5.Commands = Base.extend(
blocks[i].parentNode.insertBefore(blocks[i].ownerDocument.createElement('BR'), nextEl);
}
}
- wysihtml5.dom.unwrap(blocks[i]);
+ wysihtml.dom.unwrap(blocks[i]);
}
}
@@ -14450,7 +12375,7 @@ wysihtml5.Commands = Base.extend(
// Range starts before and ends inside the node
tmpRange = ranges[i].cloneRange();
- closestLI = wysihtml5.dom.domNode(lis[j]).prev({nodeTypes: [1]});
+ closestLI = wysihtml.dom.domNode(lis[j]).prev({nodeTypes: [1]});
if (closestLI) {
tmpRange.setEnd(closestLI, closestLI.childNodes.length);
@@ -14472,7 +12397,7 @@ wysihtml5.Commands = Base.extend(
newRanges.push(tmpRange);
// Find next LI in list and if present set range to it, else
- closestLI = wysihtml5.dom.domNode(lis[j]).next({nodeTypes: [1]});
+ closestLI = wysihtml.dom.domNode(lis[j]).next({nodeTypes: [1]});
if (closestLI) {
ranges[i].setStart(closestLI, 0);
} else if (lis[j].closest('ul, ol')) {
@@ -14493,7 +12418,7 @@ wysihtml5.Commands = Base.extend(
// Return options object with nodeName set if original did not have any
// Node name is set to local or global default
function getOptionsWithNodename(options, defaultName, composer) {
- var correctedOptions = (options) ? wysihtml5.lang.object(options).clone(true) : null;
+ var correctedOptions = (options) ? wysihtml.lang.object(options).clone(true) : null;
if (correctedOptions) {
correctedOptions.nodeName = correctedOptions.nodeName || defaultName || defaultNodeName(composer);
}
@@ -14515,8 +12440,8 @@ wysihtml5.Commands = Base.extend(
composer.selection.splitElementAtCaret(firstOuterBlock, fragment);
- next = wysihtml5.dom.domNode(last).next({nodeTypes: [1,3], ignoreBlankTexts: true});
- prev = wysihtml5.dom.domNode(first).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
+ next = wysihtml.dom.domNode(last).next({nodeTypes: [1,3], ignoreBlankTexts: true});
+ prev = wysihtml.dom.domNode(first).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
if (first && !isLineBreaking(first, composer) && prev && !isLineBreaking(prev, composer)) {
first.parentNode.insertBefore(composer.doc.createElement('br'), first);
@@ -14566,7 +12491,7 @@ wysihtml5.Commands = Base.extend(
// Split block formating and add new block to wrap caret
unwrapBlocksFromContent(content.firstChild);
- children = wysihtml5.dom.unwrap(content.firstChild);
+ children = wysihtml.dom.unwrap(content.firstChild);
// Add line break before if needed
if (children.length > 0) {
@@ -14597,14 +12522,14 @@ wysihtml5.Commands = Base.extend(
first = false;
}
- blocks = wysihtml5.lang.array(fragment.childNodes).get();
+ blocks = wysihtml.lang.array(fragment.childNodes).get();
injectFragmentToRange(fragment, r, composer);
return blocks;
}
// When block node is inserted, look surrounding nodes and remove surplous linebreak tags (as block format breaks line itself)
function removeSurroundingLineBreaks(prevNode, nextNode, composer) {
- var prevPrev = prevNode && wysihtml5.dom.domNode(prevNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
+ var prevPrev = prevNode && wysihtml.dom.domNode(prevNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
if (isBr(nextNode)) {
nextNode.parentNode.removeChild(nextNode);
}
@@ -14672,7 +12597,7 @@ wysihtml5.Commands = Base.extend(
rangeStartContainer = r.startContainer,
startNode = getRangeNode(r.startContainer, r.startOffset),
endNode = getRangeNode(r.endContainer, r.endOffset),
- prevNode = (r.startContainer === startNode && startNode.nodeType === 3 && !isWhitespaceBefore(startNode, r.startOffset)) ? startNode : wysihtml5.dom.domNode(startNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true}),
+ prevNode = (r.startContainer === startNode && startNode.nodeType === 3 && !isWhitespaceBefore(startNode, r.startOffset)) ? startNode : wysihtml.dom.domNode(startNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true}),
nextNode = (
(
r.endContainer.nodeType === 1 &&
@@ -14680,23 +12605,23 @@ wysihtml5.Commands = Base.extend(
(
endNode.nodeType === 1 ||
!isWhitespaceAfter(endNode, r.endOffset) &&
- !wysihtml5.dom.domNode(endNode).is.rangyBookmark()
+ !wysihtml.dom.domNode(endNode).is.rangyBookmark()
)
) || (
r.endContainer === endNode &&
endNode.nodeType === 3 &&
!isWhitespaceAfter(endNode, r.endOffset)
)
- ) ? endNode : wysihtml5.dom.domNode(endNode).next({nodeTypes: [1,3], ignoreBlankTexts: true}),
+ ) ? endNode : wysihtml.dom.domNode(endNode).next({nodeTypes: [1,3], ignoreBlankTexts: true}),
content = r.extractContents(),
fragment = composer.doc.createDocumentFragment(),
- similarOuterBlock = similarOptions ? wysihtml5.dom.getParentElement(rangeStartContainer, similarOptions, null, composer.element) : null,
+ similarOuterBlock = similarOptions ? wysihtml.dom.getParentElement(rangeStartContainer, similarOptions, null, composer.element) : null,
splitAllBlocks = !closestBlockName || !options || (options.nodeName === "BLOCKQUOTE" && closestBlockName === "BLOCKQUOTE"),
firstOuterBlock = similarOuterBlock || findOuterBlock(rangeStartContainer, composer.element, splitAllBlocks), // The outermost un-nestable block element parent of selection start
wrapper, blocks, children,
firstc, lastC;
- if (wysihtml5.dom.domNode(nextNode).is.rangyBookmark()) {
+ if (wysihtml.dom.domNode(nextNode).is.rangyBookmark()) {
endNode = nextNode;
nextNode = endNode.nextSibling;
}
@@ -14746,7 +12671,7 @@ wysihtml5.Commands = Base.extend(
}
}
- blocks = wysihtml5.lang.array(fragment.childNodes).get();
+ blocks = wysihtml.lang.array(fragment.childNodes).get();
}
injectFragmentToRange(fragment, r, composer, firstOuterBlock);
removeSurroundingLineBreaks(prevNode, nextNode, composer);
@@ -14755,7 +12680,7 @@ wysihtml5.Commands = Base.extend(
// (if it contains rangy bookmark, so selection can be restored later correctly)
if (blocks.length > 0 &&
(
- typeof blocks[blocks.length - 1].lastChild === "undefined" || wysihtml5.dom.domNode(blocks[blocks.length - 1].lastChild).is.rangyBookmark()
+ typeof blocks[blocks.length - 1].lastChild === "undefined" || wysihtml.dom.domNode(blocks[blocks.length - 1].lastChild).is.rangyBookmark()
)
) {
blocks[blocks.length - 1].appendChild(composer.doc.createElement('br'));
@@ -14765,7 +12690,7 @@ wysihtml5.Commands = Base.extend(
// Find closest block level element
function getParentBlockNodeName(element, composer) {
- var parentNode = wysihtml5.dom.getParentElement(element, {
+ var parentNode = wysihtml.dom.getParentElement(element, {
query: BLOCK_ELEMENTS
}, null, composer.element);
@@ -14780,7 +12705,7 @@ wysihtml5.Commands = Base.extend(
//
// If nothing found selects the current line
function expandCaretToBlock(composer, insertingNodeName) {
- var parent = wysihtml5.dom.getParentElement(composer.selection.getOwnRanges()[0].startContainer, {
+ var parent = wysihtml.dom.getParentElement(composer.selection.getOwnRanges()[0].startContainer, {
query: UNNESTABLE_BLOCK_ELEMENTS + ', ' + (insertingNodeName ? insertingNodeName.toLowerCase() : 'div'),
}, null, composer.element),
range;
@@ -14846,13 +12771,13 @@ wysihtml5.Commands = Base.extend(
if (caretInfo && caretInfo.caretNode) {
if (
// caret is allready breaknode
- wysihtml5.dom.domNode(caretInfo.caretNode).is.lineBreak() ||
+ wysihtml.dom.domNode(caretInfo.caretNode).is.lineBreak() ||
// caret is textnode
- (caretInfo.caretNode.nodeType === 3 && caretInfo.textOffset === 0 && (!caretInfo.prevNode || wysihtml5.dom.domNode(caretInfo.prevNode).is.lineBreak())) ||
+ (caretInfo.caretNode.nodeType === 3 && caretInfo.textOffset === 0 && (!caretInfo.prevNode || wysihtml.dom.domNode(caretInfo.prevNode).is.lineBreak())) ||
// Caret is temprorary rangy selection marker
(caretInfo.caretNode.nodeType === 1 && caretInfo.caretNode.classList.contains('rangySelectionBoundary') &&
- (!caretInfo.prevNode || wysihtml5.dom.domNode(caretInfo.prevNode).is.lineBreak() || wysihtml5.dom.domNode(caretInfo.prevNode).is.block()) &&
- (!caretInfo.nextNode || wysihtml5.dom.domNode(caretInfo.nextNode).is.lineBreak() || wysihtml5.dom.domNode(caretInfo.nextNode).is.block())
+ (!caretInfo.prevNode || wysihtml.dom.domNode(caretInfo.prevNode).is.lineBreak() || wysihtml.dom.domNode(caretInfo.prevNode).is.block()) &&
+ (!caretInfo.nextNode || wysihtml.dom.domNode(caretInfo.nextNode).is.lineBreak() || wysihtml.dom.domNode(caretInfo.nextNode).is.block())
)
) {
return true;
@@ -14862,7 +12787,7 @@ wysihtml5.Commands = Base.extend(
return false;
}
- wysihtml5.commands.formatBlock = {
+ wysihtml.commands.formatBlock = {
exec: function(composer, command, options) {
options = parseOptions(options);
var newBlockElements = [],
@@ -14938,7 +12863,7 @@ wysihtml5.Commands = Base.extend(
options = parseOptions(options);
var nodes = composer.selection.filterElements((function (element) { // Finds matching elements inside selection
- return wysihtml5.dom.domNode(element).test(options || { query: BLOCK_ELEMENTS });
+ return wysihtml.dom.domNode(element).test(options || { query: BLOCK_ELEMENTS });
}).bind(this)),
parentNodes = composer.selection.getSelectedOwnNodes(),
parent;
@@ -14955,67 +12880,14 @@ wysihtml5.Commands = Base.extend(
}
};
-})(wysihtml5);
-;/* Formats block for as a
block
- * Useful in conjuction for sytax highlight utility: highlight.js
- *
- * Usage:
- *
- * editorInstance.composer.commands.exec("formatCode", "language-html");
-*/
-
-(function(wysihtml5){
- wysihtml5.commands.formatCode = {
-
- exec: function(composer, command, classname) {
- var pre = this.state(composer)[0],
- code, range, selectedNodes;
-
- if (pre) {
- // caret is already within a ...
- composer.selection.executeAndRestore(function() {
- code = pre.querySelector("code");
- wysihtml5.dom.replaceWithChildNodes(pre);
- if (code) {
- wysihtml5.dom.replaceWithChildNodes(code);
- }
- });
- } else {
- // Wrap in ...
- range = composer.selection.getRange();
- selectedNodes = range.extractContents();
- pre = composer.doc.createElement("pre");
- code = composer.doc.createElement("code");
+})(wysihtml);
- if (classname) {
- code.className = classname;
- }
-
- pre.appendChild(code);
- code.appendChild(selectedNodes);
- range.insertNode(pre);
- composer.selection.selectNode(pre);
- }
- },
-
- state: function(composer) {
- var selectedNode = composer.selection.getSelectedNode(), node;
- if (selectedNode && selectedNode.nodeName && selectedNode.nodeName == "PRE"&&
- selectedNode.firstChild && selectedNode.firstChild.nodeName && selectedNode.firstChild.nodeName == "CODE") {
- return [selectedNode];
- } else {
- node = wysihtml5.dom.getParentElement(selectedNode, { query: "pre code" });
- return node ? [node.parentNode] : false;
- }
- }
- };
-}(wysihtml5));
-;/**
+/**
* Unifies all inline tags additions and removals
* See https://github.com/Voog/wysihtml/pull/169 for specification of action
*/
-(function(wysihtml5) {
+(function(wysihtml) {
var defaultTag = "SPAN",
INLINE_ELEMENTS = "b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u",
@@ -15037,8 +12909,8 @@ wysihtml5.Commands = Base.extend(
// Associative arrays in javascript are really objects and do not have length defined
// Thus have to check emptyness in a different way
function hasNoAttributes(element) {
- var attr = wysihtml5.dom.getAttributes(element);
- return wysihtml5.lang.object(attr).isEmpty();
+ var attr = wysihtml.dom.getAttributes(element);
+ return wysihtml.lang.object(attr).isEmpty();
}
// compares two nodes if they are semantically the same
@@ -15057,14 +12929,14 @@ wysihtml5.Commands = Base.extend(
classes1 = element1.className.trim().replace(/\s+/g, ' ').split(' ');
classes2 = element2.className.trim().replace(/\s+/g, ' ').split(' ');
- if (wysihtml5.lang.array(classes1).without(classes2).length > 0) {
+ if (wysihtml.lang.array(classes1).without(classes2).length > 0) {
return false;
}
- attr1 = wysihtml5.dom.getAttributes(element1);
- attr2 = wysihtml5.dom.getAttributes(element2);
+ attr1 = wysihtml.dom.getAttributes(element1);
+ attr2 = wysihtml.dom.getAttributes(element2);
- if (attr1.length !== attr2.length || !wysihtml5.lang.object(wysihtml5.lang.object(attr1).difference(attr2)).isEmpty()) {
+ if (attr1.length !== attr2.length || !wysihtml.lang.object(wysihtml.lang.object(attr1).difference(attr2)).isEmpty()) {
return false;
}
@@ -15085,7 +12957,7 @@ wysihtml5.Commands = Base.extend(
}
if (options.styleProperty && typeof options.styleValue !== "undefined") {
- element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)] = options.styleValue;
+ element.style[wysihtml.browser.fixStyleKey(options.styleProperty)] = options.styleValue;
}
if (options.attribute) {
@@ -15119,9 +12991,9 @@ wysihtml5.Commands = Base.extend(
// If attrbutes and values are the same > remove
// if attributes or values
function updateElementAttributes(element, newAttributes, toggle) {
- var attr = wysihtml5.dom.getAttributes(element),
+ var attr = wysihtml.dom.getAttributes(element),
fullContain = containsSameAttributes(newAttributes, attr),
- attrDifference = wysihtml5.lang.object(attr).difference(newAttributes),
+ attrDifference = wysihtml.lang.object(attr).difference(newAttributes),
a, b;
if (fullContain && toggle !== false) {
@@ -15132,7 +13004,7 @@ wysihtml5.Commands = Base.extend(
}
} else {
- /*if (!wysihtml5.lang.object(attrDifference).isEmpty()) {
+ /*if (!wysihtml.lang.object(attrDifference).isEmpty()) {
for (b in attrDifference) {
if (attrDifference.hasOwnProperty(b)) {
element.removeAttribute(b);
@@ -15167,10 +13039,10 @@ wysihtml5.Commands = Base.extend(
// change/remove style
if (options.styleProperty) {
- if (options.toggle !== false && element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)].trim().replace(/, /g, ",") === options.styleValue) {
- element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)] = '';
+ if (options.toggle !== false && element.style[wysihtml.browser.fixStyleKey(options.styleProperty)].trim().replace(/, /g, ",") === options.styleValue) {
+ element.style[wysihtml.browser.fixStyleKey(options.styleProperty)] = '';
} else {
- element.style[wysihtml5.browser.fixStyleKey(options.styleProperty)] = options.styleValue;
+ element.style[wysihtml.browser.fixStyleKey(options.styleProperty)] = options.styleValue;
}
}
if (hasNoStyle(element)) {
@@ -15190,7 +13062,7 @@ wysihtml5.Commands = Base.extend(
// Handle similar semantically same elements (queryAliasMap)
nodeNameQuery = options.nodeName ? queryAliasMap[options.nodeName.toLowerCase()] || options.nodeName.toLowerCase() : null;
- nodeQueryMatch = nodeNameQuery ? wysihtml5.dom.domNode(element).test({ query: nodeNameQuery }) : false;
+ nodeQueryMatch = nodeNameQuery ? wysihtml.dom.domNode(element).test({ query: nodeNameQuery }) : false;
// Unwrap element if no attributes present and node name given
// or no attributes and if no nodename set but node is the default
@@ -15199,7 +13071,7 @@ wysihtml5.Commands = Base.extend(
((options.toggle !== false && nodeQueryMatch) || (!options.nodeName && element.nodeName === defaultTag)) &&
hasNoClass(element) && hasNoStyle(element) && hasNoAttributes(element)
) {
- wysihtml5.dom.unwrap(element);
+ wysihtml.dom.unwrap(element);
}
}
@@ -15213,7 +13085,7 @@ wysihtml5.Commands = Base.extend(
if (!selection.isCollapsed()) {
textNodes = textNodes.concat(selection.getOwnNodes([3], function(node) {
// Exclude empty nodes except caret node
- return (!wysihtml5.dom.domNode(node).is.emptyTextNode());
+ return (!wysihtml.dom.domNode(node).is.emptyTextNode());
}, splitBounds));
}
@@ -15249,11 +13121,11 @@ wysihtml5.Commands = Base.extend(
var o;
if (options.nodeName) {
var query = queryAliasMap[options.nodeName.toLowerCase()] || options.nodeName.toLowerCase();
- return wysihtml5.dom.domNode(node).test({ query: query });
+ return wysihtml.dom.domNode(node).test({ query: query });
} else {
- o = wysihtml5.lang.object(options).clone();
+ o = wysihtml.lang.object(options).clone();
o.query = INLINE_ELEMENTS; // make sure only inline elements with styles and classes are counted
- return wysihtml5.dom.domNode(node).test(o);
+ return wysihtml.dom.domNode(node).test(o);
}
}
@@ -15269,7 +13141,7 @@ wysihtml5.Commands = Base.extend(
try {
rangy.getSelection(composer.win).addRange(range);
} catch (e) {}
- if (!composer.doc.activeElement || !wysihtml5.dom.contains(composer.element, composer.doc.activeElement)) {
+ if (!composer.doc.activeElement || !wysihtml.dom.contains(composer.element, composer.doc.activeElement)) {
composer.element.focus();
d.scrollTop = oldScrollTop;
d.scrollLeft = oldScrollLeft;
@@ -15386,7 +13258,7 @@ wysihtml5.Commands = Base.extend(
range.setStartAndEnd(anchor, offsetStart, offsetEnd);
range.splitBoundaries();
txtNodes = range.getNodes([3], function(node) {
- return (!wysihtml5.dom.domNode(node).is.emptyTextNode());
+ return (!wysihtml.dom.domNode(node).is.emptyTextNode());
});
return {
@@ -15458,7 +13330,7 @@ wysihtml5.Commands = Base.extend(
if (wrapNode) {
newWrapNode = wrapNode.cloneNode(false);
- wysihtml5.dom.domNode(textNode).escapeParent(wrapNode, newWrapNode);
+ wysihtml.dom.domNode(textNode).escapeParent(wrapNode, newWrapNode);
updateFormatOfElement(newWrapNode, options);
}
}
@@ -15469,7 +13341,7 @@ wysihtml5.Commands = Base.extend(
wrapNode = findSimilarTextNodeWrapper(textNode, options, container);
if (wrapNode) {
- wysihtml5.dom.domNode(textNode).escapeParent(wrapNode);
+ wysihtml.dom.domNode(textNode).escapeParent(wrapNode);
}
}
@@ -15503,7 +13375,7 @@ wysihtml5.Commands = Base.extend(
} else {
// Escape caret out of format
- textNode = composer.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ textNode = composer.doc.createTextNode(wysihtml.INVISIBLE_SPACE);
newNode = state.nodes[0].cloneNode(false);
newNode.appendChild(textNode);
composer.selection.splitElementAtCaret(state.nodes[0], newNode);
@@ -15568,7 +13440,7 @@ wysihtml5.Commands = Base.extend(
textOffset = selection.anchorOffset;
for (i = state.nodes.length; i--;) {
- wysihtml5.dom.unwrap(state.nodes[i]);
+ wysihtml.dom.unwrap(state.nodes[i]);
}
cleanupAndSetCaret(composer, textNode, textOffset, options);
@@ -15616,7 +13488,7 @@ wysihtml5.Commands = Base.extend(
return options;
}
- wysihtml5.commands.formatInline = {
+ wysihtml.commands.formatInline = {
// Basics:
// In case of plain text or inline state not set wrap all non-empty textnodes with
@@ -15648,195 +13520,93 @@ wysihtml5.Commands = Base.extend(
state = getState(composer, options);
if (state.nodes.length > 0) {
- // Text allready has the format applied
- removeFormat(composer, textNodes, state, options);
- }
-
- composer.element.normalize();
- },
-
- state: function(composer, command, options) {
- options = fixOptions(options);
- var nodes = getState(composer, options, true).nodes;
- return (nodes.length === 0) ? false : nodes;
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- nodeName: "BLOCKQUOTE",
- toggle: true
- };
-
- wysihtml5.commands.insertBlockQuote = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5){
- wysihtml5.commands.insertHTML = {
- exec: function(composer, command, html) {
- composer.selection.insertHTML(html);
- },
-
- state: function() {
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5) {
- var NODE_NAME = "IMG";
-
- wysihtml5.commands.insertImage = {
- /**
- * Inserts an
- * If selection is already an image link, it removes it
- *
- * @example
- * // either ...
- * wysihtml5.commands.insertImage.exec(composer, "insertImage", "http://www.google.de/logo.jpg");
- * // ... or ...
- * wysihtml5.commands.insertImage.exec(composer, "insertImage", { src: "http://www.google.de/logo.jpg", title: "foo" });
- */
- exec: function(composer, command, value) {
- value = typeof(value) === "object" ? value : { src: value };
-
- var doc = composer.doc,
- image = this.state(composer),
- textNode,
- parent;
-
- // If image is selected and src ie empty, set the caret before it and delete the image
- if (image && !value.src) {
- composer.selection.setBefore(image);
- parent = image.parentNode;
- parent.removeChild(image);
-
- // and it's parent too if it hasn't got any other relevant child nodes
- wysihtml5.dom.removeEmptyTextNodes(parent);
- if (parent.nodeName === "A" && !parent.firstChild) {
- composer.selection.setAfter(parent);
- parent.parentNode.removeChild(parent);
- }
-
- // firefox and ie sometimes don't remove the image handles, even though the image got removed
- wysihtml5.quirks.redraw(composer.element);
- return;
- }
-
- // If image selected change attributes accordingly
- if (image) {
- for (var key in value) {
- if (value.hasOwnProperty(key)) {
- image.setAttribute(key === "className" ? "class" : key, value[key]);
- }
- }
- return;
+ // Text allready has the format applied
+ removeFormat(composer, textNodes, state, options);
}
+
+ composer.element.normalize();
+ },
- // Otherwise lets create the image
- image = doc.createElement(NODE_NAME);
+ state: function(composer, command, options) {
+ options = fixOptions(options);
+ var nodes = getState(composer, options, true).nodes;
+ return (nodes.length === 0) ? false : nodes;
+ }
+ };
- for (var i in value) {
- image.setAttribute(i === "className" ? "class" : i, value[i]);
- }
+})(wysihtml);
- composer.selection.insertNode(image);
- if (wysihtml5.browser.hasProblemsSettingCaretAfterImg()) {
- textNode = doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
- composer.selection.insertNode(textNode);
- composer.selection.setAfter(textNode);
- } else {
- composer.selection.setAfter(image);
+(function(wysihtml){
+ wysihtml.commands.indentList = {
+ exec: function(composer, command, value) {
+ var listEls = composer.selection.getSelectionParentsByTag('LI');
+ if (listEls) {
+ return this.tryToPushLiLevel(listEls, composer.selection);
}
+ return false;
},
- state: function(composer) {
- var doc = composer.doc,
- selectedNode,
- text,
- imagesInSelection;
-
- if (!wysihtml5.dom.hasElementWithTagName(doc, NODE_NAME)) {
+ state: function(composer, command) {
return false;
- }
+ },
- selectedNode = composer.selection.getSelectedNode();
- if (!selectedNode) {
- return false;
- }
+ tryToPushLiLevel: function(liNodes, selection) {
+ var listTag, list, prevLi, liNode, prevLiList,
+ found = false;
- if (selectedNode.nodeName === NODE_NAME) {
- // This works perfectly in IE
- return selectedNode;
- }
+ selection.executeAndRestoreRangy(function() {
- if (selectedNode.nodeType !== wysihtml5.ELEMENT_NODE) {
- return false;
- }
+ for (var i = liNodes.length; i--;) {
+ liNode = liNodes[i];
+ listTag = (liNode.parentNode.nodeName === 'OL') ? 'OL' : 'UL';
+ list = liNode.ownerDocument.createElement(listTag);
+ prevLi = wysihtml.dom.domNode(liNode).prev({nodeTypes: [wysihtml.ELEMENT_NODE]});
+ prevLiList = (prevLi) ? prevLi.querySelector('ul, ol') : null;
- text = composer.selection.getText();
- text = wysihtml5.lang.string(text).trim();
- if (text) {
- return false;
- }
+ if (prevLi) {
+ if (prevLiList) {
+ prevLiList.appendChild(liNode);
+ } else {
+ list.appendChild(liNode);
+ prevLi.appendChild(list);
+ }
+ found = true;
+ }
+ }
- imagesInSelection = composer.selection.getNodes(wysihtml5.ELEMENT_NODE, function(node) {
- return node.nodeName === "IMG";
});
-
- if (imagesInSelection.length !== 1) {
- return false;
- }
-
- return imagesInSelection[0];
+ return found;
}
};
-})(wysihtml5);
-;(function(wysihtml5) {
- var LINE_BREAK = " " + (wysihtml5.browser.needsSpaceAfterLineBreak() ? " " : "");
+}(wysihtml));
- wysihtml5.commands.insertLineBreak = {
- exec: function(composer, command) {
- composer.selection.insertHTML(LINE_BREAK);
+(function(wysihtml){
+ wysihtml.commands.insertHTML = {
+ exec: function(composer, command, html) {
+ composer.selection.insertHTML(html);
},
state: function() {
return false;
}
};
-})(wysihtml5);
-;(function(wysihtml5){
- wysihtml5.commands.insertOrderedList = {
- exec: function(composer, command) {
- wysihtml5.commands.insertList.exec(composer, command, "OL");
- },
+}(wysihtml));
- state: function(composer, command) {
- return wysihtml5.commands.insertList.state(composer, command, "OL");
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.insertUnorderedList = {
+(function(wysihtml) {
+ var LINE_BREAK = " " + (wysihtml.browser.needsSpaceAfterLineBreak() ? " " : "");
+
+ wysihtml.commands.insertLineBreak = {
exec: function(composer, command) {
- wysihtml5.commands.insertList.exec(composer, command, "UL");
+ composer.selection.insertHTML(LINE_BREAK);
},
- state: function(composer, command) {
- return wysihtml5.commands.insertList.state(composer, command, "UL");
+ state: function() {
+ return false;
}
};
-}(wysihtml5));
-;wysihtml5.commands.insertList = (function(wysihtml5) {
+})(wysihtml);
+
+wysihtml.commands.insertList = (function(wysihtml) {
var isNode = function(node, name) {
if (node && node.nodeName) {
@@ -15859,7 +13629,7 @@ wysihtml5.Commands = Base.extend(
};
if (node) {
- var parentLi = wysihtml5.dom.getParentElement(node, { query: "li" }, false, composer.element),
+ var parentLi = wysihtml.dom.getParentElement(node, { query: "li" }, false, composer.element),
otherNodeName = (nodeName === "UL") ? "OL" : "UL";
if (isNode(node, nodeName)) {
@@ -15901,511 +13671,138 @@ wysihtml5.Commands = Base.extend(
otherLists = getListsInSelection(otherNodeName, composer);
if (otherLists.length) {
for (var l = otherLists.length; l--;) {
- wysihtml5.dom.renameElement(otherLists[l], nodeName.toLowerCase());
- }
- } else {
- innerLists = getListsInSelection(['OL', 'UL'], composer);
- for (var i = innerLists.length; i--;) {
- wysihtml5.dom.resolveList(innerLists[i], composer.config.useLineBreaks);
- }
- if (innerLists.length === 0) {
- wysihtml5.dom.resolveList(el, composer.config.useLineBreaks);
- }
- }
- });
- };
-
- var handleOtherTypeList = function(el, nodeName, composer) {
- var otherNodeName = (nodeName === "UL") ? "OL" : "UL";
- // Turn an ordered list into an unordered list
- // foo bar
- // becomes:
- //
- // Also rename other lists in selection
- composer.selection.executeAndRestoreRangy(function() {
- var renameLists = [el].concat(getListsInSelection(otherNodeName, composer));
-
- // All selection inner lists get renamed too
- for (var l = renameLists.length; l--;) {
- wysihtml5.dom.renameElement(renameLists[l], nodeName.toLowerCase());
- }
- });
- };
-
- var getListsInSelection = function(nodeName, composer) {
- var ranges = composer.selection.getOwnRanges(),
- renameLists = [];
-
- for (var r = ranges.length; r--;) {
- renameLists = renameLists.concat(ranges[r].getNodes([1], function(node) {
- return isNode(node, nodeName);
- }));
- }
-
- return renameLists;
- };
-
- var createListFallback = function(nodeName, composer) {
- var sel = rangy.saveSelection(composer.win);
-
- // Fallback for Create list
- var tempClassName = "_wysihtml5-temp-" + new Date().getTime(),
- isEmpty, list;
-
- composer.commands.exec("formatBlock", {
- "nodeName": "div",
- "className": tempClassName
- });
-
- var tempElement = composer.element.querySelector("." + tempClassName);
-
- // This space causes new lists to never break on enter
- var INVISIBLE_SPACE_REG_EXP = /\uFEFF/g;
- tempElement.innerHTML = tempElement.innerHTML.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
- if (tempElement) {
- isEmpty = (/^(\s|( ))+$/i).test(tempElement.innerHTML);
- list = wysihtml5.dom.convertToList(tempElement, nodeName.toLowerCase(), composer.parent.config.classNames.uneditableContainer);
- if (sel) {
- rangy.restoreSelection(sel);
- }
- if (isEmpty) {
- composer.selection.selectNode(list.querySelector("li"), true);
- }
- }
- };
-
- return {
- exec: function(composer, command, nodeName) {
- var doc = composer.doc,
- cmd = (nodeName === "OL") ? "insertOrderedList" : "insertUnorderedList",
- s = composer.selection.getSelection(),
- anode = s.anchorNode.nodeType === 1 && s.anchorNode.firstChild ? s.anchorNode.childNodes[s.anchorOffset] : s.anchorNode,
- fnode = s.focusNode.nodeType === 1 && s.focusNode.firstChild ? s.focusNode.childNodes[s.focusOffset] || s.focusNode.lastChild : s.focusNode,
- selectedNode, list;
-
- if (s.isBackwards()) {
- // swap variables
- anode = [fnode, fnode = anode][0];
- }
-
- if (wysihtml5.dom.domNode(fnode).is.emptyTextNode(true) && fnode) {
- fnode = wysihtml5.dom.domNode(fnode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
- }
- if (wysihtml5.dom.domNode(anode).is.emptyTextNode(true) && anode) {
- anode = wysihtml5.dom.domNode(anode).next({nodeTypes: [1,3], ignoreBlankTexts: true});
- }
-
- if (anode && fnode) {
- if (anode === fnode) {
- selectedNode = anode;
- } else {
- selectedNode = wysihtml5.dom.domNode(anode).commonAncestor(fnode, composer.element);
- }
- } else {
- selectedNode = composer.selection.getSelectedNode();
- }
-
- list = findListEl(selectedNode, nodeName, composer);
-
- if (!list.el) {
- if (composer.commands.support(cmd)) {
- doc.execCommand(cmd, false, null);
- } else {
- createListFallback(nodeName, composer);
- }
- } else if (list.other) {
- handleOtherTypeList(list.el, nodeName, composer);
- } else {
- handleSameTypeList(list.el, nodeName, composer);
- }
- },
-
- state: function(composer, command, nodeName) {
- var selectedNode = composer.selection.getSelectedNode(),
- list = findListEl(selectedNode, nodeName, composer);
-
- return (list.el && !list.other) ? list.el : false;
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5){
-
- var nodeOptions = {
- nodeName: "I",
- toggle: true
- };
-
- wysihtml5.commands.italic = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.exec(composer, command, nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
- }
- };
-
-}(wysihtml5));
-;(function(wysihtml5) {
-
- var nodeOptions = {
- className: "wysiwyg-text-align-center",
- classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
- toggle: true
- };
-
- wysihtml5.commands.justifyCenter = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- className: "wysiwyg-text-align-left",
- classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
- toggle: true
- };
-
- wysihtml5.commands.justifyLeft = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- className: "wysiwyg-text-align-right",
- classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
- toggle: true
- };
-
- wysihtml5.commands.justifyRight = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- className: "wysiwyg-text-align-justify",
- classRegExp: /wysiwyg-text-align-[0-9a-z]+/g,
- toggle: true
- };
-
- wysihtml5.commands.justifyFull = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- styleProperty: "textAlign",
- styleValue: "right",
- toggle: true
- };
-
- wysihtml5.commands.alignRightStyle = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-})(wysihtml5);
-;(function(wysihtml5) {
-
- var nodeOptions = {
- styleProperty: "textAlign",
- styleValue: "left",
- toggle: true
- };
-
- wysihtml5.commands.alignLeftStyle = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
+ wysihtml.dom.renameElement(otherLists[l], nodeName.toLowerCase());
+ }
+ } else {
+ innerLists = getListsInSelection(['OL', 'UL'], composer);
+ for (var i = innerLists.length; i--;) {
+ wysihtml.dom.resolveList(innerLists[i], composer.config.useLineBreaks);
+ }
+ if (innerLists.length === 0) {
+ wysihtml.dom.resolveList(el, composer.config.useLineBreaks);
+ }
+ }
+ });
};
-})(wysihtml5);
-;(function(wysihtml5) {
+ var handleOtherTypeList = function(el, nodeName, composer) {
+ var otherNodeName = (nodeName === "UL") ? "OL" : "UL";
+ // Turn an ordered list into an unordered list
+ // foo bar
+ // becomes:
+ //
+ // Also rename other lists in selection
+ composer.selection.executeAndRestoreRangy(function() {
+ var renameLists = [el].concat(getListsInSelection(otherNodeName, composer));
- var nodeOptions = {
- styleProperty: "textAlign",
- styleValue: "center",
- toggle: true
+ // All selection inner lists get renamed too
+ for (var l = renameLists.length; l--;) {
+ wysihtml.dom.renameElement(renameLists[l], nodeName.toLowerCase());
+ }
+ });
};
- wysihtml5.commands.alignCenterStyle = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
+ var getListsInSelection = function(nodeName, composer) {
+ var ranges = composer.selection.getOwnRanges(),
+ renameLists = [];
-})(wysihtml5);
-;(function(wysihtml5) {
+ for (var r = ranges.length; r--;) {
+ renameLists = renameLists.concat(ranges[r].getNodes([1], function(node) {
+ return isNode(node, nodeName);
+ }));
+ }
- var nodeOptions = {
- styleProperty: "textAlign",
- styleValue: "justify",
- toggle: true
+ return renameLists;
};
- wysihtml5.commands.alignJustifyStyle = {
- exec: function(composer, command) {
- return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", nodeOptions);
- },
-
- state: function(composer, command) {
- return wysihtml5.commands.formatBlock.state(composer, "formatBlock", nodeOptions);
- }
- };
-})(wysihtml5);
-;(function(wysihtml5){
- wysihtml5.commands.redo = {
- exec: function(composer) {
- return composer.undoManager.redo();
- },
+ var createListFallback = function(nodeName, composer) {
+ var sel = rangy.saveSelection(composer.win);
- state: function(composer) {
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
+ // Fallback for Create list
+ var tempClassName = "_wysihtml-temp-" + new Date().getTime(),
+ isEmpty, list;
- var nodeOptions = {
- nodeName: "U",
- toggle: true
- };
+ composer.commands.exec("formatBlock", {
+ "nodeName": "div",
+ "className": tempClassName
+ });
- wysihtml5.commands.underline = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.exec(composer, command, nodeOptions);
- },
+ var tempElement = composer.element.querySelector("." + tempClassName);
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
+ // This space causes new lists to never break on enter
+ var INVISIBLE_SPACE_REG_EXP = /\uFEFF/g;
+ tempElement.innerHTML = tempElement.innerHTML.replace(wysihtml.INVISIBLE_SPACE_REG_EXP, "");
+ if (tempElement) {
+ isEmpty = (/^(\s|( ))+$/i).test(tempElement.innerHTML);
+ list = wysihtml.dom.convertToList(tempElement, nodeName.toLowerCase(), composer.parent.config.classNames.uneditableContainer);
+ if (sel) {
+ rangy.restoreSelection(sel);
+ }
+ if (isEmpty) {
+ composer.selection.selectNode(list.querySelector("li"), true);
+ }
}
};
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.undo = {
- exec: function(composer) {
- return composer.undoManager.undo();
- },
+ return {
+ exec: function(composer, command, nodeName) {
+ var doc = composer.doc,
+ cmd = (nodeName === "OL") ? "insertOrderedList" : "insertUnorderedList",
+ s = composer.selection.getSelection(),
+ anode = s.anchorNode.nodeType === 1 && s.anchorNode.firstChild ? s.anchorNode.childNodes[s.anchorOffset] : s.anchorNode,
+ fnode = s.focusNode.nodeType === 1 && s.focusNode.firstChild ? s.focusNode.childNodes[s.focusOffset] || s.focusNode.lastChild : s.focusNode,
+ selectedNode, list;
- state: function(composer) {
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.createTable = {
- exec: function(composer, command, value) {
- var col, row, html;
- if (value && value.cols && value.rows && parseInt(value.cols, 10) > 0 && parseInt(value.rows, 10) > 0) {
- if (value.tableStyle) {
- html = " ";
- } else {
- html = "";
- }
- html += "";
- for (row = 0; row < value.rows; row ++) {
- html += '';
- for (col = 0; col < value.cols; col ++) {
- html += " ";
- }
- html += ' ';
- }
- html += "
";
- composer.commands.exec("insertHTML", html);
- //composer.selection.insertHTML(html);
+ if (s.isBackwards()) {
+ // swap variables
+ anode = [fnode, fnode = anode][0];
}
- },
- state: function(composer, command) {
- return false;
- }
- };
+ if (wysihtml.dom.domNode(fnode).is.emptyTextNode(true) && fnode) {
+ fnode = wysihtml.dom.domNode(fnode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
+ }
+ if (wysihtml.dom.domNode(anode).is.emptyTextNode(true) && anode) {
+ anode = wysihtml.dom.domNode(anode).next({nodeTypes: [1,3], ignoreBlankTexts: true});
+ }
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.mergeTableCells = {
- exec: function(composer, command) {
- if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
- if (this.state(composer, command)) {
- wysihtml5.dom.table.unmergeCell(composer.tableSelection.start);
+ if (anode && fnode) {
+ if (anode === fnode) {
+ selectedNode = anode;
} else {
- wysihtml5.dom.table.mergeCellsBetween(composer.tableSelection.start, composer.tableSelection.end);
+ selectedNode = wysihtml.dom.domNode(anode).commonAncestor(fnode, composer.element);
}
+ } else {
+ selectedNode = composer.selection.getSelectedNode();
}
- },
- state: function(composer, command) {
- if (composer.tableSelection) {
- var start = composer.tableSelection.start,
- end = composer.tableSelection.end;
- if (start && end && start == end &&
- ((
- wysihtml5.dom.getAttribute(start, "colspan") &&
- parseInt(wysihtml5.dom.getAttribute(start, "colspan"), 10) > 1
- ) || (
- wysihtml5.dom.getAttribute(start, "rowspan") &&
- parseInt(wysihtml5.dom.getAttribute(start, "rowspan"), 10) > 1
- ))
- ) {
- return [start];
- }
- }
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.addTableCells = {
- exec: function(composer, command, value) {
- if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+ list = findListEl(selectedNode, nodeName, composer);
- // switches start and end if start is bigger than end (reverse selection)
- var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end);
- if (value == "before" || value == "above") {
- wysihtml5.dom.table.addCells(tableSelect.start, value);
- } else if (value == "after" || value == "below") {
- wysihtml5.dom.table.addCells(tableSelect.end, value);
+ if (!list.el) {
+ if (composer.commands.support(cmd)) {
+ doc.execCommand(cmd, false, null);
+ } else {
+ createListFallback(nodeName, composer);
}
- setTimeout(function() {
- composer.tableSelection.select(tableSelect.start, tableSelect.end);
- },0);
+ } else if (list.other) {
+ handleOtherTypeList(list.el, nodeName, composer);
+ } else {
+ handleSameTypeList(list.el, nodeName, composer);
}
},
- state: function(composer, command) {
- return false;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.deleteTableCells = {
- exec: function(composer, command, value) {
- if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
- var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end),
- idx = wysihtml5.dom.table.indexOf(tableSelect.start),
- selCell,
- table = composer.tableSelection.table;
-
- wysihtml5.dom.table.removeCells(tableSelect.start, value);
- setTimeout(function() {
- // move selection to next or previous if not present
- selCell = wysihtml5.dom.table.findCell(table, idx);
-
- if (!selCell){
- if (value == "row") {
- selCell = wysihtml5.dom.table.findCell(table, {
- "row": idx.row - 1,
- "col": idx.col
- });
- }
+ state: function(composer, command, nodeName) {
+ var selectedNode = composer.selection.getSelectedNode(),
+ list = findListEl(selectedNode, nodeName, composer);
- if (value == "column") {
- selCell = wysihtml5.dom.table.findCell(table, {
- "row": idx.row,
- "col": idx.col - 1
- });
- }
- }
- if (selCell) {
- composer.tableSelection.select(selCell, selCell);
- }
- }, 0);
+ return (list.el && !list.other) ? list.el : false;
}
- },
-
- state: function(composer, command) {
- return false;
- }
};
-}(wysihtml5));
-;(function(wysihtml5){
- wysihtml5.commands.indentList = {
- exec: function(composer, command, value) {
- var listEls = composer.selection.getSelectionParentsByTag('LI');
- if (listEls) {
- return this.tryToPushLiLevel(listEls, composer.selection);
- }
- return false;
- },
-
- state: function(composer, command) {
- return false;
- },
-
- tryToPushLiLevel: function(liNodes, selection) {
- var listTag, list, prevLi, liNode, prevLiList,
- found = false;
-
- selection.executeAndRestoreRangy(function() {
-
- for (var i = liNodes.length; i--;) {
- liNode = liNodes[i];
- listTag = (liNode.parentNode.nodeName === 'OL') ? 'OL' : 'UL';
- list = liNode.ownerDocument.createElement(listTag);
- prevLi = wysihtml5.dom.domNode(liNode).prev({nodeTypes: [wysihtml5.ELEMENT_NODE]});
- prevLiList = (prevLi) ? prevLi.querySelector('ul, ol') : null;
- if (prevLi) {
- if (prevLiList) {
- prevLiList.appendChild(liNode);
- } else {
- list.appendChild(liNode);
- prevLi.appendChild(list);
- }
- found = true;
- }
- }
+})(wysihtml);
- });
- return found;
- }
- };
-}(wysihtml5));
-;(function(wysihtml5){
+(function(wysihtml){
- wysihtml5.commands.outdentList = {
+ wysihtml.commands.outdentList = {
exec: function(composer, command, value) {
var listEls = composer.selection.getSelectionParentsByTag('LI');
if (listEls) {
@@ -16433,8 +13830,8 @@ wysihtml5.Commands = Base.extend(
if (listNode.tagName === 'OL' || listNode.tagName === 'UL') {
found = true;
- outerListNode = wysihtml5.dom.getParentElement(listNode.parentNode, { query: 'ol, ul' }, false, composer.element);
- outerLiNode = wysihtml5.dom.getParentElement(listNode.parentNode, { query: 'li' }, false, composer.element);
+ outerListNode = wysihtml.dom.getParentElement(listNode.parentNode, { query: 'ol, ul' }, false, composer.element);
+ outerLiNode = wysihtml.dom.getParentElement(listNode.parentNode, { query: 'li' }, false, composer.element);
if (outerListNode && outerLiNode) {
@@ -16483,66 +13880,75 @@ wysihtml5.Commands = Base.extend(
}
};
-}(wysihtml5));
-;(function(wysihtml5){
-
+}(wysihtml));
+
+(function(wysihtml){
+ wysihtml.commands.redo = {
+ exec: function(composer) {
+ return composer.undoManager.redo();
+ },
+
+ state: function(composer) {
+ return false;
+ }
+ };
+}(wysihtml));
+
+(function(wysihtml) {
+
var nodeOptions = {
- nodeName: "SUB",
- toggle: true
+ nodeName: "A"
};
- wysihtml5.commands.subscript = {
+ wysihtml.commands.removeLink = {
exec: function(composer, command) {
- wysihtml5.commands.formatInline.exec(composer, command, nodeOptions);
+ wysihtml.commands.formatInline.remove(composer, command, nodeOptions);
},
state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
+ return wysihtml.commands.formatInline.state(composer, command, nodeOptions);
}
};
-}(wysihtml5));
-;(function(wysihtml5) {
- var nodeOptions = {
- nodeName: "SUP",
- toggle: true
- };
+})(wysihtml);
- wysihtml5.commands.superscript = {
- exec: function(composer, command) {
- wysihtml5.commands.formatInline.exec(composer, command, nodeOptions);
+(function(wysihtml){
+ wysihtml.commands.undo = {
+ exec: function(composer) {
+ return composer.undoManager.undo();
},
- state: function(composer, command) {
- return wysihtml5.commands.formatInline.state(composer, command, nodeOptions);
+ state: function(composer) {
+ return false;
}
};
-}(wysihtml5));
-;/**
- * Undo Manager for wysihtml5
+}(wysihtml));
+
+/**
+ * Undo Manager for wysihtml
* slightly inspired by http://rniwa.com/editing/undomanager.html#the-undomanager-interface
*/
-(function(wysihtml5) {
+(function(wysihtml) {
var Z_KEY = 90,
Y_KEY = 89,
BACKSPACE_KEY = 8,
DELETE_KEY = 46,
MAX_HISTORY_ENTRIES = 25,
- DATA_ATTR_NODE = "data-wysihtml5-selection-node",
- DATA_ATTR_OFFSET = "data-wysihtml5-selection-offset",
- UNDO_HTML = '' + wysihtml5.INVISIBLE_SPACE + ' ',
- REDO_HTML = '' + wysihtml5.INVISIBLE_SPACE + ' ',
- dom = wysihtml5.dom;
+ DATA_ATTR_NODE = "data-wysihtml-selection-node",
+ DATA_ATTR_OFFSET = "data-wysihtml-selection-offset",
+ UNDO_HTML = '' + wysihtml.INVISIBLE_SPACE + ' ',
+ REDO_HTML = '' + wysihtml.INVISIBLE_SPACE + ' ',
+ dom = wysihtml.dom;
function cleanTempElements(doc) {
var tempElement;
- while (tempElement = doc.querySelector("._wysihtml5-temp")) {
+ while (tempElement = doc.querySelector("._wysihtml-temp")) {
tempElement.parentNode.removeChild(tempElement);
}
}
- wysihtml5.UndoManager = wysihtml5.lang.Dispatcher.extend(
- /** @scope wysihtml5.UndoManager.prototype */ {
+ wysihtml.UndoManager = wysihtml.lang.Dispatcher.extend(
+ /** @scope wysihtml.UndoManager.prototype */ {
constructor: function(editor) {
this.editor = editor;
this.composer = editor.composer;
@@ -16630,7 +14036,7 @@ wysihtml5.Commands = Base.extend(
node = (range && range.startContainer) ? range.startContainer : this.element;
offset = (range && range.startOffset) ? range.startOffset : 0;
- if (node.nodeType === wysihtml5.ELEMENT_NODE) {
+ if (node.nodeType === wysihtml.ELEMENT_NODE) {
element = node;
} else {
element = node.parentNode;
@@ -16732,12 +14138,13 @@ wysihtml5.Commands = Base.extend(
return parent.childNodes[index];
}
});
-})(wysihtml5);
-;/**
+})(wysihtml);
+
+/**
* TODO: the following methods still need unit test coverage
*/
-wysihtml5.views.View = Base.extend(
- /** @scope wysihtml5.views.View.prototype */ {
+wysihtml.views.View = Base.extend(
+ /** @scope wysihtml.views.View.prototype */ {
constructor: function(parent, textareaElement, config) {
this.parent = parent;
this.element = textareaElement;
@@ -16787,12 +14194,13 @@ wysihtml5.views.View = Base.extend(
this.element.removeAttribute("disabled");
}
});
-;(function(wysihtml5) {
- var dom = wysihtml5.dom,
- browser = wysihtml5.browser;
- wysihtml5.views.Composer = wysihtml5.views.View.extend(
- /** @scope wysihtml5.views.Composer.prototype */ {
+(function(wysihtml) {
+ var dom = wysihtml.dom,
+ browser = wysihtml.browser;
+
+ wysihtml.views.Composer = wysihtml.views.View.extend(
+ /** @scope wysihtml.views.Composer.prototype */ {
name: "composer",
constructor: function(parent, editableElement, config) {
@@ -16814,7 +14222,7 @@ wysihtml5.views.View = Base.extend(
},
getValue: function(parse, clearInternals) {
- var value = this.isEmpty() ? "" : wysihtml5.quirks.getCorrectInnerHTML(this.element);
+ var value = this.isEmpty() ? "" : wysihtml.quirks.getCorrectInnerHTML(this.element);
if (parse !== false) {
value = this.parent.parse(value, (clearInternals === false) ? false : true);
}
@@ -16876,7 +14284,7 @@ wysihtml5.views.View = Base.extend(
// IE 8 fires the focus event after .focus()
// This is needed by our simulate_placeholder.js to work
// therefore we clear it ourselves this time
- if (wysihtml5.browser.doesAsyncFocus() && this.hasPlaceholderSet()) {
+ if (wysihtml.browser.doesAsyncFocus() && this.hasPlaceholderSet()) {
this.clear();
}
@@ -16977,7 +14385,7 @@ wysihtml5.views.View = Base.extend(
if (this.textarea.element.form) {
var hiddenField = document.createElement("input");
hiddenField.type = "hidden";
- hiddenField.name = "_wysihtml5_mode";
+ hiddenField.name = "_wysihtml_mode";
hiddenField.value = 1;
dom.insert(hiddenField).after(this.textarea.element);
}
@@ -16996,10 +14404,10 @@ wysihtml5.views.View = Base.extend(
}
// Make sure our selection handler is ready
- this.selection = new wysihtml5.Selection(this.parent, this.element, this.config.classNames.uneditableContainer);
+ this.selection = new wysihtml.Selection(this.parent, this.element, this.config.classNames.uneditableContainer);
// Make sure commands dispatcher is ready
- this.commands = new wysihtml5.Commands(this.parent);
+ this.commands = new wysihtml.Commands(this.parent);
if (!this.config.noTextarea) {
dom.copyAttributes([
@@ -17053,7 +14461,7 @@ wysihtml5.views.View = Base.extend(
// IE sometimes leaves a single paragraph, which can't be removed by the user
if (!browser.clearsContentEditableCorrectly()) {
- wysihtml5.quirks.ensureProperClearing(this);
+ wysihtml.quirks.ensureProperClearing(this);
}
// Set up a sync that makes sure that textarea and editor have the same content
@@ -17091,7 +14499,7 @@ wysihtml5.views.View = Base.extend(
isInUneditable = false;
for (var i = uneditables.length; i--;) {
- if (wysihtml5.dom.contains(uneditables[i], nodeWithSelection)) {
+ if (wysihtml.dom.contains(uneditables[i], nodeWithSelection)) {
isInUneditable = true;
}
}
@@ -17114,7 +14522,7 @@ wysihtml5.views.View = Base.extend(
// The autoLink helper method reveals a reg exp to detect correct urls
urlRegExp = dom.autoLink.URL_REG_EXP,
getTextContent = function(element) {
- var textContent = wysihtml5.lang.string(dom.getTextContent(element)).trim();
+ var textContent = wysihtml.lang.string(dom.getTextContent(element)).trim();
if (textContent.substr(0, 4) === "www.") {
textContent = "http://" + textContent;
}
@@ -17181,13 +14589,13 @@ wysihtml5.views.View = Base.extend(
}
// After resizing IE sometimes forgets to remove the old resize handles
- wysihtml5.quirks.redraw(element);
+ wysihtml.quirks.redraw(element);
});
}
},
_initUndoManager: function() {
- this.undoManager = new wysihtml5.UndoManager(this.parent);
+ this.undoManager = new wysihtml.UndoManager(this.parent);
},
_initLineBreaking: function() {
@@ -17237,7 +14645,7 @@ wysihtml5.views.View = Base.extend(
return;
}
- if (keyCode !== wysihtml5.ENTER_KEY && keyCode !== wysihtml5.BACKSPACE_KEY) {
+ if (keyCode !== wysihtml.ENTER_KEY && keyCode !== wysihtml.BACKSPACE_KEY) {
return;
}
var blockElement = dom.getParentElement(that.selection.getSelectedNode(), { query: USE_NATIVE_LINE_BREAK_INSIDE_TAGS }, 4);
@@ -17259,22 +14667,23 @@ wysihtml5.views.View = Base.extend(
}
}
- if (keyCode === wysihtml5.ENTER_KEY && blockElement.nodeName.match(/^H[1-6]$/)) {
+ if (keyCode === wysihtml.ENTER_KEY && blockElement.nodeName.match(/^H[1-6]$/)) {
adjust(selectedNode);
}
}, 0);
return;
}
- if (that.config.useLineBreaks && keyCode === wysihtml5.ENTER_KEY && !wysihtml5.browser.insertsLineBreaksOnReturn()) {
+ if (that.config.useLineBreaks && keyCode === wysihtml.ENTER_KEY && !wysihtml.browser.insertsLineBreaksOnReturn()) {
event.preventDefault();
that.commands.exec("insertLineBreak");
}
});
}
});
-})(wysihtml5);
-;(function(wysihtml5) {
- var dom = wysihtml5.dom,
+})(wysihtml);
+
+(function(wysihtml) {
+ var dom = wysihtml.dom,
doc = document,
win = window,
HOST_TEMPLATE = doc.createElement("div"),
@@ -17317,8 +14726,8 @@ wysihtml5.views.View = Base.extend(
"html { height: 100%; }",
"body { height: 100%; padding: 1px 0 0 0; margin: -1px 0 0 0; }",
"body > p:first-child { margin-top: 0; }",
- "._wysihtml5-temp { display: none; }",
- wysihtml5.browser.isGecko ?
+ "._wysihtml-temp { display: none; }",
+ wysihtml.browser.isGecko ?
"body.placeholder { color: graytext !important; }" :
"body.placeholder { color: #a9a9a9 !important; }",
// Ensure that user see's broken images and can delete them
@@ -17371,7 +14780,7 @@ wysihtml5.views.View = Base.extend(
};
- wysihtml5.views.Composer.prototype.style = function() {
+ wysihtml.views.Composer.prototype.style = function() {
var that = this,
originalActiveElement = doc.querySelector(":focus"),
textareaElement = this.textarea.element,
@@ -17436,7 +14845,7 @@ wysihtml5.views.View = Base.extend(
// Make sure that we don't change the display style of the iframe when copying styles oblur/onfocus
// this is needed for when the change_view event is fired where the iframe is hidden and then
// the blur event fires and re-displays it
- var boxFormattingStyles = wysihtml5.lang.array(BOX_FORMATTING).without(["display"]);
+ var boxFormattingStyles = wysihtml.lang.array(BOX_FORMATTING).without(["display"]);
// --------- restore focus ---------
if (originalActiveElement) {
@@ -17473,8 +14882,9 @@ wysihtml5.views.View = Base.extend(
return this;
};
-})(wysihtml5);
-;/**
+})(wysihtml);
+
+/**
* Taking care of events
* - Simulating 'change' event on contentEditable element
* - Handling drag & drop logic
@@ -17482,10 +14892,10 @@ wysihtml5.views.View = Base.extend(
* - Dispatch proprietary newword:composer event
* - Keyboard shortcuts
*/
-(function(wysihtml5) {
- var dom = wysihtml5.dom,
+(function(wysihtml) {
+ var dom = wysihtml.dom,
domNode = dom.domNode,
- browser = wysihtml5.browser,
+ browser = wysihtml.browser,
/**
* Map keyCodes to query commands
*/
@@ -17494,11 +14904,11 @@ wysihtml5.views.View = Base.extend(
"73": "italic", // I
"85": "underline" // U
};
-
+
var actions = {
// Adds multiple eventlisteners to target, bound to one callback
- // TODO: If needed elsewhere make it part of wysihtml5.dom or sth
+ // TODO: If needed elsewhere make it part of wysihtml.dom or sth
addListeners: function (target, events, callback) {
for(var i = 0, max = events.length; i < max; i++) {
target.addEventListener(events[i], callback, false);
@@ -17506,7 +14916,7 @@ wysihtml5.views.View = Base.extend(
},
// Removes multiple eventlisteners from target, bound to one callback
- // TODO: If needed elsewhere make it part of wysihtml5.dom or sth
+ // TODO: If needed elsewhere make it part of wysihtml.dom or sth
removeListeners: function (target, events, callback) {
for(var i = 0, max = events.length; i < max; i++) {
target.removeEventListener(events[i], callback, false);
@@ -17518,7 +14928,7 @@ wysihtml5.views.View = Base.extend(
if (composer.selection.caretIsLastInSelection()) {
var sel = composer.selection.getSelection(),
aNode = sel.anchorNode;
- if (aNode && aNode.nodeType === 1 && (wysihtml5.dom.getParentElement(aNode, {query: 'td, th'}, false, composer.element) || force)) {
+ if (aNode && aNode.nodeType === 1 && (wysihtml.dom.getParentElement(aNode, {query: 'td, th'}, false, composer.element) || force)) {
var nextNode = aNode.childNodes[sel.anchorOffset];
if (nextNode && nextNode.nodeType === 1 & nextNode.nodeName === "BR") {
nextNode.parentNode.removeChild(nextNode);
@@ -17537,7 +14947,7 @@ wysihtml5.views.View = Base.extend(
return true;
}
try {
- var ev = new CustomEvent("wysihtml5:uneditable:delete", {bubbles: true, cancelable: false});
+ var ev = new CustomEvent("wysihtml:uneditable:delete", {bubbles: true, cancelable: false});
before.node.dispatchEvent(ev);
} catch (err) {}
before.node.parentNode.removeChild(before.node);
@@ -17552,9 +14962,9 @@ wysihtml5.views.View = Base.extend(
var selection = composer.selection,
prevNode = selection.getPreviousNode();
- if (selection.caretIsFirstInSelection(wysihtml5.browser.usesControlRanges()) && prevNode) {
+ if (selection.caretIsFirstInSelection(wysihtml.browser.usesControlRanges()) && prevNode) {
if (prevNode.nodeType === 1 &&
- wysihtml5.dom.domNode(prevNode).is.block() &&
+ wysihtml.dom.domNode(prevNode).is.block() &&
!domNode(prevNode).test({
query: "ol, ul, table, tr, dl"
})
@@ -17568,7 +14978,7 @@ wysihtml5.views.View = Base.extend(
var selNode = prevNode.lastChild,
selectedNode = selection.getSelectedNode(),
commonAncestorNode = domNode(prevNode).commonAncestor(selectedNode, composer.element),
- curNode = wysihtml5.dom.getParentElement(selectedNode, {
+ curNode = wysihtml.dom.getParentElement(selectedNode, {
query: "h1, h2, h3, h4, h5, h6, p, pre, div, blockquote"
}, false, commonAncestorNode || composer.element);
@@ -17576,7 +14986,7 @@ wysihtml5.views.View = Base.extend(
domNode(curNode).transferContentTo(prevNode, true);
selection.setAfter(selNode);
return true;
- } else if (wysihtml5.browser.usesControlRanges()) {
+ } else if (wysihtml.browser.usesControlRanges()) {
selectedNode = selection.getCaretNode();
domNode(selectedNode).transferContentTo(prevNode, true);
selection.setAfter(selNode);
@@ -17592,11 +15002,13 @@ wysihtml5.views.View = Base.extend(
/* In IE when deleting with caret at the begining of LI, list gets broken into half instead of merging the LI with previous */
/* This does not match other browsers an is less intuitive from UI standpoint, thus has to be fixed */
fixDeleteInTheBeginningOfLi: function(composer) {
- if (wysihtml5.browser.hasLiDeletingProblem()) {
+ if (wysihtml.browser.hasLiDeletingProblem()) {
var selection = composer.selection.getSelection(),
aNode = selection.anchorNode,
listNode, prevNode, firstNode,
- isInBeginnig = composer.selection.caretIsFirstInSelection();
+ isInBeginnig = composer.selection.caretIsFirstInSelection(),
+ prevNode,
+ intermediaryNode;
// Fix caret at the beginnig of first textNode in LI
if (aNode.nodeType === 3 && selection.anchorOffset === 0 && aNode === aNode.parentNode.firstChild) {
@@ -17608,10 +15020,16 @@ wysihtml5.views.View = Base.extend(
prevNode = domNode(aNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
if (!prevNode && aNode.parentNode && (aNode.parentNode.nodeName === "UL" || aNode.parentNode.nodeName === "OL")) {
prevNode = domNode(aNode.parentNode).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
+ intermediaryNode = aNode.parentNode;
}
if (prevNode) {
firstNode = aNode.firstChild;
domNode(aNode).transferContentTo(prevNode, true);
+
+ if (intermediaryNode && intermediaryNode.children.length === 0){
+ intermediaryNode.remove();
+ }
+
if (firstNode) {
composer.selection.setBefore(firstNode);
} else if (prevNode) {
@@ -17631,7 +15049,7 @@ wysihtml5.views.View = Base.extend(
}
return false;
},
-
+
fixDeleteInTheBeginningOfControlSelection: function(composer) {
var selection = composer.selection,
prevNode = selection.getPreviousNode(),
@@ -17652,32 +15070,6 @@ wysihtml5.views.View = Base.extend(
return false;
},
- // Table management
- // If present enableObjectResizing and enableInlineTableEditing command should be called with false to prevent native table handlers
- initTableHandling: function() {
- var hideHandlers = function() {
- window.removeEventListener('load', hideHandlers);
- this.doc.execCommand("enableObjectResizing", false, "false");
- this.doc.execCommand("enableInlineTableEditing", false, "false");
- }.bind(this),
- iframeInitiator = (function() {
- hideHandlers.call(this);
- actions.removeListeners(this.sandbox.getIframe(), ["focus", "mouseup", "mouseover"], iframeInitiator);
- }).bind(this);
-
- if( this.doc.execCommand &&
- wysihtml5.browser.supportsCommand(this.doc, "enableObjectResizing") &&
- wysihtml5.browser.supportsCommand(this.doc, "enableInlineTableEditing"))
- {
- if (this.sandbox.getIframe) {
- actions.addListeners(this.sandbox.getIframe(), ["focus", "mouseup", "mouseover"], iframeInitiator);
- } else {
- window.addEventListener('load', hideHandlers);
- }
- }
- this.tableSelection = wysihtml5.quirks.tableCellsSelection(this.element, this.parent);
- },
-
// Fixes some misbehaviours of enters in linebreaks mode (natively a bit unsupported feature)
// Returns true if some corrections is applied so events know when to prevent default
doLineBreaksModeEnterWithCaret: function(composer) {
@@ -17723,7 +15115,7 @@ wysihtml5.views.View = Base.extend(
composer.selection.setBefore(brNode);
}
- } else if (caretInfo.caretNode.nodeType === 3 && wysihtml5.browser.hasCaretBlockElementIssue() && caretInfo.textOffset === caretInfo.caretNode.data.length && !caretInfo.nextNode) {
+ } else if (caretInfo.caretNode.nodeType === 3 && wysihtml.browser.hasCaretBlockElementIssue() && caretInfo.textOffset === caretInfo.caretNode.data.length && !caretInfo.nextNode) {
// This fixes annoying webkit issue when you press enter at the end of a block then seemingly nothing happens.
// in reality one line break is generated and cursor is reported after it, but when entering something cursor jumps before the br
@@ -17748,6 +15140,14 @@ wysihtml5.views.View = Base.extend(
element = composer.element;
if (selection.isCollapsed()) {
+ /**
+ * when the editor is empty in useLineBreaks = false mode, preserve
+ * the default value in it which is
+ */
+ if (composer.isEmpty() && !composer.config.useLineBreaks) {
+ event.preventDefault();
+ return;
+ }
if (actions.handleUneditableDeletion(composer)) {
event.preventDefault();
return;
@@ -17764,7 +15164,7 @@ wysihtml5.views.View = Base.extend(
event.preventDefault();
return;
}
- if (wysihtml5.browser.usesControlRanges()) {
+ if (wysihtml.browser.usesControlRanges()) {
if (actions.fixDeleteInTheBeginningOfControlSelection(composer)) {
event.preventDefault();
return;
@@ -17858,7 +15258,7 @@ wysihtml5.views.View = Base.extend(
if (this.config.copyedFromMarking) {
// If supported the copied source can be based directly on selection
// Very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection.
- if (wysihtml5.browser.supportsModernPaste()) {
+ if (wysihtml.browser.supportsModernPaste()) {
event.clipboardData.setData("text/html", this.config.copyedFromMarking + this.selection.getHtml());
event.clipboardData.setData("text/plain", this.selection.getPlainText());
event.preventDefault();
@@ -17869,7 +15269,7 @@ wysihtml5.views.View = Base.extend(
var handleKeyUp = function(event) {
var keyCode = event.keyCode;
- if (keyCode === wysihtml5.SPACE_KEY || keyCode === wysihtml5.ENTER_KEY) {
+ if (keyCode === wysihtml.SPACE_KEY || keyCode === wysihtml.ENTER_KEY) {
this.parent.fire("newword:composer");
}
};
@@ -17880,15 +15280,15 @@ wysihtml5.views.View = Base.extend(
var target = event.target,
allImages = this.element.querySelectorAll('img'),
notMyImages = this.element.querySelectorAll('.' + this.config.classNames.uneditableContainer + ' img'),
- myImages = wysihtml5.lang.array(allImages).without(notMyImages);
+ myImages = wysihtml.lang.array(allImages).without(notMyImages);
- if (target.nodeName === "IMG" && wysihtml5.lang.array(myImages).contains(target)) {
+ if (target.nodeName === "IMG" && wysihtml.lang.array(myImages).contains(target)) {
this.selection.selectNode(target);
}
}
// Saves mousedown position for IE controlSelect fix
- if (wysihtml5.browser.usesControlRanges()) {
+ if (wysihtml.browser.usesControlRanges()) {
this.selection.lastMouseDownPos = {x: event.clientX, y: event.clientY};
setTimeout(function() {
delete this.selection.lastMouseDownPos;
@@ -17916,7 +15316,7 @@ wysihtml5.views.View = Base.extend(
if (this.config.classNames.uneditableContainer) {
// If uneditables is configured, makes clicking on uneditable move caret after clicked element (so it can be deleted like text)
// If uneditable needs text selection itself event.stopPropagation can be used to prevent this behaviour
- var uneditable = wysihtml5.dom.getParentElement(event.target, { query: "." + this.config.classNames.uneditableContainer }, false, this.element);
+ var uneditable = wysihtml.dom.getParentElement(event.target, { query: "." + this.config.classNames.uneditableContainer }, false, this.element);
if (uneditable) {
this.selection.setAfter(uneditable);
}
@@ -17950,13 +15350,13 @@ wysihtml5.views.View = Base.extend(
event.preventDefault();
}
- if (keyCode === wysihtml5.BACKSPACE_KEY) {
+ if (keyCode === wysihtml.BACKSPACE_KEY) {
// Delete key override for special cases
handleDeleteKeyPress(event, this);
}
// Make sure that when pressing backspace/delete on selected images deletes the image and it's anchor
- if (keyCode === wysihtml5.BACKSPACE_KEY || keyCode === wysihtml5.DELETE_KEY) {
+ if (keyCode === wysihtml.BACKSPACE_KEY || keyCode === wysihtml.DELETE_KEY) {
target = this.selection.getSelectedNode(true);
if (target && target.nodeName === "IMG") {
event.preventDefault();
@@ -17967,18 +15367,18 @@ wysihtml5.views.View = Base.extend(
parent.parentNode.removeChild(parent);
}
setTimeout((function() {
- wysihtml5.quirks.redraw(this.element);
+ wysihtml.quirks.redraw(this.element);
}).bind(this), 0);
}
}
- if (this.config.handleTabKey && keyCode === wysihtml5.TAB_KEY) {
+ if (this.config.handleTabKey && keyCode === wysihtml.TAB_KEY) {
// TAB key handling
event.preventDefault();
handleTabKeyDown(this, this.element, event.shiftKey);
}
- if (keyCode === wysihtml5.ENTER_KEY) {
+ if (keyCode === wysihtml.ENTER_KEY) {
handleEnterKeyPress(event, this);
}
@@ -17997,11 +15397,11 @@ wysihtml5.views.View = Base.extend(
this.selection.getSelection().removeAllRanges();
}).bind(this), 0);
};
-
+
// Testing requires actions to be accessible from out of scope
- wysihtml5.views.Composer.prototype.observeActions = actions;
+ wysihtml.views.Composer.prototype.observeActions = actions;
- wysihtml5.views.Composer.prototype.observe = function() {
+ wysihtml.views.Composer.prototype.observe = function() {
var that = this,
container = (this.sandbox.getIframe) ? this.sandbox.getIframe() : this.sandbox.getContentEditable(),
element = this.element,
@@ -18022,16 +15422,10 @@ wysihtml5.views.View = Base.extend(
}, 250);
}
- // --------- User interactions --
- if (this.config.handleTables) {
- // If handleTables option is true, table handling functions are bound
- actions.initTableHandling.call(this);
- }
-
actions.addListeners(focusBlurElement, ["drop", "paste", "mouseup", "focus", "keyup"], handleUserInteraction.bind(this));
focusBlurElement.addEventListener("focus", handleFocus.bind(this), false);
focusBlurElement.addEventListener("blur", handleBlur.bind(this), false);
-
+
actions.addListeners(this.element, ["drop", "paste", "beforepaste"], handlePaste.bind(this), false);
this.element.addEventListener("copy", handleCopy.bind(this), false);
this.element.addEventListener("mousedown", handleMouseDown.bind(this), false);
@@ -18041,7 +15435,7 @@ wysihtml5.views.View = Base.extend(
this.element.addEventListener("keydown", handleKeyDown.bind(this), false);
// IE controlselect madness fix
- if (wysihtml5.browser.usesControlRanges()) {
+ if (wysihtml.browser.usesControlRanges()) {
this.element.addEventListener('mscontrolselect', handleIEControlSelect.bind(this), false);
}
@@ -18050,15 +15444,16 @@ wysihtml5.views.View = Base.extend(
}).bind(this), false);
};
-})(wysihtml5);
-;/**
+})(wysihtml);
+
+/**
* Class that takes care that the value of the composer and the textarea is always in sync
*/
-(function(wysihtml5) {
+(function(wysihtml) {
var INTERVAL = 400;
- wysihtml5.views.Synchronizer = Base.extend(
- /** @scope wysihtml5.views.Synchronizer.prototype */ {
+ wysihtml.views.Synchronizer = Base.extend(
+ /** @scope wysihtml.views.Synchronizer.prototype */ {
constructor: function(editor, textarea, composer) {
this.editor = editor;
@@ -18074,7 +15469,7 @@ wysihtml5.views.View = Base.extend(
* @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the textarea
*/
fromComposerToTextarea: function(shouldParseHtml) {
- this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue(false, false)).trim(), shouldParseHtml);
+ this.textarea.setValue(wysihtml.lang.string(this.composer.getValue(false, false)).trim(), shouldParseHtml);
},
/**
@@ -18126,10 +15521,10 @@ wysihtml5.views.View = Base.extend(
if (form) {
// If the textarea is in a form make sure that after onreset and onsubmit the composer
// has the correct state
- wysihtml5.dom.observe(form, "submit", function() {
+ wysihtml.dom.observe(form, "submit", function() {
that.sync(true);
});
- wysihtml5.dom.observe(form, "reset", function() {
+ wysihtml.dom.observe(form, "reset", function() {
setTimeout(function() { that.fromTextareaToComposer(); }, 0);
});
}
@@ -18147,11 +15542,12 @@ wysihtml5.views.View = Base.extend(
this.editor.on("destroy:composer", stopInterval);
}
});
-})(wysihtml5);
-;(function(wysihtml5) {
+})(wysihtml);
+
+(function(wysihtml) {
- wysihtml5.views.SourceView = Base.extend(
- /** @scope wysihtml5.views.SourceView.prototype */ {
+ wysihtml.views.SourceView = Base.extend(
+ /** @scope wysihtml.views.SourceView.prototype */ {
constructor: function(editor, composer) {
this.editor = editor;
@@ -18167,7 +15563,7 @@ wysihtml5.views.View = Base.extend(
if (!this.textarea) {
this.textarea = this.composer.doc.createElement('textarea');
- this.textarea.className = "wysihtml5-source-view";
+ this.textarea.className = "wysihtml-source-view";
}
this.textarea.style.width = width + 'px';
this.textarea.style.height = height + 'px';
@@ -18202,9 +15598,10 @@ wysihtml5.views.View = Base.extend(
});
-})(wysihtml5);
-;wysihtml5.views.Textarea = wysihtml5.views.View.extend(
- /** @scope wysihtml5.views.Textarea.prototype */ {
+})(wysihtml);
+
+wysihtml.views.Textarea = wysihtml.views.View.extend(
+ /** @scope wysihtml.views.Textarea.prototype */ {
name: "textarea",
constructor: function(parent, textareaElement, config) {
@@ -18238,7 +15635,7 @@ wysihtml5.views.View = Base.extend(
},
hasPlaceholderSet: function() {
- var supportsPlaceholder = wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),
+ var supportsPlaceholder = wysihtml.browser.supportsPlaceholderAttributeOn(this.element),
placeholderText = this.element.getAttribute("placeholder") || null,
value = this.element.value,
isEmpty = !value;
@@ -18246,7 +15643,7 @@ wysihtml5.views.View = Base.extend(
},
isEmpty: function() {
- return !wysihtml5.lang.string(this.element.value).trim() || this.hasPlaceholderSet();
+ return !wysihtml.lang.string(this.element.value).trim() || this.hasPlaceholderSet();
},
_observe: function() {
@@ -18260,25 +15657,26 @@ wysihtml5.views.View = Base.extend(
* Calling focus() or blur() on an element doesn't synchronously trigger the attached focus/blur events
* This is the case for focusin and focusout, so let's use them whenever possible, kkthxbai
*/
- events = wysihtml5.browser.supportsEvent("focusin") ? ["focusin", "focusout", "change"] : ["focus", "blur", "change"];
+ events = wysihtml.browser.supportsEvent("focusin") ? ["focusin", "focusout", "change"] : ["focus", "blur", "change"];
parent.on("beforeload", function() {
- wysihtml5.dom.observe(element, events, function(event) {
+ wysihtml.dom.observe(element, events, function(event) {
var eventName = eventMapping[event.type] || event.type;
parent.fire(eventName).fire(eventName + ":textarea");
});
- wysihtml5.dom.observe(element, ["paste", "drop"], function() {
+ wysihtml.dom.observe(element, ["paste", "drop"], function() {
setTimeout(function() { parent.fire("paste").fire("paste:textarea"); }, 0);
});
});
}
});
-;/**
- * WYSIHTML5 Editor
+
+/**
+ * WYSIHTML Editor
*
* @param {Element} editableElement Reference to the textarea which should be turned into a rich text interface
- * @param {Object} [config] See defaultConfig object below for explanation of each individual config option
+ * @param {Object} [config] See defaults object below for explanation of each individual config option
*
* @events
* load
@@ -18305,78 +15703,69 @@ wysihtml5.views.View = Base.extend(
* disable:composer
* change_view
*/
-(function(wysihtml5) {
+(function(wysihtml) {
var undef;
- var defaultConfig = {
- // Give the editor a name, the name will also be set as class name on the iframe and on the iframe's body
- name: undef,
- // Whether the editor should look like the textarea (by adopting styles)
- style: true,
- // Id of the toolbar element, pass falsey value if you don't want any toolbar logic
- toolbar: undef,
- // Whether toolbar is displayed after init by script automatically.
- // Can be set to false if toolobar is set to display only on editable area focus
- showToolbarAfterInit: true,
- // With default toolbar it shows dialogs in toolbar when their related text format state becomes active (click on link in text opens link dialogue)
- showToolbarDialogsOnSelection: true,
- // Whether urls, entered by the user should automatically become clickable-links
- autoLink: true,
- // Includes table editing events and cell selection tracking
- handleTables: true,
- // Tab key inserts tab into text as default behaviour. It can be disabled to regain keyboard navigation
- handleTabKey: true,
- // Object which includes parser rules to apply when html gets cleaned
- // See parser_rules/*.js for examples
- parserRules: { tags: { br: {}, span: {}, div: {}, p: {}, b: {}, i: {}, u: {} }, classes: {} },
- // Object which includes parser when the user inserts content via copy & paste. If null parserRules will be used instead
- pasteParserRulesets: null,
- // Parser method to use when the user inserts content
- parser: wysihtml5.dom.parse,
- // By default wysihtml5 will insert a for line breaks, set this to false to use
- useLineBreaks: true,
- // Double enter (enter on blank line) exits block element in useLineBreaks mode.
- // It enables a way of escaping out of block elements and splitting block elements
- doubleLineBreakEscapesBlock: true,
- // Array (or single string) of stylesheet urls to be loaded in the editor's iframe
- stylesheets: [],
- // Placeholder text to use, defaults to the placeholder attribute on the textarea element
- placeholderText: undef,
- // Whether the rich text editor should be rendered on touch devices (wysihtml5 >= 0.3.0 comes with basic support for iOS 5)
- supportTouchDevices: true,
- // Whether senseless elements (empty or without attributes) should be removed/replaced with their content
- cleanUp: true,
- // Whether to use div instead of secure iframe
- contentEditableMode: false,
- classNames: {
- // Class name which should be set on the contentEditable element in the created sandbox iframe, can be styled via the 'stylesheets' option
- composer: "wysihtml5-editor",
- // Class name to add to the body when the wysihtml5 editor is supported
- body: "wysihtml5-supported",
- // classname added to editable area element (iframe/div) on creation
- sandbox: "wysihtml5-sandbox",
- // class on editable area with placeholder
- placeholder: "wysihtml5-placeholder",
- // Classname of container that editor should not touch and pass through
- uneditableContainer: "wysihtml5-uneditable-container"
+ wysihtml.Editor = wysihtml.lang.Dispatcher.extend({
+ /** @scope wysihtml.Editor.prototype */
+ defaults: {
+ // Give the editor a name, the name will also be set as class name on the iframe and on the iframe's body
+ name: undef,
+ // Whether the editor should look like the textarea (by adopting styles)
+ style: true,
+ // Whether urls, entered by the user should automatically become clickable-links
+ autoLink: true,
+ // Tab key inserts tab into text as default behaviour. It can be disabled to regain keyboard navigation
+ handleTabKey: true,
+ // Object which includes parser rules to apply when html gets cleaned
+ // See parser_rules/*.js for examples
+ parserRules: { tags: { br: {}, span: {}, div: {}, p: {}, b: {}, i: {}, u: {} }, classes: {} },
+ // Object which includes parser when the user inserts content via copy & paste. If null parserRules will be used instead
+ pasteParserRulesets: null,
+ // Parser method to use when the user inserts content
+ parser: wysihtml.dom.parse,
+ // By default wysihtml will insert a for line breaks, set this to false to use
+ useLineBreaks: true,
+ // Double enter (enter on blank line) exits block element in useLineBreaks mode.
+ // It enables a way of escaping out of block elements and splitting block elements
+ doubleLineBreakEscapesBlock: true,
+ // Array (or single string) of stylesheet urls to be loaded in the editor's iframe
+ stylesheets: [],
+ // Placeholder text to use, defaults to the placeholder attribute on the textarea element
+ placeholderText: undef,
+ // Whether the rich text editor should be rendered on touch devices (wysihtml >= 0.3.0 comes with basic support for iOS 5)
+ supportTouchDevices: true,
+ // Whether senseless elements (empty or without attributes) should be removed/replaced with their content
+ cleanUp: true,
+ // Whether to use div instead of secure iframe
+ contentEditableMode: false,
+ classNames: {
+ // Class name which should be set on the contentEditable element in the created sandbox iframe, can be styled via the 'stylesheets' option
+ composer: "wysihtml-editor",
+ // Class name to add to the body when the wysihtml editor is supported
+ body: "wysihtml-supported",
+ // classname added to editable area element (iframe/div) on creation
+ sandbox: "wysihtml-sandbox",
+ // class on editable area with placeholder
+ placeholder: "wysihtml-placeholder",
+ // Classname of container that editor should not touch and pass through
+ uneditableContainer: "wysihtml-uneditable-container"
+ },
+ // Browsers that support copied source handling will get a marking of the origin of the copied source (for determinig code cleanup rules on paste)
+ // Also copied source is based directly on selection -
+ // (very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection).
+ // If falsy value is passed source override is also disabled
+ copyedFromMarking: ' '
},
- // Browsers that support copied source handling will get a marking of the origin of the copied source (for determinig code cleanup rules on paste)
- // Also copied source is based directly on selection -
- // (very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection).
- // If falsy value is passed source override is also disabled
- copyedFromMarking: ' '
- };
-
- wysihtml5.Editor = wysihtml5.lang.Dispatcher.extend(
- /** @scope wysihtml5.Editor.prototype */ {
+
constructor: function(editableElement, config) {
this.editableElement = typeof(editableElement) === "string" ? document.getElementById(editableElement) : editableElement;
- this.config = wysihtml5.lang.object({}).merge(defaultConfig).merge(config).get();
- this._isCompatible = wysihtml5.browser.supported();
+ this.config = wysihtml.lang.object({}).merge(this.defaults).merge(config).get();
+ this._isCompatible = wysihtml.browser.supported();
// merge classNames
if (config && config.classNames) {
- wysihtml5.lang.object(this.config.classNames).merge(config.classNames);
+ wysihtml.lang.object(this.config.classNames).merge(config.classNames);
}
if (this.editableElement.nodeName.toLowerCase() != "textarea") {
@@ -18384,21 +15773,21 @@ wysihtml5.views.View = Base.extend(
this.config.noTextarea = true;
}
if (!this.config.noTextarea) {
- this.textarea = new wysihtml5.views.Textarea(this, this.editableElement, this.config);
+ this.textarea = new wysihtml.views.Textarea(this, this.editableElement, this.config);
this.currentView = this.textarea;
}
// Sort out unsupported/unwanted browsers here
- if (!this._isCompatible || (!this.config.supportTouchDevices && wysihtml5.browser.isTouchDevice())) {
+ if (!this._isCompatible || (!this.config.supportTouchDevices && wysihtml.browser.isTouchDevice())) {
var that = this;
setTimeout(function() { that.fire("beforeload").fire("load"); }, 0);
return;
}
// Add class name to body, to indicate that the editor is supported
- wysihtml5.dom.addClass(document.body, this.config.classNames.body);
+ wysihtml.dom.addClass(document.body, this.config.classNames.body);
- this.composer = new wysihtml5.views.Composer(this, this.editableElement, this.config);
+ this.composer = new wysihtml.views.Composer(this, this.editableElement, this.config);
this.currentView = this.composer;
if (typeof(this.config.parser) === "function") {
@@ -18410,13 +15799,17 @@ wysihtml5.views.View = Base.extend(
handleBeforeLoad: function() {
if (!this.config.noTextarea) {
- this.synchronizer = new wysihtml5.views.Synchronizer(this, this.textarea, this.composer);
+ this.synchronizer = new wysihtml.views.Synchronizer(this, this.textarea, this.composer);
} else {
- this.sourceView = new wysihtml5.views.SourceView(this, this.composer);
- }
- if (this.config.toolbar) {
- this.toolbar = new wysihtml5.toolbar.Toolbar(this, this.config.toolbar, this.config.showToolbarAfterInit);
+ this.sourceView = new wysihtml.views.SourceView(this, this.composer);
}
+ this.runEditorExtenders();
+ },
+
+ runEditorExtenders: function() {
+ wysihtml.editorExtenders.forEach(function(extender) {
+ extender(this);
+ }.bind(this));
},
isCompatible: function() {
@@ -18480,9 +15873,7 @@ wysihtml5.views.View = Base.extend(
if (this.composer && this.composer.sandbox) {
this.composer.sandbox.destroy();
}
- if (this.toolbar) {
- this.toolbar.destroy();
- }
+ this.fire("destroy:composer");
this.off();
},
@@ -18496,7 +15887,7 @@ wysihtml5.views.View = Base.extend(
"clearInternals" : clearInternals
});
if (typeof(htmlOrElement) === "object") {
- wysihtml5.quirks.redraw(htmlOrElement);
+ wysihtml.quirks.redraw(htmlOrElement);
}
return returnValue;
},
@@ -18508,10 +15899,10 @@ wysihtml5.views.View = Base.extend(
_initParser: function() {
var oldHtml;
- if (wysihtml5.browser.supportsModernPaste()) {
+ if (wysihtml.browser.supportsModernPaste()) {
this.on("paste:composer", function(event) {
event.preventDefault();
- oldHtml = wysihtml5.dom.getPastedHtml(event);
+ oldHtml = wysihtml.dom.getPastedHtml(event);
if (oldHtml) {
this._cleanAndPaste(oldHtml);
}
@@ -18522,7 +15913,7 @@ wysihtml5.views.View = Base.extend(
event.preventDefault();
var scrollPos = this.composer.getScrollPos();
- wysihtml5.dom.getPastedHtmlWithDiv(this.composer, function(pastedHTML) {
+ wysihtml.dom.getPastedHtmlWithDiv(this.composer, function(pastedHTML) {
if (pastedHTML) {
this._cleanAndPaste(pastedHTML);
}
@@ -18534,7 +15925,7 @@ wysihtml5.views.View = Base.extend(
},
_cleanAndPaste: function (oldHtml) {
- var cleanHtml = wysihtml5.quirks.cleanPastedHTML(oldHtml, {
+ var cleanHtml = wysihtml.quirks.cleanPastedHTML(oldHtml, {
"referenceNode": this.composer.element,
"rules": this.config.pasteParserRulesets || [{"set": this.config.parserRules}],
"uneditableClass": this.config.classNames.uneditableContainer
@@ -18543,4 +15934,4 @@ wysihtml5.views.View = Base.extend(
this.composer.selection.insertHTML(cleanHtml);
}
});
-})(wysihtml5);
+})(wysihtml);
diff --git a/dist/wysihtml.min.js b/dist/wysihtml.min.js
deleted file mode 100644
index 8a4e8e4..0000000
--- a/dist/wysihtml.min.js
+++ /dev/null
@@ -1,11 +0,0 @@
-/*! wysihtml - v0.5.5 (2016-01-06) */
-
-var wysihtml5={version:"0.5.5",commands:{},dom:{},quirks:{},toolbar:{},lang:{},selection:{},views:{},INVISIBLE_SPACE:"\ufeff",INVISIBLE_SPACE_REG_EXP:/\uFEFF/g,VOID_ELEMENTS:"area, base, br, col, embed, hr, img, input, keygen, link, meta, param, source, track, wbr",EMPTY_FUNCTION:function(){},ELEMENT_NODE:1,TEXT_NODE:3,BACKSPACE_KEY:8,ENTER_KEY:13,ESCAPE_KEY:27,SPACE_KEY:32,TAB_KEY:9,DELETE_KEY:46};wysihtml5.polyfills=function(a,b){function c(){try{var a=new CustomEvent("cat",{detail:{foo:"bar"}});return"cat"===a.type&&"bar"===a.detail.foo}catch(b){}return!1}String.prototype.trim||!function(){var a=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;String.prototype.trim=function(){return this.replace(a,"")}}(),function(){var c="addEventListener",d="removeEventListener";b[c]||(a.Element.prototype[c]=a[c]=b[c]=function(b,c,d){return(d=this).attachEvent("on"+b,function(b){var b=b||a.event;b.target=b.target||b.srcElement,b.preventDefault=b.preventDefault||function(){b.returnValue=!1},b.stopPropagation=b.stopPropagation||function(){b.cancelBubble=!0},b.which=b.button?2===b.button?3:4===b.button?2:b.button:b.keyCode,c.call(d,b)})},a.Element.prototype[d]=a[d]=b[d]=function(a,b){return this.detachEvent("on"+a,b)})}(),Object.defineProperty&&Object.getOwnPropertyDescriptor&&Object.getOwnPropertyDescriptor(a.Element.prototype,"textContent")&&!Object.getOwnPropertyDescriptor(a.Element.prototype,"textContent").get&&!function(){var b=Object.getOwnPropertyDescriptor(a.Element.prototype,"innerText");Object.defineProperty(a.Element.prototype,"textContent",{get:function(){return b.get.call(this)},set:function(a){return b.set.call(this,a)}})}(),Array.isArray||(Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a,b){for(var c=this.length,d=-1,e=b>>>0;~(c-e);d=this[--c]===a?c:d);return d}),Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e}),function(a){a.matches=a.matches||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector||a.webkitMatchesSelector||function(a){for(var b=this,c=(b.document||b.ownerDocument).querySelectorAll(a),d=0;c[d]&&c[d]!==b;)++d;return c[d]?!0:!1},a.closest=a.closest||function(a){for(var b=this;b&&!b.matches(a);)b=b.parentElement;return b}}(Element.prototype),"document"in a&&("classList"in b.createElement("_")?"DOMTokenList"in a&&!function(){"use strict";var c=b.createElement("_");if(c.classList.add("c1","c2"),!c.classList.contains("c2")){var d=function(b){var c=a.DOMTokenList.prototype[b];a.DOMTokenList.prototype[b]=function(a){var b,d=arguments.length;for(b=0;d>b;b++)a=arguments[b],c.call(this,a)}};d("add"),d("remove")}if(c.classList.toggle("c3",!1),c.classList.contains("c3")){var e=a.DOMTokenList.prototype.toggle;a.DOMTokenList.prototype.toggle=function(a,b){return 1 in arguments&&!this.contains(a)==!b?b:e.call(this,a)}}c=null}():!function(a){"use strict";if("Element"in a){var b="classList",c="prototype",d=a.Element[c],e=Object,f=String[c].trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=Array[c].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a,this.code=DOMException[a],this.message=b},i=function(a,b){if(""===b)throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return g.call(a,b)},j=function(a){for(var b=f.call(a.getAttribute("class")||""),c=b?b.split(/\s+/):[],d=0,e=c.length;e>d;d++)this.push(c[d]);this._updateClassName=function(){a.setAttribute("class",this.toString())}},k=j[c]=[],l=function(){return new j(this)};if(h[c]=Error[c],k.item=function(a){return this[a]||null},k.contains=function(a){return a+="",-1!==i(this,a)},k.add=function(){var a,b=arguments,c=0,d=b.length,e=!1;do a=b[c]+"",-1===i(this,a)&&(this.push(a),e=!0);while(++c0?c.childNodes[d]:void 0,h=b.focusNode,i=b.focusOffset,j=h&&1===h.nodeType&&i>0?h.childNodes[i-1]:void 0,k=this.ownerDocument.createRange(),l=a.shift(),m=l?a.shift():null;for(j&&3===j.nodeType&&(h=j,i=j.nodeValue.length,j=void 0),g&&3===g.nodeType&&(c=g,d=0,g=void 0),(c===h&&d>i||c!==h&&c.compareDocumentPosition(h)&Node.DOCUMENT_POSITION_PRECEDING&&!(c.compareDocumentPosition(h)&Node.DOCUMENT_POSITION_CONTAINS))&&(h=[c,c=h][0],i=[d,d=i][0]);l&&m;)m.previousSibling&&m.previousSibling===l?(c===m&&(c=l,d=l.nodeValue.length+d),h===m&&(h=l,i=l.nodeValue.length+i),l.nodeValue=l.nodeValue+m.nodeValue,m.parentNode.removeChild(m),m=a.shift()):(l=m,m=a.shift());j&&(i=Array.prototype.indexOf.call(j.parentNode.childNodes,j)+1),g&&(d=Array.prototype.indexOf.call(g.parentNode.childNodes,g)),f(this)&&c&&c.parentNode&&h&&h.parentNode&&(k.setStart(c,d),k.setEnd(h,i),b.removeAllRanges(),b.addRange(k))});Node.prototype.normalize=a},h=function(){window.removeEventListener("load",h),"Node"in window&&"normalize"in Node.prototype&&d()&&g()};"complete"!==b.readyState?window.addEventListener("load",h):h();var i=c();!function(){function c(a,c){c=c||{bubbles:!1,cancelable:!1,detail:void 0};var d=b.createEvent("CustomEvent");return d.initCustomEvent(a,c.bubbles,c.cancelable,c.detail),d}!i&&"CustomEvent"in window&&(c.prototype=a.Event.prototype,a.CustomEvent=c,i=!0)}()},wysihtml5.polyfills(window,document),function(a,b){"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"object"==typeof exports?module.exports=a():b.rangy=a()}(function(){function a(a,b){var c=typeof a[b];return c==u||!(c!=t||!a[b])||"unknown"==c}function b(a,b){return!(typeof a[b]!=t||!a[b])}function c(a,b){return typeof a[b]!=v}function d(a){return function(b,c){for(var d=c.length;d--;)if(!a(b,c[d]))return!1;return!0}}function e(a){return a&&A(a,z)&&C(a,y)}function f(a){return b(a,"body")?a.body:a.getElementsByTagName("body")[0]}function g(b){typeof console!=v&&a(console,"log")&&console.log(b)}function h(a,b){F&&b?alert(a):g(a)}function i(a){H.initialized=!0,H.supported=!1,h("Rangy is not supported in this environment. Reason: "+a,H.config.alertOnFail)}function j(a){h("Rangy warning: "+a,H.config.alertOnWarn)}function k(a){return a.message||a.description||String(a)}function l(){if(F&&!H.initialized){var b,c=!1,d=!1;a(document,"createRange")&&(b=document.createRange(),A(b,x)&&C(b,w)&&(c=!0));var h=f(document);if(!h||"body"!=h.nodeName.toLowerCase())return void i("No body element found");if(h&&a(h,"createTextRange")&&(b=h.createTextRange(),e(b)&&(d=!0)),!c&&!d)return void i("Neither Range nor TextRange are available");H.initialized=!0,H.features={implementsDomRange:c,implementsTextRange:d};var j,l;for(var m in E)(j=E[m])instanceof p&&j.init(j,H);for(var n=0,o=K.length;o>n;++n)try{K[n](H)}catch(q){l="Rangy init listener threw an exception. Continuing. Detail: "+k(q),g(l)}}}function m(a,b,c){c&&(a+=" in module "+c.name),H.warn("DEPRECATED: "+a+" is deprecated. Please use "+b+" instead.")}function n(a,b,c,d){a[b]=function(){return m(b,c,d),a[c].apply(a,G.toArray(arguments))}}function o(a){a=a||window,l();for(var b=0,c=L.length;c>b;++b)L[b](a)}function p(a,b,c){this.name=a,this.dependencies=b,this.initialized=!1,this.supported=!1,this.initializer=c}function q(a,b,c){var d=new p(a,b,function(b){if(!b.initialized){b.initialized=!0;try{c(H,b),b.supported=!0}catch(d){var e="Module '"+a+"' failed to load: "+k(d);g(e),d.stack&&g(d.stack)}}});return E[a]=d,d}function r(){}function s(){}var t="object",u="function",v="undefined",w=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],x=["setStart","setStartBefore","setStartAfter","setEnd","setEndBefore","setEndAfter","collapse","selectNode","selectNodeContents","compareBoundaryPoints","deleteContents","extractContents","cloneContents","insertNode","surroundContents","cloneRange","toString","detach"],y=["boundingHeight","boundingLeft","boundingTop","boundingWidth","htmlText","text"],z=["collapse","compareEndPoints","duplicate","moveToElementText","parentElement","select","setEndPoint","getBoundingClientRect"],A=d(a),B=d(b),C=d(c),D=[].forEach?function(a,b){a.forEach(b)}:function(a,b){for(var c=0,d=a.length;d>c;++c)b(a[c],c)},E={},F=typeof window!=v&&typeof document!=v,G={isHostMethod:a,isHostObject:b,isHostProperty:c,areHostMethods:A,areHostObjects:B,areHostProperties:C,isTextRange:e,getBody:f,forEach:D},H={version:"1.3.0",initialized:!1,isBrowser:F,supported:!0,util:G,features:{},modules:E,config:{alertOnFail:!1,alertOnWarn:!1,preferTextRange:!1,autoInitialize:typeof rangyAutoInitialize==v?!0:rangyAutoInitialize}};H.fail=i,H.warn=j;var I;({}).hasOwnProperty?(G.extend=I=function(a,b,c){var d,e;for(var f in b)b.hasOwnProperty(f)&&(d=a[f],e=b[f],c&&null!==d&&"object"==typeof d&&null!==e&&"object"==typeof e&&I(d,e,!0),a[f]=e);return b.hasOwnProperty("toString")&&(a.toString=b.toString),a},G.createOptions=function(a,b){var c={};return I(c,b),a&&I(c,a),c}):i("hasOwnProperty not supported"),F||i("Rangy can only run in a browser"),function(){var a;if(F){var b=document.createElement("div");b.appendChild(document.createElement("span"));var c=[].slice;try{1==c.call(b.childNodes,0)[0].nodeType&&(a=function(a){return c.call(a,0)})}catch(d){}}a||(a=function(a){for(var b=[],c=0,d=a.length;d>c;++c)b[c]=a[c];return b}),G.toArray=a}();var J;F&&(a(document,"addEventListener")?J=function(a,b,c){a.addEventListener(b,c,!1)}:a(document,"attachEvent")?J=function(a,b,c){a.attachEvent("on"+b,c)}:i("Document does not have required addEventListener or attachEvent method"),G.addListener=J);var K=[];G.deprecationNotice=m,G.createAliasForDeprecatedMethod=n,H.init=l,H.addInitListener=function(a){H.initialized?a(H):K.push(a)};var L=[];H.addShimListener=function(a){L.push(a)},F&&(H.shim=H.createMissingNativeApi=o,n(H,"createMissingNativeApi","shim")),p.prototype={init:function(){for(var a,b,c=this.dependencies||[],d=0,e=c.length;e>d;++d){if(b=c[d],a=E[b],!(a&&a instanceof p))throw new Error("required module '"+b+"' not found");if(a.init(),!a.supported)throw new Error("required module '"+b+"' not supported")}this.initializer(this)},fail:function(a){throw this.initialized=!0,this.supported=!1,new Error(a)},warn:function(a){H.warn("Module "+this.name+": "+a)},deprecationNotice:function(a,b){H.warn("DEPRECATED: "+a+" in module "+this.name+" is deprecated. Please use "+b+" instead")},createError:function(a){return new Error("Error in Rangy "+this.name+" module: "+a)}},H.createModule=function(a){var b,c;2==arguments.length?(b=arguments[1],c=[]):(b=arguments[2],c=arguments[1]);var d=q(a,c,b);H.initialized&&H.supported&&d.init()},H.createCoreModule=function(a,b,c){q(a,b,c)},H.RangePrototype=r,H.rangePrototype=new r,H.selectionPrototype=new s,H.createCoreModule("DomUtil",[],function(a,b){function c(a){var b;return typeof a.namespaceURI==F||null===(b=a.namespaceURI)||"http://www.w3.org/1999/xhtml"==b}function d(a){var b=a.parentNode;return 1==b.nodeType?b:null}function e(a){for(var b=0;a=a.previousSibling;)++b;return b}function f(a){switch(a.nodeType){case 7:case 10:return 0;case 3:case 8:return a.length;default:return a.childNodes.length}}function g(a,b){var c,d=[];for(c=a;c;c=c.parentNode)d.push(c);for(c=b;c;c=c.parentNode)if(K(d,c))return c;return null}function h(a,b,c){for(var d=c?b:b.parentNode;d;){if(d===a)return!0;d=d.parentNode}return!1}function i(a,b){return h(a,b,!0)}function j(a,b,c){for(var d,e=c?a:a.parentNode;e;){if(d=e.parentNode,d===b)return e;e=d}return null}function k(a){var b=a.nodeType;return 3==b||4==b||8==b}function l(a){if(!a)return!1;var b=a.nodeType;return 3==b||8==b}function m(a,b){var c=b.nextSibling,d=b.parentNode;return c?d.insertBefore(a,c):d.appendChild(a),a}function n(a,b,c){var d=a.cloneNode(!1);if(d.deleteData(0,b),a.deleteData(b,a.length-b),m(d,a),c)for(var f,g=0;f=c[g++];)f.node==a&&f.offset>b?(f.node=d,f.offset-=b):f.node==a.parentNode&&f.offset>e(a)&&++f.offset;return d}function o(a){if(9==a.nodeType)return a;if(typeof a.ownerDocument!=F)return a.ownerDocument;if(typeof a.document!=F)return a.document;if(a.parentNode)return o(a.parentNode);throw b.createError("getDocument: no document found for node")}function p(a){var c=o(a);if(typeof c.defaultView!=F)return c.defaultView;if(typeof c.parentWindow!=F)return c.parentWindow;throw b.createError("Cannot get a window object for node")}function q(a){if(typeof a.contentDocument!=F)return a.contentDocument;if(typeof a.contentWindow!=F)return a.contentWindow.document;throw b.createError("getIframeDocument: No Document object found for iframe element")}function r(a){if(typeof a.contentWindow!=F)return a.contentWindow;if(typeof a.contentDocument!=F)return a.contentDocument.defaultView;throw b.createError("getIframeWindow: No Window object found for iframe element")}function s(a){return a&&G.isHostMethod(a,"setTimeout")&&G.isHostObject(a,"document")}function t(a,b,c){var d;if(a?G.isHostProperty(a,"nodeType")?d=1==a.nodeType&&"iframe"==a.tagName.toLowerCase()?q(a):o(a):s(a)&&(d=a.document):d=document,!d)throw b.createError(c+"(): Parameter must be a Window object or DOM node");return d}function u(a){for(var b;b=a.parentNode;)a=b;return a}function v(a,c,d,f){var h,i,k,l,m;if(a==d)return c===f?0:f>c?-1:1;if(h=j(d,a,!0))return c<=e(h)?-1:1;if(h=j(a,d,!0))return e(h)[index:"+e(a)+",length:"+a.childNodes.length+"]["+(a.innerHTML||"[innerHTML not supported]").slice(0,25)+"]"}return a.nodeName}function y(a){for(var b,c=o(a).createDocumentFragment();b=a.firstChild;)c.appendChild(b);return c}function z(a,b,c){var d=H(a),e=a.createElement("div");e.contentEditable=""+!!c,b&&(e.innerHTML=b);var f=d.firstChild;return f?d.insertBefore(e,f):d.appendChild(e),e}function A(a){return a.parentNode.removeChild(a)}function B(a){this.root=a,this._next=a}function C(a){return new B(a)}function D(a,b){this.node=a,this.offset=b}function E(a){this.code=this[a],this.codeName=a,this.message="DOMException: "+this.codeName}var F="undefined",G=a.util,H=G.getBody;G.areHostMethods(document,["createDocumentFragment","createElement","createTextNode"])||b.fail("document missing a Node creation method"),G.isHostMethod(document,"getElementsByTagName")||b.fail("document missing getElementsByTagName method");var I=document.createElement("div");G.areHostMethods(I,["insertBefore","appendChild","cloneNode"]||!G.areHostObjects(I,["previousSibling","nextSibling","childNodes","parentNode"]))||b.fail("Incomplete Element implementation"),G.isHostProperty(I,"innerHTML")||b.fail("Element is missing innerHTML property");var J=document.createTextNode("test");G.areHostMethods(J,["splitText","deleteData","insertData","appendData","cloneNode"]||!G.areHostObjects(I,["previousSibling","nextSibling","childNodes","parentNode"])||!G.areHostProperties(J,["data"]))||b.fail("Incomplete Text Node implementation");var K=function(a,b){for(var c=a.length;c--;)if(a[c]===b)return!0;return!1},L=!1;!function(){var b=document.createElement("b");b.innerHTML="1";var c=b.firstChild;b.innerHTML=" ",L=w(c),a.features.crashyTextNodes=L}();var M;typeof window.getComputedStyle!=F?M=function(a,b){return p(a).getComputedStyle(a,null)[b]}:typeof document.documentElement.currentStyle!=F?M=function(a,b){return a.currentStyle?a.currentStyle[b]:""}:b.fail("No means of obtaining computed style properties found"),B.prototype={_current:null,hasNext:function(){return!!this._next},next:function(){var a,b,c=this._current=this._next;if(this._current)if(a=c.firstChild)this._next=a;else{for(b=null;c!==this.root&&!(b=c.nextSibling);)c=c.parentNode;this._next=b}return this._current},detach:function(){this._current=this._next=this.root=null}},D.prototype={equals:function(a){return!!a&&this.node===a.node&&this.offset==a.offset},inspect:function(){return"[DomPosition("+x(this.node)+":"+this.offset+")]"},toString:function(){return this.inspect()}},E.prototype={INDEX_SIZE_ERR:1,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INVALID_STATE_ERR:11,INVALID_NODE_TYPE_ERR:24},E.prototype.toString=function(){return this.message},a.dom={arrayContains:K,isHtmlNamespace:c,parentElement:d,getNodeIndex:e,getNodeLength:f,getCommonAncestor:g,isAncestorOf:h,isOrIsAncestorOf:i,getClosestAncestorIn:j,isCharacterDataNode:k,isTextOrCommentNode:l,insertAfter:m,splitDataNode:n,getDocument:o,getWindow:p,getIframeWindow:r,getIframeDocument:q,getBody:H,isWindow:s,getContentDocument:t,getRootContainer:u,comparePoints:v,isBrokenNode:w,inspectNode:x,getComputedStyleProperty:M,createTestElement:z,removeNode:A,fragmentFromNodeChildren:y,createIterator:C,DomPosition:D},a.DOMException=E}),H.createCoreModule("DomRange",["DomUtil"],function(a,b){function c(a,b){return 3!=a.nodeType&&(P(a,b.startContainer)||P(a,b.endContainer))}function d(a){return a.document||Q(a.startContainer)}function e(a){return W(a.startContainer)}function f(a){return new L(a.parentNode,O(a))}function g(a){return new L(a.parentNode,O(a)+1)}function h(a,b,c){var d=11==a.nodeType?a.firstChild:a;return N(b)?c==b.length?J.insertAfter(a,b):b.parentNode.insertBefore(a,0==c?b:S(b,c)):c>=b.childNodes.length?b.appendChild(a):b.insertBefore(a,b.childNodes[c]),d}function i(a,b,c){if(z(a),z(b),d(b)!=d(a))throw new M("WRONG_DOCUMENT_ERR");var e=R(a.startContainer,a.startOffset,b.endContainer,b.endOffset),f=R(a.endContainer,a.endOffset,b.startContainer,b.startOffset);return c?0>=e&&f>=0:0>e&&f>0}function j(a){for(var b,c,e,f=d(a.range).createDocumentFragment();c=a.next();){if(b=a.isPartiallySelectedSubtree(),c=c.cloneNode(!b),b&&(e=a.getSubtreeIterator(),c.appendChild(j(e)),e.detach()),10==c.nodeType)throw new M("HIERARCHY_REQUEST_ERR");f.appendChild(c)}return f}function k(a,b,c){var d,e;c=c||{stop:!1};for(var f,g;f=a.next();)if(a.isPartiallySelectedSubtree()){if(b(f)===!1)return void(c.stop=!0);if(g=a.getSubtreeIterator(),k(g,b,c),g.detach(),c.stop)return}else for(d=J.createIterator(f);e=d.next();)if(b(e)===!1)return void(c.stop=!0)}function l(a){for(var b;a.next();)a.isPartiallySelectedSubtree()?(b=a.getSubtreeIterator(),l(b),b.detach()):a.remove()}function m(a){for(var b,c,e=d(a.range).createDocumentFragment();b=a.next();){if(a.isPartiallySelectedSubtree()?(b=b.cloneNode(!1),c=a.getSubtreeIterator(),b.appendChild(m(c)),c.detach()):a.remove(),10==b.nodeType)throw new M("HIERARCHY_REQUEST_ERR");e.appendChild(b)}return e}function n(a,b,c){var d,e=!(!b||!b.length),f=!!c;e&&(d=new RegExp("^("+b.join("|")+")$"));var g=[];return k(new p(a,!1),function(b){if((!e||d.test(b.nodeType))&&(!f||c(b))){var h=a.startContainer;if(b!=h||!N(h)||a.startOffset!=h.length){var i=a.endContainer;b==i&&N(i)&&0==a.endOffset||g.push(b)}}}),g}function o(a){var b="undefined"==typeof a.getName?"Range":a.getName();return"["+b+"("+J.inspectNode(a.startContainer)+":"+a.startOffset+", "+J.inspectNode(a.endContainer)+":"+a.endOffset+")]"}function p(a,b){if(this.range=a,this.clonePartiallySelectedTextNodes=b,!a.collapsed){this.sc=a.startContainer,this.so=a.startOffset,this.ec=a.endContainer,this.eo=a.endOffset;var c=a.commonAncestorContainer;this.sc===this.ec&&N(this.sc)?(this.isSingleCharacterDataNode=!0,this._first=this._last=this._next=this.sc):(this._first=this._next=this.sc!==c||N(this.sc)?T(this.sc,c,!0):this.sc.childNodes[this.so],this._last=this.ec!==c||N(this.ec)?T(this.ec,c,!0):this.ec.childNodes[this.eo-1])}}function q(a){return function(b,c){for(var d,e=c?b:b.parentNode;e;){if(d=e.nodeType,V(a,d))return e;e=e.parentNode}return null}}function r(a,b){if(ea(a,b))throw new M("INVALID_NODE_TYPE_ERR")}function s(a,b){if(!V(b,a.nodeType))throw new M("INVALID_NODE_TYPE_ERR")}function t(a,b){if(0>b||b>(N(a)?a.length:a.childNodes.length))throw new M("INDEX_SIZE_ERR")}function u(a,b){if(ca(a,!0)!==ca(b,!0))throw new M("WRONG_DOCUMENT_ERR")}function v(a){if(da(a,!0))throw new M("NO_MODIFICATION_ALLOWED_ERR")}function w(a,b){if(!a)throw new M(b)}function x(a,b){return b<=(N(a)?a.length:a.childNodes.length)}function y(a){return!!a.startContainer&&!!a.endContainer&&!(X&&(J.isBrokenNode(a.startContainer)||J.isBrokenNode(a.endContainer)))&&W(a.startContainer)==W(a.endContainer)&&x(a.startContainer,a.startOffset)&&x(a.endContainer,a.endOffset)}function z(a){if(!y(a))throw new Error("Range error: Range is not valid. This usually happens after DOM mutation. Range: ("+a.inspect()+")")}function A(a,b){z(a);var c=a.startContainer,d=a.startOffset,e=a.endContainer,f=a.endOffset,g=c===e;N(e)&&f>0&&f0&&d=O(c)&&f++,d=0),a.setStartAndEnd(c,d,e,f)}function B(a){z(a);var b=a.commonAncestorContainer.parentNode.cloneNode(!1);return b.appendChild(a.cloneContents()),b.innerHTML}function C(a){a.START_TO_START=ka,a.START_TO_END=la,a.END_TO_END=ma,a.END_TO_START=na,a.NODE_BEFORE=oa,a.NODE_AFTER=pa,a.NODE_BEFORE_AND_AFTER=qa,a.NODE_INSIDE=ra}function D(a){C(a),C(a.prototype)}function E(a,b){return function(){z(this);var c,d,e=this.startContainer,f=this.startOffset,h=this.commonAncestorContainer,i=new p(this,!0);e!==h&&(c=T(e,h,!0),d=g(c),e=d.node,f=d.offset),k(i,v),i.reset();var j=a(i);return i.detach(),b(this,e,f,e,f),j}}function F(b,d){function e(a,b){return function(c){s(c,Z),s(W(c),$);var d=(a?f:g)(c);(b?h:i)(this,d.node,d.offset)}}function h(a,b,c){var e=a.endContainer,f=a.endOffset;(b!==a.startContainer||c!==a.startOffset)&&((W(b)!=W(e)||1==R(b,c,e,f))&&(e=b,f=c),d(a,b,c,e,f))}function i(a,b,c){var e=a.startContainer,f=a.startOffset;(b!==a.endContainer||c!==a.endOffset)&&((W(b)!=W(e)||-1==R(b,c,e,f))&&(e=b,f=c),d(a,e,f,b,c))}var j=function(){};j.prototype=a.rangePrototype,b.prototype=new j,K.extend(b.prototype,{setStart:function(a,b){r(a,!0),t(a,b),h(this,a,b)},setEnd:function(a,b){r(a,!0),t(a,b),i(this,a,b)},setStartAndEnd:function(){var a=arguments,b=a[0],c=a[1],e=b,f=c;switch(a.length){case 3:f=a[2];break;case 4:e=a[2],f=a[3]}d(this,b,c,e,f)},setBoundary:function(a,b,c){this["set"+(c?"Start":"End")](a,b)},setStartBefore:e(!0,!0),setStartAfter:e(!1,!0),setEndBefore:e(!0,!1),setEndAfter:e(!1,!1),collapse:function(a){z(this),a?d(this,this.startContainer,this.startOffset,this.startContainer,this.startOffset):d(this,this.endContainer,this.endOffset,this.endContainer,this.endOffset)},selectNodeContents:function(a){r(a,!0),d(this,a,0,a,U(a))},selectNode:function(a){r(a,!1),s(a,Z);var b=f(a),c=g(a);d(this,b.node,b.offset,c.node,c.offset)},extractContents:E(m,d),deleteContents:E(l,d),canSurroundContents:function(){z(this),v(this.startContainer),v(this.endContainer);var a=new p(this,!0),b=a._first&&c(a._first,this)||a._last&&c(a._last,this);return a.detach(),!b},splitBoundaries:function(){A(this)},splitBoundariesPreservingPositions:function(a){A(this,a)},normalizeBoundaries:function(){z(this);var a,b=this.startContainer,c=this.startOffset,e=this.endContainer,f=this.endOffset,g=function(a){var b=a.nextSibling;b&&b.nodeType==a.nodeType&&(e=a,f=a.length,a.appendData(b.data),Y(b))},h=function(a){var d=a.previousSibling;if(d&&d.nodeType==a.nodeType){b=a;var g=a.length;if(c=d.length,a.insertData(0,d.data),Y(d),b==e)f+=c,e=b;else if(e==a.parentNode){var h=O(a);f==h?(e=a,f=g):f>h&&f--}}},i=!0;if(N(e))f==e.length?g(e):0==f&&(a=e.previousSibling,a&&a.nodeType==e.nodeType&&(f=a.length,b==e&&(i=!1),a.appendData(e.data),Y(e),e=a));else{if(f>0){var j=e.childNodes[f-1];j&&N(j)&&g(j)}i=!this.collapsed}if(i){if(N(b))0==c?h(b):c==b.length&&(a=b.nextSibling,a&&a.nodeType==b.nodeType&&(e==a&&(e=b,f+=b.length),b.appendData(a.data),Y(a)));else if(cx",ga=3==fa.firstChild.nodeType}catch(ha){}a.features.htmlParsingConforms=ga;var ia=ga?function(a){var b=this.startContainer,c=Q(b);if(!b)throw new M("INVALID_STATE_ERR");var d=null;return 1==b.nodeType?d=b:N(b)&&(d=J.parentElement(b)),d=null===d||"HTML"==d.nodeName&&J.isHtmlNamespace(Q(d).documentElement)&&J.isHtmlNamespace(d)?c.createElement("body"):d.cloneNode(!1),d.innerHTML=a,J.fragmentFromNodeChildren(d)}:function(a){var b=d(this),c=b.createElement("body");return c.innerHTML=a,J.fragmentFromNodeChildren(c)},ja=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],ka=0,la=1,ma=2,na=3,oa=0,pa=1,qa=2,ra=3;K.extend(a.rangePrototype,{compareBoundaryPoints:function(a,b){z(this),u(this.startContainer,b.startContainer);var c,d,e,f,g=a==na||a==ka?"start":"end",h=a==la||a==ka?"start":"end";return c=this[g+"Container"],d=this[g+"Offset"],e=b[h+"Container"],f=b[h+"Offset"],R(c,d,e,f)},insertNode:function(a){if(z(this),s(a,aa),v(this.startContainer),P(a,this.startContainer))throw new M("HIERARCHY_REQUEST_ERR");var b=h(a,this.startContainer,this.startOffset);this.setStartBefore(b)},cloneContents:function(){z(this);var a,b;if(this.collapsed)return d(this).createDocumentFragment();if(this.startContainer===this.endContainer&&N(this.startContainer))return a=this.startContainer.cloneNode(!0),a.data=a.data.slice(this.startOffset,this.endOffset),b=d(this).createDocumentFragment(),b.appendChild(a),b;var c=new p(this,!0);return a=j(c),c.detach(),a},canSurroundContents:function(){z(this),v(this.startContainer),v(this.endContainer);var a=new p(this,!0),b=a._first&&c(a._first,this)||a._last&&c(a._last,this);return a.detach(),!b},surroundContents:function(a){if(s(a,ba),!this.canSurroundContents())throw new M("INVALID_STATE_ERR");var b=this.extractContents();if(a.hasChildNodes())for(;a.lastChild;)a.removeChild(a.lastChild);h(a,this.startContainer,this.startOffset),a.appendChild(b),this.selectNode(a)},cloneRange:function(){z(this);for(var a,b=new I(d(this)),c=ja.length;c--;)a=ja[c],b[a]=this[a];return b},toString:function(){z(this);var a=this.startContainer;if(a===this.endContainer&&N(a))return 3==a.nodeType||4==a.nodeType?a.data.slice(this.startOffset,this.endOffset):"";var b=[],c=new p(this,!0);return k(c,function(a){(3==a.nodeType||4==a.nodeType)&&b.push(a.data)}),c.detach(),b.join("")},compareNode:function(a){z(this);var b=a.parentNode,c=O(a);if(!b)throw new M("NOT_FOUND_ERR");var d=this.comparePoint(b,c),e=this.comparePoint(b,c+1);return 0>d?e>0?qa:oa:e>0?pa:ra},comparePoint:function(a,b){return z(this),w(a,"HIERARCHY_REQUEST_ERR"),u(a,this.startContainer),R(a,b,this.startContainer,this.startOffset)<0?-1:R(a,b,this.endContainer,this.endOffset)>0?1:0},createContextualFragment:ia,toHtml:function(){return B(this)},intersectsNode:function(a,b){if(z(this),W(a)!=e(this))return!1;var c=a.parentNode,d=O(a);if(!c)return!0;var f=R(c,d,this.endContainer,this.endOffset),g=R(c,d+1,this.startContainer,this.startOffset);return b?0>=f&&g>=0:0>f&&g>0},isPointInRange:function(a,b){return z(this),w(a,"HIERARCHY_REQUEST_ERR"),u(a,this.startContainer),R(a,b,this.startContainer,this.startOffset)>=0&&R(a,b,this.endContainer,this.endOffset)<=0},intersectsRange:function(a){return i(this,a,!1)},intersectsOrTouchesRange:function(a){return i(this,a,!0)},intersection:function(a){if(this.intersectsRange(a)){var b=R(this.startContainer,this.startOffset,a.startContainer,a.startOffset),c=R(this.endContainer,this.endOffset,a.endContainer,a.endOffset),d=this.cloneRange();return-1==b&&d.setStart(a.startContainer,a.startOffset),1==c&&d.setEnd(a.endContainer,a.endOffset),d}return null},union:function(a){if(this.intersectsOrTouchesRange(a)){var b=this.cloneRange();return-1==R(a.startContainer,a.startOffset,this.startContainer,this.startOffset)&&b.setStart(a.startContainer,a.startOffset),1==R(a.endContainer,a.endOffset,this.endContainer,this.endOffset)&&b.setEnd(a.endContainer,a.endOffset),
-b}throw new M("Ranges do not intersect")},containsNode:function(a,b){return b?this.intersectsNode(a,!1):this.compareNode(a)==ra},containsNodeContents:function(a){return this.comparePoint(a,0)>=0&&this.comparePoint(a,U(a))<=0},containsRange:function(a){var b=this.intersection(a);return null!==b&&a.equals(b)},containsNodeText:function(a){var b=this.cloneRange();b.selectNode(a);var c=b.getNodes([3]);if(c.length>0){b.setStart(c[0],0);var d=c.pop();return b.setEnd(d,d.length),this.containsRange(b)}return this.containsNodeContents(a)},getNodes:function(a,b){return z(this),n(this,a,b)},getDocument:function(){return d(this)},collapseBefore:function(a){this.setEndBefore(a),this.collapse(!1)},collapseAfter:function(a){this.setStartAfter(a),this.collapse(!0)},getBookmark:function(b){var c=d(this),e=a.createRange(c);b=b||J.getBody(c),e.selectNodeContents(b);var f=this.intersection(e),g=0,h=0;return f&&(e.setEnd(f.startContainer,f.startOffset),g=e.toString().length,h=g+f.toString().length),{start:g,end:h,containerNode:b}},moveToBookmark:function(a){var b=a.containerNode,c=0;this.setStart(b,0),this.collapse(!0);for(var d,e,f,g,h=[b],i=!1,j=!1;!j&&(d=h.pop());)if(3==d.nodeType)e=c+d.length,!i&&a.start>=c&&a.start<=e&&(this.setStart(d,a.start-c),i=!0),i&&a.end>=c&&a.end<=e&&(this.setEnd(d,a.end-c),j=!0),c=e;else for(g=d.childNodes,f=g.length;f--;)h.push(g[f])},getName:function(){return"DomRange"},equals:function(a){return I.rangesEqual(this,a)},isValid:function(){return y(this)},inspect:function(){return o(this)},detach:function(){}}),F(I,H),K.extend(I,{rangeProperties:ja,RangeIterator:p,copyComparisonConstants:D,createPrototypeRange:F,inspect:o,toHtml:B,getRangeDocument:d,rangesEqual:function(a,b){return a.startContainer===b.startContainer&&a.startOffset===b.startOffset&&a.endContainer===b.endContainer&&a.endOffset===b.endOffset}}),a.DomRange=I}),H.createCoreModule("WrappedRange",["DomRange"],function(a,b){var c,d,e=a.dom,f=a.util,g=e.DomPosition,h=a.DomRange,i=e.getBody,j=e.getContentDocument,k=e.isCharacterDataNode;if(a.features.implementsDomRange&&!function(){function d(a){for(var b,c=m.length;c--;)b=m[c],a[b]=a.nativeRange[b];a.collapsed=a.startContainer===a.endContainer&&a.startOffset===a.endOffset}function g(a,b,c,d,e){var f=a.startContainer!==b||a.startOffset!=c,g=a.endContainer!==d||a.endOffset!=e,h=!a.equals(a.nativeRange);(f||g||h)&&(a.setEnd(d,e),a.setStart(b,c))}var k,l,m=h.rangeProperties;c=function(a){if(!a)throw b.createError("WrappedRange: Range must be specified");this.nativeRange=a,d(this)},h.createPrototypeRange(c,g),k=c.prototype,k.selectNode=function(a){this.nativeRange.selectNode(a),d(this)},k.cloneContents=function(){return this.nativeRange.cloneContents()},k.surroundContents=function(a){this.nativeRange.surroundContents(a),d(this)},k.collapse=function(a){this.nativeRange.collapse(a),d(this)},k.cloneRange=function(){return new c(this.nativeRange.cloneRange())},k.refresh=function(){d(this)},k.toString=function(){return this.nativeRange.toString()};var n=document.createTextNode("test");i(document).appendChild(n);var o=document.createRange();o.setStart(n,0),o.setEnd(n,0);try{o.setStart(n,1),k.setStart=function(a,b){this.nativeRange.setStart(a,b),d(this)},k.setEnd=function(a,b){this.nativeRange.setEnd(a,b),d(this)},l=function(a){return function(b){this.nativeRange[a](b),d(this)}}}catch(p){k.setStart=function(a,b){try{this.nativeRange.setStart(a,b)}catch(c){this.nativeRange.setEnd(a,b),this.nativeRange.setStart(a,b)}d(this)},k.setEnd=function(a,b){try{this.nativeRange.setEnd(a,b)}catch(c){this.nativeRange.setStart(a,b),this.nativeRange.setEnd(a,b)}d(this)},l=function(a,b){return function(c){try{this.nativeRange[a](c)}catch(e){this.nativeRange[b](c),this.nativeRange[a](c)}d(this)}}}k.setStartBefore=l("setStartBefore","setEndBefore"),k.setStartAfter=l("setStartAfter","setEndAfter"),k.setEndBefore=l("setEndBefore","setStartBefore"),k.setEndAfter=l("setEndAfter","setStartAfter"),k.selectNodeContents=function(a){this.setStartAndEnd(a,0,e.getNodeLength(a))},o.selectNodeContents(n),o.setEnd(n,3);var q=document.createRange();q.selectNodeContents(n),q.setEnd(n,4),q.setStart(n,2),-1==o.compareBoundaryPoints(o.START_TO_END,q)&&1==o.compareBoundaryPoints(o.END_TO_START,q)?k.compareBoundaryPoints=function(a,b){return b=b.nativeRange||b,a==b.START_TO_END?a=b.END_TO_START:a==b.END_TO_START&&(a=b.START_TO_END),this.nativeRange.compareBoundaryPoints(a,b)}:k.compareBoundaryPoints=function(a,b){return this.nativeRange.compareBoundaryPoints(a,b.nativeRange||b)};var r=document.createElement("div");r.innerHTML="123";var s=r.firstChild,t=i(document);t.appendChild(r),o.setStart(s,1),o.setEnd(s,2),o.deleteContents(),"13"==s.data&&(k.deleteContents=function(){this.nativeRange.deleteContents(),d(this)},k.extractContents=function(){var a=this.nativeRange.extractContents();return d(this),a}),t.removeChild(r),t=null,f.isHostMethod(o,"createContextualFragment")&&(k.createContextualFragment=function(a){return this.nativeRange.createContextualFragment(a)}),i(document).removeChild(n),k.getName=function(){return"WrappedRange"},a.WrappedRange=c,a.createNativeRange=function(a){return a=j(a,b,"createNativeRange"),a.createRange()}}(),a.features.implementsTextRange){var l=function(a){var b=a.parentElement(),c=a.duplicate();c.collapse(!0);var d=c.parentElement();c=a.duplicate(),c.collapse(!1);var f=c.parentElement(),g=d==f?d:e.getCommonAncestor(d,f);return g==b?g:e.getCommonAncestor(b,g)},m=function(a){return 0==a.compareEndPoints("StartToEnd",a)},n=function(a,b,c,d,f){var h=a.duplicate();h.collapse(c);var i=h.parentElement();if(e.isOrIsAncestorOf(b,i)||(i=b),!i.canHaveHTML){var j=new g(i.parentNode,e.getNodeIndex(i));return{boundaryPosition:j,nodeInfo:{nodeIndex:j.offset,containerElement:j.node}}}var l=e.getDocument(i).createElement("span");l.parentNode&&e.removeNode(l);for(var m,n,o,p,q,r=c?"StartToStart":"StartToEnd",s=f&&f.containerElement==i?f.nodeIndex:0,t=i.childNodes.length,u=t,v=u;;){if(v==t?i.appendChild(l):i.insertBefore(l,i.childNodes[v]),h.moveToElementText(l),m=h.compareEndPoints(r,a),0==m||s==u)break;if(-1==m){if(u==s+1)break;s=v}else u=u==s+1?s:v;v=Math.floor((s+u)/2),i.removeChild(l)}if(q=l.nextSibling,-1==m&&q&&k(q)){h.setEndPoint(c?"EndToStart":"EndToEnd",a);var w;if(/[\r\n]/.test(q.data)){var x=h.duplicate(),y=x.text.replace(/\r\n/g,"\r").length;for(w=x.moveStart("character",y);-1==(m=x.compareEndPoints("StartToEnd",x));)w++,x.moveStart("character",1)}else w=h.text.length;p=new g(q,w)}else n=(d||!c)&&l.previousSibling,o=(d||c)&&l.nextSibling,p=o&&k(o)?new g(o,0):n&&k(n)?new g(n,n.data.length):new g(i,e.getNodeIndex(l));return e.removeNode(l),{boundaryPosition:p,nodeInfo:{nodeIndex:v,containerElement:i}}},o=function(a,b){var c,d,f,g,h=a.offset,j=e.getDocument(a.node),l=i(j).createTextRange(),m=k(a.node);return m?(c=a.node,d=c.parentNode):(g=a.node.childNodes,c=hb;++b)if(!C.isAncestorOf(a[0],a[b]))return!1;return!0}function m(a){var c=a.getNodes();if(!l(c))throw b.createError("getSingleElementFromRange: range "+a.inspect()+" did not consist of a single element");return c[0]}function n(a){return!!a&&"undefined"!=typeof a.text}function o(a,b){var c=new G(b);a._ranges=[c],h(a,c,!1),a.rangeCount=1,a.isCollapsed=c.collapsed}function p(b){if(b._ranges.length=0,"None"==b.docSelection.type)j(b);else{var c=b.docSelection.createRange();if(n(c))o(b,c);else{b.rangeCount=c.length;for(var d,e=L(c.item(0)),f=0;fh;++h)g.add(d.item(h));try{g.add(e)}catch(j){throw b.createError("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)")}g.select(),p(a)}function r(a,b,c){this.nativeSelection=a,this.docSelection=b,this._ranges=[],this.win=c,this.refresh()}function s(a){a.win=a.anchorNode=a.focusNode=a._ranges=null,a.rangeCount=a.anchorOffset=a.focusOffset=0,a.detached=!0}function t(a,b){for(var c,d,e=ba.length;e--;)if(c=ba[e],d=c.selection,"deleteAll"==b)s(d);else if(c.win==a)return"delete"==b?(ba.splice(e,1),!0):d;return"deleteAll"==b&&(ba.length=0),null}function u(a,c){for(var d,e=L(c[0].startContainer),f=M(e).createControlRange(),g=0,h=c.length;h>g;++g){d=m(c[g]);try{f.add(d)}catch(i){throw b.createError("setRanges(): Element within one of the specified Ranges could not be added to control selection (does it have layout?)")}}f.select(),p(a)}function v(a,b){if(a.win.document!=L(b))throw new H("WRONG_DOCUMENT_ERR")}function w(b){return function(c,d){var e;this.rangeCount?(e=this.getRangeAt(0),e["set"+(b?"Start":"End")](c,d)):(e=a.createRange(this.win.document),e.setStartAndEnd(c,d)),this.setSingleRange(e,this.isBackward())}}function x(a){var b=[],c=new I(a.anchorNode,a.anchorOffset),d=new I(a.focusNode,a.focusOffset),e="function"==typeof a.getName?a.getName():"Selection";if("undefined"!=typeof a.rangeCount)for(var f=0,g=a.rangeCount;g>f;++f)b[f]=F.inspect(a.getRangeAt(f));return"["+e+"(Ranges: "+b.join(", ")+")(anchor: "+c.inspect()+", focus: "+d.inspect()+"]"}a.config.checkSelectionRanges=!0;var y,z,A="boolean",B="number",C=a.dom,D=a.util,E=D.isHostMethod,F=a.DomRange,G=a.WrappedRange,H=a.DOMException,I=C.DomPosition,J=a.features,K="Control",L=C.getDocument,M=C.getBody,N=F.rangesEqual,O=E(window,"getSelection"),P=D.isHostObject(document,"selection");J.implementsWinGetSelection=O,J.implementsDocSelection=P;var Q=P&&(!O||a.config.preferTextRange);if(Q)y=f,a.isSelectionValid=function(a){var b=d(a,"isSelectionValid").document,c=b.selection;return"None"!=c.type||L(c.createRange().parentElement())==b};else{if(!O)return b.fail("Neither document.selection or window.getSelection() detected."),!1;y=e,a.isSelectionValid=function(){return!0}}a.getNativeSelection=y;var R=y();if(!R)return b.fail("Native selection was null (possibly issue 138?)"),!1;var S=a.createNativeRange(document),T=M(document),U=D.areHostProperties(R,["anchorNode","focusNode","anchorOffset","focusOffset"]);J.selectionHasAnchorAndFocus=U;var V=E(R,"extend");J.selectionHasExtend=V;var W=typeof R.rangeCount==B;J.selectionHasRangeCount=W;var X=!1,Y=!0,Z=V?function(b,c){var d=F.getRangeDocument(c),e=a.createRange(d);e.collapseToPoint(c.endContainer,c.endOffset),b.addRange(k(e)),b.extend(c.startContainer,c.startOffset)}:null;D.areHostMethods(R,["addRange","getRangeAt","removeAllRanges"])&&typeof R.rangeCount==B&&J.implementsDomRange&&!function(){var b=window.getSelection();if(b){for(var c=b.rangeCount,d=c>1,e=[],f=g(b),h=0;c>h;++h)e[h]=b.getRangeAt(h);var i=C.createTestElement(document,"",!1),j=i.appendChild(document.createTextNode("Â Â Â ")),k=document.createRange();if(k.setStart(j,1),k.collapse(!0),b.removeAllRanges(),b.addRange(k),Y=1==b.rangeCount,b.removeAllRanges(),!d){var l=window.navigator.appVersion.match(/Chrome\/(.*?) /);if(l&&parseInt(l[1])>=36)X=!1;else{var m=k.cloneRange();k.setStart(j,0),m.setEnd(j,3),m.setStart(j,2),b.addRange(k),b.addRange(m),X=2==b.rangeCount}}for(C.removeNode(i),b.removeAllRanges(),h=0;c>h;++h)0==h&&f?Z?Z(b,e[h]):(a.warn("Rangy initialization: original selection was backwards but selection has been restored forwards because the browser does not support Selection.extend"),b.addRange(e[h])):b.addRange(e[h])}}(),J.selectionSupportsMultipleRanges=X,J.collapsedNonEditableSelectionsSupported=Y;var $,_=!1;T&&E(T,"createControlRange")&&($=T.createControlRange(),D.areHostProperties($,["item","add"])&&(_=!0)),J.implementsControlRange=_,z=U?function(a){return a.anchorNode===a.focusNode&&a.anchorOffset===a.focusOffset}:function(a){return a.rangeCount?a.getRangeAt(a.rangeCount-1).collapsed:!1};var aa;E(R,"getRangeAt")?aa=function(a,b){try{return a.getRangeAt(b)}catch(c){return null}}:U&&(aa=function(b){var c=L(b.anchorNode),d=a.createRange(c);return d.setStartAndEnd(b.anchorNode,b.anchorOffset,b.focusNode,b.focusOffset),d.collapsed!==this.isCollapsed&&d.setStartAndEnd(b.focusNode,b.focusOffset,b.anchorNode,b.anchorOffset),d}),r.prototype=a.selectionPrototype;var ba=[],ca=function(a){if(a&&a instanceof r)return a.refresh(),a;a=d(a,"getNativeSelection");var b=t(a),c=y(a),e=P?f(a):null;return b?(b.nativeSelection=c,b.docSelection=e,b.refresh()):(b=new r(c,e,a),ba.push({win:a,selection:b})),b};a.getSelection=ca,D.createAliasForDeprecatedMethod(a,"getIframeSelection","getSelection");var da=r.prototype;if(!Q&&U&&D.areHostMethods(R,["removeAllRanges","addRange"])){da.removeAllRanges=function(){this.nativeSelection.removeAllRanges(),j(this)};var ea=function(a,b){Z(a.nativeSelection,b),a.refresh()};W?da.addRange=function(b,d){if(_&&P&&this.docSelection.type==K)q(this,b);else if(c(d)&&V)ea(this,b);else{var e;X?e=this.rangeCount:(this.removeAllRanges(),e=0);var f=k(b).cloneRange();try{this.nativeSelection.addRange(f)}catch(g){}if(this.rangeCount=this.nativeSelection.rangeCount,this.rangeCount==e+1){if(a.config.checkSelectionRanges){var i=aa(this.nativeSelection,this.rangeCount-1);i&&!N(i,b)&&(b=new G(i))}this._ranges[this.rangeCount-1]=b,h(this,b,ha(this.nativeSelection)),this.isCollapsed=z(this)}else this.refresh()}}:da.addRange=function(a,b){c(b)&&V?ea(this,a):(this.nativeSelection.addRange(k(a)),this.refresh())},da.setRanges=function(a){if(_&&P&&a.length>1)u(this,a);else{this.removeAllRanges();for(var b=0,c=a.length;c>b;++b)this.addRange(a[b])}}}else{if(!(E(R,"empty")&&E(S,"select")&&_&&Q))return b.fail("No means of selecting a Range or TextRange was found"),!1;da.removeAllRanges=function(){try{if(this.docSelection.empty(),"None"!=this.docSelection.type){var a;if(this.anchorNode)a=L(this.anchorNode);else if(this.docSelection.type==K){var b=this.docSelection.createRange();b.length&&(a=L(b.item(0)))}if(a){var c=M(a).createTextRange();c.select(),this.docSelection.empty()}}}catch(d){}j(this)},da.addRange=function(b){this.docSelection.type==K?q(this,b):(a.WrappedTextRange.rangeToTextRange(b).select(),this._ranges[0]=b,this.rangeCount=1,this.isCollapsed=this._ranges[0].collapsed,h(this,b,!1))},da.setRanges=function(a){this.removeAllRanges();var b=a.length;b>1?u(this,a):b&&this.addRange(a[0])}}da.getRangeAt=function(a){if(0>a||a>=this.rangeCount)throw new H("INDEX_SIZE_ERR");return this._ranges[a].cloneRange()};var fa;if(Q)fa=function(b){var c;a.isSelectionValid(b.win)?c=b.docSelection.createRange():(c=M(b.win.document).createTextRange(),c.collapse(!0)),b.docSelection.type==K?p(b):n(c)?o(b,c):j(b)};else if(E(R,"getRangeAt")&&typeof R.rangeCount==B)fa=function(b){if(_&&P&&b.docSelection.type==K)p(b);else if(b._ranges.length=b.rangeCount=b.nativeSelection.rangeCount,b.rangeCount){for(var c=0,d=b.rangeCount;d>c;++c)b._ranges[c]=new a.WrappedRange(b.nativeSelection.getRangeAt(c));h(b,b._ranges[b.rangeCount-1],ha(b.nativeSelection)),b.isCollapsed=z(b)}else j(b)};else{if(!U||typeof R.isCollapsed!=A||typeof S.collapsed!=A||!J.implementsDomRange)return b.fail("No means of obtaining a Range or TextRange from the user's selection was found"),!1;fa=function(a){var b,c=a.nativeSelection;c.anchorNode?(b=aa(c,0),a._ranges=[b],a.rangeCount=1,i(a),a.isCollapsed=z(a)):j(a)}}da.refresh=function(a){var b=a?this._ranges.slice(0):null,c=this.anchorNode,d=this.anchorOffset;if(fa(this),a){var e=b.length;if(e!=this._ranges.length)return!0;if(this.anchorNode!=c||this.anchorOffset!=d)return!0;for(;e--;)if(!N(b[e],this._ranges[e]))return!0;return!1}};var ga=function(a,b){var c=a.getAllRanges();a.removeAllRanges();for(var d=0,e=c.length;e>d;++d)N(b,c[d])||a.addRange(c[d]);a.rangeCount||j(a)};_&&P?da.removeRange=function(a){if(this.docSelection.type==K){for(var b,c=this.docSelection.createRange(),d=m(a),e=L(c.item(0)),f=M(e).createControlRange(),g=!1,h=0,i=c.length;i>h;++h)b=c.item(h),b!==d||g?f.add(c.item(h)):g=!0;f.select(),p(this)}else ga(this,a)}:da.removeRange=function(a){ga(this,a)};var ha;!Q&&U&&J.implementsDomRange?(ha=g,da.isBackward=function(){return ha(this)}):ha=da.isBackward=function(){return!1},da.isBackwards=da.isBackward,da.toString=function(){for(var a=[],b=0,c=this.rangeCount;c>b;++b)a[b]=""+this._ranges[b];return a.join("")},da.collapse=function(b,c){v(this,b);var d=a.createRange(b);d.collapseToPoint(b,c),this.setSingleRange(d),this.isCollapsed=!0},da.collapseToStart=function(){if(!this.rangeCount)throw new H("INVALID_STATE_ERR");var a=this._ranges[0];this.collapse(a.startContainer,a.startOffset)},da.collapseToEnd=function(){if(!this.rangeCount)throw new H("INVALID_STATE_ERR");var a=this._ranges[this.rangeCount-1];this.collapse(a.endContainer,a.endOffset)},da.selectAllChildren=function(b){v(this,b);var c=a.createRange(b);c.selectNodeContents(b),this.setSingleRange(c)},da.deleteFromDocument=function(){if(_&&P&&this.docSelection.type==K){for(var a,b=this.docSelection.createRange();b.length;)a=b.item(0),b.remove(a),C.removeNode(a);this.refresh()}else if(this.rangeCount){var c=this.getAllRanges();if(c.length){this.removeAllRanges();for(var d=0,e=c.length;e>d;++d)c[d].deleteContents();this.addRange(c[e-1])}}},da.eachRange=function(a,b){for(var c=0,d=this._ranges.length;d>c;++c)if(a(this.getRangeAt(c)))return b},da.getAllRanges=function(){var a=[];return this.eachRange(function(b){a.push(b)}),a},da.setSingleRange=function(a,b){this.removeAllRanges(),this.addRange(a,b)},da.callMethodOnEachRange=function(a,b){var c=[];return this.eachRange(function(d){c.push(d[a].apply(d,b||[]))}),c},da.setStart=w(!0),da.setEnd=w(!1),a.rangePrototype.select=function(a){ca(this.getDocument()).setSingleRange(this,a)},da.changeEachRange=function(a){var b=[],c=this.isBackward();this.eachRange(function(c){a(c),b.push(c)}),this.removeAllRanges(),c&&1==b.length?this.addRange(b[0],"backward"):this.setRanges(b)},da.containsNode=function(a,b){return this.eachRange(function(c){return c.containsNode(a,b)},!0)||!1},da.getBookmark=function(a){return{backward:this.isBackward(),rangeBookmarks:this.callMethodOnEachRange("getBookmark",[a])}},da.moveToBookmark=function(b){for(var c,d,e=[],f=0;c=b.rangeBookmarks[f++];)d=a.createRange(this.win),d.moveToBookmark(c),e.push(d);b.backward?this.setSingleRange(e[0],"backward"):this.setRanges(e)},da.saveRanges=function(){return{backward:this.isBackward(),ranges:this.callMethodOnEachRange("cloneRange")}},da.restoreRanges=function(a){this.removeAllRanges();for(var b,c=0;b=a.ranges[c];++c)this.addRange(b,a.backward&&0==c)},da.toHtml=function(){var a=[];return this.eachRange(function(b){a.push(F.toHtml(b))}),a.join("")},J.implementsTextRange&&(da.getNativeTextRange=function(){var c;if(c=this.docSelection){var d=c.createRange();if(n(d))return d;throw b.createError("getNativeTextRange: selection is a control selection")}if(this.rangeCount>0)return a.WrappedTextRange.rangeToTextRange(this.getRangeAt(0));throw b.createError("getNativeTextRange: selection contains no range")}),da.getName=function(){return"WrappedSelection"},da.inspect=function(){return x(this)},da.detach=function(){t(this.win,"delete"),s(this)},r.detachAll=function(){t(null,"deleteAll")},r.inspect=x,r.isDirectionBackward=c,a.Selection=r,a.selectionPrototype=da,a.addShimListener(function(a){"undefined"==typeof a.getSelection&&(a.getSelection=function(){return ca(a)}),a=null})});var M=!1,N=function(a){M||(M=!0,!H.initialized&&H.config.autoInitialize&&l())};return F&&("complete"==document.readyState?N():(a(document,"addEventListener")&&document.addEventListener("DOMContentLoaded",N,!1),J(window,"load",N))),H},this),function(a,b){"function"==typeof define&&define.amd?define(["./rangy-core"],a):"undefined"!=typeof module&&"object"==typeof exports?module.exports=a(require("rangy")):a(b.rangy)}(function(a){return a.createModule("TextRange",["WrappedSelection"],function(a,b){function c(a,b){function c(a,b,c){h.push({start:a,end:b,isWord:c})}for(var d,e,f,g=a.join(""),h=[],i=0;d=b.wordRegex.exec(g);){if(e=d.index,f=e+d[0].length,e>i&&c(i,e,!1),b.includeTrailingSpace)for(;$.test(a[f]);)++f;c(e,f,!0),i=f}return ie;++e)c[e].token=d;return d}function e(a,b,c){for(var e,f=c(a,b),g=[],h=0;e=f[h++];)g.push(d(a,e));return g}function f(a){var b=a||"",c="string"==typeof b?b.split(""):b;return c.sort(function(a,b){return a.charCodeAt(0)-b.charCodeAt(0)}),c.join("").replace(/(.)\1+/g,"$1")}function g(a){var b,c;return a?(b=a.language||_,c={},U(c,ia[b]||ia[_]),U(c,a),c):ia[_]}function h(a,b){var c=V(a,b);return b.hasOwnProperty("wordOptions")&&(c.wordOptions=g(c.wordOptions)),b.hasOwnProperty("characterOptions")&&(c.characterOptions=V(c.characterOptions,ga)),c}function i(a,b){var c=na(a,"display",b),d=a.tagName.toLowerCase();return"block"==c&&fa&&oa.hasOwnProperty(d)?oa[d]:c}function j(a){for(var b=o(a),c=0,d=b.length;d>c;++c)if(1==b[c].nodeType&&"none"==i(b[c]))return!0;return!1}function k(a){var b;return 3==a.nodeType&&(b=a.parentNode)&&"hidden"==na(b,"visibility")}function l(a){return a&&(1==a.nodeType&&!/^(inline(-block|-table)?|none)$/.test(i(a))||9==a.nodeType||11==a.nodeType)}function m(a){return S.isCharacterDataNode(a)||!/^(area|base|basefont|br|col|frame|hr|img|input|isindex|link|meta|param)$/i.test(a.nodeName)}function n(a){for(var b=[];a.parentNode;)b.unshift(a.parentNode),a=a.parentNode;return b}function o(a){return n(a).concat([a])}function p(a){for(;a&&!a.nextSibling;)a=a.parentNode;return a?a.nextSibling:null}function q(a,b){return!b&&a.hasChildNodes()?a.firstChild:p(a)}function r(a){var b=a.previousSibling;if(b){for(a=b;a.hasChildNodes();)a=a.lastChild;return a}var c=a.parentNode;return c&&1==c.nodeType?c:null}function s(a){if(!a||3!=a.nodeType)return!1;var b=a.data;if(""===b)return!0;var c=a.parentNode;if(!c||1!=c.nodeType)return!1;var d=na(a.parentNode,"whiteSpace");return/^[\t\n\r ]+$/.test(b)&&/^(normal|nowrap)$/.test(d)||/^[\t\r ]+$/.test(b)&&"pre-line"==d}function t(a){if(""===a.data)return!0;if(!s(a))return!1;var b=a.parentNode;return b?j(a)?!0:!1:!0}function u(a){var b=a.nodeType;return 7==b||8==b||j(a)||/^(script|style)$/i.test(a.nodeName)||k(a)||t(a)}function v(a,b){var c=a.nodeType;return 7==c||8==c||1==c&&"none"==i(a,b)}function w(){this.store={}}function x(a,b,c){return function(d){var e=this.cache;if(e.hasOwnProperty(a))return pa++,e[a];qa++;var f=b.call(this,c?this[c]:this,d);return e[a]=f,f}}function y(a,b){this.node=a,this.session=b,this.cache=new w,this.positions=new w}function z(a,b){this.offset=b,this.nodeWrapper=a,this.node=a.node,this.session=a.session,this.cache=new w}function A(){return"[Position("+S.inspectNode(this.node)+":"+this.offset+")]"}function B(){return D(),Da=new Ea}function C(){return Da||B()}function D(){Da&&Da.detach(),Da=null}function E(a,c,d,e){function f(){var a=null;return c?(a=h,i||(h=h.previousVisible(),i=!h||d&&h.equals(d))):i||(a=h=h.nextVisible(),i=!h||d&&h.equals(d)),i&&(h=null),a}d&&(c?u(d.node)&&(d=a.previousVisible()):u(d.node)&&(d=d.nextVisible()));var g,h=a,i=!1,j=!1;return{next:function(){if(j)return j=!1,g;for(var a,b;a=f();)if(b=a.getCharacter(e))return g=a,a;return null},rewind:function(){if(!g)throw b.createError("createCharacterIterator: cannot rewind. Only one position can be rewound.");j=!0},dispose:function(){a=d=null}}}function F(a,b,c){function d(a){for(var b,c,d=[],e=a?f:g,h=!1,i=!1;b=e.next();){if(c=b.character,Z.test(c))i&&(i=!1,h=!0);else{if(h){e.rewind();break}i=!0}d.push(b)}return d}var f=E(a,!1,null,b),g=E(a,!0,null,b),h=c.tokenizer,i=d(!0),j=d(!1).reverse(),k=e(j.concat(i),c,h),l=i.length?k.slice(Fa(k,i[0].token)):[],m=j.length?k.slice(0,Fa(k,j.pop().token)+1):[];return{nextEndToken:function(){for(var a,b;1==l.length&&!(a=l[0]).isWord&&(b=d(!0)).length>0;)l=e(a.chars.concat(b),c,h);return l.shift()},previousStartToken:function(){for(var a,b;1==m.length&&!(a=m[0]).isWord&&(b=d(!1)).length>0;)m=e(b.reverse().concat(a.chars),c,h);return m.pop()},dispose:function(){f.dispose(),g.dispose(),l=m=null}}}function G(a,b,c,d,e){var f,g,h,i,j=0,k=a,l=Math.abs(c);if(0!==c){var m=0>c;switch(b){case Q:for(g=E(a,m,null,d);(f=g.next())&&l>j;)++j,k=f;h=f,g.dispose();break;case R:for(var n=F(a,d,e),o=m?n.previousStartToken:n.nextEndToken;(i=o())&&l>j;)i.isWord&&(++j,k=m?i.chars[0]:i.chars[i.chars.length-1]);break;default:throw new Error("movePositionBy: unit '"+b+"' not implemented")}m?(k=k.previousVisible(),j=-j):k&&k.isLeadingSpace&&!k.isTrailingSpace&&(b==R&&(g=E(a,!1,null,d),h=g.next(),g.dispose()),h&&(k=h.previousVisible()))}return{position:k,unitsMoved:j}}function H(a,b,c,d){var e=a.getRangeBoundaryPosition(b,!0),f=a.getRangeBoundaryPosition(b,!1),g=d?f:e,h=d?e:f;return E(g,!!d,h,c)}function I(a,b,c){for(var d,e=[],f=H(a,b,c);d=f.next();)e.push(d);return f.dispose(),e}function J(b,c,d){var e=a.createRange(b.node);return e.setStartAndEnd(b.node,b.offset,c.node,c.offset),!e.expand("word",{wordOptions:d})}function K(a,b,c,d,e){function f(a,b){var c=p[a].previousVisible(),d=p[b-1],f=!e.wholeWordsOnly||J(c,d,e.wordOptions);return{startPos:c,endPos:d,valid:f}}for(var g,h,i,j,k,l,m=aa(e.direction),n=E(a,m,a.session.getRangeBoundaryPosition(d,m),e.characterOptions),o="",p=[],q=null;g=n.next();)if(h=g.character,c||e.caseSensitive||(h=h.toLowerCase()),m?(p.unshift(g),o=h+o):(p.push(g),o+=h),c){if(k=b.exec(o))if(i=k.index,j=i+k[0].length,l){if(!m&&j0){q=f(i,j);break}}else l=!0}else if(-1!=(i=o.indexOf(b))){q=f(i,i+b.length);break}return l&&(q=f(i,j)),n.dispose(),q}function L(a){return function(){var b=!!Da,c=C(),d=[c].concat(T.toArray(arguments)),e=a.apply(this,d);return b||D(),e}}function M(a,b){return L(function(c,d,e,f){typeof e==P&&(e=d,d=Q),f=h(f,ka);var g=a;b&&(g=e>=0,this.collapse(!g));var i=G(c.getRangeBoundaryPosition(this,g),d,e,f.characterOptions,f.wordOptions),j=i.position;return this[g?"setStart":"setEnd"](j.node,j.offset),i.unitsMoved})}function N(a){return L(function(b,c){c=V(c,ga);for(var d,e=H(b,this,c,!a),f=0;(d=e.next())&&Z.test(d.character);)++f;e.dispose();var g=f>0;return g&&this[a?"moveStart":"moveEnd"]("character",a?f:-f,{characterOptions:c}),g})}function O(a){return L(function(b,c){var d=!1;return this.changeEachRange(function(b){d=b[a](c)||d}),d})}var P="undefined",Q="character",R="word",S=a.dom,T=a.util,U=T.extend,V=T.createOptions,W=S.getBody,X=/^[ \t\f\r\n]+$/,Y=/^[ \t\f\r]+$/,Z=/^[\t-\r \u0085\u00A0\u1680\u180E\u2000-\u200B\u2028\u2029\u202F\u205F\u3000]+$/,$=/^[\t \u00A0\u1680\u180E\u2000-\u200B\u202F\u205F\u3000]+$/,_="en",aa=a.Selection.isDirectionBackward,ba=!1,ca=!1,da=!1,ea=!0;!function(){var b=S.createTestElement(document,"1
",!0),c=b.firstChild,d=a.getSelection();d.collapse(c.lastChild,2),d.setStart(c.firstChild,0),ba=1==(""+d).length,b.innerHTML="1 ",d.collapse(b,2),d.setStart(b.firstChild,0),ca=1==(""+d).length,b.innerHTML="1 1
",d.collapse(b,2),d.setStart(b.firstChild,0),da=1==(""+d).length,S.removeNode(b),d.removeAllRanges()}();var fa,ga={includeBlockContentTrailingSpace:!0,includeSpaceBeforeBr:!0,includeSpaceBeforeBlock:!0,includePreLineTrailingSpace:!0,ignoreCharacters:""},ha={includeBlockContentTrailingSpace:!ea,includeSpaceBeforeBr:!ca,includeSpaceBeforeBlock:!da,includePreLineTrailingSpace:!0},ia={en:{wordRegex:/[a-z0-9]+('[a-z0-9]+)*/gi,includeTrailingSpace:!1,tokenizer:c}},ja={caseSensitive:!1,withinRange:null,wholeWordsOnly:!1,wrap:!1,direction:"forward",wordOptions:null,characterOptions:null},ka={wordOptions:null,characterOptions:null},la={wordOptions:null,characterOptions:null,trim:!1,trimStart:!0,trimEnd:!0},ma={wordOptions:null,characterOptions:null,direction:"forward"},na=S.getComputedStyleProperty;!function(){var a=document.createElement("table"),b=W(document);b.appendChild(a),fa="block"==na(a,"display"),b.removeChild(a)}();var oa={table:"table",caption:"table-caption",colgroup:"table-column-group",col:"table-column",thead:"table-header-group",tbody:"table-row-group",tfoot:"table-footer-group",tr:"table-row",td:"table-cell",th:"table-cell"};w.prototype={get:function(a){return this.store.hasOwnProperty(a)?this.store[a]:null},set:function(a,b){return this.store[a]=b}};var pa=0,qa=0,ra={getPosition:function(a){var b=this.positions;return b.get(a)||b.set(a,new z(this,a))},toString:function(){return"[NodeWrapper("+S.inspectNode(this.node)+")]"}};y.prototype=ra;var sa="EMPTY",ta="NON_SPACE",ua="UNCOLLAPSIBLE_SPACE",va="COLLAPSIBLE_SPACE",wa="TRAILING_SPACE_BEFORE_BLOCK",xa="TRAILING_SPACE_IN_BLOCK",ya="TRAILING_SPACE_BEFORE_BR",za="PRE_LINE_TRAILING_SPACE_BEFORE_LINE_BREAK",Aa="TRAILING_LINE_BREAK_AFTER_BR",Ba="INCLUDED_TRAILING_LINE_BREAK_AFTER_BR";U(ra,{isCharacterDataNode:x("isCharacterDataNode",S.isCharacterDataNode,"node"),getNodeIndex:x("nodeIndex",S.getNodeIndex,"node"),getLength:x("nodeLength",S.getNodeLength,"node"),containsPositions:x("containsPositions",m,"node"),isWhitespace:x("isWhitespace",s,"node"),
-isCollapsedWhitespace:x("isCollapsedWhitespace",t,"node"),getComputedDisplay:x("computedDisplay",i,"node"),isCollapsed:x("collapsed",u,"node"),isIgnored:x("ignored",v,"node"),next:x("nextPos",q,"node"),previous:x("previous",r,"node"),getTextNodeInfo:x("textNodeInfo",function(a){var b=null,c=!1,d=na(a.parentNode,"whiteSpace"),e="pre-line"==d;return e?(b=Y,c=!0):("normal"==d||"nowrap"==d)&&(b=X,c=!0),{node:a,text:a.data,spaceRegex:b,collapseSpaces:c,preLine:e}},"node"),hasInnerText:x("hasInnerText",function(a,b){for(var c=this.session,d=c.getPosition(a.parentNode,this.getNodeIndex()+1),e=c.getPosition(a,0),f=b?d:e,g=b?e:d;f!==g;){if(f.prepopulateChar(),f.isDefinitelyNonEmpty())return!0;f=b?f.previousVisible():f.nextVisible()}return!1},"node"),isRenderedBlock:x("isRenderedBlock",function(a){for(var b=a.getElementsByTagName("br"),c=0,d=b.length;d>c;++c)if(!u(b[c]))return!0;return this.hasInnerText()},"node"),getTrailingSpace:x("trailingSpace",function(a){if("br"==a.tagName.toLowerCase())return"";switch(this.getComputedDisplay()){case"inline":for(var b=a.lastChild;b;){if(!v(b))return 1==b.nodeType?this.session.getNodeWrapper(b).getTrailingSpace():"";b=b.previousSibling}break;case"inline-block":case"inline-table":case"none":case"table-column":case"table-column-group":break;case"table-cell":return" ";default:return this.isRenderedBlock(!0)?"\n":""}return""},"node"),getLeadingSpace:x("leadingSpace",function(a){switch(this.getComputedDisplay()){case"inline":case"inline-block":case"inline-table":case"none":case"table-column":case"table-column-group":case"table-cell":break;default:return this.isRenderedBlock(!1)?"\n":""}return""},"node")});var Ca={character:"",characterType:sa,isBr:!1,prepopulateChar:function(){var a=this;if(!a.prepopulatedChar){var b=a.node,c=a.offset,d="",e=sa,f=!1;if(c>0)if(3==b.nodeType){var g=b.data,h=g.charAt(c-1),i=a.nodeWrapper.getTextNodeInfo(),j=i.spaceRegex;i.collapseSpaces?j.test(h)?c>1&&j.test(g.charAt(c-2))||(i.preLine&&"\n"===g.charAt(c)?(d=" ",e=za):(d=" ",e=va)):(d=h,e=ta,f=!0):(d=h,e=ua,f=!0)}else{var k=b.childNodes[c-1];if(k&&1==k.nodeType&&!u(k)&&("br"==k.tagName.toLowerCase()?(d="\n",a.isBr=!0,e=va,f=!1):a.checkForTrailingSpace=!0),!d){var l=b.childNodes[c];l&&1==l.nodeType&&!u(l)&&(a.checkForLeadingSpace=!0)}}a.prepopulatedChar=!0,a.character=d,a.characterType=e,a.isCharInvariant=f}},isDefinitelyNonEmpty:function(){var a=this.characterType;return a==ta||a==ua},resolveLeadingAndTrailingSpaces:function(){if(this.prepopulatedChar||this.prepopulateChar(),this.checkForTrailingSpace){var a=this.session.getNodeWrapper(this.node.childNodes[this.offset-1]).getTrailingSpace();a&&(this.isTrailingSpace=!0,this.character=a,this.characterType=va),this.checkForTrailingSpace=!1}if(this.checkForLeadingSpace){var b=this.session.getNodeWrapper(this.node.childNodes[this.offset]).getLeadingSpace();b&&(this.isLeadingSpace=!0,this.character=b,this.characterType=va),this.checkForLeadingSpace=!1}},getPrecedingUncollapsedPosition:function(a){for(var b,c=this;c=c.previousVisible();)if(b=c.getCharacter(a),""!==b)return c;return null},getCharacter:function(a){function b(){return n||(k=o.getPrecedingUncollapsedPosition(a),n=!0),k}this.resolveLeadingAndTrailingSpaces();var c,d=this.character,e=f(a.ignoreCharacters),g=""!==d&&e.indexOf(d)>-1;if(this.isCharInvariant)return c=g?"":d;var h=["character",a.includeSpaceBeforeBr,a.includeBlockContentTrailingSpace,a.includePreLineTrailingSpace,e].join("_"),i=this.cache.get(h);if(null!==i)return i;var j,k,l="",m=this.characterType==va,n=!1,o=this;return m&&(this.type==Ba?l="\n":" "==d&&(!b()||k.isTrailingSpace||"\n"==k.character||" "==k.character&&k.characterType==va)||("\n"==d&&this.isLeadingSpace?b()&&"\n"!=k.character&&(l="\n"):(j=this.nextUncollapsed(),j&&(j.isBr?this.type=ya:j.isTrailingSpace&&"\n"==j.character?this.type=xa:j.isLeadingSpace&&"\n"==j.character&&(this.type=wa),"\n"==j.character?(this.type!=ya||a.includeSpaceBeforeBr)&&(this.type!=wa||a.includeSpaceBeforeBlock)&&(this.type==xa&&j.isTrailingSpace&&!a.includeBlockContentTrailingSpace||(this.type!=za||j.type!=ta||a.includePreLineTrailingSpace)&&("\n"==d?j.isTrailingSpace?this.isTrailingSpace||this.isBr&&(j.type=Aa,b()&&k.isLeadingSpace&&!k.isTrailingSpace&&"\n"==k.character?j.character="":j.type=Ba):l="\n":" "==d&&(l=" "))):l=d)))),e.indexOf(l)>-1&&(l=""),this.cache.set(h,l),l},equals:function(a){return!!a&&this.node===a.node&&this.offset===a.offset},inspect:A,toString:function(){return this.character}};z.prototype=Ca,U(Ca,{next:x("nextPos",function(a){var b=a.nodeWrapper,c=a.node,d=a.offset,e=b.session;if(!c)return null;var f,g,h;return d==b.getLength()?(f=c.parentNode,g=f?b.getNodeIndex()+1:0):b.isCharacterDataNode()?(f=c,g=d+1):(h=c.childNodes[d],e.getNodeWrapper(h).containsPositions()?(f=h,g=0):(f=c,g=d+1)),f?e.getPosition(f,g):null}),previous:x("previous",function(a){var b,c,d,e=a.nodeWrapper,f=a.node,g=a.offset,h=e.session;return 0==g?(b=f.parentNode,c=b?e.getNodeIndex():0):e.isCharacterDataNode()?(b=f,c=g-1):(d=f.childNodes[g-1],h.getNodeWrapper(d).containsPositions()?(b=d,c=S.getNodeLength(d)):(b=f,c=g-1)),b?h.getPosition(b,c):null}),nextVisible:x("nextVisible",function(a){var b=a.next();if(!b)return null;var c=b.nodeWrapper,d=b.node,e=b;return c.isCollapsed()&&(e=c.session.getPosition(d.parentNode,c.getNodeIndex()+1)),e}),nextUncollapsed:x("nextUncollapsed",function(a){for(var b=a;b=b.nextVisible();)if(b.resolveLeadingAndTrailingSpaces(),""!==b.character)return b;return null}),previousVisible:x("previousVisible",function(a){var b=a.previous();if(!b)return null;var c=b.nodeWrapper,d=b.node,e=b;return c.isCollapsed()&&(e=c.session.getPosition(d.parentNode,c.getNodeIndex())),e})});var Da=null,Ea=function(){function a(a){var b=new w;return{get:function(c){var d=b.get(c[a]);if(d)for(var e,f=0;e=d[f++];)if(e.node===c)return e;return null},set:function(c){var d=c.node[a],e=b.get(d)||b.set(d,[]);e.push(c)}}}function b(){this.initCaches()}var c=T.isHostProperty(document.documentElement,"uniqueID");return b.prototype={initCaches:function(){this.elementCache=c?function(){var a=new w;return{get:function(b){return a.get(b.uniqueID)},set:function(b){a.set(b.node.uniqueID,b)}}}():a("tagName"),this.textNodeCache=a("data"),this.otherNodeCache=a("nodeName")},getNodeWrapper:function(a){var b;switch(a.nodeType){case 1:b=this.elementCache;break;case 3:b=this.textNodeCache;break;default:b=this.otherNodeCache}var c=b.get(a);return c||(c=new y(a,this),b.set(c)),c},getPosition:function(a,b){return this.getNodeWrapper(a).getPosition(b)},getRangeBoundaryPosition:function(a,b){var c=b?"start":"end";return this.getPosition(a[c+"Container"],a[c+"Offset"])},detach:function(){this.elementCache=this.textNodeCache=this.otherNodeCache=null}},b}();U(S,{nextNode:q,previousNode:r});var Fa=Array.prototype.indexOf?function(a,b){return a.indexOf(b)}:function(a,b){for(var c=0,d=a.length;d>c;++c)if(a[c]===b)return c;return-1};U(a.rangePrototype,{moveStart:M(!0,!1),moveEnd:M(!1,!1),move:M(!0,!0),trimStart:N(!0),trimEnd:N(!1),trim:L(function(a,b){var c=this.trimStart(b),d=this.trimEnd(b);return c||d}),expand:L(function(a,b,c){var d=!1;c=h(c,la);var e=c.characterOptions;if(b||(b=Q),b==R){var f,g,i=c.wordOptions,j=a.getRangeBoundaryPosition(this,!0),k=a.getRangeBoundaryPosition(this,!1),l=F(j,e,i),m=l.nextEndToken(),n=m.chars[0].previousVisible();if(this.collapsed)f=m;else{var o=F(k,e,i);f=o.previousStartToken()}return g=f.chars[f.chars.length-1],n.equals(j)||(this.setStart(n.node,n.offset),d=!0),g&&!g.equals(k)&&(this.setEnd(g.node,g.offset),d=!0),c.trim&&(c.trimStart&&(d=this.trimStart(e)||d),c.trimEnd&&(d=this.trimEnd(e)||d)),d}return this.moveEnd(Q,1,c)}),text:L(function(a,b){return this.collapsed?"":I(a,this,V(b,ga)).join("")}),selectCharacters:L(function(a,b,c,d,e){var f={characterOptions:e};b||(b=W(this.getDocument())),this.selectNodeContents(b),this.collapse(!0),this.moveStart("character",c,f),this.collapse(!0),this.moveEnd("character",d-c,f)}),toCharacterRange:L(function(a,b,c){b||(b=W(this.getDocument()));var d,e,f=b.parentNode,g=S.getNodeIndex(b),h=-1==S.comparePoints(this.startContainer,this.endContainer,f,g),i=this.cloneRange();return h?(i.setStartAndEnd(this.startContainer,this.startOffset,f,g),d=-i.text(c).length):(i.setStartAndEnd(f,g,this.startContainer,this.startOffset),d=i.text(c).length),e=d+this.text(c).length,{start:d,end:e}}),findText:L(function(b,c,d){d=h(d,ja),d.wholeWordsOnly&&(d.wordOptions.includeTrailingSpace=!1);var e=aa(d.direction),f=d.withinRange;f||(f=a.createRange(),f.selectNodeContents(this.getDocument()));var g=c,i=!1;"string"==typeof g?d.caseSensitive||(g=g.toLowerCase()):i=!0;var j=b.getRangeBoundaryPosition(this,!e),k=f.comparePoint(j.node,j.offset);-1===k?j=b.getRangeBoundaryPosition(f,!0):1===k&&(j=b.getRangeBoundaryPosition(f,!1));for(var l,m=j,n=!1;;)if(l=K(m,g,i,f,d)){if(l.valid)return this.setStartAndEnd(l.startPos.node,l.startPos.offset,l.endPos.node,l.endPos.offset),!0;m=e?l.startPos:l.endPos}else{if(!d.wrap||n)return!1;f=f.cloneRange(),m=b.getRangeBoundaryPosition(f,!e),f.setBoundary(j.node,j.offset,e),n=!0}}),pasteHtml:function(a){if(this.deleteContents(),a){var b=this.createContextualFragment(a),c=b.lastChild;this.insertNode(b),this.collapseAfter(c)}}}),U(a.selectionPrototype,{expand:L(function(a,b,c){this.changeEachRange(function(a){a.expand(b,c)})}),move:L(function(a,b,c,d){var e=0;if(this.focusNode){this.collapse(this.focusNode,this.focusOffset);var f=this.getRangeAt(0);d||(d={}),d.characterOptions=V(d.characterOptions,ha),e=f.move(b,c,d),this.setSingleRange(f)}return e}),trimStart:O("trimStart"),trimEnd:O("trimEnd"),trim:O("trim"),selectCharacters:L(function(b,c,d,e,f,g){var h=a.createRange(c);h.selectCharacters(c,d,e,g),this.setSingleRange(h,f)}),saveCharacterRanges:L(function(a,b,c){for(var d=this.getAllRanges(),e=d.length,f=[],g=1==e&&this.isBackward(),h=0,i=d.length;i>h;++h)f[h]={characterRange:d[h].toCharacterRange(b,c),backward:g,characterOptions:c};return f}),restoreCharacterRanges:L(function(b,c,d){this.removeAllRanges();for(var e,f,g,h=0,i=d.length;i>h;++h)f=d[h],g=f.characterRange,e=a.createRange(c),e.selectCharacters(c,g.start,g.end,f.characterOptions),this.addRange(e,f.backward)}),text:L(function(a,b){for(var c=[],d=0,e=this.rangeCount;e>d;++d)c[d]=this.getRangeAt(d).text(b);return c.join("")})}),a.innerText=function(b,c){var d=a.createRange(b);d.selectNodeContents(b);var e=d.text(c);return e},a.createWordIterator=function(a,b,c){var d=C();c=h(c,ma);var e=d.getPosition(a,b),f=F(e,c.characterOptions,c.wordOptions),g=aa(c.direction);return{next:function(){return g?f.previousStartToken():f.nextEndToken()},dispose:function(){f.dispose(),this.next=function(){}}}},a.noMutation=function(a){var b=C();a(b),D()},a.noMutation.createEntryPointFunction=L,a.textRange={isBlockNode:l,isCollapsedWhitespaceNode:t,createPosition:L(function(a,b,c){return a.getPosition(b,c)})}}),a},this),function(a,b){"function"==typeof define&&define.amd?define(["./rangy-core"],a):"undefined"!=typeof module&&"object"==typeof exports?module.exports=a(require("rangy")):a(b.rangy)}(function(a){return a.createModule("SaveRestore",["WrappedRange"],function(a,b){function c(a,b){return(b||document).getElementById(a)}function d(a,b){var c,d="selectionBoundary_"+ +new Date+"_"+(""+Math.random()).slice(2),e=o.getDocument(a.startContainer),f=a.cloneRange();return f.collapse(b),c=e.createElement("span"),c.id=d,c.style.lineHeight="0",c.style.display="none",c.className="rangySelectionBoundary",c.appendChild(e.createTextNode(r)),f.insertNode(c),c}function e(a,d,e,f){var g=c(e,a);g?(d[f?"setStartBefore":"setEndBefore"](g),p(g)):b.warn("Marker element has been removed. Cannot restore selection.")}function f(a,b){return b.compareBoundaryPoints(a.START_TO_START,a)}function g(b,c){var e,f,g=a.DomRange.getRangeDocument(b),h=b.toString(),i=q(c);return b.collapsed?(f=d(b,!1),{document:g,markerId:f.id,collapsed:!0}):(f=d(b,!1),e=d(b,!0),{document:g,startMarkerId:e.id,endMarkerId:f.id,collapsed:!1,backward:i,toString:function(){return"original text: '"+h+"', new text: '"+b.toString()+"'"}})}function h(d,f){var g=d.document;"undefined"==typeof f&&(f=!0);var h=a.createRange(g);if(d.collapsed){var i=c(d.markerId,g);if(i){i.style.display="inline";var j=i.previousSibling;j&&3==j.nodeType?(p(i),h.collapseToPoint(j,j.length)):(h.collapseBefore(i),p(i))}else b.warn("Marker element has been removed. Cannot restore selection.")}else e(g,h,d.startMarkerId,!0),e(g,h,d.endMarkerId,!1);return f&&h.normalizeBoundaries(),h}function i(b,d){var e,h,i=[],j=q(d);b=b.slice(0),b.sort(f);for(var k=0,l=b.length;l>k;++k)i[k]=g(b[k],j);for(k=l-1;k>=0;--k)e=b[k],h=a.DomRange.getRangeDocument(e),e.collapsed?e.collapseAfter(c(i[k].markerId,h)):(e.setEndBefore(c(i[k].endMarkerId,h)),e.setStartAfter(c(i[k].startMarkerId,h)));return i}function j(c){if(!a.isSelectionValid(c))return b.warn("Cannot save selection. This usually happens when the selection is collapsed and the selection document has lost focus."),null;var d=a.getSelection(c),e=d.getAllRanges(),f=1==e.length&&d.isBackward(),g=i(e,f);return f?d.setSingleRange(e[0],f):d.setRanges(e),{win:c,rangeInfos:g,restored:!1}}function k(a){for(var b=[],c=a.length,d=c-1;d>=0;d--)b[d]=h(a[d],!0);return b}function l(b,c){if(!b.restored){var d=b.rangeInfos,e=a.getSelection(b.win),f=k(d),g=d.length;1==g&&c&&a.features.selectionHasExtend&&d[0].backward?(e.removeAllRanges(),e.addRange(f[0],!0)):e.setRanges(f),b.restored=!0}}function m(a,b){var d=c(b,a);d&&p(d)}function n(a){for(var b,c=a.rangeInfos,d=0,e=c.length;e>d;++d)b=c[d],b.collapsed?m(a.doc,b.markerId):(m(a.doc,b.startMarkerId),m(a.doc,b.endMarkerId))}var o=a.dom,p=o.removeNode,q=a.Selection.isDirectionBackward,r="\ufeff";a.util.extend(a,{saveRange:g,restoreRange:h,saveRanges:i,restoreRanges:k,saveSelection:j,restoreSelection:l,removeMarkerElement:m,removeMarkers:n})}),a},this);var Base=function(){};Base.extend=function(a,b){var c=Base.prototype.extend;Base._prototyping=!0;var d=new this;c.call(d,a),d.base=function(){},delete Base._prototyping;var e=d.constructor,f=d.constructor=function(){if(!Base._prototyping)if(this._constructing||this.constructor==f)this._constructing=!0,e.apply(this,arguments),delete this._constructing;else if(null!=arguments[0])return(arguments[0].extend||c).call(arguments[0],d)};return f.ancestor=this,f.extend=this.extend,f.forEach=this.forEach,f.implement=this.implement,f.prototype=d,f.toString=this.toString,f.valueOf=function(a){return"object"==a?f:e.valueOf()},c.call(f,b),"function"==typeof f.init&&f.init(),f},Base.prototype={extend:function(a,b){if(arguments.length>1){var c=this[a];if(c&&"function"==typeof b&&(!c.valueOf||c.valueOf()!=b.valueOf())&&/\bbase\b/.test(b)){var d=b.valueOf();b=function(){var a=this.base||Base.prototype.base;this.base=c;var b=d.apply(this,arguments);return this.base=a,b},b.valueOf=function(a){return"object"==a?b:d},b.toString=Base.toString}this[a]=b}else if(a){var e=Base.prototype.extend;Base._prototyping||"function"==typeof this||(e=this.extend||e);for(var f={toSource:null},g=["constructor","toString","valueOf"],h=Base._prototyping?0:1;i=g[h++];)a[i]!=f[i]&&e.call(this,i,a[i]);for(var i in a)f[i]||e.call(this,i,a[i])}return this}},Base=Base.extend({constructor:function(){this.extend(arguments[0])}},{ancestor:Object,version:"1.1",forEach:function(a,b,c){for(var d in a)void 0===this.prototype[d]&&b.call(c,a[d],d,a)},implement:function(){for(var a=0;a-1?c=new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})"):/Edge\/(\d+)./i.test(navigator.userAgent)&&(c=/Edge\/(\d+)./i)),c&&null!=c.exec(navigator.userAgent)&&(d=parseFloat(RegExp.$1)),-1===d?!1:a?b?"<"===b?d>a:">"===b?a>d:"<="===b?d>=a:">="===b?a>=d:void 0:a===d:!0}var d=navigator.userAgent,e=document.createElement("div"),f=-1!==d.indexOf("Gecko")&&-1===d.indexOf("KHTML")&&!c(),g=-1!==d.indexOf("AppleWebKit/")&&!c(),h=-1!==d.indexOf("Chrome/")&&!c(),i=-1!==d.indexOf("Opera/")&&!c();return{USER_AGENT:d,supported:function(){var c=this.USER_AGENT.toLowerCase(),d="contentEditable"in e,f=document.execCommand&&document.queryCommandSupported&&document.queryCommandState,g=document.querySelector&&document.querySelectorAll,h=this.isIos()&&a(c)<5||this.isAndroid()&&b(c)<4||-1!==c.indexOf("opera mobi")||-1!==c.indexOf("hpwos/");return d&&f&&g&&!h},isTouchDevice:function(){return this.supportsEvent("touchmove")},isIos:function(){return/ipad|iphone|ipod/i.test(this.USER_AGENT)},isAndroid:function(){return-1!==this.USER_AGENT.indexOf("Android")},supportsSandboxedIframes:function(){return c()},throwsMixedContentWarningWhenIframeSrcIsEmpty:function(){return!("querySelector"in document)},displaysCaretInEmptyContentEditableCorrectly:function(){return c(12,">")},hasCurrentStyleProperty:function(){return"currentStyle"in e},insertsLineBreaksOnReturn:function(){return f},supportsPlaceholderAttributeOn:function(a){return"placeholder"in a},supportsEvent:function(a){return"on"+a in e||function(){return e.setAttribute("on"+a,"return;"),"function"==typeof e["on"+a]}()},supportsEventsInIframeCorrectly:function(){return!i},supportsHTML5Tags:function(a){var b=a.createElement("div"),c="foo ";return b.innerHTML=c,b.innerHTML.toLowerCase()===c},supportsCommand:function(){var a={formatBlock:c(10,"<="),insertUnorderedList:c(),insertOrderedList:c()},b={insertHTML:f};return function(c,d){var e=a[d];if(!e){try{return c.queryCommandSupported(d)}catch(f){}try{return c.queryCommandEnabled(d)}catch(g){return!!b[d]}}return!1}}(),doesAutoLinkingInContentEditable:function(){return c()},canDisableAutoLinking:function(){return this.supportsCommand(document,"AutoUrlDetect")},clearsContentEditableCorrectly:function(){return f||i||g},supportsGetAttributeCorrectly:function(){var a=document.createElement("td");return"1"!=a.getAttribute("rowspan")},canSelectImagesInContentEditable:function(){return f||c()||i},autoScrollsToCaret:function(){return!g},autoClosesUnclosedTags:function(){var a,b,c=e.cloneNode(!1);return c.innerHTML="
",b=c.innerHTML.toLowerCase(),a="
"===b||"
"===b,this.autoClosesUnclosedTags=function(){return a},a},supportsNativeGetElementsByClassName:function(){return-1!==String(document.getElementsByClassName).indexOf("[native code]")},supportsSelectionModify:function(){return"getSelection"in window&&"modify"in window.getSelection()},needsSpaceAfterLineBreak:function(){return i},supportsSpeechApiOn:function(a){var b=d.match(/Chrome\/(\d+)/)||[void 0,0];return b[1]>=11&&("onwebkitspeechchange"in a||"speech"in a)},crashesWhenDefineProperty:function(a){return c(9)&&("XMLHttpRequest"===a||"XDomainRequest"===a)},doesAsyncFocus:function(){return c(12,">")},hasProblemsSettingCaretAfterImg:function(){return c()},hasLiDeletingProblem:function(){return c()},hasUndoInContextMenu:function(){return f||h||i},hasInsertNodeIssue:function(){return i},hasIframeFocusIssue:function(){return c()},createsNestedInvalidMarkupAfterPaste:function(){return g},hasCaretBlockElementIssue:function(){return g},supportsMutationEvents:function(){return"MutationEvent"in window},supportsModernPaste:function(){return!c()},fixStyleKey:function(a){return"cssFloat"===a?"styleFloat"in document.createElement("div").style?"styleFloat":"cssFloat":a},usesControlRanges:function(){return document.body&&"createControlRange"in document.body}}}(),wysihtml5.lang.array=function(a){return{contains:function(b){if(Array.isArray(b)){for(var c=b.length;c--;)if(-1!==wysihtml5.lang.array(a).indexOf(b[c]))return!0;return!1}return-1!==wysihtml5.lang.array(a).indexOf(b)},indexOf:function(b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},without:function(b){b=wysihtml5.lang.array(b);for(var c=[],d=0,e=a.length;e>d;d++)b.contains(a[d])||c.push(a[d]);return c},get:function(){for(var b=0,c=a.length,d=[];c>b;b++)d.push(a[b]);return d},map:function(b,c){if(Array.prototype.map)return a.map(b,c);for(var d=a.length>>>0,e=new Array(d),f=0;d>f;f++)e[f]=b.call(c,a[f],f,a);return e},unique:function(){for(var b=[],c=a.length,d=0;c>d;)wysihtml5.lang.array(b).contains(a[d])||b.push(a[d]),d++;return b}}},wysihtml5.lang.Dispatcher=Base.extend({on:function(a,b){return this.events=this.events||{},this.events[a]=this.events[a]||[],this.events[a].push(b),this},off:function(a,b){this.events=this.events||{};var c,d,e=0;if(a){for(c=this.events[a]||[],d=[];e\t"]/g,d={"&":"&","<":"<",">":">",'"':"""," ":" "};wysihtml5.lang.string=function(e){return e=String(e),{trim:function(){return e.replace(a,"").replace(b,"")},interpolate:function(a){for(var b in a)e=this.replace("#{"+b+"}").by(a[b]);return e},replace:function(a){return{by:function(b){return e.split(a).join(b)}}},escapeHTML:function(a,b){var f=e.replace(c,function(a){return d[a]});return a&&(f=f.replace(/(?:\r\n|\r|\n)/g," ")),b&&(f=f.replace(/ /gi," ")),f}}}}(),function(a){function b(a,b){return f(a,b)?a:(a===a.ownerDocument.documentElement&&(a=a.ownerDocument.body),g(a,b))}function c(a){return a.replace(i,function(a,b){var c=(b.match(j)||[])[1]||"",d=l[c];b=b.replace(j,""),b.split(d).length>b.split(c).length&&(b+=c,c="");var e=b,f=b;return b.length>k&&(f=f.substr(0,k)+"..."),"www."===e.substr(0,4)&&(e="http://"+e),''+f+" "+c})}function d(a){var b=a._wysihtml5_tempElement;return b||(b=a._wysihtml5_tempElement=a.createElement("div")),b}function e(b){var e=b.parentNode,f=a.lang.string(b.data).escapeHTML(),g=d(e.ownerDocument);for(g.innerHTML=" "+c(f),g.removeChild(g.firstChild);g.firstChild;)e.insertBefore(g.firstChild,b);e.removeChild(b)}function f(b,c){for(var d;b.parentNode;){if(b=b.parentNode,d=b.nodeName,b.className&&a.lang.array(b.className.split(" ")).contains(c))return!0;if(h.contains(d))return!0;if("body"===d)return!1}return!1}function g(b,c){if(!(h.contains(b.nodeName)||b.className&&a.lang.array(b.className.split(" ")).contains(c))){if(b.nodeType===a.TEXT_NODE&&b.data.match(i))return void e(b);for(var d=a.lang.array(b.childNodes).get(),f=d.length,j=0;f>j;j++)g(d[j],c);return b}}var h=a.lang.array(["CODE","PRE","A","SCRIPT","HEAD","TITLE","STYLE"]),i=/((https?:\/\/|www\.)[^\s<]{3,})/gi,j=/([^\w\/\-](,?))$/i,k=100,l={")":"(","]":"[","}":"{"};a.dom.autoLink=b,a.dom.autoLink.URL_REG_EXP=i}(wysihtml5),function(a){var b=a.dom;b.addClass=function(a,c){var d=a.classList;return d?d.add(c):void(b.hasClass(a,c)||(a.className+=" "+c))},b.removeClass=function(a,b){var c=a.classList;return c?c.remove(b):void(a.className=a.className.replace(new RegExp("(^|\\s+)"+b+"(\\s+|$)")," "))},b.hasClass=function(a,b){var c=a.classList;if(c)return c.contains(b);var d=a.className;return d.length>0&&(d==b||new RegExp("(^|\\s)"+b+"(\\s|$)").test(d))}}(wysihtml5),wysihtml5.dom.contains=function(){var a=document.documentElement;return a.contains?function(a,b){if(b.nodeType!==wysihtml5.ELEMENT_NODE){if(b.parentNode===a)return!0;b=b.parentNode}return a!==b&&a.contains(b)}:a.compareDocumentPosition?function(a,b){return!!(16&a.compareDocumentPosition(b))}:void 0}(),wysihtml5.dom.convertToList=function(){function a(a,b){var c=a.createElement("li");return b.appendChild(c),c}function b(a,b){return a.createElement(b)}function c(c,d,e){if("UL"===c.nodeName||"OL"===c.nodeName||"MENU"===c.nodeName)return c;var f,g,h,i,j,k,l,m,n,o=c.ownerDocument,p=b(o,d),q=c.querySelectorAll("br"),r=q.length;for(n=0;r>n;n++)for(i=q[n];(j=i.parentNode)&&j!==c&&j.lastChild===i;){if("block"===wysihtml5.dom.getStyle("display").from(j)){j.removeChild(i);break}wysihtml5.dom.insert(i).after(i.parentNode)}for(f=wysihtml5.lang.array(c.childNodes).get(),g=f.length,n=0;g>n;n++)m=m||a(o,p),h=f[n],k="block"===wysihtml5.dom.getStyle("display").from(h),l="BR"===h.nodeName,!k||e&&wysihtml5.dom.hasClass(h,e)?l?m=m.firstChild?null:m:m.appendChild(h):(m=m.firstChild?a(o,p):m,m.appendChild(h),m=null);return 0===f.length&&a(o,p),c.parentNode.replaceChild(p,c),p}return c}(),wysihtml5.dom.copyAttributes=function(a){return{from:function(b){return{to:function(c){for(var d,e=0,f=a.length;f>e;e++)d=a[e],"undefined"!=typeof b[d]&&""!==b[d]&&(c[d]=b[d]);return{andTo:arguments.callee}}}}}},function(a){var b=["-webkit-box-sizing","-moz-box-sizing","-ms-box-sizing","box-sizing"],c=function(b){return d(b)?parseInt(a.getStyle("width").from(b),10)d;d++)if("border-box"===a.getStyle(b[d]).from(c))return b[d]};a.copyStyles=function(d){return{from:function(e){c(e)&&(d=wysihtml5.lang.array(d).without(b));for(var f,g="",h=d.length,i=0;h>i;i++)f=d[i],g+=f+":"+a.getStyle(f).from(e)+";";return{to:function(b){return a.setStyles(g).on(b),{andTo:arguments.callee}}}}}}}(wysihtml5.dom),function(a){a.dom.delegate=function(a,b,c,d){var e=function(c){for(var e=c.target,f=3===e.nodeType?e.parentNode:e,g=a.querySelectorAll(b),h=0,i=g.length;i>h;h++)g[h].contains(f)&&d.call(g[h],c)};return a.addEventListener(c,e,!1),{stop:function(){a.removeEventListener(c,e,!1)}}}}(wysihtml5),function(a){function b(a,b){for(var c=[a],d=a;b&&d&&d!==b||!b&&d;)c.unshift(d),d=d.parentNode;return c}a.dom.domNode=function(c){var d=[a.ELEMENT_NODE,a.TEXT_NODE];return{is:{emptyTextNode:function(b){var d=b?/^\s*$/g:/^[\r\n]*$/g;return c&&c.nodeType===a.TEXT_NODE&&d.test(c.data)},rangyBookmark:function(){return c&&1===c.nodeType&&c.classList.contains("rangySelectionBoundary")},visible:function(){var b=!/^\s*$/g.test(a.dom.getTextContent(c));return b||1===c.nodeType&&c.querySelector("img, br, hr, object, embed, canvas, input, textarea")&&(b=!0),b},lineBreak:function(){return c&&1===c.nodeType&&"BR"===c.nodeName},block:function(){return c&&1===c.nodeType&&"block"===c.ownerDocument.defaultView.getComputedStyle(c).display},voidElement:function(){return a.dom.domNode(c).test({query:a.VOID_ELEMENTS})}},prev:function(b){var e=c.previousSibling,f=b&&b.nodeTypes?b.nodeTypes:d;return e?a.dom.domNode(e).is.rangyBookmark()||!a.lang.array(f).contains(e.nodeType)||b&&b.ignoreBlankTexts&&a.dom.domNode(e).is.emptyTextNode(!0)?a.dom.domNode(e).prev(b):e:null},next:function(b){var e=c.nextSibling,f=b&&b.nodeTypes?b.nodeTypes:d;return e?a.dom.domNode(e).is.rangyBookmark()||!a.lang.array(f).contains(e.nodeType)||b&&b.ignoreBlankTexts&&a.dom.domNode(e).is.emptyTextNode(!0)?a.dom.domNode(e).next(b):e:null},commonAncestor:function(a,d){var e=b(c,d),f=b(a,d);if(e[0]!=f[0])return null;for(var g=0;g0)for(var f=!1,g=Array.isArray(b.styleProperty)?b.styleProperty:[b.styleProperty],h=0,i=g.length;i>h;h++){if(d=a.browser.fixStyleKey(g[h]),c.style[d]){if(!b.styleValue){f=!0;break}if(b.styleValue instanceof RegExp){if(c.style[d].trim().match(b.styleValue).length>0){f=!0;break}}else if(Array.isArray(b.styleValue)){if(b.styleValue.indexOf(c.style[d].trim())){f=!0;break}}else if(b.styleValue===c.style[d].trim().replace(/, /g,",")){f=!0;break}}if(!f)return!1}if(b.attribute){var j=a.dom.getAttributes(c),k=[],l=!1;Array.isArray(b.attribute)?k=b.attribute:k[b.attribute]=b.attributeValue;for(var m in k)if(k.hasOwnProperty(m))if("undefined"==typeof k[m]){if("undefined"!=typeof j[m]){l=!0;break}}else if(j[m]===k[m]){l=!0;break}if(!l)return!1}return!0}}}}(wysihtml5),wysihtml5.dom.getAsDom=function(){var a=function(a,b){var c=b.createElement("div");c.style.display="none",b.body.appendChild(c);try{c.innerHTML=a}catch(d){}return b.body.removeChild(c),c},b=function(a){if(!a._wysihtml5_supportsHTML5Tags){for(var b=0,d=c.length;d>b;b++)a.createElement(c[b]);a._wysihtml5_supportsHTML5Tags=!0}},c=["abbr","article","aside","audio","bdi","canvas","command","datalist","details","figcaption","figure","footer","header","hgroup","keygen","mark","meter","nav","output","progress","rp","rt","ruby","svg","section","source","summary","time","track","video","wbr"];return function(c,d){d=d||document;var e;return"object"==typeof c&&c.nodeType?(e=d.createElement("div"),e.appendChild(c)):wysihtml5.browser.supportsHTML5Tags(d)?(e=d.createElement("div"),e.innerHTML=c):(b(d),e=a(c,d)),e}}(),wysihtml5.dom.getParentElement=function(){return function(a,b,c,d){
-for(c=c||50;c--&&a&&"BODY"!==a.nodeName&&(!d||a!==d);){if(wysihtml5.dom.domNode(a).test(b))return a;a=a.parentNode}return null}}(),wysihtml5.dom.getStyle=function(){function a(a){return a.replace(c,function(a){return a.charAt(1).toUpperCase()})}var b={"float":"styleFloat"in document.createElement("div").style?"styleFloat":"cssFloat"},c=/\-[a-z]/g;return function(c){return{from:function(d){if(d.nodeType===wysihtml5.ELEMENT_NODE){var e=d.ownerDocument,f=b[c]||a(c),g=d.style,h=d.currentStyle,i=g[f];if(i)return i;if(h)try{return h[f]}catch(j){}var k,l,m=e.defaultView||e.parentWindow,n=("height"===c||"width"===c)&&"TEXTAREA"===d.nodeName;return m.getComputedStyle?(n&&(k=g.overflow,g.overflow="hidden"),l=m.getComputedStyle(d,null).getPropertyValue(c),n&&(g.overflow=k||""),l):void 0}}}}}(),wysihtml5.dom.getTextNodes=function(a,b){var c=[];for(a=a.firstChild;a;a=a.nextSibling)3==a.nodeType?b&&/^\s*$/.test(a.innerText||a.textContent)||c.push(a):c=c.concat(wysihtml5.dom.getTextNodes(a,b));return c},wysihtml5.dom.hasElementWithTagName=function(){function a(a){return a._wysihtml5_identifier||(a._wysihtml5_identifier=c++)}var b={},c=1;return function(c,d){var e=a(c)+":"+d,f=b[e];return f||(f=b[e]=c.getElementsByTagName(d)),f.length>0}}(),function(a){function b(a){return a._wysihtml5_identifier||(a._wysihtml5_identifier=d++)}var c={},d=1;a.dom.hasElementWithClassName=function(d,e){if(!a.browser.supportsNativeGetElementsByClassName())return!!d.querySelector("."+e);var f=b(d)+":"+e,g=c[f];return g||(g=c[f]=d.getElementsByClassName(e)),g.length>0}}(wysihtml5),wysihtml5.dom.insert=function(a){return{after:function(b){b.parentNode.insertBefore(a,b.nextSibling)},before:function(b){b.parentNode.insertBefore(a,b)},into:function(b){b.appendChild(a)}}},wysihtml5.dom.insertCSS=function(a){return a=a.join("\n"),{into:function(b){var c=b.createElement("style");c.type="text/css",c.styleSheet?c.styleSheet.cssText=a:c.appendChild(b.createTextNode(a));var d=b.querySelector("head link");if(d)return void d.parentNode.insertBefore(c,d);var e=b.querySelector("head");e&&e.appendChild(c)}}},function(a){a.dom.lineBreaks=function(b){function c(a){return"BR"===a.nodeName}function d(b){return c(b)?!0:"block"===a.dom.getStyle("display").from(b)?!0:!1}return{add:function(c){var e=b.ownerDocument,f=a.dom.domNode(b).next({ignoreBlankTexts:!0}),g=a.dom.domNode(b).prev({ignoreBlankTexts:!0});f&&!d(f)&&a.dom.insert(e.createElement("br")).after(b),g&&!d(g)&&a.dom.insert(e.createElement("br")).before(b)},remove:function(d){var e=a.dom.domNode(b).next({ignoreBlankTexts:!0}),f=a.dom.domNode(b).prev({ignoreBlankTexts:!0});e&&c(e)&&e.parentNode.removeChild(e),f&&c(f)&&f.parentNode.removeChild(f)}}}}(wysihtml5),wysihtml5.dom.observe=function(a,b,c){b="string"==typeof b?[b]:b;for(var d,e,f=0,g=b.length;g>f;f++)e=b[f],a.addEventListener?a.addEventListener(e,c,!1):(d=function(b){"target"in b||(b.target=b.srcElement),b.preventDefault=b.preventDefault||function(){this.returnValue=!1},b.stopPropagation=b.stopPropagation||function(){this.cancelBubble=!0},c.call(a,b)},a.attachEvent("on"+e,d));return{stop:function(){for(var e,f=0,g=b.length;g>f;f++)e=b[f],a.removeEventListener?a.removeEventListener(e,c,!1):a.detachEvent("on"+e,d)}}},wysihtml5.dom.parse=function(a,b){function c(a,b){wysihtml5.lang.object(t).merge(s).merge(b.rules).get();var c,f,g,h=b.context||a.ownerDocument||document,i=h.createDocumentFragment(),j="string"==typeof a,k=!1;for(b.clearInternals===!0&&(k=!0),c=j?wysihtml5.dom.getAsDom(a,h):a,t.selectors&&e(c,t.selectors);c.firstChild;)g=c.firstChild,f=d(g,b.cleanUp,k,b.uneditableClass),f&&i.appendChild(f),g!==f&&c.removeChild(g);if(b.unjoinNbsps)for(var l=wysihtml5.dom.getTextNodes(i),m=l.length;m--;)l[m].nodeValue=l[m].nodeValue.replace(/([\S\u00A0])\u00A0/gi,"$1 ");return c.innerHTML="",c.appendChild(i),j?wysihtml5.quirks.getCorrectInnerHTML(c):c}function d(a,b,c,e){var f,g,h,i,j=a.nodeType,k=a.childNodes,l=k.length,m=p[j],n=0;if(e&&1===j&&wysihtml5.dom.hasClass(a,e))return a;if(g=m&&m(a,c),!g){if(g===!1){for(f=a.ownerDocument.createDocumentFragment(),n=l;n--;)k[n]&&(h=d(k[n],b,c,e),h&&(k[n]===h&&n--,f.insertBefore(h,f.firstChild)));return i=wysihtml5.dom.getStyle("display").from(a),""===i&&(i=wysihtml5.lang.array(u).contains(a.tagName)?"block":""),wysihtml5.lang.array(["block","flex","table"]).contains(i)&&f.appendChild(a.ownerDocument.createElement("br")),wysihtml5.lang.array(["div","pre","p","table","td","th","ul","ol","li","dd","dl","footer","header","section","h1","h2","h3","h4","h5","h6"]).contains(a.nodeName.toLowerCase())&&a.parentNode.lastChild!==a&&(a.nextSibling&&3===a.nextSibling.nodeType&&/^\s/.test(a.nextSibling.nodeValue)||f.appendChild(a.ownerDocument.createTextNode(" "))),f.normalize&&f.normalize(),f}return null}for(n=0;l>n;n++)k[n]&&(h=d(k[n],b,c,e),h&&(k[n]===h&&n--,g.appendChild(h)));if(b&&g.nodeName.toLowerCase()===q&&(!g.childNodes.length||/^\s*$/gi.test(g.innerHTML)&&(c||"_wysihtml5-temp-placeholder"!==a.className&&"rangySelectionBoundary"!==a.className)||!g.attributes.length)){for(f=g.ownerDocument.createDocumentFragment();g.firstChild;)f.appendChild(g.firstChild);return f.normalize&&f.normalize(),f}return g.normalize&&g.normalize(),g}function e(a,b){var c,d,e;for(c in b)if(b.hasOwnProperty(c)){wysihtml5.lang.object(b[c]).isFunction()?d=b[c]:"string"==typeof b[c]&&z[b[c]]&&(d=z[b[c]]),e=a.querySelectorAll(c);for(var f=e.length;f--;)d(e[f])}}function f(a,b){var c,d,e,f=t.tags,h=a.nodeName.toLowerCase(),j=a.scopeName;if(a._wysihtml5)return null;if(a._wysihtml5=1,"wysihtml5-temp"===a.className)return null;if(j&&"HTML"!=j&&(h=j+":"+h),"outerHTML"in a&&(wysihtml5.browser.autoClosesUnclosedTags()||"P"!==a.nodeName||"
"===a.outerHTML.slice(-4).toLowerCase()||(h="div")),h in f){if(c=f[h],!c||c.remove)return null;if(c.unwrap)return!1;c="string"==typeof c?{rename_tag:c}:c}else{if(!a.firstChild)return null;c={rename_tag:q}}if(c.one_of_type&&!g(a,t,c.one_of_type,b)){if(!c.remove_action)return null;if("unwrap"===c.remove_action)return!1;if("rename"!==c.remove_action)return null;e=c.remove_action_rename_to||q}return d=a.ownerDocument.createElement(e||c.rename_tag||h),m(a,d,c,b),i(a,d,c),a=null,d.normalize&&d.normalize(),d}function g(a,b,c,d){var e,f;if("SPAN"===a.nodeName&&!d&&("_wysihtml5-temp-placeholder"===a.className||"rangySelectionBoundary"===a.className))return!0;for(f in c)if(c.hasOwnProperty(f)&&b.type_definitions&&b.type_definitions[f]&&(e=b.type_definitions[f],h(a,e)))return!0;return!1}function h(a,b){var c,d,e,f,g,h=a.getAttribute("class"),i=a.getAttribute("style");if(b.methods)for(var j in b.methods)if(b.methods.hasOwnProperty(j)&&y[j]&&y[j](a))return!0;if(h&&b.classes){h=h.replace(/^\s+/g,"").replace(/\s+$/g,"").split(r),c=h.length;for(var k=0;c>k;k++)if(b.classes[h[k]])return!0}if(i&&b.styles){i=i.split(";");for(d in b.styles)if(b.styles.hasOwnProperty(d))for(var l=i.length;l--;)if(g=i[l].split(":"),g[0].replace(/\s/g,"").toLowerCase()===d&&(b.styles[d]===!0||1===b.styles[d]||wysihtml5.lang.array(b.styles[d]).contains(g[1].replace(/\s/g,"").toLowerCase())))return!0}if(b.attrs)for(e in b.attrs)if(b.attrs.hasOwnProperty(e)&&(f=wysihtml5.dom.getAttribute(a,e),"string"==typeof f&&f.search(b.attrs[e])>-1))return!0;return!1}function i(a,b,c){var d,e;if(c&&c.keep_styles)for(d in c.keep_styles)if(c.keep_styles.hasOwnProperty(d)){if(e="float"===d?a.style.styleFloat||a.style.cssFloat:a.style[d],c.keep_styles[d]instanceof RegExp&&!c.keep_styles[d].test(e))continue;"float"===d?b.style[a.style.styleFloat?"styleFloat":"cssFloat"]=e:a.style[d]&&(b.style[d]=e)}}function j(a,b){var c=[];for(var d in b)b.hasOwnProperty(d)&&0===d.indexOf(a)&&c.push(d);return c}function k(a,b,c,d){var e,f=wysihtml5.lang.object(c).isFunction()?c:v[c];return f&&(e=f(b,d),"string"==typeof e)?e:!1}function l(a,b){var c,d,e,f=wysihtml5.lang.object(t.attributes||{}).clone(),g=wysihtml5.lang.object(f).merge(wysihtml5.lang.object(b||{}).clone()).get(),h={},i=wysihtml5.dom.getAttributes(a);for(c in g)if(/\*$/.test(c)){e=j(c.slice(0,-1),i);for(var l=0,m=e.length;m>l;l++)d=k(e[l],i[e[l]],g[c],a.nodeName),d!==!1&&(h[e[l]]=d)}else d=k(c,i[c],g[c],a.nodeName),d!==!1&&(h[c]=d);return h}function m(a,b,c,d){var e,f,g,h,i,j={},k=c.set_class,m=c.add_class,n=c.add_style,o=c.set_attributes,p=t.classes,q=0,s=[],u=[],v=[],y=[];if(o&&(j=wysihtml5.lang.object(o).clone()),j=wysihtml5.lang.object(j).merge(l(a,c.check_attributes)).get(),k&&s.push(k),m)for(h in m)i=x[m[h]],i&&(g=i(wysihtml5.dom.getAttribute(a,h)),"string"==typeof g&&s.push(g));if(n)for(h in n)i=w[n[h]],i&&(newStyle=i(wysihtml5.dom.getAttribute(a,h)),"string"==typeof newStyle&&u.push(newStyle));if("string"==typeof p&&"any"===p)if(a.getAttribute("class"))if(t.classes_blacklist){for(y=a.getAttribute("class"),y&&(s=s.concat(y.split(r))),e=s.length;e>q;q++)f=s[q],t.classes_blacklist[f]||v.push(f);v.length&&(j["class"]=wysihtml5.lang.array(v).unique().join(" "))}else j["class"]=a.getAttribute("class");else s&&s.length>0&&(j["class"]=wysihtml5.lang.array(s).unique().join(" "));else{for(d||(p["_wysihtml5-temp-placeholder"]=1,p._rangySelectionBoundary=1,p["wysiwyg-tmp-selected-cell"]=1),y=a.getAttribute("class"),y&&(s=s.concat(y.split(r))),e=s.length;e>q;q++)f=s[q],p[f]&&v.push(f);v.length&&(j["class"]=wysihtml5.lang.array(v).unique().join(" "))}j["class"]&&d&&(j["class"]=j["class"].replace("wysiwyg-tmp-selected-cell",""),/^\s*$/g.test(j["class"])&&delete j["class"]),u.length&&(j.style=wysihtml5.lang.array(u).unique().join(" "));for(h in j)try{b.setAttribute(h,j[h])}catch(z){}j.src&&("undefined"!=typeof j.width&&b.setAttribute("width",j.width),"undefined"!=typeof j.height&&b.setAttribute("height",j.height))}function n(a){var b=a.nextSibling;if(!b||b.nodeType!==wysihtml5.TEXT_NODE){var c=a.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"");return a.ownerDocument.createTextNode(c)}b.data=a.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"")+b.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"")}function o(a){return t.comments?a.ownerDocument.createComment(a.nodeValue):void 0}var p={1:f,3:n,8:o},q="span",r=/\s+/,s={tags:{},classes:{}},t={},u=["ADDRESS","BLOCKQUOTE","CENTER","DIR","DIV","DL","FIELDSET","FORM","H1","H2","H3","H4","H5","H6","ISINDEX","MENU","NOFRAMES","NOSCRIPT","OL","P","PRE","TABLE","UL"],v={url:function(){var a=/^https?:\/\//i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),src:function(){var a=/^(\/|https?:\/\/)/i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),href:function(){var a=/^(#|\/|https?:\/\/|mailto:|tel:)/i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),alt:function(){var a=/[^ a-z0-9_\-]/gi;return function(b,c){return b?b.replace(a,""):"IMG"===c?"":null}}(),numbers:function(){var a=/\D/g;return function(b){return b=(b||"").replace(a,""),b||null}}(),dimension:function(){var a=/\D*(\d+)(\.\d+)?\s?(%)?\D*/;return function(b){return b=(b||"").replace(a,"$1$2$3"),b||null}}(),any:function(){return function(a){return a?a:null}}()},w={align_text:function(){var a={left:"text-align: left;",right:"text-align: right;",center:"text-align: center;"};return function(b){return a[String(b).toLowerCase()]}}()},x={align_img:function(){var a={left:"wysiwyg-float-left",right:"wysiwyg-float-right"};return function(b){return a[String(b).toLowerCase()]}}(),align_text:function(){var a={left:"wysiwyg-text-align-left",right:"wysiwyg-text-align-right",center:"wysiwyg-text-align-center",justify:"wysiwyg-text-align-justify"};return function(b){return a[String(b).toLowerCase()]}}(),clear_br:function(){var a={left:"wysiwyg-clear-left",right:"wysiwyg-clear-right",both:"wysiwyg-clear-both",all:"wysiwyg-clear-both"};return function(b){return a[String(b).toLowerCase()]}}(),size_font:function(){var a={1:"wysiwyg-font-size-xx-small",2:"wysiwyg-font-size-small",3:"wysiwyg-font-size-medium",4:"wysiwyg-font-size-large",5:"wysiwyg-font-size-x-large",6:"wysiwyg-font-size-xx-large",7:"wysiwyg-font-size-xx-large","-":"wysiwyg-font-size-smaller","+":"wysiwyg-font-size-larger"};return function(b){return a[String(b).charAt(0)]}}()},y={has_visible_contet:function(){var a,b=["img","video","picture","br","script","noscript","style","table","iframe","object","embed","audio","svg","input","button","select","textarea","canvas"];return function(c){if(a=(c.innerText||c.textContent).replace(/\s/g,""),a&&a.length>0)return!0;for(var d=b.length;d--;)if(c.querySelector(b[d]))return!0;return c.offsetWidth&&c.offsetWidth>0&&c.offsetHeight&&c.offsetHeight>0?!0:!1}}()},z={unwrap:function(a){wysihtml5.dom.unwrap(a)},remove:function(a){a.parentNode.removeChild(a)}};return c(a,b)},wysihtml5.dom.removeEmptyTextNodes=function(a){for(var b,c=wysihtml5.lang.array(a.childNodes).get(),d=c.length,e=0;d>e;e++)b=c[e],b.nodeType===wysihtml5.TEXT_NODE&&/^[\n\r]*$/.test(b.data)&&b.parentNode.removeChild(b)},wysihtml5.dom.renameElement=function(a,b){for(var c,d=a.ownerDocument.createElement(b);c=a.firstChild;)d.appendChild(c);return wysihtml5.dom.copyAttributes(["align","className"]).from(a).to(d),a.parentNode&&a.parentNode.replaceChild(d,a),d},wysihtml5.dom.replaceWithChildNodes=function(a){if(a.parentNode){for(;a.firstChild;)a.parentNode.insertBefore(a.firstChild,a);a.parentNode.removeChild(a)}},function(a){function b(b){return"block"===a.getStyle("display").from(b)}function c(a){return"BR"===a.nodeName}function d(a){var b=a.ownerDocument.createElement("br");a.appendChild(b)}function e(a,e){if(a.nodeName.match(/^(MENU|UL|OL)$/)){var f,g,h,i,j,k,l,m=a.ownerDocument,n=m.createDocumentFragment(),o=wysihtml5.dom.domNode(a).prev({ignoreBlankTexts:!0}),p=wysihtml5.dom.domNode(a).next({ignoreBlankTexts:!0}),q=a.lastElementChild||a.lastChild;if(e)for(!o||b(o)||c(o)||d(n);k=a.firstElementChild||a.firstChild;){for(g=k.lastChild,l=k===q;f=k.firstChild;)h=f===g,i=(!l||p&&!b(p))&&h&&!b(f)&&!c(f),n.appendChild(f),i&&d(n);k.parentNode.removeChild(k)}else for(;k=a.firstElementChild||a.firstChild;){if(k.querySelector&&k.querySelector("div, p, ul, ol, menu, blockquote, h1, h2, h3, h4, h5, h6"))for(;f=k.firstChild;)n.appendChild(f);else{for(j=m.createElement("p");f=k.firstChild;)j.appendChild(f);n.appendChild(j)}k.parentNode.removeChild(k)}a.parentNode.replaceChild(n,a)}}a.resolveList=e}(wysihtml5.dom),function(a){var b=document,c=["parent","top","opener","frameElement","frames","localStorage","globalStorage","sessionStorage","indexedDB"],d=["open","close","openDialog","showModalDialog","alert","confirm","prompt","openDatabase","postMessage","XMLHttpRequest","XDomainRequest"],e=["referrer","write","open","close"];a.dom.Sandbox=Base.extend({constructor:function(b,c){this.callback=b||a.EMPTY_FUNCTION,this.config=a.lang.object({}).merge(c).get(),this.config.className||(this.config.className="wysihtml5-sandbox"),this.editableArea=this._createIframe()},insertInto:function(a){"string"==typeof a&&(a=b.getElementById(a)),a.appendChild(this.editableArea)},getIframe:function(){return this.editableArea},getWindow:function(){this._readyError()},getDocument:function(){this._readyError()},destroy:function(){var a=this.getIframe();a.parentNode.removeChild(a)},_readyError:function(){throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet")},_createIframe:function(){var c=this,d=b.createElement("iframe");return d.className=this.config.className,a.dom.setAttributes({security:"restricted",allowtransparency:"true",frameborder:0,width:0,height:0,marginwidth:0,marginheight:0}).on(d),a.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()&&(d.src="javascript:''"),d.onload=function(){d.onreadystatechange=d.onload=null,c._onLoadIframe(d)},d.onreadystatechange=function(){/loaded|complete/.test(d.readyState)&&(d.onreadystatechange=d.onload=null,c._onLoadIframe(d))},d},_onLoadIframe:function(f){if(a.dom.contains(b.documentElement,f)){var g=this,h=f.contentWindow,i=f.contentWindow.document,j=b.characterSet||b.charset||"utf-8",k=this._getHtml({charset:j,stylesheets:this.config.stylesheets});if(i.open("text/html","replace"),i.write(k),i.close(),this.getWindow=function(){return f.contentWindow},this.getDocument=function(){return f.contentWindow.document},h.onerror=function(a,b,c){throw new Error("wysihtml5.Sandbox: "+a,b,c)},!a.browser.supportsSandboxedIframes()){var l,m;for(l=0,m=c.length;m>l;l++)this._unset(h,c[l]);for(l=0,m=d.length;m>l;l++)this._unset(h,d[l],a.EMPTY_FUNCTION);for(l=0,m=e.length;m>l;l++)this._unset(i,e[l]);this._unset(i,"cookie","",!0)}a.polyfills&&a.polyfills(h,i),this.loaded=!0,setTimeout(function(){g.callback(g)},0)}},_getHtml:function(b){var c,d=b.stylesheets,e="",f=0;if(d="string"==typeof d?[d]:d)for(c=d.length;c>f;f++)e+=' ';return b.stylesheets=e,a.lang.string(' #{stylesheets}').interpolate(b)},_unset:function(b,c,d,e){try{b[c]=d}catch(f){}try{b.__defineGetter__(c,function(){return d})}catch(f){}if(e)try{b.__defineSetter__(c,function(){})}catch(f){}if(!a.browser.crashesWhenDefineProperty(c))try{var g={get:function(){return d}};e&&(g.set=function(){}),Object.defineProperty(b,c,g)}catch(f){}}})}(wysihtml5),function(a){var b=document;a.dom.ContentEditableArea=Base.extend({getContentEditable:function(){return this.element},getWindow:function(){return this.element.ownerDocument.defaultView||this.element.ownerDocument.parentWindow},getDocument:function(){return this.element.ownerDocument},constructor:function(b,c,d){this.callback=b||a.EMPTY_FUNCTION,this.config=a.lang.object({}).merge(c).get(),this.config.className||(this.config.className="wysihtml5-sandbox"),d?this.element=this._bindElement(d):this.element=this._createElement()},destroy:function(){},_createElement:function(){var a=b.createElement("div");return a.className=this.config.className,this._loadElement(a),a},_bindElement:function(a){return a.className=a.className?a.className+" wysihtml5-sandbox":"wysihtml5-sandbox",this._loadElement(a,!0),a},_loadElement:function(a,b){var c=this;if(!b){var d=this._getHtml();a.innerHTML=d}this.loaded=!0,setTimeout(function(){c.callback(c)},0)},_getHtml:function(a){return""}})}(wysihtml5),function(){var a={className:"class"};wysihtml5.dom.setAttributes=function(b){return{on:function(c){for(var d in b)c.setAttribute(a[d]||d,b[d])}}}}(),wysihtml5.dom.setStyles=function(a){return{on:function(b){var c=b.style;if("string"==typeof a)return void(c.cssText+=";"+a);for(var d in a)"float"===d?(c.cssFloat=a[d],c.styleFloat=a[d]):c[d]=a[d]}}},function(a){a.simulatePlaceholder=function(b,c,d,e){var f=e||"wysihtml5-placeholder",g=function(){var b=c.element.offsetWidth>0&&c.element.offsetHeight>0;c.hasPlaceholderSet()&&(c.clear(),c.element.focus(),b&&setTimeout(function(){var a=c.selection.getSelection();a.focusNode&&a.anchorNode||c.selection.selectNode(c.element.firstChild||c.element)},0)),c.placeholderSet=!1,a.removeClass(c.element,f)},h=function(){c.isEmpty()&&!c.placeholderSet&&(c.placeholderSet=!0,c.setValue(d,!1),a.addClass(c.element,f))};b.on("set_placeholder",h).on("unset_placeholder",g).on("focus:composer",g).on("paste:composer",g).on("blur:composer",h),h()}}(wysihtml5.dom),function(a){var b=document.documentElement;"textContent"in b?(a.setTextContent=function(a,b){a.textContent=b},a.getTextContent=function(a){return a.textContent}):"innerText"in b?(a.setTextContent=function(a,b){a.innerText=b},a.getTextContent=function(a){return a.innerText}):(a.setTextContent=function(a,b){a.nodeValue=b},a.getTextContent=function(a){return a.nodeValue})}(wysihtml5.dom),wysihtml5.dom.getAttribute=function(a,b){var c=!wysihtml5.browser.supportsGetAttributeCorrectly();b=b.toLowerCase();var d=a.nodeName;if("IMG"==d&&"src"==b&&wysihtml5.dom.isLoadedImage(a)===!0)return a.src;if(c&&"outerHTML"in a){var e=a.outerHTML.toLowerCase(),f=-1!=e.indexOf(" "+b+"=");return f?a.getAttribute(b):null}return a.getAttribute(b)},wysihtml5.dom.getAttributes=function(a){var b,c=!wysihtml5.browser.supportsGetAttributeCorrectly(),d=a.nodeName,e=[];for(b in a.attributes)(a.attributes.hasOwnProperty&&a.attributes.hasOwnProperty(b)||!a.attributes.hasOwnProperty&&Object.prototype.hasOwnProperty.call(a.attributes,b))&&a.attributes[b].specified&&("IMG"==d&&"src"==a.attributes[b].name.toLowerCase()&&wysihtml5.dom.isLoadedImage(a)===!0?e.src=a.src:wysihtml5.lang.array(["rowspan","colspan"]).contains(a.attributes[b].name.toLowerCase())&&c?1!==a.attributes[b].value&&(e[a.attributes[b].name]=a.attributes[b].value):e[a.attributes[b].name]=a.attributes[b].value);return e},wysihtml5.dom.isLoadedImage=function(a){try{return a.complete&&!a.mozMatchesSelector(":-moz-broken")}catch(b){if(a.complete&&"complete"===a.readyState)return!0}},function(a){function b(a,b){for(var c,d=[],e=0,f=a.length;f>e;e++)if(c=a[e].querySelectorAll(b))for(var g=c.length;g--;d.unshift(c[g]));return d}function d(a){a.parentNode.removeChild(a)}function e(a,b){a.parentNode.insertBefore(b,a.nextSibling)}function f(a,b){for(var c=a.nextSibling;1!=c.nodeType;)if(c=c.nextSibling,!b||b==c.tagName.toLowerCase())return c;return null}var g=a.dom,h=function(a){this.el=a,this.isColspan=!1,this.isRowspan=!1,this.firstCol=!0,this.lastCol=!0,this.firstRow=!0,this.lastRow=!0,this.isReal=!0,this.spanCollection=[],this.modified=!1},i=function(a,b){a?(this.cell=a,this.table=g.getParentElement(a,{query:"table"})):b&&(this.table=b,this.cell=this.table.querySelectorAll("th, td")[0])};i.prototype={addSpannedCellToMap:function(a,b,c,d,e,f){for(var g=[],i=c+(f?parseInt(f,10)-1:0),j=d+(e?parseInt(e,10)-1:0),k=c;i>=k;k++){"undefined"==typeof b[k]&&(b[k]=[]);for(var l=d;j>=l;l++)b[k][l]=new h(a),b[k][l].isColspan=e&&parseInt(e,10)>1,b[k][l].isRowspan=f&&parseInt(f,10)>1,b[k][l].firstCol=l==d,b[k][l].lastCol=l==j,b[k][l].firstRow=k==c,b[k][l].lastRow=k==i,b[k][l].isReal=l==d&&k==c,b[k][l].spanCollection=g,g.push(b[k][l])}},setCellAsModified:function(a){if(a.modified=!0,a.spanCollection.length>0)for(var b=0,c=a.spanCollection.length;c>b;b++)a.spanCollection[b].modified=!0},setTableMap:function(){var a,b,c,d,e,f,i,j,k=[],l=this.getTableRows();for(a=0;a0?a.lang.array(f).without(e):f;return g},getTableRows:function(){var c=this.table.querySelectorAll("table"),d=c?b(c,"tr"):[],e=this.table.querySelectorAll("tr"),f=d.length>0?a.lang.array(e).without(d):e;return f},getMapIndex:function(a){for(var b=this.map.length,c=this.map&&this.map[0]?this.map[0].length:0,d=0;b>d;d++)for(var e=0;c>e;e++)if(this.map[d][e].el===a)return{row:d,col:e};return!1},getElementAtIndex:function(a){return this.setTableMap(),this.map[a.row]&&this.map[a.row][a.col]&&this.map[a.row][a.col].el?this.map[a.row][a.col].el:null},getMapElsTo:function(a){var b=[];if(this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(a),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var c=this.idx_start;this.idx_start=this.idx_end,this.idx_end=c}if(this.idx_start.col>this.idx_end.col){var d=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=d}if(null!=this.idx_start&&null!=this.idx_end)for(var e=this.idx_start.row,f=this.idx_end.row;f>=e;e++)for(var g=this.idx_start.col,h=this.idx_end.col;h>=g;g++)b.push(this.map[e][g].el);return b},orderSelectionEnds:function(a){if(this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(a),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var b=this.idx_start;this.idx_start=this.idx_end,this.idx_end=b}if(this.idx_start.col>this.idx_end.col){var c=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=c}return{start:this.map[this.idx_start.row][this.idx_start.col].el,end:this.map[this.idx_end.row][this.idx_end.col].el}},createCells:function(a,b,c){for(var d,e=this.table.ownerDocument,f=e.createDocumentFragment(),g=0;b>g;g++){if(d=e.createElement(a),c)for(var h in c)c.hasOwnProperty(h)&&d.setAttribute(h,c[h]);d.appendChild(document.createTextNode("Â ")),f.appendChild(d)}return f},correctColIndexForUnreals:function(a,b){for(var c=this.map[b],d=-1,e=0;a>e;e++)c[e].isReal&&d++;return d},getLastNewCellOnRow:function(a,b){for(var c,d,e=this.getRowCells(a),f=0,g=e.length;g>f;f++)if(c=e[f],d=this.getMapIndex(c),d===!1||"undefined"!=typeof b&&d.row!=b)return c;return null},removeEmptyTable:function(){var a=this.table.querySelectorAll("td, th");return a&&0!=a.length?!1:(d(this.table),!0)},splitRowToCells:function(a){if(a.isColspan){var b=parseInt(g.getAttribute(a.el,"colspan")||1,10),c=a.el.tagName.toLowerCase();if(b>1){var d=this.createCells(c,b-1);e(a.el,d)}a.el.removeAttribute("colspan")}},getRealRowEl:function(a,b){var c=null,d=null;b=b||this.idx;for(var e=0,f=this.map[b.row].length;f>e;e++)if(d=this.map[b.row][e],d.isReal&&(c=g.getParentElement(d.el,{query:"tr"})))return c;return null===c&&a&&(c=g.getParentElement(this.map[b.row][b.col].el,{query:"tr"})||null),c},injectRowAt:function(a,b,c,d,f){var h=this.getRealRowEl(!1,{row:a,col:b}),i=this.createCells(d,c);if(h){var j=this.correctColIndexForUnreals(b,a);j>=0?e(this.getRowCells(h)[j],i):h.insertBefore(i,h.firstChild)}else{var k=this.table.ownerDocument.createElement("tr");k.appendChild(i),e(g.getParentElement(f.el,{query:"tr"}),k)}},canMerge:function(a){if(this.to=a,this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(this.to),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var b=this.idx_start;this.idx_start=this.idx_end,this.idx_end=b}if(this.idx_start.col>this.idx_end.col){var c=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=c}for(var d=this.idx_start.row,e=this.idx_end.row;e>=d;d++)for(var f=this.idx_start.col,g=this.idx_end.col;g>=f;f++)if(this.map[d][f].isColspan||this.map[d][f].isRowspan)return!1;return!0},decreaseCellSpan:function(a,b){var c=parseInt(g.getAttribute(a.el,b),10)-1;c>=1?a.el.setAttribute(b,c):(a.el.removeAttribute(b),"colspan"==b&&(a.isColspan=!1),"rowspan"==b&&(a.isRowspan=!1),a.firstCol=!0,a.lastCol=!0,a.firstRow=!0,a.lastRow=!0,a.isReal=!0)},removeSurplusLines:function(){var a,b,c,e,f,h,i;if(this.setTableMap(),this.map){for(c=0,e=this.map.length;e>c;c++){for(a=this.map[c],i=!0,f=0,h=a.length;h>f;f++)if(b=a[f],!(g.getAttribute(b.el,"rowspan")&&parseInt(g.getAttribute(b.el,"rowspan"),10)>1&&b.firstRow!==!0)){i=!1;break}if(i)for(f=0;h>f;f++)this.decreaseCellSpan(a[f],"rowspan")}var j=this.getTableRows();for(c=0,e=j.length;e>c;c++)a=j[c],0==a.childNodes.length&&/^\s*$/.test(a.textContent||a.innerText)&&d(a)}},fillMissingCells:function(){var a=0,b=0,c=null;if(this.setTableMap(),this.map){a=this.map.length;for(var d=0;a>d;d++)this.map[d].length>b&&(b=this.map[d].length);for(var f=0;a>f;f++)for(var g=0;b>g;g++)this.map[f]&&!this.map[f][g]&&g>0&&(this.map[f][g]=new h(this.createCells("td",1)),c=this.map[f][g-1],c&&c.el&&c.el.parent&&e(this.map[f][g-1].el,this.map[f][g].el))}},rectify:function(){return this.removeEmptyTable()?!1:(this.removeSurplusLines(),this.fillMissingCells(),!0)},unmerge:function(){if(this.rectify()&&(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx)){var a=this.map[this.idx.row][this.idx.col],b=g.getAttribute(a.el,"colspan")?parseInt(g.getAttribute(a.el,"colspan"),10):1,c=a.el.tagName.toLowerCase();if(a.isRowspan){var d=parseInt(g.getAttribute(a.el,"rowspan"),10);if(d>1)for(var e=1,f=d-1;f>=e;e++)this.injectRowAt(this.idx.row+e,this.idx.col,b,c,a);a.el.removeAttribute("rowspan")}this.splitRowToCells(a)}},merge:function(a){if(this.rectify())if(this.canMerge(a)){for(var b=this.idx_end.row-this.idx_start.row+1,c=this.idx_end.col-this.idx_start.col+1,e=this.idx_start.row,f=this.idx_end.row;f>=e;e++)for(var g=this.idx_start.col,h=this.idx_end.col;h>=g;g++)e==this.idx_start.row&&g==this.idx_start.col?(b>1&&this.map[e][g].el.setAttribute("rowspan",b),c>1&&this.map[e][g].el.setAttribute("colspan",c)):(/^\s* \s*$/.test(this.map[e][g].el.innerHTML.toLowerCase())||(this.map[this.idx_start.row][this.idx_start.col].el.innerHTML+=" "+this.map[e][g].el.innerHTML),d(this.map[e][g].el));this.rectify()}else window.console&&console.log("Do not know how to merge allready merged cells.")},collapseCellToNextRow:function(a){var b=this.getMapIndex(a.el),c=b.row+1,d={row:c,col:b.col};if(c=0)e(this.getRowCells(f)[h],a.el);else{var i=this.getLastNewCellOnRow(f,c);null!==i?e(i,a.el):f.insertBefore(a.el,f.firstChild)}parseInt(g.getAttribute(a.el,"rowspan"),10)>2?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)-1):a.el.removeAttribute("rowspan")}}},removeRowCell:function(a){a.isReal?a.isRowspan?this.collapseCellToNextRow(a):d(a.el):parseInt(g.getAttribute(a.el,"rowspan"),10)>2?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)-1):a.el.removeAttribute("rowspan")},getRowElementsByCell:function(){var a=[];if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=this.map[this.idx.row],c=0,d=b.length;d>c;c++)b[c].isReal&&a.push(b[c].el);return a},getColumnElementsByCell:function(){var a=[];if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=0,c=this.map.length;c>b;b++)this.map[b][this.idx.col]&&this.map[b][this.idx.col].isReal&&a.push(this.map[b][this.idx.col].el);return a},removeRow:function(){var a=g.getParentElement(this.cell,{query:"tr"});if(a){if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=this.map[this.idx.row],c=0,e=b.length;e>c;c++)b[c].modified||(this.setCellAsModified(b[c]),this.removeRowCell(b[c]));d(a)}},removeColCell:function(a){a.isColspan?parseInt(g.getAttribute(a.el,"colspan"),10)>2?a.el.setAttribute("colspan",parseInt(g.getAttribute(a.el,"colspan"),10)-1):a.el.removeAttribute("colspan"):a.isReal&&d(a.el)},removeColumn:function(){if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var a=0,b=this.map.length;b>a;a++)this.map[a][this.idx.col].modified||(this.setCellAsModified(this.map[a][this.idx.col]),this.removeColCell(this.map[a][this.idx.col]))},remove:function(a){if(this.rectify()){switch(a){case"row":this.removeRow();break;case"column":this.removeColumn()}this.rectify()}},addRow:function(a){var b=this.table.ownerDocument;if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),"below"==a&&g.getAttribute(this.cell,"rowspan")&&(this.idx.row=this.idx.row+parseInt(g.getAttribute(this.cell,"rowspan"),10)-1),this.idx!==!1){for(var c=this.map[this.idx.row],d=b.createElement("tr"),f=0,h=c.length;h>f;f++)c[f].modified||(this.setCellAsModified(c[f]),this.addRowCell(c[f],d,a));switch(a){case"below":e(this.getRealRowEl(!0),d);break;case"above":var i=g.getParentElement(this.map[this.idx.row][this.idx.col].el,{query:"tr"});i&&i.parentNode.insertBefore(d,i)}}},addRowCell:function(a,b,d){var e=a.isColspan?{colspan:g.getAttribute(a.el,"colspan")}:null;a.isReal?"above"!=d&&a.isRowspan?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)+1):b.appendChild(this.createCells("td",1,e)):"above"!=d&&a.isRowspan&&a.lastRow?b.appendChild(this.createCells("td",1,e)):c.isRowspan&&a.el.attr("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)+1)},add:function(a){this.rectify()&&(("below"==a||"above"==a)&&this.addRow(a),("before"==a||"after"==a)&&this.addColumn(a))},addColCell:function(a,b,d){
-var f,h=a.el.tagName.toLowerCase();switch(d){case"before":f=!a.isColspan||a.firstCol;break;case"after":f=!a.isColspan||a.lastCol||a.isColspan&&c.el==this.cell}if(f){switch(d){case"before":a.el.parentNode.insertBefore(this.createCells(h,1),a.el);break;case"after":e(a.el,this.createCells(h,1))}a.isRowspan&&this.handleCellAddWithRowspan(a,b+1,d)}else a.el.setAttribute("colspan",parseInt(g.getAttribute(a.el,"colspan"),10)+1)},addColumn:function(a){var b,c;if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),"after"==a&&g.getAttribute(this.cell,"colspan")&&(this.idx.col=this.idx.col+parseInt(g.getAttribute(this.cell,"colspan"),10)-1),this.idx!==!1)for(var d=0,e=this.map.length;e>d;d++)b=this.map[d],b[this.idx.col]&&(c=b[this.idx.col],c.modified||(this.setCellAsModified(c),this.addColCell(c,d,a)))},handleCellAddWithRowspan:function(a,b,c){for(var d,h,i,j=parseInt(g.getAttribute(this.cell,"rowspan"),10)-1,k=g.getParentElement(a.el,{query:"tr"}),l=a.el.tagName.toLowerCase(),m=this.table.ownerDocument,n=0;j>n;n++)if(d=this.correctColIndexForUnreals(this.idx.col,b+n),k=f(k,"tr"))if(d>0)switch(c){case"before":h=this.getRowCells(k),d>0&&this.map[b+n][this.idx.col].el!=h[d]&&d==h.length-1?e(h[d],this.createCells(l,1)):h[d].parentNode.insertBefore(this.createCells(l,1),h[d]);break;case"after":e(this.getRowCells(k)[d],this.createCells(l,1))}else k.insertBefore(this.createCells(l,1),k.firstChild);else i=m.createElement("tr"),i.appendChild(this.createCells(l,1)),this.table.appendChild(i)}},g.table={getCellsBetween:function(a,b){var c=new i(a);return c.getMapElsTo(b)},addCells:function(a,b){var c=new i(a);c.add(b)},removeCells:function(a,b){var c=new i(a);c.remove(b)},mergeCellsBetween:function(a,b){var c=new i(a);c.merge(b)},unmergeCell:function(a){var b=new i(a);b.unmerge()},orderSelectionEnds:function(a,b){var c=new i(a);return c.orderSelectionEnds(b)},indexOf:function(a){var b=new i(a);return b.setTableMap(),b.getMapIndex(a)},findCell:function(a,b){var c=new i(null,a);return c.getElementAtIndex(b)},findRowByCell:function(a){var b=new i(a);return b.getRowElementsByCell()},findColumnByCell:function(a){var b=new i(a);return b.getColumnElementsByCell()},canMerge:function(a,b){var c=new i(a);return c.canMerge(b)}}}(wysihtml5),wysihtml5.dom.query=function(a,b){var c,d=[];a.nodeType&&(a=[a]);for(var e=0,f=a.length;f>e;e++)if(c=a[e].querySelectorAll(b))for(var g=c.length;g--;d.unshift(c[g]));return d},wysihtml5.dom.compareDocumentPosition=function(){var a=document.documentElement;return a.compareDocumentPosition?function(a,b){return a.compareDocumentPosition(b)}:function(a,b){var c,d;if(c=9===a.nodeType?a:a.ownerDocument,d=9===b.nodeType?b:b.ownerDocument,a===b)return 0;if(a===b.ownerDocument)return 20;if(a.ownerDocument===b)return 10;if(c!==d)return 1;if(2===a.nodeType&&a.childNodes&&-1!==wysihtml5.lang.array(a.childNodes).indexOf(b))return 20;if(2===b.nodeType&&b.childNodes&&-1!==wysihtml5.lang.array(b.childNodes).indexOf(a))return 10;for(var e=a,f=[],g=null;e;){if(e==b)return 10;f.push(e),e=e.parentNode}for(e=b,g=null;e;){if(e==a)return 20;var h=wysihtml5.lang.array(f).indexOf(e);if(-1!==h){var i=f[h],j=wysihtml5.lang.array(i.childNodes).indexOf(f[h-1]),k=wysihtml5.lang.array(i.childNodes).indexOf(g);return j>k?2:4}g=e,e=e.parentNode}return 1}}(),wysihtml5.dom.unwrap=function(a){var b=[];if(a.parentNode){for(;a.lastChild;)b.unshift(a.lastChild),wysihtml5.dom.insert(a.lastChild).after(a);a.parentNode.removeChild(a)}return b},wysihtml5.dom.getPastedHtml=function(a){var b;return wysihtml5.browser.supportsModernPaste()&&a.clipboardData&&(wysihtml5.lang.array(a.clipboardData.types).contains("text/html")?b=a.clipboardData.getData("text/html"):wysihtml5.lang.array(a.clipboardData.types).contains("text/plain")&&(b=wysihtml5.lang.string(a.clipboardData.getData("text/plain")).escapeHTML(!0,!0))),b},wysihtml5.dom.getPastedHtmlWithDiv=function(a,b){var c=a.selection.getBookmark(),d=a.element.ownerDocument,e=d.createElement("DIV"),f=a.getScrollPos();d.body.appendChild(e),e.style.width="1px",e.style.height="1px",e.style.overflow="hidden",e.style.position="absolute",e.style.top=f.y+"px",e.style.left=f.x+"px",e.setAttribute("contenteditable","true"),e.focus(),setTimeout(function(){var d;a.selection.setBookmark(c),d=e.innerHTML,d&&/^ $/i.test(d.trim())&&(d=!1),b(d),e.parentNode.removeChild(e)},0)},wysihtml5.dom.removeInvisibleSpaces=function(a){for(var b=wysihtml5.dom.getTextNodes(a),c=b.length;c--;)b[c].nodeValue=b[c].nodeValue.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"")},wysihtml5.quirks.cleanPastedHTML=function(){var a=function(a){var b=wysihtml5.lang.string(a).trim(),c=b.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");return new RegExp("^((?!^"+c+"$).)*$","i")},b=function(b,c){var d,e,f=wysihtml5.lang.object(b).clone(!0);for(d in f.tags)if(f.tags.hasOwnProperty(d)&&f.tags[d].keep_styles)for(e in f.tags[d].keep_styles)f.tags[d].keep_styles.hasOwnProperty(e)&&c[e]&&(f.tags[d].keep_styles[e]=a(c[e]));return f},c=function(a,b){var c;if(!a)return null;for(var d=0,e=a.length;e>d;d++)if(a[d].condition||(c=a[d].set),a[d].condition&&a[d].condition.test(b))return a[d].set;return c};return function(a,d){var e,f={color:wysihtml5.dom.getStyle("color").from(d.referenceNode),fontSize:wysihtml5.dom.getStyle("font-size").from(d.referenceNode)},g=b(c(d.rules,a)||{},f);return e=wysihtml5.dom.parse(a,{rules:g,cleanUp:!0,context:d.referenceNode.ownerDocument,uneditableClass:d.uneditableClass,clearInternals:!0,unjoinNbsps:!0})}}(),wysihtml5.quirks.ensureProperClearing=function(){var a=function(){var a=this;setTimeout(function(){var b=a.innerHTML.toLowerCase();("
"==b||"
"==b)&&(a.innerHTML="")},0)};return function(b){wysihtml5.dom.observe(b.element,["cut","keydown"],a)}}(),function(a){var b="%7E";a.quirks.getCorrectInnerHTML=function(c){var d=c.innerHTML;if(-1===d.indexOf(b))return d;var e,f,g,h,i=c.querySelectorAll("[href*='~'], [src*='~']");for(h=0,g=i.length;g>h;h++)e=i[h].href||i[h].src,f=a.lang.string(e).replace("~").by(b),d=a.lang.string(d).replace(f).by(e);return d}}(wysihtml5),function(a){var b="wysihtml5-quirks-redraw";a.quirks.redraw=function(c){a.dom.addClass(c,b),a.dom.removeClass(c,b);try{var d=c.ownerDocument;d.execCommand("italic",!1,null),d.execCommand("italic",!1,null)}catch(e){}}}(wysihtml5),wysihtml5.quirks.tableCellsSelection=function(a,b){function c(){return a.addEventListener("mousedown",n),l}function d(c){l.start=c,l.end=c,l.cells=[c],l.table=k.getParentElement(l.start,{query:"table"},!1,a),l.table&&(e(),k.addClass(c,m),a.addEventListener("mousemove",g),a.addEventListener("mouseup",h),b.fire("tableselectstart").fire("tableselectstart:composer"))}function e(){if(a){var b=a.querySelectorAll("."+m);if(b.length>0)for(var c=0;c1&&b.composer.selection.deselect(),f(l.cells),l.end!==d&&b.fire("tableselectchange").fire("tableselectchange:composer")))}function h(c){a.removeEventListener("mousemove",g),a.removeEventListener("mouseup",h),b.fire("tableselect").fire("tableselect:composer"),setTimeout(function(){i()},0)}function i(){a.ownerDocument.addEventListener("click",o)}function j(c,d){l.start=c,l.end=d,l.table=k.getParentElement(l.start,{query:"table"},!1,a),selectedCells=k.table.getCellsBetween(l.start,l.end),f(selectedCells),i(),b.fire("tableselect").fire("tableselect:composer")}var k=wysihtml5.dom,l={table:null,start:null,end:null,cells:null,select:j},m="wysiwyg-tmp-selected-cell",n=function(b){var c=wysihtml5.dom.getParentElement(b.target,{query:"td, th"},!1,a);c&&d(c)},o=function(c){a.ownerDocument.removeEventListener("click",o),k.getParentElement(c.target,{query:"table"},!1,a)!=l.table&&(e(),l.table=null,l.start=null,l.end=null,b.fire("tableunselect").fire("tableunselect:composer"))};return c()},function(a){function b(a){var b,c;for(b in d)if(d.hasOwnProperty(b)&&(c=d[b],c.regex.test(a)))return c}function c(a){var c=b(a);return c?c.name:void 0}var d={rgba:{regex:/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d\.]+)\s*\)/i,name:"rgba"},rgb:{regex:/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i,name:"rgb"},hex6:{regex:/^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/i,name:"hex",radix:16},hex3:{regex:/^#([0-9a-f])([0-9a-f])([0-9a-f])/i,name:"hex",radix:16}},e=function(a){return new RegExp("(^|\\s|;)"+a+"\\s*:\\s*[^;$]+","gi")};a.quirks.styleParser={getColorParseMethod:b,getColorFormat:c,parseColor:function(c,f){var g,h,i,j,k,l=c;if(f){if(g=e(f),!(h=c.match(g)))return!1;h=h.pop().split(":")[1],l=a.lang.string(h).trim()}return(i=b(l))&&(j=l.match(i.regex))?(k=i.radix||10,i===d.hex3?(j.shift(),j.push(1),a.lang.array(j).map(function(a,b){return 3>b?parseInt(a,k)*k+parseInt(a,k):parseFloat(a)})):(j.shift(),j[3]||j.push(1),a.lang.array(j).map(function(a,b){return 3>b?parseInt(a,k):parseFloat(a)}))):!1},unparseColor:function(a,b){var c=16;return"hex"===b?(a[0].toString(c)+a[1].toString(c)+a[2].toString(c)).toUpperCase():"hash"===b?"#"+(a[0].toString(c)+a[1].toString(c)+a[2].toString(c)).toUpperCase():"rgb"===b?"rgb("+a[0]+","+a[1]+","+a[2]+")":"rgba"===b?"rgba("+a[0]+","+a[1]+","+a[2]+","+a[3]+")":"csv"===b?a[0]+","+a[1]+","+a[2]+","+a[3]:a[3]&&1!==a[3]?"rgba("+a[0]+","+a[1]+","+a[2]+","+a[3]+")":"rgb("+a[0]+","+a[1]+","+a[2]+")"},parseFontSize:function(b){var c=b.match(e("font-size"));return c?a.lang.string(c[c.length-1].split(":")[1]).trim():!1}}}(wysihtml5),function(a){function b(a){var b=0;if(a.parentNode)do b+=a.offsetTop||0,a=a.offsetParent;while(a);return b}function c(a,b){for(var c=0;b!==a;)if(c++,b=b.parentNode,!b)throw new Error("not a descendant of ancestor!");return c}function d(a,b){return 3===a.nodeType?a:a.childNodes[b]||a}function e(b){var c=document.createElement("span"),d=function(a){b.removeEventListener("mouseup",d),b.removeEventListener("keydown",d),b.removeEventListener("touchstart",d),b.removeEventListener("focus",d),b.removeEventListener("blur",d),b.removeEventListener("paste",e),b.removeEventListener("drop",e),b.removeEventListener("beforepaste",e),c&&c.parentNode&&c.parentNode.removeChild(c)},e=function(a){c&&c.parentNode&&setTimeout(d,0)};return c.appendChild(b.ownerDocument.createTextNode(a.INVISIBLE_SPACE)),c.className="_wysihtml5-temp-caret-fix",c.style.display="block",c.style.minWidth="1px",c.style.height="0px",b.addEventListener("mouseup",d),b.addEventListener("keydown",d),b.addEventListener("touchstart",d),b.addEventListener("focus",d),b.addEventListener("blur",d),b.addEventListener("paste",e),b.addEventListener("drop",e),b.addEventListener("beforepaste",e),c}function f(a){if(!a.canSurroundContents())for(var b=a.commonAncestorContainer,d=c(b,a.startContainer),e=c(b,a.endContainer);!a.canSurroundContents();)d>e?(a.setStartBefore(a.startContainer),d=c(b,a.startContainer)):(a.setEndAfter(a.endContainer),e=c(b,a.endContainer))}var g=a.dom;a.Selection=Base.extend({constructor:function(a,b,c){rangy.init(),this.editor=a,this.composer=a.composer,this.doc=this.composer.doc,this.win=this.composer.win,this.contain=b,this.unselectableClass=c||!1},getBookmark:function(){var a=this.getRange();return a&&a.cloneRange()},setBookmark:function(a){a&&this.setSelection(a)},setBefore:function(a){var b=rangy.createRange(this.doc);return b.setStartBefore(a),b.setEndBefore(a),this.setSelection(b)},createTemporaryCaretSpaceAfter:function(b){var c=this.doc.createElement("span"),d=this.doc.createTextNode(a.INVISIBLE_SPACE),e=function(b){var d;this.contain.removeEventListener("mouseup",e),this.contain.removeEventListener("keydown",g),this.contain.removeEventListener("touchstart",e),this.contain.removeEventListener("focus",e),this.contain.removeEventListener("blur",e),this.contain.removeEventListener("paste",f),this.contain.removeEventListener("drop",f),this.contain.removeEventListener("beforepaste",f),c&&c.parentNode&&(c.innerHTML=c.innerHTML.replace(a.INVISIBLE_SPACE_REG_EXP,""),/[^\s]+/.test(c.innerHTML)?(d=c.lastChild,a.dom.unwrap(c),this.setAfter(d)):c.parentNode.removeChild(c))}.bind(this),f=function(a){c&&c.parentNode&&setTimeout(e,0)},g=function(a){8===a.which||91===a.which||17===a.which||86===a.which&&(a.ctrlKey||a.metaKey)||e()};return c.className="_wysihtml5-temp-caret-fix",c.style.position="absolute",c.style.display="block",c.style.minWidth="1px",c.style.zIndex="99999",c.appendChild(d),b.parentNode.insertBefore(c,b.nextSibling),this.setBefore(d),this.contain.addEventListener("mouseup",e),this.contain.addEventListener("keydown",g),this.contain.addEventListener("touchstart",e),this.contain.addEventListener("focus",e),this.contain.addEventListener("blur",e),this.contain.addEventListener("paste",f),this.contain.addEventListener("drop",f),this.contain.addEventListener("beforepaste",f),c},setAfter:function(b,c,d){var e,f=this.win,g=rangy.createRange(this.doc),h=function(){var d=b.parentNode,g=d?d.childNodes[d.childNodes.length-1]:null;if(!e||g===b&&1===b.nodeType&&"block"===f.getComputedStyle(b).display)if(c){var h=this.doc.createTextNode(a.INVISIBLE_SPACE);b.parentNode.insertBefore(h,b.nextSibling),this.selectNode(h),setTimeout(function(){h&&h.parentNode&&h.parentNode.removeChild(h)},0)}else this.createTemporaryCaretSpaceAfter(b)}.bind(this);if(g.setStartAfter(b),g.setEndAfter(b),document.activeElement&&document.activeElement===this.composer.element)e=this.setSelection(g),h(),d&&d(e);else{var i=this.composer.getScrollPos();this.composer.element.focus(),this.composer.setScrollPos(i),setTimeout(function(){e=this.setSelection(g),h(),d&&d(e)}.bind(this),0)}},selectNode:function(b,c){var d=rangy.createRange(this.doc),e=b.nodeType===a.ELEMENT_NODE,f="canHaveHTML"in b?b.canHaveHTML:"IMG"!==b.nodeName,h=e?b.innerHTML:b.data,i=""===h||h===a.INVISIBLE_SPACE,j=g.getStyle("display").from(b),k="block"===j||"list-item"===j;if(i&&e&&f&&!c)try{b.innerHTML=a.INVISIBLE_SPACE}catch(l){}f?d.selectNodeContents(b):d.selectNode(b),f&&i&&e?d.collapse(k):f&&i&&(d.setStartAfter(b),d.setEndAfter(b)),this.setSelection(d)},getSelectedNode:function(a){var b,c;return a&&this.doc.selection&&"Control"===this.doc.selection.type&&(c=this.doc.selection.createRange(),c&&c.length)?c.item(0):(b=this.getSelection(this.doc),b.focusNode===b.anchorNode?b.focusNode:(c=this.getRange(this.doc),c?c.commonAncestorContainer:this.doc.body))},fixSelBorders:function(){var a=this.getRange();f(a),this.setSelection(a)},getSelectedOwnNodes:function(a){for(var b=this.getOwnRanges(),c=[],d=0,e=b.length;e>d;d++)c.push(b[d].commonAncestorContainer||this.doc.body);return c},findNodesInSelection:function(b){for(var c,d=this.getOwnRanges(),e=[],f=0,g=d.length;g>f;f++)c=d[f].getNodes([1],function(c){return a.lang.array(b).contains(c.nodeName)}),e=e.concat(c);return e},filterElements:function(a){for(var b,c=this.getOwnRanges(),d=[],e=0,f=c.length;f>e;e++)b=c[e].getNodes([1],function(b){return a(b,c[e])}),d=d.concat(b);return d},containsUneditable:function(){for(var a=this.getOwnUneditables(),b=this.getSelection(),c=0,d=a.length;d>c;c++)if(b.containsNode(a[c]))return!0;return!1},deleteContents:function(){var a=this.getRange();this.deleteRangeContents(a),this.setSelection(a)},deleteRangeContents:function(b){var c,d,e,f;if(this.unselectableClass){(c=a.dom.getParentElement(b.startContainer,{query:"."+this.unselectableClass},!1,this.contain))&&b.setStartBefore(c),(d=a.dom.getParentElement(b.endContainer,{query:"."+this.unselectableClass},!1,this.contain))&&b.setEndAfter(d),e=b.getNodes([1],function(b){return a.dom.hasClass(b,this.unselectableClass)}.bind(this));for(var g=e.length;g--;)try{f=new CustomEvent("wysihtml5:uneditable:delete"),e[g].dispatchEvent(f)}catch(h){}}b.deleteContents()},getCaretNode:function(){var a=this.getSelection();return a&&a.anchorNode?d(a.anchorNode,a.anchorOffset):null},getPreviousNode:function(b,c){var e;if(!b){var f=this.getSelection();b=f&&f.anchorNode?d(f.anchorNode,f.anchorOffset):null}if(b===this.contain)return!1;var g,h=b.previousSibling;return h===this.contain?!1:(h&&3!==h.nodeType&&1!==h.nodeType?h=this.getPreviousNode(h,c):h&&3===h.nodeType&&/^\s*$/.test(h.textContent)?h=this.getPreviousNode(h,c):c&&h&&1===h.nodeType?(e=a.dom.getStyle("display").from(h),a.lang.array(["BR","HR","IMG"]).contains(h.nodeName)||a.lang.array(["block","inline-block","flex","list-item","table"]).contains(e)||!/^[\s]*$/.test(h.innerHTML)||(h=this.getPreviousNode(h,c))):h||b===this.contain||(g=b.parentNode,g!==this.contain&&(h=this.getPreviousNode(g,c))),h!==this.contain?h:!1)},getNodesNearCaret:function(){if(!this.isCollapsed())throw"Selection must be caret when using selection.getNodesNearCaret()";var a,b,c,d,e=this.getOwnRanges();return e&&e.length>0?(1===e[0].startContainer.nodeType?(a=e[0].startContainer.childNodes[e[0].startOffset-1],a||0!==e[0].startOffset?a&&(b=a.previousSibling,c=a.nextSibling):c=e[0].startContainer.childNodes[0]):(0===e[0].startOffset&&e[0].startContainer.previousSibling?(a=e[0].startContainer.previousSibling,3===a.nodeType&&(d=a.data.length)):(a=e[0].startContainer,d=e[0].startOffset),b=a.previousSibling,c=a.nextSibling),{caretNode:a,prevNode:b,nextNode:c,textOffset:d}):null},getSelectionParentsByTag:function(b){for(var c,d=this.getSelectedOwnNodes(),e=[],f=0,g=d.length;g>f;f++)c=d[f].nodeName&&"LI"===d[f].nodeName?d[f]:a.dom.getParentElement(d[f],{query:"li"},!1,this.contain),c&&e.push(c);return e.length?e:null},getRangeToNodeEnd:function(){if(this.isCollapsed()){var a=this.getRange(),b=a.startContainer,c=a.startOffset,d=rangy.createRange(this.doc);return d.selectNodeContents(b),d.setStart(b,c),d}},caretIsLastInSelection:function(){var a=(rangy.createRange(this.doc),this.getSelection(),this.getRangeToNodeEnd().cloneContents()),b=a.textContent;return/^\s*$/.test(b)},caretIsFirstInSelection:function(b){var c=rangy.createRange(this.doc),e=this.getSelection(),f=this.getRange(),g=d(f.startContainer,f.startOffset);if(g){if(g.nodeType===a.TEXT_NODE){if(!g.parentNode)return!1;if(!this.isCollapsed()||g.parentNode.firstChild!==g&&!a.dom.domNode(g.previousSibling).is.block())return!1;var h=this.win.getComputedStyle(g.parentNode).whiteSpace;return"pre"===h||"pre-wrap"===h?0===f.startOffset:/^\s*$/.test(g.data.substr(0,f.startOffset))}return b&&a.dom.domNode(g).is.lineBreak()?!0:(c.selectNodeContents(this.getRange().commonAncestorContainer),c.collapse(!0),this.isCollapsed()&&(c.startContainer===e.anchorNode||c.endContainer===e.anchorNode)&&c.startOffset===e.anchorOffset)}},caretIsInTheBeginnig:function(b){var c=this.getSelection(),d=c.anchorNode,e=c.anchorOffset;return b&&d?0===e&&(d.nodeName&&d.nodeName===b.toUpperCase()||a.dom.getParentElement(d.parentNode,{query:b},1)):d?0===e&&!this.getPreviousNode(d,!0):void 0},getBeforeSelection:function(b){var c,d,e=this.getSelection(),f=e.isBackwards()?e.focusNode:e.anchorNode,g=e.isBackwards()?e.focusOffset:e.anchorOffset,h=this.createRange();if(f&&3===f.nodeType&&/^\s*$/.test(f.data.slice(0,g))&&(g=0),d=a.dom.getParentElement(f,{query:"._wysihtml5-temp-caret-fix"},1),d&&(f=d.parentNode,g=Array.prototype.indexOf.call(f.childNodes,d)),f){if(g>0)return 3===f.nodeType?(h.setStart(f,0),h.setEnd(f,g),{type:"text",range:h,offset:g,node:f}):(h.setStartBefore(f.childNodes[0]),c=f.childNodes[g-1],h.setEndAfter(c),{type:"element",range:h,offset:g,node:c});if(h.setStartAndEnd(f,0),b){var i=this.getPreviousNode(f,!0),j=null;if(i&&(j=1===i.nodeType&&a.dom.hasClass(i,this.unselectableClass)?i:a.dom.domNode(i).lastLeafNode()),j)return{type:"leafnode",range:h,offset:g,node:j}}return{type:"none",range:h,offset:g,node:f}}return null},executeAndRestoreRangy:function(a,b){var c=rangy.saveSelection(this.win);if(c)try{a()}catch(d){setTimeout(function(){throw d},0)}else a();rangy.restoreSelection(c)},executeAndRestore:function(b,c){var d,e,f,h,i,j,k,l,m=this.doc.body,n=c&&m.scrollTop,o=c&&m.scrollLeft,p="_wysihtml5-temp-placeholder",q=''+a.INVISIBLE_SPACE+" ",r=this.getRange(!0);if(!r)return void b(m,m);r.collapsed||(k=r.cloneRange(),j=k.createContextualFragment(q),k.collapse(!1),k.insertNode(j),k.detach()),i=r.createContextualFragment(q),r.insertNode(i),j&&(d=this.contain.querySelectorAll("."+p),r.setStartBefore(d[0]),r.setEndAfter(d[d.length-1])),this.setSelection(r);try{b(r.startContainer,r.endContainer)}catch(s){setTimeout(function(){throw s},0)}if(d=this.contain.querySelectorAll("."+p),d&&d.length){l=rangy.createRange(this.doc),f=d[0].nextSibling,d.length>1&&(h=d[d.length-1].previousSibling),h&&f?(l.setStartBefore(f),l.setEndAfter(h)):(e=this.doc.createTextNode(a.INVISIBLE_SPACE),g.insert(e).after(d[0]),l.setStartBefore(e),l.setEndAfter(e)),this.setSelection(l);for(var t=d.length;t--;)d[t].parentNode.removeChild(d[t])}else this.contain.focus();c&&(m.scrollTop=n,m.scrollLeft=o);try{d.parentNode.removeChild(d)}catch(u){}},set:function(a,b){var c=rangy.createRange(this.doc);c.setStart(a,b||0),this.setSelection(c)},insertHTML:function(a){var b,c,d=this.getRange(),e=this.doc.createElement("DIV"),f=this.doc.createDocumentFragment();if(d){for(d.deleteContents(),e.innerHTML=a,b=e.lastChild;e.firstChild;)f.appendChild(e.firstChild);for(d.insertNode(f),c=this.contain.lastChild;c&&3===c.nodeType&&c.previousSibling&&/^\s*$/.test(c.data);)c=c.previousSibling;b&&(c&&b===c&&1===b.nodeType&&this.contain.appendChild(this.doc.createElement("br")),this.setAfter(b))}},insertNode:function(a){var b=this.getRange();b&&b.insertNode(a)},canAppendChild:function(a){var b,c,d=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],e=this.getRange();return b=a||e.startContainer,b&&(c=(b.tagName||b.nodeName).toLowerCase()),-1===d.indexOf(c)},splitElementAtCaret:function(b,c){var d,e,f,g,h,i=this.getSelection();if(i.rangeCount>0){d=i.getRangeAt(0).cloneRange(),d.setEndAfter(b),e=d.extractContents(),h=e.childNodes;for(var j=h.length;j--;)a.dom.domNode(h[j]).is.visible()||e.removeChild(h[j]);b.parentNode.insertBefore(e,b.nextSibling),c?(f=c.firstChild||c,g=c.lastChild||c,b.parentNode.insertBefore(c,b.nextSibling),f&&g&&(d.setStartBefore(f),d.setEndAfter(g),this.setSelection(d))):(d.setStartAfter(b),d.setEndAfter(b)),a.dom.domNode(b).is.visible()||(""===a.dom.getTextContent(b)?b.parentNode.removeChild(b):b.parentNode.replaceChild(this.doc.createTextNode(" "),b))}},surround:function(a){var b,c=this.getOwnRanges(),d=[];if(0==c.length)return d;for(var e=c.length;e--;){b=this.doc.createElement(a.nodeName),d.push(b),a.className&&(b.className=a.className),a.cssStyle&&b.setAttribute("style",a.cssStyle);try{c[e].surroundContents(b),this.selectNode(b)}catch(f){b.appendChild(c[e].extractContents()),c[e].insertNode(b)}}return d},scrollIntoView:function(){var c,d=this.doc,e=5,f=d.documentElement.scrollHeight>d.documentElement.offsetHeight,g=d._wysihtml5ScrollIntoViewElement=d._wysihtml5ScrollIntoViewElement||function(){var b=d.createElement("span");return b.innerHTML=a.INVISIBLE_SPACE,b}();f&&(this.insertNode(g),c=b(g),g.parentNode.removeChild(g),c>=d.body.scrollTop+d.documentElement.offsetHeight-e&&(d.body.scrollTop=c))},selectLine:function(){var b=rangy.createRange();a.browser.supportsSelectionModify()?this._selectLine_W3C():b.nativeRange&&b.nativeRange.getBoundingClientRect&&this._selectLineUniversal()},includeRangyRangeHelpers:function(){var a=this.getSelection(),b=a.getRangeAt(0),c=function(a){return a&&1===a.nodeType&&a.classList.contains("rangySelectionBoundary")},d=function(a){return 1===a.nodeType?a.childNodes&&a.childNodes.length||0:a.data&&a.data.length||0},e=1===a.anchorNode.nodeType?a.anchorNode.childNodes[a.anchorOffset]:a.anchorNode,f=1===a.focusNode.nodeType?a.focusNode.childNodes[a.focusOffset]:a.focusNode;f&&a.focusOffset===d(f)&&f.nextSibling&&c(f.nextSibling)&&b.setEndAfter(f.nextSibling),e&&0===a.anchorOffset&&e.previousSibling&&c(e.previousSibling)&&b.setStartBefore(e.previousSibling),b.select()},_selectLine_W3C:function(){var a=this.win.getSelection(),b=[a.anchorNode,a.anchorOffset,a.focusNode,a.focusOffset];a.modify("move","left","lineboundary"),a.modify("extend","right","lineboundary"),a.anchorNode===b[0]&&a.anchorOffset===b[1]&&a.focusNode===b[2]&&a.focusOffset===b[3]?this._selectLineUniversal():this.includeRangyRangeHelpers()},toLineBoundary:function(b,c){if(c="undefined"==typeof c?!1:c,a.browser.supportsSelectionModify()){var d=this.win.getSelection();d.modify("extend",b,"lineboundary"),c&&("left"===b?d.collapseToStart():"right"===b&&d.collapseToEnd())}},getRangeRect:function(a){var b,c=(this.doc.createTextNode("i"),this.doc.createTextNode("i"));return a.collapsed?(a.insertNode(c),a.selectNode(c),b=a.nativeRange.getBoundingClientRect(),a.deleteContents()):b=a.nativeRange.getBoundingClientRect(),b},_selectLineUniversal:function(){var b,c,d,e,f,g,h=this.getSelection(),i=h.getRangeAt(0),j=0,k=this,l=function(b){return b&&1===b.nodeType&&("block"===k.win.getComputedStyle(b).display||a.lang.array(["BR","HR"]).contains(b.nodeName))},m=function(a){var b=a;if(b)for(;b&&(1===b.nodeType&&b.classList.contains("rangySelectionBoundary")||3===b.nodeType&&/^\s*$/.test(b.data));)b=b.previousSibling;return b};c=i.cloneRange(),d=i.cloneRange(),i.collapsed&&(3===i.startContainer.nodeType&&i.startOffset0?i.moveEnd("character",1):i.startOffset>0&&(3===i.startContainer.nodeType||1===i.startContainer.nodeType&&!l(m(i.startContainer.childNodes[i.startOffset-1])))&&i.moveStart("character",-1)),i.collapsed||i.insertNode(this.doc.createTextNode(a.INVISIBLE_SPACE)),b=i.nativeRange.getBoundingClientRect();do e=i.moveStart("character",-1),f=i.nativeRange.getBoundingClientRect(),f&&Math.floor(f.top)===Math.floor(b.top)||(i.moveStart("character",1),g=!0),j++;while(0!==e&&!g&&2e3>j);if(j=0,g=!1,b=i.nativeRange.getBoundingClientRect(),i.endContainer!==this.contain||this.contain.lastChild&&this.contain.childNodes[i.endOffset]!==this.contain.lastChild)do e=i.moveEnd("character",1),f=i.nativeRange.getBoundingClientRect(),f&&Math.floor(f.bottom)===Math.floor(b.bottom)||(i.moveEnd("character",-1),i.endContainer&&1===i.endContainer.nodeType&&i.endContainer.childNodes[i.endOffset]&&1===i.endContainer.childNodes[i.endOffset].nodeType&&"BR"===i.endContainer.childNodes[i.endOffset].nodeName&&i.endContainer.childNodes[i.endOffset].previousSibling&&(1===i.endContainer.childNodes[i.endOffset].previousSibling.nodeType?i.setEnd(i.endContainer.childNodes[i.endOffset].previousSibling,i.endContainer.childNodes[i.endOffset].previousSibling.childNodes.length):3===i.endContainer.childNodes[i.endOffset].previousSibling.nodeType&&i.setEnd(i.endContainer.childNodes[i.endOffset].previousSibling,i.endContainer.childNodes[i.endOffset].previousSibling.data.length)),g=!0),j++;while(0!==e&&!g&&2e3>j);i.select(),this.includeRangyRangeHelpers()},getText:function(){var a=this.getSelection();return a?a.toString():""},getNodes:function(a,b){var c=this.getRange();return c?c.getNodes(Array.isArray(a)?a:[a],b):[]},getOwnNodes:function(a,b,c){for(var d=this.getOwnRanges(),e=[],f=0,g=d.length;g>f;f++)d[f]&&(c&&d[f].splitBoundaries(),e=e.concat(d[f].getNodes(Array.isArray(a)?a:[a],b)));return e},fixRangeOverflow:function(a){if(this.contain&&this.contain.firstChild&&a){var b=a.compareNode(this.contain);if(2!==b)1===b&&a.setStartBefore(this.contain.firstChild),0===b&&a.setEndAfter(this.contain.lastChild),3===b&&(a.setStartBefore(this.contain.firstChild),a.setEndAfter(this.contain.lastChild));else if(this._detectInlineRangeProblems(a)){var c=a.endContainer.previousElementSibling;c&&a.setEnd(c,this._endOffsetForNode(c))}}},_endOffsetForNode:function(a){var b=document.createRange();return b.selectNodeContents(a),b.endOffset},_detectInlineRangeProblems:function(a){var b=g.compareDocumentPosition(a.startContainer,a.endContainer);return 0==a.endOffset&&4&b},getRange:function(a){var b=this.getSelection(),c=b&&b.rangeCount&&b.getRangeAt(0);return a!==!0&&this.fixRangeOverflow(c),c},getOwnUneditables:function(){var b=g.query(this.contain,"."+this.unselectableClass),c=g.query(b,"."+this.unselectableClass);return a.lang.array(b).without(c)},getOwnRanges:function(){var a,b=[],c=this.getRange();if(c&&b.push(c),this.unselectableClass&&this.contain&&c){var d,e=this.getOwnUneditables();if(e.length>0)for(var f=0,g=e.length;g>f;f++){a=[];for(var h=0,i=b.length;i>h;h++){if(b[h])switch(b[h].compareNode(e[f])){case 2:break;case 3:d=b[h].cloneRange(),d.setEndBefore(e[f]),a.push(d),d=b[h].cloneRange(),d.setStartAfter(e[f]),a.push(d);break;default:a.push(b[h])}b=a}}}return b},getSelection:function(){return rangy.getSelection(this.win)},setSelection:function(a){var b=rangy.getSelection(this.win);return b.setSingleRange(a),b&&b.anchorNode&&b.focusNode?b:null},selectAll:function(){var b,c=this.createRange(),d=this.composer,f=this,g=e(this.composer.element),h=e(this.composer.element),i=function(){c.setStart(d.element,0),c.setEnd(d.element,d.element.childNodes.length),b=f.setSelection(c)},j=function(){return!b||b.nativeSelection&&b.nativeSelection.type&&("Caret"===b.nativeSelection.type||"None"===b.nativeSelection.type)};a.dom.removeInvisibleSpaces(this.composer.element),i(),this.composer.element.firstChild&&j()&&(this.composer.element.appendChild(g),i(),j()&&(g.parentNode.removeChild(g),this.composer.element.insertBefore(h,this.composer.element.firstChild),i(),j()&&(this.composer.element.appendChild(g),i())))},createRange:function(){return rangy.createRange(this.doc)},isCollapsed:function(){return this.getSelection().isCollapsed},getHtml:function(){return this.getSelection().toHtml()},getPlainText:function(){return this.getSelection().toString()},isEndToEndInNode:function(b){var c=this.getRange(),d=c.commonAncestorContainer,e=c.startContainer,f=c.endContainer;if(d.nodeType===a.TEXT_NODE&&(d=d.parentNode),e.nodeType===a.TEXT_NODE&&!/^\s*$/.test(e.data.substr(c.startOffset)))return!1;if(f.nodeType===a.TEXT_NODE&&!/^\s*$/.test(f.data.substr(c.endOffset)))return!1;for(;e&&e!==d;){if(e.nodeType!==a.TEXT_NODE&&!a.dom.contains(d,e))return!1;if(a.dom.domNode(e).prev({ignoreBlankTexts:!0}))return!1;e=e.parentNode}for(;f&&f!==d;){if(f.nodeType!==a.TEXT_NODE&&!a.dom.contains(d,f))return!1;if(a.dom.domNode(f).next({ignoreBlankTexts:!0}))return!1;f=f.parentNode}return a.lang.array(b).contains(d.nodeName)?d:!1},isInThisEditable:function(){var b=this.getSelection(),c=b.focusNode,d=b.anchorNode;return c&&1!==c.nodeType&&(c=c.parentNode),d&&1!==d.nodeType&&(d=d.parentNode),d&&c&&(a.dom.contains(this.composer.element,c)||this.composer.element===c)&&(a.dom.contains(this.composer.element,d)||this.composer.element===d)},deselect:function(){var a=this.getSelection();a&&a.removeAllRanges()}})}(wysihtml5),function(a,b){function c(a,b,c){if(!a.className)return!1;var d=a.className.match(c)||[];return d[d.length-1]===b}function d(a,b){if(!a.getAttribute||!a.getAttribute("style"))return!1;a.getAttribute("style").match(b);return a.getAttribute("style").match(b)?!0:!1}function e(a,b,c){a.getAttribute("style")?(h(a,c),a.getAttribute("style")&&!/^\s*$/.test(a.getAttribute("style"))?a.setAttribute("style",b+";"+a.getAttribute("style")):a.setAttribute("style",b)):a.setAttribute("style",b)}function f(a,b,c){a.className?(g(a,c),a.className+=" "+b):a.className=b}function g(a,b){a.className&&(a.className=a.className.replace(b,""))}function h(a,b){var c,d=[];if(a.getAttribute("style")){c=a.getAttribute("style").split(";");for(var e=c.length;e--;)c[e].match(b)||/^\s*$/.test(c[e])||d.push(c[e]);d.length?a.setAttribute("style",d.join(";")):a.removeAttribute("style")}}function i(a,b){var c=[],d=b.split(";"),e=a.getAttribute("style");if(e){e=e.replace(/\s/gi,"").toLowerCase(),
-c.push(new RegExp("(^|\\s|;)"+b.replace(/\s/gi,"").replace(/([\(\)])/gi,"\\$1").toLowerCase().replace(";",";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi,"\\s?rgb\\($1,\\s?$2,\\s?$3\\)"),"gi"));for(var f=d.length;f-->0;)/^\s*$/.test(d[f])||c.push(new RegExp("(^|\\s|;)"+d[f].replace(/\s/gi,"").replace(/([\(\)])/gi,"\\$1").toLowerCase().replace(";",";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi,"\\s?rgb\\($1,\\s?$2,\\s?$3\\)"),"gi"));for(var g=0,h=c.length;h>g;g++)if(e.match(c[g]))return c[g]}return!1}function j(c,d,e,f){return e?i(c,e):f?a.dom.hasClass(c,f):b.dom.arrayContains(d,c.tagName.toLowerCase())}function k(a,b,c,d){for(var e=a.length;e--;)if(!j(a[e],b,c,d))return!1;return a.length?!0:!1}function l(a,b,c){var d=i(a,b);return d?(h(a,d),"remove"):(e(a,b,c),"change")}function m(a,b){return a.className.replace(u," ")==b.className.replace(u," ")}function n(a){for(var b=a.parentNode;a.firstChild;)b.insertBefore(a.firstChild,a);b.removeChild(a)}function o(a,b){if(a.attributes.length!=b.attributes.length)return!1;for(var c,d,e,f=0,g=a.attributes.length;g>f;++f)if(c=a.attributes[f],e=c.name,"class"!=e){if(d=b.attributes.getNamedItem(e),c.specified!=d.specified)return!1;if(c.specified&&c.nodeValue!==d.nodeValue)return!1}return!0}function p(a,c){return b.dom.isCharacterDataNode(a)?0==c?!!a.previousSibling:c==a.length?!!a.nextSibling:!0:c>0&&ce;++e)a=this.textNodes[e],b=a.parentNode,d[e]=a.data,e&&(b.removeChild(a),b.hasChildNodes()||b.parentNode.removeChild(b));return this.firstTextNode.data=c=d.join(""),c},getLength:function(){for(var a=this.textNodes.length,b=0;a--;)b+=this.textNodes[a].length;return b},toString:function(){for(var a=[],b=0,c=this.textNodes.length;c>b;++b)a[b]="'"+this.textNodes[b].data+"'";return"[Merge("+a.join(",")+")]"}},s.prototype={getAncestorWithClass:function(d){for(var e;d;){if(e=this.cssClass?c(d,this.cssClass,this.similarClassRegExp):""!==this.cssStyle?!1:!0,d.nodeType==a.ELEMENT_NODE&&"false"!=d.getAttribute("contenteditable")&&b.dom.arrayContains(this.tagNames,d.tagName.toLowerCase())&&e)return d;d=d.parentNode}return!1},getAncestorWithStyle:function(c){for(var e;c;){if(e=this.cssStyle?d(c,this.similarStyleRegExp):!1,c.nodeType==a.ELEMENT_NODE&&"false"!=c.getAttribute("contenteditable")&&b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase())&&e)return c;c=c.parentNode}return!1},getMatchingAncestor:function(a){var b=this.getAncestorWithClass(a),c=!1;return b?this.cssStyle&&(c="class"):(b=this.getAncestorWithStyle(a),b&&(c="style")),{element:b,type:c}},postApply:function(a,b){for(var c,d,e,f=a[0],g=a[a.length-1],h=[],i=f,j=g,k=0,l=g.length,m=0,n=a.length;n>m;++m)d=a[m],e=null,d&&d.parentNode&&(e=this.getAdjacentMergeableTextNode(d.parentNode,!1)),e?(c||(c=new r(e),h.push(c)),c.textNodes.push(d),d===f&&(i=c.firstTextNode,k=i.length),d===g&&(j=c.firstTextNode,l=c.getLength())):c=null;if(g&&g.parentNode){var o=this.getAdjacentMergeableTextNode(g.parentNode,!0);o&&(c||(c=new r(g),h.push(c)),c.textNodes.push(o))}if(h.length){for(m=0,n=h.length;n>m;++m)h[m].doMerge();b.setStart(i,k),b.setEnd(j,l)}},getAdjacentMergeableTextNode:function(b,c){var d,e=b.nodeType==a.TEXT_NODE,f=e?b.parentNode:b,g=c?"nextSibling":"previousSibling";if(e){if(d=b[g],d&&d.nodeType==a.TEXT_NODE)return d}else if(d=f[g],d&&this.areElementsMergeable(b,d))return d[c?"firstChild":"lastChild"];return null},areElementsMergeable:function(a,c){return b.dom.arrayContains(this.tagNames,(a.tagName||"").toLowerCase())&&b.dom.arrayContains(this.tagNames,(c.tagName||"").toLowerCase())&&m(a,c)&&o(a,c)},createContainer:function(a){var b=a.createElement(this.tagNames[0]);return this.cssClass&&(b.className=this.cssClass),this.cssStyle&&b.setAttribute("style",this.cssStyle),b},applyToTextNode:function(a){var c=a.parentNode;if(1==c.childNodes.length&&b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase()))this.cssClass&&f(c,this.cssClass,this.similarClassRegExp),this.cssStyle&&e(c,this.cssStyle,this.similarStyleRegExp);else{var d=this.createContainer(b.dom.getDocument(a));a.parentNode.insertBefore(d,a),d.appendChild(a)}},isRemovable:function(c){return b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase())&&""===a.lang.string(c.className).trim()&&(!c.getAttribute("style")||""===a.lang.string(c.getAttribute("style")).trim())},undoToTextNode:function(a,b,c,d){var e=c?!1:!0,f=c||d,h=!1;if(!b.containsNode(f)){var i=b.cloneRange();i.selectNode(f),i.isPointInRange(b.endContainer,b.endOffset)&&p(b.endContainer,b.endOffset)&&(q(f,b.endContainer,b.endOffset,this.container),b.setEndAfter(f)),i.isPointInRange(b.startContainer,b.startOffset)&&p(b.startContainer,b.startOffset)&&(f=q(f,b.startContainer,b.startOffset,this.container))}!e&&this.similarClassRegExp&&g(f,this.similarClassRegExp),e&&this.similarStyleRegExp&&(h="change"===l(f,this.cssStyle,this.similarStyleRegExp)),this.isRemovable(f)&&!h&&n(f)},applyToRange:function(b){for(var c,d=b.length;d--;){if(c=b[d].getNodes([a.TEXT_NODE]),!c.length)try{var e=this.createContainer(b[d].endContainer.ownerDocument);return b[d].surroundContents(e),void this.selectNode(b[d],e)}catch(f){}if(b[d].splitBoundaries(),c=b[d].getNodes([a.TEXT_NODE]),c.length){for(var g,h=0,i=c.length;i>h;++h)g=c[h],this.getMatchingAncestor(g).element||this.applyToTextNode(g);b[d].setStart(c[0],0),g=c[c.length-1],b[d].setEnd(g,g.length),this.normalize&&this.postApply(c,b[d])}}},undoToRange:function(b){for(var c,d,e,f=b.length;f--;){if(c=b[f].getNodes([a.TEXT_NODE]),c.length)b[f].splitBoundaries(),c=b[f].getNodes([a.TEXT_NODE]);else{var g=b[f].endContainer.ownerDocument,h=g.createTextNode(a.INVISIBLE_SPACE);b[f].insertNode(h),b[f].selectNode(h),c=[h]}for(var i=0,j=c.length;j>i;++i)b[f].isValid()&&(d=c[i],e=this.getMatchingAncestor(d),"style"===e.type?this.undoToTextNode(d,b[f],!1,e.element):e.element&&this.undoToTextNode(d,b[f],e.element));1==j?this.selectNode(b[f],c[0]):(b[f].setStart(c[0],0),d=c[c.length-1],b[f].setEnd(d,d.length),this.normalize&&this.postApply(c,b[f]))}},selectNode:function(b,c){var d=c.nodeType===a.ELEMENT_NODE,e="canHaveHTML"in c?c.canHaveHTML:!0,f=d?c.innerHTML:c.data,g=""===f||f===a.INVISIBLE_SPACE;if(g&&d&&e)try{c.innerHTML=a.INVISIBLE_SPACE}catch(h){}b.selectNodeContents(c),g&&d?b.collapse(!1):g&&(b.setStartAfter(c),b.setEndAfter(c))},getTextSelectedByRange:function(a,b){var c=b.cloneRange();c.selectNodeContents(a);var d=c.intersection(b),e=d?d.toString():"";return c.detach(),e},isAppliedToRange:function(b){for(var c,d,e=[],f="full",g=b.length;g--;){if(d=b[g].getNodes([a.TEXT_NODE]),!d.length)return c=this.getMatchingAncestor(b[g].startContainer).element,c?{elements:[c],coverage:f}:!1;for(var h,i=0,j=d.length;j>i;++i)h=this.getTextSelectedByRange(d[i],b[g]),c=this.getMatchingAncestor(d[i]).element,c&&""!=h?(e.push(c),1===a.dom.getTextNodes(c,!0).length?f="full":"full"===f&&(f="inline")):c||(f="partial")}return e.length?{elements:e,coverage:f}:!1},toggleRange:function(a){var b,c=this.isAppliedToRange(a);c?"full"===c.coverage?this.undoToRange(a):"inline"===c.coverage?(b=k(c.elements,this.tagNames,this.cssStyle,this.cssClass),this.undoToRange(a),b||this.applyToRange(a)):(k(c.elements,this.tagNames,this.cssStyle,this.cssClass)||this.undoToRange(a),this.applyToRange(a)):this.applyToRange(a)}},a.selection.HTMLApplier=s}(wysihtml5,rangy),wysihtml5.Commands=Base.extend({constructor:function(a){this.editor=a,this.composer=a.composer,this.doc=this.composer.doc},support:function(a){return wysihtml5.browser.supportsCommand(this.doc,a)},exec:function(a,b){var c=wysihtml5.commands[a],d=wysihtml5.lang.array(arguments).get(),e=c&&c.exec,f=null;if(this.composer.hasPlaceholderSet()&&!wysihtml5.lang.array(["styleWithCSS","enableObjectResizing","enableInlineTableEditing"]).contains(a)&&(this.composer.element.innerHTML="",this.composer.selection.selectNode(this.composer.element)),this.editor.fire("beforecommand:composer"),e)d.unshift(this.composer),f=e.apply(c,d);else try{f=this.doc.execCommand(a,!1,b)}catch(g){}return this.editor.fire("aftercommand:composer"),f},remove:function(a,b){var c=wysihtml5.commands[a],d=wysihtml5.lang.array(arguments).get(),e=c&&c.remove;return e?(d.unshift(this.composer),e.apply(c,d)):void 0},state:function(a,b){var c=wysihtml5.commands[a],d=wysihtml5.lang.array(arguments).get(),e=c&&c.state;if(e)return d.unshift(this.composer),e.apply(c,d);try{return this.doc.queryCommandState(a)}catch(f){return!1}},stateValue:function(a){var b=wysihtml5.commands[a],c=wysihtml5.lang.array(arguments).get(),d=b&&b.stateValue;return d?(c.unshift(this.composer),d.apply(b,c)):!1}}),function(a){var b={nodeName:"B",toggle:!0};a.commands.bold={exec:function(c,d){a.commands.formatInline.exec(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){function b(b){return a.lang.object({}).merge(c).merge({attribute:b}).get()}var c={nodeName:"A",toggle:!1};a.commands.createLink={exec:function(c,d,e){var f=b(e);if(c.selection.isCollapsed()&&!this.state(c,d)){var g=c.doc.createTextNode(f.attribute.href);c.selection.insertNode(g),c.selection.selectNode(g)}a.commands.formatInline.exec(c,d,f)},state:function(b,d){return a.commands.formatInline.state(b,d,c)}}}(wysihtml5),function(a){var b={nodeName:"A"};a.commands.removeLink={exec:function(c,d){a.commands.formatInline.remove(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){var b=/wysiwyg-font-size-[0-9a-z\-]+/g;a.commands.fontSize={exec:function(c,d,e){a.commands.formatInline.exec(c,d,{className:"wysiwyg-font-size-"+e,classRegExp:b,toggle:!0})},state:function(b,c,d){return a.commands.formatInline.state(b,c,{className:"wysiwyg-font-size-"+d})}}}(wysihtml5),function(a){a.commands.fontSizeStyle={exec:function(b,c,d){d=d.size||d,/^\s*$/.test(d)||a.commands.formatInline.exec(b,c,{styleProperty:"fontSize",styleValue:d,toggle:!1})},state:function(b,c,d){return a.commands.formatInline.state(b,c,{styleProperty:"fontSize",styleValue:d||void 0})},remove:function(b,c){return a.commands.formatInline.remove(b,c,{styleProperty:"fontSize"})},stateValue:function(b,c){var d,e=this.state(b,c);return e&&a.lang.object(e).isArray()&&(e=e[0]),e&&(d=e.getAttribute("style"))?a.quirks.styleParser.parseFontSize(d):!1}}}(wysihtml5),function(a){var b=/wysiwyg-color-[0-9a-z]+/g;a.commands.foreColor={exec:function(c,d,e){a.commands.formatInline.exec(c,d,{className:"wysiwyg-color-"+e,classRegExp:b,toggle:!0})},state:function(b,c,d){return a.commands.formatInline.state(b,c,{className:"wysiwyg-color-"+d})}}}(wysihtml5),function(a){a.commands.foreColorStyle={exec:function(b,c,d){var e,f;d&&(e=a.quirks.styleParser.parseColor("color:"+(d.color||d),"color"),e&&(f=(1===e[3]?"rgb("+[e[0],e[1],e[2]].join(", "):"rgba("+e.join(", "))+")",a.commands.formatInline.exec(b,c,{styleProperty:"color",styleValue:f})))},state:function(b,c,d){var e,f=d?a.quirks.styleParser.parseColor("color:"+(d.color||d),"color"):null;return f&&(e=(1===f[3]?"rgb("+[f[0],f[1],f[2]].join(", "):"rgba("+f.join(", "))+")"),a.commands.formatInline.state(b,c,{styleProperty:"color",styleValue:e})},remove:function(b,c){return a.commands.formatInline.remove(b,c,{styleProperty:"color"})},stateValue:function(b,c,d){var e,f=this.state(b,c),g=!1;return f&&a.lang.object(f).isArray()&&(f=f[0]),f&&(e=f.getAttribute("style"))?(g=a.quirks.styleParser.parseColor(e,"color"),a.quirks.styleParser.unparseColor(g,d)):!1}}}(wysihtml5),function(a){a.commands.bgColorStyle={exec:function(b,c,d){var e,f=a.quirks.styleParser.parseColor("background-color:"+(d.color||d),"background-color");f&&(e=(1===f[3]?"rgb("+[f[0],f[1],f[2]].join(", "):"rgba("+f.join(", "))+")",a.commands.formatInline.exec(b,c,{styleProperty:"backgroundColor",styleValue:e}))},state:function(b,c,d){var e,f=d?a.quirks.styleParser.parseColor("background-color:"+(d.color||d),"background-color"):null;return f&&(e=(1===f[3]?"rgb("+[f[0],f[1],f[2]].join(", "):"rgba("+f.join(", "))+")"),a.commands.formatInline.state(b,c,{styleProperty:"backgroundColor",styleValue:e})},remove:function(b,c){return a.commands.formatInline.remove(b,c,{styleProperty:"backgroundColor"})},stateValue:function(b,c,d){var e,f=this.state(b,c),g=!1;return f&&a.lang.object(f).isArray()&&(f=f[0]),f&&(e=f.getAttribute("style"))?(g=a.quirks.styleParser.parseColor(e,"background-color"),a.quirks.styleParser.unparseColor(g,d)):!1}}}(wysihtml5),function(a){function b(a){return{nodeName:a.nodeName||null,className:a.classRegExp?null:a.className||null,classRegExp:a.classRegExp||null,styleProperty:a.styleProperty||null}}function c(a,b){return 3===a.nodeType?a:a.childNodes[b]||a}function d(a){return a&&1===a.nodeType&&"BR"===a.nodeName}function e(a,b){return a&&1===a.nodeType&&"block"===b.win.getComputedStyle(a).display}function f(a){return a&&1===a.nodeType&&a.classList.contains("rangySelectionBoundary")}function g(a,b){return d(a)||e(a,b)}function h(b,c){a.dom.removeInvisibleSpaces(b.element);for(var d,e=b.element,f=e.querySelectorAll(E),g=b.config.classNames.uneditableContainer+[""].concat(E.split(",")).join(", "+b.config.classNames.uneditableContainer+" "),h=e.querySelectorAll(g),i=a.lang.array(f).without(h),j=i.length;j--;)""!==i[j].innerHTML.replace(/[\uFEFF]/g,"")||0!==c.length&&i[j]===c[c.length-1]||(d=a.lang.array(c).indexOf(i[j]),d>-1&&c.splice(d,1),i[j].parentNode.removeChild(i[j]));return c}function i(a){return a.config.useLineBreaks?"DIV":"P"}function j(a,b,c){for(var d=a,e=null;d&&b&&d!==b;)1===d.nodeType&&d.matches(c?E:D)&&(e=d),d=d.parentNode;return e}function k(a,b){for(var c,d,e,f=a,g=null;f&&b&&f!==b;)1===f.nodeType&&f.matches(F)&&(d=f,null===g?(g=f.cloneNode(!1),c=g):(e=f.cloneNode(!1),e.appendChild(g),g=e)),f=f.parentNode;return{parent:d,outerNode:g,innerNode:c}}function l(b,c,d){return b||(b=d.doc.createElement(c.nodeName||i(d)),b.appendChild(d.doc.createTextNode(a.INVISIBLE_SPACE))),c.nodeName&&b.nodeName!==c.nodeName&&(b=C.renameElement(b,c.nodeName)),c.classRegExp&&(b.className=b.className.replace(c.classRegExp,"")),c.className&&b.classList.add(c.className),c.styleProperty&&"undefined"!=typeof c.styleValue&&(b.style[a.browser.fixStyleKey(c.styleProperty)]=c.styleValue),b}function m(b,c,d){var e,f=b.previousSibling,g=b.nextSibling,h=!1;c.styleProperty&&(b.style[a.browser.fixStyleKey(c.styleProperty)]=""),c.className&&b.classList.remove(c.className),c.classRegExp&&(b.className=b.className.replace(c.classRegExp,"")),null!==b.getAttribute("class")&&""===b.getAttribute("class").trim()&&b.removeAttribute("class"),c.nodeName&&b.nodeName.toLowerCase()===c.nodeName.toLowerCase()&&(e=b.getAttribute("style"),e&&""!==e.trim()?b=C.renameElement(b,i(d)):(C.unwrap(b),h=!0)),null!==b.getAttribute("style")&&""===b.getAttribute("style").trim()&&b.removeAttribute("style"),h&&u(f,g,d)}function n(b){for(var c,d,e=b.querySelectorAll(E)||[],f=e.length;f--;)c=a.dom.domNode(e[f]).next({nodeTypes:[1,3],ignoreBlankTexts:!0}),d=a.dom.domNode(e[f]).prev({nodeTypes:[1,3],ignoreBlankTexts:!0}),c&&1!==c.nodeType&&"BR"!==c.nodeName&&""!==(e[f].innerHTML||e[f].nodeValue||"").trim()&&e[f].parentNode.insertBefore(e[f].ownerDocument.createElement("BR"),c),c&&1!==c.nodeType&&"BR"!==c.nodeName&&""!==(e[f].innerHTML||e[f].nodeValue||"").trim()&&e[f].parentNode.insertBefore(e[f].ownerDocument.createElement("BR"),c),a.dom.unwrap(e[f])}function o(a,b){var c,d=a.startContainer,e=a.endContainer;return d&&1===d.nodeType&&d===e?void(d.firstChild===d.lastChild&&1===a.endOffset&&d!==b.element&&"LI"!==d.nodeName&&"TD"!==d.nodeName&&(a.setStartBefore(d),a.setEndAfter(e))):d&&1===d.nodeType&&3===e.nodeType?void(d.firstChild===e&&a.endOffset===e.data.length&&d!==b.element&&"LI"!==d.nodeName&&"TD"!==d.nodeName&&a.setEndAfter(d)):e&&1===e.nodeType&&3===d.nodeType?void(e.firstChild===d&&0===a.startOffset&&e!==b.element&&"LI"!==e.nodeName&&"TD"!==e.nodeName&&a.setStartBefore(e)):d&&3===d.nodeType&&d===e&&1===d.parentNode.childNodes.length?void(a.endOffset==e.data.length&&0===a.startOffset&&(c=d.parentNode,c!==b.element&&"LI"!==c.nodeName&&"TD"!==c.nodeName&&(a.setStartBefore(c),a.setEndAfter(c)))):void 0}function p(b){for(var c,d,e,f,g,h,i=[],j=0,k=b.length;k>j;j++)if(1===b[j].startContainer.nodeType&&b[j].startContainer.matches("ul, ol")&&b[j].setStart(b[j].startContainer.childNodes[b[j].startOffset],0),1===b[j].endContainer.nodeType&&b[j].endContainer.matches("ul, ol")&&(h=b[j].endContainer.childNodes[Math.max(b[j].endOffset-1,0)],h.childNodes&&b[j].setEnd(h,h.childNodes.length)),c=b[j].getNodes([1],function(a){return"LI"===a.nodeName}),c.length>0){for(d=0,e=c.length;e>d;d++)g=b[j].compareNode(c[d]),(g===b[j].NODE_AFTER||g===b[j].NODE_INSIDE)&&(f=b[j].cloneRange(),h=a.dom.domNode(c[d]).prev({nodeTypes:[1]}),h?f.setEnd(h,h.childNodes.length):c[d].closest("ul, ol")?f.setEndBefore(c[d].closest("ul, ol")):f.setEndBefore(c[d]),i.push(f),b[j].setStart(c[d],0)),(g===b[j].NODE_BEFORE||g===b[j].NODE_INSIDE)&&(f=b[j].cloneRange(),f.setEnd(c[d],c[d].childNodes.length),i.push(f),h=a.dom.domNode(c[d]).next({nodeTypes:[1]}),h?b[j].setStart(h,0):c[d].closest("ul, ol")?b[j].setStartAfter(c[d].closest("ul, ol")):b[j].setStartAfter(c[d]));i.push(b[j])}else i.push(b[j]);return i}function q(b,c,d){var e=b?a.lang.object(b).clone(!0):null;return e&&(e.nodeName=e.nodeName||c||i(d)),e}function r(b,c,d,e){var f,h,i,l,m,n=c.startContainer,e=e||j(n,d.element,!0);if(e)h=b.firstChild,i=b.lastChild,d.selection.splitElementAtCaret(e,b),m=a.dom.domNode(i).next({nodeTypes:[1,3],ignoreBlankTexts:!0}),l=a.dom.domNode(h).prev({nodeTypes:[1,3],ignoreBlankTexts:!0}),h&&!g(h,d)&&l&&!g(l,d)&&h.parentNode.insertBefore(d.doc.createElement("br"),h),i&&!g(i,d)&&m&&!g(m,d)&&m.parentNode.insertBefore(d.doc.createElement("br"),m);else if(f=k(n,d.element),f.outerNode&&f.innerNode&&f.parent){if(1===b.childNodes.length){for(;b.firstChild.firstChild;)f.innerNode.appendChild(b.firstChild.firstChild);b.firstChild.appendChild(f.outerNode)}d.selection.splitElementAtCaret(f.parent,b)}else{var o=b.firstChild,p=b.lastChild;c.insertNode(b),c.setStartBefore(o),c.setEndAfter(p)}}function s(b,d,e){for(var f,h,i=b.cloneRange(),j=c(i.startContainer,i.startOffset).previousSibling,k=c(i.endContainer,i.endOffset).nextSibling,l=i.extractContents(),m=e.doc.createDocumentFragment(),o=!0;l.firstChild;){if(1===l.firstChild.nodeType&&l.firstChild.matches(E)){n(l.firstChild),f=a.dom.unwrap(l.firstChild),f.length>0&&(m.lastChild&&(1!==m.lastChild.nodeType||!g(m.lastChild,e))||!m.lastChild&&j&&(1!==j.nodeType||g(j,e)))&&m.appendChild(e.doc.createElement("BR"));for(var p=0,q=f.length;q>p;p++)m.appendChild(f[p]);f.length>0&&(1===m.lastChild.nodeType&&g(m.lastChild,e)||(k||m.lastChild!==l.lastChild)&&m.appendChild(e.doc.createElement("BR")))}else m.appendChild(l.firstChild);o=!1}return h=a.lang.array(m.childNodes).get(),r(m,i,e),h}function t(b,c,e){var f=b&&a.dom.domNode(b).prev({nodeTypes:[1,3],ignoreBlankTexts:!0});d(c)&&c.parentNode.removeChild(c),!d(b)||f&&1===f.nodeType&&"block"===e.win.getComputedStyle(f).display||b.parentNode.removeChild(b)}function u(a,b,c){var e;a&&f(a)&&(a=a.previousSibling),b&&f(b)&&(b=b.nextSibling),e=a&&a.previousSibling,a&&(1!==a.nodeType||"block"!==c.win.getComputedStyle(a).display&&!d(a))&&a.parentNode&&a.parentNode.insertBefore(c.doc.createElement("br"),a.nextSibling),b&&(1!==b.nodeType||"block"!==c.win.getComputedStyle(b).display)&&b.parentNode&&b.parentNode.insertBefore(c.doc.createElement("br"),b)}function v(d,e,f,g){var h,i,k=e?b(e):null,m=d.cloneRange(),o=m.startContainer,p=c(m.startContainer,m.startOffset),s=c(m.endContainer,m.endOffset),u=m.startContainer!==p||3!==p.nodeType||G(p,m.startOffset)?a.dom.domNode(p).prev({nodeTypes:[1,3],ignoreBlankTexts:!0}):p,v=1===m.endContainer.nodeType&&m.endContainer.childNodes[m.endOffset]===s&&(1===s.nodeType||!H(s,m.endOffset)&&!a.dom.domNode(s).is.rangyBookmark())||m.endContainer===s&&3===s.nodeType&&!H(s,m.endOffset)?s:a.dom.domNode(s).next({nodeTypes:[1,3],ignoreBlankTexts:!0}),w=m.extractContents(),x=g.doc.createDocumentFragment(),y=k?a.dom.getParentElement(o,k,null,g.element):null,z=!f||!e||"BLOCKQUOTE"===e.nodeName&&"BLOCKQUOTE"===f,A=y||j(o,g.element,z);if(a.dom.domNode(v).is.rangyBookmark()&&(s=v,v=s.nextSibling),I(w),e&&"BLOCKQUOTE"===e.nodeName){var B=l(null,e,g);B.appendChild(w),x.appendChild(B),i=[B]}else{if(w.firstChild)for(;w.firstChild;)if(1==w.firstChild.nodeType&&w.firstChild.matches(E))l(w.firstChild,e,g),w.firstChild.matches(D)&&n(w.firstChild),x.appendChild(w.firstChild);else{for(h=l(null,q(e,f,g),g);w.firstChild&&(1!==w.firstChild.nodeType||!w.firstChild.matches(E));)1==w.firstChild.nodeType&&h.matches(D)&&n(w.firstChild),h.appendChild(w.firstChild);x.appendChild(h)}else x.appendChild(l(null,e,g));i=a.lang.array(x.childNodes).get()}return r(x,m,g,A),t(u,v,g),i.length>0&&("undefined"==typeof i[i.length-1].lastChild||a.dom.domNode(i[i.length-1].lastChild).is.rangyBookmark())&&i[i.length-1].appendChild(g.doc.createElement("br")),i}function w(b,c){var d=a.dom.getParentElement(b,{query:E},null,c.element);return d?d.nodeName:null}function x(b,c){var d,e=a.dom.getParentElement(b.selection.getOwnRanges()[0].startContainer,{query:D+", "+(c?c.toLowerCase():"div")},null,b.element);e?(d=b.selection.createRange(),d.selectNode(e),b.selection.setSelection(d)):b.isEmpty()||b.selection.selectLine()}function y(a,b){var c=b.selection.createRange(),d=a[a.length-1],e=1===d.nodeType&&d.childNodes?0|d.childNodes.length:d.length||0;c.setStart(a[0],0),c.setEnd(d,e),c.select()}function z(a,b,c){var d,e=b.selection.getOwnRanges(),f=[];e=p(e);for(var g=e.length;g--;)o(e[g],b),d=w(e[g].startContainer,b),f="remove"===a?f.concat(s(e[g],d,b)):f.concat(v(e[g],c,d,b));return f}function A(a){return"string"==typeof a&&(a={nodeName:a.toUpperCase()}),a}function B(b){var c;return b.selection.isCollapsed()&&(c=b.selection.getNodesNearCaret(),c&&c.caretNode&&(a.dom.domNode(c.caretNode).is.lineBreak()||3===c.caretNode.nodeType&&0===c.textOffset&&(!c.prevNode||a.dom.domNode(c.prevNode).is.lineBreak())||1===c.caretNode.nodeType&&c.caretNode.classList.contains("rangySelectionBoundary")&&(!c.prevNode||a.dom.domNode(c.prevNode).is.lineBreak()||a.dom.domNode(c.prevNode).is.block())&&(!c.nextNode||a.dom.domNode(c.nextNode).is.lineBreak()||a.dom.domNode(c.nextNode).is.block())))?!0:!1}var C=a.dom,D="h1, h2, h3, h4, h5, h6, p, pre",E="h1, h2, h3, h4, h5, h6, p, pre, div, blockquote",F="b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u",G=function(a,b){var c=a.data?a.data.slice(0,b):"";return/^\s*$/.test(c)},H=function(a,b){var c=a.data?a.data.slice(b):"";return/^\s*$/.test(c)},I=function(a){if(a){for(;a.firstChild&&3===a.firstChild.nodeType&&/^\s*$/.test(a.firstChild.data)&&a.lastChild!==a.firstChild;)a.removeChild(a.firstChild);for(;a.lastChild&&3===a.lastChild.nodeType&&/^\s*$/.test(a.lastChild.data)&&a.lastChild!==a.firstChild;)a.removeChild(a.lastChild);a.firstChild&&1===a.firstChild.nodeType&&"BR"===a.firstChild.nodeName&&a.lastChild!==a.firstChild&&a.removeChild(a.firstChild),a.lastChild&&1===a.lastChild.nodeType&&"BR"===a.lastChild.nodeName&&a.lastChild!==a.firstChild&&a.removeChild(a.lastChild)}};a.commands.formatBlock={exec:function(a,b,c){c=A(c);var d,e,f=[];if(c&&c.toggle&&(e=this.state(a,b,c)),e){d=rangy.saveSelection(a.win);for(var g=0,i=e.length;i>g;g++)m(e[g],c,a)}else a.selection.isCollapsed()&&(d=rangy.saveSelection(a.win),B(a)?a.selection.selectLine():x(a,c&&c.nodeName?c.nodeName.toUpperCase():void 0)),f=c?z("apply",a,c):z("remove",a);f=h(a,f),d?rangy.restoreSelection(d):y(f,a)},remove:function(a,b,c){c=A(c);var d,e;a.selection.isCollapsed()&&(e=rangy.saveSelection(a.win),x(a,c&&c.nodeName?c.nodeName.toUpperCase():void 0)),d=z("remove",a),d=h(a,d),e?rangy.restoreSelection(e):y(d,a)},state:function(b,c,d){d=A(d);for(var e,f=b.selection.filterElements(function(b){return a.dom.domNode(b).test(d||{query:E})}.bind(this)),g=b.selection.getSelectedOwnNodes(),h=0,i=g.length;i>h;h++)e=C.getParentElement(g[h],d||{query:E},null,b.element),e&&-1===f.indexOf(e)&&f.push(e);return 0===f.length?!1:f}}}(wysihtml5),function(a){a.commands.formatCode={exec:function(b,c,d){var e,f,g,h=this.state(b)[0];h?b.selection.executeAndRestore(function(){e=h.querySelector("code"),a.dom.replaceWithChildNodes(h),e&&a.dom.replaceWithChildNodes(e)}):(f=b.selection.getRange(),g=f.extractContents(),h=b.doc.createElement("pre"),e=b.doc.createElement("code"),d&&(e.className=d),h.appendChild(e),e.appendChild(g),f.insertNode(h),b.selection.selectNode(h))},state:function(b){var c,d=b.selection.getSelectedNode();return d&&d.nodeName&&"PRE"==d.nodeName&&d.firstChild&&d.firstChild.nodeName&&"CODE"==d.firstChild.nodeName?[d]:(c=a.dom.getParentElement(d,{query:"pre code"}),c?[c.parentNode]:!1)}}}(wysihtml5),function(a){function b(a){return/^\s*$/.test(a.className)}function c(a){return!a.getAttribute("style")||/^\s*$/.test(a.getAttribute("style"))}function d(b){var c=a.dom.getAttributes(b);return a.lang.object(c).isEmpty()}function e(b,c){var d,e,f,g;return 1!==b.nodeType||1!==c.nodeType?!1:b.nodeName!==c.nodeName?!1:(d=b.className.trim().replace(/\s+/g," ").split(" "),e=c.className.trim().replace(/\s+/g," ").split(" "),a.lang.array(d).without(e).length>0?!1:(f=a.dom.getAttributes(b),g=a.dom.getAttributes(c),f.length===g.length&&a.lang.object(a.lang.object(f).difference(g)).isEmpty()?!0:!1))}function f(b,c){var d=c&&c.nodeName||F,e=b.ownerDocument.createElement(d);if(c.classRegExp&&(e.className=e.className.replace(c.classRegExp,"")),c.className&&e.classList.add(c.className),c.styleProperty&&"undefined"!=typeof c.styleValue&&(e.style[a.browser.fixStyleKey(c.styleProperty)]=c.styleValue),c.attribute)if("object"==typeof c.attribute)for(var f in c.attribute)c.attribute.hasOwnProperty(f)&&e.setAttribute(f,c.attribute[f]);else"undefined"!=typeof c.attributeValue&&e.setAttribute(c.attribute,c.attributeValue);return e}function g(a,b){for(var c in a)if(a.hasOwnProperty(c)&&(void 0===typeof b[c]||b[c]!==a[c]))return!1;return!0}function h(b,c,d){var e,f=a.dom.getAttributes(b),h=g(c,f);a.lang.object(f).difference(c);if(h&&d!==!1)for(e in c)c.hasOwnProperty(e)&&b.removeAttribute(e);else for(e in c)c.hasOwnProperty(e)&&b.setAttribute(e,c[e])}function i(e,f){var g,i,j;f.className&&(f.toggle!==!1&&e.classList.contains(f.className)?e.classList.remove(f.className):(f.classRegExp&&(e.className=e.className.replace(f.classRegExp,"")),e.classList.add(f.className)),b(e)&&e.removeAttribute("class")),f.styleProperty&&(f.toggle!==!1&&e.style[a.browser.fixStyleKey(f.styleProperty)].trim().replace(/, /g,",")===f.styleValue?e.style[a.browser.fixStyleKey(f.styleProperty)]="":e.style[a.browser.fixStyleKey(f.styleProperty)]=f.styleValue),c(e)&&e.removeAttribute("style"),f.attribute&&("object"==typeof f.attribute?g=f.attribute:(g={},g[f.attribute]=f.attributeValue||""),h(e,g,f.toggle)),i=f.nodeName?H[f.nodeName.toLowerCase()]||f.nodeName.toLowerCase():null,j=i?a.dom.domNode(e).test({query:i}):!1,(!f.nodeName||f.nodeName===F||j)&&(f.toggle!==!1&&j||!f.nodeName&&e.nodeName===F)&&b(e)&&c(e)&&d(e)&&a.dom.unwrap(e)}function j(b,c){var d=[];return b.isCollapsed()||(d=d.concat(b.getOwnNodes([3],function(b){return!a.dom.domNode(b).is.emptyTextNode()},c))),d}function k(a,b,c,d){var e=a,f=d?b:l(b);do{if(1===e.nodeType&&m(e,f))return e;e=e.parentNode}while(e&&e!==c);return null}function l(a){return{nodeName:a.nodeName||null,className:a.classRegExp?null:a.className||null,classRegExp:a.classRegExp||null,styleProperty:a.styleProperty||null}}function m(b,c){var d;if(c.nodeName){var e=H[c.nodeName.toLowerCase()]||c.nodeName.toLowerCase();return a.dom.domNode(b).test({query:e})}return d=a.lang.object(c).clone(),d.query=G,a.dom.domNode(b).test(d)}function n(b,c){var d=document.documentElement||document.body,e=d.scrollTop,f=d.scrollLeft;rangy.getSelection(b.win);rangy.getSelection(b.win).removeAllRanges();try{rangy.getSelection(b.win).addRange(c)}catch(g){}b.doc.activeElement&&a.dom.contains(b.element,b.doc.activeElement)||(b.element.focus(),d.scrollTop=e,d.scrollLeft=f,rangy.getSelection(b.win).addRange(c))}function o(a,b){var c=rangy.createRange(b.doc),d=a[a.length-1];a[0]&&d&&(c.setStart(a[0],0),c.setEnd(d,d.length),n(b,c))}function p(a,b,c,d){var e=rangy.createRange(a.doc);b&&(e.setStart(b,c),e.setEnd(b,"undefined"!=typeof d?d:c),n(a,e))}function q(a,b,c){var d,e,f,g=j(a.selection),h=[],i=!1;if(a.selection.isInThisEditable()){if(0===g.length&&a.selection.isCollapsed()){if(f=a.selection.getSelection().anchorNode,!f)return{nodes:[],partial:!1};3===f.nodeType&&(g=[f])}g.length||(e=a.selection.getOwnRanges()[0],e&&(g=[e.endContainer]));for(var l=0,m=g.length;m>l;l++)d=k(g[l],b,a.element,c),d?h.push(d):i=!0}return{nodes:h,partial:i}}function r(a){var b,c,d,e;return a&&(b=a.anchorNode,c=a.anchorOffset,b&&3===b.nodeType&&c>0&&c0&&/\w/.test(c.data[g-1]);)g--;for(;h0&&o(b,a),u(q(a,c).nodes),b.length>0&&o(b,a)}function w(a,b,c,d){p(a,b,c),u(q(a,d).nodes),p(a,b,c)}function x(a,b){var c=f(a,b);a.parentNode.insertBefore(c,a),c.appendChild(a)}function y(b,c,d){var e,f=c.element,g=k(b,d,f);g&&(e=g.cloneNode(!1),a.dom.domNode(b).escapeParent(g,e),i(e,d))}function z(b,c,d){var e=c.element,f=k(b,d,e);f&&a.dom.domNode(b).escapeParent(f)}function A(a,b,c){var d=f(a.endContainer,c);a.surroundContents(d),b.selection.selectNode(d)}function B(b,c,d,e){var f,g,h,j,l=q(b,e,!0),m=b.selection.getSelection();if(c.length){if(l.partial||e.toggle===!1)for(j=c.length;j--;)k(c[j],e,b.element)&&y(c[j],b,e),k(c[j],e,b.element)||x(c[j],e);else for(j=c.length;j--;)y(c[j],b,e);v(b,c,e)}else if(e.toggle!==!1)if(r(m))f=s(m),g=f.textNode,y(f.textNode,b,e),w(b,f.textNode,f.wordOffset,e);else{g=b.doc.createTextNode(a.INVISIBLE_SPACE),h=d.nodes[0].cloneNode(!1),h.appendChild(g),b.selection.splitElementAtCaret(d.nodes[0],h),i(h,e),v(b,[g],e);var n=b.selection.getSelection();if(n.anchorNode&&n.focusNode)try{n.collapseToEnd()}catch(o){}}else for(j=d.nodes.length;j--;)i(d.nodes[j],e)}function C(b,c,d,e){var f,g,h,i=b.selection.getSelection();if(c.length){for(h=c.length;h--;)z(c[h],b,e);v(b,c,e)}else{for(f=i.anchorNode,g=i.anchorOffset,h=d.nodes.length;h--;)a.dom.unwrap(d.nodes[h]);w(b,f,g,e)}}function D(a,b,c){var d,e,f=a.selection.getSelection();if(b.length){for(e=b.length;e--;)x(b[e],c);v(a,b,c)}else if(r(f))d=s(f),x(d.textNode,c),w(a,d.textNode,d.wordOffset,c);else{var g=a.selection.getOwnRanges()[0];g&&A(g,a,c)}}function E(a){
-return a="string"==typeof a?{nodeName:a}:a,a.nodeName&&(a.nodeName=a.nodeName.toUpperCase()),a}var F="SPAN",G="b, big, i, small, tt, abbr, acronym, cite, code, dfn, em, kbd, strong, samp, var, a, bdo, br, q, span, sub, sup, button, label, textarea, input, select, u",H={b:"b, strong",strong:"b, strong",em:"em, i",i:"em, i"};a.commands.formatInline={exec:function(a,b,c){c=E(c),a.element.normalize();var d=j(a.selection,!0),e=q(a,c);e.nodes.length>0?B(a,d,e,c):D(a,d,c),a.element.normalize()},remove:function(a,b,c){c=E(c),a.element.normalize();var d=j(a.selection,!0),e=q(a,c);e.nodes.length>0&&C(a,d,e,c),a.element.normalize()},state:function(a,b,c){c=E(c);var d=q(a,c,!0).nodes;return 0===d.length?!1:d}}}(wysihtml5),function(a){var b={nodeName:"BLOCKQUOTE",toggle:!0};a.commands.insertBlockQuote={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){a.commands.insertHTML={exec:function(a,b,c){a.selection.insertHTML(c)},state:function(){return!1}}}(wysihtml5),function(a){var b="IMG";a.commands.insertImage={exec:function(c,d,e){e="object"==typeof e?e:{src:e};var f,g,h=c.doc,i=this.state(c);if(i&&!e.src)return c.selection.setBefore(i),g=i.parentNode,g.removeChild(i),a.dom.removeEmptyTextNodes(g),"A"!==g.nodeName||g.firstChild||(c.selection.setAfter(g),g.parentNode.removeChild(g)),void a.quirks.redraw(c.element);if(i)for(var j in e)e.hasOwnProperty(j)&&i.setAttribute("className"===j?"class":j,e[j]);else{i=h.createElement(b);for(var k in e)i.setAttribute("className"===k?"class":k,e[k]);c.selection.insertNode(i),a.browser.hasProblemsSettingCaretAfterImg()?(f=h.createTextNode(a.INVISIBLE_SPACE),c.selection.insertNode(f),c.selection.setAfter(f)):c.selection.setAfter(i)}},state:function(c){var d,e,f,g=c.doc;return a.dom.hasElementWithTagName(g,b)&&(d=c.selection.getSelectedNode())?d.nodeName===b?d:d.nodeType!==a.ELEMENT_NODE?!1:(e=c.selection.getText(),(e=a.lang.string(e).trim())?!1:(f=c.selection.getNodes(a.ELEMENT_NODE,function(a){return"IMG"===a.nodeName}),1!==f.length?!1:f[0])):!1}}}(wysihtml5),function(a){var b=" "+(a.browser.needsSpaceAfterLineBreak()?" ":"");a.commands.insertLineBreak={exec:function(a,c){a.selection.insertHTML(b)},state:function(){return!1}}}(wysihtml5),function(a){a.commands.insertOrderedList={exec:function(b,c){a.commands.insertList.exec(b,c,"OL")},state:function(b,c){return a.commands.insertList.state(b,c,"OL")}}}(wysihtml5),function(a){a.commands.insertUnorderedList={exec:function(b,c){a.commands.insertList.exec(b,c,"UL")},state:function(b,c){return a.commands.insertList.state(b,c,"UL")}}}(wysihtml5),wysihtml5.commands.insertList=function(a){var b=function(a,b){if(a&&a.nodeName){"string"==typeof b&&(b=[b]);for(var c=b.length;c--;)if(a.nodeName===b[c])return!0}return!1},c=function(c,d,e){var f={el:null,other:!1};if(c){var g=a.dom.getParentElement(c,{query:"li"},!1,e.element),h="UL"===d?"OL":"UL";b(c,d)?f.el=c:b(c,h)?f={el:c,other:!0}:g&&(b(g.parentNode,d)?f.el=g.parentNode:b(g.parentNode,h)&&(f={el:g.parentNode,other:!0}))}return f.el&&!e.element.contains(f.el)&&(f.el=null),f},d=function(b,c,d){var e,g,h="UL"===c?"OL":"UL";d.selection.executeAndRestoreRangy(function(){if(e=f(h,d),e.length)for(var i=e.length;i--;)a.dom.renameElement(e[i],c.toLowerCase());else{g=f(["OL","UL"],d);for(var j=g.length;j--;)a.dom.resolveList(g[j],d.config.useLineBreaks);0===g.length&&a.dom.resolveList(b,d.config.useLineBreaks)}})},e=function(b,c,d){var e="UL"===c?"OL":"UL";d.selection.executeAndRestoreRangy(function(){for(var g=[b].concat(f(e,d)),h=g.length;h--;)a.dom.renameElement(g[h],c.toLowerCase())})},f=function(a,c){for(var d=c.selection.getOwnRanges(),e=[],f=d.length;f--;)e=e.concat(d[f].getNodes([1],function(c){return b(c,a)}));return e},g=function(b,c){var d,e,f=rangy.saveSelection(c.win),g="_wysihtml5-temp-"+(new Date).getTime();c.commands.exec("formatBlock",{nodeName:"div",className:g});var h=c.element.querySelector("."+g);h.innerHTML=h.innerHTML.replace(a.INVISIBLE_SPACE_REG_EXP,""),h&&(d=/^(\s|( ))+$/i.test(h.innerHTML),e=a.dom.convertToList(h,b.toLowerCase(),c.parent.config.classNames.uneditableContainer),f&&rangy.restoreSelection(f),d&&c.selection.selectNode(e.querySelector("li"),!0))};return{exec:function(b,f,h){var i,j,k=b.doc,l="OL"===h?"insertOrderedList":"insertUnorderedList",m=b.selection.getSelection(),n=1===m.anchorNode.nodeType&&m.anchorNode.firstChild?m.anchorNode.childNodes[m.anchorOffset]:m.anchorNode,o=1===m.focusNode.nodeType&&m.focusNode.firstChild?m.focusNode.childNodes[m.focusOffset]||m.focusNode.lastChild:m.focusNode;m.isBackwards()&&(n=[o,o=n][0]),a.dom.domNode(o).is.emptyTextNode(!0)&&o&&(o=a.dom.domNode(o).prev({nodeTypes:[1,3],ignoreBlankTexts:!0})),a.dom.domNode(n).is.emptyTextNode(!0)&&n&&(n=a.dom.domNode(n).next({nodeTypes:[1,3],ignoreBlankTexts:!0})),i=n&&o?n===o?n:a.dom.domNode(n).commonAncestor(o,b.element):b.selection.getSelectedNode(),j=c(i,h,b),j.el?j.other?e(j.el,h,b):d(j.el,h,b):b.commands.support(l)?k.execCommand(l,!1,null):g(h,b)},state:function(a,b,d){var e=a.selection.getSelectedNode(),f=c(e,d,a);return f.el&&!f.other?f.el:!1}}}(wysihtml5),function(a){var b={nodeName:"I",toggle:!0};a.commands.italic={exec:function(c,d){a.commands.formatInline.exec(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){var b={className:"wysiwyg-text-align-center",classRegExp:/wysiwyg-text-align-[0-9a-z]+/g,toggle:!0};a.commands.justifyCenter={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={className:"wysiwyg-text-align-left",classRegExp:/wysiwyg-text-align-[0-9a-z]+/g,toggle:!0};a.commands.justifyLeft={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={className:"wysiwyg-text-align-right",classRegExp:/wysiwyg-text-align-[0-9a-z]+/g,toggle:!0};a.commands.justifyRight={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={className:"wysiwyg-text-align-justify",classRegExp:/wysiwyg-text-align-[0-9a-z]+/g,toggle:!0};a.commands.justifyFull={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={styleProperty:"textAlign",styleValue:"right",toggle:!0};a.commands.alignRightStyle={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={styleProperty:"textAlign",styleValue:"left",toggle:!0};a.commands.alignLeftStyle={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={styleProperty:"textAlign",styleValue:"center",toggle:!0};a.commands.alignCenterStyle={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){var b={styleProperty:"textAlign",styleValue:"justify",toggle:!0};a.commands.alignJustifyStyle={exec:function(c,d){return a.commands.formatBlock.exec(c,"formatBlock",b)},state:function(c,d){return a.commands.formatBlock.state(c,"formatBlock",b)}}}(wysihtml5),function(a){a.commands.redo={exec:function(a){return a.undoManager.redo()},state:function(a){return!1}}}(wysihtml5),function(a){var b={nodeName:"U",toggle:!0};a.commands.underline={exec:function(c,d){a.commands.formatInline.exec(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){a.commands.undo={exec:function(a){return a.undoManager.undo()},state:function(a){return!1}}}(wysihtml5),function(a){a.commands.createTable={exec:function(a,b,c){var d,e,f;if(c&&c.cols&&c.rows&&parseInt(c.cols,10)>0&&parseInt(c.rows,10)>0){for(f=c.tableStyle?'':"",f+="",e=0;e",d=0;d ";f+=""}f+="
",a.commands.exec("insertHTML",f)}},state:function(a,b){return!1}}}(wysihtml5),function(a){a.commands.mergeTableCells={exec:function(b,c){b.tableSelection&&b.tableSelection.start&&b.tableSelection.end&&(this.state(b,c)?a.dom.table.unmergeCell(b.tableSelection.start):a.dom.table.mergeCellsBetween(b.tableSelection.start,b.tableSelection.end))},state:function(b,c){if(b.tableSelection){var d=b.tableSelection.start,e=b.tableSelection.end;if(d&&e&&d==e&&(a.dom.getAttribute(d,"colspan")&&parseInt(a.dom.getAttribute(d,"colspan"),10)>1||a.dom.getAttribute(d,"rowspan")&&parseInt(a.dom.getAttribute(d,"rowspan"),10)>1))return[d]}return!1}}}(wysihtml5),function(a){a.commands.addTableCells={exec:function(b,c,d){if(b.tableSelection&&b.tableSelection.start&&b.tableSelection.end){var e=a.dom.table.orderSelectionEnds(b.tableSelection.start,b.tableSelection.end);"before"==d||"above"==d?a.dom.table.addCells(e.start,d):("after"==d||"below"==d)&&a.dom.table.addCells(e.end,d),setTimeout(function(){b.tableSelection.select(e.start,e.end)},0)}},state:function(a,b){return!1}}}(wysihtml5),function(a){a.commands.deleteTableCells={exec:function(b,c,d){if(b.tableSelection&&b.tableSelection.start&&b.tableSelection.end){var e,f=a.dom.table.orderSelectionEnds(b.tableSelection.start,b.tableSelection.end),g=a.dom.table.indexOf(f.start),h=b.tableSelection.table;a.dom.table.removeCells(f.start,d),setTimeout(function(){e=a.dom.table.findCell(h,g),e||("row"==d&&(e=a.dom.table.findCell(h,{row:g.row-1,col:g.col})),"column"==d&&(e=a.dom.table.findCell(h,{row:g.row,col:g.col-1}))),e&&b.tableSelection.select(e,e)},0)}},state:function(a,b){return!1}}}(wysihtml5),function(a){a.commands.indentList={exec:function(a,b,c){var d=a.selection.getSelectionParentsByTag("LI");return d?this.tryToPushLiLevel(d,a.selection):!1},state:function(a,b){return!1},tryToPushLiLevel:function(b,c){var d,e,f,g,h,i=!1;return c.executeAndRestoreRangy(function(){for(var c=b.length;c--;)g=b[c],d="OL"===g.parentNode.nodeName?"OL":"UL",e=g.ownerDocument.createElement(d),f=a.dom.domNode(g).prev({nodeTypes:[a.ELEMENT_NODE]}),h=f?f.querySelector("ul, ol"):null,f&&(h?h.appendChild(g):(e.appendChild(g),f.appendChild(e)),i=!0)}),i}}}(wysihtml5),function(a){a.commands.outdentList={exec:function(a,b,c){var d=a.selection.getSelectionParentsByTag("LI");return d?this.tryToPullLiLevel(d,a):!1},state:function(a,b){return!1},tryToPullLiLevel:function(b,c){var d,e,f,g,h,i=!1,j=this;return c.selection.executeAndRestoreRangy(function(){for(var k=b.length;k--;)if(g=b[k],g.parentNode&&(d=g.parentNode,"OL"===d.tagName||"UL"===d.tagName)){if(i=!0,e=a.dom.getParentElement(d.parentNode,{query:"ol, ul"},!1,c.element),f=a.dom.getParentElement(d.parentNode,{query:"li"},!1,c.element),e&&f)g.nextSibling&&(h=j.getAfterList(d,g),g.appendChild(h)),e.insertBefore(g,f.nextSibling);else{g.nextSibling&&(h=j.getAfterList(d,g),g.appendChild(h));for(var l=g.childNodes.length;l--;)d.parentNode.insertBefore(g.childNodes[l],d.nextSibling);d.parentNode.insertBefore(document.createElement("br"),d.nextSibling),g.parentNode.removeChild(g)}0===d.childNodes.length&&d.parentNode.removeChild(d)}}),i},getAfterList:function(a,b){for(var c=a.nodeName,d=document.createElement(c);b.nextSibling;)d.appendChild(b.nextSibling);return d}}}(wysihtml5),function(a){var b={nodeName:"SUB",toggle:!0};a.commands.subscript={exec:function(c,d){a.commands.formatInline.exec(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){var b={nodeName:"SUP",toggle:!0};a.commands.superscript={exec:function(c,d){a.commands.formatInline.exec(c,d,b)},state:function(c,d){return a.commands.formatInline.state(c,d,b)}}}(wysihtml5),function(a){var b=90,c=89,d=8,e=46,f=25,g="data-wysihtml5-selection-node",h="data-wysihtml5-selection-offset",i=(''+a.INVISIBLE_SPACE+" ",''+a.INVISIBLE_SPACE+" ",a.dom);a.UndoManager=a.lang.Dispatcher.extend({constructor:function(a){this.editor=a,this.composer=a.composer,this.element=this.composer.element,this.position=0,this.historyStr=[],this.historyDom=[],this.transact(),this._observe()},_observe:function(){var a,f=this;this.composer.sandbox.getDocument();i.observe(this.element,"keydown",function(a){if(!a.altKey&&(a.ctrlKey||a.metaKey)){var d=a.keyCode,e=d===b&&!a.shiftKey,g=d===b&&a.shiftKey||d===c;e?(f.undo(),a.preventDefault()):g&&(f.redo(),a.preventDefault())}}),i.observe(this.element,"keydown",function(b){var c=b.keyCode;c!==a&&(a=c,(c===d||c===e)&&f.transact())}),this.editor.on("newword:composer",function(){f.transact()}).on("beforecommand:composer",function(){f.transact()})},transact:function(){var b,c,d,e,i,j=this.historyStr[this.position-1],k=this.composer.getValue(!1,!1),l=this.element.offsetWidth>0&&this.element.offsetHeight>0;if(k!==j){var m=this.historyStr.length=this.historyDom.length=this.position;m>f&&(this.historyStr.shift(),this.historyDom.shift(),this.position--),this.position++,l&&(b=this.composer.selection.getRange(),c=b&&b.startContainer?b.startContainer:this.element,d=b&&b.startOffset?b.startOffset:0,c.nodeType===a.ELEMENT_NODE?e=c:(e=c.parentNode,i=this.getChildNodeIndex(e,c)),e.setAttribute(h,d),"undefined"!=typeof i&&e.setAttribute(g,i));var n=this.element.cloneNode(!!k);this.historyDom.push(n),this.historyStr.push(k),e&&(e.removeAttribute(h),e.removeAttribute(g))}},undo:function(){this.transact(),this.undoPossible()&&(this.set(this.historyDom[--this.position-1]),this.editor.fire("undo:composer"))},redo:function(){this.redoPossible()&&(this.set(this.historyDom[++this.position-1]),this.editor.fire("redo:composer"))},undoPossible:function(){return this.position>1},redoPossible:function(){return this.positionb;b++)this.element.appendChild(c[b].cloneNode(!0));var e,f,i;a.hasAttribute(h)?(e=a.getAttribute(h),i=a.getAttribute(g),f=this.element):(f=this.element.querySelector("["+h+"]")||this.element,e=f.getAttribute(h),i=f.getAttribute(g),f.removeAttribute(h),f.removeAttribute(g)),null!==i&&(f=this.getChildNodeByIndex(f,+i)),this.composer.selection.set(f,e)},getChildNodeIndex:function(a,b){for(var c=0,d=a.childNodes,e=d.length;e>c;c++)if(d[c]===b)return c},getChildNodeByIndex:function(a,b){return a.childNodes[b]}})}(wysihtml5),wysihtml5.views.View=Base.extend({constructor:function(a,b,c){this.parent=a,this.element=b,this.config=c,this.config.noTextarea||this._observeViewChange()},_observeViewChange:function(){var a=this;this.parent.on("beforeload",function(){a.parent.on("change_view",function(b){b===a.name?(a.parent.currentView=a,a.show(),setTimeout(function(){a.focus()},0)):a.hide()})})},focus:function(){if(!this.element||!this.element.ownerDocument||this.element.ownerDocument.querySelector(":focus")!==this.element)try{this.element&&this.element.focus()}catch(a){}},hide:function(){this.element.style.display="none"},show:function(){this.element.style.display=""},disable:function(){this.element.setAttribute("disabled","disabled")},enable:function(){this.element.removeAttribute("disabled")}}),function(a){var b=a.dom,c=a.browser;a.views.Composer=a.views.View.extend({name:"composer",constructor:function(a,b,c){this.base(a,b,c),this.config.noTextarea?this.editableArea=b:this.textarea=this.parent.textarea,this.config.contentEditableMode?this._initContentEditableArea():this._initSandbox()},clear:function(){this.element.innerHTML=c.displaysCaretInEmptyContentEditableCorrectly()?"":" "},getValue:function(b,c){var d=this.isEmpty()?"":a.quirks.getCorrectInnerHTML(this.element);return b!==!1&&(d=this.parent.parse(d,c===!1?!1:!0)),d},setValue:function(a,b){b!==!1&&(a=this.parent.parse(a));try{this.element.innerHTML=a}catch(c){this.element.innerText=a}},cleanUp:function(a){var b;this.selection&&this.selection.isInThisEditable()&&(b=rangy.saveSelection(this.win)),this.parent.parse(this.element,void 0,a),b&&rangy.restoreSelection(b)},show:function(){this.editableArea.style.display=this._displayStyle||"",this.config.noTextarea||this.textarea.element.disabled||(this.disable(),this.enable())},hide:function(){this._displayStyle=b.getStyle("display").from(this.editableArea),"none"===this._displayStyle&&(this._displayStyle=null),this.editableArea.style.display="none"},disable:function(){this.parent.fire("disable:composer"),this.element.removeAttribute("contentEditable")},enable:function(){this.parent.fire("enable:composer"),this.element.setAttribute("contentEditable","true")},focus:function(b){a.browser.doesAsyncFocus()&&this.hasPlaceholderSet()&&this.clear(),this.base();var c=this.element.lastChild;b&&c&&this.selection&&("BR"===c.nodeName?this.selection.setBefore(this.element.lastChild):this.selection.setAfter(this.element.lastChild))},getScrollPos:function(){if(this.doc&&this.win){var a={};return"undefined"!=typeof this.win.pageYOffset?a.y=this.win.pageYOffset:a.y=(this.doc.documentElement||this.doc.body.parentNode||this.doc.body).scrollTop,"undefined"!=typeof this.win.pageXOffset?a.x=this.win.pageXOffset:a.x=(this.doc.documentElement||this.doc.body.parentNode||this.doc.body).scrollLeft,a}},setScrollPos:function(a){a&&"undefined"!=typeof a.x&&"undefined"!=typeof a.y&&this.win.scrollTo(a.x,a.y)},getTextContent:function(){return b.getTextContent(this.element)},hasPlaceholderSet:function(){return this.getTextContent()==(this.config.noTextarea?this.editableArea.getAttribute("data-placeholder"):this.textarea.element.getAttribute("placeholder"))&&this.placeholderSet},isEmpty:function(){var a=this.element.innerHTML.toLowerCase();return/^(\s| |<\/br>||<\/p>)*$/i.test(a)||""===a||" "===a||"
"===a||"
"===a||this.hasPlaceholderSet()},_initContentEditableArea:function(){var a=this;this.config.noTextarea?this.sandbox=new b.ContentEditableArea(function(){a._create()},{className:this.config.classNames.sandbox},this.editableArea):(this.sandbox=new b.ContentEditableArea(function(){a._create()},{className:this.config.classNames.sandbox}),this.editableArea=this.sandbox.getContentEditable(),b.insert(this.editableArea).after(this.textarea.element),this._createWysiwygFormField())},_initSandbox:function(){var a=this;this.sandbox=new b.Sandbox(function(){a._create()},{stylesheets:this.config.stylesheets,className:this.config.classNames.sandbox}),this.editableArea=this.sandbox.getIframe();var c=this.textarea.element;b.insert(this.editableArea).after(c),this._createWysiwygFormField()},_createWysiwygFormField:function(){if(this.textarea.element.form){var a=document.createElement("input");a.type="hidden",a.name="_wysihtml5_mode",a.value=1,b.insert(a).after(this.textarea.element)}},_create:function(){var d=this;this.doc=this.sandbox.getDocument(),this.win=this.sandbox.getWindow(),this.element=this.config.contentEditableMode?this.sandbox.getContentEditable():this.doc.body,this.config.noTextarea?this.cleanUp():(this.textarea=this.parent.textarea,this.element.innerHTML=this.textarea.getValue(!0,!1)),this.selection=new a.Selection(this.parent,this.element,this.config.classNames.uneditableContainer),this.commands=new a.Commands(this.parent),this.config.noTextarea||b.copyAttributes(["className","spellcheck","title","lang","dir","accessKey"]).from(this.textarea.element).to(this.element),this._initAutoLinking(),b.addClass(this.element,this.config.classNames.composer),this.config.style&&!this.config.contentEditableMode&&this.style(),this.observe();var e=this.config.name;e&&(b.addClass(this.element,e),this.config.contentEditableMode||b.addClass(this.editableArea,e)),this.enable(),!this.config.noTextarea&&this.textarea.element.disabled&&this.disable();var f="string"==typeof this.config.placeholder?this.config.placeholder:this.config.noTextarea?this.editableArea.getAttribute("data-placeholder"):this.textarea.element.getAttribute("placeholder");f&&b.simulatePlaceholder(this.parent,this,f,this.config.classNames.placeholder),this.commands.exec("styleWithCSS",!1),this._initObjectResizing(),this._initUndoManager(),this._initLineBreaking(),this.config.noTextarea||!this.textarea.element.hasAttribute("autofocus")&&document.querySelector(":focus")!=this.textarea.element||c.isIos()||setTimeout(function(){d.focus(!0)},100),c.clearsContentEditableCorrectly()||a.quirks.ensureProperClearing(this),this.initSync&&this.config.sync&&this.initSync(),this.config.noTextarea||this.textarea.hide(),this.parent.fire("beforeload").fire("load")},_initAutoLinking:function(){var d=this,e=c.canDisableAutoLinking(),f=c.doesAutoLinkingInContentEditable();if(e&&this.commands.exec("AutoUrlDetect",!1,!1),this.config.autoLink){(!f||f&&e)&&(this.parent.on("newword:composer",function(){if(b.getTextContent(d.element).match(b.autoLink.URL_REG_EXP)){for(var c=d.selection.getSelectedNode(),e=d.element.querySelectorAll("."+d.config.classNames.uneditableContainer),f=!1,g=e.length;g--;)a.dom.contains(e[g],c)&&(f=!0);f||b.autoLink(c,[d.config.classNames.uneditableContainer])}}),b.observe(this.element,"blur",function(){b.autoLink(d.element,[d.config.classNames.uneditableContainer])}));var g=this.sandbox.getDocument().getElementsByTagName("a"),h=b.autoLink.URL_REG_EXP,i=function(c){var d=a.lang.string(b.getTextContent(c)).trim();return"www."===d.substr(0,4)&&(d="http://"+d),d};b.observe(this.element,"keydown",function(a){if(g.length){var c,e=d.selection.getSelectedNode(a.target.ownerDocument),f=b.getParentElement(e,{query:"a"},4);f&&(c=i(f),setTimeout(function(){var a=i(f);a!==c&&a.match(h)&&f.setAttribute("href",a)},0))}})}},_initObjectResizing:function(){if(this.commands.exec("enableObjectResizing",!0),c.supportsEvent("resizeend")){var d=["width","height"],e=d.length,f=this.element;b.observe(f,"resizeend",function(b){var c,g=b.target||b.srcElement,h=g.style,i=0;if("IMG"===g.nodeName){for(;e>i;i++)c=d[i],h[c]&&(g.setAttribute(c,parseInt(h[c],10)),h[c]="");a.quirks.redraw(f)}})}},_initUndoManager:function(){this.undoManager=new a.UndoManager(this.parent)},_initLineBreaking:function(){function d(a){var c=b.getParentElement(a,{query:"p, div"},2);c&&b.contains(e.element,c)&&e.selection.executeAndRestoreRangy(function(){e.config.useLineBreaks?((!c.firstChild||c.firstChild===c.lastChild&&1===c.firstChild.nodeType&&c.firstChild.classList.contains("rangySelectionBoundary"))&&c.appendChild(e.doc.createElement("br")),b.replaceWithChildNodes(c)):"P"!==c.nodeName&&b.renameElement(c,"p")})}var e=this,f="li, p, h1, h2, h3, h4, h5, h6",g="ul, ol, menu";this.config.useLineBreaks||b.observe(this.element,["focus"],function(){e.isEmpty()&&setTimeout(function(){var a=e.doc.createElement("P");e.element.innerHTML="",e.element.appendChild(a),c.displaysCaretInEmptyContentEditableCorrectly()?e.selection.selectNode(a,!0):(a.innerHTML=" ",e.selection.setBefore(a.firstChild))},0)}),b.observe(this.element,"keydown",function(c){var h=c.keyCode;if(!(c.shiftKey||c.ctrlKey||c.defaultPrevented||h!==a.ENTER_KEY&&h!==a.BACKSPACE_KEY)){var i=b.getParentElement(e.selection.getSelectedNode(),{query:f},4);return i?void setTimeout(function(){var c,f=e.selection.getSelectedNode();if("LI"===i.nodeName){if(!f)return;c=b.getParentElement(f,{query:g},2),c||d(f)}h===a.ENTER_KEY&&i.nodeName.match(/^H[1-6]$/)&&d(f)},0):void(e.config.useLineBreaks&&h===a.ENTER_KEY&&!a.browser.insertsLineBreaksOnReturn()&&(c.preventDefault(),e.commands.exec("insertLineBreak")))}})}})}(wysihtml5),function(a){var b=a.dom,c=document,d=window,e=c.createElement("div"),f=["background-color","color","cursor","font-family","font-size","font-style","font-variant","font-weight","line-height","letter-spacing","text-align","text-decoration","text-indent","text-rendering","word-break","word-wrap","word-spacing"],g=["background-color","border-collapse","border-bottom-color","border-bottom-style","border-bottom-width","border-left-color","border-left-style","border-left-width","border-right-color","border-right-style","border-right-width","border-top-color","border-top-style","border-top-width","clear","display","float","margin-bottom","margin-left","margin-right","margin-top","outline-color","outline-offset","outline-width","outline-style","padding-left","padding-right","padding-top","padding-bottom","position","top","left","right","bottom","z-index","vertical-align","text-align","-webkit-box-sizing","-moz-box-sizing","-ms-box-sizing","box-sizing","-webkit-box-shadow","-moz-box-shadow","-ms-box-shadow","box-shadow","-webkit-border-top-right-radius","-moz-border-radius-topright","border-top-right-radius","-webkit-border-bottom-right-radius","-moz-border-radius-bottomright","border-bottom-right-radius","-webkit-border-bottom-left-radius","-moz-border-radius-bottomleft","border-bottom-left-radius","-webkit-border-top-left-radius","-moz-border-radius-topleft","border-top-left-radius","width","height"],h=["html { height: 100%; }","body { height: 100%; padding: 1px 0 0 0; margin: -1px 0 0 0; }","body > p:first-child { margin-top: 0; }","._wysihtml5-temp { display: none; }",a.browser.isGecko?"body.placeholder { color: graytext !important; }":"body.placeholder { color: #a9a9a9 !important; }","img:-moz-broken { -moz-force-broken-image-icon: 1; height: 24px; width: 24px; }"],i=function(a){if(a.setActive)try{a.setActive()}catch(e){}else{var f=a.style,g=c.documentElement.scrollTop||c.body.scrollTop,h=c.documentElement.scrollLeft||c.body.scrollLeft,i={position:f.position,top:f.top,left:f.left,WebkitUserSelect:f.WebkitUserSelect};b.setStyles({position:"absolute",top:"-99999px",left:"-99999px",WebkitUserSelect:"none"}).on(a),a.focus(),b.setStyles(i).on(a),d.scrollTo&&d.scrollTo(h,g)}};a.views.Composer.prototype.style=function(){var d,j=this,k=c.querySelector(":focus"),l=this.textarea.element,m=l.hasAttribute("placeholder"),n=m&&l.getAttribute("placeholder"),o=l.style.display,p=l.disabled;this.focusStylesHost=e.cloneNode(!1),this.blurStylesHost=e.cloneNode(!1),this.disabledStylesHost=e.cloneNode(!1),m&&l.removeAttribute("placeholder"),l===k&&l.blur(),l.disabled=!1,l.style.display=d="none",(l.getAttribute("rows")&&"auto"===b.getStyle("height").from(l)||l.getAttribute("cols")&&"auto"===b.getStyle("width").from(l))&&(l.style.display=d=o),b.copyStyles(g).from(l).to(this.editableArea).andTo(this.blurStylesHost),b.copyStyles(f).from(l).to(this.element).andTo(this.blurStylesHost),b.insertCSS(h).into(this.element.ownerDocument),l.disabled=!0,b.copyStyles(g).from(l).to(this.disabledStylesHost),b.copyStyles(f).from(l).to(this.disabledStylesHost),l.disabled=p,l.style.display=o,i(l),l.style.display=d,b.copyStyles(g).from(l).to(this.focusStylesHost),b.copyStyles(f).from(l).to(this.focusStylesHost),l.style.display=o,b.copyStyles(["display"]).from(l).to(this.editableArea);var q=a.lang.array(g).without(["display"]);return k?k.focus():l.blur(),m&&l.setAttribute("placeholder",n),this.parent.on("focus:composer",function(){b.copyStyles(q).from(j.focusStylesHost).to(j.editableArea),b.copyStyles(f).from(j.focusStylesHost).to(j.element)}),this.parent.on("blur:composer",function(){b.copyStyles(q).from(j.blurStylesHost).to(j.editableArea),b.copyStyles(f).from(j.blurStylesHost).to(j.element)}),this.parent.observe("disable:composer",function(){b.copyStyles(q).from(j.disabledStylesHost).to(j.editableArea),b.copyStyles(f).from(j.disabledStylesHost).to(j.element)}),this.parent.observe("enable:composer",function(){b.copyStyles(q).from(j.blurStylesHost).to(j.editableArea),b.copyStyles(f).from(j.blurStylesHost).to(j.element)}),this}}(wysihtml5),function(a){var b=a.dom,c=b.domNode,d=a.browser,e={66:"bold",73:"italic",85:"underline"},f={addListeners:function(a,b,c){for(var d=0,e=b.length;e>d;d++)a.addEventListener(b[d],c,!1)},removeListeners:function(a,b,c){for(var d=0,e=b.length;e>d;d++)a.removeEventListener(b[d],c,!1)},fixLastBrDeletionInTable:function(b,c){if(b.selection.caretIsLastInSelection()){var d=b.selection.getSelection(),e=d.anchorNode;if(e&&1===e.nodeType&&(a.dom.getParentElement(e,{query:"td, th"},!1,b.element)||c)){var f=e.childNodes[d.anchorOffset];if(f&&1===f.nodeType&"BR"===f.nodeName)return f.parentNode.removeChild(f),!0}}return!1},handleUneditableDeletion:function(a){var b=a.selection.getBeforeSelection(!0);if(b&&("element"===b.type||"leafnode"===b.type)&&1===b.node.nodeType&&b.node.classList.contains(a.config.classNames.uneditableContainer)){if(f.fixLastBrDeletionInTable(a,!0))return!0;try{var c=new CustomEvent("wysihtml5:uneditable:delete",{bubbles:!0,cancelable:!1});b.node.dispatchEvent(c)}catch(d){}return b.node.parentNode.removeChild(b.node),!0}return!1},fixDeleteInTheBeginningOfBlock:function(b){var d=b.selection,e=d.getPreviousNode();if(d.caretIsFirstInSelection(a.browser.usesControlRanges())&&e&&1===e.nodeType&&a.dom.domNode(e).is.block()&&!c(e).test({query:"ol, ul, table, tr, dl"})){if(/^\s*$/.test(e.textContent||e.innerText))return e.parentNode.removeChild(e),!0;if(e.lastChild){var f=e.lastChild,g=d.getSelectedNode(),h=c(e).commonAncestor(g,b.element),i=a.dom.getParentElement(g,{query:"h1, h2, h3, h4, h5, h6, p, pre, div, blockquote"},!1,h||b.element);if(i)return c(i).transferContentTo(e,!0),d.setAfter(f),!0;if(a.browser.usesControlRanges())return g=d.getCaretNode(),c(g).transferContentTo(e,!0),d.setAfter(f),!0}}return!1},fixDeleteInTheBeginningOfLi:function(b){if(a.browser.hasLiDeletingProblem()){var d,e,f=b.selection.getSelection(),g=f.anchorNode,h=b.selection.caretIsFirstInSelection();if(3===g.nodeType&&0===f.anchorOffset&&g===g.parentNode.firstChild&&(g=g.parentNode,h=!0),h&&g&&1===g.nodeType&&"LI"===g.nodeName&&(d=c(g).prev({nodeTypes:[1,3],ignoreBlankTexts:!0}),d||!g.parentNode||"UL"!==g.parentNode.nodeName&&"OL"!==g.parentNode.nodeName||(d=c(g.parentNode).prev({nodeTypes:[1,3],ignoreBlankTexts:!0})),d))return e=g.firstChild,c(g).transferContentTo(d,!0),e?b.selection.setBefore(e):d&&(1===d.nodeType?d.lastChild?b.selection.setAfter(d.lastChild):b.selection.selectNode(d):b.selection.setAfter(d)),!0}return!1},fixDeleteInTheBeginningOfControlSelection:function(a){var b,d=a.selection,e=d.getPreviousNode(),f=d.getSelectedNode();return d.caretIsFirstInSelection()?(3===f.nodeType&&(f=f.parentNode),b=f.firstChild,c(f).transferContentTo(e,!0),b&&a.selection.setBefore(b),!0):!1},initTableHandling:function(){var b=function(){window.removeEventListener("load",b),this.doc.execCommand("enableObjectResizing",!1,"false"),this.doc.execCommand("enableInlineTableEditing",!1,"false")}.bind(this),c=function(){b.call(this),f.removeListeners(this.sandbox.getIframe(),["focus","mouseup","mouseover"],c)}.bind(this);this.doc.execCommand&&a.browser.supportsCommand(this.doc,"enableObjectResizing")&&a.browser.supportsCommand(this.doc,"enableInlineTableEditing")&&(this.sandbox.getIframe?f.addListeners(this.sandbox.getIframe(),["focus","mouseup","mouseover"],c):window.addEventListener("load",b)),this.tableSelection=a.quirks.tableCellsSelection(this.element,this.parent)},doLineBreaksModeEnterWithCaret:function(d){var e,f,g="p, pre, div, blockquote",h=!1;if(e=d.selection.getNodesNearCaret(),e&&((e.caretNode||e.nextNode)&&(f=b.getParentElement(e.caretNode||e.nextNode,{query:g},2),f===d.element&&(f=void 0)),f&&e.caretNode))if(c(e.caretNode).is.lineBreak()){if(d.config.doubleLineBreakEscapesBlock){h=!0,e.caretNode.parentNode.removeChild(e.caretNode),c(e.nextNode).is.lineBreak()&&e.nextNode.parentNode.removeChild(e.nextNode);var i=d.doc.createElement("br");c(e.nextNode).is.lineBreak()&&e.nextNode===f.lastChild?f.parentNode.insertBefore(i,f.nextSibling):d.selection.splitElementAtCaret(f,i),e.nextNode&&3===e.nextNode.nodeType&&(e.nextNode.data=e.nextNode.data.replace(/^ *[\r\n]+/,"")),
-d.selection.setBefore(i)}}else if(3===e.caretNode.nodeType&&a.browser.hasCaretBlockElementIssue()&&e.textOffset===e.caretNode.data.length&&!e.nextNode){h=!0;var j=d.doc.createElement("br"),k=d.doc.createElement("br"),l=d.doc.createDocumentFragment();l.appendChild(j),l.appendChild(k),d.selection.insertNode(l),d.selection.setBefore(k)}return h}},g=function(b,c){var d=c.selection;c.element;if(d.isCollapsed()){if(f.handleUneditableDeletion(c))return void b.preventDefault();if(f.fixDeleteInTheBeginningOfLi(c))return void b.preventDefault();if(f.fixDeleteInTheBeginningOfBlock(c))return void b.preventDefault();if(f.fixLastBrDeletionInTable(c))return void b.preventDefault();if(a.browser.usesControlRanges()&&f.fixDeleteInTheBeginningOfControlSelection(c))return void b.preventDefault()}else d.containsUneditable()&&(b.preventDefault(),d.deleteContents())},h=function(a,b){if(b.config.useLineBreaks&&!a.shiftKey&&!a.ctrlKey){b.selection.isCollapsed()&&f.doLineBreaksModeEnterWithCaret(b)&&a.preventDefault()}},i=function(a,b,c){if(a.selection.isCollapsed()){if(a.selection.caretIsInTheBeginnig("li"))if(c){if(a.commands.exec("outdentList"))return}else if(a.commands.exec("indentList"))return}else a.selection.deleteContents();a.commands.exec("insertHTML"," ")},j=function(a){this.domNodeRemovedInterval&&clearInterval(domNodeRemovedInterval),this.parent.fire("destroy:composer")},k=function(a){this.parent.fire("beforeinteraction",a).fire("beforeinteraction:composer",a),setTimeout(function(){this.parent.fire("interaction",a).fire("interaction:composer",a)}.bind(this),0)},l=function(a){this.parent.fire("focus",a).fire("focus:composer",a),setTimeout(function(){this.focusState=this.getValue(!1,!1)}.bind(this),0)},m=function(a){if(this.focusState!==this.getValue(!1,!1)){var b=a;"function"==typeof Object.create&&(b=Object.create(a,{type:{value:"change"}})),this.parent.fire("change",b).fire("change:composer",b)}this.parent.fire("blur",a).fire("blur:composer",a)},n=function(a){this.parent.fire(a.type,a).fire(a.type+":composer",a),"paste"===a.type&&setTimeout(function(){this.parent.fire("newword:composer")}.bind(this),0)},o=function(b){this.config.copyedFromMarking&&(a.browser.supportsModernPaste()&&(b.clipboardData.setData("text/html",this.config.copyedFromMarking+this.selection.getHtml()),b.clipboardData.setData("text/plain",this.selection.getPlainText()),b.preventDefault()),this.parent.fire(b.type,b).fire(b.type+":composer",b))},p=function(b){var c=b.keyCode;(c===a.SPACE_KEY||c===a.ENTER_KEY)&&this.parent.fire("newword:composer")},q=function(b){if(!d.canSelectImagesInContentEditable()){var c=b.target,e=this.element.querySelectorAll("img"),f=this.element.querySelectorAll("."+this.config.classNames.uneditableContainer+" img"),g=a.lang.array(e).without(f);"IMG"===c.nodeName&&a.lang.array(g).contains(c)&&this.selection.selectNode(c)}a.browser.usesControlRanges()&&(this.selection.lastMouseDownPos={x:b.clientX,y:b.clientY},setTimeout(function(){delete this.selection.lastMouseDownPos}.bind(this),0))},r=function(a){var b=(a.target,this.selection.lastMouseDownPos);if(b){var c=document.body.createTextRange();setTimeout(function(){try{c.moveToPoint(b.x,b.y),c.select()}catch(a){}}.bind(this),0)}},s=function(b){if(this.config.classNames.uneditableContainer){var c=a.dom.getParentElement(b.target,{query:"."+this.config.classNames.uneditableContainer},!1,this.element);c&&this.selection.setAfter(c)}},t=function(a){d.canSelectImagesInContentEditable()||setTimeout(function(){this.selection.getSelection().removeAllRanges()}.bind(this),0)},u=function(b){var c,d,f=b.keyCode,j=e[f];return!b.ctrlKey&&!b.metaKey||b.altKey||65!==f?((b.ctrlKey||b.metaKey)&&!b.altKey&&j&&(this.commands.exec(j),b.preventDefault()),f===a.BACKSPACE_KEY&&g(b,this),(f===a.BACKSPACE_KEY||f===a.DELETE_KEY)&&(c=this.selection.getSelectedNode(!0),c&&"IMG"===c.nodeName&&(b.preventDefault(),d=c.parentNode,d.removeChild(c),"A"!==d.nodeName||d.firstChild||d.parentNode.removeChild(d),setTimeout(function(){a.quirks.redraw(this.element)}.bind(this),0))),this.config.handleTabKey&&f===a.TAB_KEY&&(b.preventDefault(),i(this,this.element,b.shiftKey)),void(f===a.ENTER_KEY&&h(b,this))):(this.selection.selectAll(),void b.preventDefault())};a.views.Composer.prototype.observeActions=f,a.views.Composer.prototype.observe=function(){var c=this.sandbox.getIframe?this.sandbox.getIframe():this.sandbox.getContentEditable(),e=(this.element,d.supportsEventsInIframeCorrectly()||this.sandbox.getContentEditable?this.element:this.sandbox.getWindow());this.focusState=this.getValue(!1,!1),c.addEventListener(["DOMNodeRemoved"],j.bind(this),!1),d.supportsMutationEvents()||(this.domNodeRemovedInterval=setInterval(function(){b.contains(document.documentElement,c)||j.call(this)},250)),this.config.handleTables&&f.initTableHandling.call(this),f.addListeners(e,["drop","paste","mouseup","focus","keyup"],k.bind(this)),e.addEventListener("focus",l.bind(this),!1),e.addEventListener("blur",m.bind(this),!1),f.addListeners(this.element,["drop","paste","beforepaste"],n.bind(this),!1),this.element.addEventListener("copy",o.bind(this),!1),this.element.addEventListener("mousedown",q.bind(this),!1),this.element.addEventListener("click",s.bind(this),!1),this.element.addEventListener("drop",t.bind(this),!1),this.element.addEventListener("keyup",p.bind(this),!1),this.element.addEventListener("keydown",u.bind(this),!1),a.browser.usesControlRanges()&&this.element.addEventListener("mscontrolselect",r.bind(this),!1),this.element.addEventListener("dragenter",function(){this.parent.fire("unset_placeholder")}.bind(this),!1)}}(wysihtml5),function(a){var b=400;a.views.Synchronizer=Base.extend({constructor:function(a,b,c){this.editor=a,this.textarea=b,this.composer=c,this._observe()},fromComposerToTextarea:function(b){this.textarea.setValue(a.lang.string(this.composer.getValue(!1,!1)).trim(),b)},fromTextareaToComposer:function(a){var b=this.textarea.getValue(!1,!1);b?this.composer.setValue(b,a):(this.composer.clear(),this.editor.fire("set_placeholder"))},sync:function(a){"textarea"===this.editor.currentView.name?this.fromTextareaToComposer(a):this.fromComposerToTextarea(a)},_observe:function(){var c,d=this,e=this.textarea.element.form,f=function(){c=setInterval(function(){d.fromComposerToTextarea()},b)},g=function(){clearInterval(c),c=null};f(),e&&(a.dom.observe(e,"submit",function(){d.sync(!0)}),a.dom.observe(e,"reset",function(){setTimeout(function(){d.fromTextareaToComposer()},0)})),this.editor.on("change_view",function(a){"composer"!==a||c?"textarea"===a&&(d.fromComposerToTextarea(!0),g()):(d.fromTextareaToComposer(!0),f())}),this.editor.on("destroy:composer",g)}})}(wysihtml5),function(a){a.views.SourceView=Base.extend({constructor:function(a,b){this.editor=a,this.composer=b,this._observe()},switchToTextarea:function(a){var b=this.composer.win.getComputedStyle(this.composer.element),c=parseFloat(b.width),d=Math.max(parseFloat(b.height),100);this.textarea||(this.textarea=this.composer.doc.createElement("textarea"),this.textarea.className="wysihtml5-source-view"),this.textarea.style.width=c+"px",this.textarea.style.height=d+"px",this.textarea.value=this.editor.getValue(a,!0),this.composer.element.parentNode.insertBefore(this.textarea,this.composer.element),this.editor.currentView="source",this.composer.element.style.display="none"},switchToComposer:function(a){var b=this.textarea.value;b?this.composer.setValue(b,a):(this.composer.clear(),this.editor.fire("set_placeholder")),this.textarea.parentNode.removeChild(this.textarea),this.editor.currentView=this.composer,this.composer.element.style.display=""},_observe:function(){this.editor.on("change_view",function(a){"composer"===a?this.switchToComposer(!0):"textarea"===a&&this.switchToTextarea(!0)}.bind(this))}})}(wysihtml5),wysihtml5.views.Textarea=wysihtml5.views.View.extend({name:"textarea",constructor:function(a,b,c){this.base(a,b,c),this._observe()},clear:function(){this.element.value=""},getValue:function(a){var b=this.isEmpty()?"":this.element.value;return a!==!1&&(b=this.parent.parse(b)),b},setValue:function(a,b){b!==!1&&(a=this.parent.parse(a)),this.element.value=a},cleanUp:function(a){var b=this.parent.parse(this.element.value,void 0,a);this.element.value=b},hasPlaceholderSet:function(){var a=wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),b=this.element.getAttribute("placeholder")||null,c=this.element.value,d=!c;return a&&d||c===b},isEmpty:function(){return!wysihtml5.lang.string(this.element.value).trim()||this.hasPlaceholderSet()},_observe:function(){var a=this.element,b=this.parent,c={focusin:"focus",focusout:"blur"},d=wysihtml5.browser.supportsEvent("focusin")?["focusin","focusout","change"]:["focus","blur","change"];b.on("beforeload",function(){wysihtml5.dom.observe(a,d,function(a){var d=c[a.type]||a.type;b.fire(d).fire(d+":textarea")}),wysihtml5.dom.observe(a,["paste","drop"],function(){setTimeout(function(){b.fire("paste").fire("paste:textarea")},0)})})}}),function(a){var b,c={name:b,style:!0,toolbar:b,showToolbarAfterInit:!0,showToolbarDialogsOnSelection:!0,autoLink:!0,handleTables:!0,handleTabKey:!0,parserRules:{tags:{br:{},span:{},div:{},p:{},b:{},i:{},u:{}},classes:{}},pasteParserRulesets:null,parser:a.dom.parse,useLineBreaks:!0,doubleLineBreakEscapesBlock:!0,stylesheets:[],placeholderText:b,supportTouchDevices:!0,cleanUp:!0,contentEditableMode:!1,classNames:{composer:"wysihtml5-editor",body:"wysihtml5-supported",sandbox:"wysihtml5-sandbox",placeholder:"wysihtml5-placeholder",uneditableContainer:"wysihtml5-uneditable-container"},copyedFromMarking:' '};a.Editor=a.lang.Dispatcher.extend({constructor:function(b,d){if(this.editableElement="string"==typeof b?document.getElementById(b):b,this.config=a.lang.object({}).merge(c).merge(d).get(),this._isCompatible=a.browser.supported(),d&&d.classNames&&a.lang.object(this.config.classNames).merge(d.classNames),"textarea"!=this.editableElement.nodeName.toLowerCase()&&(this.config.contentEditableMode=!0,this.config.noTextarea=!0),this.config.noTextarea||(this.textarea=new a.views.Textarea(this,this.editableElement,this.config),this.currentView=this.textarea),!this._isCompatible||!this.config.supportTouchDevices&&a.browser.isTouchDevice()){var e=this;return void setTimeout(function(){e.fire("beforeload").fire("load")},0)}a.dom.addClass(document.body,this.config.classNames.body),this.composer=new a.views.Composer(this,this.editableElement,this.config),this.currentView=this.composer,"function"==typeof this.config.parser&&this._initParser(),this.on("beforeload",this.handleBeforeLoad)},handleBeforeLoad:function(){this.config.noTextarea?this.sourceView=new a.views.SourceView(this,this.composer):this.synchronizer=new a.views.Synchronizer(this,this.textarea,this.composer),this.config.toolbar&&(this.toolbar=new a.toolbar.Toolbar(this,this.config.toolbar,this.config.showToolbarAfterInit))},isCompatible:function(){return this._isCompatible},clear:function(){return this.currentView.clear(),this},getValue:function(a,b){return this.currentView.getValue(a,b)},setValue:function(a,b){return this.fire("unset_placeholder"),a?(this.currentView.setValue(a,b),this):this.clear()},cleanUp:function(a){this.currentView.cleanUp(a)},focus:function(a){return this.currentView.focus(a),this},disable:function(){return this.currentView.disable(),this},enable:function(){return this.currentView.enable(),this},isEmpty:function(){return this.currentView.isEmpty()},hasPlaceholderSet:function(){return this.currentView.hasPlaceholderSet()},destroy:function(){this.composer&&this.composer.sandbox&&this.composer.sandbox.destroy(),this.toolbar&&this.toolbar.destroy(),this.off()},parse:function(b,c,d){var e=this.config.contentEditableMode?document:this.composer?this.composer.sandbox.getDocument():null,f=this.config.parser(b,{rules:d||this.config.parserRules,cleanUp:this.config.cleanUp,context:e,uneditableClass:this.config.classNames.uneditableContainer,clearInternals:c});return"object"==typeof b&&a.quirks.redraw(b),f},_initParser:function(){var b;a.browser.supportsModernPaste()?this.on("paste:composer",function(c){c.preventDefault(),b=a.dom.getPastedHtml(c),b&&this._cleanAndPaste(b)}.bind(this)):this.on("beforepaste:composer",function(b){b.preventDefault();var c=this.composer.getScrollPos();a.dom.getPastedHtmlWithDiv(this.composer,function(a){a&&this._cleanAndPaste(a),this.composer.setScrollPos(c)}.bind(this))}.bind(this))},_cleanAndPaste:function(b){var c=a.quirks.cleanPastedHTML(b,{referenceNode:this.composer.element,rules:this.config.pasteParserRulesets||[{set:this.config.parserRules}],uneditableClass:this.config.classNames.uneditableContainer});this.composer.selection.deleteContents(),this.composer.selection.insertHTML(c)}})}(wysihtml5);
-//# sourceMappingURL=wysihtml.min.map
\ No newline at end of file
diff --git a/dist/wysihtml.min.map b/dist/wysihtml.min.map
deleted file mode 100644
index f632a9d..0000000
--- a/dist/wysihtml.min.map
+++ /dev/null
@@ -1 +0,0 @@
-{"version":3,"file":"wysihtml.min.js","sources":["wysihtml.js"],"names":["wysihtml5","version","commands","dom","quirks","toolbar","lang","selection","views","INVISIBLE_SPACE","INVISIBLE_SPACE_REG_EXP","VOID_ELEMENTS","EMPTY_FUNCTION","ELEMENT_NODE","TEXT_NODE","BACKSPACE_KEY","ENTER_KEY","ESCAPE_KEY","SPACE_KEY","TAB_KEY","DELETE_KEY","polyfills","win","doc","nativeCustomEventSupported","p","CustomEvent","detail","foo","type","e","String","prototype","trim","rtrim","this","replace","s_add","s_rem","Element","on","fn","self","attachEvent","event","target","srcElement","preventDefault","returnValue","stopPropagation","cancelBubble","which","button","keyCode","call","detachEvent","Object","defineProperty","getOwnPropertyDescriptor","get","innerText","set","s","Array","isArray","arg","toString","indexOf","a","f","c","length","r","d","Function","bind","oThis","TypeError","aArgs","slice","arguments","fToBind","fNOP","fBound","apply","concat","ELEMENT","matches","mozMatchesSelector","msMatchesSelector","oMatchesSelector","webkitMatchesSelector","selector","element","elements","document","ownerDocument","querySelectorAll","index","closest","parentElement","createElement","testElement","classList","add","contains","createMethod","method","original","DOMTokenList","token","i","len","toggle","_toggle","force","view","classListProp","protoProp","elemCtrProto","objCtr","strTrim","arrIndexOf","item","DOMEx","message","name","code","DOMException","checkTokenAndGetIndex","test","ClassList","elem","trimmedClasses","getAttribute","classes","split","push","_updateClassName","setAttribute","classListProto","classListGetter","Error","tokens","l","updated","remove","splice","result","join","classListPropDesc","enumerable","configurable","ex","number","__defineGetter__","normalizeHasCaretError","window","ret","t1","createTextNode","t2","t3","createRange","appendChild","body","setStart","setEnd","getSelection","removeAllRanges","addRange","normalize","childNodes","anchorNode","firstChild","anchorOffset","parentNode","removeChild","getTextNodes","node","all","nextSibling","nodeType","isInDom","n","normalizeFix","nf","Node","texts","defaultView","anode","aoffset","aelement","undefined","fnode","focusNode","foffset","focusOffset","felement","prevTxt","shift","curText","nodeValue","compareDocumentPosition","DOCUMENT_POSITION_PRECEDING","DOCUMENT_POSITION_CONTAINS","previousSibling","F","removeEventListener","readyState","addEventListener","customEventSupported","params","bubbles","cancelable","evt","createEvent","initCustomEvent","Event","factory","root","define","amd","module","exports","rangy","isHostMethod","o","t","FUNCTION","OBJECT","isHostObject","isHostProperty","UNDEFINED","createMultiplePropertyTest","testFunc","props","isTextRange","range","areHostMethods","textRangeMethods","areHostProperties","textRangeProperties","getBody","getElementsByTagName","consoleLog","msg","console","log","alertOrLog","shouldAlert","isBrowser","alert","fail","reason","api","initialized","supported","config","alertOnFail","warn","alertOnWarn","getErrorDesc","description","init","testRange","implementsDomRange","implementsTextRange","domRangeMethods","domRangeProperties","nodeName","toLowerCase","createTextRange","features","errorMessage","moduleName","modules","Module","initListeners","deprecationNotice","deprecated","replacement","createAliasForDeprecatedMethod","owner","util","toArray","shim","shimListeners","dependencies","initializer","createModule","initFunc","newModule","stack","RangePrototype","SelectionPrototype","areHostObjects","forEach","arr","func","preferTextRange","autoInitialize","rangyAutoInitialize","extend","hasOwnProperty","obj","deep","createOptions","optionsParam","defaults","options","el","arrayLike","addListener","eventType","listener","addInitListener","addShimListener","createMissingNativeApi","requiredModule","requiredModuleNames","createError","createCoreModule","rangePrototype","selectionPrototype","isHtmlNamespace","ns","namespaceURI","UNDEF","parent","getNodeIndex","getNodeLength","getCommonAncestor","node1","node2","ancestors","arrayContains","isAncestorOf","ancestor","descendant","selfIsAncestor","isOrIsAncestorOf","getClosestAncestorIn","isCharacterDataNode","isTextOrCommentNode","insertAfter","precedingNode","nextNode","insertBefore","splitDataNode","positionsToPreserve","newNode","cloneNode","deleteData","position","offset","getDocument","getWindow","parentWindow","getIframeDocument","iframeEl","contentDocument","contentWindow","getIframeWindow","isWindow","getContentDocument","methodName","tagName","getRootContainer","comparePoints","nodeA","offsetA","nodeB","offsetB","nodeC","childA","childB","isBrokenNode","inspectNode","crashyTextNodes","data","idAttr","id","innerHTML","fragmentFromNodeChildren","child","fragment","createDocumentFragment","createTestElement","html","contentEditable","bodyFirstChild","removeNode","NodeIterator","_next","createIterator","DomPosition","codeName","textNode","val","getComputedStyleProperty","getComputedStyle","propName","documentElement","currentStyle","_current","hasNext","next","detach","equals","pos","inspect","INDEX_SIZE_ERR","HIERARCHY_REQUEST_ERR","WRONG_DOCUMENT_ERR","NO_MODIFICATION_ALLOWED_ERR","NOT_FOUND_ERR","NOT_SUPPORTED_ERR","INVALID_STATE_ERR","INVALID_NODE_TYPE_ERR","isNonTextPartiallySelected","startContainer","endContainer","getRangeDocument","getRangeRoot","getBoundaryBeforeNode","getBoundaryAfterNode","insertNodeAtPosition","firstNodeInserted","rangesIntersect","rangeA","rangeB","touchingIsIntersecting","assertRangeValid","startComparison","startOffset","endOffset","endComparison","cloneSubtree","iterator","partiallySelected","subIterator","frag","isPartiallySelectedSubtree","getSubtreeIterator","iterateSubtree","rangeIterator","iteratorState","it","stop","subRangeIterator","deleteSubtree","extractSubtree","getNodesInRange","nodeTypes","filter","regex","filterNodeTypes","filterExists","RegExp","nodes","RangeIterator","sc","ec","getName","clonePartiallySelectedTextNodes","collapsed","so","eo","commonAncestorContainer","isSingleCharacterDataNode","_first","_last","createAncestorFinder","assertNoDocTypeNotationEntityAncestor","allowSelf","getDocTypeNotationEntityAncestor","assertValidNodeType","invalidTypes","assertValidOffset","assertSameDocumentOrFragment","getDocumentOrFragmentContainer","assertNodeNotReadOnly","getReadonlyAncestor","assertNode","isValidOffset","isRangeValid","splitRangeBoundaries","startEndSame","setStartAndEnd","rangeToHtml","container","cloneContents","copyComparisonConstantsToObject","START_TO_START","s2s","START_TO_END","s2e","END_TO_END","e2e","END_TO_START","e2s","NODE_BEFORE","n_b","NODE_AFTER","n_a","NODE_BEFORE_AND_AFTER","n_b_a","NODE_INSIDE","n_i","copyComparisonConstants","constructor","createRangeContentRemover","remover","boundaryUpdater","boundary","reset","createPrototypeRange","createBeforeAfterNodeSetter","isBefore","isStart","beforeAfterNodeTypes","rootContainerNodeTypes","setRangeStart","setRangeEnd","args","setBoundary","setStartBefore","setStartAfter","setEndBefore","setEndAfter","collapse","selectNodeContents","selectNode","start","end","extractContents","deleteContents","canSurroundContents","boundariesInvalid","splitBoundaries","splitBoundariesPreservingPositions","normalizeBoundaries","sibling","mergeForward","appendData","mergeBackward","nodeLength","insertData","nodeIndex","normalizeStart","endNode","startNode","collapseToPoint","updateCollapsedAndCommonAncestor","updateBoundaries","Range","current","subRange","cloneRange","readonlyNodeTypes","insertableNodeTypes","surroundNodeTypes","styleEl","htmlParsingConforms","createContextualFragment","fragmentStr","rangeProperties","compareBoundaryPoints","how","prefixA","prefixB","insertNode","clone","surroundContents","content","hasChildNodes","lastChild","prop","textParts","compareNode","comparePoint","toHtml","intersectsNode","isPointInRange","intersectsRange","intersectsOrTouchesRange","intersection","intersectionRange","union","unionRange","containsNode","allowPartial","containsNodeContents","containsRange","containsNodeText","nodeRange","textNodes","getNodes","lastTextNode","pop","collapseBefore","collapseAfter","getBookmark","containerNode","preSelectionRange","moveToBookmark","bookmark","charIndex","nextCharIndex","nodeStack","foundStart","rangesEqual","isValid","r1","r2","DomRange","WrappedRange","WrappedTextRange","updateRangeProperties","nativeRange","updateNativeRange","startMoved","endMoved","nativeRangeDifferent","rangeProto","refresh","testTextNode","oppositeName","range2","createNativeRange","getTextRangeContainerElement","textRange","parentEl","duplicate","startEl","endEl","startEndContainer","textRangeIsCollapsed","compareEndPoints","getTextRangeBoundaryPosition","wholeRangeContainerElement","isCollapsed","startInfo","workingRange","containerElement","canHaveHTML","boundaryPosition","nodeInfo","workingNode","comparison","previousNode","boundaryNode","workingComparisonType","childNodeCount","moveToElementText","Math","floor","setEndPoint","tempRange","rangeLength","text","moveStart","createBoundaryTextRange","boundaryParent","boundaryOffset","nodeIsDataNode","startBoundary","rangeContainerElement","rangeToTextRange","startRange","endRange","toTextRange","globalObj","createRangyRange","isDirectionBackward","dir","WrappedSelection","getWinSelection","winParam","getDocSelection","winSelectionIsBackward","sel","backward","updateAnchorAndFocusFromRange","anchorPrefix","focusPrefix","updateAnchorAndFocusFromNativeSelection","nativeSel","nativeSelection","updateEmptySelection","rangeCount","_ranges","getNativeRange","rangeContainsSingleElement","rangeNodes","getSingleElementFromRange","updateFromTextRange","wrappedRange","updateControlSelection","docSelection","controlRange","addRangeToControlSelection","rangeElement","newControlRange","createControlRange","select","deleteProperties","detached","actOnCachedSelection","action","cached","cachedRangySelections","createControlSelection","ranges","assertNodeInSameDocument","createStartOrEndSetter","getRangeAt","setSingleRange","isBackward","rangeInspects","anchor","focus","checkSelectionRanges","getNativeSelection","selectionIsCollapsed","BOOLEAN","NUMBER","CONTROL","implementsWinGetSelection","implementsDocSelection","useDocumentSelection","isSelectionValid","testSelection","selectionHasAnchorAndFocus","selectionHasExtend","selectionHasRangeCount","selectionSupportsMultipleRanges","collapsedNonEditableSelectionsSupported","addRangeBackwardToNative","originalSelectionRangeCount","selectionHasMultipleRanges","originalSelectionRanges","originalSelectionBackward","testEl","chromeMatch","navigator","appVersion","match","parseInt","testControlRange","implementsControlRange","getSelectionRangeAt","docSel","selProto","addRangeBackward","direction","previousRangeCount","clonedNativeRange","selectionIsBackward","setRanges","empty","refreshSelection","checkForChanges","oldRanges","oldAnchorNode","oldAnchorOffset","removeRangeManually","getAllRanges","removeRange","removed","isBackwards","rangeTexts","collapseToStart","collapseToEnd","selectAllChildren","deleteFromDocument","eachRange","callMethodOnEachRange","results","changeEachRange","rangeBookmarks","rangeBookmark","selRanges","saveRanges","restoreRanges","rangeHtmls","getNativeTextRange","detachAll","Selection","docReady","loadHandler","require","defaultTokenizer","chars","wordOptions","createTokenRange","isWord","tokenRanges","wordStart","wordEnd","word","lastWordEnd","wordRegex","exec","includeTrailingSpace","nonLineBreakWhiteSpaceRegex","convertCharRangeToToken","tokenRange","tokenChars","tokenize","tokenizer","normalizeIgnoredCharacters","ignoredCharacters","ignoredChars","ignoredCharsArray","sort","char1","char2","charCodeAt","createWordOptions","language","defaultLanguage","defaultWordOptions","createNestedOptions","characterOptions","defaultCharacterOptions","getComputedDisplay","display","tableCssDisplayBlock","defaultDisplayValueForTag","isHidden","getAncestorsAndSelf","isVisibilityHiddenTextNode","isBlockNode","containsPositions","getAncestors","unshift","nextNodeDescendants","excludeChildren","previous","isWhitespaceNode","computedWhiteSpace","isCollapsedWhitespaceNode","isCollapsedNode","isIgnoredNode","Cache","store","createCachingGetter","objProperty","cache","cachedCount","uncachedCount","value","NodeWrapper","session","positions","Position","nodeWrapper","inspectPosition","startSession","endSession","currentSession","Session","getSession","createCharacterIterator","startPos","endPos","charPos","finished","previousVisible","nextVisible","previousTextPos","returnPreviousTextPos","character","getCharacter","rewind","dispose","createTokenizedTextProvider","consumeWord","forward","textChar","newChars","forwardIterator","backwardIterator","passedWordBoundary","insideWord","allWhiteSpaceRegex","forwardChars","backwardChars","reverse","forwardTokensBuffer","arrayIndexOf","backwardTokensBuffer","nextEndToken","lastToken","previousStartToken","movePositionBy","unit","count","currentPos","charIterator","nextPos","unitsMoved","newPos","absCount","abs","CHARACTER","WORD","tokenizedTextProvider","isLeadingSpace","isTrailingSpace","createRangeCharacterIterator","rangeStart","getRangeBoundaryPosition","rangeEnd","itStart","itEnd","getRangeCharacters","isWholeWord","expand","findTextFromPosition","initialPos","searchTerm","isRegex","searchScopeRange","findOptions","handleMatch","startIndex","endIndex","valid","wholeWordsOnly","currentChar","matchStartIndex","matchEndIndex","insideRegexMatch","caseSensitive","createEntryPointFunction","sessionRunning","createRangeBoundaryMover","moveOptions","defaultMoveOptions","boundaryIsStart","moveResult","createRangeTrimmer","trimCharCount","trimmed","createSelectionTrimmer","spacesRegex","spacesMinusLineBreaksRegex","trailingSpaceInBlockCollapses","trailingSpaceBeforeBrCollapses","trailingSpaceBeforeBlockCollapses","trailingSpaceBeforeLineBreakInPreLineCollapses","includeBlockContentTrailingSpace","includeSpaceBeforeBr","includeSpaceBeforeBlock","includePreLineTrailingSpace","ignoreCharacters","defaultCaretCharacterOptions","en","defaultFindOptions","withinRange","wrap","defaultExpandOptions","trimStart","trimEnd","defaultWordIteratorOptions","table","caption","colgroup","col","thead","tbody","tfoot","tr","td","th","key","nodeProto","getPosition","EMPTY","NON_SPACE","UNCOLLAPSIBLE_SPACE","COLLAPSIBLE_SPACE","TRAILING_SPACE_BEFORE_BLOCK","TRAILING_SPACE_IN_BLOCK","TRAILING_SPACE_BEFORE_BR","PRE_LINE_TRAILING_SPACE_BEFORE_LINE_BREAK","TRAILING_LINE_BREAK_AFTER_BR","INCLUDED_TRAILING_LINE_BREAK_AFTER_BR","getLength","isWhitespace","isCollapsedWhitespace","isIgnored","getTextNodeInfo","spaceRegex","collapseSpaces","cssWhitespace","preLine","hasInnerText","posAfterEl","firstPosInEl","prepopulateChar","isDefinitelyNonEmpty","isRenderedBlock","brs","getTrailingSpace","getNodeWrapper","getLeadingSpace","positionProto","characterType","isBr","prepopulatedChar","visibleChar","charType","finalizedChar","charAt","nodePassed","checkForTrailingSpace","checkForLeadingSpace","isCharInvariant","resolveLeadingAndTrailingSpaces","trailingSpace","leadingSpace","getPrecedingUncollapsedPosition","getPreviousPos","gotPreviousPos","previousPos","returnChar","thisChar","isIgnoredCharacter","cacheKey","cachedChar","collapsible","nextUncollapsed","nextOffset","previousOffset","createWrapperCache","nodeProperty","wrappersByProperty","wrapper","property","initCaches","uniqueIDSupported","elementCache","elementsCache","uniqueID","elWrapper","textNodeCache","otherNodeCache","wrapperCache","prefix","moveEnd","move","startTrimmed","endTrimmed","expandOptions","moved","endToken","newEndPos","startTokenizedTextProvider","startToken","newStartPos","endTokenizedTextProvider","selectCharacters","toCharacterRange","rangeStartsBeforeNode","rangeBetween","findText","searchTermParam","findResult","wrappedAround","pasteHtml","saveCharacterRanges","rangeInfos","characterRange","restoreCharacterRanges","saved","rangeInfo","createWordIterator","iteratorOptions","noMutation","createPosition","gEBI","getElementById","insertRangeBoundaryMarker","atStart","markerEl","markerId","Date","random","boundaryRange","style","lineHeight","className","markerTextChar","setRangeBoundary","compareRanges","saveRange","startMarkerId","endMarkerId","restoreRange","saveSelection","restored","restoreSelection","savedSelection","preserveDirection","removeMarkerElement","removeMarkers","Base","_instance","_static","_prototyping","proto","base","klass","_constructing","implement","valueOf","source","toSource","hidden","object","block","context","browser","iosVersion","userAgent","androidVersion","isIE","equation","re","rv","appName","parseFloat","$1","isGecko","isWebKit","isChrome","isOpera","USER_AGENT","hasContentEditableSupport","hasEditingApiSupport","execCommand","queryCommandSupported","queryCommandState","hasQuerySelectorSupport","querySelector","isIncompatibleMobileBrowser","isIos","isAndroid","isTouchDevice","supportsEvent","supportsSandboxedIframes","throwsMixedContentWarningWhenIframeSrcIsEmpty","displaysCaretInEmptyContentEditableCorrectly","hasCurrentStyleProperty","insertsLineBreaksOnReturn","supportsPlaceholderAttributeOn","eventName","supportsEventsInIframeCorrectly","supportsHTML5Tags","html5","supportsCommand","buggyCommands","formatBlock","insertUnorderedList","insertOrderedList","insertHTML","command","isBuggy","e1","queryCommandEnabled","e2","doesAutoLinkingInContentEditable","canDisableAutoLinking","clearsContentEditableCorrectly","supportsGetAttributeCorrectly","canSelectImagesInContentEditable","autoScrollsToCaret","autoClosesUnclosedTags","clonedTestElement","supportsNativeGetElementsByClassName","getElementsByClassName","supportsSelectionModify","needsSpaceAfterLineBreak","supportsSpeechApiOn","input","chromeVersion","crashesWhenDefineProperty","doesAsyncFocus","hasProblemsSettingCaretAfterImg","hasLiDeletingProblem","hasUndoInContextMenu","hasInsertNodeIssue","hasIframeFocusIssue","createsNestedInvalidMarkupAfterPaste","hasCaretBlockElementIssue","supportsMutationEvents","supportsModernPaste","fixStyleKey","usesControlRanges","array","needle","without","arrayToSubstract","newArr","newArray","map","callback","thisArg","A","unique","vals","max","idx","Dispatcher","handler","events","off","handlers","newHandlers","fire","payload","observe","stopObserving","merge","otherObj","isPlainObject","difference","diffObj","newObj","isFunction","Text","isEmpty","WHITE_SPACE_START","WHITE_SPACE_END","ENTITY_REG_EXP","ENTITY_MAP","&","<",">","\"","\t","string","str","interpolate","vars","by","search","escapeHTML","linebreaks","convertSpaces","autoLink","ignoreInClasses","_hasParentThatShouldBeIgnored","_parseNode","_convertUrlsToLinks","URL_REG_EXP","url","punctuation","TRAILING_CHAR_REG_EXP","opening","BRACKETS","realUrl","displayUrl","MAX_DISPLAY_LENGTH","substr","_getTempElement","tempElement","_wysihtml5_tempElement","_wrapMatchesInNode","IGNORE_URLS_IN","childNodesLength",")","]","}","addClass","hasClass","removeClass","elementClassName","convertToList","_createListItem","list","listItem","_createList","listType","uneditableClass","childNode","lineBreak","isBlockElement","isLineBreak","currentListItem","lineBreaks","lineBreaksLength","getStyle","from","insert","after","replaceChild","copyAttributes","attributesToCopy","elementToCopyFrom","to","elementToCopyTo","attribute","andTo","callee","BOX_SIZING_PROPERTIES","shouldIgnoreBoxSizingBorderBox","hasBoxSizingBorderBox","offsetWidth","copyStyles","stylesToCopy","cssText","setStyles","delegate","parents","domNode","defaultNodeTypes","is","emptyTextNode","ignoreWhitespace","regx","rangyBookmark","visible","isVisible","getTextContent","voidElement","query","prev","prevNode","types","ignoreBlankTexts","commonAncestor","parents1","parents2","lastLeafNode","leafClasses","escapeParent","newWrapper","split2","nodeWrap","curNode","transferContentTo","targetNode","removeOldWrapper","properties","classRegExp","styleProperty","hasOneStyle","styles","j","maxStyleP","styleValue","attr","getAttributes","attrList","hasOneAttribute","attributeValue","getAsDom","_innerHTMLShiv","_ensureHTML5Compatibility","_wysihtml5_supportsHTML5Tags","HTML5_ELEMENTS","getParentElement","levels","camelize","REG_EXP_CAMELIZE","toUpperCase","stylePropertyMapping","float","camelizedProperty","originalOverflow","needsOverflowReset","overflow","getPropertyValue","ingoreEmpty","textContent","hasElementWithTagName","_getDocumentIdentifier","_wysihtml5_identifier","DOCUMENT_IDENTIFIER","LIVE_CACHE","cacheEntry","hasElementWithClassName","elementToInsert","before","into","insertCSS","rules","styleElement","styleSheet","link","head","_isLineBreak","_isLineBreakOrBlockElement","eventNames","handlerWrapper","parse","elementOrHtml_current","config_current","elementOrHtml","currentRules","defaultRules","isString","clearInternals","selectors","_applySelectorRules","_convert","cleanUp","unjoinNbsps","txtnodes","getCorrectInnerHTML","oldNode","newChild","nodeDisplay","oldNodeType","oldChilds","oldChildsLength","NODE_TYPE_MAPPING","blockElements","DEFAULT_NODE_NAME","attributes","selectorRules","els","elementHandlingMethods","_handleElement","rule","renameTag","tagRules","tags","scopeName","_wysihtml5","outerHTML","unwrap","rename_tag","one_of_type","_testTypes","remove_action","remove_action_rename_to","_handleAttributes","_handleStyles","definition","type_definitions","_testType","classesLength","styleProp","nodeClasses","nodeStyles","methods","m","typeCeckMethods","WHITE_SPACE_REG_EXP","sp","attrs","v","keep_styles","styleFloat","cssFloat","_getAttributesBeginningWith","beginning","returnAttributes","_checkAttribute","attributeName","newAttributeValue","attributeCheckMethods","_checkAttributes","local_attributes","newValue","matchingAttributes","globalAttributes","checkAttributes","oldAttributes","imax","currentClass","newClass","setClass","set_class","add_class","addStyle","add_style","setAttributes","set_attributes","allowedClasses","newClasses","oldClasses","check_attributes","addClassMethods","addStyleMethods","newStyle","classes_blacklist","src","width","height","_handleText","_handleComment","comments","createComment","1","3","8","REG_EXP","href","alt","numbers","dimension","any","align_text","mapping","left","right","center","align_img","justify","clear_br","both","size_font","2","4","5","6","7","-","+","has_visible_contet","txt","visibleElements","offsetHeight","removeEmptyTextNodes","renameElement","newNodeName","newElement","replaceWithChildNodes","_isBlockElement","_appendLineBreak","resolveList","useLineBreaks","isLastChild","shouldAppendLineBreak","paragraph","isLastItem","lastListItem","lastElementChild","firstElementChild","windowProperties","windowProperties2","documentProperties","Sandbox","readyCallback","editableArea","_createIframe","insertInto","getIframe","_readyError","destroy","iframe","that","security","allowtransparency","frameborder","marginwidth","marginheight","onload","onreadystatechange","_onLoadIframe","iframeWindow","iframeDocument","charset","characterSet","sandboxHtml","_getHtml","stylesheets","open","write","close","onerror","fileName","lineNumber","_unset","loaded","setTimeout","templateVars","setter","__defineSetter__","ContentEditableArea","getContentEditable","_bindElement","_createElement","_loadElement","contentExists","innerHtml","simulatePlaceholder","editor","placeholderText","placeholderClassName","CLASS_NAME","unset","composerIsVisible","hasPlaceholderSet","clear","placeholderSet","setValue","setTextContent","HAS_GET_ATTRIBUTE_BUG","isLoadedImage","hasAttribute","specified","complete","queryInList","q","removeElement","referenceNode","tag","MapCell","cell","isColspan","isRowspan","firstCol","lastCol","firstRow","lastRow","isReal","spanCollection","modified","TableModifyerByCell","addSpannedCellToMap","cspan","rspan","spanCollect","rmax","cmax","rr","cc","setCellAsModified","smax","setTableMap","ridx","row","cells","cidx","tableRows","getTableRows","getRowCells","inlineTables","inlineCells","allCells","tableCells","inlineRows","allRows","getMapIndex","r_length","c_length","r_idx","c_idx","getElementAtIndex","getMapElsTo","to_cell","idx_start","idx_end","temp_idx","temp_cidx","maxr","maxc","orderSelectionEnds","secondcell","createCells","nr","correctColIndexForUnreals","corrIdx","getLastNewCellOnRow","rowLimit","removeEmptyTable","splitRowToCells","colspan","cType","newCells","removeAttribute","getRealRowEl","injectRowAt","new_cells","n_cidx","canMerge","decreaseCellSpan","span","removeSurplusLines","allRowspan","fillMissingCells","r_max","c_max","prevcell","rectify","unmerge","thisCell","rowspan","collapseCellToNextRow","cellIdx","newRowIdx","newIdx","lastCell","removeRowCell","getRowElementsByCell","modRow","getColumnElementsByCell","removeRow","oldRow","removeColCell","removeColumn","what","addRow","where","newRow","addRowCell","cr","colSpanAttr","addColumn","addColCell","doAdd","handleCellAddWithRowspan","modCell","temp_r_cells","nrow","addRowsNr","crow","getCellsBetween","cell1","cell2","c1","addCells","removeCells","mergeCellsBetween","unmergeCell","findCell","findRowByCell","findColumnByCell","thisOwner","otherOwner","point","location_index","smallest_common_ancestor","this_index","other_index","children","getPastedHtml","clipboardData","getData","getPastedHtmlWithDiv","composer","selBookmark","cleanerDiv","scrollPos","getScrollPos","top","y","x","setBookmark","removeInvisibleSpaces","cleanPastedHTML","styleToRegex","styleStr","trimmedStr","escapedStr","extendRulesWithStyleExceptions","exceptStyles","newRules","pickRuleset","ruleset","defaultSet","condition","newHtml","color","fontSize","ensureProperClearing","clearIfNecessary","TILDE_ESCAPED","urlToSearch","elementsWithTilde","redraw","tableCellsSelection","editable","handleMouseDown","handleSelectionMousedown","removeCellSelections","selection_class","handleMouseMove","handleMouseUp","selectedCells","addSelections","oldEnd","curTable","deselect","bindSideclick","sideClickHandler","selectCells","getColorParseMethod","colorStr","colorTypeConf","colorParseMethods","getColorFormat","rgba","rgb","hex6","radix","hex3","makeParamRegExp","styleParser","parseColor","stylesStr","paramName","paramsRegex","colorType","colorMatch","unparseColor","colorFormat","hexRadix","parseFontSize","_getCumulativeOffsetTop","offsetTop","offsetParent","getDepth","getRangeNode","getWebkitSelectionFixNode","blankNode","placeholderRemover","delayedPlaceholderRemover","minWidth","expandRangeToSurround","common","start_depth","end_depth","contain","unselectableClass","getRange","setSelection","setBefore","createTemporaryCaretSpaceAfter","caretPlaceholder","caretPlaceholderText","keyDownHandler","setAfter","ctrlKey","metaKey","zIndex","notVisual","fixWebkitSelection","lastSibling","activeElement","setScrollPos","avoidInvisibleSpace","isElement","displayStyle","getSelectedNode","fixSelBorders","getSelectedOwnNodes","getOwnRanges","ownNodes","maxi","findNodesInSelection","curNodes","filterElements","containsUneditable","uneditables","getOwnUneditables","deleteRangeContents","startParent","endParent","ev","dispatchEvent","err","getCaretNode","getPreviousNode","ignoreEmpty","getNodesNearCaret","caretNode","textOffset","getSelectionParentsByTag","curEl","getRangeToNodeEnd","sNode","lastR","caretIsLastInSelection","endc","endtxt","caretIsFirstInSelection","includeLineBreaks","ws","whiteSpace","caretIsInTheBeginnig","ofNode","getBeforeSelection","includePrevLeaves","inTmpCaret","rng","prevLeaf","executeAndRestoreRangy","restoreScrollPosition","executeAndRestore","newCaretPlaceholder","prevSibling","newRange","oldScrollTop","scrollTop","oldScrollLeft","scrollLeft","placeholderHtml","lastEditorElement","canAppendChild","anchorNodeTagNameLower","voidElements","splitElementAtCaret","contentAfterRangeStart","surround","nodeOptions","cssStyle","scrollIntoView","tolerance","hasScrollBars","scrollHeight","_wysihtml5ScrollIntoViewElement","selectLine","_selectLine_W3C","getBoundingClientRect","_selectLineUniversal","includeRangyRangeHelpers","isHelperNode","initialBoundry","modify","toLineBoundary","location","getRangeRect","rect","testNode","amount","testRect","found","isLineBreakingElement","pnode","bottom","getText","getOwnNodes","splitBounds","fixRangeOverflow","containment","_detectInlineRangeProblems","previousElementSibling","_endOffsetForNode","dontFix","allUneditables","deepUneditables","tmpRanges","tmpRange","jmax","selectAll","blankEndNode","blankStartNode","doSelect","notSelected","getHtml","getPlainText","isEndToEndInNode","nodeNames","isInThisEditable","cssClass","regExp","matchingClassNames","hasStyleAttr","removeStyle","s2","getMatchingStyleRegexp","regexes","sSplit","elStyle","isMatchingAllready","areMatchingAllready","removeOrChangeStyle","exactRegex","hasSameClasses","el1","el2","REG_EXP_WHITE_SPACE","replaceWithOwnChildren","elementsHaveSameNonClassAttributes","attr1","attr2","getNamedItem","isSplitPoint","splitNodeAt","descendantNode","descendantOffset","Merge","firstNode","isElementMerge","firstTextNode","HTMLApplier","tagNames","similarClassRegExp","similarStyleRegExp","defaultTagName","applyToAnyTagName","doMerge","textBits","getAncestorWithClass","cssClassMatch","getAncestorWithStyle","cssStyleMatch","getMatchingAncestor","matchType","postApply","currentMerge","precedingTextNode","lastNode","merges","rangeStartNode","rangeEndNode","rangeStartOffset","rangeEndOffset","getAdjacentMergeableTextNode","nextTextNode","adjacentNode","isTextNode","areElementsMergeable","createContainer","applyToTextNode","isRemovable","undoToTextNode","ancestorWithClass","ancestorWithStyle","styleMode","styleChanged","ancestorRange","applyToRange","ri","undoToRange","getTextSelectedByRange","isAppliedToRange","appliedType","coverage","selectedText","toggleRange","parentsExactMatch","isApplied","Commands","support","commandValue","state","stateValue","bold","formatInline","getOptions","createLink","opts","removeLink","size","fontSizeStyle","st","foreColor","foreColorStyle","colorVals","colString","bgColorStyle","correctOptionsForSimilarityCheck","isBlock","isBookmark","isLineBreaking","cleanup","newBlockElements","nbIdx","allElements","BLOCK_ELEMENTS","noEditQuery","classNames","uneditableContainer","defaultNodeName","findOuterBlock","allBlocks","UNNESTABLE_BLOCK_ELEMENTS","cloneOuterInlines","innerNode","INLINE_ELEMENTS","outerNode","applyOptionsToElement","removeOptionsFromElement","unwrapped","applySurroundingLineBreaks","unwrapBlocksFromContent","nextEl","prevEl","blocks","fixRangeCoverage","fixNotPermittedInsertionPoints","lis","maxj","rangePos","closestLI","newRanges","getOptionsWithNodename","defaultName","correctedOptions","injectFragmentToRange","firstOuterBlock","outerInlines","first","last","rangeStartContainer","fc","lc","clearRangeBlockFromating","closestBlockName","removeSurroundingLineBreaks","prevPrev","wrapRangeWithElement","similarOptions","isWhitespaceBefore","isWhitespaceAfter","similarOuterBlock","splitAllBlocks","trimBlankTextsAndBreaks","tmpEl","getParentBlockNodeName","expandCaretToBlock","insertingNodeName","selectElements","lastEl","lastOffset","formatSelection","parseOptions","caretIsOnEmptyLine","caretInfo","parentNodes","formatCode","classname","selectedNodes","pre","selectedNode","hasNoClass","hasNoStyle","hasNoAttributes","isSameNode","element1","element2","classes1","classes2","createWrapNode","defaultTag","containsSameAttributes","updateElementAttributes","newAttributes","fullContain","updateFormatOfElement","nodeNameQuery","nodeQueryMatch","queryAliasMap","getSelectedTextNodes","findSimilarTextNodeWrapper","exact","isSimilarNode","selectRange","selectTextNodes","lastText","selectTextNode","getState","searchNodes","partial","caretIsInsideWord","beforeChar","afterChar","getRangeForWord","offsetStart","offsetEnd","txtNodes","wordOffset","mergeContents","mergeConsequentSimilarElements","cleanupAndSetSelection","cleanupAndSetCaret","formatTextNode","wrapNode","unformatTextNode","newWrapNode","removeFormatFromTextNode","formatTextRange","updateFormat","wordObj","exactState","removeFormat","applyFormat","fixOptions","b","strong","em","insertBlockQuote","NODE_NAME","insertImage","image","imagesInSelection","LINE_BREAK","insertLineBreak","insertList","isNode","findListEl","other","parentLi","otherNodeName","handleSameTypeList","otherLists","innerLists","getListsInSelection","handleOtherTypeList","renameLists","createListFallback","tempClassName","getTime","cmd","italic","justifyCenter","justifyLeft","justifyRight","justifyFull","alignRightStyle","alignLeftStyle","alignCenterStyle","alignJustifyStyle","redo","undoManager","underline","undo","createTable","cols","rows","tableStyle","mergeTableCells","tableSelection","addTableCells","tableSelect","deleteTableCells","selCell","indentList","listEls","tryToPushLiLevel","liNodes","listTag","prevLi","liNode","prevLiList","outdentList","tryToPullLiLevel","listNode","outerListNode","outerLiNode","afterList","getAfterList","newList","subscript","superscript","Z_KEY","Y_KEY","MAX_HISTORY_ENTRIES","DATA_ATTR_NODE","DATA_ATTR_OFFSET","UndoManager","historyStr","historyDom","transact","_observe","lastKey","sandbox","altKey","isUndo","shiftKey","isRedo","previousHtml","currentHtml","getValue","getChildNodeIndex","undoPossible","redoPossible","historyEntry","getChildNodeByIndex","View","textareaElement","noTextarea","_observeViewChange","currentView","show","hide","disable","enable","Composer","editableElement","textarea","contentEditableMode","_initContentEditableArea","_initSandbox","_displayStyle","disabled","setToEnd","pageYOffset","pageXOffset","scrollTo","_create","_createWysiwygFormField","form","hiddenField","_initAutoLinking","placeholder","_initObjectResizing","_initUndoManager","_initLineBreaking","initSync","sync","supportsDisablingOfAutoLinking","supportsAutoLinking","nodeWithSelection","isInUneditable","links","urlRegExp","newTextContent","propertiesLength","adjust","USE_NATIVE_LINE_BREAK_INSIDE_TAGS","LIST_TAGS","defaultPrevented","blockElement","HOST_TEMPLATE","TEXT_FORMATTING","BOX_FORMATTING","ADDITIONAL_CSS_RULES","focusWithoutScrolling","setActive","elementStyle","originalScrollTop","originalScrollLeft","originalStyles","WebkitUserSelect","displayValueForCopying","originalActiveElement","hasPlaceholder","originalPlaceholder","originalDisplayValue","originalDisabled","focusStylesHost","blurStylesHost","disabledStylesHost","blur","boxFormattingStyles","shortcuts","66","73","85","actions","addListeners","removeListeners","fixLastBrDeletionInTable","aNode","handleUneditableDeletion","fixDeleteInTheBeginningOfBlock","selNode","commonAncestorNode","fixDeleteInTheBeginningOfLi","isInBeginnig","fixDeleteInTheBeginningOfControlSelection","afterCaretNode","initTableHandling","hideHandlers","iframeInitiator","doLineBreaksModeEnterWithCaret","breakNodes","doubleLineBreakEscapesBlock","brNode","br1","br2","handleDeleteKeyPress","handleEnterKeyPress","handleTabKeyDown","handleDomNodeRemoved","domNodeRemovedInterval","clearInterval","handleUserInteraction","handleFocus","focusState","handleBlur","changeevent","create","handlePaste","handleCopy","copyedFromMarking","setData","handleKeyUp","allImages","notMyImages","myImages","lastMouseDownPos","clientX","clientY","handleIEControlSelect","caretPosition","moveToPoint","handleClick","uneditable","handleDrop","handleKeyDown","handleTabKey","observeActions","focusBlurElement","setInterval","handleTables","INTERVAL","Synchronizer","fromComposerToTextarea","shouldParseHtml","fromTextareaToComposer","textareaValue","interval","startInterval","stopInterval","SourceView","switchToTextarea","composerStyles","switchToComposer","Textarea","supportsPlaceholder","eventMapping","focusin","focusout","undef","defaultConfig","showToolbarAfterInit","showToolbarDialogsOnSelection","parserRules","br","div","u","pasteParserRulesets","parser","supportTouchDevices","Editor","_isCompatible","_initParser","handleBeforeLoad","sourceView","synchronizer","Toolbar","isCompatible","htmlOrElement","customRules","parseContext","oldHtml","_cleanAndPaste","pastedHTML","cleanHtml"],"mappings":";;AAWA,GAAIA,YACFC,QAAS,QAGTC,YACAC,OACAC,UACAC,WACAC,QACAC,aACAC,SAEAC,gBAAiB,SACjBC,wBAAyB,UAEzBC,cAAe,4FAEfC,eAAgB,aAEhBC,aAAc,EACdC,UAAc,EAEdC,cAAgB,EAChBC,UAAgB,GAChBC,WAAgB,GAChBC,UAAgB,GAChBC,QAAgB,EAChBC,WAAgB,GAEjBpB,WAAUqB,UAAY,SAASC,EAAKC,GAkenC,QAASC,KACP,IAC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AKirD,SAAS7sD,UAAUkhB,iBACxBtf,KAAKirD,SAAS7sD,UAAU0oC,WAAWiwC,OAGtCl5E"}
\ No newline at end of file
diff --git a/dist/wysihtml.table_editing.js b/dist/wysihtml.table_editing.js
new file mode 100644
index 0000000..99dbfdb
--- /dev/null
+++ b/dist/wysihtml.table_editing.js
@@ -0,0 +1,1163 @@
+wysihtml.commands.addTableCells = {
+ exec: function(composer, command, value) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+
+ // switches start and end if start is bigger than end (reverse selection)
+ var tableSelect = wysihtml.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end);
+ if (value == 'before' || value == 'above') {
+ wysihtml.dom.table.addCells(tableSelect.start, value);
+ } else if (value == 'after' || value == 'below') {
+ wysihtml.dom.table.addCells(tableSelect.end, value);
+ }
+ setTimeout(function() {
+ composer.tableSelection.select(tableSelect.start, tableSelect.end);
+ },0);
+ }
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
+
+wysihtml.commands.createTable = {
+ exec: function(composer, command, value) {
+ var col, row, html;
+ if (value && value.cols && value.rows && parseInt(value.cols, 10) > 0 && parseInt(value.rows, 10) > 0) {
+ if (value.tableStyle) {
+ html = '';
+ } else {
+ html = '';
+ }
+ html += '';
+ for (row = 0; row < value.rows; row ++) {
+ html += '';
+ for (col = 0; col < value.cols; col ++) {
+ html += ' ';
+ }
+ html += ' ';
+ }
+ html += '
';
+ composer.commands.exec('insertHTML', html);
+ }
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
+
+wysihtml.commands.deleteTableCells = {
+ exec: function(composer, command, value) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+ var tableSelect = wysihtml.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end),
+ idx = wysihtml.dom.table.indexOf(tableSelect.start),
+ selCell,
+ table = composer.tableSelection.table;
+
+ wysihtml.dom.table.removeCells(tableSelect.start, value);
+ setTimeout(function() {
+ // move selection to next or previous if not present
+ selCell = wysihtml.dom.table.findCell(table, idx);
+
+ if (!selCell) {
+ if (value == 'row') {
+ selCell = wysihtml.dom.table.findCell(table, {
+ 'row': idx.row - 1,
+ 'col': idx.col
+ });
+ }
+
+ if (value == 'column') {
+ selCell = wysihtml.dom.table.findCell(table, {
+ 'row': idx.row,
+ 'col': idx.col - 1
+ });
+ }
+ }
+ if (selCell) {
+ composer.tableSelection.select(selCell, selCell);
+ }
+ }, 0);
+ }
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
+
+wysihtml.commands.mergeTableCells = {
+ exec: function(composer, command) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+ if (this.state(composer, command)) {
+ wysihtml.dom.table.unmergeCell(composer.tableSelection.start);
+ } else {
+ wysihtml.dom.table.mergeCellsBetween(composer.tableSelection.start, composer.tableSelection.end);
+ }
+ }
+ },
+
+ state: function(composer, command) {
+ if (composer.tableSelection) {
+ var start = composer.tableSelection.start,
+ end = composer.tableSelection.end;
+ if (start && end && start == end &&
+ ((
+ wysihtml.dom.getAttribute(start, 'colspan') &&
+ parseInt(wysihtml.dom.getAttribute(start, 'colspan'), 10) > 1
+ ) || (
+ wysihtml.dom.getAttribute(start, 'rowspan') &&
+ parseInt(wysihtml.dom.getAttribute(start, 'rowspan'), 10) > 1
+ ))
+ ) {
+ return [start];
+ }
+ }
+ return false;
+ }
+};
+
+(function() {
+
+ var api = wysihtml.dom;
+
+ var MapCell = function(cell) {
+ this.el = cell;
+ this.isColspan= false;
+ this.isRowspan= false;
+ this.firstCol= true;
+ this.lastCol= true;
+ this.firstRow= true;
+ this.lastRow= true;
+ this.isReal= true;
+ this.spanCollection= [];
+ this.modified = false;
+ };
+
+ var TableModifyerByCell = function (cell, table) {
+ if (cell) {
+ this.cell = cell;
+ this.table = api.getParentElement(cell, { query: "table" });
+ } else if (table) {
+ this.table = table;
+ this.cell = this.table.querySelectorAll('th, td')[0];
+ }
+ };
+
+ function queryInList(list, query) {
+ var ret = [],
+ q;
+ for (var e = 0, len = list.length; e < len; e++) {
+ q = list[e].querySelectorAll(query);
+ if (q) {
+ for(var i = q.length; i--; ret.unshift(q[i]));
+ }
+ }
+ return ret;
+ }
+
+ function removeElement(el) {
+ el.parentNode.removeChild(el);
+ }
+
+ function insertAfter(referenceNode, newNode) {
+ referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
+ }
+
+ function nextNode(node, tag) {
+ var element = node.nextSibling;
+ while (element.nodeType !=1) {
+ element = element.nextSibling;
+ if (!tag || tag == element.tagName.toLowerCase()) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ TableModifyerByCell.prototype = {
+
+ addSpannedCellToMap: function(cell, map, r, c, cspan, rspan) {
+ var spanCollect = [],
+ rmax = r + ((rspan) ? parseInt(rspan, 10) - 1 : 0),
+ cmax = c + ((cspan) ? parseInt(cspan, 10) - 1 : 0);
+
+ for (var rr = r; rr <= rmax; rr++) {
+ if (typeof map[rr] == "undefined") { map[rr] = []; }
+ for (var cc = c; cc <= cmax; cc++) {
+ map[rr][cc] = new MapCell(cell);
+ map[rr][cc].isColspan = (cspan && parseInt(cspan, 10) > 1);
+ map[rr][cc].isRowspan = (rspan && parseInt(rspan, 10) > 1);
+ map[rr][cc].firstCol = cc == c;
+ map[rr][cc].lastCol = cc == cmax;
+ map[rr][cc].firstRow = rr == r;
+ map[rr][cc].lastRow = rr == rmax;
+ map[rr][cc].isReal = cc == c && rr == r;
+ map[rr][cc].spanCollection = spanCollect;
+
+ spanCollect.push(map[rr][cc]);
+ }
+ }
+ },
+
+ setCellAsModified: function(cell) {
+ cell.modified = true;
+ if (cell.spanCollection.length > 0) {
+ for (var s = 0, smax = cell.spanCollection.length; s < smax; s++) {
+ cell.spanCollection[s].modified = true;
+ }
+ }
+ },
+
+ setTableMap: function() {
+ var map = [];
+ var tableRows = this.getTableRows(),
+ ridx, row, cells, cidx, cell,
+ c,
+ cspan, rspan;
+
+ for (ridx = 0; ridx < tableRows.length; ridx++) {
+ row = tableRows[ridx];
+ cells = this.getRowCells(row);
+ c = 0;
+ if (typeof map[ridx] == "undefined") { map[ridx] = []; }
+ for (cidx = 0; cidx < cells.length; cidx++) {
+ cell = cells[cidx];
+
+ // If cell allready set means it is set by col or rowspan,
+ // so increase cols index until free col is found
+ while (typeof map[ridx][c] != "undefined") { c++; }
+
+ cspan = api.getAttribute(cell, 'colspan');
+ rspan = api.getAttribute(cell, 'rowspan');
+
+ if (cspan || rspan) {
+ this.addSpannedCellToMap(cell, map, ridx, c, cspan, rspan);
+ c = c + ((cspan) ? parseInt(cspan, 10) : 1);
+ } else {
+ map[ridx][c] = new MapCell(cell);
+ c++;
+ }
+ }
+ }
+ this.map = map;
+ return map;
+ },
+
+ getRowCells: function(row) {
+ var inlineTables = this.table.querySelectorAll('table'),
+ inlineCells = (inlineTables) ? queryInList(inlineTables, 'th, td') : [],
+ allCells = row.querySelectorAll('th, td'),
+ tableCells = (inlineCells.length > 0) ? wysihtml.lang.array(allCells).without(inlineCells) : allCells;
+
+ return tableCells;
+ },
+
+ getTableRows: function() {
+ var inlineTables = this.table.querySelectorAll('table'),
+ inlineRows = (inlineTables) ? queryInList(inlineTables, 'tr') : [],
+ allRows = this.table.querySelectorAll('tr'),
+ tableRows = (inlineRows.length > 0) ? wysihtml.lang.array(allRows).without(inlineRows) : allRows;
+
+ return tableRows;
+ },
+
+ getMapIndex: function(cell) {
+ var r_length = this.map.length,
+ c_length = (this.map && this.map[0]) ? this.map[0].length : 0;
+
+ for (var r_idx = 0;r_idx < r_length; r_idx++) {
+ for (var c_idx = 0;c_idx < c_length; c_idx++) {
+ if (this.map[r_idx][c_idx].el === cell) {
+ return {'row': r_idx, 'col': c_idx};
+ }
+ }
+ }
+ return false;
+ },
+
+ getElementAtIndex: function(idx) {
+ this.setTableMap();
+ if (this.map[idx.row] && this.map[idx.row][idx.col] && this.map[idx.row][idx.col].el) {
+ return this.map[idx.row][idx.col].el;
+ }
+ return null;
+ },
+
+ getMapElsTo: function(to_cell) {
+ var els = [];
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(to_cell);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ if (this.idx_start != null && this.idx_end != null) {
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+ els.push(this.map[row][col].el);
+ }
+ }
+ }
+ return els;
+ },
+
+ orderSelectionEnds: function(secondcell) {
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(secondcell);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ return {
+ "start": this.map[this.idx_start.row][this.idx_start.col].el,
+ "end": this.map[this.idx_end.row][this.idx_end.col].el
+ };
+ },
+
+ createCells: function(tag, nr, attrs) {
+ var doc = this.table.ownerDocument,
+ frag = doc.createDocumentFragment(),
+ cell;
+ for (var i = 0; i < nr; i++) {
+ cell = doc.createElement(tag);
+
+ if (attrs) {
+ for (var attr in attrs) {
+ if (attrs.hasOwnProperty(attr)) {
+ cell.setAttribute(attr, attrs[attr]);
+ }
+ }
+ }
+
+ // add non breaking space
+ cell.appendChild(document.createTextNode("\u00a0"));
+ frag.appendChild(cell);
+ }
+ return frag;
+ },
+
+ // Returns next real cell (not part of spanned cell unless first) on row if selected index is not real. I no real cells -1 will be returned
+ correctColIndexForUnreals: function(col, row) {
+ var r = this.map[row],
+ corrIdx = -1;
+ for (var i = 0, max = col; i < col; i++) {
+ if (r[i].isReal){
+ corrIdx++;
+ }
+ }
+ return corrIdx;
+ },
+
+ getLastNewCellOnRow: function(row, rowLimit) {
+ var cells = this.getRowCells(row),
+ cell, idx;
+
+ for (var cidx = 0, cmax = cells.length; cidx < cmax; cidx++) {
+ cell = cells[cidx];
+ idx = this.getMapIndex(cell);
+ if (idx === false || (typeof rowLimit != "undefined" && idx.row != rowLimit)) {
+ return cell;
+ }
+ }
+ return null;
+ },
+
+ removeEmptyTable: function() {
+ var cells = this.table.querySelectorAll('td, th');
+ if (!cells || cells.length == 0) {
+ removeElement(this.table);
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ // Splits merged cell on row to unique cells
+ splitRowToCells: function(cell) {
+ if (cell.isColspan) {
+ var colspan = parseInt(api.getAttribute(cell.el, 'colspan') || 1, 10),
+ cType = cell.el.tagName.toLowerCase();
+ if (colspan > 1) {
+ var newCells = this.createCells(cType, colspan -1);
+ insertAfter(cell.el, newCells);
+ }
+ cell.el.removeAttribute('colspan');
+ }
+ },
+
+ getRealRowEl: function(force, idx) {
+ var r = null,
+ c = null;
+
+ idx = idx || this.idx;
+
+ for (var cidx = 0, cmax = this.map[idx.row].length; cidx < cmax; cidx++) {
+ c = this.map[idx.row][cidx];
+ if (c.isReal) {
+ r = api.getParentElement(c.el, { query: "tr" });
+ if (r) {
+ return r;
+ }
+ }
+ }
+
+ if (r === null && force) {
+ r = api.getParentElement(this.map[idx.row][idx.col].el, { query: "tr" }) || null;
+ }
+
+ return r;
+ },
+
+ injectRowAt: function(row, col, colspan, cType, c) {
+ var r = this.getRealRowEl(false, {'row': row, 'col': col}),
+ new_cells = this.createCells(cType, colspan);
+
+ if (r) {
+ var n_cidx = this.correctColIndexForUnreals(col, row);
+ if (n_cidx >= 0) {
+ insertAfter(this.getRowCells(r)[n_cidx], new_cells);
+ } else {
+ r.insertBefore(new_cells, r.firstChild);
+ }
+ } else {
+ var rr = this.table.ownerDocument.createElement('tr');
+ rr.appendChild(new_cells);
+ insertAfter(api.getParentElement(c.el, { query: "tr" }), rr);
+ }
+ },
+
+ canMerge: function(to) {
+ this.to = to;
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(this.to);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+ if (this.map[row][col].isColspan || this.map[row][col].isRowspan) {
+ return false;
+ }
+ }
+ }
+ return true;
+ },
+
+ decreaseCellSpan: function(cell, span) {
+ var nr = parseInt(api.getAttribute(cell.el, span), 10) - 1;
+ if (nr >= 1) {
+ cell.el.setAttribute(span, nr);
+ } else {
+ cell.el.removeAttribute(span);
+ if (span == 'colspan') {
+ cell.isColspan = false;
+ }
+ if (span == 'rowspan') {
+ cell.isRowspan = false;
+ }
+ cell.firstCol = true;
+ cell.lastCol = true;
+ cell.firstRow = true;
+ cell.lastRow = true;
+ cell.isReal = true;
+ }
+ },
+
+ removeSurplusLines: function() {
+ var row, cell, ridx, rmax, cidx, cmax, allRowspan;
+
+ this.setTableMap();
+ if (this.map) {
+ ridx = 0;
+ rmax = this.map.length;
+ for (;ridx < rmax; ridx++) {
+ row = this.map[ridx];
+ allRowspan = true;
+ cidx = 0;
+ cmax = row.length;
+ for (; cidx < cmax; cidx++) {
+ cell = row[cidx];
+ if (!(api.getAttribute(cell.el, "rowspan") && parseInt(api.getAttribute(cell.el, "rowspan"), 10) > 1 && cell.firstRow !== true)) {
+ allRowspan = false;
+ break;
+ }
+ }
+ if (allRowspan) {
+ cidx = 0;
+ for (; cidx < cmax; cidx++) {
+ this.decreaseCellSpan(row[cidx], 'rowspan');
+ }
+ }
+ }
+
+ // remove rows without cells
+ var tableRows = this.getTableRows();
+ ridx = 0;
+ rmax = tableRows.length;
+ for (;ridx < rmax; ridx++) {
+ row = tableRows[ridx];
+ if (row.childNodes.length == 0 && (/^\s*$/.test(row.textContent || row.innerText))) {
+ removeElement(row);
+ }
+ }
+ }
+ },
+
+ fillMissingCells: function() {
+ var r_max = 0,
+ c_max = 0,
+ prevcell = null;
+
+ this.setTableMap();
+ if (this.map) {
+
+ // find maximal dimensions of broken table
+ r_max = this.map.length;
+ for (var ridx = 0; ridx < r_max; ridx++) {
+ if (this.map[ridx].length > c_max) { c_max = this.map[ridx].length; }
+ }
+
+ for (var row = 0; row < r_max; row++) {
+ for (var col = 0; col < c_max; col++) {
+ if (this.map[row] && !this.map[row][col]) {
+ if (col > 0) {
+ this.map[row][col] = new MapCell(this.createCells('td', 1));
+ prevcell = this.map[row][col-1];
+ if (prevcell && prevcell.el && prevcell.el.parent) { // if parent does not exist element is removed from dom
+ insertAfter(this.map[row][col-1].el, this.map[row][col].el);
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+
+ rectify: function() {
+ if (!this.removeEmptyTable()) {
+ this.removeSurplusLines();
+ this.fillMissingCells();
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ unmerge: function() {
+ if (this.rectify()) {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+
+ if (this.idx) {
+ var thisCell = this.map[this.idx.row][this.idx.col],
+ colspan = (api.getAttribute(thisCell.el, "colspan")) ? parseInt(api.getAttribute(thisCell.el, "colspan"), 10) : 1,
+ cType = thisCell.el.tagName.toLowerCase();
+
+ if (thisCell.isRowspan) {
+ var rowspan = parseInt(api.getAttribute(thisCell.el, "rowspan"), 10);
+ if (rowspan > 1) {
+ for (var nr = 1, maxr = rowspan - 1; nr <= maxr; nr++){
+ this.injectRowAt(this.idx.row + nr, this.idx.col, colspan, cType, thisCell);
+ }
+ }
+ thisCell.el.removeAttribute('rowspan');
+ }
+ this.splitRowToCells(thisCell);
+ }
+ }
+ },
+
+ // merges cells from start cell (defined in creating obj) to "to" cell
+ merge: function(to) {
+ if (this.rectify()) {
+ if (this.canMerge(to)) {
+ var rowspan = this.idx_end.row - this.idx_start.row + 1,
+ colspan = this.idx_end.col - this.idx_start.col + 1;
+
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+
+ if (row == this.idx_start.row && col == this.idx_start.col) {
+ if (rowspan > 1) {
+ this.map[row][col].el.setAttribute('rowspan', rowspan);
+ }
+ if (colspan > 1) {
+ this.map[row][col].el.setAttribute('colspan', colspan);
+ }
+ } else {
+ // transfer content
+ if (!(/^\s* \s*$/.test(this.map[row][col].el.innerHTML.toLowerCase()))) {
+ this.map[this.idx_start.row][this.idx_start.col].el.innerHTML += ' ' + this.map[row][col].el.innerHTML;
+ }
+ removeElement(this.map[row][col].el);
+ }
+
+ }
+ }
+ this.rectify();
+ } else {
+ if (window.console) {
+ console.log('Do not know how to merge allready merged cells.');
+ }
+ }
+ }
+ },
+
+ // Decreases rowspan of a cell if it is done on first cell of rowspan row (real cell)
+ // Cell is moved to next row (if it is real)
+ collapseCellToNextRow: function(cell) {
+ var cellIdx = this.getMapIndex(cell.el),
+ newRowIdx = cellIdx.row + 1,
+ newIdx = {'row': newRowIdx, 'col': cellIdx.col};
+
+ if (newRowIdx < this.map.length) {
+
+ var row = this.getRealRowEl(false, newIdx);
+ if (row !== null) {
+ var n_cidx = this.correctColIndexForUnreals(newIdx.col, newIdx.row);
+ if (n_cidx >= 0) {
+ insertAfter(this.getRowCells(row)[n_cidx], cell.el);
+ } else {
+ var lastCell = this.getLastNewCellOnRow(row, newRowIdx);
+ if (lastCell !== null) {
+ insertAfter(lastCell, cell.el);
+ } else {
+ row.insertBefore(cell.el, row.firstChild);
+ }
+ }
+ if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('rowspan');
+ }
+ }
+ }
+ },
+
+ // Removes a cell when removing a row
+ // If is rowspan cell then decreases the rowspan
+ // and moves cell to next row if needed (is first cell of rowspan)
+ removeRowCell: function(cell) {
+ if (cell.isReal) {
+ if (cell.isRowspan) {
+ this.collapseCellToNextRow(cell);
+ } else {
+ removeElement(cell.el);
+ }
+ } else {
+ if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('rowspan');
+ }
+ }
+ },
+
+ getRowElementsByCell: function() {
+ var cells = [];
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row];
+ for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
+ if (modRow[cidx].isReal) {
+ cells.push(modRow[cidx].el);
+ }
+ }
+ }
+ return cells;
+ },
+
+ getColumnElementsByCell: function() {
+ var cells = [];
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
+ if (this.map[ridx][this.idx.col] && this.map[ridx][this.idx.col].isReal) {
+ cells.push(this.map[ridx][this.idx.col].el);
+ }
+ }
+ }
+ return cells;
+ },
+
+ // Removes the row of selected cell
+ removeRow: function() {
+ var oldRow = api.getParentElement(this.cell, { query: "tr" });
+ if (oldRow) {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row];
+ for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
+ if (!modRow[cidx].modified) {
+ this.setCellAsModified(modRow[cidx]);
+ this.removeRowCell(modRow[cidx]);
+ }
+ }
+ }
+ removeElement(oldRow);
+ }
+ },
+
+ removeColCell: function(cell) {
+ if (cell.isColspan) {
+ if (parseInt(api.getAttribute(cell.el, 'colspan'), 10) > 2) {
+ cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('colspan');
+ }
+ } else if (cell.isReal) {
+ removeElement(cell.el);
+ }
+ },
+
+ removeColumn: function() {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
+ if (!this.map[ridx][this.idx.col].modified) {
+ this.setCellAsModified(this.map[ridx][this.idx.col]);
+ this.removeColCell(this.map[ridx][this.idx.col]);
+ }
+ }
+ }
+ },
+
+ // removes row or column by selected cell element
+ remove: function(what) {
+ if (this.rectify()) {
+ switch (what) {
+ case 'row':
+ this.removeRow();
+ break;
+ case 'column':
+ this.removeColumn();
+ break;
+ }
+ this.rectify();
+ }
+ },
+
+ addRow: function(where) {
+ var doc = this.table.ownerDocument;
+
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (where == "below" && api.getAttribute(this.cell, 'rowspan')) {
+ this.idx.row = this.idx.row + parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1;
+ }
+
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row],
+ newRow = doc.createElement('tr');
+
+ for (var ridx = 0, rmax = modRow.length; ridx < rmax; ridx++) {
+ if (!modRow[ridx].modified) {
+ this.setCellAsModified(modRow[ridx]);
+ this.addRowCell(modRow[ridx], newRow, where);
+ }
+ }
+
+ switch (where) {
+ case 'below':
+ insertAfter(this.getRealRowEl(true), newRow);
+ break;
+ case 'above':
+ var cr = api.getParentElement(this.map[this.idx.row][this.idx.col].el, { query: "tr" });
+ if (cr) {
+ cr.parentNode.insertBefore(newRow, cr);
+ }
+ break;
+ }
+ }
+ },
+
+ addRowCell: function(cell, row, where) {
+ var colSpanAttr = (cell.isColspan) ? {"colspan" : api.getAttribute(cell.el, 'colspan')} : null;
+ if (cell.isReal) {
+ if (where != 'above' && cell.isRowspan) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el,'rowspan'), 10) + 1);
+ } else {
+ row.appendChild(this.createCells('td', 1, colSpanAttr));
+ }
+ } else {
+ if (where != 'above' && cell.isRowspan && cell.lastRow) {
+ row.appendChild(this.createCells('td', 1, colSpanAttr));
+ } else if (c.isRowspan) {
+ cell.el.attr('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) + 1);
+ }
+ }
+ },
+
+ add: function(where) {
+ if (this.rectify()) {
+ if (where == 'below' || where == 'above') {
+ this.addRow(where);
+ }
+ if (where == 'before' || where == 'after') {
+ this.addColumn(where);
+ }
+ }
+ },
+
+ addColCell: function (cell, ridx, where) {
+ var doAdd,
+ cType = cell.el.tagName.toLowerCase();
+
+ // defines add cell vs expand cell conditions
+ // true means add
+ switch (where) {
+ case "before":
+ doAdd = (!cell.isColspan || cell.firstCol);
+ break;
+ case "after":
+ doAdd = (!cell.isColspan || cell.lastCol || (cell.isColspan && cell.el == this.cell));
+ break;
+ }
+
+ if (doAdd){
+ // adds a cell before or after current cell element
+ switch (where) {
+ case "before":
+ cell.el.parentNode.insertBefore(this.createCells(cType, 1), cell.el);
+ break;
+ case "after":
+ insertAfter(cell.el, this.createCells(cType, 1));
+ break;
+ }
+
+ // handles if cell has rowspan
+ if (cell.isRowspan) {
+ this.handleCellAddWithRowspan(cell, ridx+1, where);
+ }
+
+ } else {
+ // expands cell
+ cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) + 1);
+ }
+ },
+
+ addColumn: function(where) {
+ var row, modCell;
+
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (where == "after" && api.getAttribute(this.cell, 'colspan')) {
+ this.idx.col = this.idx.col + parseInt(api.getAttribute(this.cell, 'colspan'), 10) - 1;
+ }
+
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++ ) {
+ row = this.map[ridx];
+ if (row[this.idx.col]) {
+ modCell = row[this.idx.col];
+ if (!modCell.modified) {
+ this.setCellAsModified(modCell);
+ this.addColCell(modCell, ridx , where);
+ }
+ }
+ }
+ }
+ },
+
+ handleCellAddWithRowspan: function (cell, ridx, where) {
+ var addRowsNr = parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1,
+ crow = api.getParentElement(cell.el, { query: "tr" }),
+ cType = cell.el.tagName.toLowerCase(),
+ cidx, temp_r_cells,
+ doc = this.table.ownerDocument,
+ nrow;
+
+ for (var i = 0; i < addRowsNr; i++) {
+ cidx = this.correctColIndexForUnreals(this.idx.col, (ridx + i));
+ crow = nextNode(crow, 'tr');
+ if (crow) {
+ if (cidx > 0) {
+ switch (where) {
+ case "before":
+ temp_r_cells = this.getRowCells(crow);
+ if (cidx > 0 && this.map[ridx + i][this.idx.col].el != temp_r_cells[cidx] && cidx == temp_r_cells.length - 1) {
+ insertAfter(temp_r_cells[cidx], this.createCells(cType, 1));
+ } else {
+ temp_r_cells[cidx].parentNode.insertBefore(this.createCells(cType, 1), temp_r_cells[cidx]);
+ }
+
+ break;
+ case "after":
+ insertAfter(this.getRowCells(crow)[cidx], this.createCells(cType, 1));
+ break;
+ }
+ } else {
+ crow.insertBefore(this.createCells(cType, 1), crow.firstChild);
+ }
+ } else {
+ nrow = doc.createElement('tr');
+ nrow.appendChild(this.createCells(cType, 1));
+ this.table.appendChild(nrow);
+ }
+ }
+ }
+ };
+
+ api.table = {
+ getCellsBetween: function(cell1, cell2) {
+ var c1 = new TableModifyerByCell(cell1);
+ return c1.getMapElsTo(cell2);
+ },
+
+ addCells: function(cell, where) {
+ var c = new TableModifyerByCell(cell);
+ c.add(where);
+ },
+
+ removeCells: function(cell, what) {
+ var c = new TableModifyerByCell(cell);
+ c.remove(what);
+ },
+
+ mergeCellsBetween: function(cell1, cell2) {
+ var c1 = new TableModifyerByCell(cell1);
+ c1.merge(cell2);
+ },
+
+ unmergeCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ c.unmerge();
+ },
+
+ orderSelectionEnds: function(cell, cell2) {
+ var c = new TableModifyerByCell(cell);
+ return c.orderSelectionEnds(cell2);
+ },
+
+ indexOf: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ c.setTableMap();
+ return c.getMapIndex(cell);
+ },
+
+ findCell: function(table, idx) {
+ var c = new TableModifyerByCell(null, table);
+ return c.getElementAtIndex(idx);
+ },
+
+ findRowByCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ return c.getRowElementsByCell();
+ },
+
+ findColumnByCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ return c.getColumnElementsByCell();
+ },
+
+ canMerge: function(cell1, cell2) {
+ var c = new TableModifyerByCell(cell1);
+ return c.canMerge(cell2);
+ }
+ };
+
+})();
+
+(function() {
+
+ // Keep the old composer.observe function.
+ var oldObserverFunction = wysihtml.views.Composer.prototype.observe;
+
+ var extendedObserverFunction = function() {
+ oldObserverFunction.call(this);
+ // Bind the table user interaction tracking
+ if (this.config.handleTables) {
+ // If handleTables option is true, table handling functions are bound
+ initTableHandling.call(this);
+ }
+ };
+
+ // Table management.
+ // If present enableObjectResizing and enableInlineTableEditing command
+ // should be called with false to prevent native table handlers.
+ var initTableHandling = function() {
+ var hideHandlers = function() {
+ this.win.removeEventListener('load', hideHandlers);
+ this.doc.execCommand('enableObjectResizing', false, 'false');
+ this.doc.execCommand('enableInlineTableEditing', false, 'false');
+ }.bind(this),
+ iframeInitiator = (function() {
+ hideHandlers.call(this);
+ actions.removeListeners(this.sandbox.getIframe(), ['focus', 'mouseup', 'mouseover'], iframeInitiator);
+ }).bind(this);
+
+ if (
+ this.doc.execCommand &&
+ wysihtml.browser.supportsCommand(this.doc, 'enableObjectResizing') &&
+ wysihtml.browser.supportsCommand(this.doc, 'enableInlineTableEditing')
+ ) {
+ if (this.sandbox.getIframe) {
+ actions.addListeners(this.sandbox.getIframe(), ['focus', 'mouseup', 'mouseover'], iframeInitiator);
+ } else {
+ this.win.addEventListener('load', hideHandlers);
+ }
+ }
+ this.tableSelection = wysihtml.quirks.tableCellsSelection(this.element, this.parent);
+ };
+
+ // Cell selections handling
+ var tableCellsSelection = function(editable, editor) {
+
+ var init = function() {
+ editable.addEventListener('mousedown', handleMouseDown);
+ return select;
+ };
+
+ var handleMouseDown = function(event) {
+ var target = wysihtml.dom.getParentElement(event.target, {query: 'td, th'}, false, editable);
+ if (target) {
+ handleSelectionMousedown(target);
+ }
+ };
+
+ var handleSelectionMousedown = function(target) {
+ select.start = target;
+ select.end = target;
+ select.cells = [target];
+ select.table = dom.getParentElement(select.start, {query: 'table'}, false, editable);
+
+ if (select.table) {
+ removeCellSelections();
+ dom.addClass(target, selectionClass);
+ editable.addEventListener('mousemove', handleMouseMove);
+ editable.addEventListener('mouseup', handleMouseUp);
+ editor.fire('tableselectstart').fire('tableselectstart:composer');
+ }
+ };
+
+ // remove all selection classes
+ var removeCellSelections = function() {
+ if (editable) {
+ var selectedCells = editable.querySelectorAll('.' + selectionClass);
+ if (selectedCells.length > 0) {
+ for (var i = 0; i < selectedCells.length; i++) {
+ dom.removeClass(selectedCells[i], selectionClass);
+ }
+ }
+ }
+ };
+
+ var addSelections = function(cells) {
+ for (var i = 0; i < cells.length; i++) {
+ dom.addClass(cells[i], selectionClass);
+ }
+ };
+
+ var handleMouseMove = function(event) {
+ var curTable = null,
+ cell = dom.getParentElement(event.target, {query: 'td, th'}, false, editable),
+ oldEnd;
+
+ if (cell && select.table && select.start) {
+ curTable = dom.getParentElement(cell, {query: 'table'}, false, editable);
+ if (curTable && curTable === select.table) {
+ removeCellSelections();
+ oldEnd = select.end;
+ select.end = cell;
+ select.cells = dom.table.getCellsBetween(select.start, cell);
+ if (select.cells.length > 1) {
+ editor.composer.selection.deselect();
+ }
+ addSelections(select.cells);
+ if (select.end !== oldEnd) {
+ editor.fire('tableselectchange').fire('tableselectchange:composer');
+ }
+ }
+ }
+ };
+
+ var handleMouseUp = function(event) {
+ editable.removeEventListener('mousemove', handleMouseMove);
+ editable.removeEventListener('mouseup', handleMouseUp);
+ editor.fire('tableselect').fire('tableselect:composer');
+ setTimeout(function() {
+ bindSideclick();
+ }, 0);
+ };
+
+ var sideClickHandler = function(event) {
+ editable.ownerDocument.removeEventListener('click', sideClickHandler);
+ if (dom.getParentElement(event.target, {query: 'table'}, false, editable) != select.table) {
+ removeCellSelections();
+ select.table = null;
+ select.start = null;
+ select.end = null;
+ editor.fire('tableunselect').fire('tableunselect:composer');
+ }
+ };
+
+ var bindSideclick = function() {
+ editable.ownerDocument.addEventListener('click', sideClickHandler);
+ };
+
+ var selectCells = function(start, end) {
+ select.start = start;
+ select.end = end;
+ select.table = dom.getParentElement(select.start, {query: 'table'}, false, editable);
+ selectedCells = dom.table.getCellsBetween(select.start, select.end);
+ addSelections(selectedCells);
+ bindSideclick();
+ editor.fire('tableselect').fire('tableselect:composer');
+ };
+
+ var dom = wysihtml.dom,
+ select = {
+ table: null,
+ start: null,
+ end: null,
+ cells: null,
+ select: selectCells
+ },
+ selectionClass = 'wysiwyg-tmp-selected-cell';
+
+ return init();
+ };
+
+ // Bind to wysihtml
+ wysihtml.Editor.prototype.defaults.handleTables = true;
+ wysihtml.quirks.tableCellsSelection = tableCellsSelection;
+ wysihtml.views.Composer.prototype.observe = extendedObserverFunction;
+
+})();
diff --git a/dist/wysihtml.toolbar.js b/dist/wysihtml.toolbar.js
new file mode 100644
index 0000000..4a9db45
--- /dev/null
+++ b/dist/wysihtml.toolbar.js
@@ -0,0 +1,850 @@
+/**
+ * Toolbar Dialog
+ *
+ * @param {Element} link The toolbar link which causes the dialog to show up
+ * @param {Element} container The dialog container
+ *
+ * @example
+ *
+ * insert an image
+ *
+ *
+ *
+ *
+ * URL:
+ *
+ *
+ * Alternative text:
+ *
+ *
+ *
+ *
+ */
+(function(wysihtml) {
+ var dom = wysihtml.dom,
+ CLASS_NAME_OPENED = "wysihtml-command-dialog-opened",
+ SELECTOR_FORM_ELEMENTS = "input, select, textarea",
+ SELECTOR_FIELDS = "[data-wysihtml-dialog-field]",
+ ATTRIBUTE_FIELDS = "data-wysihtml-dialog-field";
+
+
+ wysihtml.toolbar.Dialog = wysihtml.lang.Dispatcher.extend(
+ /** @scope wysihtml.toolbar.Dialog.prototype */ {
+ constructor: function(link, container) {
+ this.link = link;
+ this.container = container;
+ },
+
+ _observe: function() {
+ if (this._observed) {
+ return;
+ }
+
+ var that = this,
+ callbackWrapper = function(event) {
+ var attributes = that._serialize();
+ that.fire("save", attributes);
+ that.hide();
+ event.preventDefault();
+ event.stopPropagation();
+ };
+
+ dom.observe(that.link, "click", function() {
+ if (dom.hasClass(that.link, CLASS_NAME_OPENED)) {
+ setTimeout(function() { that.hide(); }, 0);
+ }
+ });
+
+ dom.observe(this.container, "keydown", function(event) {
+ var keyCode = event.keyCode;
+ if (keyCode === wysihtml.ENTER_KEY) {
+ callbackWrapper(event);
+ }
+ if (keyCode === wysihtml.ESCAPE_KEY) {
+ that.cancel();
+ }
+ });
+
+ dom.delegate(this.container, "[data-wysihtml-dialog-action=save]", "click", callbackWrapper);
+
+ dom.delegate(this.container, "[data-wysihtml-dialog-action=cancel]", "click", function(event) {
+ that.cancel();
+ event.preventDefault();
+ event.stopPropagation();
+ });
+
+ this._observed = true;
+ },
+
+ /**
+ * Grabs all fields in the dialog and puts them in key=>value style in an object which
+ * then gets returned
+ */
+ _serialize: function() {
+ var data = {},
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0;
+
+ for (; ifoo
+ *
+ * and we have the following dialog:
+ *
+ *
+ *
+ * after calling _interpolate() the dialog will look like this
+ *
+ *
+ *
+ * Basically it adopted the attribute values into the corresponding input fields
+ *
+ */
+ _interpolate: function(avoidHiddenFields) {
+ var field,
+ fieldName,
+ newValue,
+ focusedElement = document.querySelector(":focus"),
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0;
+ for (; i= 11
+ *
+ * Note that it sends the recorded audio to the google speech recognition api:
+ * http://stackoverflow.com/questions/4361826/does-chrome-have-buil-in-speech-recognition-for-input-type-text-x-webkit-speec
+ *
+ * Current HTML5 draft can be found here
+ * http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html
+ *
+ * "Accessing Google Speech API Chrome 11"
+ * http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
+ */
+(function(wysihtml) {
+ var dom = wysihtml.dom;
+
+ var linkStyles = {
+ position: "relative"
+ };
+
+ var wrapperStyles = {
+ left: 0,
+ margin: 0,
+ opacity: 0,
+ overflow: "hidden",
+ padding: 0,
+ position: "absolute",
+ top: 0,
+ zIndex: 1
+ };
+
+ var inputStyles = {
+ cursor: "inherit",
+ fontSize: "50px",
+ height: "50px",
+ marginTop: "-25px",
+ outline: 0,
+ padding: 0,
+ position: "absolute",
+ right: "-4px",
+ top: "50%"
+ };
+
+ var inputAttributes = {
+ "x-webkit-speech": "",
+ "speech": ""
+ };
+
+ wysihtml.toolbar.Speech = function(parent, link) {
+ var input = document.createElement("input");
+ if (!wysihtml.browser.supportsSpeechApiOn(input)) {
+ link.style.display = "none";
+ return;
+ }
+ var lang = parent.editor.textarea.element.getAttribute("lang");
+ if (lang) {
+ inputAttributes.lang = lang;
+ }
+
+ var wrapper = document.createElement("div");
+
+ wysihtml.lang.object(wrapperStyles).merge({
+ width: link.offsetWidth + "px",
+ height: link.offsetHeight + "px"
+ });
+
+ dom.insert(input).into(wrapper);
+ dom.insert(wrapper).into(link);
+
+ dom.setStyles(inputStyles).on(input);
+ dom.setAttributes(inputAttributes).on(input);
+
+ dom.setStyles(wrapperStyles).on(wrapper);
+ dom.setStyles(linkStyles).on(link);
+
+ var eventName = "onwebkitspeechchange" in input ? "webkitspeechchange" : "speechchange";
+ dom.observe(input, eventName, function() {
+ parent.execCommand("insertText", input.value);
+ input.value = "";
+ });
+
+ dom.observe(input, "click", function(event) {
+ if (dom.hasClass(link, "wysihtml-command-disabled")) {
+ event.preventDefault();
+ }
+
+ event.stopPropagation();
+ });
+ };
+})(wysihtml);
+
+/**
+ * Toolbar
+ *
+ * @param {Object} parent Reference to instance of Editor instance
+ * @param {Element} container Reference to the toolbar container element
+ *
+ * @example
+ *
+ *
+ *
+ */
+(function(wysihtml) {
+ var CLASS_NAME_COMMAND_DISABLED = "wysihtml-command-disabled",
+ CLASS_NAME_COMMANDS_DISABLED = "wysihtml-commands-disabled",
+ CLASS_NAME_COMMAND_ACTIVE = "wysihtml-command-active",
+ CLASS_NAME_ACTION_ACTIVE = "wysihtml-action-active",
+ dom = wysihtml.dom;
+
+ wysihtml.toolbar.Toolbar = Base.extend(
+ /** @scope wysihtml.toolbar.Toolbar.prototype */ {
+ constructor: function(editor, container, showOnInit) {
+ this.editor = editor;
+ this.container = typeof(container) === "string" ? document.getElementById(container) : container;
+ this.composer = editor.composer;
+
+ this._getLinks("command");
+ this._getLinks("action");
+
+ this._observe();
+ if (showOnInit) { this.show(); }
+
+ if (editor.config.classNameCommandDisabled != null) {
+ CLASS_NAME_COMMAND_DISABLED = editor.config.classNameCommandDisabled;
+ }
+ if (editor.config.classNameCommandsDisabled != null) {
+ CLASS_NAME_COMMANDS_DISABLED = editor.config.classNameCommandsDisabled;
+ }
+ if (editor.config.classNameCommandActive != null) {
+ CLASS_NAME_COMMAND_ACTIVE = editor.config.classNameCommandActive;
+ }
+ if (editor.config.classNameActionActive != null) {
+ CLASS_NAME_ACTION_ACTIVE = editor.config.classNameActionActive;
+ }
+
+ var speechInputLinks = this.container.querySelectorAll("[data-wysihtml-command=insertSpeech]"),
+ length = speechInputLinks.length,
+ i = 0;
+ for (; i element or wrap current selection in
+ * toolbar.execCommand("formatBlock", "blockquote");
+ */
+ execCommand: function(command, commandValue) {
+ if (this.commandsDisabled) {
+ return;
+ }
+
+ this._execCommand(command, commandValue);
+ },
+
+ _execCommand: function(command, commandValue) {
+ // Make sure that composer is focussed (false => don't move caret to the end)
+ this.editor.focus(false);
+
+ this.composer.commands.exec(command, commandValue);
+ this._updateLinkStates();
+ },
+
+ execAction: function(action) {
+ var editor = this.editor;
+ if (action === "change_view") {
+ if (editor.currentView === editor.textarea || editor.currentView === "source") {
+ editor.fire("change_view", "composer");
+ } else {
+ editor.fire("change_view", "textarea");
+ }
+ }
+ if (action == "showSource") {
+ editor.fire("showSource");
+ }
+ },
+
+ _observe: function() {
+ var that = this,
+ editor = this.editor,
+ container = this.container,
+ links = this.commandLinks.concat(this.actionLinks),
+ length = links.length,
+ i = 0;
+
+ for (; i
-wysihtml5 - Advanced Demo
+wysihtml - Advanced Demo
-wysihtml5 - Advanced Editor Example
+wysihtml - Advanced Editor Example
+Example of editor with iframe wrapper and as textarea replacement
+