From d9872fb4b219438ca10f16b3b480a192d0b23751 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Wed, 17 Jun 2015 14:12:23 +0700 Subject: [PATCH] More efficient forEachChildInRange fn. No need for a tree walker, and we don't waste time iterating into children that can never match the filter function. --- build/squire-raw.js | 16 +++++++--------- build/squire.js | 2 +- source/Editor.js | 16 +++++++--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 284c019..b643fc5 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -3622,15 +3622,13 @@ proto.setTextDirection = function ( direction ) { function forEachChildInRange ( rootNode, range, iterator ) { - var walker = new TreeWalker( rootNode, SHOW_ELEMENT|SHOW_TEXT, - function ( node ) { - return node.parentNode === rootNode && - isNodeContainedInRange( range, node, false /* include partials */ ); - } - ); - var node; - while ( node = walker.nextNode() ) { - iterator( node ); + var childNodes = rootNode.childNodes, + node = rootNode.firstChild; + while ( node ) { + if ( isNodeContainedInRange( range, node, false ) ) { + iterator( node ); + } + node = node.nextSibling; } } diff --git a/build/squire.js b/build/squire.js index 47c7387..25e4b52 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1,2 +1,2 @@ -!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function o(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function r(e,t,n){if(e.nodeName!==t)return!1;for(var o in n)if(e.getAttribute(o)!==n[o])return!1;return!0}function i(e,t){return e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function a(e){return e.nodeType===R&&!!rt[e.nodeName]}function s(e){return ot.test(e.nodeName)}function d(e){return e.nodeType===R&&!s(e)&&o(e.childNodes,s)}function l(e){return e.nodeType===R&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,o=new n(t.body,U,d,!1);return o.currentNode=e,o}function h(e){return c(e).previousNode()}function f(e){return c(e).nextNode()}function u(e,t,n){do if(r(e,t,n))return e;while(e=e.parentNode);return null}function p(e){var t,n,o,r,i,a=e.parentNode;return a&&e.nodeType===R?(t=p(a),t+=(t?">":"")+e.nodeName,(n=e.id)&&(t+="#"+n),(o=e.className.trim())&&(r=o.split(/\s\s*/),r.sort(),t+=".",t+=r.join(".")),(i=e.dir)&&(t+="[dir="+i+"]")):t=a?p(a):"",t}function g(e){var t=e.nodeType;return t===R?e.childNodes.length:e.length||0}function m(e){var t=e.parentNode;return t&&t.removeChild(e),e}function v(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function C(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,o=n?n.length:0;o--;)t.appendChild(e.firstChild);return t}function N(e,n,o,r){var i,a,s,d,l=e.createElement(n);if(o instanceof Array&&(r=o,o=null),o)for(i in o)a=o[i],a!==t&&l.setAttribute(i,o[i]);if(r)for(s=0,d=r.length;d>s;s+=1)l.appendChild(r[s]);return l}function _(e){var t,n,o=e.ownerDocument,r=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=E(o).createDefaultBlock(),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;Y&&n&&n.nodeType===D&&!n.data;)e.removeChild(n),n=e.firstChild;n||(Y?(t=o.createTextNode(M),E(o)._didAddZWS()):t=o.createTextNode(""))}else if(j){for(;e.nodeType!==D&&!a(e);){if(n=e.firstChild,!n){t=o.createTextNode("");break}e=n}e.nodeType===D?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(o.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=N(o,"BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),r}function S(e){var t,n,o,r,i=e.childNodes,a=e.ownerDocument,d=null,c=E(a)._config;for(t=0,n=i.length;n>t;t+=1)o=i[t],r="BR"===o.nodeName,!r&&s(o)?(d||(d=N(a,c.blockTag,c.blockAttributes)),d.appendChild(o),t-=1,n-=1):(r||d)&&(d||(d=N(a,c.blockTag,c.blockAttributes)),_(d),r?e.replaceChild(d,o):(e.insertBefore(d,o),t+=1,n+=1),d=null),l(o)&&S(o);return d&&e.appendChild(_(d)),e}function y(e,t,n){var o,r,i,a=e.nodeType;if(a===D&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===R){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=o,t.startOffset=g(o))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=o,t.endOffset=g(o))),m(n),n.nodeType===D?o.appendData(n.data):l.push(C(n));else if(n.nodeType===R){for(r=l.length;r--;)n.appendChild(l.pop());T(n,t)}}function b(e,t,n){for(var o,r,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;m(a),r=e.childNodes.length,o=e.lastChild,o&&"BR"===o.nodeName&&(e.removeChild(o),r-=1),i={startContainer:e,startOffset:r,endContainer:e,endOffset:r},e.appendChild(C(t)),T(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),V&&(o=e.lastChild)&&"BR"===o.nodeName&&e.removeChild(o)}function k(e){var t,n,o=e.previousSibling,r=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||r&&/^[OU]L$/.test(r.nodeName))if(o&&i(o,e)){if(!l(o)){if(!s)return;n=N(a,"DIV"),n.appendChild(C(o)),o.appendChild(n)}m(e),t=!l(e),o.appendChild(C(e)),t&&S(o),r&&k(r)}else s&&(o=N(a,"DIV"),e.insertBefore(o,r),_(o))}function E(e){for(var t,n=bt.length;n--;)if(t=bt[n],t._doc===e)return t;return null}function B(e,t){var n,o;e||(e={});for(n in t)o=t[n],e[n]=o&&o.constructor===Object?B(e[n],o):o;return e}function O(e,t){var n,o=e.defaultView,r=e.body;this._win=o,this._doc=e,this._body=r,this._events={},this._sel=o.getSelection(),this._lastSelection=null,X&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this.addEventListener("keyup",this._updatePathOnEvent),this.addEventListener("mouseup",this._updatePathOnEvent),o.addEventListener("focus",this,!1),o.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,J?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(r,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._awaitingPaste=!1,this.addEventListener(Q?"beforecut":"cut",this._onCut),this.addEventListener(Q?"beforepaste":"paste",this._onPaste),this.addEventListener(V?"keypress":"keydown",this._onKey),this._keyHandlers=Object.create(Tt),this.setConfig(t),Q&&(o.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,o=this.parentNode,r=this.length-e;return n?o.insertBefore(t,n):o.appendChild(t),r&&this.deleteData(e,r),t}),r.setAttribute("contenteditable","true");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}bt.push(this),this.setHTML("")}function A(e,t,o){for(var r,i=new n(e,U|I,function(n){return n.parentNode===e&&ht(t,n,!1)});r=i.nextNode();)o(r)}function L(e,t,n){var o=[];return A(e,t,function(e){o.push(n(e))}),o}var x=2,R=1,D=3,U=1,I=4,P=0,w=1,F=2,H=3,M="​",W=e.defaultView,K=navigator.userAgent,z=/iP(?:ad|hone|od)/.test(K),Z=/Mac OS X/.test(K),q=/Gecko\//.test(K),Q=/Trident\/[456]\./.test(K),V=!!W.opera,G=/WebKit\//.test(K),$=Z?"meta-":"ctrl-",j=Q||V,Y=Q||G,X=Q,J="undefined"!=typeof MutationObserver,et=/[^ \t\r\n]/,tt=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var nt={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,r=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(nt[e.nodeType]&o&&r(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,r=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(nt[e.nodeType]&o&&r(e))return this.currentNode=e,e;t=e}};var ot=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|FN|EL)|EM|FONT|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TR(?:IKE|ONG)|MALL|AMP)?|U|VAR|WBR)$/,rt={BR:1,IMG:1,INPUT:1},it=function(e,t){for(var n=e.childNodes;t&&e.nodeType===R;)e=n[t-1],n=e.childNodes,t=n.length;return e},at=function(e,t){if(e.nodeType===R){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(w,o)<1;return!r&&!i}var a=e.compareBoundaryPoints(P,o)<1,s=e.compareBoundaryPoints(F,o)>-1;return a&&s},ft=function(e){for(var t,n=e.startContainer,o=e.startOffset,r=e.endContainer,i=e.endOffset;n.nodeType!==D&&(t=n.childNodes[o],t&&!a(t));)n=t,o=0;if(i)for(;r.nodeType!==D&&(t=r.childNodes[i-1],t&&!a(t));)r=t,i=g(r);else for(;r.nodeType!==D&&(t=r.firstChild,t&&!a(t));)r=t;e.collapsed?(e.setStart(r,i),e.setEnd(n,o)):(e.setStart(n,o),e.setEnd(r,i))},ut=function(e,t){var n,o=e.startContainer,r=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);o!==t&&!r;)n=o.parentNode,r=tt.call(n.childNodes,o),o=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=tt.call(n.childNodes,i)+1,i=n;e.setStart(o,r),e.setEnd(i,a)},pt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=it(n,e.startOffset),t=f(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,o=e.endContainer;if(s(o))t=h(o);else if(d(o))t=o;else{if(t=at(o,e.endOffset),!t)for(t=o.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},mt=new n(null,I|U,function(e){return e.nodeType===D?et.test(e.data):"IMG"===e.nodeName}),vt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===D){if(n)return!1;mt.currentNode=t}else mt.currentNode=at(t,n);return mt.root=pt(e),!mt.previousNode()},Ct=function(e){var t,n=e.endContainer,o=e.endOffset;if(n.nodeType===D){if(t=n.data.length,t&&t>o)return!1;mt.currentNode=n}else mt.currentNode=it(n,o);return mt.root=gt(e),!mt.nextNode()},Nt=function(e){var t,n=pt(e),o=gt(e);n&&o&&(t=n.parentNode,e.setStart(t,tt.call(t.childNodes,n)),t=o.parentNode,e.setEnd(t,tt.call(t.childNodes,o)+1))},_t=function(e){return function(t,n){n.preventDefault(),t[e]()}},St=function(e,t){return t=t||null,function(n,o){o.preventDefault();var r=n.getSelection();n.hasFormat(e,null,r)?n.changeFormat(null,{tag:e},r):n.changeFormat({tag:e},t,r)}},yt=function(e,t){try{t||(t=e.getSelection());var n,o=t.startContainer;for(o.nodeType===D&&(o=o.parentNode),n=o;s(n)&&(!n.textContent||n.textContent===M);)o=n,n=o.parentNode;o!==n&&(t.setStart(n,tt.call(n.childNodes,o)),t.collapse(!0),n.removeChild(o),d(n)||(n=h(n)),_(n),ft(t)),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(r){e.didError(r)}},Tt={enter:function(e,t,n){var o,r,i;if(t.preventDefault(),e._recordUndoState(n),Kt(n.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||lt(n),o=pt(n),!o||/^T[HD]$/.test(o.nodeName))return st(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((r=u(o,"LI"))&&(o=r),!o.textContent){if(u(o,"UL")||u(o,"OL"))return e.modifyBlocks(Mt,n);if(u(o,"BLOCKQUOTE"))return e.modifyBlocks(Ut,n)}for(i=xt(e,o,n.startContainer,n.startOffset),Bt(o),Gt(o),_(o);i.nodeType===R;){var a,s=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===M)){s=e._doc.createTextNode(""),v(i,s),i=s;break}for(;s&&s.nodeType===D&&!s.data&&(a=s.nextSibling,a&&"BR"!==a.nodeName);)m(s),s=a;if(!s||"BR"===s.nodeName||s.nodeType===D&&!V)break;i=s}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0),i.nodeType===D&&(i=i.parentNode);var d=e._doc,l=e._body;i.offsetTop+i.offsetHeight>(d.documentElement.scrollTop||l.scrollTop)+l.offsetHeight&&i.scrollIntoView(!1)},backspace:function(e,t,n){if(e._removeZWS(),e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(vt(n)){t.preventDefault();var o=pt(n),r=o&&h(o);if(r){if(!r.isContentEditable)return void m(r);for(b(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&k(o),e.setSelection(n)}else if(o){if(u(o,"UL")||u(o,"OL"))return e.modifyBlocks(Mt,n);if(u(o,"BLOCKQUOTE"))return e.modifyBlocks(Dt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){yt(e)},0);else t.preventDefault(),lt(n),yt(e,n)},"delete":function(e,t,n){if(e._removeZWS(),e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(Ct(n)){t.preventDefault();var o=pt(n),r=o&&f(o);if(r){if(!r.isContentEditable)return void m(r);for(b(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&k(r),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){yt(e)},0);else t.preventDefault(),lt(n),yt(e,n)},tab:function(e,t,n){var o,r;if(e._removeZWS(),n.collapsed&&vt(n)&&Ct(n)){for(o=pt(n);r=o.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){o.previousSibling&&(t.preventDefault(),e.modifyBlocks(Ht,n));break}o=r}t.preventDefault()}},space:function(e,t,n){var o,r;e._recordUndoState(n),Kt(n.startContainer),e._getRangeAndRemoveBookmark(n),o=n.endContainer,r=o.parentNode,n.collapsed&&"A"===r.nodeName&&!o.nextSibling&&n.endOffset===g(o)&&n.setStartAfter(r),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};Z&&q&&W.getSelection().modify&&(Tt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Tt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Tt[$+"b"]=St("B"),Tt[$+"i"]=St("I"),Tt[$+"u"]=St("U"),Tt[$+"shift-7"]=St("S"),Tt[$+"shift-5"]=St("SUB",{tag:"SUP"}),Tt[$+"shift-6"]=St("SUP",{tag:"SUB"}),Tt[$+"shift-8"]=_t("makeUnorderedList"),Tt[$+"shift-9"]=_t("makeOrderedList"),Tt[$+"["]=_t("decreaseQuoteLevel"),Tt[$+"]"]=_t("increaseQuoteLevel"),Tt[$+"y"]=_t("redo"),Tt[$+"z"]=_t("undo"),Tt[$+"shift-z"]=_t("redo");var bt=[],kt=O.prototype;kt.setConfig=function(e){return e=B({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},kt.createElement=function(e,t,n){return N(this._doc,e,t,n)},kt.createDefaultBlock=function(e){var t=this._config;return _(this.createElement(t.blockTag,t.blockAttributes,e))},kt.didError=function(e){console.log(e)},kt.getDocument=function(){return this._doc};var Et={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};kt.fireEvent=function(e,t){var n,o,r,i=this._events[e];if(i)for(t||(t={}),t.type!==e&&(t.type=e),i=i.slice(),n=0,o=i.length;o>n;n+=1){r=i[n];try{r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},kt.destroy=function(){var e,t=this._win,n=this._doc,o=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in o)Et[e]||n.removeEventListener(e,this,!0);this._mutation&&this._mutation.disconnect();for(var r=bt.length;r--;)bt[r]===this&&bt.splice(r,1)},kt.handleEvent=function(e){this.fireEvent(e.type,e)},kt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Et[e]||this._doc.addEventListener(e,this,!0)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},kt.removeEventListener=function(e,t){var n,o=this._events[e];if(o){for(n=o.length;n--;)o[n]===t&&o.splice(n,1);o.length||(delete this._events[e],Et[e]||this._doc.removeEventListener(e,this,!1))}return this},kt._createRange=function(e,t,n,o){if(e instanceof this._win.Range)return e.cloneRange();var r=this._doc.createRange();return r.setStart(e,t),n?r.setEnd(n,o):r.setEnd(e,t),r},kt._moveCursorTo=function(e){var t=this._body,n=this._createRange(t,e?0:t.childNodes.length);return ft(n),this.setSelection(n),this},kt.moveCursorToStart=function(){return this._moveCursorTo(!0)},kt.moveCursorToEnd=function(){return this._moveCursorTo(!1)},kt.setSelection=function(e){if(e){z&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},kt.getSelection=function(){var e,t,n,o=this._sel;return o.rangeCount?(e=o.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n),this._lastSelection=e):e=this._lastSelection,e||(e=this._createRange(this._body.firstChild,0)),e},kt.getSelectedText=function(){var e,t=this.getSelection(),o=new n(t.commonAncestorContainer,I|U,function(e){return ht(t,e,!0)}),r=t.startContainer,i=t.endContainer,a=o.currentNode=r,d="",l=!1;for(o.filter(a)||(a=o.nextNode());a;)a.nodeType===D?(e=a.data,e&&/\S/.test(e)&&(a===i&&(e=e.slice(0,t.endOffset)),a===r&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===a.nodeName||l&&!s(a))&&(d+="\n",l=!1),a=o.nextNode();return d},kt.getPath=function(){return this._path};var Bt=function(e){for(var t,o,r,i=new n(e,I,function(){return!0},!1);o=i.nextNode();)for(;(r=o.data.indexOf(M))>-1;){if(1===o.length){do t=o.parentNode,t.removeChild(o),o=t;while(s(o)&&!g(o));break}o.deleteData(r,1)}};kt._didAddZWS=function(){this._hasZWS=!0},kt._removeZWS=function(){this._hasZWS&&(Bt(this._body),this._hasZWS=!1)},kt._updatePath=function(e,t){var n,o=e.startContainer,r=e.endContainer;(t||o!==this._lastAnchorNode||r!==this._lastFocusNode)&&(this._lastAnchorNode=o,this._lastFocusNode=r,n=o&&r?o===r?p(r):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},kt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},kt.focus=function(){return V||this._body.focus(),this._win.focus(),this},kt.blur=function(){return q&&this._body.blur(),top.focus(),this};var Ot="squire-selection-start",At="squire-selection-end";kt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ot,type:"hidden"}),o=this.createElement("INPUT",{id:At,type:"hidden"});st(e,n),e.collapse(!1),st(e,o),n.compareDocumentPosition(o)&x&&(n.id=At,o.id=Ot,t=n,n=o,o=t),e.setStartAfter(n),e.setEndBefore(o)},kt._getRangeAndRemoveBookmark=function(e,t){var n=this._doc,o=n.getElementById(Ot),r=n.getElementById(At);if(o&&r){var i,a=o.parentNode,s=r.parentNode,d={startContainer:a,endContainer:s,startOffset:tt.call(a.childNodes,o),endOffset:tt.call(s.childNodes,r)};a===s&&(d.endOffset-=1),m(o),m(r),t||(T(a,d),a!==s&&T(s,d)),e||(e=n.createRange()),e.setStart(d.startContainer,d.startOffset),e.setEnd(d.endContainer,d.endOffset),i=e.collapsed,ft(e),i&&e.collapse(!0)}return e||null},kt._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},kt._docWasChanged=function(){return J&&this._ignoreChange?void(this._ignoreChange=!1):(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),void this.fireEvent("input"))},kt._recordUndoState=function(e){if(!this._isInUndoState){var t=this._undoIndex+=1,n=this._undoStack;te+1&&this._isInUndoState){this._undoIndex+=1,this._setHTML(this._undoStack[this._undoIndex]);var n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:t>e+2}),this.fireEvent("input")}return this},kt.hasFormat=function(e,t,o){if(e=e.toUpperCase(),t||(t={}),!o&&!(o=this.getSelection()))return!1;var r,i,a=o.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===D)return!1;r=new n(a,I,function(e){return ht(o,e,!0)},!1);for(var s=!1;i=r.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},kt._addFormat=function(e,t,o){var r,i,a,s,d,l,c,h;if(o.collapsed)r=_(this.createElement(e,t)),st(o,r),o.setStart(r.firstChild,r.firstChild.length),o.collapse(!0);else{if(i=new n(o.commonAncestorContainer,I|U,function(e){return(e.nodeType===D||"BR"===e.nodeName)&&ht(o,e,!0)},!1),a=o.startContainer,d=o.startOffset,s=o.endContainer,l=o.endOffset,i.currentNode=a,i.filter(a)||(a=i.nextNode(),d=0),!a)return o;do c=i.currentNode,h=!u(c,e,t),h&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),s===a&&(s=c,l-=d),a=c,d=0),r=this.createElement(e,t),v(c,r),r.appendChild(c));while(i.nextNode());s.nodeType!==D&&(c.nodeType===D?(s=c,l=c.length):(s=c.parentNode,l=1)),o=this._createRange(a,d,s,l)}return o},kt._removeFormat=function(e,t,n,o){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode(M),this._didAddZWS()):i=a.createTextNode(""),st(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,h=n.endContainer,f=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var o,r,i=e.nodeType===D;if(!ht(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===h&&f!==e.length&&u.push([t,e.splitText(f)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(o=e.firstChild;o;o=r)r=o.nextSibling,p(o,t)}},g=Array.prototype.filter.call(d.getElementsByTagName(e),function(o){return ht(n,o,!0)&&r(o,e,t)});o||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];v(n,t),t.appendChild(n)}),g.forEach(function(e){v(e,C(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return T(d,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},kt.changeFormat=function(e,t,n,o){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,o)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),J||this._docWasChanged(),this):void 0};var Lt={DT:"DD",DD:"DT",LI:"LI"},xt=function(e,t,n,o){var i=Lt[t.nodeName],a=null,s=y(n,o,t.parentNode),d=e._config;return i||(i=d.blockTag,a=d.blockAttributes),r(s,i,a)||(t=N(s.ownerDocument,i,a),s.dir&&(t.dir=s.dir),v(s,t),t.appendChild(C(s)),s=t),s};kt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var o=pt(n),r=gt(n);if(o&&r)do if(e(o)||o===r)break;while(o=f(o));return t&&(this.setSelection(n),this._updatePath(n,!0),J||this._docWasChanged()),this},kt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Nt(t);var n,o=this._body;return ut(t,o),n=dt(t,o),st(t,e.call(this,n)),t.endOffsett;t+=1){for(r=d[t],i=C(r),a=i.childNodes,o=a.length;o--;)s=a[o],v(s,C(s));S(i),v(r,i)}return e},Ht=function(e){var t,n,o,r,i,a,s=e.querySelectorAll("LI"),d=this._config.tagAttributes,c=d.li;for(t=0,n=s.length;n>t;t+=1)o=s[t],l(o.firstChild)||(r=o.parentNode.nodeName,i=o.previousSibling,i&&(i=i.lastChild)&&i.nodeName===r||(a=d[r.toLowerCase()],v(o,this.createElement("LI",c,[i=this.createElement(r,a)]))),i.appendChild(o));return e},Mt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,o=t.parentNode,r=o.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(o=y(o,t,r));a&&(n=a.nextSibling,!l(a));)r.insertBefore(a,o),a=n;for("LI"===r.nodeName&&i.previousSibling&&y(r,i,r.parentNode);t!==e&&!t.childNodes.length;)o=t.parentNode,o.removeChild(t),t=o},this),S(e),e},Wt=/\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i,Kt=function(e){for(var t,o,r,i,a,s,d,l=e.ownerDocument,c=new n(e,I,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(o=t.data,r=t.parentNode;i=Wt.exec(o);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(o.slice(0,a)),r.insertBefore(d,t)),d=l.createElement("A"),d.textContent=o.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],r.insertBefore(d,t),t.data=o=o.slice(s)},zt=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/,Zt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},qt={backgroundColor:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return N(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return N(e,"I")}},fontFamily:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Qt=function(e){return function(t,n){var o=N(t.ownerDocument,e);return n.replaceChild(o,t),o.appendChild(C(t)),o}},Vt={SPAN:function(e,t){var n,o,r,i,a,s,d=e.style,l=e.ownerDocument;for(n in qt)o=qt[n],r=d[n],r&&o.regexp.test(r)&&(s=o.replace(l,r),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(C(e)),t.replaceChild(a,e)),i||e},STRONG:Qt("B"),EM:Qt("I"),STRIKE:Qt("S"),FONT:function(e,t){var n,o,r,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=N(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(o=N(c,"SPAN",{"class":"size",style:"font-size:"+Zt[d]+"px"}),a||(a=o),i&&i.appendChild(o),i=o),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),r=N(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=r),i&&i.appendChild(r),i=r),a||(a=i=N(c,"SPAN")),t.replaceChild(a,e),i.appendChild(C(e)),i},TT:function(e,t){var n=N(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(C(e)),n}},Gt=function(e){for(var t,n=e.childNodes,o=n.length;o--;)t=n[o],t.nodeType!==R||a(t)?t.nodeType!==D||t.data||e.removeChild(t):(Gt(t),s(t)&&!t.firstChild&&e.removeChild(t))},$t=function(e,t){var n,o,r,i,a,d,l,c,h,f,u=e.childNodes;for(n=0,o=u.length;o>n;n+=1)if(r=u[n],i=r.nodeName,a=r.nodeType,d=Vt[i],a===R){if(l=r.childNodes.length,d)r=d(r,e);else{if(!zt.test(i)&&!s(r)){n-=1,o+=l-1,e.replaceChild(C(r),r);continue}!t&&r.style.cssText&&r.removeAttribute("style")}l&&$t(r,t)}else{if(a===D){if(c=r.data,/\S/.test(c)){if(s(e))continue;if(h=0,f=c.length,!n||!s(u[n-1])){for(;f>h&&!et.test(c.charAt(h));)h+=1;h&&(r.data=c=c.slice(h),f-=h)}if(n+1===o||!s(u[n+1])){for(h=f;h>0&&!et.test(c.charAt(h-1));)h-=1;f>h&&(r.data=c.slice(0,h))}continue}if(n&&o>n+1&&s(u[n-1])&&s(u[n+1])){r.data=" ";continue}}e.removeChild(r),n-=1,o-=1}return e},jt=function(e){return e.nodeType===R?"BR"===e.nodeName:et.test(e.data)},Yt=function(e){for(var t,o=e.parentNode;s(o);)o=o.parentNode;return t=new n(o,U|I,jt),t.currentNode=e,!!t.nextNode()},Xt=function(e){var t,n,o,r=e.querySelectorAll("BR"),i=[],a=r.length;for(t=0;a>t;t+=1)i[t]=Yt(r[t]);for(;a--;)n=r[a],o=n.parentNode,o&&(i[a]?s(o)||S(o):m(n))};kt._ensureBottomLine=function(){var e=this._body,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&d(t)||e.appendChild(this.createDefaultBlock())},kt._onCut=function(){var e=this.getSelection(),t=this;this._recordUndoState(e),this._getRangeAndRemoveBookmark(e),this.setSelection(e),setTimeout(function(){try{t._ensureBottomLine()}catch(e){t.didError(e)}},0)},kt._onPaste=function(e){if(!this._awaitingPaste){var t,n,o=e.clipboardData,r=o&&o.items,i=!1,a=!1;if(r){for(t=r.length;t--;){if(n=r[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:o,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:o}))}this._awaitingPaste=!0;var s,d,l,c,h,u=this,p=this._body,g=this.getSelection();u._recordUndoState(g),u._getRangeAndRemoveBookmark(g),s=g.startContainer,d=g.startOffset,l=g.endContainer,c=g.endOffset,h=pt(g);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(p.scrollTop+(h?h.getBoundingClientRect().top:0))+"px; right: 150%; width: 1px; height: 1px;"});p.appendChild(v),g.selectNodeContents(v),this.setSelection(g),setTimeout(function(){try{for(var e,t,n=u._doc.createDocumentFragment(),o=v;v=o;)o=v.nextSibling,n.appendChild(C(m(v)));if(e=n.firstChild,t=u._createRange(s,d,l,c),e){e===n.lastChild&&"DIV"===e.nodeName&&n.replaceChild(C(e),e),n.normalize(),Kt(n),$t(n,!1),Xt(n),Gt(n);for(var r=n,i=!0,a={fragment:n,preventDefault:function(){i=!1},isDefaultPrevented:function(){return!i}};r=f(r);)_(r);u.fireEvent("willPaste",a),i&&(ct(t,a.fragment),J||u._docWasChanged(),t.collapse(!1),u._ensureBottomLine())}u.setSelection(t),u._updatePath(t,!0),u._awaitingPaste=!1}catch(h){u.didError(h) +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function o(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function r(e,t,n){if(e.nodeName!==t)return!1;for(var o in n)if(e.getAttribute(o)!==n[o])return!1;return!0}function i(e,t){return e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function a(e){return e.nodeType===R&&!!rt[e.nodeName]}function s(e){return ot.test(e.nodeName)}function d(e){return e.nodeType===R&&!s(e)&&o(e.childNodes,s)}function l(e){return e.nodeType===R&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,o=new n(t.body,U,d,!1);return o.currentNode=e,o}function h(e){return c(e).previousNode()}function f(e){return c(e).nextNode()}function u(e,t,n){do if(r(e,t,n))return e;while(e=e.parentNode);return null}function p(e){var t,n,o,r,i,a=e.parentNode;return a&&e.nodeType===R?(t=p(a),t+=(t?">":"")+e.nodeName,(n=e.id)&&(t+="#"+n),(o=e.className.trim())&&(r=o.split(/\s\s*/),r.sort(),t+=".",t+=r.join(".")),(i=e.dir)&&(t+="[dir="+i+"]")):t=a?p(a):"",t}function g(e){var t=e.nodeType;return t===R?e.childNodes.length:e.length||0}function m(e){var t=e.parentNode;return t&&t.removeChild(e),e}function v(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function C(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,o=n?n.length:0;o--;)t.appendChild(e.firstChild);return t}function N(e,n,o,r){var i,a,s,d,l=e.createElement(n);if(o instanceof Array&&(r=o,o=null),o)for(i in o)a=o[i],a!==t&&l.setAttribute(i,o[i]);if(r)for(s=0,d=r.length;d>s;s+=1)l.appendChild(r[s]);return l}function _(e){var t,n,o=e.ownerDocument,r=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=E(o).createDefaultBlock(),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;Y&&n&&n.nodeType===D&&!n.data;)e.removeChild(n),n=e.firstChild;n||(Y?(t=o.createTextNode(M),E(o)._didAddZWS()):t=o.createTextNode(""))}else if(j){for(;e.nodeType!==D&&!a(e);){if(n=e.firstChild,!n){t=o.createTextNode("");break}e=n}e.nodeType===D?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(o.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=N(o,"BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),r}function S(e){var t,n,o,r,i=e.childNodes,a=e.ownerDocument,d=null,c=E(a)._config;for(t=0,n=i.length;n>t;t+=1)o=i[t],r="BR"===o.nodeName,!r&&s(o)?(d||(d=N(a,c.blockTag,c.blockAttributes)),d.appendChild(o),t-=1,n-=1):(r||d)&&(d||(d=N(a,c.blockTag,c.blockAttributes)),_(d),r?e.replaceChild(d,o):(e.insertBefore(d,o),t+=1,n+=1),d=null),l(o)&&S(o);return d&&e.appendChild(_(d)),e}function y(e,t,n){var o,r,i,a=e.nodeType;if(a===D&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===R){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=o,t.startOffset=g(o))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=o,t.endOffset=g(o))),m(n),n.nodeType===D?o.appendData(n.data):l.push(C(n));else if(n.nodeType===R){for(r=l.length;r--;)n.appendChild(l.pop());T(n,t)}}function b(e,t,n){for(var o,r,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;m(a),r=e.childNodes.length,o=e.lastChild,o&&"BR"===o.nodeName&&(e.removeChild(o),r-=1),i={startContainer:e,startOffset:r,endContainer:e,endOffset:r},e.appendChild(C(t)),T(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),V&&(o=e.lastChild)&&"BR"===o.nodeName&&e.removeChild(o)}function k(e){var t,n,o=e.previousSibling,r=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||r&&/^[OU]L$/.test(r.nodeName))if(o&&i(o,e)){if(!l(o)){if(!s)return;n=N(a,"DIV"),n.appendChild(C(o)),o.appendChild(n)}m(e),t=!l(e),o.appendChild(C(e)),t&&S(o),r&&k(r)}else s&&(o=N(a,"DIV"),e.insertBefore(o,r),_(o))}function E(e){for(var t,n=bt.length;n--;)if(t=bt[n],t._doc===e)return t;return null}function B(e,t){var n,o;e||(e={});for(n in t)o=t[n],e[n]=o&&o.constructor===Object?B(e[n],o):o;return e}function O(e,t){var n,o=e.defaultView,r=e.body;this._win=o,this._doc=e,this._body=r,this._events={},this._sel=o.getSelection(),this._lastSelection=null,X&&this.addEventListener("beforedeactivate",this.getSelection),this._hasZWS=!1,this._lastAnchorNode=null,this._lastFocusNode=null,this._path="",this.addEventListener("keyup",this._updatePathOnEvent),this.addEventListener("mouseup",this._updatePathOnEvent),o.addEventListener("focus",this,!1),o.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,J?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(r,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._awaitingPaste=!1,this.addEventListener(Q?"beforecut":"cut",this._onCut),this.addEventListener(Q?"beforepaste":"paste",this._onPaste),this.addEventListener(V?"keypress":"keydown",this._onKey),this._keyHandlers=Object.create(Tt),this.setConfig(t),Q&&(o.Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,o=this.parentNode,r=this.length-e;return n?o.insertBefore(t,n):o.appendChild(t),r&&this.deleteData(e,r),t}),r.setAttribute("contenteditable","true");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}bt.push(this),this.setHTML("")}function A(e,t,n){for(var o=(e.childNodes,e.firstChild);o;)ht(t,o,!1)&&n(o),o=o.nextSibling}function L(e,t,n){var o=[];return A(e,t,function(e){o.push(n(e))}),o}var x=2,R=1,D=3,U=1,I=4,P=0,w=1,F=2,H=3,M="​",W=e.defaultView,K=navigator.userAgent,z=/iP(?:ad|hone|od)/.test(K),Z=/Mac OS X/.test(K),q=/Gecko\//.test(K),Q=/Trident\/[456]\./.test(K),V=!!W.opera,G=/WebKit\//.test(K),$=Z?"meta-":"ctrl-",j=Q||V,Y=Q||G,X=Q,J="undefined"!=typeof MutationObserver,et=/[^ \t\r\n]/,tt=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var nt={1:1,2:2,3:4,8:128,9:256,11:1024};n.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,r=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(nt[e.nodeType]&o&&r(e))return this.currentNode=e,e;t=e}},n.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,o=this.nodeType,r=this.filter;;){if(t===n)return null;if(e=t.previousSibling)for(;t=e.lastChild;)e=t;else e=t.parentNode;if(!e)return null;if(nt[e.nodeType]&o&&r(e))return this.currentNode=e,e;t=e}};var ot=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|FN|EL)|EM|FONT|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TR(?:IKE|ONG)|MALL|AMP)?|U|VAR|WBR)$/,rt={BR:1,IMG:1,INPUT:1},it=function(e,t){for(var n=e.childNodes;t&&e.nodeType===R;)e=n[t-1],n=e.childNodes,t=n.length;return e},at=function(e,t){if(e.nodeType===R){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(w,o)<1;return!r&&!i}var a=e.compareBoundaryPoints(P,o)<1,s=e.compareBoundaryPoints(F,o)>-1;return a&&s},ft=function(e){for(var t,n=e.startContainer,o=e.startOffset,r=e.endContainer,i=e.endOffset;n.nodeType!==D&&(t=n.childNodes[o],t&&!a(t));)n=t,o=0;if(i)for(;r.nodeType!==D&&(t=r.childNodes[i-1],t&&!a(t));)r=t,i=g(r);else for(;r.nodeType!==D&&(t=r.firstChild,t&&!a(t));)r=t;e.collapsed?(e.setStart(r,i),e.setEnd(n,o)):(e.setStart(n,o),e.setEnd(r,i))},ut=function(e,t){var n,o=e.startContainer,r=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);o!==t&&!r;)n=o.parentNode,r=tt.call(n.childNodes,o),o=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=tt.call(n.childNodes,i)+1,i=n;e.setStart(o,r),e.setEnd(i,a)},pt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=it(n,e.startOffset),t=f(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,o=e.endContainer;if(s(o))t=h(o);else if(d(o))t=o;else{if(t=at(o,e.endOffset),!t)for(t=o.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},mt=new n(null,I|U,function(e){return e.nodeType===D?et.test(e.data):"IMG"===e.nodeName}),vt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===D){if(n)return!1;mt.currentNode=t}else mt.currentNode=at(t,n);return mt.root=pt(e),!mt.previousNode()},Ct=function(e){var t,n=e.endContainer,o=e.endOffset;if(n.nodeType===D){if(t=n.data.length,t&&t>o)return!1;mt.currentNode=n}else mt.currentNode=it(n,o);return mt.root=gt(e),!mt.nextNode()},Nt=function(e){var t,n=pt(e),o=gt(e);n&&o&&(t=n.parentNode,e.setStart(t,tt.call(t.childNodes,n)),t=o.parentNode,e.setEnd(t,tt.call(t.childNodes,o)+1))},_t=function(e){return function(t,n){n.preventDefault(),t[e]()}},St=function(e,t){return t=t||null,function(n,o){o.preventDefault();var r=n.getSelection();n.hasFormat(e,null,r)?n.changeFormat(null,{tag:e},r):n.changeFormat({tag:e},t,r)}},yt=function(e,t){try{t||(t=e.getSelection());var n,o=t.startContainer;for(o.nodeType===D&&(o=o.parentNode),n=o;s(n)&&(!n.textContent||n.textContent===M);)o=n,n=o.parentNode;o!==n&&(t.setStart(n,tt.call(n.childNodes,o)),t.collapse(!0),n.removeChild(o),d(n)||(n=h(n)),_(n),ft(t)),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(r){e.didError(r)}},Tt={enter:function(e,t,n){var o,r,i;if(t.preventDefault(),e._recordUndoState(n),Kt(n.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||lt(n),o=pt(n),!o||/^T[HD]$/.test(o.nodeName))return st(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((r=u(o,"LI"))&&(o=r),!o.textContent){if(u(o,"UL")||u(o,"OL"))return e.modifyBlocks(Mt,n);if(u(o,"BLOCKQUOTE"))return e.modifyBlocks(Ut,n)}for(i=xt(e,o,n.startContainer,n.startOffset),Bt(o),Gt(o),_(o);i.nodeType===R;){var a,s=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===M)){s=e._doc.createTextNode(""),v(i,s),i=s;break}for(;s&&s.nodeType===D&&!s.data&&(a=s.nextSibling,a&&"BR"!==a.nodeName);)m(s),s=a;if(!s||"BR"===s.nodeName||s.nodeType===D&&!V)break;i=s}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0),i.nodeType===D&&(i=i.parentNode);var d=e._doc,l=e._body;i.offsetTop+i.offsetHeight>(d.documentElement.scrollTop||l.scrollTop)+l.offsetHeight&&i.scrollIntoView(!1)},backspace:function(e,t,n){if(e._removeZWS(),e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(vt(n)){t.preventDefault();var o=pt(n),r=o&&h(o);if(r){if(!r.isContentEditable)return void m(r);for(b(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&k(o),e.setSelection(n)}else if(o){if(u(o,"UL")||u(o,"OL"))return e.modifyBlocks(Mt,n);if(u(o,"BLOCKQUOTE"))return e.modifyBlocks(Dt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){yt(e)},0);else t.preventDefault(),lt(n),yt(e,n)},"delete":function(e,t,n){if(e._removeZWS(),e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(Ct(n)){t.preventDefault();var o=pt(n),r=o&&f(o);if(r){if(!r.isContentEditable)return void m(r);for(b(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&k(r),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){yt(e)},0);else t.preventDefault(),lt(n),yt(e,n)},tab:function(e,t,n){var o,r;if(e._removeZWS(),n.collapsed&&vt(n)&&Ct(n)){for(o=pt(n);r=o.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){o.previousSibling&&(t.preventDefault(),e.modifyBlocks(Ht,n));break}o=r}t.preventDefault()}},space:function(e,t,n){var o,r;e._recordUndoState(n),Kt(n.startContainer),e._getRangeAndRemoveBookmark(n),o=n.endContainer,r=o.parentNode,n.collapsed&&"A"===r.nodeName&&!o.nextSibling&&n.endOffset===g(o)&&n.setStartAfter(r),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};Z&&q&&W.getSelection().modify&&(Tt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Tt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Tt[$+"b"]=St("B"),Tt[$+"i"]=St("I"),Tt[$+"u"]=St("U"),Tt[$+"shift-7"]=St("S"),Tt[$+"shift-5"]=St("SUB",{tag:"SUP"}),Tt[$+"shift-6"]=St("SUP",{tag:"SUB"}),Tt[$+"shift-8"]=_t("makeUnorderedList"),Tt[$+"shift-9"]=_t("makeOrderedList"),Tt[$+"["]=_t("decreaseQuoteLevel"),Tt[$+"]"]=_t("increaseQuoteLevel"),Tt[$+"y"]=_t("redo"),Tt[$+"z"]=_t("undo"),Tt[$+"shift-z"]=_t("redo");var bt=[],kt=O.prototype;kt.setConfig=function(e){return e=B({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},kt.createElement=function(e,t,n){return N(this._doc,e,t,n)},kt.createDefaultBlock=function(e){var t=this._config;return _(this.createElement(t.blockTag,t.blockAttributes,e))},kt.didError=function(e){console.log(e)},kt.getDocument=function(){return this._doc};var Et={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};kt.fireEvent=function(e,t){var n,o,r,i=this._events[e];if(i)for(t||(t={}),t.type!==e&&(t.type=e),i=i.slice(),n=0,o=i.length;o>n;n+=1){r=i[n];try{r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},kt.destroy=function(){var e,t=this._win,n=this._doc,o=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in o)Et[e]||n.removeEventListener(e,this,!0);this._mutation&&this._mutation.disconnect();for(var r=bt.length;r--;)bt[r]===this&&bt.splice(r,1)},kt.handleEvent=function(e){this.fireEvent(e.type,e)},kt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Et[e]||this._doc.addEventListener(e,this,!0)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},kt.removeEventListener=function(e,t){var n,o=this._events[e];if(o){for(n=o.length;n--;)o[n]===t&&o.splice(n,1);o.length||(delete this._events[e],Et[e]||this._doc.removeEventListener(e,this,!1))}return this},kt._createRange=function(e,t,n,o){if(e instanceof this._win.Range)return e.cloneRange();var r=this._doc.createRange();return r.setStart(e,t),n?r.setEnd(n,o):r.setEnd(e,t),r},kt._moveCursorTo=function(e){var t=this._body,n=this._createRange(t,e?0:t.childNodes.length);return ft(n),this.setSelection(n),this},kt.moveCursorToStart=function(){return this._moveCursorTo(!0)},kt.moveCursorToEnd=function(){return this._moveCursorTo(!1)},kt.setSelection=function(e){if(e){z&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},kt.getSelection=function(){var e,t,n,o=this._sel;return o.rangeCount?(e=o.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n),this._lastSelection=e):e=this._lastSelection,e||(e=this._createRange(this._body.firstChild,0)),e},kt.getSelectedText=function(){var e,t=this.getSelection(),o=new n(t.commonAncestorContainer,I|U,function(e){return ht(t,e,!0)}),r=t.startContainer,i=t.endContainer,a=o.currentNode=r,d="",l=!1;for(o.filter(a)||(a=o.nextNode());a;)a.nodeType===D?(e=a.data,e&&/\S/.test(e)&&(a===i&&(e=e.slice(0,t.endOffset)),a===r&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===a.nodeName||l&&!s(a))&&(d+="\n",l=!1),a=o.nextNode();return d},kt.getPath=function(){return this._path};var Bt=function(e){for(var t,o,r,i=new n(e,I,function(){return!0},!1);o=i.nextNode();)for(;(r=o.data.indexOf(M))>-1;){if(1===o.length){do t=o.parentNode,t.removeChild(o),o=t;while(s(o)&&!g(o));break}o.deleteData(r,1)}};kt._didAddZWS=function(){this._hasZWS=!0},kt._removeZWS=function(){this._hasZWS&&(Bt(this._body),this._hasZWS=!1)},kt._updatePath=function(e,t){var n,o=e.startContainer,r=e.endContainer;(t||o!==this._lastAnchorNode||r!==this._lastFocusNode)&&(this._lastAnchorNode=o,this._lastFocusNode=r,n=o&&r?o===r?p(r):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},kt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},kt.focus=function(){return V||this._body.focus(),this._win.focus(),this},kt.blur=function(){return q&&this._body.blur(),top.focus(),this};var Ot="squire-selection-start",At="squire-selection-end";kt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ot,type:"hidden"}),o=this.createElement("INPUT",{id:At,type:"hidden"});st(e,n),e.collapse(!1),st(e,o),n.compareDocumentPosition(o)&x&&(n.id=At,o.id=Ot,t=n,n=o,o=t),e.setStartAfter(n),e.setEndBefore(o)},kt._getRangeAndRemoveBookmark=function(e,t){var n=this._doc,o=n.getElementById(Ot),r=n.getElementById(At);if(o&&r){var i,a=o.parentNode,s=r.parentNode,d={startContainer:a,endContainer:s,startOffset:tt.call(a.childNodes,o),endOffset:tt.call(s.childNodes,r)};a===s&&(d.endOffset-=1),m(o),m(r),t||(T(a,d),a!==s&&T(s,d)),e||(e=n.createRange()),e.setStart(d.startContainer,d.startOffset),e.setEnd(d.endContainer,d.endOffset),i=e.collapsed,ft(e),i&&e.collapse(!0)}return e||null},kt._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},kt._docWasChanged=function(){return J&&this._ignoreChange?void(this._ignoreChange=!1):(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),void this.fireEvent("input"))},kt._recordUndoState=function(e){if(!this._isInUndoState){var t=this._undoIndex+=1,n=this._undoStack;te+1&&this._isInUndoState){this._undoIndex+=1,this._setHTML(this._undoStack[this._undoIndex]);var n=this._getRangeAndRemoveBookmark();n&&this.setSelection(n),this.fireEvent("undoStateChange",{canUndo:!0,canRedo:t>e+2}),this.fireEvent("input")}return this},kt.hasFormat=function(e,t,o){if(e=e.toUpperCase(),t||(t={}),!o&&!(o=this.getSelection()))return!1;var r,i,a=o.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===D)return!1;r=new n(a,I,function(e){return ht(o,e,!0)},!1);for(var s=!1;i=r.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},kt._addFormat=function(e,t,o){var r,i,a,s,d,l,c,h;if(o.collapsed)r=_(this.createElement(e,t)),st(o,r),o.setStart(r.firstChild,r.firstChild.length),o.collapse(!0);else{if(i=new n(o.commonAncestorContainer,I|U,function(e){return(e.nodeType===D||"BR"===e.nodeName)&&ht(o,e,!0)},!1),a=o.startContainer,d=o.startOffset,s=o.endContainer,l=o.endOffset,i.currentNode=a,i.filter(a)||(a=i.nextNode(),d=0),!a)return o;do c=i.currentNode,h=!u(c,e,t),h&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),s===a&&(s=c,l-=d),a=c,d=0),r=this.createElement(e,t),v(c,r),r.appendChild(c));while(i.nextNode());s.nodeType!==D&&(c.nodeType===D?(s=c,l=c.length):(s=c.parentNode,l=1)),o=this._createRange(a,d,s,l)}return o},kt._removeFormat=function(e,t,n,o){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode(M),this._didAddZWS()):i=a.createTextNode(""),st(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,h=n.endContainer,f=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var o,r,i=e.nodeType===D;if(!ht(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===h&&f!==e.length&&u.push([t,e.splitText(f)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(o=e.firstChild;o;o=r)r=o.nextSibling,p(o,t)}},g=Array.prototype.filter.call(d.getElementsByTagName(e),function(o){return ht(n,o,!0)&&r(o,e,t)});o||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];v(n,t),t.appendChild(n)}),g.forEach(function(e){v(e,C(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return T(d,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},kt.changeFormat=function(e,t,n,o){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,o)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),J||this._docWasChanged(),this):void 0};var Lt={DT:"DD",DD:"DT",LI:"LI"},xt=function(e,t,n,o){var i=Lt[t.nodeName],a=null,s=y(n,o,t.parentNode),d=e._config;return i||(i=d.blockTag,a=d.blockAttributes),r(s,i,a)||(t=N(s.ownerDocument,i,a),s.dir&&(t.dir=s.dir),v(s,t),t.appendChild(C(s)),s=t),s};kt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var o=pt(n),r=gt(n);if(o&&r)do if(e(o)||o===r)break;while(o=f(o));return t&&(this.setSelection(n),this._updatePath(n,!0),J||this._docWasChanged()),this},kt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Nt(t);var n,o=this._body;return ut(t,o),n=dt(t,o),st(t,e.call(this,n)),t.endOffsett;t+=1){for(r=d[t],i=C(r),a=i.childNodes,o=a.length;o--;)s=a[o],v(s,C(s));S(i),v(r,i)}return e},Ht=function(e){var t,n,o,r,i,a,s=e.querySelectorAll("LI"),d=this._config.tagAttributes,c=d.li;for(t=0,n=s.length;n>t;t+=1)o=s[t],l(o.firstChild)||(r=o.parentNode.nodeName,i=o.previousSibling,i&&(i=i.lastChild)&&i.nodeName===r||(a=d[r.toLowerCase()],v(o,this.createElement("LI",c,[i=this.createElement(r,a)]))),i.appendChild(o));return e},Mt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,o=t.parentNode,r=o.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(o=y(o,t,r));a&&(n=a.nextSibling,!l(a));)r.insertBefore(a,o),a=n;for("LI"===r.nodeName&&i.previousSibling&&y(r,i,r.parentNode);t!==e&&!t.childNodes.length;)o=t.parentNode,o.removeChild(t),t=o},this),S(e),e},Wt=/\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i,Kt=function(e){for(var t,o,r,i,a,s,d,l=e.ownerDocument,c=new n(e,I,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(o=t.data,r=t.parentNode;i=Wt.exec(o);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(o.slice(0,a)),r.insertBefore(d,t)),d=l.createElement("A"),d.textContent=o.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],r.insertBefore(d,t),t.data=o=o.slice(s)},zt=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/,Zt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},qt={backgroundColor:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return N(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return N(e,"I")}},fontFamily:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:et,replace:function(e,t){return N(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Qt=function(e){return function(t,n){var o=N(t.ownerDocument,e);return n.replaceChild(o,t),o.appendChild(C(t)),o}},Vt={SPAN:function(e,t){var n,o,r,i,a,s,d=e.style,l=e.ownerDocument;for(n in qt)o=qt[n],r=d[n],r&&o.regexp.test(r)&&(s=o.replace(l,r),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(C(e)),t.replaceChild(a,e)),i||e},STRONG:Qt("B"),EM:Qt("I"),STRIKE:Qt("S"),FONT:function(e,t){var n,o,r,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=N(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(o=N(c,"SPAN",{"class":"size",style:"font-size:"+Zt[d]+"px"}),a||(a=o),i&&i.appendChild(o),i=o),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),r=N(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=r),i&&i.appendChild(r),i=r),a||(a=i=N(c,"SPAN")),t.replaceChild(a,e),i.appendChild(C(e)),i},TT:function(e,t){var n=N(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(C(e)),n}},Gt=function(e){for(var t,n=e.childNodes,o=n.length;o--;)t=n[o],t.nodeType!==R||a(t)?t.nodeType!==D||t.data||e.removeChild(t):(Gt(t),s(t)&&!t.firstChild&&e.removeChild(t))},$t=function(e,t){var n,o,r,i,a,d,l,c,h,f,u=e.childNodes;for(n=0,o=u.length;o>n;n+=1)if(r=u[n],i=r.nodeName,a=r.nodeType,d=Vt[i],a===R){if(l=r.childNodes.length,d)r=d(r,e);else{if(!zt.test(i)&&!s(r)){n-=1,o+=l-1,e.replaceChild(C(r),r);continue}!t&&r.style.cssText&&r.removeAttribute("style")}l&&$t(r,t)}else{if(a===D){if(c=r.data,/\S/.test(c)){if(s(e))continue;if(h=0,f=c.length,!n||!s(u[n-1])){for(;f>h&&!et.test(c.charAt(h));)h+=1;h&&(r.data=c=c.slice(h),f-=h)}if(n+1===o||!s(u[n+1])){for(h=f;h>0&&!et.test(c.charAt(h-1));)h-=1;f>h&&(r.data=c.slice(0,h))}continue}if(n&&o>n+1&&s(u[n-1])&&s(u[n+1])){r.data=" ";continue}}e.removeChild(r),n-=1,o-=1}return e},jt=function(e){return e.nodeType===R?"BR"===e.nodeName:et.test(e.data)},Yt=function(e){for(var t,o=e.parentNode;s(o);)o=o.parentNode;return t=new n(o,U|I,jt),t.currentNode=e,!!t.nextNode()},Xt=function(e){var t,n,o,r=e.querySelectorAll("BR"),i=[],a=r.length;for(t=0;a>t;t+=1)i[t]=Yt(r[t]);for(;a--;)n=r[a],o=n.parentNode,o&&(i[a]?s(o)||S(o):m(n))};kt._ensureBottomLine=function(){var e=this._body,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&d(t)||e.appendChild(this.createDefaultBlock())},kt._onCut=function(){var e=this.getSelection(),t=this;this._recordUndoState(e),this._getRangeAndRemoveBookmark(e),this.setSelection(e),setTimeout(function(){try{t._ensureBottomLine()}catch(e){t.didError(e)}},0)},kt._onPaste=function(e){if(!this._awaitingPaste){var t,n,o=e.clipboardData,r=o&&o.items,i=!1,a=!1;if(r){for(t=r.length;t--;){if(n=r[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:o,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:o}))}this._awaitingPaste=!0;var s,d,l,c,h,u=this,p=this._body,g=this.getSelection();u._recordUndoState(g),u._getRangeAndRemoveBookmark(g),s=g.startContainer,d=g.startOffset,l=g.endContainer,c=g.endOffset,h=pt(g);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(p.scrollTop+(h?h.getBoundingClientRect().top:0))+"px; right: 150%; width: 1px; height: 1px;"});p.appendChild(v),g.selectNodeContents(v),this.setSelection(g),setTimeout(function(){try{for(var e,t,n=u._doc.createDocumentFragment(),o=v;v=o;)o=v.nextSibling,n.appendChild(C(m(v)));if(e=n.firstChild,t=u._createRange(s,d,l,c),e){e===n.lastChild&&"DIV"===e.nodeName&&n.replaceChild(C(e),e),n.normalize(),Kt(n),$t(n,!1),Xt(n),Gt(n);for(var r=n,i=!0,a={fragment:n,preventDefault:function(){i=!1},isDefaultPrevented:function(){return!i}};r=f(r);)_(r);u.fireEvent("willPaste",a),i&&(ct(t,a.fragment),J||u._docWasChanged(),t.collapse(!1),u._ensureBottomLine())}u.setSelection(t),u._updatePath(t,!0),u._awaitingPaste=!1}catch(h){u.didError(h) }},0)}};var Jt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"};kt._onKey=function(e){var t=e.keyCode,n=Jt[t],o="",r=this.getSelection();n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),V&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(o+="alt-"),e.ctrlKey&&(o+="ctrl-"),e.metaKey&&(o+="meta-")),e.shiftKey&&(o+="shift-"),n=o+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,r):1!==n.length||r.collapsed||(this._recordUndoState(r),this._getRangeAndRemoveBookmark(r),lt(r),this._ensureBottomLine(),this.setSelection(r),this._updatePath(r,!0))},kt.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},kt._getHTML=function(){return this._body.innerHTML},kt._setHTML=function(e){var t=this._body;t.innerHTML=e;do _(t);while(t=f(t));this._ignoreChange=!0},kt.getHTML=function(e){var t,n,o,r,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),j)for(t=this._body;t=f(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(o=this._getHTML().replace(/\u200B/g,""),j)for(r=a.length;r--;)m(a[r]);return i&&this._getRangeAndRemoveBookmark(i),o},kt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),o=this.createElement("DIV");o.innerHTML=e,n.appendChild(C(o)),$t(n,!0),Xt(n),S(n);for(var r=n;r=f(r);)_(r);this._ignoreChange=!0;for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),_(i),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var a=this._getRangeAndRemoveBookmark()||this._createRange(i.firstChild,0);return this._recordUndoState(a),this._getRangeAndRemoveBookmark(a),X?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},kt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))st(t,e),t.setStartAfter(e);else{for(var n,o,r=this._body,i=pt(t)||r;i!==r&&!i.nextSibling;)i=i.parentNode;i!==r&&(n=i.parentNode,o=y(n,i.nextSibling,r)),o?r.insertBefore(e,o):(r.appendChild(e),o=this.createDefaultBlock(),r.appendChild(o)),t.setStart(o,0),t.setEnd(o,0),ft(t)}return this.focus(),this.setSelection(t),this._updatePath(t),this},kt.insertImage=function(e,t){var n=this.createElement("IMG",B({src:e},t));return this.insertElement(n),n},kt.insertHTML=function(e){var t=this.getSelection(),n=this._doc.createDocumentFragment(),o=this.createElement("DIV");o.innerHTML=e,n.appendChild(C(o)),this._recordUndoState(t),this._getRangeAndRemoveBookmark(t);try{n.normalize(),Kt(n),$t(n,!0),Xt(n),Gt(n),S(n);for(var r=n;r=f(r);)_(r);ct(t,n),J||this._docWasChanged(),t.collapse(!1),this._ensureBottomLine(),this.setSelection(t),this._updatePath(t,!0)}catch(i){this.didError(i)}return this};var en=function(e,t,n){return function(){return this[e](t,n),this.focus()}};kt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.appendChild(this._doc.createTextNode(e)),t.appendChild(n)}return this},kt.bold=en("changeFormat",{tag:"B"}),kt.italic=en("changeFormat",{tag:"I"}),kt.underline=en("changeFormat",{tag:"U"}),kt.strikethrough=en("changeFormat",{tag:"S"}),kt.subscript=en("changeFormat",{tag:"SUB"},{tag:"SUP"}),kt.superscript=en("changeFormat",{tag:"SUP"},{tag:"SUB"}),kt.removeBold=en("changeFormat",null,{tag:"B"}),kt.removeItalic=en("changeFormat",null,{tag:"I"}),kt.removeUnderline=en("changeFormat",null,{tag:"U"}),kt.removeStrikethrough=en("changeFormat",null,{tag:"S"}),kt.removeSubscript=en("changeFormat",null,{tag:"SUB"}),kt.removeSuperscript=en("changeFormat",null,{tag:"SUP"}),kt.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var o=e.indexOf(":")+1;if(o)for(;"/"===e[o];)o+=1;st(n,this._doc.createTextNode(e.slice(o)))}return t||(t={}),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},kt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},kt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},kt.setFontSize=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}},{tag:"SPAN",attributes:{"class":"size"}}),this.focus()},kt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},kt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},kt.setTextAlignment=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/align/.test(e)}).join(" ")+" align-"+e).trim(),t.style.textAlign=e},!0),this.focus()},kt.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()};var tn=/(^|>)(?:B|I|S|SUB|SUP|U|BLOCKQUOTE|OL|UL|LI|T(?:ABLE|BODY|HEAD|FOOT|R|D|H))(>|$)/;kt.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return!1;for(var t=e.commonAncestorContainer;tn.test(p(t));)t=t.parentNode;if(t.nodeType===D)return!1;ut(e,t),this._saveRangeToBookmark(e);var n=t.ownerDocument,o=e.startContainer,r=e.startOffset,i=e.endContainer,a=e.endOffset;y(i,a,t),y(o,r,t),e=this._getRangeAndRemoveBookmark(null,!0),ut(e,t),this._saveRangeToBookmark(e);var c=this,h=[];A(t,e,function u(t){if(l(t))A(t,e,u);else if(d(t)){var o=c.createDefaultBlock();o.appendChild(n.createTextNode(t.textContent)),h.push(o)}else s(t)&&h.push(n.createTextNode(t.textContent))});var f=L(t,e,function(e){return e});return h.forEach(function(e){t.insertBefore(e,f[0])}),f.forEach(function(e){t.removeChild(e)}),this.setSelection(this._getRangeAndRemoveBookmark()),this},kt.increaseQuoteLevel=en("modifyBlocks",Rt),kt.decreaseQuoteLevel=en("modifyBlocks",Dt),kt.makeUnorderedList=en("modifyBlocks",Pt),kt.makeOrderedList=en("modifyBlocks",wt),kt.removeList=en("modifyBlocks",Ft),kt.increaseListLevel=en("modifyBlocks",Ht),kt.decreaseListLevel=en("modifyBlocks",Mt),top!==W?(W.editor=new O(e),W.onEditorLoad&&(W.onEditorLoad(W.editor),W.onEditorLoad=null)):"object"==typeof exports?module.exports=O:W.Squire=O}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 69be598..b54c038 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -2164,15 +2164,13 @@ proto.setTextDirection = function ( direction ) { function forEachChildInRange ( rootNode, range, iterator ) { - var walker = new TreeWalker( rootNode, SHOW_ELEMENT|SHOW_TEXT, - function ( node ) { - return node.parentNode === rootNode && - isNodeContainedInRange( range, node, false /* include partials */ ); - } - ); - var node; - while ( node = walker.nextNode() ) { - iterator( node ); + var childNodes = rootNode.childNodes, + node = rootNode.firstChild; + while ( node ) { + if ( isNodeContainedInRange( range, node, false ) ) { + iterator( node ); + } + node = node.nextSibling; } }