diff --git a/build/squire-raw.js b/build/squire-raw.js index eb2fc3a..22ad94a 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -1159,6 +1159,8 @@ var fireEvent = function ( type, event ) { if ( event.type !== type ) { event.type = type; } + // Clone handlers array, so any handlers added/removed do not affect it. + handlers = handlers.slice(); for ( i = 0, l = handlers.length; i < l; i += 1 ) { obj = handlers[i]; try { diff --git a/build/squire.js b/build/squire.js index 316c88c..2fe365f 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1 +1 @@ -(function(e){"use strict";function t(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function n(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 r in n)if(e.getAttribute(r)!==n[r])return!1;return!0}function o(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 i(e){return e.nodeType===x&&!!et[e.nodeName]}function a(e){return J.test(e.nodeName)}function s(e){return e.nodeType===x&&!a(e)&&n(e.childNodes,a)}function d(e){return e.nodeType===x&&!a(e)&&!s(e)}function l(e){return s(e)?I:L}function f(e){var n=e.ownerDocument,r=new t(n.body,b,l,!1);return r.currentNode=e,r}function c(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function h(e,t,n){do if(r(e,t,n))return e;while(e=e.parentNode);return null}function p(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===x?(t=p(i),t+=(t?">":"")+e.nodeName,(n=e.id)&&(t+="#"+n),(r=e.className.trim())&&(o=r.split(/\s\s*/),o.sort(),t+=".",t+=o.join("."))):t=i?p(i):"",t}function N(e){var t=e.nodeType;return t===x?e.childNodes.length:e.length||0}function C(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 g(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function m(e){var t,n,r=e.ownerDocument,o=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=r.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),a(e))e.firstChild||($?(t=r.createTextNode("​"),Bt(t)):t=r.createTextNode(""));else if(Y){for(;e.nodeType!==D&&!i(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===D?/^ +$/.test(e.data)&&(e.data=""):i(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!a(n);)e=n;return t&&e.appendChild(t),o}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===D&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===x){if("number"==typeof t&&(t=e.childNodes.length>t?e.childNodes[t]:null),e===n)return t;for(r=e.parentNode,o=e.cloneNode(!1);t;)i=t.nextSibling,o.appendChild(t),t=i;return m(e),m(o),(i=e.nextSibling)?r.insertBefore(o,i):r.appendChild(o),y(r,o,n)}return t}function T(e,t){if(e.nodeType===x)for(var n,r,i,s=e.childNodes,d=s.length,l=[];d--;)if(n=s[d],r=d&&s[d-1],d&&a(n)&&o(n,r)&&!et[n.nodeName])t.startContainer===n&&(t.startContainer=r,t.startOffset+=N(r)),t.endContainer===n&&(t.endContainer=r,t.endOffset+=N(r)),t.startContainer===e&&(t.startOffset>d?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=N(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=N(r))),C(n),n.nodeType===D?r.appendData(n.data.replace(/\u200B/g,"")):l.push(g(n));else if(n.nodeType===x){for(i=l.length;i--;)n.appendChild(l.pop());T(n,t)}}function S(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;C(a),o=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),o-=1),i={startContainer:e,startOffset:o,endContainer:e,endOffset:o},e.appendChild(g(t)),T(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),q&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t=e.previousSibling,n=e.firstChild;t&&o(t,e)&&d(t)&&(C(e),t.appendChild(g(e)),n&&B(n))}function O(t,n,r){var o,i,a,s=e.createElement(t);if(n instanceof Array&&(r=n,n=null),n)for(o in n)s.setAttribute(o,n[o]);if(r)for(i=0,a=r.length;a>i;i+=1)s.appendChild(r[i]);return s}var E=2,x=1,D=3,b=1,A=4,I=1,L=3,R=0,k=1,w=2,P=3,U=e.defaultView,V=e.body,H=navigator.userAgent,_=/iP(?:ad|hone|od)/.test(H),F=/Mac OS X/.test(H),z=/Gecko\//.test(H),M=/Trident\//.test(H),K=8===U.ie,q=!!U.opera,G=/WebKit\//.test(H),Q=F?"meta-":"ctrl-",Y=M||q,$=M||G,j=M,W=/\S/,X=Array.prototype.indexOf,Z={1:1,2:2,3:4,8:128,9:256,11:1024};t.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(Z[e.nodeType]&r&&o(e)===I)return this.currentNode=e,e;t=e}},t.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=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(Z[e.nodeType]&r&&o(e)===I)return this.currentNode=e,e;t=e}};var J=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:FN|EL)|EM|FONT|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TRONG|AMP)|U)$/,et={BR:1,IMG:1,INPUT:1};(function(){var t=e.createElement("div"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length})()&&(Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,r=this.parentNode,o=this.length-e;return n?r.insertBefore(t,n):r.appendChild(t),o&&this.deleteData(e,o),t});var tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===x;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===x){var n=e.childNodes;if(n.length>t)e=n[t];else{for(;e&&!e.nextSibling;)e=e.parentNode;e&&(e=e.nextSibling)}}return e},rt=Range.prototype;rt.forEachTextNode=function(e){var n=this.cloneRange();n.moveBoundariesDownTree();for(var r=n.startContainer,o=n.endContainer,i=n.commonAncestorContainer,a=new t(i,A,function(){return I},!1),s=a.currentNode=r;!e(s,n)&&s!==o&&(s=a.nextNode()););},rt.getTextContent=function(){var e="";return this.forEachTextNode(function(t,n){var r=t.data;r&&/\S/.test(r)&&(t===n.endContainer&&(r=r.slice(0,n.endOffset)),t===n.startContainer&&(r=r.slice(n.startOffset)),e+=r)}),e},rt._insertNode=function(e){var t,n,r,o,i=this.startContainer,a=this.startOffset,s=this.endContainer,d=this.endOffset;return i.nodeType===D?(t=i.parentNode,n=t.childNodes,a===i.length?(a=X.call(n,i)+1,this.collapsed&&(s=t,d=a)):(a&&(o=i.splitText(a),s===i?(d-=a,s=o):s===t&&(d+=1),i=o),a=X.call(n,i)),i=t):n=i.childNodes,r=n.length,a===r?i.appendChild(e):i.insertBefore(e,n[a]),i===s&&(d+=n.length-r),this.setStart(i,a),this.setEnd(s,d),this},rt._extractContents=function(e){var t=this.startContainer,n=this.startOffset,r=this.endContainer,o=this.endOffset;e||(e=this.commonAncestorContainer),e.nodeType===D&&(e=e.parentNode);for(var i,a=y(r,o,e),s=y(t,n,e),d=e.ownerDocument.createDocumentFragment();s!==a;)i=s.nextSibling,d.appendChild(s),s=i;return this.setStart(e,a?X.call(e.childNodes,a):e.childNodes.length),this.collapse(!0),m(e),d},rt._deleteContents=function(){this.moveBoundariesUpTree(),this._extractContents();var e=this.getStartBlock(),t=this.getEndBlock();e&&t&&e!==t&&S(e,t,this),e&&m(e);var n=this.endContainer.ownerDocument.body,r=n.firstChild;r&&"BR"!==r.nodeName||(m(n),this.selectNodeContents(n.firstChild));var o=this.collapsed;return this.moveBoundariesDownTree(),o&&this.collapse(!0),this},rt.insertTreeFragment=function(e){for(var t=!0,n=e.childNodes,r=n.length;r--;)if(!a(n[r])){t=!1;break}if(this.collapsed||this._deleteContents(),this.moveBoundariesDownTree(),t)this._insertNode(e),this.collapse(!1);else{for(var o,i,s=y(this.startContainer,this.startOffset,this.startContainer.ownerDocument.body),d=s.previousSibling,l=d,f=l.childNodes.length,c=s,h=0,p=s.parentNode;(o=l.lastChild)&&o.nodeType===x&&"BR"!==o.nodeName;)l=o,f=l.childNodes.length;for(;(o=c.firstChild)&&o.nodeType===x&&"BR"!==o.nodeName;)c=o;for(;(o=e.firstChild)&&a(o);)l.appendChild(o);for(;(o=e.lastChild)&&a(o);)c.insertBefore(o,c.firstChild),h+=1;for(i=e;i=u(i);)m(i);p.insertBefore(e,s),i=s.previousSibling,s.textContent?B(s):p.removeChild(s),s.parentNode||(c=i,h=N(c)),d.textContent?B(d):(l=d.nextSibling,f=0,p.removeChild(d)),this.setStart(l,f),this.setEnd(c,h),this.moveBoundariesDownTree()}},rt.containsNode=function(e,t){var n=this,r=e.ownerDocument.createRange();if(r.selectNode(e),t){var o=n.compareBoundaryPoints(P,r)>-1,i=1>n.compareBoundaryPoints(k,r);return!o&&!i}var a=1>n.compareBoundaryPoints(R,r),s=n.compareBoundaryPoints(w,r)>-1;return a&&s},rt.moveBoundariesDownTree=function(){for(var e,t=this.startContainer,n=this.startOffset,r=this.endContainer,o=this.endOffset;t.nodeType!==D&&(e=t.childNodes[n],e&&!i(e));)t=e,n=0;if(o)for(;r.nodeType!==D&&(e=r.childNodes[o-1],e&&!i(e));)r=e,o=N(r);else for(;r.nodeType!==D&&(e=r.firstChild,e&&!i(e));)r=e;return this.collapsed?(this.setStart(r,o),this.setEnd(t,n)):(this.setStart(t,n),this.setEnd(r,o)),this},rt.moveBoundariesUpTree=function(e){var t,n=this.startContainer,r=this.startOffset,o=this.endContainer,i=this.endOffset;for(e||(e=this.commonAncestorContainer);n!==e&&!r;)t=n.parentNode,r=X.call(t.childNodes,n),n=t;for(;o!==e&&i===N(o);)t=o.parentNode,i=X.call(t.childNodes,o)+1,o=t;return this.setStart(n,r),this.setEnd(o,i),this},rt.getStartBlock=function(){var e,t=this.startContainer;return a(t)?e=c(t):s(t)?e=t:(e=tt(t,this.startOffset),e=u(e)),e&&this.containsNode(e,!0)?e:null},rt.getEndBlock=function(){var e,t,n=this.endContainer;if(a(n))e=c(n);else if(s(n))e=n;else{if(e=nt(n,this.endOffset),!e)for(e=n.ownerDocument.body;t=e.lastChild;)e=t;e=c(e)}return e&&this.containsNode(e,!0)?e:null},rt.startsAtBlockBoundary=function(){for(var e,t,n=this.startContainer,r=this.startOffset;a(n);){if(r)return!1;e=n.parentNode,r=X.call(e.childNodes,n),n=e}for(;r&&(t=n.childNodes[r-1])&&(""===t.data||"BR"===t.nodeName);)r-=1;return!r},rt.endsAtBlockBoundary=function(){for(var e,t,n=this.endContainer,r=this.endOffset,o=N(n);a(n);){if(r!==o)return!1;e=n.parentNode,r=X.call(e.childNodes,n)+1,n=e,o=n.childNodes.length}for(;o>r&&(t=n.childNodes[r])&&(""===t.data||"BR"===t.nodeName);)r+=1;return r===o},rt.expandToBlockBoundaries=function(){var e,t=this.getStartBlock(),n=this.getEndBlock();return t&&n&&(e=t.parentNode,this.setStart(e,X.call(e.childNodes,t)),e=n.parentNode,this.setEnd(e,X.call(e.childNodes,n)+1)),this};var ot,it={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1},at={},st=function(e,t){var n,r,o,i=at[e];if(i)for(t||(t={}),t.type!==e&&(t.type=e),n=0,r=i.length;r>n;n+=1){o=i[n];try{o.handleEvent?o.handleEvent(t):o(t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,ot.didError(a)}}},dt=function(e){st(e.type,e)},lt=function(t,n){var r=at[t];return n?(r||(r=at[t]=[],it[t]||e.addEventListener(t,dt,!1)),r.push(n),void 0):(ot.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+t}),void 0)},ft=function(t,n){var r,o=at[t];if(o){for(r=o.length;r--;)o[r]===n&&o.splice(r,1);o.length||(delete at[t],it[t]||e.removeEventListener(t,dt,!1))}},ct=function(t,n,r,o){if(t instanceof Range)return t.cloneRange();var i=e.createRange();return i.setStart(t,n),r?i.setEnd(r,o):i.setEnd(t,n),i},ut=U.getSelection(),ht=null,pt=function(e){e&&(_&&U.focus(),ut.removeAllRanges(),ut.addRange(e))},Nt=function(){if(ut.rangeCount){ht=ut.getRangeAt(0).cloneRange();var e=ht.startContainer,t=ht.endContainer;try{e&&i(e)&&ht.setStartBefore(e),t&&i(t)&&ht.setEndBefore(t)}catch(n){ot.didError({name:"Squire#getSelection error",message:"Starts: "+e.nodeName+"\nEnds: "+t.nodeName})}}return ht};j&&U.addEventListener("beforedeactivate",Nt,!0);var Ct,vt,gt=null,mt=!0,yt=!1,Tt=function(){mt=!0,yt=!1,ft("keydown",Tt)},St=function(){if(mt){var e,t=gt;if(gt=null,t.parentNode){for(;(e=t.data.indexOf("​"))>-1;)t.deleteData(e,1);t.data||t.nextSibling||t.previousSibling||!a(t.parentNode)||C(t.parentNode)}}},Bt=function(e){gt&&(mt=!0,St()),yt||(lt("keydown",Tt),yt=!0),mt=!1,gt=e},Ot="",Et=function(e,t){gt&&!t&&St(e);var n,r=e.startContainer,o=e.endContainer;(t||r!==Ct||o!==vt)&&(Ct=r,vt=o,n=r&&o?r===o?p(o):"(selection)":"",Ot!==n&&(Ot=n,st("pathChange",{path:n}))),r!==o&&st("select")},xt=function(){Et(Nt())};lt("keyup",xt),lt("mouseup",xt);var Dt=function(){z&&V.focus(),U.focus()},bt=function(){z&&V.blur(),top.focus()};U.addEventListener("focus",dt,!1),U.addEventListener("blur",dt,!1);var At,It,Lt,Rt,kt=function(){return V.innerHTML},wt=function(e){var t=V;t.innerHTML=e;do m(t);while(t=u(t))},Pt=function(e,t){if(t||(t=Nt()),t.collapse(!0),a(e))t._insertNode(e),t.setStartAfter(e);else{for(var n,r,o=t.getStartBlock()||V;o!==V&&!o.nextSibling;)o=o.parentNode;o!==V&&(n=o.parentNode,r=y(n,o.nextSibling,V)),r?(V.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),t.moveBoundariesDownTree()):(V.appendChild(e),V.appendChild(m(O("div"))),t.setStart(e,0),t.setEnd(e,0)),Dt(),pt(t),Et(t)}},Ut="squire-selection-start",Vt="squire-selection-end",Ht=function(e){var t,n=O("INPUT",{id:Ut,type:"hidden"}),r=O("INPUT",{id:Vt,type:"hidden"});e._insertNode(n),e.collapse(!1),e._insertNode(r),n.compareDocumentPosition(r)&E&&(n.id=Vt,r.id=Ut,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},_t=function(t){var n=e.getElementById(Ut),r=e.getElementById(Vt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:X.call(i.childNodes,n),endOffset:X.call(a.childNodes,r)};i===a&&(s.endOffset-=1),C(n),C(r),T(i,s),i!==a&&T(a,s),t||(t=e.createRange()),t.setStart(s.startContainer,s.startOffset),t.setEnd(s.endContainer,s.endOffset),o=t.collapsed,t.moveBoundariesDownTree(),o&&t.collapse(!0)}return t||null},Ft=function(){Rt&&(Rt=!1,st("undoStateChange",{canUndo:!0,canRedo:!1})),st("input")};lt("keyup",function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||Ft()});var zt=function(e){Rt||(At+=1,Lt>At&&(It.length=Lt=At),e&&Ht(e),It[At]=kt(),Lt+=1,Rt=!0)},Mt=function(){if(0!==At||!Rt){zt(Nt()),At-=1,wt(It[At]);var e=_t();e&&pt(e),Rt=!0,st("undoStateChange",{canUndo:0!==At,canRedo:!0}),st("input")}},Kt=function(){if(Lt>At+1&&Rt){At+=1,wt(It[At]);var e=_t();e&&pt(e),st("undoStateChange",{canUndo:!0,canRedo:Lt>At+1}),st("input")}},qt=function(e,n,r){if(e=e.toUpperCase(),n||(n={}),!r&&!(r=Nt()))return!1;var o,i,a=r.commonAncestorContainer;if(h(a,e,n))return!0;if(a.nodeType===D)return!1;o=new t(a,A,function(e){return r.containsNode(e,!0)?I:L},!1);for(var s=!1;i=o.nextNode();){if(!h(i,e,n))return!1;s=!0}return s},Gt=function(e,n,r){var o,i,a,s,d,l,f,c;if(r.collapsed)o=m(O(e,n)),r._insertNode(o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new t(r.commonAncestorContainer,A,function(e){return r.containsNode(e,!0)?I:L},!1),d=0,l=0,f=i.currentNode=r.startContainer,f.nodeType!==D&&(f=i.nextNode());do c=!h(f,e,n),f===r.endContainer&&(c&&f.length>r.endOffset?f.splitText(r.endOffset):l=r.endOffset),f===r.startContainer&&(c&&r.startOffset?f=f.splitText(r.startOffset):d=r.startOffset),c&&(o=O(e,n),v(f,o),o.appendChild(f),l=f.length),s=f,a||(a=s);while(f=i.nextNode());r=ct(a,d,s,l)}return r},Qt=function(t,n,o,i){Ht(o);var s;o.collapsed&&($?(s=e.createTextNode("​"),Bt(s)):s=e.createTextNode(""),o._insertNode(s));for(var d=o.commonAncestorContainer;a(d);)d=d.parentNode;var l=o.startContainer,f=o.startOffset,c=o.endContainer,u=o.endOffset,h=[],p=function(e,t){if(!o.containsNode(e,!1)){var n,r,i=e.nodeType===D;if(!o.containsNode(e,!0))return"INPUT"===e.nodeName||i&&!e.data||h.push([t,e]),void 0;if(i)e===c&&u!==e.length&&h.push([t,e.splitText(u)]),e===l&&f&&(e.splitText(f),h.push([t,e]));else for(n=e.firstChild;n;n=r)r=n.nextSibling,p(n,t)}},N=Array.prototype.filter.call(d.getElementsByTagName(t),function(e){return o.containsNode(e,!0)&&r(e,t,n)});i||N.forEach(function(e){p(e,e)}),h.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];v(n,t),t.appendChild(n)}),N.forEach(function(e){v(e,g(e))}),_t(o),s&&o.collapse(!1);var C={startContainer:o.startContainer,startOffset:o.startOffset,endContainer:o.endContainer,endOffset:o.endOffset};return T(d,C),o.setStart(C.startContainer,C.startOffset),o.setEnd(C.endContainer,C.endOffset),o},Yt=function(e,t,n,r){(n||(n=Nt()))&&(zt(n),_t(n),t&&(n=Qt(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=Gt(e.tag.toUpperCase(),e.attributes||{},n)),pt(n),Et(n,!0),Ft())},$t={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},jt=function(e,t,n){var r=$t[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=O(r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(g(o)),o=e),o},Wt=function(e,t,n){if(n||(n=Nt())){t&&(zt(n),_t(n));var r=n.getStartBlock(),o=n.getEndBlock();if(r&&o)do if(e(r)||r===o)break;while(r=u(r));t&&(pt(n),Et(n,!0),Ft())}},Xt=function(e,t){if(t||(t=Nt())){q||V.setAttribute("contenteditable","false"),Rt?Ht(t):zt(t),t.expandToBlockBoundaries(),t.moveBoundariesUpTree(V);var n=t._extractContents(V);t._insertNode(e(n)),t.endOffsetn;n+=1)o=e[n],i=o.nodeName,s(o)?"LI"!==i&&(l=O("LI",{"class":"rtl"===o.dir?"dir-rtl":"",dir:o.dir},[g(o)]),o.parentNode.nodeName===t?v(o,l):(a=o.previousSibling)&&a.nodeName===t?(a.appendChild(l),C(o),n-=1,r-=1):v(o,O(t,[l]))):d(o)&&(i!==t&&/^[DOU]L$/.test(i)?v(o,O(t,[g(o)])):tn(o.childNodes,t))},nn=function(e){return tn(e.childNodes,"UL"),e},rn=function(e){return tn(e.childNodes,"OL"),e},on=function(e){var t=e.querySelectorAll("UL, OL");return Array.prototype.filter.call(t,function(e){return!h(e.parentNode,"UL")&&!h(e.parentNode,"OL")}).forEach(function(e){for(var t,n=g(e),r=n.childNodes,o=r.length;o--;)t=r[o],"LI"===t.nodeName&&n.replaceChild(O("DIV",{"class":"rtl"===t.dir?"dir-rtl":"",dir:t.dir},[g(t)]),t);v(e,n)}),e},an=/\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:[\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,4}))/i,sn=function(e){for(var n,r,o,i,a,s,d,l=e.ownerDocument,f=new t(e,A,function(e){return h(e,"A")?L:I},!1);n=f.nextNode();)if(r=n.data.split(an),i=r.length,i>1){for(s=n.parentNode,d=n.nextSibling,o=0;i>o;o+=1)a=r[o],o?(o%2?(n=l.createElement("A"),n.textContent=a,n.href=/@/.test(a)?"mailto:"+a:/^(?:ht|f)tps?:/.test(a)?a:"http://"+a):n=l.createTextNode(a),d?s.insertBefore(n,d):s.appendChild(n)):n.data=a;f.currentNode=n}},dn=/^(?:A(?:DDRESS|RTICLE|SIDE)|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)$/,ln={1:10,2:13,3:16,4:18,5:24,6:32,7:48},fn={backgroundColor:{regexp:W,replace:function(e){return O("SPAN",{"class":"highlight",style:"background-color: "+e})}},color:{regexp:W,replace:function(e){return O("SPAN",{"class":"colour",style:"color:"+e})}},fontWeight:{regexp:/^bold/i,replace:function(){return O("B")}},fontStyle:{regexp:/^italic/i,replace:function(){return O("I")}},fontFamily:{regexp:W,replace:function(e){return O("SPAN",{"class":"font",style:"font-family:"+e})}},fontSize:{regexp:W,replace:function(e){return O("SPAN",{"class":"size",style:"font-size:"+e})}}},cn={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style;for(n in fn)r=fn[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(g(e)),t.replaceChild(a,e)),i||e},STRONG:function(e,t){var n=O("B");return t.replaceChild(n,e),n.appendChild(g(e)),n},EM:function(e,t){var n=O("I");return t.replaceChild(n,e),n.appendChild(g(e)),n},FONT:function(e,t){var n,r,o,i,a=e.face,s=e.size;return a&&(n=O("SPAN",{"class":"font",style:"font-family:"+a})),s&&(r=O("SPAN",{"class":"size",style:"font-size:"+ln[s]+"px"}),n&&n.appendChild(r)),i=n||r||O("SPAN"),o=r||n||i,t.replaceChild(i,e),o.appendChild(g(e)),o},TT:function(e,t){var n=O("SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(g(e)),n}},un=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===x&&"IMG"!==t.nodeName&&(un(t),a(t)&&!t.firstChild&&e.removeChild(t))},hn=function(e,t){var n,r,o,i,s,d,l,f=e.childNodes;for(n=0,r=f.length;r>n;n+=1)if(o=f[n],i=o.nodeName,s=o.nodeType,d=cn[i],s===x){if(l=o.childNodes.length,d)o=d(o,e);else{if(!dn.test(i)&&!a(o)){n-=1,r+=l-1,e.replaceChild(g(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&hn(o,t)}else s===D&&(W.test(o.data)||n>0&&a(f[n-1])||r>n+1&&a(f[n+1]))||(e.removeChild(o),n-=1,r-=1);return e},pn=function(e,t){var n,r,o,i,s=e.childNodes,d=null;for(n=0,r=s.length;r>n;n+=1)o=s[n],i="BR"===o.nodeName,!i&&a(o)?(d||(d=O(t)),d.appendChild(o),n-=1,r-=1):(i||d)&&(d||(d=O(t)),m(d),i?e.replaceChild(d,o):(e.insertBefore(d,o),n+=1,r+=1),d=null);return d&&e.appendChild(m(d)),e},Nn=function(e){return(e.nodeType===x?"BR"===e.nodeName:W.test(e.data))?I:L},Cn=function(e){for(var n,r=e.parentNode;a(r);)r=r.parentNode;return n=new t(r,b|A,Nn),n.currentNode=e,!!n.nextNode()},vn=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],d=o.length;for(t=0;d>t;t+=1)i[t]=Cn(o[t]);for(;d--;)if(n=o[d],r=n.parentNode){for(;a(r);)r=r.parentNode;s(r)&&$t[r.nodeName]?(i[d]&&jt(r,n.parentNode,n),C(n)):pn(r,"DIV")}},gn=function(){try{m(V)}catch(e){ot.didError(e)}};lt(M?"beforecut":"cut",function(){var e=Nt();zt(e),_t(e),pt(e),setTimeout(gn,0)});var mn=!1;lt(M?"beforepaste":"paste",function(e){if(!mn){var t,n=e.clipboardData,r=n&&n.items,o=!1;if(r)for(t=r.length;t--;)if(/^image\/.*/.test(r[t].type))return e.preventDefault(),st("dragover",{dataTransfer:n,preventDefault:function(){o=!0}}),o&&st("drop",{dataTransfer:n}),void 0;mn=!0;var i=Nt(),a=i.startContainer,s=i.startOffset,d=i.endContainer,l=i.endOffset,f=O("DIV",{style:"position: absolute; overflow: hidden; top:"+(V.scrollTop+30)+"px; left: 0; width: 1px; height: 1px;"});V.appendChild(f),i.selectNodeContents(f),pt(i),setTimeout(function(){try{var e=g(C(f)),t=e.firstChild,n=ct(a,s,d,l);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(g(t),t),e.normalize(),sn(e),hn(e,!1),vn(e),un(e);for(var r=e,o=!0;r=u(r);)m(r);st("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(n.insertTreeFragment(e),Ft(),n.collapse(!1))}pt(n),Et(n,!0),mn=!1}catch(i){ot.didError(i)}},0)}});var yn={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete"},Tn=function(e){return function(t){t.preventDefault(),e()}},Sn=function(e){return function(t){t.preventDefault();var n=Nt();qt(e,null,n)?Yt(null,{tag:e},n):Yt({tag:e},null,n)}},Bn=function(){try{var e,t=Nt(),n=t.startContainer;if(n.nodeType===D&&(n=n.parentNode),a(n)&&!n.textContent){do e=n.parentNode;while(a(e)&&!e.textContent&&(n=e));t.setStart(e,X.call(e.childNodes,n)),t.collapse(!0),e.removeChild(n),s(e)||(e=c(e)),m(e),t.moveBoundariesDownTree(),pt(t),Et(t)}}catch(r){ot.didError(r)}};K&<("keyup",function(){var e=V.firstChild;"P"===e.nodeName&&(Ht(Nt()),v(e,O("DIV",[g(e)])),pt(_t()))});var On={enter:function(t){t.preventDefault();var n=Nt();if(n){zt(n),sn(n.startContainer),_t(n),n.collapsed||n._deleteContents();var r,o=n.getStartBlock(),i=o?o.nodeName:"DIV",a=$t[i];if(!o)return n._insertNode(O("BR")),n.collapse(!1),pt(n),Et(n,!0),Ft(),void 0;var s,d=n.startContainer,l=n.startOffset;if(a||(d===o&&(d=l?d.childNodes[l-1]:null,l=0,d&&("BR"===d.nodeName?d=d.nextSibling:l=N(d),d&&"BR"!==d.nodeName||(s=m(O("DIV")),d?o.replaceChild(s,d):o.appendChild(s),d=s))),pn(o,"DIV"),a="DIV",d||(d=o.firstChild),n.setStart(d,l),n.setEnd(d,l),o=n.getStartBlock()),!o.textContent){if(h(o,"UL")||h(o,"OL"))return Xt(on,n);if(h(o,"BLOCKQUOTE"))return Xt(en,n)}for(r=jt(o,d,l);r.nodeType===x;){var f,c=r.firstChild;if("A"!==r.nodeName){for(;c&&c.nodeType===D&&!c.data&&(f=c.nextSibling,f&&"BR"!==f.nodeName);)C(c),c=f;if(!c||"BR"===c.nodeName||c.nodeType===D&&!q)break;r=c}else v(r,g(r)),r=c}n=ct(r,0),pt(n),Et(n,!0),r.nodeType===D&&(r=r.parentNode),r.offsetTop+r.offsetHeight>(e.documentElement.scrollTop||V.scrollTop)+V.offsetHeight&&r.scrollIntoView(!1),Ft()}},backspace:function(e){var t=Nt();if(t.collapsed)if(t.startsAtBlockBoundary()){zt(t),_t(t),e.preventDefault();var n=t.getStartBlock(),r=n&&c(n);if(r){if(!r.isContentEditable)return C(r),void 0;for(S(r,n,t),n=r.parentNode;n&&!n.nextSibling;)n=n.parentNode;n&&(n=n.nextSibling)&&B(n),pt(t)}else if(n){if(h(n,"UL")||h(n,"OL"))return Xt(on,t);if(h(n,"BLOCKQUOTE"))return Xt(Jt,t);pt(t),Et(t,!0)}}else{var o=t.startContainer.data||"";W.test(o.charAt(t.startOffset-1))||(zt(t),_t(t),pt(t)),setTimeout(Bn,0)}else zt(t),_t(t),e.preventDefault(),t._deleteContents(),pt(t),Et(t,!0)},"delete":function(e){var t=Nt();if(t.collapsed)if(t.endsAtBlockBoundary()){zt(t),_t(t),e.preventDefault();var n=t.getStartBlock(),r=n&&u(n);if(r){if(!r.isContentEditable)return C(r),void 0;for(S(n,r,t),r=n.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),pt(t),Et(t,!0)}}else{var o=t.startContainer.data||"";W.test(o.charAt(t.startOffset))||(zt(t),_t(t),pt(t)),setTimeout(Bn,0)}else zt(t),_t(t),e.preventDefault(),t._deleteContents(),pt(t),Et(t,!0)},space:function(){var e=Nt();zt(e),sn(e.startContainer),_t(e),pt(e)}};F&&z&&ut.modify&&(On["meta-left"]=function(e){e.preventDefault(),ut.modify("move","backward","lineboundary")},On["meta-right"]=function(e){e.preventDefault(),ut.modify("move","forward","lineboundary")}),On[Q+"b"]=Sn("B"),On[Q+"i"]=Sn("I"),On[Q+"u"]=Sn("U"),On[Q+"y"]=Tn(Kt),On[Q+"z"]=Tn(Mt),On[Q+"shift-z"]=Tn(Kt),lt(q?"keypress":"keydown",function(e){var t=e.keyCode,n=yn[t]||String.fromCharCode(t).toLowerCase(),r="";q&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n,On[n]&&On[n](e)});var En=function(e){return function(){return e.apply(null,arguments),this}},xn=function(e,t,n){return function(){return e(t,n),Dt(),this}};ot=U.editor={didError:function(e){console.log(e)},addEventListener:En(lt),removeEventListener:En(ft),focus:En(Dt),blur:En(bt),getDocument:function(){return e},addStyles:function(t){if(t){var n=e.documentElement.firstChild,r=O("STYLE",{type:"text/css"});r.styleSheet?(n.appendChild(r),r.styleSheet.cssText=t):(r.appendChild(e.createTextNode(t)),n.appendChild(r))}return this},getHTML:function(e){var t,n,r,o,i,a=[];if(e&&(i=Nt())&&Ht(i),Y)for(t=V;t=u(t);)t.textContent||t.querySelector("BR")||(n=O("BR"),t.appendChild(n),a.push(n));if(r=kt(),Y)for(o=a.length;o--;)C(a[o]);return i&&_t(i),r},setHTML:function(t){var n,r=e.createDocumentFragment(),o=O("DIV");o.innerHTML=t,r.appendChild(g(o)),hn(r,!0),vn(r),pn(r,"DIV");for(var i=r;i=u(i);)m(i);for(;n=V.lastChild;)V.removeChild(n);V.appendChild(r),m(V),At=-1,It=[],Lt=0,Rt=!1;var a=_t()||ct(V.firstChild,0);return zt(a),_t(a),j?ht=a:pt(a),Et(a,!0),this},getSelectedText:function(){return Nt().getTextContent()},insertElement:En(Pt),insertImage:function(e){var t=O("IMG",{src:e});return Pt(t),t},getPath:function(){return Ot},getSelection:Nt,setSelection:En(pt),undo:En(Mt),redo:En(Kt),hasFormat:qt,changeFormat:En(Yt),bold:xn(Yt,{tag:"B"}),italic:xn(Yt,{tag:"I"}),underline:xn(Yt,{tag:"U"}),removeBold:xn(Yt,null,{tag:"B"}),removeItalic:xn(Yt,null,{tag:"I"}),removeUnderline:xn(Yt,null,{tag:"U"}),makeLink:function(t){t=encodeURI(t);var n=Nt();if(n.collapsed){var r=t.indexOf(":")+1;if(r)for(;"/"===t[r];)r+=1;n._insertNode(e.createTextNode(t.slice(r)))}return Yt({tag:"A",attributes:{href:t}},{tag:"A"},n),Dt(),this},removeLink:function(){return Yt(null,{tag:"A"},Nt(),!0),Dt(),this},setFontFace:function(e){return Yt({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),Dt(),this},setFontSize:function(e){return Yt({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}},{tag:"SPAN",attributes:{"class":"size"}}),Dt(),this},setTextColour:function(e){return Yt({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),Dt(),this},setHighlightColour:function(e){return Yt({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),Dt(),this},setTextAlignment:function(e){return Wt(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/align/.test(e)}).join(" ")+" align-"+e).trim(),t.style.textAlign=e},!0),Dt(),this},setTextDirection:function(e){return Wt(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),Dt(),this},forEachBlock:En(Wt),modifyBlocks:En(Xt),increaseQuoteLevel:xn(Xt,Zt),decreaseQuoteLevel:xn(Xt,Jt),makeUnorderedList:xn(Xt,nn),makeOrderedList:xn(Xt,rn),removeList:xn(Xt,on)},V.setAttribute("contenteditable","true"),ot.setHTML(""),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)})(document); \ No newline at end of file +!function(e){"use strict";function t(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function n(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 r in n)if(e.getAttribute(r)!==n[r])return!1;return!0}function o(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 i(e){return e.nodeType===x&&!!et[e.nodeName]}function a(e){return J.test(e.nodeName)}function s(e){return e.nodeType===x&&!a(e)&&n(e.childNodes,a)}function d(e){return e.nodeType===x&&!a(e)&&!s(e)}function l(e){return s(e)?I:L}function f(e){var n=e.ownerDocument,r=new t(n.body,b,l,!1);return r.currentNode=e,r}function c(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function h(e,t,n){do if(r(e,t,n))return e;while(e=e.parentNode);return null}function p(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===x?(t=p(i),t+=(t?">":"")+e.nodeName,(n=e.id)&&(t+="#"+n),(r=e.className.trim())&&(o=r.split(/\s\s*/),o.sort(),t+=".",t+=o.join("."))):t=i?p(i):"",t}function N(e){var t=e.nodeType;return t===x?e.childNodes.length:e.length||0}function C(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 g(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function m(e){var t,n,r=e.ownerDocument,o=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=r.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),a(e))e.firstChild||($?(t=r.createTextNode("​"),Bt(t)):t=r.createTextNode(""));else if(Y){for(;e.nodeType!==D&&!i(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===D?/^ +$/.test(e.data)&&(e.data=""):i(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!a(n);)e=n;return t&&e.appendChild(t),o}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===D&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===x){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=N(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=N(r))),C(n),n.nodeType===D?r.appendData(n.data.replace(/\u200B/g,"")):l.push(g(n));else if(n.nodeType===x){for(i=l.length;i--;)n.appendChild(l.pop());T(n,t)}}function S(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;C(a),o=e.childNodes.length,r=e.lastChild,r&&"BR"===r.nodeName&&(e.removeChild(r),o-=1),i={startContainer:e,startOffset:o,endContainer:e,endOffset:o},e.appendChild(g(t)),T(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),q&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t=e.previousSibling,n=e.firstChild;t&&o(t,e)&&d(t)&&(C(e),t.appendChild(g(e)),n&&B(n))}function O(t,n,r){var o,i,a,s=e.createElement(t);if(n instanceof Array&&(r=n,n=null),n)for(o in n)s.setAttribute(o,n[o]);if(r)for(i=0,a=r.length;a>i;i+=1)s.appendChild(r[i]);return s}var E=2,x=1,D=3,b=1,A=4,I=1,L=3,R=0,k=1,w=2,P=3,U=e.defaultView,V=e.body,H=navigator.userAgent,_=/iP(?:ad|hone|od)/.test(H),F=/Mac OS X/.test(H),z=/Gecko\//.test(H),M=/Trident\//.test(H),K=8===U.ie,q=!!U.opera,G=/WebKit\//.test(H),Q=F?"meta-":"ctrl-",Y=M||q,$=M||G,j=M,W=/\S/,X=Array.prototype.indexOf,Z={1:1,2:2,3:4,8:128,9:256,11:1024};t.prototype.nextNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.firstChild;!e&&t&&t!==n;)e=t.nextSibling,e||(t=t.parentNode);if(!e)return null;if(Z[e.nodeType]&r&&o(e)===I)return this.currentNode=e,e;t=e}},t.prototype.previousNode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=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(Z[e.nodeType]&r&&o(e)===I)return this.currentNode=e,e;t=e}};var J=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:FN|EL)|EM|FONT|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TRONG|AMP)|U)$/,et={BR:1,IMG:1,INPUT:1};!function(){var t=e.createElement("div"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}()&&(Text.prototype.splitText=function(e){var t=this.ownerDocument.createTextNode(this.data.slice(e)),n=this.nextSibling,r=this.parentNode,o=this.length-e;return n?r.insertBefore(t,n):r.appendChild(t),o&&this.deleteData(e,o),t});var tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===x;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===x){var n=e.childNodes;if(t-1,i=n.compareBoundaryPoints(k,r)<1;return!o&&!i}var a=n.compareBoundaryPoints(R,r)<1,s=n.compareBoundaryPoints(w,r)>-1;return a&&s},rt.moveBoundariesDownTree=function(){for(var e,t=this.startContainer,n=this.startOffset,r=this.endContainer,o=this.endOffset;t.nodeType!==D&&(e=t.childNodes[n],e&&!i(e));)t=e,n=0;if(o)for(;r.nodeType!==D&&(e=r.childNodes[o-1],e&&!i(e));)r=e,o=N(r);else for(;r.nodeType!==D&&(e=r.firstChild,e&&!i(e));)r=e;return this.collapsed?(this.setStart(r,o),this.setEnd(t,n)):(this.setStart(t,n),this.setEnd(r,o)),this},rt.moveBoundariesUpTree=function(e){var t,n=this.startContainer,r=this.startOffset,o=this.endContainer,i=this.endOffset;for(e||(e=this.commonAncestorContainer);n!==e&&!r;)t=n.parentNode,r=X.call(t.childNodes,n),n=t;for(;o!==e&&i===N(o);)t=o.parentNode,i=X.call(t.childNodes,o)+1,o=t;return this.setStart(n,r),this.setEnd(o,i),this},rt.getStartBlock=function(){var e,t=this.startContainer;return a(t)?e=c(t):s(t)?e=t:(e=tt(t,this.startOffset),e=u(e)),e&&this.containsNode(e,!0)?e:null},rt.getEndBlock=function(){var e,t,n=this.endContainer;if(a(n))e=c(n);else if(s(n))e=n;else{if(e=nt(n,this.endOffset),!e)for(e=n.ownerDocument.body;t=e.lastChild;)e=t;e=c(e)}return e&&this.containsNode(e,!0)?e:null},rt.startsAtBlockBoundary=function(){for(var e,t,n=this.startContainer,r=this.startOffset;a(n);){if(r)return!1;e=n.parentNode,r=X.call(e.childNodes,n),n=e}for(;r&&(t=n.childNodes[r-1])&&(""===t.data||"BR"===t.nodeName);)r-=1;return!r},rt.endsAtBlockBoundary=function(){for(var e,t,n=this.endContainer,r=this.endOffset,o=N(n);a(n);){if(r!==o)return!1;e=n.parentNode,r=X.call(e.childNodes,n)+1,n=e,o=n.childNodes.length}for(;o>r&&(t=n.childNodes[r])&&(""===t.data||"BR"===t.nodeName);)r+=1;return r===o},rt.expandToBlockBoundaries=function(){var e,t=this.getStartBlock(),n=this.getEndBlock();return t&&n&&(e=t.parentNode,this.setStart(e,X.call(e.childNodes,t)),e=n.parentNode,this.setEnd(e,X.call(e.childNodes,n)+1)),this};var ot,it={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1},at={},st=function(e,t){var n,r,o,i=at[e];if(i)for(t||(t={}),t.type!==e&&(t.type=e),i=i.slice(),n=0,r=i.length;r>n;n+=1){o=i[n];try{o.handleEvent?o.handleEvent(t):o(t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,ot.didError(a)}}},dt=function(e){st(e.type,e)},lt=function(t,n){var r=at[t];return n?(r||(r=at[t]=[],it[t]||e.addEventListener(t,dt,!1)),r.push(n),void 0):(ot.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+t}),void 0)},ft=function(t,n){var r,o=at[t];if(o){for(r=o.length;r--;)o[r]===n&&o.splice(r,1);o.length||(delete at[t],it[t]||e.removeEventListener(t,dt,!1))}},ct=function(t,n,r,o){if(t instanceof Range)return t.cloneRange();var i=e.createRange();return i.setStart(t,n),r?i.setEnd(r,o):i.setEnd(t,n),i},ut=U.getSelection(),ht=null,pt=function(e){e&&(_&&U.focus(),ut.removeAllRanges(),ut.addRange(e))},Nt=function(){if(ut.rangeCount){ht=ut.getRangeAt(0).cloneRange();var e=ht.startContainer,t=ht.endContainer;try{e&&i(e)&&ht.setStartBefore(e),t&&i(t)&&ht.setEndBefore(t)}catch(n){ot.didError({name:"Squire#getSelection error",message:"Starts: "+e.nodeName+"\nEnds: "+t.nodeName})}}return ht};j&&U.addEventListener("beforedeactivate",Nt,!0);var Ct,vt,gt=null,mt=!0,yt=!1,Tt=function(){mt=!0,yt=!1,ft("keydown",Tt)},St=function(){if(mt){var e,t=gt;if(gt=null,t.parentNode){for(;(e=t.data.indexOf("​"))>-1;)t.deleteData(e,1);t.data||t.nextSibling||t.previousSibling||!a(t.parentNode)||C(t.parentNode)}}},Bt=function(e){gt&&(mt=!0,St()),yt||(lt("keydown",Tt),yt=!0),mt=!1,gt=e},Ot="",Et=function(e,t){gt&&!t&&St(e);var n,r=e.startContainer,o=e.endContainer;(t||r!==Ct||o!==vt)&&(Ct=r,vt=o,n=r&&o?r===o?p(o):"(selection)":"",Ot!==n&&(Ot=n,st("pathChange",{path:n}))),r!==o&&st("select")},xt=function(){Et(Nt())};lt("keyup",xt),lt("mouseup",xt);var Dt=function(){z&&V.focus(),U.focus()},bt=function(){z&&V.blur(),top.focus()};U.addEventListener("focus",dt,!1),U.addEventListener("blur",dt,!1);var At,It,Lt,Rt,kt=function(){return V.innerHTML},wt=function(e){var t=V;t.innerHTML=e;do m(t);while(t=u(t))},Pt=function(e,t){if(t||(t=Nt()),t.collapse(!0),a(e))t._insertNode(e),t.setStartAfter(e);else{for(var n,r,o=t.getStartBlock()||V;o!==V&&!o.nextSibling;)o=o.parentNode;o!==V&&(n=o.parentNode,r=y(n,o.nextSibling,V)),r?(V.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),t.moveBoundariesDownTree()):(V.appendChild(e),V.appendChild(m(O("div"))),t.setStart(e,0),t.setEnd(e,0)),Dt(),pt(t),Et(t)}},Ut="squire-selection-start",Vt="squire-selection-end",Ht=function(e){var t,n=O("INPUT",{id:Ut,type:"hidden"}),r=O("INPUT",{id:Vt,type:"hidden"});e._insertNode(n),e.collapse(!1),e._insertNode(r),n.compareDocumentPosition(r)&E&&(n.id=Vt,r.id=Ut,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},_t=function(t){var n=e.getElementById(Ut),r=e.getElementById(Vt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:X.call(i.childNodes,n),endOffset:X.call(a.childNodes,r)};i===a&&(s.endOffset-=1),C(n),C(r),T(i,s),i!==a&&T(a,s),t||(t=e.createRange()),t.setStart(s.startContainer,s.startOffset),t.setEnd(s.endContainer,s.endOffset),o=t.collapsed,t.moveBoundariesDownTree(),o&&t.collapse(!0)}return t||null},Ft=function(){Rt&&(Rt=!1,st("undoStateChange",{canUndo:!0,canRedo:!1})),st("input")};lt("keyup",function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||Ft()});var zt=function(e){Rt||(At+=1,Lt>At&&(It.length=Lt=At),e&&Ht(e),It[At]=kt(),Lt+=1,Rt=!0)},Mt=function(){if(0!==At||!Rt){zt(Nt()),At-=1,wt(It[At]);var e=_t();e&&pt(e),Rt=!0,st("undoStateChange",{canUndo:0!==At,canRedo:!0}),st("input")}},Kt=function(){if(Lt>At+1&&Rt){At+=1,wt(It[At]);var e=_t();e&&pt(e),st("undoStateChange",{canUndo:!0,canRedo:Lt>At+1}),st("input")}},qt=function(e,n,r){if(e=e.toUpperCase(),n||(n={}),!r&&!(r=Nt()))return!1;var o,i,a=r.commonAncestorContainer;if(h(a,e,n))return!0;if(a.nodeType===D)return!1;o=new t(a,A,function(e){return r.containsNode(e,!0)?I:L},!1);for(var s=!1;i=o.nextNode();){if(!h(i,e,n))return!1;s=!0}return s},Gt=function(e,n,r){var o,i,a,s,d,l,f,c;if(r.collapsed)o=m(O(e,n)),r._insertNode(o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new t(r.commonAncestorContainer,A,function(e){return r.containsNode(e,!0)?I:L},!1),d=0,l=0,f=i.currentNode=r.startContainer,f.nodeType!==D&&(f=i.nextNode());do c=!h(f,e,n),f===r.endContainer&&(c&&f.length>r.endOffset?f.splitText(r.endOffset):l=r.endOffset),f===r.startContainer&&(c&&r.startOffset?f=f.splitText(r.startOffset):d=r.startOffset),c&&(o=O(e,n),v(f,o),o.appendChild(f),l=f.length),s=f,a||(a=s);while(f=i.nextNode());r=ct(a,d,s,l)}return r},Qt=function(t,n,o,i){Ht(o);var s;o.collapsed&&($?(s=e.createTextNode("​"),Bt(s)):s=e.createTextNode(""),o._insertNode(s));for(var d=o.commonAncestorContainer;a(d);)d=d.parentNode;var l=o.startContainer,f=o.startOffset,c=o.endContainer,u=o.endOffset,h=[],p=function(e,t){if(!o.containsNode(e,!1)){var n,r,i=e.nodeType===D;if(!o.containsNode(e,!0))return"INPUT"===e.nodeName||i&&!e.data||h.push([t,e]),void 0;if(i)e===c&&u!==e.length&&h.push([t,e.splitText(u)]),e===l&&f&&(e.splitText(f),h.push([t,e]));else for(n=e.firstChild;n;n=r)r=n.nextSibling,p(n,t)}},N=Array.prototype.filter.call(d.getElementsByTagName(t),function(e){return o.containsNode(e,!0)&&r(e,t,n)});i||N.forEach(function(e){p(e,e)}),h.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];v(n,t),t.appendChild(n)}),N.forEach(function(e){v(e,g(e))}),_t(o),s&&o.collapse(!1);var C={startContainer:o.startContainer,startOffset:o.startOffset,endContainer:o.endContainer,endOffset:o.endOffset};return T(d,C),o.setStart(C.startContainer,C.startOffset),o.setEnd(C.endContainer,C.endOffset),o},Yt=function(e,t,n,r){(n||(n=Nt()))&&(zt(n),_t(n),t&&(n=Qt(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=Gt(e.tag.toUpperCase(),e.attributes||{},n)),pt(n),Et(n,!0),Ft())},$t={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},jt=function(e,t,n){var r=$t[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=O(r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(g(o)),o=e),o},Wt=function(e,t,n){if(n||(n=Nt())){t&&(zt(n),_t(n));var r=n.getStartBlock(),o=n.getEndBlock();if(r&&o)do if(e(r)||r===o)break;while(r=u(r));t&&(pt(n),Et(n,!0),Ft())}},Xt=function(e,t){if(t||(t=Nt())){q||V.setAttribute("contenteditable","false"),Rt?Ht(t):zt(t),t.expandToBlockBoundaries(),t.moveBoundariesUpTree(V);var n=t._extractContents(V);t._insertNode(e(n)),t.endOffsetn;n+=1)o=e[n],i=o.nodeName,s(o)?"LI"!==i&&(l=O("LI",{"class":"rtl"===o.dir?"dir-rtl":"",dir:o.dir},[g(o)]),o.parentNode.nodeName===t?v(o,l):(a=o.previousSibling)&&a.nodeName===t?(a.appendChild(l),C(o),n-=1,r-=1):v(o,O(t,[l]))):d(o)&&(i!==t&&/^[DOU]L$/.test(i)?v(o,O(t,[g(o)])):tn(o.childNodes,t))},nn=function(e){return tn(e.childNodes,"UL"),e},rn=function(e){return tn(e.childNodes,"OL"),e},on=function(e){var t=e.querySelectorAll("UL, OL");return Array.prototype.filter.call(t,function(e){return!h(e.parentNode,"UL")&&!h(e.parentNode,"OL")}).forEach(function(e){for(var t,n=g(e),r=n.childNodes,o=r.length;o--;)t=r[o],"LI"===t.nodeName&&n.replaceChild(O("DIV",{"class":"rtl"===t.dir?"dir-rtl":"",dir:t.dir},[g(t)]),t);v(e,n)}),e},an=/\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:[\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,4}))/i,sn=function(e){for(var n,r,o,i,a,s,d,l=e.ownerDocument,f=new t(e,A,function(e){return h(e,"A")?L:I},!1);n=f.nextNode();)if(r=n.data.split(an),i=r.length,i>1){for(s=n.parentNode,d=n.nextSibling,o=0;i>o;o+=1)a=r[o],o?(o%2?(n=l.createElement("A"),n.textContent=a,n.href=/@/.test(a)?"mailto:"+a:/^(?:ht|f)tps?:/.test(a)?a:"http://"+a):n=l.createTextNode(a),d?s.insertBefore(n,d):s.appendChild(n)):n.data=a;f.currentNode=n}},dn=/^(?:A(?:DDRESS|RTICLE|SIDE)|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)$/,ln={1:10,2:13,3:16,4:18,5:24,6:32,7:48},fn={backgroundColor:{regexp:W,replace:function(e){return O("SPAN",{"class":"highlight",style:"background-color: "+e})}},color:{regexp:W,replace:function(e){return O("SPAN",{"class":"colour",style:"color:"+e})}},fontWeight:{regexp:/^bold/i,replace:function(){return O("B")}},fontStyle:{regexp:/^italic/i,replace:function(){return O("I")}},fontFamily:{regexp:W,replace:function(e){return O("SPAN",{"class":"font",style:"font-family:"+e})}},fontSize:{regexp:W,replace:function(e){return O("SPAN",{"class":"size",style:"font-size:"+e})}}},cn={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style;for(n in fn)r=fn[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(g(e)),t.replaceChild(a,e)),i||e},STRONG:function(e,t){var n=O("B");return t.replaceChild(n,e),n.appendChild(g(e)),n},EM:function(e,t){var n=O("I");return t.replaceChild(n,e),n.appendChild(g(e)),n},FONT:function(e,t){var n,r,o,i,a=e.face,s=e.size;return a&&(n=O("SPAN",{"class":"font",style:"font-family:"+a})),s&&(r=O("SPAN",{"class":"size",style:"font-size:"+ln[s]+"px"}),n&&n.appendChild(r)),i=n||r||O("SPAN"),o=r||n||i,t.replaceChild(i,e),o.appendChild(g(e)),o},TT:function(e,t){var n=O("SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(g(e)),n}},un=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===x&&"IMG"!==t.nodeName&&(un(t),a(t)&&!t.firstChild&&e.removeChild(t))},hn=function(e,t){var n,r,o,i,s,d,l,f=e.childNodes;for(n=0,r=f.length;r>n;n+=1)if(o=f[n],i=o.nodeName,s=o.nodeType,d=cn[i],s===x){if(l=o.childNodes.length,d)o=d(o,e);else{if(!dn.test(i)&&!a(o)){n-=1,r+=l-1,e.replaceChild(g(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&hn(o,t)}else s===D&&(W.test(o.data)||n>0&&a(f[n-1])||r>n+1&&a(f[n+1]))||(e.removeChild(o),n-=1,r-=1);return e},pn=function(e,t){var n,r,o,i,s=e.childNodes,d=null;for(n=0,r=s.length;r>n;n+=1)o=s[n],i="BR"===o.nodeName,!i&&a(o)?(d||(d=O(t)),d.appendChild(o),n-=1,r-=1):(i||d)&&(d||(d=O(t)),m(d),i?e.replaceChild(d,o):(e.insertBefore(d,o),n+=1,r+=1),d=null);return d&&e.appendChild(m(d)),e},Nn=function(e){return(e.nodeType===x?"BR"===e.nodeName:W.test(e.data))?I:L},Cn=function(e){for(var n,r=e.parentNode;a(r);)r=r.parentNode;return n=new t(r,b|A,Nn),n.currentNode=e,!!n.nextNode()},vn=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],d=o.length;for(t=0;d>t;t+=1)i[t]=Cn(o[t]);for(;d--;)if(n=o[d],r=n.parentNode){for(;a(r);)r=r.parentNode;s(r)&&$t[r.nodeName]?(i[d]&&jt(r,n.parentNode,n),C(n)):pn(r,"DIV")}},gn=function(){try{m(V)}catch(e){ot.didError(e)}};lt(M?"beforecut":"cut",function(){var e=Nt();zt(e),_t(e),pt(e),setTimeout(gn,0)});var mn=!1;lt(M?"beforepaste":"paste",function(e){if(!mn){var t,n=e.clipboardData,r=n&&n.items,o=!1;if(r)for(t=r.length;t--;)if(/^image\/.*/.test(r[t].type))return e.preventDefault(),st("dragover",{dataTransfer:n,preventDefault:function(){o=!0}}),o&&st("drop",{dataTransfer:n}),void 0;mn=!0;var i=Nt(),a=i.startContainer,s=i.startOffset,d=i.endContainer,l=i.endOffset,f=O("DIV",{style:"position: absolute; overflow: hidden; top:"+(V.scrollTop+30)+"px; left: 0; width: 1px; height: 1px;"});V.appendChild(f),i.selectNodeContents(f),pt(i),setTimeout(function(){try{var e=g(C(f)),t=e.firstChild,n=ct(a,s,d,l);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(g(t),t),e.normalize(),sn(e),hn(e,!1),vn(e),un(e);for(var r=e,o=!0;r=u(r);)m(r);st("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(n.insertTreeFragment(e),Ft(),n.collapse(!1))}pt(n),Et(n,!0),mn=!1}catch(i){ot.didError(i)}},0)}});var yn={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete"},Tn=function(e){return function(t){t.preventDefault(),e()}},Sn=function(e){return function(t){t.preventDefault();var n=Nt();qt(e,null,n)?Yt(null,{tag:e},n):Yt({tag:e},null,n)}},Bn=function(){try{var e,t=Nt(),n=t.startContainer;if(n.nodeType===D&&(n=n.parentNode),a(n)&&!n.textContent){do e=n.parentNode;while(a(e)&&!e.textContent&&(n=e));t.setStart(e,X.call(e.childNodes,n)),t.collapse(!0),e.removeChild(n),s(e)||(e=c(e)),m(e),t.moveBoundariesDownTree(),pt(t),Et(t)}}catch(r){ot.didError(r)}};K&<("keyup",function(){var e=V.firstChild;"P"===e.nodeName&&(Ht(Nt()),v(e,O("DIV",[g(e)])),pt(_t()))});var On={enter:function(t){t.preventDefault();var n=Nt();if(n){zt(n),sn(n.startContainer),_t(n),n.collapsed||n._deleteContents();var r,o=n.getStartBlock(),i=o?o.nodeName:"DIV",a=$t[i];if(!o)return n._insertNode(O("BR")),n.collapse(!1),pt(n),Et(n,!0),Ft(),void 0;var s,d=n.startContainer,l=n.startOffset;if(a||(d===o&&(d=l?d.childNodes[l-1]:null,l=0,d&&("BR"===d.nodeName?d=d.nextSibling:l=N(d),d&&"BR"!==d.nodeName||(s=m(O("DIV")),d?o.replaceChild(s,d):o.appendChild(s),d=s))),pn(o,"DIV"),a="DIV",d||(d=o.firstChild),n.setStart(d,l),n.setEnd(d,l),o=n.getStartBlock()),!o.textContent){if(h(o,"UL")||h(o,"OL"))return Xt(on,n);if(h(o,"BLOCKQUOTE"))return Xt(en,n)}for(r=jt(o,d,l);r.nodeType===x;){var f,c=r.firstChild;if("A"!==r.nodeName){for(;c&&c.nodeType===D&&!c.data&&(f=c.nextSibling,f&&"BR"!==f.nodeName);)C(c),c=f;if(!c||"BR"===c.nodeName||c.nodeType===D&&!q)break;r=c}else v(r,g(r)),r=c}n=ct(r,0),pt(n),Et(n,!0),r.nodeType===D&&(r=r.parentNode),r.offsetTop+r.offsetHeight>(e.documentElement.scrollTop||V.scrollTop)+V.offsetHeight&&r.scrollIntoView(!1),Ft()}},backspace:function(e){var t=Nt();if(t.collapsed)if(t.startsAtBlockBoundary()){zt(t),_t(t),e.preventDefault();var n=t.getStartBlock(),r=n&&c(n);if(r){if(!r.isContentEditable)return C(r),void 0;for(S(r,n,t),n=r.parentNode;n&&!n.nextSibling;)n=n.parentNode;n&&(n=n.nextSibling)&&B(n),pt(t)}else if(n){if(h(n,"UL")||h(n,"OL"))return Xt(on,t);if(h(n,"BLOCKQUOTE"))return Xt(Jt,t);pt(t),Et(t,!0)}}else{var o=t.startContainer.data||"";W.test(o.charAt(t.startOffset-1))||(zt(t),_t(t),pt(t)),setTimeout(Bn,0)}else zt(t),_t(t),e.preventDefault(),t._deleteContents(),pt(t),Et(t,!0)},"delete":function(e){var t=Nt();if(t.collapsed)if(t.endsAtBlockBoundary()){zt(t),_t(t),e.preventDefault();var n=t.getStartBlock(),r=n&&u(n);if(r){if(!r.isContentEditable)return C(r),void 0;for(S(n,r,t),r=n.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),pt(t),Et(t,!0)}}else{var o=t.startContainer.data||"";W.test(o.charAt(t.startOffset))||(zt(t),_t(t),pt(t)),setTimeout(Bn,0)}else zt(t),_t(t),e.preventDefault(),t._deleteContents(),pt(t),Et(t,!0)},space:function(){var e=Nt();zt(e),sn(e.startContainer),_t(e),pt(e)}};F&&z&&ut.modify&&(On["meta-left"]=function(e){e.preventDefault(),ut.modify("move","backward","lineboundary")},On["meta-right"]=function(e){e.preventDefault(),ut.modify("move","forward","lineboundary")}),On[Q+"b"]=Sn("B"),On[Q+"i"]=Sn("I"),On[Q+"u"]=Sn("U"),On[Q+"y"]=Tn(Kt),On[Q+"z"]=Tn(Mt),On[Q+"shift-z"]=Tn(Kt),lt(q?"keypress":"keydown",function(e){var t=e.keyCode,n=yn[t]||String.fromCharCode(t).toLowerCase(),r="";q&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n,On[n]&&On[n](e)});var En=function(e){return function(){return e.apply(null,arguments),this}},xn=function(e,t,n){return function(){return e(t,n),Dt(),this}};ot=U.editor={didError:function(e){console.log(e)},addEventListener:En(lt),removeEventListener:En(ft),focus:En(Dt),blur:En(bt),getDocument:function(){return e},addStyles:function(t){if(t){var n=e.documentElement.firstChild,r=O("STYLE",{type:"text/css"});r.styleSheet?(n.appendChild(r),r.styleSheet.cssText=t):(r.appendChild(e.createTextNode(t)),n.appendChild(r))}return this},getHTML:function(e){var t,n,r,o,i,a=[];if(e&&(i=Nt())&&Ht(i),Y)for(t=V;t=u(t);)t.textContent||t.querySelector("BR")||(n=O("BR"),t.appendChild(n),a.push(n));if(r=kt(),Y)for(o=a.length;o--;)C(a[o]);return i&&_t(i),r},setHTML:function(t){var n,r=e.createDocumentFragment(),o=O("DIV");o.innerHTML=t,r.appendChild(g(o)),hn(r,!0),vn(r),pn(r,"DIV");for(var i=r;i=u(i);)m(i);for(;n=V.lastChild;)V.removeChild(n);V.appendChild(r),m(V),At=-1,It=[],Lt=0,Rt=!1;var a=_t()||ct(V.firstChild,0);return zt(a),_t(a),j?ht=a:pt(a),Et(a,!0),this},getSelectedText:function(){return Nt().getTextContent()},insertElement:En(Pt),insertImage:function(e){var t=O("IMG",{src:e});return Pt(t),t},getPath:function(){return Ot},getSelection:Nt,setSelection:En(pt),undo:En(Mt),redo:En(Kt),hasFormat:qt,changeFormat:En(Yt),bold:xn(Yt,{tag:"B"}),italic:xn(Yt,{tag:"I"}),underline:xn(Yt,{tag:"U"}),removeBold:xn(Yt,null,{tag:"B"}),removeItalic:xn(Yt,null,{tag:"I"}),removeUnderline:xn(Yt,null,{tag:"U"}),makeLink:function(t){t=encodeURI(t);var n=Nt();if(n.collapsed){var r=t.indexOf(":")+1;if(r)for(;"/"===t[r];)r+=1;n._insertNode(e.createTextNode(t.slice(r)))}return Yt({tag:"A",attributes:{href:t}},{tag:"A"},n),Dt(),this},removeLink:function(){return Yt(null,{tag:"A"},Nt(),!0),Dt(),this},setFontFace:function(e){return Yt({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),Dt(),this},setFontSize:function(e){return Yt({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+("number"==typeof e?e+"px":e)}},{tag:"SPAN",attributes:{"class":"size"}}),Dt(),this},setTextColour:function(e){return Yt({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),Dt(),this},setHighlightColour:function(e){return Yt({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),Dt(),this},setTextAlignment:function(e){return Wt(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/align/.test(e)}).join(" ")+" align-"+e).trim(),t.style.textAlign=e},!0),Dt(),this},setTextDirection:function(e){return Wt(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),Dt(),this},forEachBlock:En(Wt),modifyBlocks:En(Xt),increaseQuoteLevel:xn(Xt,Zt),decreaseQuoteLevel:xn(Xt,Jt),makeUnorderedList:xn(Xt,nn),makeOrderedList:xn(Xt,rn),removeList:xn(Xt,on)},V.setAttribute("contenteditable","true"),ot.setHTML(""),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 3d46c80..bdfa90d 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -75,6 +75,8 @@ var fireEvent = function ( type, event ) { if ( event.type !== type ) { event.type = type; } + // Clone handlers array, so any handlers added/removed do not affect it. + handlers = handlers.slice(); for ( i = 0, l = handlers.length; i < l; i += 1 ) { obj = handlers[i]; try {