From 1fac17b514f1da7fea4872447e07b6cc76dc4e71 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Tue, 5 Aug 2014 10:58:22 +0100 Subject: [PATCH 01/24] Don't strip WS between two inline nodes. --- build/squire-raw.js | 8 ++++++++ build/squire.js | 2 +- source/Editor.js | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 2ddfe95..0a66e18 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -2483,6 +2483,14 @@ var cleanTree = function ( node, allowStyles ) { } continue; } + // If we have just white space, it may still be important if it + // separates two inline nodes, e.g. "link link". + else if ( i && i + 1 < l && + isInline( children[ i - 1 ] ) && + isInline( children[ i + 1 ] ) ) { + child.data = ' '; + continue; + } } node.removeChild( child ); i -= 1; diff --git a/build/squire.js b/build/squire.js index d8d4add..1a12ae7 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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)),s(e))e.firstChild||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""));else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(S(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(S(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Z&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(S(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(S(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(C(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function b(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),q&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(Z?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var R=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,M=/iP(?:ad|hone|od)/.test(H),W=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),q=8===V.ie,Z=!!V.opera,Q=/WebKit\//.test(H),G=W?"meta-":"ctrl-",$=z||Z,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},St=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},Ct=b.prototype;Ct.createElement=function(e,t,n){return k(this._doc,e,t,n)},Ct.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},Ct.didError=function(e){console.log(e)},Ct.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Ct.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Ct.handleEvent=function(e){this.fireEvent(e.type,e)},Ct.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Ct.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},Ct._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Ct.setSelection=function(e){if(e){M&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Ct.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Ct.getSelectedText=function(){return st(this.getSelection())},Ct.getPath=function(){return this._path},Ct._didAddZWS=function(){this._hasZWS=!0},Ct._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Ct._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Ct._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Ct.focus=function(){return K&&this._body.focus(),this._win.focus(),this},Ct.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";Ct._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&R&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Ct._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},Ct._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Ct._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},Ct.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},Ct._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Ct._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return"INPUT"===e.nodeName||i&&!e.data||u.push([t,e]),void 0;if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Ct.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(S(o)),o=e),o};Ct.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Ct.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),St(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=S(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,S(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(S(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(S(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(S(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(S(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O&&(c=o.data,/\S/.test(c))){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;d(r)&&Tt[r.nodeName]?(i[a]&&Bt(r,n.parentNode,n),v(n)):B(r)}};Ct._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Ct._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)},Ct._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),i&&this.fireEvent("drop",{dataTransfer:r}),void 0}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,h=l.endContainer,p=l.endOffset,m=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+30)+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(m),l.selectNodeContents(m),this.setSelection(l),setTimeout(function(){try{var e=S(v(m)),t=e.firstChild,n=s._createRange(c,f,h,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(S(t),t),e.normalize(),Ut(e),Kt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=u(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),C(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};q&&(Ct._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([S(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),e._docWasChanged(),void 0;var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(Rt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!Z)break;a=h}else N(a,S(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return v(o),void 0;for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(bt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return v(o),void 0;for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};W&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),Ct._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),Z&&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,jt[n]&&jt[n](this,e)},Ct._getHTML=function(){return this._body.innerHTML},Ct._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=u(t))},Ct.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Ct.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(S(r)),Kt(n,!0),Zt(n),B(n);for(var o=n;o=u(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},Ct.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e); +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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)),s(e))e.firstChild||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""));else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(S(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(S(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Z&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(S(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(S(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(C(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function b(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),q&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(Z?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var R=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,M=/iP(?:ad|hone|od)/.test(H),W=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),q=8===V.ie,Z=!!V.opera,Q=/WebKit\//.test(H),G=W?"meta-":"ctrl-",$=z||Z,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},St=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},Ct=b.prototype;Ct.createElement=function(e,t,n){return k(this._doc,e,t,n)},Ct.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},Ct.didError=function(e){console.log(e)},Ct.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Ct.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Ct.handleEvent=function(e){this.fireEvent(e.type,e)},Ct.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Ct.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},Ct._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Ct.setSelection=function(e){if(e){M&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Ct.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Ct.getSelectedText=function(){return st(this.getSelection())},Ct.getPath=function(){return this._path},Ct._didAddZWS=function(){this._hasZWS=!0},Ct._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Ct._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Ct._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Ct.focus=function(){return K&&this._body.focus(),this._win.focus(),this},Ct.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";Ct._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&R&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Ct._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},Ct._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Ct._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},Ct.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},Ct._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Ct._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return"INPUT"===e.nodeName||i&&!e.data||u.push([t,e]),void 0;if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Ct.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(S(o)),o=e),o};Ct.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Ct.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),St(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=S(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,S(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(S(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(S(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(S(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(S(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;d(r)&&Tt[r.nodeName]?(i[a]&&Bt(r,n.parentNode,n),v(n)):B(r)}};Ct._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Ct._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)},Ct._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),i&&this.fireEvent("drop",{dataTransfer:r}),void 0}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,h=l.endContainer,p=l.endOffset,m=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+30)+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(m),l.selectNodeContents(m),this.setSelection(l),setTimeout(function(){try{var e=S(v(m)),t=e.firstChild,n=s._createRange(c,f,h,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(S(t),t),e.normalize(),Ut(e),Kt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=u(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),C(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};q&&(Ct._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([S(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),e._docWasChanged(),void 0;var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(Rt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!Z)break;a=h}else N(a,S(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return v(o),void 0;for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(bt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return v(o),void 0;for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};W&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),Ct._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),Z&&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,jt[n]&&jt[n](this,e)},Ct._getHTML=function(){return this._body.innerHTML},Ct._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=u(t))},Ct.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Ct.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(S(r)),Kt(n,!0),Zt(n),B(n);for(var o=n;o=u(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},Ct.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e); else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Ct.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Xt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Ct.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Ct.bold=Xt("changeFormat",{tag:"B"}),Ct.italic=Xt("changeFormat",{tag:"I"}),Ct.underline=Xt("changeFormat",{tag:"U"}),Ct.strikethrough=Xt("changeFormat",{tag:"S"}),Ct.subscript=Xt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Ct.superscript=Xt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Ct.removeBold=Xt("changeFormat",null,{tag:"B"}),Ct.removeItalic=Xt("changeFormat",null,{tag:"I"}),Ct.removeUnderline=Xt("changeFormat",null,{tag:"U"}),Ct.removeStrikethrough=Xt("changeFormat",null,{tag:"S"}),Ct.removeSubscript=Xt("changeFormat",null,{tag:"SUB"}),Ct.removeSuperscript=Xt("changeFormat",null,{tag:"SUP"}),Ct.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Ct.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Ct.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Ct.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()},Ct.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Ct.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Ct.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()},Ct.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Ct.increaseQuoteLevel=Xt("modifyBlocks",kt),Ct.decreaseQuoteLevel=Xt("modifyBlocks",bt),Ct.makeUnorderedList=Xt("modifyBlocks",Ot),Ct.makeOrderedList=Xt("modifyBlocks",xt),Ct.removeList=Xt("modifyBlocks",Lt),Ct.increaseListLevel=Xt("modifyBlocks",Dt),Ct.decreaseListLevel=Xt("modifyBlocks",It),top!==V?(V.editor=new b(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=b}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 792ed55..fbab29a 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1370,6 +1370,14 @@ var cleanTree = function ( node, allowStyles ) { } continue; } + // If we have just white space, it may still be important if it + // separates two inline nodes, e.g. "link link". + else if ( i && i + 1 < l && + isInline( children[ i - 1 ] ) && + isInline( children[ i + 1 ] ) ) { + child.data = ' '; + continue; + } } node.removeChild( child ); i -= 1; From afd3e9807cb7b21a2fffebca013befcaf6462ea5 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Tue, 5 Aug 2014 11:59:48 +0100 Subject: [PATCH 02/24] Be more careful about splitting nodes to remove
s. Can't split an
  • to remove a
    . --- build/squire-raw.js | 20 +++++++++++++------- build/squire.js | 4 ++-- source/Editor.js | 20 +++++++++++++------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 0a66e18..8a204bf 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -2548,17 +2548,23 @@ var cleanupBRs = function ( root ) { block = block.parentNode; } // If this is not inside a block, replace it by wrapping - // inlines in DIV. - if ( !isBlock( block ) || !tagAfterSplit[ block.nodeName ] ) { + // inlines in a
    . + if ( !isBlock( block ) ) { fixContainer( block ); } - // If in a block we can split, split it instead, but only if there - // is actual text content in the block. Otherwise, the
    is a - // placeholder to stop the block from collapsing, so we must leave - // it. else { + // If it doesn't break a line, just remove it; it's not doing + // anything useful. We'll add it back later if required by the + // browser. If it breaks a line, split the block or leave it as + // appropriate. if ( brBreaksLine[l] ) { - splitBlock( block, br.parentNode, br ); + // If in a
    , split, but anywhere else we might change + // the formatting too much (e.g.
  • -> to two list items!) + // so just play it safe and leave it. + if ( block.nodeName !== 'DIV' ) { + continue; + } + split( br.parentNode, br, block.parentNode ); } detach( br ); } diff --git a/build/squire.js b/build/squire.js index 1a12ae7..724251e 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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)),s(e))e.firstChild||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""));else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(S(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(S(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Z&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(S(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(S(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(C(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function b(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),q&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(Z?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var R=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,M=/iP(?:ad|hone|od)/.test(H),W=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),q=8===V.ie,Z=!!V.opera,Q=/WebKit\//.test(H),G=W?"meta-":"ctrl-",$=z||Z,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},St=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},Ct=b.prototype;Ct.createElement=function(e,t,n){return k(this._doc,e,t,n)},Ct.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},Ct.didError=function(e){console.log(e)},Ct.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Ct.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Ct.handleEvent=function(e){this.fireEvent(e.type,e)},Ct.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Ct.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},Ct._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Ct.setSelection=function(e){if(e){M&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Ct.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Ct.getSelectedText=function(){return st(this.getSelection())},Ct.getPath=function(){return this._path},Ct._didAddZWS=function(){this._hasZWS=!0},Ct._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Ct._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Ct._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Ct.focus=function(){return K&&this._body.focus(),this._win.focus(),this},Ct.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";Ct._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&R&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Ct._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},Ct._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Ct._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},Ct.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},Ct._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Ct._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return"INPUT"===e.nodeName||i&&!e.data||u.push([t,e]),void 0;if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Ct.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(S(o)),o=e),o};Ct.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Ct.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),St(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=S(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,S(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(S(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(S(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(S(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(S(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;d(r)&&Tt[r.nodeName]?(i[a]&&Bt(r,n.parentNode,n),v(n)):B(r)}};Ct._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Ct._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)},Ct._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),i&&this.fireEvent("drop",{dataTransfer:r}),void 0}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,h=l.endContainer,p=l.endOffset,m=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+30)+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(m),l.selectNodeContents(m),this.setSelection(l),setTimeout(function(){try{var e=S(v(m)),t=e.firstChild,n=s._createRange(c,f,h,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(S(t),t),e.normalize(),Ut(e),Kt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=u(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),C(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};q&&(Ct._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([S(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),e._docWasChanged(),void 0;var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(Rt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!Z)break;a=h}else N(a,S(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return v(o),void 0;for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(bt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return v(o),void 0;for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};W&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),Ct._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),Z&&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,jt[n]&&jt[n](this,e)},Ct._getHTML=function(){return this._body.innerHTML},Ct._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=u(t))},Ct.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Ct.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(S(r)),Kt(n,!0),Zt(n),B(n);for(var o=n;o=u(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},Ct.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e); -else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Ct.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Xt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Ct.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Ct.bold=Xt("changeFormat",{tag:"B"}),Ct.italic=Xt("changeFormat",{tag:"I"}),Ct.underline=Xt("changeFormat",{tag:"U"}),Ct.strikethrough=Xt("changeFormat",{tag:"S"}),Ct.subscript=Xt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Ct.superscript=Xt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Ct.removeBold=Xt("changeFormat",null,{tag:"B"}),Ct.removeItalic=Xt("changeFormat",null,{tag:"I"}),Ct.removeUnderline=Xt("changeFormat",null,{tag:"U"}),Ct.removeStrikethrough=Xt("changeFormat",null,{tag:"S"}),Ct.removeSubscript=Xt("changeFormat",null,{tag:"SUB"}),Ct.removeSuperscript=Xt("changeFormat",null,{tag:"SUP"}),Ct.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Ct.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Ct.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Ct.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()},Ct.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Ct.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Ct.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()},Ct.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Ct.increaseQuoteLevel=Xt("modifyBlocks",kt),Ct.decreaseQuoteLevel=Xt("modifyBlocks",bt),Ct.makeUnorderedList=Xt("modifyBlocks",Ot),Ct.makeOrderedList=Xt("modifyBlocks",xt),Ct.removeList=Xt("modifyBlocks",Lt),Ct.increaseListLevel=Xt("modifyBlocks",Dt),Ct.decreaseListLevel=Xt("modifyBlocks",It),top!==V?(V.editor=new b(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=b}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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)),s(e))e.firstChild||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""));else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(S(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(S(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Z&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(S(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(S(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(C(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function b(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),q&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(Z?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var R=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,M=/iP(?:ad|hone|od)/.test(H),W=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),q=8===V.ie,Z=!!V.opera,Q=/WebKit\//.test(H),G=W?"meta-":"ctrl-",$=z||Z,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},St=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},Ct=b.prototype;Ct.createElement=function(e,t,n){return k(this._doc,e,t,n)},Ct.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},Ct.didError=function(e){console.log(e)},Ct.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Ct.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Ct.handleEvent=function(e){this.fireEvent(e.type,e)},Ct.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Ct.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},Ct._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Ct.setSelection=function(e){if(e){M&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Ct.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Ct.getSelectedText=function(){return st(this.getSelection())},Ct.getPath=function(){return this._path},Ct._didAddZWS=function(){this._hasZWS=!0},Ct._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Ct._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Ct._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Ct.focus=function(){return K&&this._body.focus(),this._win.focus(),this},Ct.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";Ct._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&R&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Ct._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},Ct._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Ct._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},Ct.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},Ct._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Ct._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return"INPUT"===e.nodeName||i&&!e.data||u.push([t,e]),void 0;if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Ct.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(S(o)),o=e),o};Ct.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Ct.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),St(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=S(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,S(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(S(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(S(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(S(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(S(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;_(n.parentNode,n,r.parentNode)}v(n)}else B(r)}};Ct._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Ct._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)},Ct._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),i&&this.fireEvent("drop",{dataTransfer:r}),void 0}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,h=l.endContainer,p=l.endOffset,m=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+30)+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(m),l.selectNodeContents(m),this.setSelection(l),setTimeout(function(){try{var e=S(v(m)),t=e.firstChild,n=s._createRange(c,f,h,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(S(t),t),e.normalize(),Ut(e),Kt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=u(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),C(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};q&&(Ct._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([S(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),e._docWasChanged(),void 0;var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(Rt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!Z)break;a=h}else N(a,S(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return v(o),void 0;for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(bt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return v(o),void 0;for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};W&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),Ct._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),Z&&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,jt[n]&&jt[n](this,e)},Ct._getHTML=function(){return this._body.innerHTML},Ct._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=u(t))},Ct.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Ct.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(S(r)),Kt(n,!0),Zt(n),B(n);for(var o=n;o=u(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this +},Ct.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Ct.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Xt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Ct.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Ct.bold=Xt("changeFormat",{tag:"B"}),Ct.italic=Xt("changeFormat",{tag:"I"}),Ct.underline=Xt("changeFormat",{tag:"U"}),Ct.strikethrough=Xt("changeFormat",{tag:"S"}),Ct.subscript=Xt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Ct.superscript=Xt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Ct.removeBold=Xt("changeFormat",null,{tag:"B"}),Ct.removeItalic=Xt("changeFormat",null,{tag:"I"}),Ct.removeUnderline=Xt("changeFormat",null,{tag:"U"}),Ct.removeStrikethrough=Xt("changeFormat",null,{tag:"S"}),Ct.removeSubscript=Xt("changeFormat",null,{tag:"SUB"}),Ct.removeSuperscript=Xt("changeFormat",null,{tag:"SUP"}),Ct.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Ct.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Ct.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Ct.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()},Ct.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Ct.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Ct.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()},Ct.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Ct.increaseQuoteLevel=Xt("modifyBlocks",kt),Ct.decreaseQuoteLevel=Xt("modifyBlocks",bt),Ct.makeUnorderedList=Xt("modifyBlocks",Ot),Ct.makeOrderedList=Xt("modifyBlocks",xt),Ct.removeList=Xt("modifyBlocks",Lt),Ct.increaseListLevel=Xt("modifyBlocks",Dt),Ct.decreaseListLevel=Xt("modifyBlocks",It),top!==V?(V.editor=new b(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=b}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index fbab29a..395806c 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1435,17 +1435,23 @@ var cleanupBRs = function ( root ) { block = block.parentNode; } // If this is not inside a block, replace it by wrapping - // inlines in DIV. - if ( !isBlock( block ) || !tagAfterSplit[ block.nodeName ] ) { + // inlines in a
    . + if ( !isBlock( block ) ) { fixContainer( block ); } - // If in a block we can split, split it instead, but only if there - // is actual text content in the block. Otherwise, the
    is a - // placeholder to stop the block from collapsing, so we must leave - // it. else { + // If it doesn't break a line, just remove it; it's not doing + // anything useful. We'll add it back later if required by the + // browser. If it breaks a line, split the block or leave it as + // appropriate. if ( brBreaksLine[l] ) { - splitBlock( block, br.parentNode, br ); + // If in a
    , split, but anywhere else we might change + // the formatting too much (e.g.
  • -> to two list items!) + // so just play it safe and leave it. + if ( block.nodeName !== 'DIV' ) { + continue; + } + split( br.parentNode, br, block.parentNode ); } detach( br ); } From da4931687668632ccbd0e6aa4b8ae5588139ba35 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Wed, 6 Aug 2014 14:42:57 +0200 Subject: [PATCH 03/24] Better positioning of paste area to prevent auto-scrolling. --- build/squire-raw.js | 13 +++++++++++-- build/squire.js | 4 ++-- source/Editor.js | 13 +++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 8a204bf..7daec85 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -2646,11 +2646,20 @@ proto._onPaste = function ( event ) { startContainer = range.startContainer, startOffset = range.startOffset, endContainer = range.endContainer, - endOffset = range.endOffset; + endOffset = range.endOffset, + startBlock = startContainer.nodeType === TEXT_NODE ? + startContainer : startContainer.childNodes[ startOffset ]; + + // We need to position the pasteArea in the visible portion of the screen + // to stop the browser auto-scrolling. + while ( isInline( startBlock ) ) { + startBlock = startBlock.parentNode; + } var pasteArea = this.createElement( 'DIV', { style: 'position: absolute; overflow: hidden; top:' + - (body.scrollTop + 30) + 'px; left: 0; width: 1px; height: 1px;' + ( body.scrollTop + startBlock.getBoundingClientRect().top ) + + 'px; left: 0; width: 1px; height: 1px;' }); body.appendChild( pasteArea ); range.selectNodeContents( pasteArea ); diff --git a/build/squire.js b/build/squire.js index 724251e..59be2d7 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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)),s(e))e.firstChild||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""));else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(S(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(S(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Z&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(S(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(S(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(C(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function b(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),q&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(Z?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var R=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,M=/iP(?:ad|hone|od)/.test(H),W=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),q=8===V.ie,Z=!!V.opera,Q=/WebKit\//.test(H),G=W?"meta-":"ctrl-",$=z||Z,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},St=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},Ct=b.prototype;Ct.createElement=function(e,t,n){return k(this._doc,e,t,n)},Ct.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},Ct.didError=function(e){console.log(e)},Ct.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Ct.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Ct.handleEvent=function(e){this.fireEvent(e.type,e)},Ct.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Ct.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},Ct._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Ct.setSelection=function(e){if(e){M&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Ct.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Ct.getSelectedText=function(){return st(this.getSelection())},Ct.getPath=function(){return this._path},Ct._didAddZWS=function(){this._hasZWS=!0},Ct._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Ct._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Ct._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Ct.focus=function(){return K&&this._body.focus(),this._win.focus(),this},Ct.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";Ct._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&R&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Ct._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},Ct._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Ct._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},Ct.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},Ct._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Ct._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return"INPUT"===e.nodeName||i&&!e.data||u.push([t,e]),void 0;if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Ct.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(S(o)),o=e),o};Ct.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Ct.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),St(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=S(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,S(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(S(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(S(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(S(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(S(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;_(n.parentNode,n,r.parentNode)}v(n)}else B(r)}};Ct._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Ct._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)},Ct._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),i&&this.fireEvent("drop",{dataTransfer:r}),void 0}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,h=l.endContainer,p=l.endOffset,m=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+30)+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(m),l.selectNodeContents(m),this.setSelection(l),setTimeout(function(){try{var e=S(v(m)),t=e.firstChild,n=s._createRange(c,f,h,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(S(t),t),e.normalize(),Ut(e),Kt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=u(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),C(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};q&&(Ct._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([S(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),e._docWasChanged(),void 0;var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(Rt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!Z)break;a=h}else N(a,S(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return v(o),void 0;for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(bt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return v(o),void 0;for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};W&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),Ct._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),Z&&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,jt[n]&&jt[n](this,e)},Ct._getHTML=function(){return this._body.innerHTML},Ct._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=u(t))},Ct.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Ct.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(S(r)),Kt(n,!0),Zt(n),B(n);for(var o=n;o=u(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this -},Ct.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Ct.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Xt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Ct.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Ct.bold=Xt("changeFormat",{tag:"B"}),Ct.italic=Xt("changeFormat",{tag:"I"}),Ct.underline=Xt("changeFormat",{tag:"U"}),Ct.strikethrough=Xt("changeFormat",{tag:"S"}),Ct.subscript=Xt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Ct.superscript=Xt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Ct.removeBold=Xt("changeFormat",null,{tag:"B"}),Ct.removeItalic=Xt("changeFormat",null,{tag:"I"}),Ct.removeUnderline=Xt("changeFormat",null,{tag:"U"}),Ct.removeStrikethrough=Xt("changeFormat",null,{tag:"S"}),Ct.removeSubscript=Xt("changeFormat",null,{tag:"SUB"}),Ct.removeSuperscript=Xt("changeFormat",null,{tag:"SUP"}),Ct.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Ct.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Ct.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Ct.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()},Ct.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Ct.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Ct.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()},Ct.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Ct.increaseQuoteLevel=Xt("modifyBlocks",kt),Ct.decreaseQuoteLevel=Xt("modifyBlocks",bt),Ct.makeUnorderedList=Xt("modifyBlocks",Ot),Ct.makeOrderedList=Xt("modifyBlocks",xt),Ct.removeList=Xt("modifyBlocks",Lt),Ct.increaseListLevel=Xt("modifyBlocks",Dt),Ct.decreaseListLevel=Xt("modifyBlocks",It),top!==V?(V.editor=new b(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=b}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function C(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e))e.firstChild||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""));else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(C(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(C(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Z&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(C(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(C(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(S(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function R(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),q&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(Z?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,M=/iP(?:ad|hone|od)/.test(H),W=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),q=8===V.ie,Z=!!V.opera,Q=/WebKit\//.test(H),G=W?"meta-":"ctrl-",$=z||Z,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},Ct=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},St=R.prototype;St.createElement=function(e,t,n){return k(this._doc,e,t,n)},St.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){M&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return st(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return K&&this._body.focus(),this._win.focus(),this},St.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&b&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,C(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(C(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Ct(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=C(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,C(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(C(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(C(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(C(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(C(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(C(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;_(n.parentNode,n,r.parentNode)}v(n)}else B(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;for(var d=this,l=this._body,c=this.getSelection(),f=c.startContainer,h=c.startOffset,p=c.endContainer,m=c.endOffset,g=f.nodeType===O?f:f.childNodes[h];s(g);)g=g.parentNode;var N=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(l.scrollTop+g.getBoundingClientRect().top)+"px; left: 0; width: 1px; height: 1px;"});l.appendChild(N),c.selectNodeContents(N),this.setSelection(c),setTimeout(function(){try{var e=C(v(N)),t=e.firstChild,n=d._createRange(f,h,p,m);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(C(t),t),e.normalize(),Ut(e),Kt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=u(r);)S(r);d.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),d._docWasChanged(),n.collapse(!1),d._ensureBottomLine())}d.setSelection(n),d._updatePath(n,!0),d._awaitingPaste=!1}catch(i){d.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),S(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};q&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([C(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!Z)break;a=h}else N(a,C(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void v(o);for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(Rt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};W&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),Z&&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,jt[n]&&jt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=u(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(C(r)),Kt(n,!0),Zt(n),B(n);for(var o=n;o=u(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this +},St.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},St.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Xt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};St.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},St.bold=Xt("changeFormat",{tag:"B"}),St.italic=Xt("changeFormat",{tag:"I"}),St.underline=Xt("changeFormat",{tag:"U"}),St.strikethrough=Xt("changeFormat",{tag:"S"}),St.subscript=Xt("changeFormat",{tag:"SUB"},{tag:"SUP"}),St.superscript=Xt("changeFormat",{tag:"SUP"},{tag:"SUB"}),St.removeBold=Xt("changeFormat",null,{tag:"B"}),St.removeItalic=Xt("changeFormat",null,{tag:"I"}),St.removeUnderline=Xt("changeFormat",null,{tag:"U"}),St.removeStrikethrough=Xt("changeFormat",null,{tag:"S"}),St.removeSubscript=Xt("changeFormat",null,{tag:"SUB"}),St.removeSuperscript=Xt("changeFormat",null,{tag:"SUP"}),St.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},St.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},St.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},St.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()},St.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},St.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},St.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()},St.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},St.increaseQuoteLevel=Xt("modifyBlocks",kt),St.decreaseQuoteLevel=Xt("modifyBlocks",Rt),St.makeUnorderedList=Xt("modifyBlocks",Ot),St.makeOrderedList=Xt("modifyBlocks",xt),St.removeList=Xt("modifyBlocks",Lt),St.increaseListLevel=Xt("modifyBlocks",Dt),St.decreaseListLevel=Xt("modifyBlocks",It),top!==V?(V.editor=new R(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=R}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 395806c..03e3572 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1533,11 +1533,20 @@ proto._onPaste = function ( event ) { startContainer = range.startContainer, startOffset = range.startOffset, endContainer = range.endContainer, - endOffset = range.endOffset; + endOffset = range.endOffset, + startBlock = startContainer.nodeType === TEXT_NODE ? + startContainer : startContainer.childNodes[ startOffset ]; + + // We need to position the pasteArea in the visible portion of the screen + // to stop the browser auto-scrolling. + while ( isInline( startBlock ) ) { + startBlock = startBlock.parentNode; + } var pasteArea = this.createElement( 'DIV', { style: 'position: absolute; overflow: hidden; top:' + - (body.scrollTop + 30) + 'px; left: 0; width: 1px; height: 1px;' + ( body.scrollTop + startBlock.getBoundingClientRect().top ) + + 'px; left: 0; width: 1px; height: 1px;' }); body.appendChild( pasteArea ); range.selectNodeContents( pasteArea ); From d5e8ef1381679445f1a78a4bfa7f28ef119ef54d Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 28 Aug 2014 08:10:31 +0700 Subject: [PATCH 04/24] Preserve inline styles on enter in WebKit. --- build/squire-raw.js | 8 +++++++- build/squire.js | 4 ++-- source/Node.js | 8 +++++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 7daec85..37031e5 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -314,7 +314,13 @@ function fixCursor ( node ) { } if ( isInline( node ) ) { - if ( !node.firstChild ) { + child = node.firstChild; + while ( cantFocusEmptyTextNodes && child && + child.nodeType === TEXT_NODE && !child.data ) { + node.removeChild( child ); + child = node.firstChild; + } + if ( !child ) { if ( cantFocusEmptyTextNodes ) { fixer = doc.createTextNode( '\u200B' ); if ( win.editor ) { diff --git a/build/squire.js b/build/squire.js index 59be2d7..47cffa0 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function C(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e))e.firstChild||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""));else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(C(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(C(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Z&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(C(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(C(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(S(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function R(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),q&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(Z?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,M=/iP(?:ad|hone|od)/.test(H),W=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),q=8===V.ie,Z=!!V.opera,Q=/WebKit\//.test(H),G=W?"meta-":"ctrl-",$=z||Z,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},Ct=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},St=R.prototype;St.createElement=function(e,t,n){return k(this._doc,e,t,n)},St.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){M&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return st(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return K&&this._body.focus(),this._win.focus(),this},St.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&b&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,C(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(C(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Ct(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=C(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,C(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(C(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(C(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(C(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(C(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(C(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;_(n.parentNode,n,r.parentNode)}v(n)}else B(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;for(var d=this,l=this._body,c=this.getSelection(),f=c.startContainer,h=c.startOffset,p=c.endContainer,m=c.endOffset,g=f.nodeType===O?f:f.childNodes[h];s(g);)g=g.parentNode;var N=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(l.scrollTop+g.getBoundingClientRect().top)+"px; left: 0; width: 1px; height: 1px;"});l.appendChild(N),c.selectNodeContents(N),this.setSelection(c),setTimeout(function(){try{var e=C(v(N)),t=e.firstChild,n=d._createRange(f,h,p,m);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(C(t),t),e.normalize(),Ut(e),Kt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=u(r);)S(r);d.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),d._docWasChanged(),n.collapse(!1),d._ensureBottomLine())}d.setSelection(n),d._updatePath(n,!0),d._awaitingPaste=!1}catch(i){d.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),S(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};q&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([C(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!Z)break;a=h}else N(a,C(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void v(o);for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(Rt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};W&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),Z&&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,jt[n]&&jt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=u(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(C(r)),Kt(n,!0),Zt(n),B(n);for(var o=n;o=u(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this -},St.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},St.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Xt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};St.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},St.bold=Xt("changeFormat",{tag:"B"}),St.italic=Xt("changeFormat",{tag:"I"}),St.underline=Xt("changeFormat",{tag:"U"}),St.strikethrough=Xt("changeFormat",{tag:"S"}),St.subscript=Xt("changeFormat",{tag:"SUB"},{tag:"SUP"}),St.superscript=Xt("changeFormat",{tag:"SUP"},{tag:"SUB"}),St.removeBold=Xt("changeFormat",null,{tag:"B"}),St.removeItalic=Xt("changeFormat",null,{tag:"I"}),St.removeUnderline=Xt("changeFormat",null,{tag:"U"}),St.removeStrikethrough=Xt("changeFormat",null,{tag:"S"}),St.removeSubscript=Xt("changeFormat",null,{tag:"SUB"}),St.removeSuperscript=Xt("changeFormat",null,{tag:"SUP"}),St.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},St.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},St.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},St.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()},St.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},St.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},St.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()},St.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},St.increaseQuoteLevel=Xt("modifyBlocks",kt),St.decreaseQuoteLevel=Xt("modifyBlocks",Rt),St.makeUnorderedList=Xt("modifyBlocks",Ot),St.makeOrderedList=Xt("modifyBlocks",xt),St.removeList=Xt("modifyBlocks",Lt),St.increaseListLevel=Xt("modifyBlocks",Dt),St.decreaseListLevel=Xt("modifyBlocks",It),top!==V?(V.editor=new R(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=R}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function C(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;Y&&n&&n.nodeType===O&&!n.data;)e.removeChild(n),n=e.firstChild;n||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""))}else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(C(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(C(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Z&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(C(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(C(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(S(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function R(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),q&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(Z?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,M=/iP(?:ad|hone|od)/.test(H),W=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),q=8===V.ie,Z=!!V.opera,Q=/WebKit\//.test(H),G=W?"meta-":"ctrl-",$=z||Z,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},Ct=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},St=R.prototype;St.createElement=function(e,t,n){return k(this._doc,e,t,n)},St.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){M&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return st(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return K&&this._body.focus(),this._win.focus(),this},St.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&b&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,C(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(C(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Ct(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=C(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,C(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(C(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(C(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(C(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(C(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(C(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;_(n.parentNode,n,r.parentNode)}v(n)}else B(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;for(var d=this,l=this._body,c=this.getSelection(),f=c.startContainer,h=c.startOffset,p=c.endContainer,m=c.endOffset,g=f.nodeType===O?f:f.childNodes[h];s(g);)g=g.parentNode;var N=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(l.scrollTop+g.getBoundingClientRect().top)+"px; left: 0; width: 1px; height: 1px;"});l.appendChild(N),c.selectNodeContents(N),this.setSelection(c),setTimeout(function(){try{var e=C(v(N)),t=e.firstChild,n=d._createRange(f,h,p,m);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(C(t),t),e.normalize(),Ut(e),Kt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=u(r);)S(r);d.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),d._docWasChanged(),n.collapse(!1),d._ensureBottomLine())}d.setSelection(n),d._updatePath(n,!0),d._awaitingPaste=!1}catch(i){d.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),S(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};q&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([C(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!Z)break;a=h}else N(a,C(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void v(o);for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(Rt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};W&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),Z&&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,jt[n]&&jt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=u(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(C(r)),Kt(n,!0),Zt(n),B(n);for(var o=n;o=u(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},St.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},St.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Xt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};St.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},St.bold=Xt("changeFormat",{tag:"B"}),St.italic=Xt("changeFormat",{tag:"I"}),St.underline=Xt("changeFormat",{tag:"U"}),St.strikethrough=Xt("changeFormat",{tag:"S"}),St.subscript=Xt("changeFormat",{tag:"SUB"},{tag:"SUP"}),St.superscript=Xt("changeFormat",{tag:"SUP"},{tag:"SUB"}),St.removeBold=Xt("changeFormat",null,{tag:"B"}),St.removeItalic=Xt("changeFormat",null,{tag:"I"}),St.removeUnderline=Xt("changeFormat",null,{tag:"U"}),St.removeStrikethrough=Xt("changeFormat",null,{tag:"S"}),St.removeSubscript=Xt("changeFormat",null,{tag:"SUB"}),St.removeSuperscript=Xt("changeFormat",null,{tag:"SUP"}),St.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},St.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},St.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},St.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()},St.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},St.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},St.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()},St.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},St.increaseQuoteLevel=Xt("modifyBlocks",kt),St.decreaseQuoteLevel=Xt("modifyBlocks",Rt),St.makeUnorderedList=Xt("modifyBlocks",Ot),St.makeOrderedList=Xt("modifyBlocks",xt),St.removeList=Xt("modifyBlocks",Lt),St.increaseListLevel=Xt("modifyBlocks",Dt),St.decreaseListLevel=Xt("modifyBlocks",It),top!==V?(V.editor=new R(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=R}(document); \ No newline at end of file diff --git a/source/Node.js b/source/Node.js index ebca6e2..a4a627c 100644 --- a/source/Node.js +++ b/source/Node.js @@ -172,7 +172,13 @@ function fixCursor ( node ) { } if ( isInline( node ) ) { - if ( !node.firstChild ) { + child = node.firstChild; + while ( cantFocusEmptyTextNodes && child && + child.nodeType === TEXT_NODE && !child.data ) { + node.removeChild( child ); + child = node.firstChild; + } + if ( !child ) { if ( cantFocusEmptyTextNodes ) { fixer = doc.createTextNode( '\u200B' ); if ( win.editor ) { From 4a8152d2803fc2000a21366f28753ee6c0ad0277 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Wed, 3 Sep 2014 09:21:16 +0700 Subject: [PATCH 05/24] Remove zws in key handlers they could affect. --- build/squire-raw.js | 6 ++++++ build/squire.js | 4 ++-- source/Editor.js | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 37031e5..8bc1920 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -2824,8 +2824,11 @@ var keyHandlers = { if ( !range ) { return; } // Save undo checkpoint and add any links in the preceding section. + // Remove any zws so we don't think there's content in an empty + // block. self._recordUndoState( range ); addLinks( range.startContainer ); + self._removeZWS(); self._getRangeAndRemoveBookmark( range ); // Selected text is overwritten, therefore delete the contents @@ -2958,6 +2961,7 @@ var keyHandlers = { self._docWasChanged(); }, backspace: function ( self, event ) { + self._removeZWS(); var range = self.getSelection(); // If not collapsed, delete contents if ( !range.collapsed ) { @@ -3025,6 +3029,7 @@ var keyHandlers = { } }, 'delete': function ( self, event ) { + self._removeZWS(); var range = self.getSelection(); // If not collapsed, delete contents if ( !range.collapsed ) { @@ -3079,6 +3084,7 @@ var keyHandlers = { } }, tab: function ( self, event ) { + self._removeZWS(); var range = self.getSelection(), node, parent; // If no selection and in an empty block diff --git a/build/squire.js b/build/squire.js index 47cffa0..96bb159 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function C(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;Y&&n&&n.nodeType===O&&!n.data;)e.removeChild(n),n=e.firstChild;n||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""))}else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(C(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(C(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Z&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(C(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(C(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(S(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function R(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),q&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(Z?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,M=/iP(?:ad|hone|od)/.test(H),W=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),q=8===V.ie,Z=!!V.opera,Q=/WebKit\//.test(H),G=W?"meta-":"ctrl-",$=z||Z,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},Ct=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},St=R.prototype;St.createElement=function(e,t,n){return k(this._doc,e,t,n)},St.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){M&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return st(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return K&&this._body.focus(),this._win.focus(),this},St.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&b&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,C(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(C(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Ct(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=C(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,C(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(C(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(C(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(C(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(C(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(C(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;_(n.parentNode,n,r.parentNode)}v(n)}else B(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;for(var d=this,l=this._body,c=this.getSelection(),f=c.startContainer,h=c.startOffset,p=c.endContainer,m=c.endOffset,g=f.nodeType===O?f:f.childNodes[h];s(g);)g=g.parentNode;var N=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(l.scrollTop+g.getBoundingClientRect().top)+"px; left: 0; width: 1px; height: 1px;"});l.appendChild(N),c.selectNodeContents(N),this.setSelection(c),setTimeout(function(){try{var e=C(v(N)),t=e.firstChild,n=d._createRange(f,h,p,m);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(C(t),t),e.normalize(),Ut(e),Kt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=u(r);)S(r);d.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),d._docWasChanged(),n.collapse(!1),d._ensureBottomLine())}d.setSelection(n),d._updatePath(n,!0),d._awaitingPaste=!1}catch(i){d.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),S(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};q&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([C(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!Z)break;a=h}else N(a,C(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void v(o);for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(Rt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};W&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),Z&&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,jt[n]&&jt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=u(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(C(r)),Kt(n,!0),Zt(n),B(n);for(var o=n;o=u(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},St.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},St.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Xt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};St.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},St.bold=Xt("changeFormat",{tag:"B"}),St.italic=Xt("changeFormat",{tag:"I"}),St.underline=Xt("changeFormat",{tag:"U"}),St.strikethrough=Xt("changeFormat",{tag:"S"}),St.subscript=Xt("changeFormat",{tag:"SUB"},{tag:"SUP"}),St.superscript=Xt("changeFormat",{tag:"SUP"},{tag:"SUB"}),St.removeBold=Xt("changeFormat",null,{tag:"B"}),St.removeItalic=Xt("changeFormat",null,{tag:"I"}),St.removeUnderline=Xt("changeFormat",null,{tag:"U"}),St.removeStrikethrough=Xt("changeFormat",null,{tag:"S"}),St.removeSubscript=Xt("changeFormat",null,{tag:"SUB"}),St.removeSuperscript=Xt("changeFormat",null,{tag:"SUP"}),St.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},St.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},St.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},St.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()},St.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},St.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},St.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()},St.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},St.increaseQuoteLevel=Xt("modifyBlocks",kt),St.decreaseQuoteLevel=Xt("modifyBlocks",Rt),St.makeUnorderedList=Xt("modifyBlocks",Ot),St.makeOrderedList=Xt("modifyBlocks",xt),St.removeList=Xt("modifyBlocks",Lt),St.increaseListLevel=Xt("modifyBlocks",Dt),St.decreaseListLevel=Xt("modifyBlocks",It),top!==V?(V.editor=new R(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=R}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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)),s(e)){for(n=e.firstChild;Y&&n&&n.nodeType===O&&!n.data;)e.removeChild(n),n=e.firstChild;n||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""))}else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(S(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(S(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),q&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(S(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(S(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(C(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function R(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),Z&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(q?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,W=/iP(?:ad|hone|od)/.test(H),M=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),Z=8===V.ie,q=!!V.opera,Q=/WebKit\//.test(H),G=M?"meta-":"ctrl-",$=z||q,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},St=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},Ct=R.prototype;Ct.createElement=function(e,t,n){return k(this._doc,e,t,n)},Ct.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},Ct.didError=function(e){console.log(e)},Ct.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Ct.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Ct.handleEvent=function(e){this.fireEvent(e.type,e)},Ct.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Ct.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},Ct._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Ct.setSelection=function(e){if(e){W&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Ct.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Ct.getSelectedText=function(){return st(this.getSelection())},Ct.getPath=function(){return this._path},Ct._didAddZWS=function(){this._hasZWS=!0},Ct._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Ct._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Ct._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Ct.focus=function(){return K&&this._body.focus(),this._win.focus(),this},Ct.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";Ct._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&b&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Ct._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},Ct._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Ct._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},Ct.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},Ct._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Ct._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Ct.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(S(o)),o=e),o};Ct.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Ct.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),St(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=S(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,S(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(S(t)),r}},Wt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(S(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(S(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Mt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Mt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Wt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(S(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},Zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},qt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;_(n.parentNode,n,r.parentNode)}v(n)}else B(r)}};Ct._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Ct._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)},Ct._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;for(var d=this,l=this._body,c=this.getSelection(),f=c.startContainer,h=c.startOffset,p=c.endContainer,m=c.endOffset,g=f.nodeType===O?f:f.childNodes[h];s(g);)g=g.parentNode;var N=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(l.scrollTop+g.getBoundingClientRect().top)+"px; left: 0; width: 1px; height: 1px;"});l.appendChild(N),c.selectNodeContents(N),this.setSelection(c),setTimeout(function(){try{var e=S(v(N)),t=e.firstChild,n=d._createRange(f,h,p,m);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(S(t),t),e.normalize(),Ut(e),Kt(e,!1),qt(e),Mt(e);for(var r=e,o=!0;r=u(r);)C(r);d.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),d._docWasChanged(),n.collapse(!1),d._ensureBottomLine())}d.setSelection(n),d._updatePath(n,!0),d._awaitingPaste=!1}catch(i){d.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),C(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};Z&&(Ct._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([S(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!q)break;a=h}else N(a,S(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void v(o);for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(Rt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};M&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),Ct._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),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,jt[n]&&jt[n](this,e)},Ct._getHTML=function(){return this._body.innerHTML},Ct._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=u(t))},Ct.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Ct.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(S(r)),Kt(n,!0),qt(n),B(n);for(var o=n;o=u(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},Ct.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Ct.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Xt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Ct.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Ct.bold=Xt("changeFormat",{tag:"B"}),Ct.italic=Xt("changeFormat",{tag:"I"}),Ct.underline=Xt("changeFormat",{tag:"U"}),Ct.strikethrough=Xt("changeFormat",{tag:"S"}),Ct.subscript=Xt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Ct.superscript=Xt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Ct.removeBold=Xt("changeFormat",null,{tag:"B"}),Ct.removeItalic=Xt("changeFormat",null,{tag:"I"}),Ct.removeUnderline=Xt("changeFormat",null,{tag:"U"}),Ct.removeStrikethrough=Xt("changeFormat",null,{tag:"S"}),Ct.removeSubscript=Xt("changeFormat",null,{tag:"SUB"}),Ct.removeSuperscript=Xt("changeFormat",null,{tag:"SUP"}),Ct.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Ct.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Ct.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Ct.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()},Ct.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Ct.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Ct.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()},Ct.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Ct.increaseQuoteLevel=Xt("modifyBlocks",kt),Ct.decreaseQuoteLevel=Xt("modifyBlocks",Rt),Ct.makeUnorderedList=Xt("modifyBlocks",Ot),Ct.makeOrderedList=Xt("modifyBlocks",xt),Ct.removeList=Xt("modifyBlocks",Lt),Ct.increaseListLevel=Xt("modifyBlocks",Dt),Ct.decreaseListLevel=Xt("modifyBlocks",It),top!==V?(V.editor=new R(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=R}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 03e3572..74695f0 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1705,8 +1705,11 @@ var keyHandlers = { if ( !range ) { return; } // Save undo checkpoint and add any links in the preceding section. + // Remove any zws so we don't think there's content in an empty + // block. self._recordUndoState( range ); addLinks( range.startContainer ); + self._removeZWS(); self._getRangeAndRemoveBookmark( range ); // Selected text is overwritten, therefore delete the contents @@ -1839,6 +1842,7 @@ var keyHandlers = { self._docWasChanged(); }, backspace: function ( self, event ) { + self._removeZWS(); var range = self.getSelection(); // If not collapsed, delete contents if ( !range.collapsed ) { @@ -1906,6 +1910,7 @@ var keyHandlers = { } }, 'delete': function ( self, event ) { + self._removeZWS(); var range = self.getSelection(); // If not collapsed, delete contents if ( !range.collapsed ) { @@ -1960,6 +1965,7 @@ var keyHandlers = { } }, tab: function ( self, event ) { + self._removeZWS(); var range = self.getSelection(), node, parent; // If no selection and in an empty block From a280cb4946b16a8272269fa2cd7b8665de4c82a6 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Wed, 3 Sep 2014 10:27:38 +0700 Subject: [PATCH 06/24] Improve detection of range at begin/end of block. --- build/squire-raw.js | 63 +++++++++++++++++++++++++-------------------- build/squire.js | 4 +-- source/Range.js | 63 +++++++++++++++++++++++++-------------------- 3 files changed, 72 insertions(+), 58 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 8bc1920..db27524 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -615,6 +615,7 @@ function createElement ( doc, tag, props, children ) { START_TO_END, END_TO_END, END_TO_START, + notWS, indexOf, TreeWalker, @@ -1059,50 +1060,56 @@ var getEndBlockOfRange = function ( range ) { return block && isNodeContainedInRange( range, block, true ) ? block : null; }; +var contentWalker = new TreeWalker( null, + SHOW_TEXT|SHOW_ELEMENT, + function ( node ) { + return node.nodeType === TEXT_NODE ? + notWS.test( node.data ) : + node.nodeName === 'IMG'; + } +); + var rangeDoesStartAtBlockBoundary = function ( range ) { var startContainer = range.startContainer, - startOffset = range.startOffset, - parent, child; + startOffset = range.startOffset; - while ( isInline( startContainer ) ) { + // If in the middle or end of a text node, we're not at the boundary. + if ( startContainer.nodeType === TEXT_NODE ) { if ( startOffset ) { return false; } - parent = startContainer.parentNode; - startOffset = indexOf.call( parent.childNodes, startContainer ); - startContainer = parent; + contentWalker.currentNode = startContainer; + } else { + contentWalker.currentNode = getNodeAfter( startContainer, startOffset ); } - // Skip empty text nodes and
    s. - while ( startOffset && - ( child = startContainer.childNodes[ startOffset - 1 ] ) && - ( child.data === '' || child.nodeName === 'BR' ) ) { - startOffset -= 1; - } - return !startOffset; + + // Otherwise, look for any previous content in the same block. + contentWalker.root = getStartBlockOfRange( range ); + + return !contentWalker.previousNode(); }; var rangeDoesEndAtBlockBoundary = function ( range ) { var endContainer = range.endContainer, endOffset = range.endOffset, - length = getLength( endContainer ), - parent, child; + length; - while ( isInline( endContainer ) ) { - if ( endOffset !== length ) { + // If in a text node with content, and not at the end, we're not + // at the boundary + if ( endContainer.nodeType === TEXT_NODE ) { + length = endContainer.data.length; + if ( length && endOffset < length ) { return false; } - parent = endContainer.parentNode; - endOffset = indexOf.call( parent.childNodes, endContainer ) + 1; - endContainer = parent; - length = endContainer.childNodes.length; + contentWalker.currentNode = endContainer; + } else { + contentWalker.currentNode = getNodeBefore( endContainer, endOffset ); } - // Skip empty text nodes and
    s. - while ( endOffset < length && - ( child = endContainer.childNodes[ endOffset ] ) && - ( child.data === '' || child.nodeName === 'BR' ) ) { - endOffset += 1; - } - return endOffset === length; + + // Otherwise, look for any further content in the same block. + contentWalker.root = getEndBlockOfRange( range ); + + return !contentWalker.nextNode(); }; var expandRangeToBlockBoundaries = function ( range ) { diff --git a/build/squire.js b/build/squire.js index 96bb159..b0f9850 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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)),s(e)){for(n=e.firstChild;Y&&n&&n.nodeType===O&&!n.data;)e.removeChild(n),n=e.firstChild;n||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""))}else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(S(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(S(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),q&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(S(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(S(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(C(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function R(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),Z&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(q?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,W=/iP(?:ad|hone|od)/.test(H),M=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),Z=8===V.ie,q=!!V.opera,Q=/WebKit\//.test(H),G=M?"meta-":"ctrl-",$=z||q,Y=z||Q,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=function(e){for(var t,n,r=e.startContainer,o=e.startOffset;s(r);){if(o)return!1;t=r.parentNode,o=et.call(t.childNodes,r),r=t}for(;o&&(n=r.childNodes[o-1])&&(""===n.data||"BR"===n.nodeName);)o-=1;return!o},Nt=function(e){for(var t,n,r=e.endContainer,o=e.endOffset,i=g(r);s(r);){if(o!==i)return!1;t=r.parentNode,o=et.call(t.childNodes,r)+1,r=t,i=r.childNodes.length}for(;i>o&&(n=r.childNodes[o])&&(""===n.data||"BR"===n.nodeName);)o+=1;return o===i},St=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},Ct=R.prototype;Ct.createElement=function(e,t,n){return k(this._doc,e,t,n)},Ct.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},Ct.didError=function(e){console.log(e)},Ct.getDocument=function(){return this._doc};var _t={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Ct.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Ct.handleEvent=function(e){this.fireEvent(e.type,e)},Ct.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],_t[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Ct.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],_t[e]||this._doc.removeEventListener(e,this,!1))}return this},Ct._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Ct.setSelection=function(e){if(e){W&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Ct.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Ct.getSelectedText=function(){return st(this.getSelection())},Ct.getPath=function(){return this._path},Ct._didAddZWS=function(){this._hasZWS=!0},Ct._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Ct._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Ct._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Ct.focus=function(){return K&&this._body.focus(),this._win.focus(),this},Ct.blur=function(){return K&&this._body.blur(),top.focus(),this};var yt="squire-selection-start",Et="squire-selection-end";Ct._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:yt,type:"hidden"}),r=this.createElement("INPUT",{id:Et,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&b&&(n.id=Et,r.id=yt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Ct._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(yt),r=t.getElementById(Et);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},Ct._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Ct._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},Ct.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},Ct._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Ct._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Ct.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Tt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Bt=function(e,t,n){var r=Tt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(S(o)),o=e),o};Ct.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Ct.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),St(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=S(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,S(s));B(i),N(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},It=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Pt=/\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,Ut=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Pt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},wt=/^(?: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)$/,Ft={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Vt={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ht=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(S(t)),r}},Wt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Vt)r=Vt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(S(e)),t.replaceChild(a,e)),i||e},STRONG:Ht("B"),EM:Ht("I"),STRIKE:Ht("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Ft[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(S(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Mt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Mt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Kt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Wt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!wt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(S(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Kt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},Zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,zt),t.currentNode=e,!!t.nextNode()},qt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;_(n.parentNode,n,r.parentNode)}v(n)}else B(r)}};Ct._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Ct._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)},Ct._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;for(var d=this,l=this._body,c=this.getSelection(),f=c.startContainer,h=c.startOffset,p=c.endContainer,m=c.endOffset,g=f.nodeType===O?f:f.childNodes[h];s(g);)g=g.parentNode;var N=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(l.scrollTop+g.getBoundingClientRect().top)+"px; left: 0; width: 1px; height: 1px;"});l.appendChild(N),c.selectNodeContents(N),this.setSelection(c),setTimeout(function(){try{var e=S(v(N)),t=e.firstChild,n=d._createRange(f,h,p,m);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(S(t),t),e.normalize(),Ut(e),Kt(e,!1),qt(e),Mt(e);for(var r=e,o=!0;r=u(r);)C(r);d.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),d._docWasChanged(),n.collapse(!1),d._ensureBottomLine())}d.setSelection(n),d._updatePath(n,!0),d._awaitingPaste=!1}catch(i){d.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},$t=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Yt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),C(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};Z&&(Ct._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([S(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var jt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Ut(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Tt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(It,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Bt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!q)break;a=h}else N(a,S(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(vt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void v(o);for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(It,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(Rt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Yt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&vt(o)&&Nt(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Ut(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};M&&K&&V.getSelection().modify&&(jt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},jt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),jt[G+"b"]=$t("B"),jt[G+"i"]=$t("I"),jt[G+"u"]=$t("U"),jt[G+"shift-7"]=$t("S"),jt[G+"shift-5"]=$t("SUB",{tag:"SUP"}),jt[G+"shift-6"]=$t("SUP",{tag:"SUB"}),jt[G+"shift-8"]=Gt("makeUnorderedList"),jt[G+"shift-9"]=Gt("makeOrderedList"),jt[G+"["]=Gt("decreaseQuoteLevel"),jt[G+"]"]=Gt("increaseQuoteLevel"),jt[G+"y"]=Gt("redo"),jt[G+"z"]=Gt("undo"),jt[G+"shift-z"]=Gt("redo"),Ct._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),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,jt[n]&&jt[n](this,e)},Ct._getHTML=function(){return this._body.innerHTML},Ct._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=u(t))},Ct.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Ct.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(S(r)),Kt(n,!0),qt(n),B(n);for(var o=n;o=u(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},Ct.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Ct.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Xt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Ct.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Ct.bold=Xt("changeFormat",{tag:"B"}),Ct.italic=Xt("changeFormat",{tag:"I"}),Ct.underline=Xt("changeFormat",{tag:"U"}),Ct.strikethrough=Xt("changeFormat",{tag:"S"}),Ct.subscript=Xt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Ct.superscript=Xt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Ct.removeBold=Xt("changeFormat",null,{tag:"B"}),Ct.removeItalic=Xt("changeFormat",null,{tag:"I"}),Ct.removeUnderline=Xt("changeFormat",null,{tag:"U"}),Ct.removeStrikethrough=Xt("changeFormat",null,{tag:"S"}),Ct.removeSubscript=Xt("changeFormat",null,{tag:"SUB"}),Ct.removeSuperscript=Xt("changeFormat",null,{tag:"SUP"}),Ct.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Ct.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Ct.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Ct.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()},Ct.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Ct.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Ct.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()},Ct.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Ct.increaseQuoteLevel=Xt("modifyBlocks",kt),Ct.decreaseQuoteLevel=Xt("modifyBlocks",Rt),Ct.makeUnorderedList=Xt("modifyBlocks",Ot),Ct.makeOrderedList=Xt("modifyBlocks",xt),Ct.removeList=Xt("modifyBlocks",Lt),Ct.increaseListLevel=Xt("modifyBlocks",Dt),Ct.decreaseListLevel=Xt("modifyBlocks",It),top!==V?(V.editor=new R(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=R}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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)),s(e)){for(n=e.firstChild;Y&&n&&n.nodeType===O&&!n.data;)e.removeChild(n),n=e.firstChild;n||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""))}else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(S(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(S(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),q&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(S(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(S(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(C(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function b(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),Z&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(q?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var R=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,W=/iP(?:ad|hone|od)/.test(H),M=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),Z=8===V.ie,q=!!V.opera,G=/WebKit\//.test(H),Q=M?"meta-":"ctrl-",$=z||q,Y=z||G,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=new n(null,L|x,function(e){return e.nodeType===O?J.test(e.data):"IMG"===e.nodeName}),Nt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===O){if(n)return!1;vt.currentNode=t}else vt.currentNode=it(t,n);return vt.root=mt(e),!vt.previousNode()},St=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===O){if(t=n.data.length,t&&t>r)return!1;vt.currentNode=n}else vt.currentNode=ot(n,r);return vt.root=gt(e),!vt.nextNode()},Ct=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},_t=b.prototype;_t.createElement=function(e,t,n){return k(this._doc,e,t,n)},_t.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},_t.didError=function(e){console.log(e)},_t.getDocument=function(){return this._doc};var yt={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};_t.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},_t.handleEvent=function(e){this.fireEvent(e.type,e)},_t.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],yt[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},_t.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],yt[e]||this._doc.removeEventListener(e,this,!1))}return this},_t._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},_t.setSelection=function(e){if(e){W&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},_t.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},_t.getSelectedText=function(){return st(this.getSelection())},_t.getPath=function(){return this._path},_t._didAddZWS=function(){this._hasZWS=!0},_t._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},_t._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},_t._updatePathOnEvent=function(){this._updatePath(this.getSelection())},_t.focus=function(){return K&&this._body.focus(),this._win.focus(),this},_t.blur=function(){return K&&this._body.blur(),top.focus(),this};var Et="squire-selection-start",Tt="squire-selection-end";_t._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Et,type:"hidden"}),r=this.createElement("INPUT",{id:Tt,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&R&&(n.id=Tt,r.id=Et,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},_t._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Et),r=t.getElementById(Tt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},_t._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},_t._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},_t.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},_t._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},_t._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},_t.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Bt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},kt=function(e,t,n){var r=Bt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(S(o)),o=e),o};_t.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},_t.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Ct(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=S(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,S(s));B(i),N(o,i)}return e},It=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Pt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Ut=/\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,wt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Ut.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ft=/^(?: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)$/,Vt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ht={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Wt=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(S(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ht)r=Ht[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(S(e)),t.replaceChild(a,e)),i||e},STRONG:Wt("B"),EM:Wt("I"),STRIKE:Wt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Vt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(S(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Kt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Kt(t),s(t)&&!t.firstChild&&e.removeChild(t))},zt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ft.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(S(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&zt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,Zt),t.currentNode=e,!!t.nextNode()},Gt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;_(n.parentNode,n,r.parentNode)}v(n)}else B(r)}};_t._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},_t._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)},_t._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;for(var d=this,l=this._body,c=this.getSelection(),f=c.startContainer,h=c.startOffset,p=c.endContainer,m=c.endOffset,g=f.nodeType===O?f:f.childNodes[h];s(g);)g=g.parentNode;var N=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(l.scrollTop+g.getBoundingClientRect().top)+"px; left: 0; width: 1px; height: 1px;"});l.appendChild(N),c.selectNodeContents(N),this.setSelection(c),setTimeout(function(){try{var e=S(v(N)),t=e.firstChild,n=d._createRange(f,h,p,m);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(S(t),t),e.normalize(),wt(e),zt(e,!1),Gt(e),Kt(e);for(var r=e,o=!0;r=u(r);)C(r);d.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),d._docWasChanged(),n.collapse(!1),d._ensureBottomLine())}d.setSelection(n),d._updatePath(n,!0),d._awaitingPaste=!1}catch(i){d.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},$t=function(e){return function(t,n){n.preventDefault(),t[e]()}},Yt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},jt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),C(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};Z&&(_t._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([S(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Xt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),wt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Bt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(Pt,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(At,s)}for(a=kt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!q)break;a=h}else N(a,S(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void v(o);for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(Pt,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(Rt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){jt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(St(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){jt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&Nt(o)&&St(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(It,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),wt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};M&&K&&V.getSelection().modify&&(Xt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Xt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Xt[Q+"b"]=Yt("B"),Xt[Q+"i"]=Yt("I"),Xt[Q+"u"]=Yt("U"),Xt[Q+"shift-7"]=Yt("S"),Xt[Q+"shift-5"]=Yt("SUB",{tag:"SUP"}),Xt[Q+"shift-6"]=Yt("SUP",{tag:"SUB"}),Xt[Q+"shift-8"]=$t("makeUnorderedList"),Xt[Q+"shift-9"]=$t("makeOrderedList"),Xt[Q+"["]=$t("decreaseQuoteLevel"),Xt[Q+"]"]=$t("increaseQuoteLevel"),Xt[Q+"y"]=$t("redo"),Xt[Q+"z"]=$t("undo"),Xt[Q+"shift-z"]=$t("redo"),_t._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),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,Xt[n]&&Xt[n](this,e)},_t._getHTML=function(){return this._body.innerHTML},_t._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=u(t))},_t.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},_t.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(S(r)),zt(n,!0),Gt(n),B(n);for(var o=n;o=u(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},_t.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},_t.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Jt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};_t.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},_t.bold=Jt("changeFormat",{tag:"B"}),_t.italic=Jt("changeFormat",{tag:"I"}),_t.underline=Jt("changeFormat",{tag:"U"}),_t.strikethrough=Jt("changeFormat",{tag:"S"}),_t.subscript=Jt("changeFormat",{tag:"SUB"},{tag:"SUP"}),_t.superscript=Jt("changeFormat",{tag:"SUP"},{tag:"SUB"}),_t.removeBold=Jt("changeFormat",null,{tag:"B"}),_t.removeItalic=Jt("changeFormat",null,{tag:"I"}),_t.removeUnderline=Jt("changeFormat",null,{tag:"U"}),_t.removeStrikethrough=Jt("changeFormat",null,{tag:"S"}),_t.removeSubscript=Jt("changeFormat",null,{tag:"SUB"}),_t.removeSuperscript=Jt("changeFormat",null,{tag:"SUP"}),_t.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},_t.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},_t.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},_t.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()},_t.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},_t.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},_t.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()},_t.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},_t.increaseQuoteLevel=Jt("modifyBlocks",bt),_t.decreaseQuoteLevel=Jt("modifyBlocks",Rt),_t.makeUnorderedList=Jt("modifyBlocks",xt),_t.makeOrderedList=Jt("modifyBlocks",Lt),_t.removeList=Jt("modifyBlocks",Dt),_t.increaseListLevel=Jt("modifyBlocks",It),_t.decreaseListLevel=Jt("modifyBlocks",Pt),top!==V?(V.editor=new b(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=b}(document); \ No newline at end of file diff --git a/source/Range.js b/source/Range.js index 3efdde1..5d90a69 100644 --- a/source/Range.js +++ b/source/Range.js @@ -7,6 +7,7 @@ START_TO_END, END_TO_END, END_TO_START, + notWS, indexOf, TreeWalker, @@ -451,50 +452,56 @@ var getEndBlockOfRange = function ( range ) { return block && isNodeContainedInRange( range, block, true ) ? block : null; }; +var contentWalker = new TreeWalker( null, + SHOW_TEXT|SHOW_ELEMENT, + function ( node ) { + return node.nodeType === TEXT_NODE ? + notWS.test( node.data ) : + node.nodeName === 'IMG'; + } +); + var rangeDoesStartAtBlockBoundary = function ( range ) { var startContainer = range.startContainer, - startOffset = range.startOffset, - parent, child; + startOffset = range.startOffset; - while ( isInline( startContainer ) ) { + // If in the middle or end of a text node, we're not at the boundary. + if ( startContainer.nodeType === TEXT_NODE ) { if ( startOffset ) { return false; } - parent = startContainer.parentNode; - startOffset = indexOf.call( parent.childNodes, startContainer ); - startContainer = parent; + contentWalker.currentNode = startContainer; + } else { + contentWalker.currentNode = getNodeAfter( startContainer, startOffset ); } - // Skip empty text nodes and
    s. - while ( startOffset && - ( child = startContainer.childNodes[ startOffset - 1 ] ) && - ( child.data === '' || child.nodeName === 'BR' ) ) { - startOffset -= 1; - } - return !startOffset; + + // Otherwise, look for any previous content in the same block. + contentWalker.root = getStartBlockOfRange( range ); + + return !contentWalker.previousNode(); }; var rangeDoesEndAtBlockBoundary = function ( range ) { var endContainer = range.endContainer, endOffset = range.endOffset, - length = getLength( endContainer ), - parent, child; + length; - while ( isInline( endContainer ) ) { - if ( endOffset !== length ) { + // If in a text node with content, and not at the end, we're not + // at the boundary + if ( endContainer.nodeType === TEXT_NODE ) { + length = endContainer.data.length; + if ( length && endOffset < length ) { return false; } - parent = endContainer.parentNode; - endOffset = indexOf.call( parent.childNodes, endContainer ) + 1; - endContainer = parent; - length = endContainer.childNodes.length; + contentWalker.currentNode = endContainer; + } else { + contentWalker.currentNode = getNodeBefore( endContainer, endOffset ); } - // Skip empty text nodes and
    s. - while ( endOffset < length && - ( child = endContainer.childNodes[ endOffset ] ) && - ( child.data === '' || child.nodeName === 'BR' ) ) { - endOffset += 1; - } - return endOffset === length; + + // Otherwise, look for any further content in the same block. + contentWalker.root = getEndBlockOfRange( range ); + + return !contentWalker.nextNode(); }; var expandRangeToBlockBoundaries = function ( range ) { From 597024eecb6c87a9a2e5102cc4659bdede2bf832 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 4 Sep 2014 17:19:02 +0700 Subject: [PATCH 07/24] Remove FILTER_(ACCEPT|SKIP) constants. Just return a boolean for the TreeWalker filter fn. This diverges from the spec, but since the goal of this implementation is not to fully implement the spec and we're never going to use a native implementation, this doesn't matter and the code is easier to read when the function is just returning a boolean like any normal filter function. --- build/squire-raw.js | 36 +++++++++++------------------------- build/squire.js | 4 ++-- source/Constants.js | 2 -- source/Editor.js | 17 ++++++----------- source/Node.js | 7 +------ source/Range.js | 5 ++--- source/TreeWalker.js | 5 ++--- 7 files changed, 24 insertions(+), 52 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index db27524..a3532cb 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -11,8 +11,6 @@ var ELEMENT_NODE = 1; // Node.ELEMENT_NODE; var TEXT_NODE = 3; // Node.TEXT_NODE; var SHOW_ELEMENT = 1; // NodeFilter.SHOW_ELEMENT; var SHOW_TEXT = 4; // NodeFilter.SHOW_TEXT; -var FILTER_ACCEPT = 1; // NodeFilter.FILTER_ACCEPT; -var FILTER_SKIP = 3; // NodeFilter.FILTER_SKIP; var START_TO_START = 0; // Range.START_TO_START var START_TO_END = 1; // Range.START_TO_END @@ -49,7 +47,6 @@ var hasBuggySplit = ( function () { var notWS = /[^ \t\r\n]/; var indexOf = Array.prototype.indexOf; -/*global FILTER_ACCEPT */ /*jshint strict:false */ /* @@ -103,7 +100,7 @@ TreeWalker.prototype.nextNode = function () { return null; } if ( ( typeToBitArray[ node.nodeType ] & nodeType ) && - filter( node ) === FILTER_ACCEPT ) { + filter( node ) ) { this.currentNode = node; return node; } @@ -133,7 +130,7 @@ TreeWalker.prototype.previousNode = function () { return null; } if ( ( typeToBitArray[ node.nodeType ] & nodeType ) && - filter( node ) === FILTER_ACCEPT ) { + filter( node ) ) { this.currentNode = node; return node; } @@ -144,8 +141,6 @@ TreeWalker.prototype.previousNode = function () { ELEMENT_NODE, TEXT_NODE, SHOW_ELEMENT, - FILTER_ACCEPT, - FILTER_SKIP, win, isOpera, useTextFixer, @@ -214,13 +209,10 @@ function isContainer ( node ) { !isInline( node ) && !isBlock( node ); } -function acceptIfBlock ( el ) { - return isBlock( el ) ? FILTER_ACCEPT : FILTER_SKIP; -} function getBlockWalker ( node ) { var doc = node.ownerDocument, walker = new TreeWalker( - doc.body, SHOW_ELEMENT, acceptIfBlock, false ); + doc.body, SHOW_ELEMENT, isBlock, false ); walker.currentNode = node; return walker; } @@ -610,7 +602,6 @@ function createElement ( doc, tag, props, children ) { ELEMENT_NODE, TEXT_NODE, SHOW_TEXT, - FILTER_ACCEPT, START_TO_START, START_TO_END, END_TO_END, @@ -668,8 +659,8 @@ var forEachTextNodeInRange = function ( range, fn ) { endContainer = range.endContainer, root = range.commonAncestorContainer, walker = new TreeWalker( - root, SHOW_TEXT, function ( node ) { - return FILTER_ACCEPT; + root, SHOW_TEXT, function (/* node */) { + return true; }, false ), textnode = walker.currentNode = startContainer; @@ -1130,8 +1121,6 @@ var expandRangeToBlockBoundaries = function ( range ) { TEXT_NODE, SHOW_ELEMENT, SHOW_TEXT, - FILTER_ACCEPT, - FILTER_SKIP, win, isIOS, isMac, @@ -1467,7 +1456,7 @@ proto._removeZWS = function () { return; } var walker = new TreeWalker( this._body, SHOW_TEXT, function () { - return FILTER_ACCEPT; + return true; }, false ), node, index; while ( node = walker.nextNode() ) { @@ -1724,8 +1713,7 @@ proto.hasFormat = function ( tag, attributes, range ) { // Otherwise, check each text node at least partially contained within // the selection and make sure all of them have the format we want. walker = new TreeWalker( root, SHOW_TEXT, function ( node ) { - return isNodeContainedInRange( range, node, true ) ? - FILTER_ACCEPT : FILTER_SKIP; + return isNodeContainedInRange( range, node, true ); }, false ); var seenNode = false; @@ -1764,8 +1752,7 @@ proto._addFormat = function ( tag, attributes, range ) { range.commonAncestorContainer, SHOW_TEXT, function ( node ) { - return isNodeContainedInRange( range, node, true ) ? - FILTER_ACCEPT : FILTER_SKIP; + return isNodeContainedInRange( range, node, true ); }, false ); @@ -2224,7 +2211,7 @@ var addLinks = function ( frag ) { var doc = frag.ownerDocument, walker = new TreeWalker( frag, SHOW_TEXT, function ( node ) { - return getNearest( node, 'A' ) ? FILTER_SKIP : FILTER_ACCEPT; + return !getNearest( node, 'A' ); }, false ), node, data, parent, match, index, endIndex, child; while ( node = walker.nextNode() ) { @@ -2514,10 +2501,9 @@ var cleanTree = function ( node, allowStyles ) { }; var notWSTextNode = function ( node ) { - return ( node.nodeType === ELEMENT_NODE ? + return node.nodeType === ELEMENT_NODE ? node.nodeName === 'BR' : - notWS.test( node.data ) ) ? - FILTER_ACCEPT : FILTER_SKIP; + notWS.test( node.data ); }; var isLineBreak = function ( br ) { var block = br.parentNode, diff --git a/build/squire.js b/build/squire.js index b0f9850..3851db8 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===A&&!!rt[e.nodeName]}function s(e){return nt.test(e.nodeName)}function d(e){return e.nodeType===A&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===A&&!s(e)&&!d(e)}function c(e){return d(e)?D:I}function f(e){var t=e.ownerDocument,r=new n(t.body,x,c,!1);return r.currentNode=e,r}function h(e){return f(e).previousNode()}function u(e){return f(e).nextNode()}function p(e,t,n){do if(o(e,t,n))return e;while(e=e.parentNode);return null}function m(e){var t,n,r,o,i=e.parentNode;return i&&e.nodeType===A?(t=m(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?m(i):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function N(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function S(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function C(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)),s(e)){for(n=e.firstChild;Y&&n&&n.nodeType===O&&!n.data;)e.removeChild(n),n=e.firstChild;n||(Y?(t=r.createTextNode("​"),V.editor&&V.editor._didAddZWS()):t=r.createTextNode(""))}else if($){for(;e.nodeType!==O&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===O?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===O&&e!==n)return _(e.parentNode,e.splitText(t),n);if(a===A){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=g(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=g(r))),v(n),n.nodeType===O?r.appendData(n.data):l.push(S(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());y(n,t)}}function E(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;v(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(S(t)),y(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),q&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function T(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(S(r)),r.appendChild(n)}v(e),t=!l(e),r.appendChild(S(e)),t&&B(r),o&&T(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function B(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=k(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=k(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&B(r);return d&&e.appendChild(C(d)),e}function k(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function b(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,j&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(z?"beforecut":"cut",this._onCut),this.addEventListener(z?"beforepaste":"paste",this._onPaste),Z&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(q?"keypress":"keydown",this._onKey),X&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var R=2,A=1,O=3,x=1,L=4,D=1,I=3,P=0,U=1,w=2,F=3,V=e.defaultView,H=navigator.userAgent,W=/iP(?:ad|hone|od)/.test(H),M=/Mac OS X/.test(H),K=/Gecko\//.test(H),z=/Trident\/[456]\./.test(H),Z=8===V.ie,q=!!V.opera,G=/WebKit\//.test(H),Q=M?"meta-":"ctrl-",$=z||q,Y=z||G,j=z,X=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),J=/[^ \t\r\n]/,et=Array.prototype.indexOf,tt={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,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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}},n.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(tt[e.nodeType]&r&&o(e)===D)return this.currentNode=e,e;t=e}};var nt=/^(?:#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},ot=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},it=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(U,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(P,r)<1,s=e.compareBoundaryPoints(w,r)>-1;return a&&s},ut=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==O&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==O&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==O&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},pt=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=et.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=et.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},mt=function(e){var t,n=e.startContainer;return s(n)?t=h(n):d(n)?t=n:(t=ot(n,e.startOffset),t=u(t)),t&&ht(e,t,!0)?t:null},gt=function(e){var t,n,r=e.endContainer;if(s(r))t=h(r);else if(d(r))t=r;else{if(t=it(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=h(t)}return t&&ht(e,t,!0)?t:null},vt=new n(null,L|x,function(e){return e.nodeType===O?J.test(e.data):"IMG"===e.nodeName}),Nt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===O){if(n)return!1;vt.currentNode=t}else vt.currentNode=it(t,n);return vt.root=mt(e),!vt.previousNode()},St=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===O){if(t=n.data.length,t&&t>r)return!1;vt.currentNode=n}else vt.currentNode=ot(n,r);return vt.root=gt(e),!vt.nextNode()},Ct=function(e){var t,n=mt(e),r=gt(e);n&&r&&(t=n.parentNode,e.setStart(t,et.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,et.call(t.childNodes,r)+1))},_t=b.prototype;_t.createElement=function(e,t,n){return k(this._doc,e,t,n)},_t.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},_t.didError=function(e){console.log(e)},_t.getDocument=function(){return this._doc};var yt={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};_t.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},_t.handleEvent=function(e){this.fireEvent(e.type,e)},_t.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],yt[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},_t.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],yt[e]||this._doc.removeEventListener(e,this,!1))}return this},_t._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},_t.setSelection=function(e){if(e){W&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},_t.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},_t.getSelectedText=function(){return st(this.getSelection())},_t.getPath=function(){return this._path},_t._didAddZWS=function(){this._hasZWS=!0},_t._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,L,function(){return D},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},_t._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?m(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},_t._updatePathOnEvent=function(){this._updatePath(this.getSelection())},_t.focus=function(){return K&&this._body.focus(),this._win.focus(),this},_t.blur=function(){return K&&this._body.blur(),top.focus(),this};var Et="squire-selection-start",Tt="squire-selection-end";_t._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Et,type:"hidden"}),r=this.createElement("INPUT",{id:Tt,type:"hidden"});dt(e,n),e.collapse(!1),dt(e,r),n.compareDocumentPosition(r)&R&&(n.id=Tt,r.id=Et,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},_t._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Et),r=t.getElementById(Tt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:et.call(i.childNodes,n),endOffset:et.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),y(i,s),i!==a&&y(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ut(e),o&&e.collapse(!0)}return e||null},_t._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},_t._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},_t.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(p(a,e,t))return!0;if(a.nodeType===O)return!1;o=new n(a,L,function(e){return ht(r,e,!0)?D:I},!1);for(var s=!1;i=o.nextNode();){if(!p(i,e,t))return!1;s=!0}return s},_t._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),dt(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,L,function(e){return ht(r,e,!0)?D:I},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==O&&(c=i.nextNode());do f=!p(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),N(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},_t._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(Y?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),dt(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!ht(n,e,!1)){var r,o,i=e.nodeType===O;if(!ht(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return ht(n,r,!0)&&o(r,e,t)});r||m.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];N(n,t),t.appendChild(n)}),m.forEach(function(e){N(e,S(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return y(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},_t.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Bt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},kt=function(e,t,n){var r=Bt[e.nodeName],o=_(t,n,e.parentNode);return o.nodeName!==r&&(e=k(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,N(o,e),e.appendChild(S(o)),o=e),o};_t.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=mt(n),o=gt(n);if(r&&o)do if(e(r)||r===o)break;while(r=u(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},_t.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Ct(t);var n,r=this._body;return pt(t,r),n=lt(t,r),dt(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=S(o),a=i.childNodes,r=a.length;r--;)s=a[r],N(s,S(s));B(i),N(o,i)}return e},It=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||N(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Pt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=_(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&_(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),B(e),e},Ut=/\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,wt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,L,function(e){return p(e,"A")?I:D},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Ut.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ft=/^(?: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)$/,Vt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ht={backgroundColor:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return k(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return k(e,"I")}},fontFamily:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:J,replace:function(e,t){return k(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Wt=function(e){return function(t,n){var r=k(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(S(t)),r}},Mt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ht)r=Ht[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(S(e)),t.replaceChild(a,e)),i||e},STRONG:Wt("B"),EM:Wt("I"),STRIKE:Wt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=k(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=k(c,"SPAN",{"class":"size",style:"font-size:"+Vt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=k(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=k(c,"SPAN")),t.replaceChild(a,e),i.appendChild(S(e)),i},TT:function(e,t){var n=k(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(S(e)),n}},Kt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===A&&"IMG"!==t.nodeName&&(Kt(t),s(t)&&!t.firstChild&&e.removeChild(t))},zt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Mt[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ft.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(S(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&zt(o,t)}else{if(a===O){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!J.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!J.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Zt=function(e){return(e.nodeType===A?"BR"===e.nodeName:J.test(e.data))?D:I},qt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|L,Zt),t.currentNode=e,!!t.nextNode()},Gt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=qt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;_(n.parentNode,n,r.parentNode)}v(n)}else B(r)}};_t._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},_t._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)},_t._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;for(var d=this,l=this._body,c=this.getSelection(),f=c.startContainer,h=c.startOffset,p=c.endContainer,m=c.endOffset,g=f.nodeType===O?f:f.childNodes[h];s(g);)g=g.parentNode;var N=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(l.scrollTop+g.getBoundingClientRect().top)+"px; left: 0; width: 1px; height: 1px;"});l.appendChild(N),c.selectNodeContents(N),this.setSelection(c),setTimeout(function(){try{var e=S(v(N)),t=e.firstChild,n=d._createRange(f,h,p,m);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(S(t),t),e.normalize(),wt(e),zt(e,!1),Gt(e),Kt(e);for(var r=e,o=!0;r=u(r);)C(r);d.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(ft(n,e),d._docWasChanged(),n.collapse(!1),d._ensureBottomLine())}d.setSelection(n),d._updatePath(n,!0),d._awaitingPaste=!1}catch(i){d.didError(i)}},0)}};var Qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},$t=function(e){return function(t,n){n.preventDefault(),t[e]()}},Yt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},jt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===O&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,et.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=h(t)),C(t),ut(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};Z&&(_t._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),N(e,this.createDefaultBlock([S(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Xt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),wt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||ct(s),n=mt(s),n&&(r=p(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Bt[o],!n)return dt(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=g(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),B(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=mt(s)),!n.textContent){if(p(n,"UL")||p(n,"OL"))return e.modifyBlocks(Pt,s);if(p(n,"BLOCKQUOTE"))return e.modifyBlocks(At,s)}for(a=kt(n,l,c);a.nodeType===A;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===O&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)v(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===O&&!q)break;a=h}else N(a,S(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===O&&(a=a.parentNode);var u=e._doc,m=e._body;a.offsetTop+a.offsetHeight>(u.documentElement.scrollTop||m.scrollTop)+m.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(Nt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void v(o);for(E(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&T(r),e.setSelection(n)}else if(r){if(p(r,"UL")||p(r,"OL"))return e.modifyBlocks(Pt,n);if(p(r,"BLOCKQUOTE"))return e.modifyBlocks(Rt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){jt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(St(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=mt(n),o=r&&u(r);if(o){if(!o.isContentEditable)return void v(o);for(E(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&T(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";J.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){jt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),ct(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&Nt(o)&&St(o)){for(n=mt(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(It,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),wt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};M&&K&&V.getSelection().modify&&(Xt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Xt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Xt[Q+"b"]=Yt("B"),Xt[Q+"i"]=Yt("I"),Xt[Q+"u"]=Yt("U"),Xt[Q+"shift-7"]=Yt("S"),Xt[Q+"shift-5"]=Yt("SUB",{tag:"SUP"}),Xt[Q+"shift-6"]=Yt("SUP",{tag:"SUB"}),Xt[Q+"shift-8"]=$t("makeUnorderedList"),Xt[Q+"shift-9"]=$t("makeOrderedList"),Xt[Q+"["]=$t("decreaseQuoteLevel"),Xt[Q+"]"]=$t("increaseQuoteLevel"),Xt[Q+"y"]=$t("redo"),Xt[Q+"z"]=$t("undo"),Xt[Q+"shift-z"]=$t("redo"),_t._onKey=function(e){var t=e.keyCode,n=Qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),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,Xt[n]&&Xt[n](this,e)},_t._getHTML=function(){return this._body.innerHTML},_t._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=u(t))},_t.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),$)for(t=this._body;t=u(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),$)for(o=a.length;o--;)v(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},_t.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(S(r)),zt(n,!0),Gt(n),B(n);for(var o=n;o=u(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),j?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},_t.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))dt(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=mt(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=_(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ut(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},_t.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Jt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};_t.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},_t.bold=Jt("changeFormat",{tag:"B"}),_t.italic=Jt("changeFormat",{tag:"I"}),_t.underline=Jt("changeFormat",{tag:"U"}),_t.strikethrough=Jt("changeFormat",{tag:"S"}),_t.subscript=Jt("changeFormat",{tag:"SUB"},{tag:"SUP"}),_t.superscript=Jt("changeFormat",{tag:"SUP"},{tag:"SUB"}),_t.removeBold=Jt("changeFormat",null,{tag:"B"}),_t.removeItalic=Jt("changeFormat",null,{tag:"I"}),_t.removeUnderline=Jt("changeFormat",null,{tag:"U"}),_t.removeStrikethrough=Jt("changeFormat",null,{tag:"S"}),_t.removeSubscript=Jt("changeFormat",null,{tag:"SUB"}),_t.removeSuperscript=Jt("changeFormat",null,{tag:"SUP"}),_t.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;dt(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},_t.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},_t.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},_t.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()},_t.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},_t.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},_t.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()},_t.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},_t.increaseQuoteLevel=Jt("modifyBlocks",bt),_t.decreaseQuoteLevel=Jt("modifyBlocks",Rt),_t.makeUnorderedList=Jt("modifyBlocks",xt),_t.makeOrderedList=Jt("modifyBlocks",Lt),_t.removeList=Jt("modifyBlocks",Dt),_t.increaseListLevel=Jt("modifyBlocks",It),_t.decreaseListLevel=Jt("modifyBlocks",Pt),top!==V?(V.editor=new b(e),V.onEditorLoad&&(V.onEditorLoad(V.editor),V.onEditorLoad=null)):V.Squire=b}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===R&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===R&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,O,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===R?(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 m(e){var t=e.nodeType;return t===R?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===A&&!n.data;)e.removeChild(n),n=e.firstChild;n||(G?(t=r.createTextNode("​"),U.editor&&U.editor._didAddZWS()):t=r.createTextNode(""))}else if(q){for(;e.nodeType!==A&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===A?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function C(e,t,n){var r,o,i,a=e.nodeType;if(a===A&&e!==n)return C(e.parentNode,e.splitText(t),n);if(a===R){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===A?r.appendData(n.data):l.push(N(n));else if(n.nodeType===R){for(o=l.length;o--;)n.appendChild(l.pop());_(n,t)}}function y(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),_(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&T(r),o&&E(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function T(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=B(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=B(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&T(r);return d&&e.appendChild(S(d)),e}function B(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,R=1,A=3,O=1,x=4,L=0,D=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===R;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===R){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(D,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(L,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==A&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==A&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==A&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,x|O,function(e){return e.nodeType===A?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===A){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===A){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=k.prototype;Nt.createElement=function(e,t,n){return B(this._doc,e,t,n)},Nt.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},Nt.didError=function(e){console.log(e)},Nt.getDocument=function(){return this._doc};var St={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Nt.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Nt.handleEvent=function(e){this.fireEvent(e.type,e)},Nt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],St[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Nt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],St[e]||this._doc.removeEventListener(e,this,!1))}return this},Nt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Nt.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Nt.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Nt.getSelectedText=function(){return ot(this.getSelection())},Nt.getPath=function(){return this._path},Nt._didAddZWS=function(){this._hasZWS=!0},Nt._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,x,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Nt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Nt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Nt.focus=function(){return H&&this._body.focus(),this._win.focus(),this},Nt.blur=function(){return H&&this._body.blur(),top.focus(),this};var Ct="squire-selection-start",_t="squire-selection-end";Nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ct,type:"hidden"}),r=this.createElement("INPUT",{id:_t,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=_t,r.id=Ct,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Nt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ct),r=t.getElementById(_t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),_(i,s),i!==a&&_(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},Nt._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Nt._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},Nt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===A)return!1;o=new n(a,x,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Nt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,x,function(e){return lt(r,e,!0)},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==A&&(c=i.nextNode());do f=!u(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),v(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Nt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===A;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return _(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Nt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var yt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Et=function(e,t,n){var r=yt[e.nodeName],o=C(t,n,e.parentNode);return o.nodeName!==r&&(e=B(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};Nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));T(i),v(o,i)}return e},xt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Lt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=C(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&C(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),T(e),e},Dt=/\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,It=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,x,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Dt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Pt=/^(?: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)$/,Ut={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return B(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return B(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ft=function(e){return function(t,n){var r=B(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Vt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ft("B"),EM:Ft("I"),STRIKE:Ft("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=B(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=B(c,"SPAN",{"class":"size",style:"font-size:"+Ut[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=B(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=B(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=B(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ht=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===R&&"IMG"!==t.nodeName&&(Ht(t),s(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Vt[i],a===R){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Pt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Wt(o,t)}else{if(a===A){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Mt=function(e){return e.nodeType===R?"BR"===e.nodeName:Y.test(e.data)},Kt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,O|x,Mt),t.currentNode=e,!!t.nextNode()},zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Kt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;C(n.parentNode,n,r.parentNode)}g(n)}else T(r)}};Nt._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Nt._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)},Nt._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;for(var d=this,l=this._body,c=this.getSelection(),f=c.startContainer,u=c.startOffset,p=c.endContainer,m=c.endOffset,v=f.nodeType===A?f:f.childNodes[u];s(v);)v=v.parentNode;var C=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(l.scrollTop+v.getBoundingClientRect().top)+"px; left: 0; width: 1px; height: 1px;"});l.appendChild(C),c.selectNodeContents(C),this.setSelection(c),setTimeout(function(){try{var e=N(g(C)),t=e.firstChild,n=d._createRange(f,u,p,m);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),It(e),Wt(e,!1),zt(e),Ht(e);for(var r=e,o=!0;r=h(r);)S(r);d.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),d._docWasChanged(),n.collapse(!1),d._ensureBottomLine())}d.setSelection(n),d._updatePath(n,!0),d._awaitingPaste=!1}catch(i){d.didError(i)}},0)}};var Zt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Qt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===A&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),S(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(Nt._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var $t={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),It(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=yt[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),T(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Lt,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(kt,s)}for(a=Et(n,l,c);a.nodeType===R;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===A&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===A&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===A&&(a=a.parentNode);var p=e._doc,C=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||C.scrollTop)+C.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(mt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(y(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Lt,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Bt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";Y.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Qt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(gt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(y(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";Y.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Qt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(xt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),It(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&($t["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},$t["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),$t[Z+"b"]=Gt("B"),$t[Z+"i"]=Gt("I"),$t[Z+"u"]=Gt("U"),$t[Z+"shift-7"]=Gt("S"),$t[Z+"shift-5"]=Gt("SUB",{tag:"SUP"}),$t[Z+"shift-6"]=Gt("SUP",{tag:"SUB"}),$t[Z+"shift-8"]=qt("makeUnorderedList"),$t[Z+"shift-9"]=qt("makeOrderedList"),$t[Z+"["]=qt("decreaseQuoteLevel"),$t[Z+"]"]=qt("increaseQuoteLevel"),$t[Z+"y"]=qt("redo"),$t[Z+"z"]=qt("undo"),$t[Z+"shift-z"]=qt("redo"),Nt._onKey=function(e){var t=e.keyCode,n=Zt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&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,$t[n]&&$t[n](this,e)},Nt._getHTML=function(){return this._body.innerHTML},Nt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t))},Nt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Nt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Wt(n,!0),zt(n),T(n);for(var o=n;o=h(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this +},Nt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=C(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Nt.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Nt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Nt.bold=Yt("changeFormat",{tag:"B"}),Nt.italic=Yt("changeFormat",{tag:"I"}),Nt.underline=Yt("changeFormat",{tag:"U"}),Nt.strikethrough=Yt("changeFormat",{tag:"S"}),Nt.subscript=Yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Nt.superscript=Yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Nt.removeBold=Yt("changeFormat",null,{tag:"B"}),Nt.removeItalic=Yt("changeFormat",null,{tag:"I"}),Nt.removeUnderline=Yt("changeFormat",null,{tag:"U"}),Nt.removeStrikethrough=Yt("changeFormat",null,{tag:"S"}),Nt.removeSubscript=Yt("changeFormat",null,{tag:"SUB"}),Nt.removeSuperscript=Yt("changeFormat",null,{tag:"SUP"}),Nt.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Nt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Nt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Nt.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()},Nt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Nt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Nt.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()},Nt.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Nt.increaseQuoteLevel=Yt("modifyBlocks",Tt),Nt.decreaseQuoteLevel=Yt("modifyBlocks",Bt),Nt.makeUnorderedList=Yt("modifyBlocks",Rt),Nt.makeOrderedList=Yt("modifyBlocks",At),Nt.removeList=Yt("modifyBlocks",Ot),Nt.increaseListLevel=Yt("modifyBlocks",xt),Nt.decreaseListLevel=Yt("modifyBlocks",Lt),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file diff --git a/source/Constants.js b/source/Constants.js index 7bb1f24..0a3ff5a 100644 --- a/source/Constants.js +++ b/source/Constants.js @@ -6,8 +6,6 @@ var ELEMENT_NODE = 1; // Node.ELEMENT_NODE; var TEXT_NODE = 3; // Node.TEXT_NODE; var SHOW_ELEMENT = 1; // NodeFilter.SHOW_ELEMENT; var SHOW_TEXT = 4; // NodeFilter.SHOW_TEXT; -var FILTER_ACCEPT = 1; // NodeFilter.FILTER_ACCEPT; -var FILTER_SKIP = 3; // NodeFilter.FILTER_SKIP; var START_TO_START = 0; // Range.START_TO_START var START_TO_END = 1; // Range.START_TO_END diff --git a/source/Editor.js b/source/Editor.js index 74695f0..e728007 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -4,8 +4,6 @@ TEXT_NODE, SHOW_ELEMENT, SHOW_TEXT, - FILTER_ACCEPT, - FILTER_SKIP, win, isIOS, isMac, @@ -341,7 +339,7 @@ proto._removeZWS = function () { return; } var walker = new TreeWalker( this._body, SHOW_TEXT, function () { - return FILTER_ACCEPT; + return true; }, false ), node, index; while ( node = walker.nextNode() ) { @@ -598,8 +596,7 @@ proto.hasFormat = function ( tag, attributes, range ) { // Otherwise, check each text node at least partially contained within // the selection and make sure all of them have the format we want. walker = new TreeWalker( root, SHOW_TEXT, function ( node ) { - return isNodeContainedInRange( range, node, true ) ? - FILTER_ACCEPT : FILTER_SKIP; + return isNodeContainedInRange( range, node, true ); }, false ); var seenNode = false; @@ -638,8 +635,7 @@ proto._addFormat = function ( tag, attributes, range ) { range.commonAncestorContainer, SHOW_TEXT, function ( node ) { - return isNodeContainedInRange( range, node, true ) ? - FILTER_ACCEPT : FILTER_SKIP; + return isNodeContainedInRange( range, node, true ); }, false ); @@ -1098,7 +1094,7 @@ var addLinks = function ( frag ) { var doc = frag.ownerDocument, walker = new TreeWalker( frag, SHOW_TEXT, function ( node ) { - return getNearest( node, 'A' ) ? FILTER_SKIP : FILTER_ACCEPT; + return !getNearest( node, 'A' ); }, false ), node, data, parent, match, index, endIndex, child; while ( node = walker.nextNode() ) { @@ -1388,10 +1384,9 @@ var cleanTree = function ( node, allowStyles ) { }; var notWSTextNode = function ( node ) { - return ( node.nodeType === ELEMENT_NODE ? + return node.nodeType === ELEMENT_NODE ? node.nodeName === 'BR' : - notWS.test( node.data ) ) ? - FILTER_ACCEPT : FILTER_SKIP; + notWS.test( node.data ); }; var isLineBreak = function ( br ) { var block = br.parentNode, diff --git a/source/Node.js b/source/Node.js index a4a627c..c037a28 100644 --- a/source/Node.js +++ b/source/Node.js @@ -2,8 +2,6 @@ ELEMENT_NODE, TEXT_NODE, SHOW_ELEMENT, - FILTER_ACCEPT, - FILTER_SKIP, win, isOpera, useTextFixer, @@ -72,13 +70,10 @@ function isContainer ( node ) { !isInline( node ) && !isBlock( node ); } -function acceptIfBlock ( el ) { - return isBlock( el ) ? FILTER_ACCEPT : FILTER_SKIP; -} function getBlockWalker ( node ) { var doc = node.ownerDocument, walker = new TreeWalker( - doc.body, SHOW_ELEMENT, acceptIfBlock, false ); + doc.body, SHOW_ELEMENT, isBlock, false ); walker.currentNode = node; return walker; } diff --git a/source/Range.js b/source/Range.js index 5d90a69..e99e1fc 100644 --- a/source/Range.js +++ b/source/Range.js @@ -2,7 +2,6 @@ ELEMENT_NODE, TEXT_NODE, SHOW_TEXT, - FILTER_ACCEPT, START_TO_START, START_TO_END, END_TO_END, @@ -60,8 +59,8 @@ var forEachTextNodeInRange = function ( range, fn ) { endContainer = range.endContainer, root = range.commonAncestorContainer, walker = new TreeWalker( - root, SHOW_TEXT, function ( node ) { - return FILTER_ACCEPT; + root, SHOW_TEXT, function (/* node */) { + return true; }, false ), textnode = walker.currentNode = startContainer; diff --git a/source/TreeWalker.js b/source/TreeWalker.js index 8bf7ffc..e2490c0 100644 --- a/source/TreeWalker.js +++ b/source/TreeWalker.js @@ -1,4 +1,3 @@ -/*global FILTER_ACCEPT */ /*jshint strict:false */ /* @@ -52,7 +51,7 @@ TreeWalker.prototype.nextNode = function () { return null; } if ( ( typeToBitArray[ node.nodeType ] & nodeType ) && - filter( node ) === FILTER_ACCEPT ) { + filter( node ) ) { this.currentNode = node; return node; } @@ -82,7 +81,7 @@ TreeWalker.prototype.previousNode = function () { return null; } if ( ( typeToBitArray[ node.nodeType ] & nodeType ) && - filter( node ) === FILTER_ACCEPT ) { + filter( node ) ) { this.currentNode = node; return node; } From c0e33843fb71a9ba4f2e70aa422f6a9dc10272da Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Wed, 24 Sep 2014 16:36:14 +0700 Subject: [PATCH 08/24] Use helper fn to get start block in paste handler. Neater and deals with the edge cases. --- build/squire-raw.js | 10 +++------- build/squire.js | 2 +- source/Editor.js | 10 +++------- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index a3532cb..c233677 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -2646,18 +2646,14 @@ proto._onPaste = function ( event ) { startOffset = range.startOffset, endContainer = range.endContainer, endOffset = range.endOffset, - startBlock = startContainer.nodeType === TEXT_NODE ? - startContainer : startContainer.childNodes[ startOffset ]; + startBlock = getStartBlockOfRange( range ); // We need to position the pasteArea in the visible portion of the screen // to stop the browser auto-scrolling. - while ( isInline( startBlock ) ) { - startBlock = startBlock.parentNode; - } - var pasteArea = this.createElement( 'DIV', { style: 'position: absolute; overflow: hidden; top:' + - ( body.scrollTop + startBlock.getBoundingClientRect().top ) + + ( body.scrollTop + + ( startBlock ? startBlock.getBoundingClientRect().top : 0 ) ) + 'px; left: 0; width: 1px; height: 1px;' }); body.appendChild( pasteArea ); diff --git a/build/squire.js b/build/squire.js index 3851db8..4fd0251 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===R&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===R&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,O,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===R?(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 m(e){var t=e.nodeType;return t===R?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===A&&!n.data;)e.removeChild(n),n=e.firstChild;n||(G?(t=r.createTextNode("​"),U.editor&&U.editor._didAddZWS()):t=r.createTextNode(""))}else if(q){for(;e.nodeType!==A&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===A?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function C(e,t,n){var r,o,i,a=e.nodeType;if(a===A&&e!==n)return C(e.parentNode,e.splitText(t),n);if(a===R){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===A?r.appendData(n.data):l.push(N(n));else if(n.nodeType===R){for(o=l.length;o--;)n.appendChild(l.pop());_(n,t)}}function y(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),_(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&T(r),o&&E(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function T(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=B(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=B(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&T(r);return d&&e.appendChild(S(d)),e}function B(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,R=1,A=3,O=1,x=4,L=0,D=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===R;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===R){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(D,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(L,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==A&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==A&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==A&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,x|O,function(e){return e.nodeType===A?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===A){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===A){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=k.prototype;Nt.createElement=function(e,t,n){return B(this._doc,e,t,n)},Nt.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},Nt.didError=function(e){console.log(e)},Nt.getDocument=function(){return this._doc};var St={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Nt.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Nt.handleEvent=function(e){this.fireEvent(e.type,e)},Nt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],St[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Nt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],St[e]||this._doc.removeEventListener(e,this,!1))}return this},Nt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Nt.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Nt.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Nt.getSelectedText=function(){return ot(this.getSelection())},Nt.getPath=function(){return this._path},Nt._didAddZWS=function(){this._hasZWS=!0},Nt._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,x,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Nt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Nt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Nt.focus=function(){return H&&this._body.focus(),this._win.focus(),this},Nt.blur=function(){return H&&this._body.blur(),top.focus(),this};var Ct="squire-selection-start",_t="squire-selection-end";Nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ct,type:"hidden"}),r=this.createElement("INPUT",{id:_t,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=_t,r.id=Ct,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Nt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ct),r=t.getElementById(_t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),_(i,s),i!==a&&_(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},Nt._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Nt._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},Nt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===A)return!1;o=new n(a,x,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Nt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,x,function(e){return lt(r,e,!0)},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==A&&(c=i.nextNode());do f=!u(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),v(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Nt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===A;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return _(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Nt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var yt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Et=function(e,t,n){var r=yt[e.nodeName],o=C(t,n,e.parentNode);return o.nodeName!==r&&(e=B(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};Nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));T(i),v(o,i)}return e},xt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Lt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=C(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&C(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),T(e),e},Dt=/\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,It=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,x,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Dt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Pt=/^(?: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)$/,Ut={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return B(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return B(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ft=function(e){return function(t,n){var r=B(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Vt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ft("B"),EM:Ft("I"),STRIKE:Ft("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=B(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=B(c,"SPAN",{"class":"size",style:"font-size:"+Ut[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=B(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=B(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=B(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ht=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===R&&"IMG"!==t.nodeName&&(Ht(t),s(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Vt[i],a===R){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Pt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Wt(o,t)}else{if(a===A){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Mt=function(e){return e.nodeType===R?"BR"===e.nodeName:Y.test(e.data)},Kt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,O|x,Mt),t.currentNode=e,!!t.nextNode()},zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Kt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;C(n.parentNode,n,r.parentNode)}g(n)}else T(r)}};Nt._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Nt._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)},Nt._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;for(var d=this,l=this._body,c=this.getSelection(),f=c.startContainer,u=c.startOffset,p=c.endContainer,m=c.endOffset,v=f.nodeType===A?f:f.childNodes[u];s(v);)v=v.parentNode;var C=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(l.scrollTop+v.getBoundingClientRect().top)+"px; left: 0; width: 1px; height: 1px;"});l.appendChild(C),c.selectNodeContents(C),this.setSelection(c),setTimeout(function(){try{var e=N(g(C)),t=e.firstChild,n=d._createRange(f,u,p,m);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),It(e),Wt(e,!1),zt(e),Ht(e);for(var r=e,o=!0;r=h(r);)S(r);d.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),d._docWasChanged(),n.collapse(!1),d._ensureBottomLine())}d.setSelection(n),d._updatePath(n,!0),d._awaitingPaste=!1}catch(i){d.didError(i)}},0)}};var Zt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Qt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===A&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),S(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(Nt._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var $t={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),It(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=yt[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),T(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Lt,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(kt,s)}for(a=Et(n,l,c);a.nodeType===R;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===A&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===A&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===A&&(a=a.parentNode);var p=e._doc,C=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||C.scrollTop)+C.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(mt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(y(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Lt,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Bt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";Y.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Qt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(gt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(y(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";Y.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Qt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(xt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),It(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&($t["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},$t["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),$t[Z+"b"]=Gt("B"),$t[Z+"i"]=Gt("I"),$t[Z+"u"]=Gt("U"),$t[Z+"shift-7"]=Gt("S"),$t[Z+"shift-5"]=Gt("SUB",{tag:"SUP"}),$t[Z+"shift-6"]=Gt("SUP",{tag:"SUB"}),$t[Z+"shift-8"]=qt("makeUnorderedList"),$t[Z+"shift-9"]=qt("makeOrderedList"),$t[Z+"["]=qt("decreaseQuoteLevel"),$t[Z+"]"]=qt("increaseQuoteLevel"),$t[Z+"y"]=qt("redo"),$t[Z+"z"]=qt("undo"),$t[Z+"shift-z"]=qt("redo"),Nt._onKey=function(e){var t=e.keyCode,n=Zt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&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,$t[n]&&$t[n](this,e)},Nt._getHTML=function(){return this._body.innerHTML},Nt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t))},Nt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Nt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Wt(n,!0),zt(n),T(n);for(var o=n;o=h(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===R&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===R&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,O,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===R?(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 m(e){var t=e.nodeType;return t===R?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===A&&!n.data;)e.removeChild(n),n=e.firstChild;n||(G?(t=r.createTextNode("​"),U.editor&&U.editor._didAddZWS()):t=r.createTextNode(""))}else if(q){for(;e.nodeType!==A&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===A?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function C(e,t,n){var r,o,i,a=e.nodeType;if(a===A&&e!==n)return C(e.parentNode,e.splitText(t),n);if(a===R){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===A?r.appendData(n.data):l.push(N(n));else if(n.nodeType===R){for(o=l.length;o--;)n.appendChild(l.pop());_(n,t)}}function y(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),_(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&T(r),o&&E(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function T(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=B(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=B(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&T(r);return d&&e.appendChild(S(d)),e}function B(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,R=1,A=3,O=1,x=4,L=0,D=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===R;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===R){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(D,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(L,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==A&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==A&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==A&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,x|O,function(e){return e.nodeType===A?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===A){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===A){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=k.prototype;Nt.createElement=function(e,t,n){return B(this._doc,e,t,n)},Nt.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},Nt.didError=function(e){console.log(e)},Nt.getDocument=function(){return this._doc};var St={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Nt.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Nt.handleEvent=function(e){this.fireEvent(e.type,e)},Nt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],St[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Nt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],St[e]||this._doc.removeEventListener(e,this,!1))}return this},Nt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Nt.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Nt.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Nt.getSelectedText=function(){return ot(this.getSelection())},Nt.getPath=function(){return this._path},Nt._didAddZWS=function(){this._hasZWS=!0},Nt._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,x,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Nt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Nt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Nt.focus=function(){return H&&this._body.focus(),this._win.focus(),this},Nt.blur=function(){return H&&this._body.blur(),top.focus(),this};var Ct="squire-selection-start",_t="squire-selection-end";Nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ct,type:"hidden"}),r=this.createElement("INPUT",{id:_t,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=_t,r.id=Ct,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Nt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ct),r=t.getElementById(_t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),_(i,s),i!==a&&_(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},Nt._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Nt._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},Nt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===A)return!1;o=new n(a,x,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Nt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,x,function(e){return lt(r,e,!0)},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==A&&(c=i.nextNode());do f=!u(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),v(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Nt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===A;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return _(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Nt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var yt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Et=function(e,t,n){var r=yt[e.nodeName],o=C(t,n,e.parentNode);return o.nodeName!==r&&(e=B(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};Nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));T(i),v(o,i)}return e},xt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Lt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=C(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&C(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),T(e),e},Dt=/\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,It=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,x,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Dt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Pt=/^(?: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)$/,Ut={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return B(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return B(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ft=function(e){return function(t,n){var r=B(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Vt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ft("B"),EM:Ft("I"),STRIKE:Ft("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=B(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=B(c,"SPAN",{"class":"size",style:"font-size:"+Ut[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=B(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=B(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=B(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ht=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===R&&"IMG"!==t.nodeName&&(Ht(t),s(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Vt[i],a===R){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Pt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Wt(o,t)}else{if(a===A){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Mt=function(e){return e.nodeType===R?"BR"===e.nodeName:Y.test(e.data)},Kt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,O|x,Mt),t.currentNode=e,!!t.nextNode()},zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Kt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;C(n.parentNode,n,r.parentNode)}g(n)}else T(r)}};Nt._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Nt._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)},Nt._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l),v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),It(e),Wt(e,!1),zt(e),Ht(e);for(var r=e,o=!0;r=h(r);)S(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Zt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Qt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===A&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),S(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(Nt._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var $t={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),It(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=yt[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),T(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Lt,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(kt,s)}for(a=Et(n,l,c);a.nodeType===R;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===A&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===A&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===A&&(a=a.parentNode);var p=e._doc,C=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||C.scrollTop)+C.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(mt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(y(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Lt,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Bt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";Y.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Qt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(gt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(y(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";Y.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Qt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(xt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),It(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&($t["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},$t["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),$t[Z+"b"]=Gt("B"),$t[Z+"i"]=Gt("I"),$t[Z+"u"]=Gt("U"),$t[Z+"shift-7"]=Gt("S"),$t[Z+"shift-5"]=Gt("SUB",{tag:"SUP"}),$t[Z+"shift-6"]=Gt("SUP",{tag:"SUB"}),$t[Z+"shift-8"]=qt("makeUnorderedList"),$t[Z+"shift-9"]=qt("makeOrderedList"),$t[Z+"["]=qt("decreaseQuoteLevel"),$t[Z+"]"]=qt("increaseQuoteLevel"),$t[Z+"y"]=qt("redo"),$t[Z+"z"]=qt("undo"),$t[Z+"shift-z"]=qt("redo"),Nt._onKey=function(e){var t=e.keyCode,n=Zt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&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,$t[n]&&$t[n](this,e)},Nt._getHTML=function(){return this._body.innerHTML},Nt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t))},Nt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Nt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Wt(n,!0),zt(n),T(n);for(var o=n;o=h(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this },Nt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=C(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Nt.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Nt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Nt.bold=Yt("changeFormat",{tag:"B"}),Nt.italic=Yt("changeFormat",{tag:"I"}),Nt.underline=Yt("changeFormat",{tag:"U"}),Nt.strikethrough=Yt("changeFormat",{tag:"S"}),Nt.subscript=Yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Nt.superscript=Yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Nt.removeBold=Yt("changeFormat",null,{tag:"B"}),Nt.removeItalic=Yt("changeFormat",null,{tag:"I"}),Nt.removeUnderline=Yt("changeFormat",null,{tag:"U"}),Nt.removeStrikethrough=Yt("changeFormat",null,{tag:"S"}),Nt.removeSubscript=Yt("changeFormat",null,{tag:"SUB"}),Nt.removeSuperscript=Yt("changeFormat",null,{tag:"SUP"}),Nt.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Nt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Nt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Nt.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()},Nt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Nt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Nt.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()},Nt.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Nt.increaseQuoteLevel=Yt("modifyBlocks",Tt),Nt.decreaseQuoteLevel=Yt("modifyBlocks",Bt),Nt.makeUnorderedList=Yt("modifyBlocks",Rt),Nt.makeOrderedList=Yt("modifyBlocks",At),Nt.removeList=Yt("modifyBlocks",Ot),Nt.increaseListLevel=Yt("modifyBlocks",xt),Nt.decreaseListLevel=Yt("modifyBlocks",Lt),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index e728007..755f6ce 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1529,18 +1529,14 @@ proto._onPaste = function ( event ) { startOffset = range.startOffset, endContainer = range.endContainer, endOffset = range.endOffset, - startBlock = startContainer.nodeType === TEXT_NODE ? - startContainer : startContainer.childNodes[ startOffset ]; + startBlock = getStartBlockOfRange( range ); // We need to position the pasteArea in the visible portion of the screen // to stop the browser auto-scrolling. - while ( isInline( startBlock ) ) { - startBlock = startBlock.parentNode; - } - var pasteArea = this.createElement( 'DIV', { style: 'position: absolute; overflow: hidden; top:' + - ( body.scrollTop + startBlock.getBoundingClientRect().top ) + + ( body.scrollTop + + ( startBlock ? startBlock.getBoundingClientRect().top : 0 ) ) + 'px; left: 0; width: 1px; height: 1px;' }); body.appendChild( pasteArea ); From d21ae232156de65609a4a23b0e8847452b374b7b Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Wed, 1 Oct 2014 09:29:54 +0700 Subject: [PATCH 09/24] Record undo checkpoint before paste or delete. --- build/squire-raw.js | 47 ++++++++++++++++++++------------------------- build/squire.js | 4 ++-- source/Editor.js | 47 ++++++++++++++++++++------------------------- 3 files changed, 44 insertions(+), 54 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index c233677..4f66f49 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -2648,6 +2648,10 @@ proto._onPaste = function ( event ) { endOffset = range.endOffset, startBlock = getStartBlockOfRange( range ); + // Record undo checkpoint + self._recordUndoState( range ); + self._getRangeAndRemoveBookmark( range ); + // We need to position the pasteArea in the visible portion of the screen // to stop the browser auto-scrolling. var pasteArea = this.createElement( 'DIV', { @@ -2951,11 +2955,12 @@ var keyHandlers = { }, backspace: function ( self, event ) { self._removeZWS(); + // Record undo checkpoint. var range = self.getSelection(); + self._recordUndoState( range ); + self._getRangeAndRemoveBookmark( range ); // If not collapsed, delete contents if ( !range.collapsed ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); event.preventDefault(); deleteContentsOfRange( range ); self._ensureBottomLine(); @@ -2964,8 +2969,6 @@ var keyHandlers = { } // If at beginning of block, merge with previous else if ( rangeDoesStartAtBlockBoundary( range ) ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); event.preventDefault(); var current = getStartBlockOfRange( range ), previous = current && getPreviousBlock( current ); @@ -3008,22 +3011,18 @@ var keyHandlers = { // Otherwise, leave to browser but check afterwards whether it has // left behind an empty inline tag. else { - var text = range.startContainer.data || ''; - if ( !notWS.test( text.charAt( range.startOffset - 1 ) ) ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); - self.setSelection( range ); - } + self.setSelection( range ); setTimeout( function () { afterDelete( self ); }, 0 ); } }, 'delete': function ( self, event ) { self._removeZWS(); + // Record undo checkpoint. var range = self.getSelection(); + self._recordUndoState( range ); + self._getRangeAndRemoveBookmark( range ); // If not collapsed, delete contents if ( !range.collapsed ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); event.preventDefault(); deleteContentsOfRange( range ); self._ensureBottomLine(); @@ -3032,8 +3031,6 @@ var keyHandlers = { } // If at end of block, merge next into this block else if ( rangeDoesEndAtBlockBoundary( range ) ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); event.preventDefault(); var current = getStartBlockOfRange( range ), next = current && getNextBlock( current ); @@ -3062,13 +3059,7 @@ var keyHandlers = { // Otherwise, leave to browser but check afterwards whether it has // left behind an empty inline tag. else { - // Record undo point if deleting whitespace - var text = range.startContainer.data || ''; - if ( !notWS.test( text.charAt( range.startOffset ) ) ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); - self.setSelection( range ); - } + self.setSelection( range ); setTimeout( function () { afterDelete( self ); }, 0 ); } }, @@ -3112,6 +3103,7 @@ var keyHandlers = { self._removeZWS(); } }; + // Firefox incorrectly handles Cmd-left/Cmd-right on Mac: // it goes back/forward in history! Override to do the right // thing. @@ -3166,12 +3158,15 @@ proto._onKey = function ( event ) { key = 'f' + ( code - 111 ); } - if ( event.altKey ) { modifiers += 'alt-'; } - if ( event.ctrlKey ) { modifiers += 'ctrl-'; } - if ( event.metaKey ) { modifiers += 'meta-'; } - if ( event.shiftKey ) { modifiers += 'shift-'; } + // We need to apply the backspace/delete handlers regardless of modifiers. + if ( key !== 'backspace' && key !== 'delete' ) { + if ( event.altKey ) { modifiers += 'alt-'; } + if ( event.ctrlKey ) { modifiers += 'ctrl-'; } + if ( event.metaKey ) { modifiers += 'meta-'; } + if ( event.shiftKey ) { modifiers += 'shift-'; } - key = modifiers + key; + key = modifiers + key; + } if ( keyHandlers[ key ] ) { keyHandlers[ key ]( this, event ); diff --git a/build/squire.js b/build/squire.js index 4fd0251..f6d5fc3 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===R&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===R&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,O,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===R?(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 m(e){var t=e.nodeType;return t===R?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===A&&!n.data;)e.removeChild(n),n=e.firstChild;n||(G?(t=r.createTextNode("​"),U.editor&&U.editor._didAddZWS()):t=r.createTextNode(""))}else if(q){for(;e.nodeType!==A&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===A?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function C(e,t,n){var r,o,i,a=e.nodeType;if(a===A&&e!==n)return C(e.parentNode,e.splitText(t),n);if(a===R){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===A?r.appendData(n.data):l.push(N(n));else if(n.nodeType===R){for(o=l.length;o--;)n.appendChild(l.pop());_(n,t)}}function y(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),_(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&T(r),o&&E(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function T(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=B(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=B(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&T(r);return d&&e.appendChild(S(d)),e}function B(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,R=1,A=3,O=1,x=4,L=0,D=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===R;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===R){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(D,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(L,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==A&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==A&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==A&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,x|O,function(e){return e.nodeType===A?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===A){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===A){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=k.prototype;Nt.createElement=function(e,t,n){return B(this._doc,e,t,n)},Nt.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},Nt.didError=function(e){console.log(e)},Nt.getDocument=function(){return this._doc};var St={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Nt.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Nt.handleEvent=function(e){this.fireEvent(e.type,e)},Nt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],St[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Nt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],St[e]||this._doc.removeEventListener(e,this,!1))}return this},Nt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Nt.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Nt.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Nt.getSelectedText=function(){return ot(this.getSelection())},Nt.getPath=function(){return this._path},Nt._didAddZWS=function(){this._hasZWS=!0},Nt._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,x,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Nt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Nt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Nt.focus=function(){return H&&this._body.focus(),this._win.focus(),this},Nt.blur=function(){return H&&this._body.blur(),top.focus(),this};var Ct="squire-selection-start",_t="squire-selection-end";Nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ct,type:"hidden"}),r=this.createElement("INPUT",{id:_t,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=_t,r.id=Ct,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Nt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ct),r=t.getElementById(_t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),_(i,s),i!==a&&_(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},Nt._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Nt._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},Nt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===A)return!1;o=new n(a,x,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Nt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,x,function(e){return lt(r,e,!0)},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==A&&(c=i.nextNode());do f=!u(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),v(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Nt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===A;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return _(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Nt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var yt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Et=function(e,t,n){var r=yt[e.nodeName],o=C(t,n,e.parentNode);return o.nodeName!==r&&(e=B(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};Nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));T(i),v(o,i)}return e},xt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Lt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=C(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&C(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),T(e),e},Dt=/\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,It=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,x,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Dt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Pt=/^(?: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)$/,Ut={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return B(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return B(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ft=function(e){return function(t,n){var r=B(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Vt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ft("B"),EM:Ft("I"),STRIKE:Ft("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=B(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=B(c,"SPAN",{"class":"size",style:"font-size:"+Ut[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=B(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=B(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=B(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ht=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===R&&"IMG"!==t.nodeName&&(Ht(t),s(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Vt[i],a===R){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Pt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Wt(o,t)}else{if(a===A){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Mt=function(e){return e.nodeType===R?"BR"===e.nodeName:Y.test(e.data)},Kt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,O|x,Mt),t.currentNode=e,!!t.nextNode()},zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Kt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;C(n.parentNode,n,r.parentNode)}g(n)}else T(r)}};Nt._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Nt._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)},Nt._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l),v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),It(e),Wt(e,!1),zt(e),Ht(e);for(var r=e,o=!0;r=h(r);)S(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Zt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Qt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===A&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),S(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(Nt._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var $t={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),It(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=yt[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),T(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Lt,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(kt,s)}for(a=Et(n,l,c);a.nodeType===R;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===A&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===A&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===A&&(a=a.parentNode);var p=e._doc,C=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||C.scrollTop)+C.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(mt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(y(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Lt,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Bt,n);e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";Y.test(i.charAt(n.startOffset-1))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Qt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(n.collapsed)if(gt(n)){e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(y(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else{var i=n.startContainer.data||"";Y.test(i.charAt(n.startOffset))||(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),e.setSelection(n)),setTimeout(function(){Qt(e)},0)}else e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(xt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),It(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&($t["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},$t["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),$t[Z+"b"]=Gt("B"),$t[Z+"i"]=Gt("I"),$t[Z+"u"]=Gt("U"),$t[Z+"shift-7"]=Gt("S"),$t[Z+"shift-5"]=Gt("SUB",{tag:"SUP"}),$t[Z+"shift-6"]=Gt("SUP",{tag:"SUB"}),$t[Z+"shift-8"]=qt("makeUnorderedList"),$t[Z+"shift-9"]=qt("makeOrderedList"),$t[Z+"["]=qt("decreaseQuoteLevel"),$t[Z+"]"]=qt("increaseQuoteLevel"),$t[Z+"y"]=qt("redo"),$t[Z+"z"]=qt("undo"),$t[Z+"shift-z"]=qt("redo"),Nt._onKey=function(e){var t=e.keyCode,n=Zt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&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,$t[n]&&$t[n](this,e)},Nt._getHTML=function(){return this._body.innerHTML},Nt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t))},Nt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Nt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Wt(n,!0),zt(n),T(n);for(var o=n;o=h(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this -},Nt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=C(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Nt.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Nt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Nt.bold=Yt("changeFormat",{tag:"B"}),Nt.italic=Yt("changeFormat",{tag:"I"}),Nt.underline=Yt("changeFormat",{tag:"U"}),Nt.strikethrough=Yt("changeFormat",{tag:"S"}),Nt.subscript=Yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Nt.superscript=Yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Nt.removeBold=Yt("changeFormat",null,{tag:"B"}),Nt.removeItalic=Yt("changeFormat",null,{tag:"I"}),Nt.removeUnderline=Yt("changeFormat",null,{tag:"U"}),Nt.removeStrikethrough=Yt("changeFormat",null,{tag:"S"}),Nt.removeSubscript=Yt("changeFormat",null,{tag:"SUB"}),Nt.removeSuperscript=Yt("changeFormat",null,{tag:"SUP"}),Nt.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Nt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Nt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Nt.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()},Nt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Nt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Nt.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()},Nt.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Nt.increaseQuoteLevel=Yt("modifyBlocks",Tt),Nt.decreaseQuoteLevel=Yt("modifyBlocks",Bt),Nt.makeUnorderedList=Yt("modifyBlocks",Rt),Nt.makeOrderedList=Yt("modifyBlocks",At),Nt.removeList=Yt("modifyBlocks",Ot),Nt.increaseListLevel=Yt("modifyBlocks",xt),Nt.decreaseListLevel=Yt("modifyBlocks",Lt),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===R&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===R&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,L,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===R?(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 m(e){var t=e.nodeType;return t===R?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===x&&!n.data;)e.removeChild(n),n=e.firstChild;n||(G?(t=r.createTextNode("​"),U.editor&&U.editor._didAddZWS()):t=r.createTextNode(""))}else if(q){for(;e.nodeType!==x&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===x?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function C(e,t,n){var r,o,i,a=e.nodeType;if(a===x&&e!==n)return C(e.parentNode,e.splitText(t),n);if(a===R){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===x?r.appendData(n.data):l.push(N(n));else if(n.nodeType===R){for(o=l.length;o--;)n.appendChild(l.pop());_(n,t)}}function y(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),_(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&T(r),o&&E(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function T(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=B(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=B(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&T(r);return d&&e.appendChild(S(d)),e}function B(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,R=1,x=3,L=1,O=4,A=0,D=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===R;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===R){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(D,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(A,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==x&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==x&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==x&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,O|L,function(e){return e.nodeType===x?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===x){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===x){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=k.prototype;Nt.createElement=function(e,t,n){return B(this._doc,e,t,n)},Nt.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},Nt.didError=function(e){console.log(e)},Nt.getDocument=function(){return this._doc};var St={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Nt.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Nt.handleEvent=function(e){this.fireEvent(e.type,e)},Nt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],St[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Nt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],St[e]||this._doc.removeEventListener(e,this,!1))}return this},Nt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Nt.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Nt.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Nt.getSelectedText=function(){return ot(this.getSelection())},Nt.getPath=function(){return this._path},Nt._didAddZWS=function(){this._hasZWS=!0},Nt._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,O,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Nt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Nt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Nt.focus=function(){return H&&this._body.focus(),this._win.focus(),this},Nt.blur=function(){return H&&this._body.blur(),top.focus(),this};var Ct="squire-selection-start",_t="squire-selection-end";Nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ct,type:"hidden"}),r=this.createElement("INPUT",{id:_t,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=_t,r.id=Ct,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Nt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ct),r=t.getElementById(_t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),_(i,s),i!==a&&_(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},Nt._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Nt._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},Nt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===x)return!1;o=new n(a,O,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Nt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,O,function(e){return lt(r,e,!0)},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==x&&(c=i.nextNode());do f=!u(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),v(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Nt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===x;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return _(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Nt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var yt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Et=function(e,t,n){var r=yt[e.nodeName],o=C(t,n,e.parentNode);return o.nodeName!==r&&(e=B(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};Nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));T(i),v(o,i)}return e},Ot=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},At=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=C(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&C(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),T(e),e},Dt=/\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,It=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,O,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Dt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Pt=/^(?: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)$/,Ut={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return B(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return B(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ft=function(e){return function(t,n){var r=B(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Vt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ft("B"),EM:Ft("I"),STRIKE:Ft("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=B(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=B(c,"SPAN",{"class":"size",style:"font-size:"+Ut[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=B(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=B(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=B(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ht=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===R&&"IMG"!==t.nodeName&&(Ht(t),s(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Vt[i],a===R){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Pt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Wt(o,t)}else{if(a===x){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Mt=function(e){return e.nodeType===R?"BR"===e.nodeName:Y.test(e.data)},Kt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,L|O,Mt),t.currentNode=e,!!t.nextNode()},zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Kt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;C(n.parentNode,n,r.parentNode)}g(n)}else T(r)}};Nt._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Nt._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)},Nt._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),It(e),Wt(e,!1),zt(e),Ht(e);for(var r=e,o=!0;r=h(r);)S(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Zt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Qt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===x&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),S(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(Nt._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var $t={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),It(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=yt[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),T(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(At,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(kt,s)}for(a=Et(n,l,c);a.nodeType===R;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===x&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===x&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===x&&(a=a.parentNode);var p=e._doc,C=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||C.scrollTop)+C.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(y(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(At,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Bt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(y(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Ot,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),It(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&($t["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},$t["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),$t[Z+"b"]=Gt("B"),$t[Z+"i"]=Gt("I"),$t[Z+"u"]=Gt("U"),$t[Z+"shift-7"]=Gt("S"),$t[Z+"shift-5"]=Gt("SUB",{tag:"SUP"}),$t[Z+"shift-6"]=Gt("SUP",{tag:"SUB"}),$t[Z+"shift-8"]=qt("makeUnorderedList"),$t[Z+"shift-9"]=qt("makeOrderedList"),$t[Z+"["]=qt("decreaseQuoteLevel"),$t[Z+"]"]=qt("increaseQuoteLevel"),$t[Z+"y"]=qt("redo"),$t[Z+"z"]=qt("undo"),$t[Z+"shift-z"]=qt("redo"),Nt._onKey=function(e){var t=e.keyCode,n=Zt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),$t[n]&&$t[n](this,e)},Nt._getHTML=function(){return this._body.innerHTML},Nt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t))},Nt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Nt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Wt(n,!0),zt(n),T(n);for(var o=n;o=h(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},Nt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode; +i!==o&&(n=i.parentNode,r=C(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Nt.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Nt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Nt.bold=Yt("changeFormat",{tag:"B"}),Nt.italic=Yt("changeFormat",{tag:"I"}),Nt.underline=Yt("changeFormat",{tag:"U"}),Nt.strikethrough=Yt("changeFormat",{tag:"S"}),Nt.subscript=Yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Nt.superscript=Yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Nt.removeBold=Yt("changeFormat",null,{tag:"B"}),Nt.removeItalic=Yt("changeFormat",null,{tag:"I"}),Nt.removeUnderline=Yt("changeFormat",null,{tag:"U"}),Nt.removeStrikethrough=Yt("changeFormat",null,{tag:"S"}),Nt.removeSubscript=Yt("changeFormat",null,{tag:"SUB"}),Nt.removeSuperscript=Yt("changeFormat",null,{tag:"SUP"}),Nt.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Nt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Nt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Nt.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()},Nt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Nt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Nt.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()},Nt.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Nt.increaseQuoteLevel=Yt("modifyBlocks",Tt),Nt.decreaseQuoteLevel=Yt("modifyBlocks",Bt),Nt.makeUnorderedList=Yt("modifyBlocks",Rt),Nt.makeOrderedList=Yt("modifyBlocks",xt),Nt.removeList=Yt("modifyBlocks",Lt),Nt.increaseListLevel=Yt("modifyBlocks",Ot),Nt.decreaseListLevel=Yt("modifyBlocks",At),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 755f6ce..8fff94a 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1531,6 +1531,10 @@ proto._onPaste = function ( event ) { endOffset = range.endOffset, startBlock = getStartBlockOfRange( range ); + // Record undo checkpoint + self._recordUndoState( range ); + self._getRangeAndRemoveBookmark( range ); + // We need to position the pasteArea in the visible portion of the screen // to stop the browser auto-scrolling. var pasteArea = this.createElement( 'DIV', { @@ -1834,11 +1838,12 @@ var keyHandlers = { }, backspace: function ( self, event ) { self._removeZWS(); + // Record undo checkpoint. var range = self.getSelection(); + self._recordUndoState( range ); + self._getRangeAndRemoveBookmark( range ); // If not collapsed, delete contents if ( !range.collapsed ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); event.preventDefault(); deleteContentsOfRange( range ); self._ensureBottomLine(); @@ -1847,8 +1852,6 @@ var keyHandlers = { } // If at beginning of block, merge with previous else if ( rangeDoesStartAtBlockBoundary( range ) ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); event.preventDefault(); var current = getStartBlockOfRange( range ), previous = current && getPreviousBlock( current ); @@ -1891,22 +1894,18 @@ var keyHandlers = { // Otherwise, leave to browser but check afterwards whether it has // left behind an empty inline tag. else { - var text = range.startContainer.data || ''; - if ( !notWS.test( text.charAt( range.startOffset - 1 ) ) ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); - self.setSelection( range ); - } + self.setSelection( range ); setTimeout( function () { afterDelete( self ); }, 0 ); } }, 'delete': function ( self, event ) { self._removeZWS(); + // Record undo checkpoint. var range = self.getSelection(); + self._recordUndoState( range ); + self._getRangeAndRemoveBookmark( range ); // If not collapsed, delete contents if ( !range.collapsed ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); event.preventDefault(); deleteContentsOfRange( range ); self._ensureBottomLine(); @@ -1915,8 +1914,6 @@ var keyHandlers = { } // If at end of block, merge next into this block else if ( rangeDoesEndAtBlockBoundary( range ) ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); event.preventDefault(); var current = getStartBlockOfRange( range ), next = current && getNextBlock( current ); @@ -1945,13 +1942,7 @@ var keyHandlers = { // Otherwise, leave to browser but check afterwards whether it has // left behind an empty inline tag. else { - // Record undo point if deleting whitespace - var text = range.startContainer.data || ''; - if ( !notWS.test( text.charAt( range.startOffset ) ) ) { - self._recordUndoState( range ); - self._getRangeAndRemoveBookmark( range ); - self.setSelection( range ); - } + self.setSelection( range ); setTimeout( function () { afterDelete( self ); }, 0 ); } }, @@ -1995,6 +1986,7 @@ var keyHandlers = { self._removeZWS(); } }; + // Firefox incorrectly handles Cmd-left/Cmd-right on Mac: // it goes back/forward in history! Override to do the right // thing. @@ -2049,12 +2041,15 @@ proto._onKey = function ( event ) { key = 'f' + ( code - 111 ); } - if ( event.altKey ) { modifiers += 'alt-'; } - if ( event.ctrlKey ) { modifiers += 'ctrl-'; } - if ( event.metaKey ) { modifiers += 'meta-'; } - if ( event.shiftKey ) { modifiers += 'shift-'; } + // We need to apply the backspace/delete handlers regardless of modifiers. + if ( key !== 'backspace' && key !== 'delete' ) { + if ( event.altKey ) { modifiers += 'alt-'; } + if ( event.ctrlKey ) { modifiers += 'ctrl-'; } + if ( event.metaKey ) { modifiers += 'meta-'; } + if ( event.shiftKey ) { modifiers += 'shift-'; } - key = modifiers + key; + key = modifiers + key; + } if ( keyHandlers[ key ] ) { keyHandlers[ key ]( this, event ); From 6080cbf819be69a516e29b7aa18b2603d424e75f Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 2 Oct 2014 12:06:17 +0700 Subject: [PATCH 10/24] Add Squire#destroy method. Unbinds all event handlers to ensure no memory leaks. --- build/squire-raw.js | 14 ++++++++++++++ build/squire.js | 4 ++-- source/Editor.js | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 4f66f49..c1ab483 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -1326,6 +1326,20 @@ proto.fireEvent = function ( type, event ) { return this; }; +proto.destroy = function () { + var win = this._win, + doc = this._doc, + events = this._events, + type; + win.removeEventListener( 'focus', this, false ); + win.removeEventListener( 'blur', this, false ); + for ( type in events ) { + if ( !customEvents[ type ] ) { + doc.removeEventListener( type, this, false ); + } + } +}; + proto.handleEvent = function ( event ) { this.fireEvent( event.type, event ); }; diff --git a/build/squire.js b/build/squire.js index f6d5fc3..edae4be 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===R&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===R&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,L,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===R?(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 m(e){var t=e.nodeType;return t===R?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===x&&!n.data;)e.removeChild(n),n=e.firstChild;n||(G?(t=r.createTextNode("​"),U.editor&&U.editor._didAddZWS()):t=r.createTextNode(""))}else if(q){for(;e.nodeType!==x&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===x?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function C(e,t,n){var r,o,i,a=e.nodeType;if(a===x&&e!==n)return C(e.parentNode,e.splitText(t),n);if(a===R){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===x?r.appendData(n.data):l.push(N(n));else if(n.nodeType===R){for(o=l.length;o--;)n.appendChild(l.pop());_(n,t)}}function y(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),_(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&T(r),o&&E(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function T(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=B(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=B(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&T(r);return d&&e.appendChild(S(d)),e}function B(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,R=1,x=3,L=1,O=4,A=0,D=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===R;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===R){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(D,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(A,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==x&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==x&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==x&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,O|L,function(e){return e.nodeType===x?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===x){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===x){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=k.prototype;Nt.createElement=function(e,t,n){return B(this._doc,e,t,n)},Nt.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},Nt.didError=function(e){console.log(e)},Nt.getDocument=function(){return this._doc};var St={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Nt.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Nt.handleEvent=function(e){this.fireEvent(e.type,e)},Nt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],St[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Nt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],St[e]||this._doc.removeEventListener(e,this,!1))}return this},Nt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Nt.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Nt.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Nt.getSelectedText=function(){return ot(this.getSelection())},Nt.getPath=function(){return this._path},Nt._didAddZWS=function(){this._hasZWS=!0},Nt._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,O,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Nt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Nt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Nt.focus=function(){return H&&this._body.focus(),this._win.focus(),this},Nt.blur=function(){return H&&this._body.blur(),top.focus(),this};var Ct="squire-selection-start",_t="squire-selection-end";Nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ct,type:"hidden"}),r=this.createElement("INPUT",{id:_t,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=_t,r.id=Ct,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Nt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ct),r=t.getElementById(_t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),_(i,s),i!==a&&_(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},Nt._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Nt._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},Nt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===x)return!1;o=new n(a,O,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Nt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,O,function(e){return lt(r,e,!0)},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==x&&(c=i.nextNode());do f=!u(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),v(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Nt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===x;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return _(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Nt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var yt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Et=function(e,t,n){var r=yt[e.nodeName],o=C(t,n,e.parentNode);return o.nodeName!==r&&(e=B(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};Nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));T(i),v(o,i)}return e},Ot=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},At=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=C(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&C(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),T(e),e},Dt=/\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,It=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,O,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Dt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Pt=/^(?: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)$/,Ut={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return B(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return B(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ft=function(e){return function(t,n){var r=B(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Vt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ft("B"),EM:Ft("I"),STRIKE:Ft("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=B(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=B(c,"SPAN",{"class":"size",style:"font-size:"+Ut[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=B(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=B(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=B(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ht=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===R&&"IMG"!==t.nodeName&&(Ht(t),s(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Vt[i],a===R){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Pt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Wt(o,t)}else{if(a===x){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Mt=function(e){return e.nodeType===R?"BR"===e.nodeName:Y.test(e.data)},Kt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,L|O,Mt),t.currentNode=e,!!t.nextNode()},zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Kt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;C(n.parentNode,n,r.parentNode)}g(n)}else T(r)}};Nt._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Nt._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)},Nt._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),It(e),Wt(e,!1),zt(e),Ht(e);for(var r=e,o=!0;r=h(r);)S(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Zt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Qt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===x&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),S(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(Nt._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var $t={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),It(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=yt[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),T(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(At,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(kt,s)}for(a=Et(n,l,c);a.nodeType===R;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===x&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===x&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===x&&(a=a.parentNode);var p=e._doc,C=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||C.scrollTop)+C.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(y(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(At,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Bt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(y(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Ot,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),It(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&($t["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},$t["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),$t[Z+"b"]=Gt("B"),$t[Z+"i"]=Gt("I"),$t[Z+"u"]=Gt("U"),$t[Z+"shift-7"]=Gt("S"),$t[Z+"shift-5"]=Gt("SUB",{tag:"SUP"}),$t[Z+"shift-6"]=Gt("SUP",{tag:"SUB"}),$t[Z+"shift-8"]=qt("makeUnorderedList"),$t[Z+"shift-9"]=qt("makeOrderedList"),$t[Z+"["]=qt("decreaseQuoteLevel"),$t[Z+"]"]=qt("increaseQuoteLevel"),$t[Z+"y"]=qt("redo"),$t[Z+"z"]=qt("undo"),$t[Z+"shift-z"]=qt("redo"),Nt._onKey=function(e){var t=e.keyCode,n=Zt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),$t[n]&&$t[n](this,e)},Nt._getHTML=function(){return this._body.innerHTML},Nt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t))},Nt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Nt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Wt(n,!0),zt(n),T(n);for(var o=n;o=h(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},Nt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode; -i!==o&&(n=i.parentNode,r=C(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Nt.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Nt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Nt.bold=Yt("changeFormat",{tag:"B"}),Nt.italic=Yt("changeFormat",{tag:"I"}),Nt.underline=Yt("changeFormat",{tag:"U"}),Nt.strikethrough=Yt("changeFormat",{tag:"S"}),Nt.subscript=Yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Nt.superscript=Yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Nt.removeBold=Yt("changeFormat",null,{tag:"B"}),Nt.removeItalic=Yt("changeFormat",null,{tag:"I"}),Nt.removeUnderline=Yt("changeFormat",null,{tag:"U"}),Nt.removeStrikethrough=Yt("changeFormat",null,{tag:"S"}),Nt.removeSubscript=Yt("changeFormat",null,{tag:"SUB"}),Nt.removeSuperscript=Yt("changeFormat",null,{tag:"SUP"}),Nt.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Nt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Nt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Nt.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()},Nt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Nt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Nt.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()},Nt.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Nt.increaseQuoteLevel=Yt("modifyBlocks",Tt),Nt.decreaseQuoteLevel=Yt("modifyBlocks",Bt),Nt.makeUnorderedList=Yt("modifyBlocks",Rt),Nt.makeOrderedList=Yt("modifyBlocks",xt),Nt.removeList=Yt("modifyBlocks",Lt),Nt.increaseListLevel=Yt("modifyBlocks",Ot),Nt.decreaseListLevel=Yt("modifyBlocks",At),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;n||(G?(t=r.createTextNode("​"),U.editor&&U.editor._didAddZWS()):t=r.createTextNode(""))}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function C(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return C(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());_(n,t)}}function y(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),_(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&T(r),o&&E(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function T(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=B(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=B(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&T(r);return d&&e.appendChild(S(d)),e}function B(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,L=1,R=3,x=1,O=4,A=0,D=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(D,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(A,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,O|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=k.prototype;Nt.createElement=function(e,t,n){return B(this._doc,e,t,n)},Nt.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},Nt.didError=function(e){console.log(e)},Nt.getDocument=function(){return this._doc};var St={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Nt.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Nt.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)St[e]||n.removeEventListener(e,this,!1)},Nt.handleEvent=function(e){this.fireEvent(e.type,e)},Nt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],St[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Nt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],St[e]||this._doc.removeEventListener(e,this,!1))}return this},Nt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Nt.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Nt.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Nt.getSelectedText=function(){return ot(this.getSelection())},Nt.getPath=function(){return this._path},Nt._didAddZWS=function(){this._hasZWS=!0},Nt._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,O,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Nt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Nt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Nt.focus=function(){return H&&this._body.focus(),this._win.focus(),this},Nt.blur=function(){return H&&this._body.blur(),top.focus(),this};var Ct="squire-selection-start",_t="squire-selection-end";Nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ct,type:"hidden"}),r=this.createElement("INPUT",{id:_t,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=_t,r.id=Ct,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Nt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ct),r=t.getElementById(_t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),_(i,s),i!==a&&_(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},Nt._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Nt._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},Nt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,O,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Nt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,O,function(e){return lt(r,e,!0)},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==R&&(c=i.nextNode());do f=!u(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),v(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Nt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return _(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Nt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var yt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Et=function(e,t,n){var r=yt[e.nodeName],o=C(t,n,e.parentNode);return o.nodeName!==r&&(e=B(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};Nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));T(i),v(o,i)}return e},Ot=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},At=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=C(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&C(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),T(e),e},Dt=/\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,It=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,O,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Dt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Pt=/^(?: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)$/,Ut={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return B(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return B(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ft=function(e){return function(t,n){var r=B(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Vt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ft("B"),EM:Ft("I"),STRIKE:Ft("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=B(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=B(c,"SPAN",{"class":"size",style:"font-size:"+Ut[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=B(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=B(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=B(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ht=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Ht(t),s(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Vt[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Pt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Wt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Mt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},Kt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|O,Mt),t.currentNode=e,!!t.nextNode()},zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Kt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;C(n.parentNode,n,r.parentNode)}g(n)}else T(r)}};Nt._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Nt._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)},Nt._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),It(e),Wt(e,!1),zt(e),Ht(e);for(var r=e,o=!0;r=h(r);)S(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Zt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Qt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),S(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(Nt._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var $t={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),It(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=yt[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),T(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(At,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(kt,s)}for(a=Et(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,C=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||C.scrollTop)+C.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(y(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(At,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Bt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(y(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Ot,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),It(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&($t["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},$t["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),$t[Z+"b"]=Gt("B"),$t[Z+"i"]=Gt("I"),$t[Z+"u"]=Gt("U"),$t[Z+"shift-7"]=Gt("S"),$t[Z+"shift-5"]=Gt("SUB",{tag:"SUP"}),$t[Z+"shift-6"]=Gt("SUP",{tag:"SUB"}),$t[Z+"shift-8"]=qt("makeUnorderedList"),$t[Z+"shift-9"]=qt("makeOrderedList"),$t[Z+"["]=qt("decreaseQuoteLevel"),$t[Z+"]"]=qt("increaseQuoteLevel"),$t[Z+"y"]=qt("redo"),$t[Z+"z"]=qt("undo"),$t[Z+"shift-z"]=qt("redo"),Nt._onKey=function(e){var t=e.keyCode,n=Zt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),$t[n]&&$t[n](this,e)},Nt._getHTML=function(){return this._body.innerHTML},Nt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t))},Nt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Nt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Wt(n,!0),zt(n),T(n);for(var o=n;o=h(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this +},Nt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=C(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Nt.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Nt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Nt.bold=Yt("changeFormat",{tag:"B"}),Nt.italic=Yt("changeFormat",{tag:"I"}),Nt.underline=Yt("changeFormat",{tag:"U"}),Nt.strikethrough=Yt("changeFormat",{tag:"S"}),Nt.subscript=Yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Nt.superscript=Yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Nt.removeBold=Yt("changeFormat",null,{tag:"B"}),Nt.removeItalic=Yt("changeFormat",null,{tag:"I"}),Nt.removeUnderline=Yt("changeFormat",null,{tag:"U"}),Nt.removeStrikethrough=Yt("changeFormat",null,{tag:"S"}),Nt.removeSubscript=Yt("changeFormat",null,{tag:"SUB"}),Nt.removeSuperscript=Yt("changeFormat",null,{tag:"SUP"}),Nt.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Nt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Nt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Nt.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()},Nt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Nt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Nt.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()},Nt.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Nt.increaseQuoteLevel=Yt("modifyBlocks",Tt),Nt.decreaseQuoteLevel=Yt("modifyBlocks",Bt),Nt.makeUnorderedList=Yt("modifyBlocks",Lt),Nt.makeOrderedList=Yt("modifyBlocks",Rt),Nt.removeList=Yt("modifyBlocks",xt),Nt.increaseListLevel=Yt("modifyBlocks",Ot),Nt.decreaseListLevel=Yt("modifyBlocks",At),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 8fff94a..5c98f4e 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -209,6 +209,20 @@ proto.fireEvent = function ( type, event ) { return this; }; +proto.destroy = function () { + var win = this._win, + doc = this._doc, + events = this._events, + type; + win.removeEventListener( 'focus', this, false ); + win.removeEventListener( 'blur', this, false ); + for ( type in events ) { + if ( !customEvents[ type ] ) { + doc.removeEventListener( type, this, false ); + } + } +}; + proto.handleEvent = function ( event ) { this.fireEvent( event.type, event ); }; From a408fcaca6e606efc61a6f04bd09fd198399b445 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 2 Oct 2014 16:00:35 +0700 Subject: [PATCH 11/24] Fix range construction in addFormat method. --- build/squire-raw.js | 58 ++++++++++++++++++++++++--------------------- build/squire.js | 4 ++-- source/Editor.js | 58 ++++++++++++++++++++++++--------------------- 3 files changed, 64 insertions(+), 56 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index c1ab483..54d5f24 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -1745,7 +1745,7 @@ proto._addFormat = function ( tag, attributes, range ) { // If the range is collapsed we simply insert the node by wrapping // it round the range and focus it. var el, walker, startContainer, endContainer, startOffset, endOffset, - textnode, needsFormat; + textNode, needsFormat; if ( range.collapsed ) { el = fixCursor( this.createElement( tag, attributes ) ); @@ -1773,39 +1773,43 @@ proto._addFormat = function ( tag, attributes, range ) { // Start at the beginning node of the range and iterate through // all the nodes in the range that need formatting. - startOffset = 0; - endOffset = 0; - textnode = walker.currentNode = range.startContainer; + startContainer = range.startContainer; + startOffset = range.startOffset; + endContainer = range.endContainer; + endOffset = range.endOffset; - if ( textnode.nodeType !== TEXT_NODE ) { - textnode = walker.nextNode(); + // Make sure we start inside a text node. + walker.currentNode = startContainer; + if ( startContainer.nodeType !== TEXT_NODE ) { + startContainer = walker.nextNode(); + startOffset = 0; } do { - needsFormat = !getNearest( textnode, tag, attributes ); - if ( textnode === range.endContainer ) { - if ( needsFormat && textnode.length > range.endOffset ) { - textnode.splitText( range.endOffset ); - } else { - endOffset = range.endOffset; - } - } - if ( textnode === range.startContainer ) { - if ( needsFormat && range.startOffset ) { - textnode = textnode.splitText( range.startOffset ); - } else { - startOffset = range.startOffset; - } - } + textNode = walker.currentNode; + needsFormat = !getNearest( textNode, tag, attributes ); if ( needsFormat ) { + if ( textNode === endContainer && + textNode.length > endOffset ) { + textNode.splitText( endOffset ); + } + if ( textNode === startContainer && startOffset ) { + textNode = textNode.splitText( startOffset ); + startContainer = textNode; + startOffset = 0; + } el = this.createElement( tag, attributes ); - replaceWith( textnode, el ); - el.appendChild( textnode ); - endOffset = textnode.length; + replaceWith( textNode, el ); + el.appendChild( textNode ); } - endContainer = textnode; - if ( !startContainer ) { startContainer = endContainer; } - } while ( textnode = walker.nextNode() ); + } while ( walker.nextNode() ); + + // Make sure we finish inside a text node. Otherwise offset may have + // changed. + if ( endContainer.nodeType !== TEXT_NODE ) { + endContainer = textNode; + endOffset = textNode.length; + } // Now set the selection to as it was before range = this._createRange( diff --git a/build/squire.js b/build/squire.js index edae4be..e37e1d1 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;n||(G?(t=r.createTextNode("​"),U.editor&&U.editor._didAddZWS()):t=r.createTextNode(""))}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function C(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return C(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());_(n,t)}}function y(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),_(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&T(r),o&&E(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function T(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=B(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=B(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&T(r);return d&&e.appendChild(S(d)),e}function B(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,L=1,R=3,x=1,O=4,A=0,D=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(D,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(A,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,O|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=k.prototype;Nt.createElement=function(e,t,n){return B(this._doc,e,t,n)},Nt.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},Nt.didError=function(e){console.log(e)},Nt.getDocument=function(){return this._doc};var St={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Nt.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Nt.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)St[e]||n.removeEventListener(e,this,!1)},Nt.handleEvent=function(e){this.fireEvent(e.type,e)},Nt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],St[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Nt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],St[e]||this._doc.removeEventListener(e,this,!1))}return this},Nt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Nt.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Nt.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Nt.getSelectedText=function(){return ot(this.getSelection())},Nt.getPath=function(){return this._path},Nt._didAddZWS=function(){this._hasZWS=!0},Nt._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,O,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Nt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Nt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Nt.focus=function(){return H&&this._body.focus(),this._win.focus(),this},Nt.blur=function(){return H&&this._body.blur(),top.focus(),this};var Ct="squire-selection-start",_t="squire-selection-end";Nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ct,type:"hidden"}),r=this.createElement("INPUT",{id:_t,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=_t,r.id=Ct,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Nt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ct),r=t.getElementById(_t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),_(i,s),i!==a&&_(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},Nt._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Nt._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},Nt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,O,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Nt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,O,function(e){return lt(r,e,!0)},!1),d=0,l=0,c=i.currentNode=r.startContainer,c.nodeType!==R&&(c=i.nextNode());do f=!u(c,e,t),c===r.endContainer&&(f&&c.length>r.endOffset?c.splitText(r.endOffset):l=r.endOffset),c===r.startContainer&&(f&&r.startOffset?c=c.splitText(r.startOffset):d=r.startOffset),f&&(o=this.createElement(e,t),v(c,o),o.appendChild(c),l=c.length),s=c,a||(a=s);while(c=i.nextNode());r=this._createRange(a,d,s,l)}return r},Nt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return _(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Nt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var yt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Et=function(e,t,n){var r=yt[e.nodeName],o=C(t,n,e.parentNode);return o.nodeName!==r&&(e=B(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};Nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));T(i),v(o,i)}return e},Ot=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},At=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=C(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&C(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),T(e),e},Dt=/\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,It=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,O,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Dt.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Pt=/^(?: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)$/,Ut={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return B(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return B(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ft=function(e){return function(t,n){var r=B(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Vt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ft("B"),EM:Ft("I"),STRIKE:Ft("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=B(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=B(c,"SPAN",{"class":"size",style:"font-size:"+Ut[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=B(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=B(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=B(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ht=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Ht(t),s(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Vt[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Pt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Wt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Mt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},Kt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|O,Mt),t.currentNode=e,!!t.nextNode()},zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Kt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;C(n.parentNode,n,r.parentNode)}g(n)}else T(r)}};Nt._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Nt._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)},Nt._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),It(e),Wt(e,!1),zt(e),Ht(e);for(var r=e,o=!0;r=h(r);)S(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Zt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Qt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),S(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(Nt._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var $t={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),It(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=yt[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),T(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(At,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(kt,s)}for(a=Et(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,C=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||C.scrollTop)+C.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(y(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(At,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Bt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(y(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Ot,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),It(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&($t["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},$t["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),$t[Z+"b"]=Gt("B"),$t[Z+"i"]=Gt("I"),$t[Z+"u"]=Gt("U"),$t[Z+"shift-7"]=Gt("S"),$t[Z+"shift-5"]=Gt("SUB",{tag:"SUP"}),$t[Z+"shift-6"]=Gt("SUP",{tag:"SUB"}),$t[Z+"shift-8"]=qt("makeUnorderedList"),$t[Z+"shift-9"]=qt("makeOrderedList"),$t[Z+"["]=qt("decreaseQuoteLevel"),$t[Z+"]"]=qt("increaseQuoteLevel"),$t[Z+"y"]=qt("redo"),$t[Z+"z"]=qt("undo"),$t[Z+"shift-z"]=qt("redo"),Nt._onKey=function(e){var t=e.keyCode,n=Zt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),$t[n]&&$t[n](this,e)},Nt._getHTML=function(){return this._body.innerHTML},Nt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t))},Nt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Nt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Wt(n,!0),zt(n),T(n);for(var o=n;o=h(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this -},Nt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=C(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Nt.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Nt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Nt.bold=Yt("changeFormat",{tag:"B"}),Nt.italic=Yt("changeFormat",{tag:"I"}),Nt.underline=Yt("changeFormat",{tag:"U"}),Nt.strikethrough=Yt("changeFormat",{tag:"S"}),Nt.subscript=Yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Nt.superscript=Yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Nt.removeBold=Yt("changeFormat",null,{tag:"B"}),Nt.removeItalic=Yt("changeFormat",null,{tag:"I"}),Nt.removeUnderline=Yt("changeFormat",null,{tag:"U"}),Nt.removeStrikethrough=Yt("changeFormat",null,{tag:"S"}),Nt.removeSubscript=Yt("changeFormat",null,{tag:"SUB"}),Nt.removeSuperscript=Yt("changeFormat",null,{tag:"SUP"}),Nt.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Nt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Nt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Nt.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()},Nt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Nt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Nt.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()},Nt.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Nt.increaseQuoteLevel=Yt("modifyBlocks",Tt),Nt.decreaseQuoteLevel=Yt("modifyBlocks",Bt),Nt.makeUnorderedList=Yt("modifyBlocks",Lt),Nt.makeOrderedList=Yt("modifyBlocks",Rt),Nt.removeList=Yt("modifyBlocks",xt),Nt.increaseListLevel=Yt("modifyBlocks",Ot),Nt.decreaseListLevel=Yt("modifyBlocks",At),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;n||(G?(t=r.createTextNode("​"),U.editor&&U.editor._didAddZWS()):t=r.createTextNode(""))}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function C(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return C(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());_(n,t)}}function y(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),_(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&T(r),o&&E(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function T(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=B(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=B(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&T(r);return d&&e.appendChild(S(d)),e}function B(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=k.prototype;Nt.createElement=function(e,t,n){return B(this._doc,e,t,n)},Nt.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},Nt.didError=function(e){console.log(e)},Nt.getDocument=function(){return this._doc};var St={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Nt.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Nt.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)St[e]||n.removeEventListener(e,this,!1)},Nt.handleEvent=function(e){this.fireEvent(e.type,e)},Nt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],St[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Nt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],St[e]||this._doc.removeEventListener(e,this,!1))}return this},Nt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Nt.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Nt.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Nt.getSelectedText=function(){return ot(this.getSelection())},Nt.getPath=function(){return this._path},Nt._didAddZWS=function(){this._hasZWS=!0},Nt._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Nt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Nt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Nt.focus=function(){return H&&this._body.focus(),this._win.focus(),this},Nt.blur=function(){return H&&this._body.blur(),top.focus(),this};var Ct="squire-selection-start",_t="squire-selection-end";Nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ct,type:"hidden"}),r=this.createElement("INPUT",{id:_t,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=_t,r.id=Ct,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Nt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ct),r=t.getElementById(_t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),_(i,s),i!==a&&_(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},Nt._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Nt._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},Nt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Nt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),a=c,d=0),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},Nt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return _(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Nt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var yt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Et=function(e,t,n){var r=yt[e.nodeName],o=C(t,n,e.parentNode);return o.nodeName!==r&&(e=B(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};Nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));T(i),v(o,i)}return e},At=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Dt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=C(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&C(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),T(e),e},Ot=/\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,It=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Ot.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Pt=/^(?: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)$/,Ut={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return B(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return B(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ft=function(e){return function(t,n){var r=B(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Vt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ft("B"),EM:Ft("I"),STRIKE:Ft("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=B(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=B(c,"SPAN",{"class":"size",style:"font-size:"+Ut[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=B(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=B(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=B(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ht=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Ht(t),s(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Vt[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Pt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Wt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Mt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},Kt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Mt),t.currentNode=e,!!t.nextNode()},zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Kt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;C(n.parentNode,n,r.parentNode)}g(n)}else T(r)}};Nt._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Nt._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)},Nt._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),It(e),Wt(e,!1),zt(e),Ht(e);for(var r=e,o=!0;r=h(r);)S(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Zt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Qt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),S(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(Nt._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var $t={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),It(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=yt[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),T(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Dt,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(kt,s)}for(a=Et(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,C=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||C.scrollTop)+C.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(y(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Dt,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Bt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(y(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(At,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),It(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&($t["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},$t["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),$t[Z+"b"]=Gt("B"),$t[Z+"i"]=Gt("I"),$t[Z+"u"]=Gt("U"),$t[Z+"shift-7"]=Gt("S"),$t[Z+"shift-5"]=Gt("SUB",{tag:"SUP"}),$t[Z+"shift-6"]=Gt("SUP",{tag:"SUB"}),$t[Z+"shift-8"]=qt("makeUnorderedList"),$t[Z+"shift-9"]=qt("makeOrderedList"),$t[Z+"["]=qt("decreaseQuoteLevel"),$t[Z+"]"]=qt("increaseQuoteLevel"),$t[Z+"y"]=qt("redo"),$t[Z+"z"]=qt("undo"),$t[Z+"shift-z"]=qt("redo"),Nt._onKey=function(e){var t=e.keyCode,n=Zt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),$t[n]&&$t[n](this,e)},Nt._getHTML=function(){return this._body.innerHTML},Nt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t))},Nt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Nt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Wt(n,!0),zt(n),T(n);for(var o=n;o=h(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},Nt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e); +else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=C(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Nt.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Nt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Nt.bold=Yt("changeFormat",{tag:"B"}),Nt.italic=Yt("changeFormat",{tag:"I"}),Nt.underline=Yt("changeFormat",{tag:"U"}),Nt.strikethrough=Yt("changeFormat",{tag:"S"}),Nt.subscript=Yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Nt.superscript=Yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Nt.removeBold=Yt("changeFormat",null,{tag:"B"}),Nt.removeItalic=Yt("changeFormat",null,{tag:"I"}),Nt.removeUnderline=Yt("changeFormat",null,{tag:"U"}),Nt.removeStrikethrough=Yt("changeFormat",null,{tag:"S"}),Nt.removeSubscript=Yt("changeFormat",null,{tag:"SUB"}),Nt.removeSuperscript=Yt("changeFormat",null,{tag:"SUP"}),Nt.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Nt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Nt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Nt.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()},Nt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Nt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Nt.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()},Nt.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Nt.increaseQuoteLevel=Yt("modifyBlocks",Tt),Nt.decreaseQuoteLevel=Yt("modifyBlocks",Bt),Nt.makeUnorderedList=Yt("modifyBlocks",Lt),Nt.makeOrderedList=Yt("modifyBlocks",Rt),Nt.removeList=Yt("modifyBlocks",xt),Nt.increaseListLevel=Yt("modifyBlocks",At),Nt.decreaseListLevel=Yt("modifyBlocks",Dt),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 5c98f4e..93a4883 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -628,7 +628,7 @@ proto._addFormat = function ( tag, attributes, range ) { // If the range is collapsed we simply insert the node by wrapping // it round the range and focus it. var el, walker, startContainer, endContainer, startOffset, endOffset, - textnode, needsFormat; + textNode, needsFormat; if ( range.collapsed ) { el = fixCursor( this.createElement( tag, attributes ) ); @@ -656,39 +656,43 @@ proto._addFormat = function ( tag, attributes, range ) { // Start at the beginning node of the range and iterate through // all the nodes in the range that need formatting. - startOffset = 0; - endOffset = 0; - textnode = walker.currentNode = range.startContainer; + startContainer = range.startContainer; + startOffset = range.startOffset; + endContainer = range.endContainer; + endOffset = range.endOffset; - if ( textnode.nodeType !== TEXT_NODE ) { - textnode = walker.nextNode(); + // Make sure we start inside a text node. + walker.currentNode = startContainer; + if ( startContainer.nodeType !== TEXT_NODE ) { + startContainer = walker.nextNode(); + startOffset = 0; } do { - needsFormat = !getNearest( textnode, tag, attributes ); - if ( textnode === range.endContainer ) { - if ( needsFormat && textnode.length > range.endOffset ) { - textnode.splitText( range.endOffset ); - } else { - endOffset = range.endOffset; - } - } - if ( textnode === range.startContainer ) { - if ( needsFormat && range.startOffset ) { - textnode = textnode.splitText( range.startOffset ); - } else { - startOffset = range.startOffset; - } - } + textNode = walker.currentNode; + needsFormat = !getNearest( textNode, tag, attributes ); if ( needsFormat ) { + if ( textNode === endContainer && + textNode.length > endOffset ) { + textNode.splitText( endOffset ); + } + if ( textNode === startContainer && startOffset ) { + textNode = textNode.splitText( startOffset ); + startContainer = textNode; + startOffset = 0; + } el = this.createElement( tag, attributes ); - replaceWith( textnode, el ); - el.appendChild( textnode ); - endOffset = textnode.length; + replaceWith( textNode, el ); + el.appendChild( textNode ); } - endContainer = textnode; - if ( !startContainer ) { startContainer = endContainer; } - } while ( textnode = walker.nextNode() ); + } while ( walker.nextNode() ); + + // Make sure we finish inside a text node. Otherwise offset may have + // changed. + if ( endContainer.nodeType !== TEXT_NODE ) { + endContainer = textNode; + endOffset = textNode.length; + } // Now set the selection to as it was before range = this._createRange( From e7cef4981890a11157bd01de6eea3c1bc0b7900d Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 2 Oct 2014 16:22:51 +0700 Subject: [PATCH 12/24] Rename isOpera -> isPresto. Opera now uses WebKit, but these tweaks are only for the Presto version. --- build/squire-raw.js | 12 ++++++------ source/Constants.js | 4 ++-- source/Editor.js | 6 +++--- source/Node.js | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 54d5f24..73ef973 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -27,12 +27,12 @@ var isMac = /Mac OS X/.test( ua ); var isGecko = /Gecko\//.test( ua ); var isIE8or9or10 = /Trident\/[456]\./.test( ua ); var isIE8 = ( win.ie === 8 ); -var isOpera = !!win.opera; +var isPresto = !!win.opera; var isWebKit = /WebKit\//.test( ua ); var ctrlKey = isMac ? 'meta-' : 'ctrl-'; -var useTextFixer = isIE8or9or10 || isOpera; +var useTextFixer = isIE8or9or10 || isPresto; var cantFocusEmptyTextNodes = isIE8or9or10 || isWebKit; var losesSelectionOnBlur = isIE8or9or10; var hasBuggySplit = ( function () { @@ -497,7 +497,7 @@ function mergeWithBlock ( block, next, range ) { // Steps to reproduce bug: Type "a-b-c" (where - is return) // then backspace twice. The cursor goes to the top instead // of after "b". - if ( isOpera && ( last = block.lastChild ) && last.nodeName === 'BR' ) { + if ( isPresto && ( last = block.lastChild ) && last.nodeName === 'BR' ) { block.removeChild( last ); } } @@ -1230,7 +1230,7 @@ function Squire ( doc ) { this.addEventListener( 'keyup', this._ieSelAllClean ); } // Opera does not fire keydown repeatedly. - this.addEventListener( isOpera ? 'keypress' : 'keydown', this._onKey ); + this.addEventListener( isPresto ? 'keypress' : 'keydown', this._onKey ); // Fix IE8/9's buggy implementation of Text#splitText. // If the split is at the end of the node, it doesn't insert the newly split @@ -2947,7 +2947,7 @@ var keyHandlers = { // If you try to select the contents of a 'BR', FF will not let // you type anything! if ( !child || child.nodeName === 'BR' || - ( child.nodeType === TEXT_NODE && !isOpera ) ) { + ( child.nodeType === TEXT_NODE && !isPresto ) ) { break; } nodeAfterSplit = child; @@ -3167,7 +3167,7 @@ proto._onKey = function ( event ) { // On keypress, delete and '.' both have event.keyCode 46 // Must check event.which to differentiate. - if ( isOpera && event.which === 46 ) { + if ( isPresto && event.which === 46 ) { key = '.'; } diff --git a/source/Constants.js b/source/Constants.js index 0a3ff5a..8e156db 100644 --- a/source/Constants.js +++ b/source/Constants.js @@ -22,12 +22,12 @@ var isMac = /Mac OS X/.test( ua ); var isGecko = /Gecko\//.test( ua ); var isIE8or9or10 = /Trident\/[456]\./.test( ua ); var isIE8 = ( win.ie === 8 ); -var isOpera = !!win.opera; +var isPresto = !!win.opera; var isWebKit = /WebKit\//.test( ua ); var ctrlKey = isMac ? 'meta-' : 'ctrl-'; -var useTextFixer = isIE8or9or10 || isOpera; +var useTextFixer = isIE8or9or10 || isPresto; var cantFocusEmptyTextNodes = isIE8or9or10 || isWebKit; var losesSelectionOnBlur = isIE8or9or10; var hasBuggySplit = ( function () { diff --git a/source/Editor.js b/source/Editor.js index 93a4883..29b8234 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -113,7 +113,7 @@ function Squire ( doc ) { this.addEventListener( 'keyup', this._ieSelAllClean ); } // Opera does not fire keydown repeatedly. - this.addEventListener( isOpera ? 'keypress' : 'keydown', this._onKey ); + this.addEventListener( isPresto ? 'keypress' : 'keydown', this._onKey ); // Fix IE8/9's buggy implementation of Text#splitText. // If the split is at the end of the node, it doesn't insert the newly split @@ -1830,7 +1830,7 @@ var keyHandlers = { // If you try to select the contents of a 'BR', FF will not let // you type anything! if ( !child || child.nodeName === 'BR' || - ( child.nodeType === TEXT_NODE && !isOpera ) ) { + ( child.nodeType === TEXT_NODE && !isPresto ) ) { break; } nodeAfterSplit = child; @@ -2050,7 +2050,7 @@ proto._onKey = function ( event ) { // On keypress, delete and '.' both have event.keyCode 46 // Must check event.which to differentiate. - if ( isOpera && event.which === 46 ) { + if ( isPresto && event.which === 46 ) { key = '.'; } diff --git a/source/Node.js b/source/Node.js index c037a28..f58cae3 100644 --- a/source/Node.js +++ b/source/Node.js @@ -358,7 +358,7 @@ function mergeWithBlock ( block, next, range ) { // Steps to reproduce bug: Type "a-b-c" (where - is return) // then backspace twice. The cursor goes to the top instead // of after "b". - if ( isOpera && ( last = block.lastChild ) && last.nodeName === 'BR' ) { + if ( isPresto && ( last = block.lastChild ) && last.nodeName === 'BR' ) { block.removeChild( last ); } } From b944eb3b3b8b29625d01559dc09922ac1be310fa Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 2 Oct 2014 16:36:39 +0700 Subject: [PATCH 13/24] Fix ZWS removal when Squire script not in iframe. --- build/squire-raw.js | 255 +++++++++++++++----------------------------- build/squire.js | 4 +- source/Constants.js | 7 +- source/Editor.js | 76 ++----------- source/Node.js | 145 ++++++++++++------------- source/Range.js | 26 +---- source/outro.js | 1 - 7 files changed, 170 insertions(+), 344 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 73ef973..703a3be 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -3,8 +3,7 @@ ( function ( doc, undefined ) { "use strict"; -/*global doc, navigator */ -/*jshint strict:false */ +/*jshint strict:false, undef:false, unused:false */ var DOCUMENT_POSITION_PRECEDING = 2; // Node.DOCUMENT_POSITION_PRECEDING var ELEMENT_NODE = 1; // Node.ELEMENT_NODE; @@ -35,13 +34,13 @@ var ctrlKey = isMac ? 'meta-' : 'ctrl-'; var useTextFixer = isIE8or9or10 || isPresto; var cantFocusEmptyTextNodes = isIE8or9or10 || isWebKit; var losesSelectionOnBlur = isIE8or9or10; -var hasBuggySplit = ( function () { +var hasBuggySplit = function ( doc ) { var div = doc.createElement( 'DIV' ), text = doc.createTextNode( '12' ); div.appendChild( text ); text.splitText( 2 ); return div.childNodes.length !== 2; -}() ); +}; // Use [^ \t\r\n] instead of \S so that nbsp does not count as white-space var notWS = /[^ \t\r\n]/; @@ -137,20 +136,7 @@ TreeWalker.prototype.previousNode = function () { current = node; } }; -/*global - ELEMENT_NODE, - TEXT_NODE, - SHOW_ELEMENT, - win, - isOpera, - useTextFixer, - cantFocusEmptyTextNodes, - - TreeWalker, - - Text -*/ -/*jshint strict:false */ +/*jshint strict:false, undef:false, unused:false */ var inlineNodeNames = /^(?:#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)$/; @@ -282,6 +268,29 @@ function empty ( node ) { return frag; } +function createElement ( doc, tag, props, children ) { + var el = doc.createElement( tag ), + attr, value, i, l; + if ( props instanceof Array ) { + children = props; + props = null; + } + if ( props ) { + for ( attr in props ) { + value = props[ attr ]; + if ( value !== undefined ) { + el.setAttribute( attr, props[ attr ] ); + } + } + } + if ( children ) { + for ( i = 0, l = children.length; i < l; i += 1 ) { + el.appendChild( children[i] ); + } + } + return el; +} + function fixCursor ( node ) { // In Webkit and Gecko, block level elements are collapsed and // unfocussable if they have no content. To remedy this, a
    must be @@ -289,7 +298,8 @@ function fixCursor ( node ) { // cursor to appear. var doc = node.ownerDocument, root = node, - fixer, child; + fixer, child, + l, instance; if ( node.nodeName === 'BODY' ) { if ( !( child = node.firstChild ) || child.nodeName === 'BR' ) { @@ -315,8 +325,13 @@ function fixCursor ( node ) { if ( !child ) { if ( cantFocusEmptyTextNodes ) { fixer = doc.createTextNode( '\u200B' ); - if ( win.editor ) { - win.editor._didAddZWS(); + // Find the relevant Squire instance and notify + l = instances.length; + while ( l-- ) { + instance = instances[l]; + if ( instance._doc === doc ) { + instance._didAddZWS(); + } } } else { fixer = doc.createTextNode( '' ); @@ -356,6 +371,42 @@ function fixCursor ( node ) { return root; } +// Recursively examine container nodes and wrap any inline children. +function fixContainer ( container ) { + var children = container.childNodes, + doc = container.ownerDocument, + wrapper = null, + i, l, child, isBR; + for ( i = 0, l = children.length; i < l; i += 1 ) { + child = children[i]; + isBR = child.nodeName === 'BR'; + if ( !isBR && isInline( child ) ) { + if ( !wrapper ) { wrapper = createElement( doc, 'DIV' ); } + wrapper.appendChild( child ); + i -= 1; + l -= 1; + } else if ( isBR || wrapper ) { + if ( !wrapper ) { wrapper = createElement( doc, 'DIV' ); } + fixCursor( wrapper ); + if ( isBR ) { + container.replaceChild( wrapper, child ); + } else { + container.insertBefore( wrapper, child ); + i += 1; + l += 1; + } + wrapper = null; + } + if ( isContainer( child ) ) { + fixContainer( child ); + } + } + if ( wrapper ) { + container.appendChild( fixCursor( wrapper ) ); + } + return container; +} + function split ( node, offset, stopNode ) { var nodeType = node.nodeType, parent, clone, next; @@ -539,90 +590,7 @@ function mergeContainers ( node ) { fixCursor( prev ); } } - -// Recursively examine container nodes and wrap any inline children. -function fixContainer ( container ) { - var children = container.childNodes, - doc = container.ownerDocument, - wrapper = null, - i, l, child, isBR; - for ( i = 0, l = children.length; i < l; i += 1 ) { - child = children[i]; - isBR = child.nodeName === 'BR'; - if ( !isBR && isInline( child ) ) { - if ( !wrapper ) { wrapper = createElement( doc, 'DIV' ); } - wrapper.appendChild( child ); - i -= 1; - l -= 1; - } else if ( isBR || wrapper ) { - if ( !wrapper ) { wrapper = createElement( doc, 'DIV' ); } - fixCursor( wrapper ); - if ( isBR ) { - container.replaceChild( wrapper, child ); - } else { - container.insertBefore( wrapper, child ); - i += 1; - l += 1; - } - wrapper = null; - } - if ( isContainer( child ) ) { - fixContainer( child ); - } - } - if ( wrapper ) { - container.appendChild( fixCursor( wrapper ) ); - } - return container; -} - -function createElement ( doc, tag, props, children ) { - var el = doc.createElement( tag ), - attr, value, i, l; - if ( props instanceof Array ) { - children = props; - props = null; - } - if ( props ) { - for ( attr in props ) { - value = props[ attr ]; - if ( value !== undefined ) { - el.setAttribute( attr, props[ attr ] ); - } - } - } - if ( children ) { - for ( i = 0, l = children.length; i < l; i += 1 ) { - el.appendChild( children[i] ); - } - } - return el; -} -/*global - ELEMENT_NODE, - TEXT_NODE, - SHOW_TEXT, - START_TO_START, - START_TO_END, - END_TO_END, - END_TO_START, - notWS, - indexOf, - - TreeWalker, - - isLeaf, - isInline, - isBlock, - getPreviousBlock, - getNextBlock, - getLength, - fixCursor, - split, - mergeWithBlock, - mergeContainers -*/ -/*jshint strict:false */ +/*jshint strict:false, undef:false, unused:false */ var getNodeBefore = function ( node, offset ) { var children = node.childNodes; @@ -1115,71 +1083,9 @@ var expandRangeToBlockBoundaries = function ( range ) { range.setEnd( parent, indexOf.call( parent.childNodes, end ) + 1 ); } }; -/*global - DOCUMENT_POSITION_PRECEDING, - ELEMENT_NODE, - TEXT_NODE, - SHOW_ELEMENT, - SHOW_TEXT, - win, - isIOS, - isMac, - isGecko, - isIE8or9or10, - isIE8, - isOpera, - ctrlKey, - useTextFixer, - cantFocusEmptyTextNodes, - losesSelectionOnBlur, - hasBuggySplit, - notWS, - indexOf, +/*jshint strict:false, undef:false, unused:false */ - TreeWalker, - - hasTagAttributes, - isLeaf, - isInline, - isBlock, - isContainer, - getBlockWalker, - getPreviousBlock, - getNextBlock, - getNearest, - getPath, - getLength, - detach, - replaceWith, - empty, - fixCursor, - split, - mergeInlines, - mergeWithBlock, - mergeContainers, - fixContainer, - createElement, - - forEachTextNodeInRange, - getTextContentInRange, - insertNodeInRange, - extractContentsOfRange, - deleteContentsOfRange, - insertTreeFragmentIntoRange, - isNodeContainedInRange, - moveRangeBoundariesDownTree, - moveRangeBoundariesUpTree, - getStartBlockOfRange, - getEndBlockOfRange, - rangeDoesStartAtBlockBoundary, - rangeDoesEndAtBlockBoundary, - expandRangeToBlockBoundaries, - - top, - console, - setTimeout -*/ -/*jshint strict:false */ +var instances = []; function Squire ( doc ) { var win = doc.defaultView; @@ -1238,7 +1144,7 @@ function Squire ( doc ) { // And even if the split is not at the end, the original node is removed // from the document and replaced by another, rather than just having its // data shortened. - if ( hasBuggySplit ) { + if ( hasBuggySplit( doc ) ) { win.Text.prototype.splitText = function ( offset ) { var afterSplit = this.ownerDocument.createTextNode( this.data.slice( offset ) ), @@ -1265,6 +1171,8 @@ function Squire ( doc ) { doc.execCommand( 'enableObjectResizing', false, 'false' ); doc.execCommand( 'enableInlineTableEditing', false, 'false' ); } catch ( error ) {} + + instances.push( this ); } var proto = Squire.prototype; @@ -1338,6 +1246,12 @@ proto.destroy = function () { doc.removeEventListener( type, this, false ); } } + var l = instances.length; + while ( l-- ) { + if ( instances[l] === this ) { + instances.splice( l, 1 ); + } + } }; proto.handleEvent = function ( event ) { @@ -3501,7 +3415,6 @@ proto.removeList = command( 'modifyBlocks', removeList ); proto.increaseListLevel = command( 'modifyBlocks', increaseListLevel ); proto.decreaseListLevel = command( 'modifyBlocks', decreaseListLevel ); -/*global top, win, doc, Squire */ if ( top !== win ) { win.editor = new Squire( doc ); diff --git a/build/squire.js b/build/squire.js index e37e1d1..a751e46 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(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)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;n||(G?(t=r.createTextNode("​"),U.editor&&U.editor._didAddZWS()):t=r.createTextNode(""))}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=r.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function C(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return C(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());_(n,t)}}function y(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),_(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function E(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&T(r),o&&E(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),S(r))}function T(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=B(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=B(a,"DIV")),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&T(r);return d&&e.appendChild(S(d)),e}function B(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length}(),Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=k.prototype;Nt.createElement=function(e,t,n){return B(this._doc,e,t,n)},Nt.createDefaultBlock=function(e){return S(this.createElement("DIV",this.defaultBlockProperties,e))},Nt.didError=function(e){console.log(e)},Nt.getDocument=function(){return this._doc};var St={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};Nt.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},Nt.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)St[e]||n.removeEventListener(e,this,!1)},Nt.handleEvent=function(e){this.fireEvent(e.type,e)},Nt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],St[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Nt.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],St[e]||this._doc.removeEventListener(e,this,!1))}return this},Nt._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},Nt.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},Nt.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},Nt.getSelectedText=function(){return ot(this.getSelection())},Nt.getPath=function(){return this._path},Nt._didAddZWS=function(){this._hasZWS=!0},Nt._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},Nt._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},Nt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Nt.focus=function(){return H&&this._body.focus(),this._win.focus(),this},Nt.blur=function(){return H&&this._body.blur(),top.focus(),this};var Ct="squire-selection-start",_t="squire-selection-end";Nt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ct,type:"hidden"}),r=this.createElement("INPUT",{id:_t,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=_t,r.id=Ct,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Nt._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ct),r=t.getElementById(_t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),_(i,s),i!==a&&_(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},Nt._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},Nt._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},Nt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},Nt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),a=c,d=0),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},Nt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return _(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},Nt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var yt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Et=function(e,t,n){var r=yt[e.nodeName],o=C(t,n,e.parentNode);return o.nodeName!==r&&(e=B(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};Nt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},Nt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));T(i),v(o,i)}return e},At=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Dt=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=C(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&C(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),T(e),e},Ot=/\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,It=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=Ot.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Pt=/^(?: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)$/,Ut={1:10,2:13,3:16,4:18,5:24,6:32,7:48},wt={backgroundColor:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return B(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return B(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return B(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Ft=function(e){return function(t,n){var r=B(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Vt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in wt)r=wt[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Ft("B"),EM:Ft("I"),STRIKE:Ft("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=B(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=B(c,"SPAN",{"class":"size",style:"font-size:"+Ut[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=B(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=B(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=B(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Ht=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Ht(t),s(t)&&!t.firstChild&&e.removeChild(t))},Wt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Vt[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Pt.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Wt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Mt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},Kt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Mt),t.currentNode=e,!!t.nextNode()},zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=Kt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;C(n.parentNode,n,r.parentNode)}g(n)}else T(r)}};Nt._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},Nt._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)},Nt._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),It(e),Wt(e,!1),zt(e),Ht(e);for(var r=e,o=!0;r=h(r);)S(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var Zt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},qt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Gt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},Qt=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),S(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(Nt._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var $t={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),It(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=yt[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=S(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),T(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Dt,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(kt,s)}for(a=Et(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,C=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||C.scrollTop)+C.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(y(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&E(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Dt,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Bt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(y(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Qt(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(At,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),It(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&($t["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},$t["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),$t[Z+"b"]=Gt("B"),$t[Z+"i"]=Gt("I"),$t[Z+"u"]=Gt("U"),$t[Z+"shift-7"]=Gt("S"),$t[Z+"shift-5"]=Gt("SUB",{tag:"SUP"}),$t[Z+"shift-6"]=Gt("SUP",{tag:"SUB"}),$t[Z+"shift-8"]=qt("makeUnorderedList"),$t[Z+"shift-9"]=qt("makeOrderedList"),$t[Z+"["]=qt("decreaseQuoteLevel"),$t[Z+"]"]=qt("increaseQuoteLevel"),$t[Z+"y"]=qt("redo"),$t[Z+"z"]=qt("undo"),$t[Z+"shift-z"]=qt("redo"),Nt._onKey=function(e){var t=e.keyCode,n=Zt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),$t[n]&&$t[n](this,e)},Nt._getHTML=function(){return this._body.innerHTML},Nt._setHTML=function(e){var t=this._body;t.innerHTML=e;do S(t);while(t=h(t))},Nt.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},Nt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Wt(n,!0),zt(n),T(n);for(var o=n;o=h(o);)S(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),S(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this},Nt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e); -else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=C(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},Nt.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var Yt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Nt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},Nt.bold=Yt("changeFormat",{tag:"B"}),Nt.italic=Yt("changeFormat",{tag:"I"}),Nt.underline=Yt("changeFormat",{tag:"U"}),Nt.strikethrough=Yt("changeFormat",{tag:"S"}),Nt.subscript=Yt("changeFormat",{tag:"SUB"},{tag:"SUP"}),Nt.superscript=Yt("changeFormat",{tag:"SUP"},{tag:"SUB"}),Nt.removeBold=Yt("changeFormat",null,{tag:"B"}),Nt.removeItalic=Yt("changeFormat",null,{tag:"I"}),Nt.removeUnderline=Yt("changeFormat",null,{tag:"U"}),Nt.removeStrikethrough=Yt("changeFormat",null,{tag:"S"}),Nt.removeSubscript=Yt("changeFormat",null,{tag:"SUB"}),Nt.removeSuperscript=Yt("changeFormat",null,{tag:"SUP"}),Nt.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},Nt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Nt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Nt.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()},Nt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Nt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Nt.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()},Nt.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},Nt.increaseQuoteLevel=Yt("modifyBlocks",Tt),Nt.decreaseQuoteLevel=Yt("modifyBlocks",Bt),Nt.makeUnorderedList=Yt("modifyBlocks",Lt),Nt.makeOrderedList=Yt("modifyBlocks",Rt),Nt.removeList=Yt("modifyBlocks",xt),Nt.increaseListLevel=Yt("modifyBlocks",At),Nt.decreaseListLevel=Yt("modifyBlocks",Dt),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function C(e){var t,n,r,o,i=e.ownerDocument,d=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=i.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;if(!n)if(G)for(t=i.createTextNode("​"),r=Nt.length;r--;)o=Nt[r],o._doc===i&&o._didAddZWS();else t=i.createTextNode("")}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=i.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(i.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=i.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),d}function _(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=S(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=S(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&_(r);return d&&e.appendChild(C(d)),e}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());E(n,t)}}function T(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),E(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&_(r),o&&B(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$(e)&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}Nt.push(this)}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(e){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length},Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=[],St=k.prototype;St.createElement=function(e,t,n){return S(this._doc,e,t,n)},St.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var Ct={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)Ct[e]||n.removeEventListener(e,this,!1);for(var o=Nt.length;o--;)Nt[o]===this&&Nt.splice(o,1)},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ct[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],Ct[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return ot(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return H&&this._body.focus(),this._win.focus(),this},St.blur=function(){return H&&this._body.blur(),top.focus(),this};var _t="squire-selection-start",yt="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_t,type:"hidden"}),r=this.createElement("INPUT",{id:yt,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=yt,r.id=_t,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(_t),r=t.getElementById(yt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),E(i,s),i!==a&&E(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),a=c,d=0),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return E(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Et={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Tt=function(e,t,n){var r=Et[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=S(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));_(i),v(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Ot=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=y(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&y(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),_(e),e},It=/\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,Pt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=It.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ut=/^(?: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)$/,wt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ft={backgroundColor:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Vt=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Ht={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ft)r=Ft[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Vt("B"),EM:Vt("I"),STRIKE:Vt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+wt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Mt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Ht[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ut.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Mt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Kt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Kt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;y(n.parentNode,n,r.parentNode)}g(n)}else _(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),Pt(e),Mt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=h(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Qt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},$t=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),C(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Yt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Pt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Et[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),_(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Ot,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Tt(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,S=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||S.scrollTop)+S.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(T(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Ot,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(kt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(T(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&B(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Pt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&(Yt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Yt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Yt[Z+"b"]=Qt("B"),Yt[Z+"i"]=Qt("I"),Yt[Z+"u"]=Qt("U"),Yt[Z+"shift-7"]=Qt("S"),Yt[Z+"shift-5"]=Qt("SUB",{tag:"SUP"}),Yt[Z+"shift-6"]=Qt("SUP",{tag:"SUB"}),Yt[Z+"shift-8"]=Gt("makeUnorderedList"),Yt[Z+"shift-9"]=Gt("makeOrderedList"),Yt[Z+"["]=Gt("decreaseQuoteLevel"),Yt[Z+"]"]=Gt("increaseQuoteLevel"),Yt[Z+"y"]=Gt("redo"),Yt[Z+"z"]=Gt("undo"),Yt[Z+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),Yt[n]&&Yt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=h(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Mt(n,!0),Zt(n),_(n);for(var o=n;o=h(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this +},St.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=y(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},St.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var jt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};St.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},St.bold=jt("changeFormat",{tag:"B"}),St.italic=jt("changeFormat",{tag:"I"}),St.underline=jt("changeFormat",{tag:"U"}),St.strikethrough=jt("changeFormat",{tag:"S"}),St.subscript=jt("changeFormat",{tag:"SUB"},{tag:"SUP"}),St.superscript=jt("changeFormat",{tag:"SUP"},{tag:"SUB"}),St.removeBold=jt("changeFormat",null,{tag:"B"}),St.removeItalic=jt("changeFormat",null,{tag:"I"}),St.removeUnderline=jt("changeFormat",null,{tag:"U"}),St.removeStrikethrough=jt("changeFormat",null,{tag:"S"}),St.removeSubscript=jt("changeFormat",null,{tag:"SUB"}),St.removeSuperscript=jt("changeFormat",null,{tag:"SUP"}),St.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},St.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},St.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},St.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()},St.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},St.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},St.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()},St.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},St.increaseQuoteLevel=jt("modifyBlocks",Bt),St.decreaseQuoteLevel=jt("modifyBlocks",kt),St.makeUnorderedList=jt("modifyBlocks",Rt),St.makeOrderedList=jt("modifyBlocks",xt),St.removeList=jt("modifyBlocks",At),St.increaseListLevel=jt("modifyBlocks",Dt),St.decreaseListLevel=jt("modifyBlocks",Ot),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file diff --git a/source/Constants.js b/source/Constants.js index 8e156db..78ca14c 100644 --- a/source/Constants.js +++ b/source/Constants.js @@ -1,5 +1,4 @@ -/*global doc, navigator */ -/*jshint strict:false */ +/*jshint strict:false, undef:false, unused:false */ var DOCUMENT_POSITION_PRECEDING = 2; // Node.DOCUMENT_POSITION_PRECEDING var ELEMENT_NODE = 1; // Node.ELEMENT_NODE; @@ -30,13 +29,13 @@ var ctrlKey = isMac ? 'meta-' : 'ctrl-'; var useTextFixer = isIE8or9or10 || isPresto; var cantFocusEmptyTextNodes = isIE8or9or10 || isWebKit; var losesSelectionOnBlur = isIE8or9or10; -var hasBuggySplit = ( function () { +var hasBuggySplit = function ( doc ) { var div = doc.createElement( 'DIV' ), text = doc.createTextNode( '12' ); div.appendChild( text ); text.splitText( 2 ); return div.childNodes.length !== 2; -}() ); +}; // Use [^ \t\r\n] instead of \S so that nbsp does not count as white-space var notWS = /[^ \t\r\n]/; diff --git a/source/Editor.js b/source/Editor.js index 29b8234..274b5b6 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1,68 +1,6 @@ -/*global - DOCUMENT_POSITION_PRECEDING, - ELEMENT_NODE, - TEXT_NODE, - SHOW_ELEMENT, - SHOW_TEXT, - win, - isIOS, - isMac, - isGecko, - isIE8or9or10, - isIE8, - isOpera, - ctrlKey, - useTextFixer, - cantFocusEmptyTextNodes, - losesSelectionOnBlur, - hasBuggySplit, - notWS, - indexOf, +/*jshint strict:false, undef:false, unused:false */ - TreeWalker, - - hasTagAttributes, - isLeaf, - isInline, - isBlock, - isContainer, - getBlockWalker, - getPreviousBlock, - getNextBlock, - getNearest, - getPath, - getLength, - detach, - replaceWith, - empty, - fixCursor, - split, - mergeInlines, - mergeWithBlock, - mergeContainers, - fixContainer, - createElement, - - forEachTextNodeInRange, - getTextContentInRange, - insertNodeInRange, - extractContentsOfRange, - deleteContentsOfRange, - insertTreeFragmentIntoRange, - isNodeContainedInRange, - moveRangeBoundariesDownTree, - moveRangeBoundariesUpTree, - getStartBlockOfRange, - getEndBlockOfRange, - rangeDoesStartAtBlockBoundary, - rangeDoesEndAtBlockBoundary, - expandRangeToBlockBoundaries, - - top, - console, - setTimeout -*/ -/*jshint strict:false */ +var instances = []; function Squire ( doc ) { var win = doc.defaultView; @@ -121,7 +59,7 @@ function Squire ( doc ) { // And even if the split is not at the end, the original node is removed // from the document and replaced by another, rather than just having its // data shortened. - if ( hasBuggySplit ) { + if ( hasBuggySplit( doc ) ) { win.Text.prototype.splitText = function ( offset ) { var afterSplit = this.ownerDocument.createTextNode( this.data.slice( offset ) ), @@ -148,6 +86,8 @@ function Squire ( doc ) { doc.execCommand( 'enableObjectResizing', false, 'false' ); doc.execCommand( 'enableInlineTableEditing', false, 'false' ); } catch ( error ) {} + + instances.push( this ); } var proto = Squire.prototype; @@ -221,6 +161,12 @@ proto.destroy = function () { doc.removeEventListener( type, this, false ); } } + var l = instances.length; + while ( l-- ) { + if ( instances[l] === this ) { + instances.splice( l, 1 ); + } + } }; proto.handleEvent = function ( event ) { diff --git a/source/Node.js b/source/Node.js index f58cae3..dc5535f 100644 --- a/source/Node.js +++ b/source/Node.js @@ -1,17 +1,4 @@ -/*global - ELEMENT_NODE, - TEXT_NODE, - SHOW_ELEMENT, - win, - isOpera, - useTextFixer, - cantFocusEmptyTextNodes, - - TreeWalker, - - Text -*/ -/*jshint strict:false */ +/*jshint strict:false, undef:false, unused:false */ var inlineNodeNames = /^(?:#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)$/; @@ -143,6 +130,29 @@ function empty ( node ) { return frag; } +function createElement ( doc, tag, props, children ) { + var el = doc.createElement( tag ), + attr, value, i, l; + if ( props instanceof Array ) { + children = props; + props = null; + } + if ( props ) { + for ( attr in props ) { + value = props[ attr ]; + if ( value !== undefined ) { + el.setAttribute( attr, props[ attr ] ); + } + } + } + if ( children ) { + for ( i = 0, l = children.length; i < l; i += 1 ) { + el.appendChild( children[i] ); + } + } + return el; +} + function fixCursor ( node ) { // In Webkit and Gecko, block level elements are collapsed and // unfocussable if they have no content. To remedy this, a
    must be @@ -150,7 +160,8 @@ function fixCursor ( node ) { // cursor to appear. var doc = node.ownerDocument, root = node, - fixer, child; + fixer, child, + l, instance; if ( node.nodeName === 'BODY' ) { if ( !( child = node.firstChild ) || child.nodeName === 'BR' ) { @@ -176,8 +187,13 @@ function fixCursor ( node ) { if ( !child ) { if ( cantFocusEmptyTextNodes ) { fixer = doc.createTextNode( '\u200B' ); - if ( win.editor ) { - win.editor._didAddZWS(); + // Find the relevant Squire instance and notify + l = instances.length; + while ( l-- ) { + instance = instances[l]; + if ( instance._doc === doc ) { + instance._didAddZWS(); + } } } else { fixer = doc.createTextNode( '' ); @@ -217,6 +233,42 @@ function fixCursor ( node ) { return root; } +// Recursively examine container nodes and wrap any inline children. +function fixContainer ( container ) { + var children = container.childNodes, + doc = container.ownerDocument, + wrapper = null, + i, l, child, isBR; + for ( i = 0, l = children.length; i < l; i += 1 ) { + child = children[i]; + isBR = child.nodeName === 'BR'; + if ( !isBR && isInline( child ) ) { + if ( !wrapper ) { wrapper = createElement( doc, 'DIV' ); } + wrapper.appendChild( child ); + i -= 1; + l -= 1; + } else if ( isBR || wrapper ) { + if ( !wrapper ) { wrapper = createElement( doc, 'DIV' ); } + fixCursor( wrapper ); + if ( isBR ) { + container.replaceChild( wrapper, child ); + } else { + container.insertBefore( wrapper, child ); + i += 1; + l += 1; + } + wrapper = null; + } + if ( isContainer( child ) ) { + fixContainer( child ); + } + } + if ( wrapper ) { + container.appendChild( fixCursor( wrapper ) ); + } + return container; +} + function split ( node, offset, stopNode ) { var nodeType = node.nodeType, parent, clone, next; @@ -400,62 +452,3 @@ function mergeContainers ( node ) { fixCursor( prev ); } } - -// Recursively examine container nodes and wrap any inline children. -function fixContainer ( container ) { - var children = container.childNodes, - doc = container.ownerDocument, - wrapper = null, - i, l, child, isBR; - for ( i = 0, l = children.length; i < l; i += 1 ) { - child = children[i]; - isBR = child.nodeName === 'BR'; - if ( !isBR && isInline( child ) ) { - if ( !wrapper ) { wrapper = createElement( doc, 'DIV' ); } - wrapper.appendChild( child ); - i -= 1; - l -= 1; - } else if ( isBR || wrapper ) { - if ( !wrapper ) { wrapper = createElement( doc, 'DIV' ); } - fixCursor( wrapper ); - if ( isBR ) { - container.replaceChild( wrapper, child ); - } else { - container.insertBefore( wrapper, child ); - i += 1; - l += 1; - } - wrapper = null; - } - if ( isContainer( child ) ) { - fixContainer( child ); - } - } - if ( wrapper ) { - container.appendChild( fixCursor( wrapper ) ); - } - return container; -} - -function createElement ( doc, tag, props, children ) { - var el = doc.createElement( tag ), - attr, value, i, l; - if ( props instanceof Array ) { - children = props; - props = null; - } - if ( props ) { - for ( attr in props ) { - value = props[ attr ]; - if ( value !== undefined ) { - el.setAttribute( attr, props[ attr ] ); - } - } - } - if ( children ) { - for ( i = 0, l = children.length; i < l; i += 1 ) { - el.appendChild( children[i] ); - } - } - return el; -} diff --git a/source/Range.js b/source/Range.js index e99e1fc..a7c5a72 100644 --- a/source/Range.js +++ b/source/Range.js @@ -1,28 +1,4 @@ -/*global - ELEMENT_NODE, - TEXT_NODE, - SHOW_TEXT, - START_TO_START, - START_TO_END, - END_TO_END, - END_TO_START, - notWS, - indexOf, - - TreeWalker, - - isLeaf, - isInline, - isBlock, - getPreviousBlock, - getNextBlock, - getLength, - fixCursor, - split, - mergeWithBlock, - mergeContainers -*/ -/*jshint strict:false */ +/*jshint strict:false, undef:false, unused:false */ var getNodeBefore = function ( node, offset ) { var children = node.childNodes; diff --git a/source/outro.js b/source/outro.js index a8f1a62..1a660b9 100644 --- a/source/outro.js +++ b/source/outro.js @@ -1,4 +1,3 @@ -/*global top, win, doc, Squire */ if ( top !== win ) { win.editor = new Squire( doc ); From 73c4146e27af2a73e666a49f5d8257932d80e229 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Fri, 3 Oct 2014 16:38:20 +0700 Subject: [PATCH 14/24] Fix range error in addFormat if start == end container. --- build/squire-raw.js | 4 ++++ build/squire.js | 2 +- source/Editor.js | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 703a3be..43ca671 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -1709,6 +1709,10 @@ proto._addFormat = function ( tag, attributes, range ) { } if ( textNode === startContainer && startOffset ) { textNode = textNode.splitText( startOffset ); + if ( endContainer === startContainer ) { + endContainer = textNode; + endOffset -= startOffset; + } startContainer = textNode; startOffset = 0; } diff --git a/build/squire.js b/build/squire.js index a751e46..60b2b72 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function C(e){var t,n,r,o,i=e.ownerDocument,d=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=i.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;if(!n)if(G)for(t=i.createTextNode("​"),r=Nt.length;r--;)o=Nt[r],o._doc===i&&o._didAddZWS();else t=i.createTextNode("")}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=i.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(i.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=i.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),d}function _(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=S(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=S(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&_(r);return d&&e.appendChild(C(d)),e}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());E(n,t)}}function T(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),E(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&_(r),o&&B(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$(e)&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}Nt.push(this)}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(e){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length},Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=[],St=k.prototype;St.createElement=function(e,t,n){return S(this._doc,e,t,n)},St.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var Ct={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)Ct[e]||n.removeEventListener(e,this,!1);for(var o=Nt.length;o--;)Nt[o]===this&&Nt.splice(o,1)},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ct[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],Ct[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return ot(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return H&&this._body.focus(),this._win.focus(),this},St.blur=function(){return H&&this._body.blur(),top.focus(),this};var _t="squire-selection-start",yt="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_t,type:"hidden"}),r=this.createElement("INPUT",{id:yt,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=yt,r.id=_t,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(_t),r=t.getElementById(yt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),E(i,s),i!==a&&E(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(c===s&&c.length>l&&c.splitText(l),c===a&&d&&(c=c.splitText(d),a=c,d=0),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return E(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Et={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Tt=function(e,t,n){var r=Et[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=S(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));_(i),v(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Ot=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=y(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&y(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),_(e),e},It=/\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,Pt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=It.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ut=/^(?: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)$/,wt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ft={backgroundColor:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Vt=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Ht={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ft)r=Ft[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Vt("B"),EM:Vt("I"),STRIKE:Vt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+wt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Mt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Ht[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ut.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Mt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Kt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Kt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;y(n.parentNode,n,r.parentNode)}g(n)}else _(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),Pt(e),Mt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=h(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Qt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},$t=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),C(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Yt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Pt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Et[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),_(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Ot,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Tt(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,S=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||S.scrollTop)+S.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(T(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Ot,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(kt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(T(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&B(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Pt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&(Yt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Yt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Yt[Z+"b"]=Qt("B"),Yt[Z+"i"]=Qt("I"),Yt[Z+"u"]=Qt("U"),Yt[Z+"shift-7"]=Qt("S"),Yt[Z+"shift-5"]=Qt("SUB",{tag:"SUP"}),Yt[Z+"shift-6"]=Qt("SUP",{tag:"SUB"}),Yt[Z+"shift-8"]=Gt("makeUnorderedList"),Yt[Z+"shift-9"]=Gt("makeOrderedList"),Yt[Z+"["]=Gt("decreaseQuoteLevel"),Yt[Z+"]"]=Gt("increaseQuoteLevel"),Yt[Z+"y"]=Gt("redo"),Yt[Z+"z"]=Gt("undo"),Yt[Z+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),Yt[n]&&Yt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=h(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Mt(n,!0),Zt(n),_(n);for(var o=n;o=h(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function C(e){var t,n,r,o,i=e.ownerDocument,d=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=i.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;if(!n)if(G)for(t=i.createTextNode("​"),r=Nt.length;r--;)o=Nt[r],o._doc===i&&o._didAddZWS();else t=i.createTextNode("")}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=i.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(i.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=i.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),d}function _(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=S(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=S(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&_(r);return d&&e.appendChild(C(d)),e}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());E(n,t)}}function T(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),E(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&_(r),o&&B(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$(e)&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}Nt.push(this)}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(e){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length},Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=[],St=k.prototype;St.createElement=function(e,t,n){return S(this._doc,e,t,n)},St.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var Ct={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)Ct[e]||n.removeEventListener(e,this,!1);for(var o=Nt.length;o--;)Nt[o]===this&&Nt.splice(o,1)},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ct[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],Ct[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return ot(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return H&&this._body.focus(),this._win.focus(),this},St.blur=function(){return H&&this._body.blur(),top.focus(),this};var _t="squire-selection-start",yt="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_t,type:"hidden"}),r=this.createElement("INPUT",{id:yt,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=yt,r.id=_t,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(_t),r=t.getElementById(yt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),E(i,s),i!==a&&E(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(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),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return E(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Et={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Tt=function(e,t,n){var r=Et[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=S(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));_(i),v(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Ot=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=y(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&y(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),_(e),e},It=/\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,Pt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=It.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ut=/^(?: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)$/,wt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ft={backgroundColor:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Vt=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Ht={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ft)r=Ft[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Vt("B"),EM:Vt("I"),STRIKE:Vt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+wt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Mt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Ht[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ut.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Mt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Kt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Kt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;y(n.parentNode,n,r.parentNode)}g(n)}else _(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),Pt(e),Mt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=h(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Qt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},$t=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),C(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Yt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Pt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Et[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),_(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Ot,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Tt(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,S=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||S.scrollTop)+S.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(T(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Ot,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(kt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(T(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&B(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Pt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&(Yt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Yt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Yt[Z+"b"]=Qt("B"),Yt[Z+"i"]=Qt("I"),Yt[Z+"u"]=Qt("U"),Yt[Z+"shift-7"]=Qt("S"),Yt[Z+"shift-5"]=Qt("SUB",{tag:"SUP"}),Yt[Z+"shift-6"]=Qt("SUP",{tag:"SUB"}),Yt[Z+"shift-8"]=Gt("makeUnorderedList"),Yt[Z+"shift-9"]=Gt("makeOrderedList"),Yt[Z+"["]=Gt("decreaseQuoteLevel"),Yt[Z+"]"]=Gt("increaseQuoteLevel"),Yt[Z+"y"]=Gt("redo"),Yt[Z+"z"]=Gt("undo"),Yt[Z+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),Yt[n]&&Yt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=h(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Mt(n,!0),Zt(n),_(n);for(var o=n;o=h(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this },St.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=y(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},St.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var jt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};St.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},St.bold=jt("changeFormat",{tag:"B"}),St.italic=jt("changeFormat",{tag:"I"}),St.underline=jt("changeFormat",{tag:"U"}),St.strikethrough=jt("changeFormat",{tag:"S"}),St.subscript=jt("changeFormat",{tag:"SUB"},{tag:"SUP"}),St.superscript=jt("changeFormat",{tag:"SUP"},{tag:"SUB"}),St.removeBold=jt("changeFormat",null,{tag:"B"}),St.removeItalic=jt("changeFormat",null,{tag:"I"}),St.removeUnderline=jt("changeFormat",null,{tag:"U"}),St.removeStrikethrough=jt("changeFormat",null,{tag:"S"}),St.removeSubscript=jt("changeFormat",null,{tag:"SUB"}),St.removeSuperscript=jt("changeFormat",null,{tag:"SUP"}),St.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},St.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},St.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},St.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()},St.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},St.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},St.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()},St.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},St.increaseQuoteLevel=jt("modifyBlocks",Bt),St.decreaseQuoteLevel=jt("modifyBlocks",kt),St.makeUnorderedList=jt("modifyBlocks",Rt),St.makeOrderedList=jt("modifyBlocks",xt),St.removeList=jt("modifyBlocks",At),St.increaseListLevel=jt("modifyBlocks",Dt),St.decreaseListLevel=jt("modifyBlocks",Ot),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 274b5b6..9512981 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -624,6 +624,10 @@ proto._addFormat = function ( tag, attributes, range ) { } if ( textNode === startContainer && startOffset ) { textNode = textNode.splitText( startOffset ); + if ( endContainer === startContainer ) { + endContainer = textNode; + endOffset -= startOffset; + } startContainer = textNode; startOffset = 0; } From 3296e7576eae3e3b5fcef18cc2d4248131517f54 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Tue, 18 Nov 2014 12:02:36 +0700 Subject: [PATCH 15/24] Register for events on capture rather than bubble phase. Allows "load" events to be triggered for images in the document. --- build/squire-raw.js | 4 ++-- build/squire.js | 2 +- source/Editor.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 43ca671..e82c0ae 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -1243,7 +1243,7 @@ proto.destroy = function () { win.removeEventListener( 'blur', this, false ); for ( type in events ) { if ( !customEvents[ type ] ) { - doc.removeEventListener( type, this, false ); + doc.removeEventListener( type, this, true ); } } var l = instances.length; @@ -1270,7 +1270,7 @@ proto.addEventListener = function ( type, fn ) { if ( !handlers ) { handlers = this._events[ type ] = []; if ( !customEvents[ type ] ) { - this._doc.addEventListener( type, this, false ); + this._doc.addEventListener( type, this, true ); } } handlers.push( fn ); diff --git a/build/squire.js b/build/squire.js index 60b2b72..3709a2f 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function C(e){var t,n,r,o,i=e.ownerDocument,d=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=i.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;if(!n)if(G)for(t=i.createTextNode("​"),r=Nt.length;r--;)o=Nt[r],o._doc===i&&o._didAddZWS();else t=i.createTextNode("")}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=i.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(i.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=i.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),d}function _(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=S(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=S(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&_(r);return d&&e.appendChild(C(d)),e}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());E(n,t)}}function T(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),E(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&_(r),o&&B(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$(e)&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}Nt.push(this)}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(e){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length},Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=[],St=k.prototype;St.createElement=function(e,t,n){return S(this._doc,e,t,n)},St.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var Ct={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)Ct[e]||n.removeEventListener(e,this,!1);for(var o=Nt.length;o--;)Nt[o]===this&&Nt.splice(o,1)},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ct[e]||this._doc.addEventListener(e,this,!1)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],Ct[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return ot(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return H&&this._body.focus(),this._win.focus(),this},St.blur=function(){return H&&this._body.blur(),top.focus(),this};var _t="squire-selection-start",yt="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_t,type:"hidden"}),r=this.createElement("INPUT",{id:yt,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=yt,r.id=_t,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(_t),r=t.getElementById(yt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),E(i,s),i!==a&&E(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(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),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return E(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Et={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Tt=function(e,t,n){var r=Et[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=S(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));_(i),v(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Ot=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=y(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&y(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),_(e),e},It=/\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,Pt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=It.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ut=/^(?: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)$/,wt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ft={backgroundColor:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Vt=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Ht={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ft)r=Ft[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Vt("B"),EM:Vt("I"),STRIKE:Vt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+wt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Mt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Ht[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ut.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Mt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Kt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Kt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;y(n.parentNode,n,r.parentNode)}g(n)}else _(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),Pt(e),Mt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=h(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Qt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},$t=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),C(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Yt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Pt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Et[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),_(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Ot,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Tt(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,S=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||S.scrollTop)+S.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(T(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Ot,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(kt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(T(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&B(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Pt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&(Yt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Yt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Yt[Z+"b"]=Qt("B"),Yt[Z+"i"]=Qt("I"),Yt[Z+"u"]=Qt("U"),Yt[Z+"shift-7"]=Qt("S"),Yt[Z+"shift-5"]=Qt("SUB",{tag:"SUP"}),Yt[Z+"shift-6"]=Qt("SUP",{tag:"SUB"}),Yt[Z+"shift-8"]=Gt("makeUnorderedList"),Yt[Z+"shift-9"]=Gt("makeOrderedList"),Yt[Z+"["]=Gt("decreaseQuoteLevel"),Yt[Z+"]"]=Gt("increaseQuoteLevel"),Yt[Z+"y"]=Gt("redo"),Yt[Z+"z"]=Gt("undo"),Yt[Z+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),Yt[n]&&Yt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=h(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Mt(n,!0),Zt(n),_(n);for(var o=n;o=h(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function C(e){var t,n,r,o,i=e.ownerDocument,d=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=i.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;if(!n)if(G)for(t=i.createTextNode("​"),r=Nt.length;r--;)o=Nt[r],o._doc===i&&o._didAddZWS();else t=i.createTextNode("")}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=i.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(i.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=i.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),d}function _(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=S(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=S(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&_(r);return d&&e.appendChild(C(d)),e}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());E(n,t)}}function T(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),E(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&_(r),o&&B(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$(e)&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}Nt.push(this)}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(e){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length},Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=[],St=k.prototype;St.createElement=function(e,t,n){return S(this._doc,e,t,n)},St.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var Ct={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)Ct[e]||n.removeEventListener(e,this,!0);for(var o=Nt.length;o--;)Nt[o]===this&&Nt.splice(o,1)},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ct[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)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],Ct[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return ot(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return H&&this._body.focus(),this._win.focus(),this},St.blur=function(){return H&&this._body.blur(),top.focus(),this};var _t="squire-selection-start",yt="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_t,type:"hidden"}),r=this.createElement("INPUT",{id:yt,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=yt,r.id=_t,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(_t),r=t.getElementById(yt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),E(i,s),i!==a&&E(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(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),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return E(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Et={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Tt=function(e,t,n){var r=Et[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=S(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));_(i),v(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Ot=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=y(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&y(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),_(e),e},It=/\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,Pt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=It.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ut=/^(?: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)$/,wt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ft={backgroundColor:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Vt=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Ht={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ft)r=Ft[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Vt("B"),EM:Vt("I"),STRIKE:Vt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+wt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Mt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Ht[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ut.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Mt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Kt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Kt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;y(n.parentNode,n,r.parentNode)}g(n)}else _(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),Pt(e),Mt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=h(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Qt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},$t=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),C(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Yt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Pt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Et[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),_(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Ot,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Tt(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,S=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||S.scrollTop)+S.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(T(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Ot,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(kt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(T(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&B(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Pt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&(Yt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Yt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Yt[Z+"b"]=Qt("B"),Yt[Z+"i"]=Qt("I"),Yt[Z+"u"]=Qt("U"),Yt[Z+"shift-7"]=Qt("S"),Yt[Z+"shift-5"]=Qt("SUB",{tag:"SUP"}),Yt[Z+"shift-6"]=Qt("SUP",{tag:"SUB"}),Yt[Z+"shift-8"]=Gt("makeUnorderedList"),Yt[Z+"shift-9"]=Gt("makeOrderedList"),Yt[Z+"["]=Gt("decreaseQuoteLevel"),Yt[Z+"]"]=Gt("increaseQuoteLevel"),Yt[Z+"y"]=Gt("redo"),Yt[Z+"z"]=Gt("undo"),Yt[Z+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),Yt[n]&&Yt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=h(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Mt(n,!0),Zt(n),_(n);for(var o=n;o=h(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this },St.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=y(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},St.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var jt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};St.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},St.bold=jt("changeFormat",{tag:"B"}),St.italic=jt("changeFormat",{tag:"I"}),St.underline=jt("changeFormat",{tag:"U"}),St.strikethrough=jt("changeFormat",{tag:"S"}),St.subscript=jt("changeFormat",{tag:"SUB"},{tag:"SUP"}),St.superscript=jt("changeFormat",{tag:"SUP"},{tag:"SUB"}),St.removeBold=jt("changeFormat",null,{tag:"B"}),St.removeItalic=jt("changeFormat",null,{tag:"I"}),St.removeUnderline=jt("changeFormat",null,{tag:"U"}),St.removeStrikethrough=jt("changeFormat",null,{tag:"S"}),St.removeSubscript=jt("changeFormat",null,{tag:"SUB"}),St.removeSuperscript=jt("changeFormat",null,{tag:"SUP"}),St.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},St.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},St.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},St.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()},St.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},St.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},St.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()},St.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},St.increaseQuoteLevel=jt("modifyBlocks",Bt),St.decreaseQuoteLevel=jt("modifyBlocks",kt),St.makeUnorderedList=jt("modifyBlocks",Rt),St.makeOrderedList=jt("modifyBlocks",xt),St.removeList=jt("modifyBlocks",At),St.increaseListLevel=jt("modifyBlocks",Dt),St.decreaseListLevel=jt("modifyBlocks",Ot),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 9512981..d982afa 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -158,7 +158,7 @@ proto.destroy = function () { win.removeEventListener( 'blur', this, false ); for ( type in events ) { if ( !customEvents[ type ] ) { - doc.removeEventListener( type, this, false ); + doc.removeEventListener( type, this, true ); } } var l = instances.length; @@ -185,7 +185,7 @@ proto.addEventListener = function ( type, fn ) { if ( !handlers ) { handlers = this._events[ type ] = []; if ( !customEvents[ type ] ) { - this._doc.addEventListener( type, this, false ); + this._doc.addEventListener( type, this, true ); } } handlers.push( fn ); From cb9292721c87d7d24924e359eebd11ab0f6165db Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 20 Nov 2014 12:45:36 +0700 Subject: [PATCH 16/24] Let the browser handle shift-delete. Apparently it's "cut" on Windows. Who knew. --- build/squire-raw.js | 13 ++++++++----- build/squire.js | 2 +- source/Editor.js | 13 ++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index e82c0ae..efecdd7 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -3094,15 +3094,18 @@ proto._onKey = function ( event ) { key = 'f' + ( code - 111 ); } - // We need to apply the backspace/delete handlers regardless of modifiers. + // We need to apply the backspace/delete handlers regardless of + // control key modifiers. if ( key !== 'backspace' && key !== 'delete' ) { - if ( event.altKey ) { modifiers += 'alt-'; } + if ( event.altKey ) { modifiers += 'alt-'; } if ( event.ctrlKey ) { modifiers += 'ctrl-'; } if ( event.metaKey ) { modifiers += 'meta-'; } - if ( event.shiftKey ) { modifiers += 'shift-'; } - - key = modifiers + key; } + // However, on Windows, shift-delete is apparently "cut" (WTF right?), so + // we want to let the browser handle shift-delete. + if ( event.shiftKey ) { modifiers += 'shift-'; } + + key = modifiers + key; if ( keyHandlers[ key ] ) { keyHandlers[ key ]( this, event ); diff --git a/build/squire.js b/build/squire.js index 3709a2f..0331479 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function C(e){var t,n,r,o,i=e.ownerDocument,d=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=i.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;if(!n)if(G)for(t=i.createTextNode("​"),r=Nt.length;r--;)o=Nt[r],o._doc===i&&o._didAddZWS();else t=i.createTextNode("")}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=i.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(i.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=i.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),d}function _(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=S(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=S(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&_(r);return d&&e.appendChild(C(d)),e}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());E(n,t)}}function T(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),E(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&_(r),o&&B(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$(e)&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}Nt.push(this)}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(e){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length},Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=[],St=k.prototype;St.createElement=function(e,t,n){return S(this._doc,e,t,n)},St.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var Ct={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)Ct[e]||n.removeEventListener(e,this,!0);for(var o=Nt.length;o--;)Nt[o]===this&&Nt.splice(o,1)},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ct[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)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],Ct[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return ot(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return H&&this._body.focus(),this._win.focus(),this},St.blur=function(){return H&&this._body.blur(),top.focus(),this};var _t="squire-selection-start",yt="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_t,type:"hidden"}),r=this.createElement("INPUT",{id:yt,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=yt,r.id=_t,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(_t),r=t.getElementById(yt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),E(i,s),i!==a&&E(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(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),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return E(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Et={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Tt=function(e,t,n){var r=Et[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=S(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));_(i),v(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Ot=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=y(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&y(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),_(e),e},It=/\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,Pt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=It.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ut=/^(?: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)$/,wt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ft={backgroundColor:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Vt=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Ht={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ft)r=Ft[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Vt("B"),EM:Vt("I"),STRIKE:Vt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+wt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Mt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Ht[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ut.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Mt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Kt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Kt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;y(n.parentNode,n,r.parentNode)}g(n)}else _(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),Pt(e),Mt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=h(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Qt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},$t=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),C(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Yt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Pt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Et[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),_(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Ot,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Tt(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,S=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||S.scrollTop)+S.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(T(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Ot,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(kt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(T(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&B(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Pt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&(Yt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Yt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Yt[Z+"b"]=Qt("B"),Yt[Z+"i"]=Qt("I"),Yt[Z+"u"]=Qt("U"),Yt[Z+"shift-7"]=Qt("S"),Yt[Z+"shift-5"]=Qt("SUB",{tag:"SUP"}),Yt[Z+"shift-6"]=Qt("SUP",{tag:"SUB"}),Yt[Z+"shift-8"]=Gt("makeUnorderedList"),Yt[Z+"shift-9"]=Gt("makeOrderedList"),Yt[Z+"["]=Gt("decreaseQuoteLevel"),Yt[Z+"]"]=Gt("increaseQuoteLevel"),Yt[Z+"y"]=Gt("redo"),Yt[Z+"z"]=Gt("undo"),Yt[Z+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-"),e.shiftKey&&(r+="shift-"),n=r+n),Yt[n]&&Yt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=h(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Mt(n,!0),Zt(n),_(n);for(var o=n;o=h(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function C(e){var t,n,r,o,i=e.ownerDocument,d=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=i.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;if(!n)if(G)for(t=i.createTextNode("​"),r=Nt.length;r--;)o=Nt[r],o._doc===i&&o._didAddZWS();else t=i.createTextNode("")}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=i.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(i.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=i.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),d}function _(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=S(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=S(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&_(r);return d&&e.appendChild(C(d)),e}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());E(n,t)}}function T(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),E(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&_(r),o&&B(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$(e)&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}Nt.push(this)}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(e){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length},Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=[],St=k.prototype;St.createElement=function(e,t,n){return S(this._doc,e,t,n)},St.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var Ct={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)Ct[e]||n.removeEventListener(e,this,!0);for(var o=Nt.length;o--;)Nt[o]===this&&Nt.splice(o,1)},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ct[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)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],Ct[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return ot(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return H&&this._body.focus(),this._win.focus(),this},St.blur=function(){return H&&this._body.blur(),top.focus(),this};var _t="squire-selection-start",yt="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_t,type:"hidden"}),r=this.createElement("INPUT",{id:yt,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=yt,r.id=_t,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(_t),r=t.getElementById(yt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),E(i,s),i!==a&&E(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(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),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return E(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Et={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Tt=function(e,t,n){var r=Et[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=S(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));_(i),v(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Ot=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=y(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&y(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),_(e),e},It=/\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,Pt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=It.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ut=/^(?: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)$/,wt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ft={backgroundColor:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Vt=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Ht={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ft)r=Ft[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Vt("B"),EM:Vt("I"),STRIKE:Vt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+wt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Mt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Ht[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ut.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Mt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Kt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Kt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;y(n.parentNode,n,r.parentNode)}g(n)}else _(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),Pt(e),Mt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=h(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Qt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},$t=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),C(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Yt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Pt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Et[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),_(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Ot,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Tt(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,S=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||S.scrollTop)+S.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(T(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Ot,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(kt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(T(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&B(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Pt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&(Yt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Yt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Yt[Z+"b"]=Qt("B"),Yt[Z+"i"]=Qt("I"),Yt[Z+"u"]=Qt("U"),Yt[Z+"shift-7"]=Qt("S"),Yt[Z+"shift-5"]=Qt("SUB",{tag:"SUP"}),Yt[Z+"shift-6"]=Qt("SUP",{tag:"SUB"}),Yt[Z+"shift-8"]=Gt("makeUnorderedList"),Yt[Z+"shift-9"]=Gt("makeOrderedList"),Yt[Z+"["]=Gt("decreaseQuoteLevel"),Yt[Z+"]"]=Gt("increaseQuoteLevel"),Yt[Z+"y"]=Gt("redo"),Yt[Z+"z"]=Gt("undo"),Yt[Z+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-")),e.shiftKey&&(r+="shift-"),n=r+n,Yt[n]&&Yt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=h(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Mt(n,!0),Zt(n),_(n);for(var o=n;o=h(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this },St.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=y(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},St.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var jt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};St.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},St.bold=jt("changeFormat",{tag:"B"}),St.italic=jt("changeFormat",{tag:"I"}),St.underline=jt("changeFormat",{tag:"U"}),St.strikethrough=jt("changeFormat",{tag:"S"}),St.subscript=jt("changeFormat",{tag:"SUB"},{tag:"SUP"}),St.superscript=jt("changeFormat",{tag:"SUP"},{tag:"SUB"}),St.removeBold=jt("changeFormat",null,{tag:"B"}),St.removeItalic=jt("changeFormat",null,{tag:"I"}),St.removeUnderline=jt("changeFormat",null,{tag:"U"}),St.removeStrikethrough=jt("changeFormat",null,{tag:"S"}),St.removeSubscript=jt("changeFormat",null,{tag:"SUB"}),St.removeSuperscript=jt("changeFormat",null,{tag:"SUP"}),St.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},St.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},St.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},St.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()},St.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},St.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},St.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()},St.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},St.increaseQuoteLevel=jt("modifyBlocks",Bt),St.decreaseQuoteLevel=jt("modifyBlocks",kt),St.makeUnorderedList=jt("modifyBlocks",Rt),St.makeOrderedList=jt("modifyBlocks",xt),St.removeList=jt("modifyBlocks",At),St.increaseListLevel=jt("modifyBlocks",Dt),St.decreaseListLevel=jt("modifyBlocks",Ot),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index d982afa..d73137b 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -2009,15 +2009,18 @@ proto._onKey = function ( event ) { key = 'f' + ( code - 111 ); } - // We need to apply the backspace/delete handlers regardless of modifiers. + // We need to apply the backspace/delete handlers regardless of + // control key modifiers. if ( key !== 'backspace' && key !== 'delete' ) { - if ( event.altKey ) { modifiers += 'alt-'; } + if ( event.altKey ) { modifiers += 'alt-'; } if ( event.ctrlKey ) { modifiers += 'ctrl-'; } if ( event.metaKey ) { modifiers += 'meta-'; } - if ( event.shiftKey ) { modifiers += 'shift-'; } - - key = modifiers + key; } + // However, on Windows, shift-delete is apparently "cut" (WTF right?), so + // we want to let the browser handle shift-delete. + if ( event.shiftKey ) { modifiers += 'shift-'; } + + key = modifiers + key; if ( keyHandlers[ key ] ) { keyHandlers[ key ]( this, event ); From ae38caba31636226f93b0d00ebda1ab6a8e3e8b5 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Sat, 29 Nov 2014 20:08:53 +0700 Subject: [PATCH 17/24] Remove IE8 support. It was always a bit buggy, and realistically there's no point in putting in the time to fix it up. --- Demo.html | 3 - Makefile | 8 +- Readme.md | 6 +- build/document.html | 5 +- build/ie8.js | 1 - source/document.html | 5 +- source/ie8dom.js | 157 -------------- source/ie8range.js | 487 ------------------------------------------- source/ie8types.js | 63 ------ 9 files changed, 6 insertions(+), 729 deletions(-) delete mode 100644 build/ie8.js delete mode 100644 source/ie8dom.js delete mode 100644 source/ie8range.js delete mode 100644 source/ie8types.js diff --git a/Demo.html b/Demo.html index 217584c..9815714 100644 --- a/Demo.html +++ b/Demo.html @@ -27,9 +27,6 @@ margin: 5px 0; } - - \ No newline at end of file + diff --git a/build/ie8.js b/build/ie8.js deleted file mode 100644 index 41efb73..0000000 --- a/build/ie8.js +++ /dev/null @@ -1 +0,0 @@ -!function(){Array.prototype.indexOf=function(t,e){for(var n=this.length,r=0>e?Math.max(0,n+e):e||0;n>r;r+=1)if(this[r]===t)return r;return-1},Array.prototype.forEach=function(t,e){var n=this.length>>>0;if("function"!=typeof t)throw new TypeError;for(var r=0;n>r;r+=1)t.call(e,this[r],r,this)},Array.prototype.filter=function(t,e){for(var n=[],r=0,o=this.length;o>r;r+=1){var i=this[r];t.call(e,i,r,this)&&n.push(i)}return n},Object.keyOf=function(t,e){for(var n in t)if(t[n]===e)return n},Date.now=function(){return+new Date},String.prototype.trim=function(){for(var t=this.replace(/^\s\s*/,""),e=/\s/,n=t.length;e.test(t.charAt(n-=1)););return t.slice(0,n+1)}}(),function(){var t=document;window.ie=8,t.defaultView=window;var e={focus:"focusin",blur:"focusout"},n=function(){return!0},r=function(){return!1},o="altKey ctrlKey metaKey shiftKey clientX clientY charCode keyCode".split(" "),i=function(t){for(var n,r=t.type,i=document,a=t.srcElement||i,s=(a.ownerDocument||i).documentElement,c=o.length;c--;)n=o[c],this[n]=t[n];"propertychange"===r&&(r="INPUT"===a.nodeName&&"text"!==a.type&&"password"!==a.type?"change":"input"),this.type=Object.keyOf(e,r)||r,this.target=a,this.pageX=t.clientX+s.scrollLeft,this.pageY=t.clientY+s.scrollTop,t.button&&(this.button=4&t.button?1:2&t.button?2:0,this.which=this.button+1),this.relatedTarget=t.fromElement===a?t.toElement:t.fromElement,this._event=t};i.prototype={constructor:i,isEvent:!0,preventDefault:function(){this.isDefaultPrevented=n,this._event.returnValue=!1},stopPropagation:function(){this.isPropagationStopped=n,this._event.cancelBubble=!0},isDefaultPrevented:r,isPropagationStopped:r},[t,Element.prototype].forEach(function(t){t.addEventListener=function(t,n){var r=n._ie_handleEvent||(n._ie_handleEvent=function(){var t=new i(window.event);"object"==typeof n?n.handleEvent(t):n.call(this,t)}),o=/paste|cut/.test(t)?this.body||this:this;n._ie_registeredCount=(n._ie_registeredCount||0)+1,o.attachEvent("on"+(e[t]||t),r)},t.addEventListener.isFake=!0,t.removeEventListener=function(t,n){var r=n._ie_handleEvent,o=/paste|cut/.test(t)?this.body||this:this;(n._ie_registeredCount-=1)||delete n._ie_handleEvent,r&&o.detachEvent("on"+(e[t]||t),r)},t.removeEventListener.isFake=!0}),t.defaultView.addEventListener=function(e,n,r){return t.addEventListener(e,n,r)},Object.defineProperty(Element.prototype,"textContent",{get:function(){return this.innerText},set:function(t){this.innerText=t}}),Element.prototype.compareDocumentPosition=function(t){1!==t.nodeType&&(t=t.parentNode);var e=this,n=e!==t,r=e.sourceIndex,o=t.sourceIndex;return(n&&e.contains(t)?16:0)+(n&&t.contains(e)?8:0)+(o>r?4:0)+(r>o?2:0)},HTMLDocument.prototype.normalize=function(){for(var t,e=this.childNodes,n=e.length;n--;)t=e[n],1===t.nodeType&&t.normalize()}}();var Range;!function(){var t=Array.prototype.indexOf,e=0,n=1,r=3,o=function(t,e){for(;e=e.parentNode;)if(t===e)return!0;return!1},i=function(t,e){var n,r,i,a,s;if(t===e||o(t,e))n=t;else if(o(e,t))n=e;else{for(r=[],i=[];t=t.parentNode;)r.push(t);for(;e=e.parentNode;)i.push(e);for(a=r.length,s=i.length;a--&&s--;)if(r[a]!==i[s]){n=r[a+1];break}n||(n=-1===a?r[0]:i[0])}return n};Range=function(t,e,n,r){t=t||document,e=e||0,this.startContainer=t,this.startOffset=e,this.endContainer=n||t,this.endOffset=void 0!==r?r:e,this._updateCollapsedAndAncestor()},Range.prototype={constructor:Range,_updateCollapsedAndAncestor:function(){this.collapsed=this.startContainer===this.endContainer&&this.startOffset===this.endOffset,this.commonAncestorContainer=i(this.startContainer,this.endContainer)},setStart:function(t,e){this.startContainer=t,this.startOffset=e,this._updateCollapsedAndAncestor()},setEnd:function(t,e){this.endContainer=t,this.endOffset=e,this._updateCollapsedAndAncestor()},setStartAfter:function(e){var n=e.parentNode;this.setStart(n,t.call(n.childNodes,e)+1)},setEndBefore:function(e){var n=e.parentNode;this.setEnd(n,t.call(n.childNodes,e))},selectNode:function(e){var n=e.parentNode,r=t.call(n.childNodes,e);this.setStart(n,r),this.setEnd(n,r+1)},selectNodeContents:function(t){this.setStart(t,0),this.setEnd(t,t.childNodes.length)},cloneRange:function(){return new Range(this.startContainer,this.startOffset,this.endContainer,this.endOffset)},collapse:function(t){t?this.setEnd(this.startContainer,this.startOffset):this.setStart(this.endContainer,this.endOffset)},compareBoundaryPoints:function(o,i){var a,s,c,d,f,u;if(o===e||o===r?(a=this.startContainer,s=this.startOffset):(a=this.endContainer,s=this.endOffset),o===e||o===n?(c=i.startContainer,d=i.startOffset):(c=i.endContainer,d=i.endOffset),a===c)return d>s?-1:s>d?1:0;for(f=a;u=f.parentNode;){if(u===c)return t.call(u.childNodes,f)c.sourceIndex?1:0}},document.createRange=function(){return new Range};var a=function(t,e){return t===e||o(t,e)},s=function(t){var e=t.nodeType;return 3===e||4===e||8===e},c=function(t,e){this.node=t,this.offset=e},d=function(t){var e,n,r,o,a=t.parentElement();return e=t.duplicate(),e.collapse(!0),n=e.parentElement(),e=t.duplicate(),e.collapse(!1),r=e.parentElement(),o=n===r?n:i(n,r),o===a?o:i(a,o)},f=function(e,n,r,o){var i=e.duplicate();i.collapse(r);var d=i.parentElement();if(a(n,d)||(d=n),!d.canHaveHTML)return new c(d.parentNode,t.call(d.parentNode.childNodes,d));var f,u,l,h,p,v=document.createElement("span"),m=r?"StartToStart":"StartToEnd";do d.insertBefore(v,v.previousSibling),i.moveToElementText(v),f=i.compareEndPoints(m,e);while(f>0&&v.previousSibling);if(p=v.nextSibling,-1===f&&p&&s(p)){i.setEndPoint(r?"EndToStart":"EndToEnd",e);var E;if(/[\r\n]/.test(p.data)||/[\r\n]/.test(i.text)){var g=i.duplicate(),y=g.text.replace(/\r\n/g,"\r").length;for(E=g.moveStart("character",y);-1===(f=g.compareEndPoints("StartToEnd",g));)E+=1,g.moveStart("character",1)}else E=i.text.length;h=new c(p,E)}else u=(o||!r)&&v.previousSibling,l=(o||r)&&v.nextSibling,h=l&&s(l)?new c(l,0):u&&s(u)?new c(u,u.data.length):new c(d,t.call(d.childNodes,v));return v.parentNode.removeChild(v),h},u=function(t,e){var n,r,o,i,a=t.offset,c=document,d=c.body.createTextRange(),f=s(t.node);return f?(n=t.node,r=n.parentNode):(i=t.node.childNodes,n=a - - \ No newline at end of file + diff --git a/source/ie8dom.js b/source/ie8dom.js deleted file mode 100644 index 0b6fd9e..0000000 --- a/source/ie8dom.js +++ /dev/null @@ -1,157 +0,0 @@ -/* Copyright © 2011-2012 by Neil Jenkins. Licensed under the MIT license. */ - -( function () { - -/*global window, document, Element, HTMLDocument */ -/*jshint strict: false */ - -var doc = document; - -// Add JS hook -window.ie = 8; - -// Add defaultView property to document -doc.defaultView = window; - -// Fake W3C events support -var translate = { - focus: 'focusin', - blur: 'focusout' -}; - -var returnTrue = function () { return true; }; -var returnFalse = function () { return false; }; - -var toCopy = 'altKey ctrlKey metaKey shiftKey clientX clientY charCode keyCode'.split( ' ' ); - -var DOMEvent = function ( event ) { - var type = event.type, - doc = document, - target = event.srcElement || doc, - html = ( target.ownerDocument || doc ).documentElement, - l = toCopy.length, - property; - - while ( l-- ) { - property = toCopy[l]; - this[ property ] = event[ property ]; - } - - if ( type === 'propertychange' ) { - type = ( target.nodeName === 'INPUT' && - target.type !== 'text' && target.type !== 'password' ) ? - 'change' : 'input'; - } - - this.type = Object.keyOf( translate, type ) || type; - this.target = target; - this.pageX = event.clientX + html.scrollLeft; - this.pageY = event.clientY + html.scrollTop; - - if ( event.button ) { - this.button = ( event.button & 4 ? 1 : - ( event.button & 2 ? 2 : 0 ) ); - this.which = this.button + 1; - } - - this.relatedTarget = event.fromElement === target ? - event.toElement : event.fromElement; - this._event = event; -}; - -DOMEvent.prototype = { - constructor: DOMEvent, - isEvent: true, - preventDefault: function () { - this.isDefaultPrevented = returnTrue; - this._event.returnValue = false; - }, - stopPropagation: function () { - this.isPropagationStopped = returnTrue; - this._event.cancelBubble = true; - }, - isDefaultPrevented: returnFalse, - isPropagationStopped: returnFalse -}; - -// Add W3C event add/remove methods to elements and document. -[ doc, Element.prototype ].forEach( - function ( dom ) { - dom.addEventListener = function ( type, handler, capture ) { - var fn = handler._ie_handleEvent || ( handler._ie_handleEvent = - function () { - var event = new DOMEvent( window.event ); - if ( typeof handler === 'object' ) { - handler.handleEvent( event ); - } else { - handler.call( this, event ); - } - } - ), - node = /paste|cut/.test( type ) ? this.body || this : this; - - handler._ie_registeredCount = ( handler._ie_registeredCount || 0 ) + 1; - - node.attachEvent( 'on' + ( translate[ type ] || type ), fn ); - }; - dom.addEventListener.isFake = true; - - dom.removeEventListener = function ( type, handler, capture ) { - var fn = handler._ie_handleEvent, - node = /paste|cut/.test( type ) ? this.body || this : this; - if ( !( handler._ie_registeredCount -= 1 ) ) { - delete handler._ie_handleEvent; - } - if ( fn ) { - node.detachEvent( 'on' + ( translate[ type ] || type ), fn ); - } - }; - dom.removeEventListener.isFake = true; -}); - -// The events that we normally attach to the window object, IE8 wants on the -// body. -doc.defaultView.addEventListener = function ( type, handler, capture ) { - return doc.addEventListener( type, handler, capture ); -}; - -// Add textContent property to elements. -Object.defineProperty( Element.prototype, 'textContent', { - get: function () { - return this.innerText; - }, - - set: function ( text ) { - this.innerText = text; - } -}); - -// Add compareDocumentPosition method to elements. -Element.prototype.compareDocumentPosition = function ( b ) { - if ( b.nodeType !== 1 ) { b = b.parentNode; } - var a = this, - different = ( a !== b ), - aIndex = a.sourceIndex, - bIndex = b.sourceIndex; - - return ( different && a.contains( b ) ? 16 : 0 ) + - ( different && b.contains( a ) ? 8 : 0 ) + - ( aIndex < bIndex ? 4 : 0 ) + - ( bIndex < aIndex ? 2 : 0 ); -}; - -// Add normalize method to document fragments -HTMLDocument.prototype.normalize = function () { - var children = this.childNodes, - l = children.length, - child; - - while ( l-- ) { - child = children[l]; - if ( child.nodeType === 1 ) { - child.normalize(); - } - } -}; - -}() ); diff --git a/source/ie8range.js b/source/ie8range.js deleted file mode 100644 index 1c54e52..0000000 --- a/source/ie8range.js +++ /dev/null @@ -1,487 +0,0 @@ -/* Copyright © 2011-2012 by Neil Jenkins. Licensed under the MIT license. - - IE TextRange <-> W3C Range code adapted from Rangy: - http://code.google.com/p/rangy/ - Copyright 2012, Tim Down. Licensed under the MIT license. -*/ - -var Range; - -( function () { - -/*global window, document */ -/*jshint strict: false */ - -var indexOf = Array.prototype.indexOf; - -var START_TO_START = 0; -var START_TO_END = 1; -var END_TO_START = 3; - -var contains = function ( a, b ) { - while ( b = b.parentNode ) { - if ( a === b ) { return true; } - } - return false; -}; - -var getCommonAncestor = function ( a, b ) { - var commonAncestor, - aParents, bParents, - aL, bL; - - if ( a === b || contains( a, b ) ) { - commonAncestor = a; - } else if ( contains( b, a ) ) { - commonAncestor = b; - } else { - aParents = []; - bParents = []; - while ( a = a.parentNode ) { - aParents.push( a ); - } - while ( b = b.parentNode ) { - bParents.push( b ); - } - aL = aParents.length; - bL = bParents.length; - while ( aL-- && bL-- ) { - if ( aParents[ aL ] !== bParents[ bL ] ) { - commonAncestor = aParents[ aL + 1 ]; - break; - } - } - if ( !commonAncestor ) { - commonAncestor = ( aL === -1 ? aParents[0] : bParents[0] ); - } - } - return commonAncestor; -}; - -Range = function ( startContainer, startOffset, endContainer, endOffset ) { - startContainer = startContainer || document; - startOffset = startOffset || 0; - - this.startContainer = startContainer; - this.startOffset = startOffset; - this.endContainer = endContainer || startContainer; - this.endOffset = endOffset !== undefined ? endOffset : startOffset; - this._updateCollapsedAndAncestor(); -}; - -Range.prototype = { - constructor: Range, - - _updateCollapsedAndAncestor: function () { - this.collapsed = ( - this.startContainer === this.endContainer && - this.startOffset === this.endOffset - ); - this.commonAncestorContainer = - getCommonAncestor( this.startContainer, this.endContainer ); - }, - setStart: function ( node, offset ) { - this.startContainer = node; - this.startOffset = offset; - this._updateCollapsedAndAncestor(); - }, - setEnd: function ( node, offset ) { - this.endContainer = node; - this.endOffset = offset; - this._updateCollapsedAndAncestor(); - }, - setStartAfter: function ( node ) { - var parent = node.parentNode; - this.setStart( parent, indexOf.call( parent.childNodes, node ) + 1 ); - }, - setEndBefore: function ( node ) { - var parent = node.parentNode; - this.setEnd( parent, indexOf.call( parent.childNodes, node ) ); - }, - selectNode: function ( node ) { - var parent = node.parentNode, - offset = indexOf.call( parent.childNodes, node ); - this.setStart( parent, offset ); - this.setEnd( parent, offset + 1 ); - }, - selectNodeContents: function ( node ) { - this.setStart( node, 0 ); - this.setEnd( node, node.childNodes.length ); - }, - cloneRange: function () { - return new Range( - this.startContainer, - this.startOffset, - this.endContainer, - this.endOffset - ); - }, - collapse: function ( toStart ) { - if ( toStart ) { - this.setEnd( this.startContainer, this.startOffset ); - } else { - this.setStart( this.endContainer, this.endOffset ); - } - }, - compareBoundaryPoints: function ( how, sourceRange ) { - var aContainer, aOffset, bContainer, bOffset, node, parent; - if ( how === START_TO_START || how === END_TO_START ) { - aContainer = this.startContainer; - aOffset = this.startOffset; - } else { - aContainer = this.endContainer; - aOffset = this.endOffset; - } - if ( how === START_TO_START || how === START_TO_END ) { - bContainer = sourceRange.startContainer; - bOffset = sourceRange.startOffset; - } else { - bContainer = sourceRange.endContainer; - bOffset = sourceRange.endOffset; - } - if ( aContainer === bContainer ) { - return aOffset < bOffset ? -1 : - aOffset > bOffset ? 1 : 0; - } - - node = aContainer; - while ( parent = node.parentNode ) { - if ( parent === bContainer ) { - return indexOf.call( parent.childNodes, node ) < bOffset ? - -1 : 1; - } - node = parent; - } - node = bContainer; - while ( parent = node.parentNode ) { - if ( parent === aContainer ) { - return indexOf.call( parent.childNodes, node ) < aOffset ? - 1 : -1; - } - node = parent; - } - if ( aContainer.nodeType !== 1 ) { - aContainer = aContainer.parentNode; - } - if ( bContainer.nodeType !== 1 ) { - bContainer = bContainer.parentNode; - } - return aContainer.sourceIndex < bContainer.sourceIndex ? -1 : - aContainer.sourceIndex > bContainer.sourceIndex ? 1 : 0; - } -}; - -document.createRange = function () { - return new Range(); -}; - -// --- - -var isAncestorOf = function ( ancestor, descendant ) { - return ancestor === descendant || contains( ancestor, descendant ); -}; - -var isCharacterDataNode = function ( node ) { - var nodeType = node.nodeType; - // Text, CDataSection or Comment - return nodeType === 3 || nodeType === 4 || nodeType === 8; -}; - -var DomPosition = function ( node, offset ) { - this.node = node; - this.offset = offset; -}; - -var getTextRangeContainerElement = function ( textRange ) { - var parentEl = textRange.parentElement(), - range, startEl, endEl, startEndContainer; - - range = textRange.duplicate(); - range.collapse( true ); - startEl = range.parentElement(); - range = textRange.duplicate(); - range.collapse( false ); - endEl = range.parentElement(); - startEndContainer = ( startEl === endEl ) ? - startEl : getCommonAncestor( startEl, endEl ); - - return startEndContainer === parentEl ? - startEndContainer : getCommonAncestor( parentEl, startEndContainer ); -}; - -// Gets the boundary of a TextRange expressed as a node and an offset within -// that node. This function started out as an improved version of code found in -// Tim Cameron Ryan's IERange (http://code.google.com/p/ierange/) but has grown, -// fixing problems with line breaks in preformatted text, adding workaround for -// IE TextRange bugs, handling for inputs and images, plus optimizations. -var getTextRangeBoundaryPosition = function ( - textRange, wholeRangeContainerElement, isStart, isCollapsed ) { - var workingRange = textRange.duplicate(); - - workingRange.collapse( isStart ); - - var containerElement = workingRange.parentElement(); - - // Sometimes collapsing a TextRange that's at the start of a text node can - // move it into the previous node, so check for that TODO: Find out when. - // Workaround for wholeRangeContainerElement may break this - if ( !isAncestorOf( wholeRangeContainerElement, containerElement ) ) { - containerElement = wholeRangeContainerElement; - } - - // Deal with nodes that cannot "contain rich HTML markup". In practice, this - // means form inputs, images and similar. See - // http://msdn.microsoft.com/en-us/library/aa703950%28VS.85%29.aspx - if ( !containerElement.canHaveHTML ) { - return new DomPosition( - containerElement.parentNode, - indexOf.call( - containerElement.parentNode.childNodes, containerElement ) - ); - } - - var workingNode = document.createElement( 'span' ), - workingComparisonType = isStart ? 'StartToStart' : 'StartToEnd', - comparison, previousNode, nextNode, boundaryPosition, boundaryNode; - - // Move the working range through the container's children, starting at the - // end and working backwards, until the working range reaches or goes past - // the boundary we're interested in - do { - containerElement.insertBefore( - workingNode, workingNode.previousSibling ); - workingRange.moveToElementText( workingNode ); - comparison = - workingRange.compareEndPoints( workingComparisonType, textRange ); - } while ( comparison > 0 && workingNode.previousSibling ); - - // We've now reached or gone past the boundary of the text range we're - // interested in so have identified the node we want - boundaryNode = workingNode.nextSibling; - - if ( comparison === -1 && boundaryNode && - isCharacterDataNode( boundaryNode ) ) { - // This is a character data node (text, comment, cdata). The working - // range is collapsed at the start of the node containing the text - // range's boundary, so we move the end of the working range to the - // boundary point and measure the length of its text to get the - // boundary's offset within the node. - workingRange.setEndPoint( - isStart ? 'EndToStart' : 'EndToEnd', textRange ); - - var offset; - - if ( /[\r\n]/.test( boundaryNode.data ) || - /[\r\n]/.test( workingRange.text ) ) { - /* - For the particular case of a boundary within a text node containing - line breaks (within a
     element, for example), we need a
    -            slightly complicated approach to get the boundary's offset in IE.
    -            The facts:
    -
    -            - Each line break is represented as \r in the text node's
    -              data/nodeValue properties
    -            - Each line break is represented as \r\n in the TextRange's 'text'
    -              property
    -            - The 'text' property of the TextRange does not contain trailing
    -              line breaks
    -
    -            To get round the problem presented by the final fact above, we can
    -            use the fact that TextRange's moveStart() and moveEnd() methods
    -            return the actual number of characters moved, which is not
    -            necessarily the same as the number of characters it was instructed
    -            to move. The simplest approach is to use this to store the
    -            characters moved when moving both the start and end of the range to
    -            the start of the document body and subtracting the start offset from
    -            the end offset (the "move-negative-gazillion" method). However, this
    -            is extremely slow when the document is large and the range is near
    -            the end of it. Clearly doing the mirror image (i.e. moving the range
    -            boundaries to the end of the document) has the same problem.
    -
    -            Another approach that works is to use moveStart() to move the start
    -            boundary of the range up to the end boundary one character at a time
    -            and incrementing a counter with the value returned by the
    -            moveStart() call. However, the check for whether the start boundary
    -            has reached the end boundary is expensive, so this method is slow
    -            (although unlike "move-negative-gazillion" is largely unaffected by
    -            the location of the range within the document).
    -
    -            The method below is a hybrid of the two methods above. It uses the
    -            fact that a string containing the TextRange's 'text' property with
    -            each \r\n converted to a single \r character cannot be longer than
    -            the text of the TextRange, so the start of the range is moved that
    -            length initially and then a character at a time to make up for any
    -            trailing line breaks not contained in the 'text' property. This has
    -            good performance in most situations compared to the previous two
    -            methods.
    -            */
    -            var tempRange = workingRange.duplicate();
    -            var rangeLength = tempRange.text.replace( /\r\n/g, '\r' ).length;
    -
    -            offset = tempRange.moveStart( 'character', rangeLength);
    -            while ( ( comparison =
    -                    tempRange.compareEndPoints( 'StartToEnd', tempRange )
    -                    ) === -1 ) {
    -                offset += 1;
    -                tempRange.moveStart( 'character', 1 );
    -            }
    -        } else {
    -            offset = workingRange.text.length;
    -        }
    -        boundaryPosition = new DomPosition( boundaryNode, offset );
    -    }
    -    else {
    -        // If the boundary immediately follows a character data node and this is
    -        // the end boundary, we should favour a position within that, and
    -        // likewise for a start boundary preceding a character data node
    -        previousNode = ( isCollapsed || !isStart ) &&
    -            workingNode.previousSibling;
    -        nextNode = ( isCollapsed || isStart ) && workingNode.nextSibling;
    -
    -        if ( nextNode && isCharacterDataNode( nextNode ) ) {
    -            boundaryPosition = new DomPosition( nextNode, 0 );
    -        } else if ( previousNode && isCharacterDataNode( previousNode ) ) {
    -            // Strange bug: if we don't read the data property, the length
    -            // property is often returned incorrectly as 0. Don't ask me why.
    -            // Therefore get the length from the data property rather than
    -            // reading it directly from the node.
    -            boundaryPosition = new DomPosition(
    -                previousNode, previousNode.data.length );
    -        } else {
    -            boundaryPosition = new DomPosition(
    -                containerElement,
    -                indexOf.call( containerElement.childNodes, workingNode )
    -            );
    -        }
    -    }
    -
    -    // Clean up
    -    workingNode.parentNode.removeChild( workingNode );
    -
    -    return boundaryPosition;
    -};
    -
    -// Returns a TextRange representing the boundary of a TextRange expressed as a
    -// node and an offset within that node. This function started out as an
    -// optimized version of code found in Tim Cameron Ryan's IERange
    -// (http://code.google.com/p/ierange/)
    -var createBoundaryTextRange = function ( boundaryPosition, isStart ) {
    -    var boundaryNode, boundaryParent, boundaryOffset = boundaryPosition.offset;
    -    var doc = document;
    -    var workingNode, childNodes, workingRange = doc.body.createTextRange();
    -    var nodeIsDataNode = isCharacterDataNode( boundaryPosition.node );
    -
    -    if ( nodeIsDataNode ) {
    -        boundaryNode = boundaryPosition.node;
    -        boundaryParent = boundaryNode.parentNode;
    -    } else {
    -        childNodes = boundaryPosition.node.childNodes;
    -        boundaryNode = ( boundaryOffset < childNodes.length ) ?
    -            childNodes[ boundaryOffset ] : null;
    -        boundaryParent = boundaryPosition.node;
    -    }
    -
    -    // Position the range immediately before the node containing the boundary
    -    workingNode = doc.createElement( 'span' );
    -
    -    // Making the working element non-empty element persuades IE to consider the
    -    // TextRange boundary to be within the element rather than immediately
    -    // before or after it, which is what we want
    -    workingNode.innerHTML = '';
    -
    -    // insertBefore is supposed to work like appendChild if the second parameter
    -    // is null. However, a bug report for IERange suggests that it can crash the
    -    // browser: http://code.google.com/p/ierange/issues/detail?id=12
    -    if ( boundaryNode ) {
    -        boundaryParent.insertBefore( workingNode, boundaryNode );
    -    } else {
    -        boundaryParent.appendChild( workingNode );
    -    }
    -
    -    workingRange.moveToElementText( workingNode );
    -    workingRange.collapse( !isStart );
    -
    -    // Clean up
    -    boundaryParent.removeChild( workingNode );
    -
    -    // Move the working range to the text offset, if required
    -    if ( nodeIsDataNode ) {
    -        workingRange[ isStart ? 'moveStart' : 'moveEnd' ](
    -            'character', boundaryOffset );
    -    }
    -
    -    return workingRange;
    -};
    -
    -var toDOMRange = function ( textRange ) {
    -    var rangeContainerElement = getTextRangeContainerElement( textRange ),
    -        start, end;
    -
    -    if ( textRange.compareEndPoints( 'StartToEnd', textRange ) === 0 ) {
    -        start = end = getTextRangeBoundaryPosition(
    -            textRange, rangeContainerElement, true, true );
    -    } else {
    -        start = getTextRangeBoundaryPosition(
    -            textRange, rangeContainerElement, true, false );
    -        end = getTextRangeBoundaryPosition(
    -            textRange, rangeContainerElement, false, false );
    -    }
    -    return new Range(
    -        start.node,
    -        start.offset,
    -        end.node,
    -        end.offset
    -    );
    -};
    -
    -var toTextRange = function ( range ) {
    -    var textRange, startRange, endRange;
    -    if ( range.collapsed ) {
    -        textRange = createBoundaryTextRange(
    -            new DomPosition( range.startContainer, range.startOffset ), true);
    -    } else {
    -        startRange = createBoundaryTextRange(
    -            new DomPosition( range.startContainer, range.startOffset ), true);
    -        endRange = createBoundaryTextRange(
    -            new DomPosition( range.endContainer, range.endOffset ), false );
    -        textRange = document.body.createTextRange();
    -        textRange.setEndPoint( 'StartToStart', startRange);
    -        textRange.setEndPoint( 'EndToEnd', endRange);
    -    }
    -    return textRange;
    -};
    -
    -var selection = {
    -    rangeCount: 0,
    -    getRangeAt: function ( index ) {
    -        if ( index !== 0 ) { return undefined; }
    -        var sel = document.selection.createRange();
    -        // Check if we have a control range.
    -        if ( sel.add ) {
    -            var range = document.createRange();
    -            range.moveToElementText( sel.item( 0 ) );
    -            range.collapse( false );
    -            range.select();
    -            sel = range;
    -        }
    -        return toDOMRange( sel );
    -    },
    -    removeAllRanges: function () {},
    -    addRange: function ( range ) {
    -        toTextRange( range ).select();
    -    }
    -};
    -
    -document.attachEvent( 'onbeforeactivate', function () {
    -    selection.rangeCount = 1;
    -});
    -
    -document.attachEvent( 'ondeactivate', function () {
    -    selection.rangeCount = 0;
    -});
    -
    -window.getSelection = function () {
    -    return selection;
    -};
    -
    -}() );
    diff --git a/source/ie8types.js b/source/ie8types.js
    deleted file mode 100644
    index 7a3361c..0000000
    --- a/source/ie8types.js
    +++ /dev/null
    @@ -1,63 +0,0 @@
    -/* Copyright © 2011-2012 by Neil Jenkins. Licensed under the MIT license. */
    -
    -( function () {
    -
    -/*jshint strict: false */
    -
    -// Note: Does not inclue the `if ( i in this ) {}` check these function should
    -// have, as IE8 will return false if this[i] is undefined (at least if the array
    -// was defined with a literal, e.g. `[ undefined, undefined ]`).
    -
    -Array.prototype.indexOf = function ( item, from ) {
    -    var l = this.length;
    -    for ( var i = ( from < 0 ) ? Math.max( 0, l + from ) : from || 0;
    -            i < l; i += 1 ) {
    -        if ( this[i] === item ) {
    -            return i;
    -        }
    -    }
    -    return -1;
    -};
    -
    -Array.prototype.forEach = function ( fn, bind ) {
    -    var l = this.length >>> 0;
    -    if ( typeof fn !== 'function' ) {
    -        throw new TypeError();
    -    }
    -    for ( var i = 0; i < l; i += 1 ) {
    -        fn.call( bind, this[i], i, this );
    -    }
    -};
    -
    -Array.prototype.filter = function ( fn, bind ) {
    -    var results = [];
    -    for ( var i = 0, l = this.length; i < l; i += 1 ) {
    -        var value = this[i];
    -        if ( fn.call( bind, value, i, this ) ) {
    -            results.push( value );
    -        }
    -    }
    -    return results;
    -};
    -
    -Object.keyOf = function ( object, value ) {
    -    for ( var key in object ) {
    -        if ( object[ key ] === value ) {
    -            return key;
    -        }
    -    }
    -};
    -
    -Date.now = function () {
    -    return +( new Date() );
    -};
    -
    -String.prototype.trim = function () {
    -    var str = this.replace( /^\s\s*/, '' ),
    -        ws = /\s/,
    -        i = str.length;
    -    while ( ws.test( str.charAt( i -= 1 ) ) ) {/* Empty! */}
    -    return str.slice( 0, i + 1 );
    -};
    -
    -}() );
    
    From 25f78ff31d968c1b64d4322e372d886b282f3a18 Mon Sep 17 00:00:00 2001
    From: Neil Jenkins 
    Date: Sun, 7 Dec 2014 14:33:43 +0700
    Subject: [PATCH 18/24] Fix cursor no longer appears on focus in Chrome.
    
    ---
     build/squire-raw.js | 9 ++++-----
     build/squire.js     | 2 +-
     source/Editor.js    | 9 ++++-----
     3 files changed, 9 insertions(+), 11 deletions(-)
    
    diff --git a/build/squire-raw.js b/build/squire-raw.js
    index efecdd7..ad8b594 100644
    --- a/build/squire-raw.js
    +++ b/build/squire-raw.js
    @@ -1424,11 +1424,10 @@ proto._updatePathOnEvent = function () {
     // --- Focus ---
     
     proto.focus = function () {
    -    // FF seems to need the body to be focussed
    -    // (at least on first load).
    -    if ( isGecko ) {
    -        this._body.focus();
    -    }
    +    // FF seems to need the body to be focussed (at least on first load).
    +    // Chrome also now needs body to be focussed in order to show the cursor
    +    // (otherwise it is focussed, but the cursor doesn't appear).
    +    this._body.focus();
         this._win.focus();
         return this;
     };
    diff --git a/build/squire.js b/build/squire.js
    index 0331479..37354c1 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 r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function C(e){var t,n,r,o,i=e.ownerDocument,d=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=i.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;if(!n)if(G)for(t=i.createTextNode("​"),r=Nt.length;r--;)o=Nt[r],o._doc===i&&o._didAddZWS();else t=i.createTextNode("")}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=i.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(i.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=i.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),d}function _(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=S(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=S(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&_(r);return d&&e.appendChild(C(d)),e}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());E(n,t)}}function T(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),E(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&_(r),o&&B(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$(e)&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}Nt.push(this)}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(e){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length},Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=[],St=k.prototype;St.createElement=function(e,t,n){return S(this._doc,e,t,n)},St.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var Ct={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)Ct[e]||n.removeEventListener(e,this,!0);for(var o=Nt.length;o--;)Nt[o]===this&&Nt.splice(o,1)},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ct[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)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],Ct[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return ot(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return H&&this._body.focus(),this._win.focus(),this},St.blur=function(){return H&&this._body.blur(),top.focus(),this};var _t="squire-selection-start",yt="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_t,type:"hidden"}),r=this.createElement("INPUT",{id:yt,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=yt,r.id=_t,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(_t),r=t.getElementById(yt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),E(i,s),i!==a&&E(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(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),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return E(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Et={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Tt=function(e,t,n){var r=Et[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=S(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));_(i),v(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Ot=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=y(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&y(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),_(e),e},It=/\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,Pt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=It.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ut=/^(?: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)$/,wt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ft={backgroundColor:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Vt=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Ht={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ft)r=Ft[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Vt("B"),EM:Vt("I"),STRIKE:Vt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+wt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Mt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Ht[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ut.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Mt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Kt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Kt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;y(n.parentNode,n,r.parentNode)}g(n)}else _(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),Pt(e),Mt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=h(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Qt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},$t=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),C(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Yt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Pt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Et[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),_(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Ot,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Tt(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,S=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||S.scrollTop)+S.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(T(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Ot,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(kt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(T(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&B(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Pt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&(Yt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Yt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Yt[Z+"b"]=Qt("B"),Yt[Z+"i"]=Qt("I"),Yt[Z+"u"]=Qt("U"),Yt[Z+"shift-7"]=Qt("S"),Yt[Z+"shift-5"]=Qt("SUB",{tag:"SUP"}),Yt[Z+"shift-6"]=Qt("SUP",{tag:"SUB"}),Yt[Z+"shift-8"]=Gt("makeUnorderedList"),Yt[Z+"shift-9"]=Gt("makeOrderedList"),Yt[Z+"["]=Gt("decreaseQuoteLevel"),Yt[Z+"]"]=Gt("increaseQuoteLevel"),Yt[Z+"y"]=Gt("redo"),Yt[Z+"z"]=Gt("undo"),Yt[Z+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-")),e.shiftKey&&(r+="shift-"),n=r+n,Yt[n]&&Yt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=h(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Mt(n,!0),Zt(n),_(n);for(var o=n;o=h(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this
    +!function(e,t){"use strict";function n(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n}function r(e,t){for(var n=e.length;n--;)if(!t(e[n]))return!1;return!0}function o(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 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===L&&!!et[e.nodeName]}function s(e){return J.test(e.nodeName)}function d(e){return e.nodeType===L&&!s(e)&&r(e.childNodes,s)}function l(e){return e.nodeType===L&&!s(e)&&!d(e)}function c(e){var t=e.ownerDocument,r=new n(t.body,x,d,!1);return r.currentNode=e,r}function f(e){return c(e).previousNode()}function h(e){return c(e).nextNode()}function u(e,t,n){do if(o(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===L?(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 m(e){var t=e.nodeType;return t===L?e.childNodes.length:e.length||0}function g(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 N(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function S(e,n,r,o){var i,a,s,d,l=e.createElement(n);if(r instanceof Array&&(o=r,r=null),r)for(i in r)a=r[i],a!==t&&l.setAttribute(i,r[i]);if(o)for(s=0,d=o.length;d>s;s+=1)l.appendChild(o[s]);return l}function C(e){var t,n,r,o,i=e.ownerDocument,d=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=i.createElement("DIV"),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;G&&n&&n.nodeType===R&&!n.data;)e.removeChild(n),n=e.firstChild;if(!n)if(G)for(t=i.createTextNode("​"),r=Nt.length;r--;)o=Nt[r],o._doc===i&&o._didAddZWS();else t=i.createTextNode("")}else if(q){for(;e.nodeType!==R&&!a(e);){if(n=e.firstChild,!n){t=i.createTextNode("");break}e=n}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(i.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=i.createElement("BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),d}function _(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=S(a,"DIV")),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=S(a,"DIV")),C(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&_(r);return d&&e.appendChild(C(d)),e}function y(e,t,n){var r,o,i,a=e.nodeType;if(a===R&&e!==n)return y(e.parentNode,e.splitText(t),n);if(a===L){if("number"==typeof t&&(t=td?t.startOffset-=1:t.startOffset===d&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>d?t.endOffset-=1:t.endOffset===d&&(t.endContainer=r,t.endOffset=m(r))),g(n),n.nodeType===R?r.appendData(n.data):l.push(N(n));else if(n.nodeType===L){for(o=l.length;o--;)n.appendChild(l.pop());E(n,t)}}function T(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;g(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(N(t)),E(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),K&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function B(e){var t,n,r=e.previousSibling,o=e.firstChild,a=e.ownerDocument,s="LI"===e.nodeName;if(!s||o&&/^[OU]L$/.test(o.nodeName))if(r&&i(r,e)){if(!l(r)){if(!s)return;n=a.createElement("DIV"),n.appendChild(N(r)),r.appendChild(n)}g(e),t=!l(e),r.appendChild(N(e)),t&&_(r),o&&B(o)}else s&&(r=a.createElement("DIV"),e.insertBefore(r,o),C(r))}function k(e){var n=e.defaultView,r=e.body;this._win=n,this._doc=e,this._body=r,this._events={},this._sel=n.getSelection(),this._lastSelection=null,Q&&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),n.addEventListener("focus",this,!1),n.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this.defaultBlockProperties=t,this.addEventListener("keyup",this._docWasChanged),this._awaitingPaste=!1,this.addEventListener(W?"beforecut":"cut",this._onCut),this.addEventListener(W?"beforepaste":"paste",this._onPaste),M&&this.addEventListener("keyup",this._ieSelAllClean),this.addEventListener(K?"keypress":"keydown",this._onKey),$(e)&&(n.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}),r.setAttribute("contenteditable","true"),this.setHTML("");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(o){}Nt.push(this)}var b=2,L=1,R=3,x=1,A=4,D=0,O=1,I=2,P=3,U=e.defaultView,w=navigator.userAgent,F=/iP(?:ad|hone|od)/.test(w),V=/Mac OS X/.test(w),H=/Gecko\//.test(w),W=/Trident\/[456]\./.test(w),M=8===U.ie,K=!!U.opera,z=/WebKit\//.test(w),Z=V?"meta-":"ctrl-",q=W||K,G=W||z,Q=W,$=function(e){var t=e.createElement("DIV"),n=e.createTextNode("12");return t.appendChild(n),n.splitText(2),2!==t.childNodes.length},Y=/[^ \t\r\n]/,j=Array.prototype.indexOf,X={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,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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.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(X[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var J=/^(?:#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)$/,et={BR:1,IMG:1,INPUT:1},tt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===L;)e=n[t-1],n=e.childNodes,t=n.length;return e},nt=function(e,t){if(e.nodeType===L){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(O,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(D,r)<1,s=e.compareBoundaryPoints(I,r)>-1;return a&&s},ct=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==R&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=m(o);else for(;o.nodeType!==R&&(t=o.firstChild,t&&!a(t));)o=t;e.collapsed?(e.setStart(o,i),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(o,i))},ft=function(e,t){var n,r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;for(t||(t=e.commonAncestorContainer);r!==t&&!o;)n=r.parentNode,o=j.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=j.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ht=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=tt(n,e.startOffset),t=h(t)),t&<(e,t,!0)?t:null},ut=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=nt(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&<(e,t,!0)?t:null},pt=new n(null,A|x,function(e){return e.nodeType===R?Y.test(e.data):"IMG"===e.nodeName}),mt=function(e){var t=e.startContainer,n=e.startOffset;if(t.nodeType===R){if(n)return!1;pt.currentNode=t}else pt.currentNode=nt(t,n);return pt.root=ht(e),!pt.previousNode()},gt=function(e){var t,n=e.endContainer,r=e.endOffset;if(n.nodeType===R){if(t=n.data.length,t&&t>r)return!1;pt.currentNode=n}else pt.currentNode=tt(n,r);return pt.root=ut(e),!pt.nextNode()},vt=function(e){var t,n=ht(e),r=ut(e);n&&r&&(t=n.parentNode,e.setStart(t,j.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,j.call(t.childNodes,r)+1))},Nt=[],St=k.prototype;St.createElement=function(e,t,n){return S(this._doc,e,t,n)},St.createDefaultBlock=function(e){return C(this.createElement("DIV",this.defaultBlockProperties,e))},St.didError=function(e){console.log(e)},St.getDocument=function(){return this._doc};var Ct={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};St.fireEvent=function(e,t){var n,r,o,i=this._events[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.call(this,t)}catch(a){a.details="Squire: fireEvent error. Event type: "+e,this.didError(a)}}return this},St.destroy=function(){var e,t=this._win,n=this._doc,r=this._events;t.removeEventListener("focus",this,!1),t.removeEventListener("blur",this,!1);for(e in r)Ct[e]||n.removeEventListener(e,this,!0);for(var o=Nt.length;o--;)Nt[o]===this&&Nt.splice(o,1)},St.handleEvent=function(e){this.fireEvent(e.type,e)},St.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ct[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)},St.removeEventListener=function(e,t){var n,r=this._events[e];if(r){for(n=r.length;n--;)r[n]===t&&r.splice(n,1);r.length||(delete this._events[e],Ct[e]||this._doc.removeEventListener(e,this,!1))}return this},St._createRange=function(e,t,n,r){if(e instanceof this._win.Range)return e.cloneRange();var o=this._doc.createRange();return o.setStart(e,t),n?o.setEnd(n,r):o.setEnd(e,t),o},St.setSelection=function(e){if(e){F&&this._win.focus();var t=this._sel;t.removeAllRanges(),t.addRange(e)}return this},St.getSelection=function(){var e,t,n,r=this._sel;if(r.rangeCount){e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer;try{t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n)}catch(o){this.didError({name:"Squire#getSelection error",message:"Starts: "+t.nodeName+"\nEnds: "+n.nodeName})}this._lastSelection=e}else e=this._lastSelection;return e||(e=this._createRange(this._body.firstChild,0)),e},St.getSelectedText=function(){return ot(this.getSelection())},St.getPath=function(){return this._path},St._didAddZWS=function(){this._hasZWS=!0},St._removeZWS=function(){if(this._hasZWS){for(var e,t,r=new n(this._body,A,function(){return!0},!1);e=r.nextNode();)for(;(t=e.data.indexOf("​"))>-1;)e.deleteData(t,1);this._hasZWS=!1}},St._updatePath=function(e,t){var n,r=e.startContainer,o=e.endContainer;(t||r!==this._lastAnchorNode||o!==this._lastFocusNode)&&(this._lastAnchorNode=r,this._lastFocusNode=o,n=r&&o?r===o?p(o):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),r!==o&&this.fireEvent("select")},St._updatePathOnEvent=function(){this._updatePath(this.getSelection())},St.focus=function(){return this._body.focus(),this._win.focus(),this},St.blur=function(){return H&&this._body.blur(),top.focus(),this};var _t="squire-selection-start",yt="squire-selection-end";St._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:_t,type:"hidden"}),r=this.createElement("INPUT",{id:yt,type:"hidden"});it(e,n),e.collapse(!1),it(e,r),n.compareDocumentPosition(r)&b&&(n.id=yt,r.id=_t,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},St._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(_t),r=t.getElementById(yt);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:j.call(i.childNodes,n),endOffset:j.call(a.childNodes,r)};i===a&&(s.endOffset-=1),g(n),g(r),E(i,s),i!==a&&E(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ct(e),o&&e.collapse(!0)}return e||null},St._docWasChanged=function(e){var t=e&&e.keyCode;(!e||!e.ctrlKey&&!e.metaKey&&!e.altKey&&(16>t||t>20)&&(33>t||t>45))&&(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),this.fireEvent("input"))},St._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},St.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===R)return!1;o=new n(a,A,function(e){return lt(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},St._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=C(this.createElement(e,t)),it(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{i=new n(r.commonAncestorContainer,A,function(e){return lt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,a.nodeType!==R&&(a=i.nextNode(),d=0);do c=i.currentNode,f=!u(c,e,t),f&&(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),o=this.createElement(e,t),v(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(s=c,l=c.length),r=this._createRange(a,d,s,l)}return r},St._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(G?(i=a.createTextNode("​"),this._didAddZWS()):i=a.createTextNode(""),it(n,i));for(var d=n.commonAncestorContainer;s(d);)d=d.parentNode;var l=n.startContainer,c=n.startOffset,f=n.endContainer,h=n.endOffset,u=[],p=function(e,t){if(!lt(n,e,!1)){var r,o,i=e.nodeType===R;if(!lt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===f&&h!==e.length&&u.push([t,e.splitText(h)]),e===l&&c&&(e.splitText(c),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},m=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return lt(n,r,!0)&&o(r,e,t)});r||m.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)}),m.forEach(function(e){v(e,N(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var g={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return E(d,g),n.setStart(g.startContainer,g.startOffset),n.setEnd(g.endContainer,g.endOffset),n},St.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n),t&&(n=this._removeFormat(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=this._addFormat(e.tag.toUpperCase(),e.attributes||{},n)),this.setSelection(n),this._updatePath(n,!0),this._docWasChanged(),this):void 0};var Et={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},Tt=function(e,t,n){var r=Et[e.nodeName],o=y(t,n,e.parentNode);return o.nodeName!==r&&(e=S(o.ownerDocument,r),e.className="rtl"===o.dir?"dir-rtl":"",e.dir=o.dir,v(o,e),e.appendChild(N(o)),o=e),o};St.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&(this._recordUndoState(n),this._getRangeAndRemoveBookmark(n));var r=ht(n),o=ut(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),this._docWasChanged()),this},St.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),vt(t);var n,r=this._body;return ft(t,r),n=at(t,r),it(t,e.call(this,n)),t.endOffsett;t+=1){for(o=d[t],i=N(o),a=i.childNodes,r=a.length;r--;)s=a[r],v(s,N(s));_(i),v(o,i)}return e},Dt=function(e){var t,n,r,o,i,a=e.querySelectorAll("LI");for(t=0,n=a.length;n>t;t+=1)r=a[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||v(r,this.createElement("LI",[i=this.createElement(o)])),i.appendChild(r));return e},Ot=function(e){var t=e.querySelectorAll("LI");return Array.prototype.filter.call(t,function(e){return!l(e.firstChild)}).forEach(function(t){var n,r=t.parentNode,o=r.parentNode,i=t.firstChild,a=i;for(t.previousSibling&&(r=y(r,t,o));a&&(n=a.nextSibling,!l(a));)o.insertBefore(a,r),a=n;for("LI"===o.nodeName&&i.previousSibling&&y(o,i,o.parentNode);t!==e&&!t.childNodes.length;)r=t.parentNode,r.removeChild(t),t=r},this),_(e),e},It=/\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,Pt=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,A,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=It.exec(r);)a=i.index,s=a+i[0].length,a&&(d=l.createTextNode(r.slice(0,a)),o.insertBefore(d,t)),d=l.createElement("A"),d.textContent=r.slice(a,s),d.href=i[1]?/^(?:ht|f)tps?:/.test(i[1])?i[1]:"http://"+i[1]:"mailto:"+i[2],o.insertBefore(d,t),t.data=r=r.slice(s)},Ut=/^(?: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)$/,wt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Ft={backgroundColor:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color: "+t})}},color:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return S(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return S(e,"I")}},fontFamily:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:Y,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Vt=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Ht={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Ft)r=Ft[n],o=d[n],o&&r.regexp.test(o)&&(s=r.replace(l,o),i&&i.appendChild(s),i=s,a||(a=s));return a&&(i.appendChild(N(e)),t.replaceChild(a,e)),i||e},STRONG:Vt("B"),EM:Vt("I"),STRIKE:Vt("S"),FONT:function(e,t){var n,r,o,i,a,s=e.face,d=e.size,l=e.color,c=e.ownerDocument;return s&&(n=S(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=S(c,"SPAN",{"class":"size",style:"font-size:"+wt[d]+"px"}),a||(a=r),i&&i.appendChild(r),i=r),l&&/^#?([\dA-F]{3}){1,2}$/i.test(l)&&("#"!==l.charAt(0)&&(l="#"+l),o=S(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=S(c,"SPAN")),t.replaceChild(a,e),i.appendChild(N(e)),i},TT:function(e,t){var n=S(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(N(e)),n}},Wt=function(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType===L&&"IMG"!==t.nodeName&&(Wt(t),s(t)&&!t.firstChild&&e.removeChild(t))},Mt=function(e,t){var n,r,o,i,a,d,l,c,f,h,u=e.childNodes;for(n=0,r=u.length;r>n;n+=1)if(o=u[n],i=o.nodeName,a=o.nodeType,d=Ht[i],a===L){if(l=o.childNodes.length,d)o=d(o,e);else{if(!Ut.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}!t&&o.style.cssText&&o.removeAttribute("style")}l&&Mt(o,t)}else{if(a===R){if(c=o.data,/\S/.test(c)){if(s(e))continue;if(f=0,h=c.length,!n||!s(u[n-1])){for(;h>f&&!Y.test(c.charAt(f));)f+=1;f&&(o.data=c=c.slice(f),h-=f)}if(n+1===r||!s(u[n+1])){for(f=h;f>0&&!Y.test(c.charAt(f-1));)f-=1;h>f&&(o.data=c.slice(0,f))}continue}if(n&&r>n+1&&s(u[n-1])&&s(u[n+1])){o.data=" ";continue}}e.removeChild(o),n-=1,r-=1}return e},Kt=function(e){return e.nodeType===L?"BR"===e.nodeName:Y.test(e.data)},zt=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,x|A,Kt),t.currentNode=e,!!t.nextNode()},Zt=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=zt(o[t]);for(;a--;)if(n=o[a],r=n.parentNode){for(;s(r);)r=r.parentNode;if(d(r)){if(i[a]){if("DIV"!==r.nodeName)continue;y(n.parentNode,n,r.parentNode)}g(n)}else _(r)}};St._ensureBottomLine=function(){var e=this._body,t=e.lastChild;t&&"DIV"===t.nodeName&&d(t)||e.appendChild(this.createDefaultBlock())},St._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)},St._onPaste=function(e){if(!this._awaitingPaste){var t,n,r=e.clipboardData,o=r&&r.items,i=!1,a=!1;if(o){for(t=o.length;t--;){if(n=o[t].type,"text/html"===n){a=!1;break}/^image\/.*/.test(n)&&(a=!0)}if(a)return e.preventDefault(),this.fireEvent("dragover",{dataTransfer:r,preventDefault:function(){i=!0}}),void(i&&this.fireEvent("drop",{dataTransfer:r}))}this._awaitingPaste=!0;var s=this,d=this._body,l=this.getSelection(),c=l.startContainer,f=l.startOffset,u=l.endContainer,p=l.endOffset,m=ht(l);s._recordUndoState(l),s._getRangeAndRemoveBookmark(l);var v=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(d.scrollTop+(m?m.getBoundingClientRect().top:0))+"px; left: 0; width: 1px; height: 1px;"});d.appendChild(v),l.selectNodeContents(v),this.setSelection(l),setTimeout(function(){try{var e=N(g(v)),t=e.firstChild,n=s._createRange(c,f,u,p);if(t){t===e.lastChild&&"DIV"===t.nodeName&&e.replaceChild(N(t),t),e.normalize(),Pt(e),Mt(e,!1),Zt(e),Wt(e);for(var r=e,o=!0;r=h(r);)C(r);s.fireEvent("willPaste",{fragment:e,preventDefault:function(){o=!1}}),o&&(dt(n,e),s._docWasChanged(),n.collapse(!1),s._ensureBottomLine())}s.setSelection(n),s._updatePath(n,!0),s._awaitingPaste=!1}catch(i){s.didError(i)}},0)}};var qt={8:"backspace",9:"tab",13:"enter",32:"space",37:"left",39:"right",46:"delete",219:"[",221:"]"},Gt=function(e){return function(t,n){n.preventDefault(),t[e]()}},Qt=function(e,t){return t=t||null,function(n,r){r.preventDefault();var o=n.getSelection();n.hasFormat(e,null,o)?n.changeFormat(null,{tag:e},o):n.changeFormat({tag:e},t,o)}},$t=function(e){try{var t,n=e.getSelection(),r=n.startContainer;if(r.nodeType===R&&(r=r.parentNode),s(r)&&!r.textContent){do t=r.parentNode;while(s(t)&&!t.textContent&&(r=t));n.setStart(t,j.call(t.childNodes,r)),n.collapse(!0),t.removeChild(r),d(t)||(t=f(t)),C(t),ct(n),e.setSelection(n),e._updatePath(n)}e._ensureBottomLine()}catch(o){e.didError(o)}};M&&(St._ieSelAllClean=function(){var e=this._body.firstChild;"P"===e.nodeName&&(this._saveRangeToBookmark(this.getSelection()),v(e,this.createDefaultBlock([N(e)])),this.setSelection(this._getRangeAndRemoveBookmark()))});var Yt={enter:function(e,t){t.preventDefault();var n,r,o,i,a,s=e.getSelection();if(s){if(e._recordUndoState(s),Pt(s.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(s),s.collapsed||st(s),n=ht(s),n&&(r=u(n,"LI"))&&(n=r),o=n?n.nodeName:"DIV",i=Et[o],!n)return it(s,e.createElement("BR")),s.collapse(!1),e.setSelection(s),e._updatePath(s,!0),void e._docWasChanged();var d,l=s.startContainer,c=s.startOffset;if(i||(l===n&&(l=c?l.childNodes[c-1]:null,c=0,l&&("BR"===l.nodeName?l=l.nextSibling:c=m(l),l&&"BR"!==l.nodeName||(d=C(e.createElement("DIV")),l?n.replaceChild(d,l):n.appendChild(d),l=d))),_(n),i="DIV",l||(l=n.firstChild),s.setStart(l,c),s.setEnd(l,c),n=ht(s)),!n.textContent){if(u(n,"UL")||u(n,"OL"))return e.modifyBlocks(Ot,s);if(u(n,"BLOCKQUOTE"))return e.modifyBlocks(bt,s)}for(a=Tt(n,l,c);a.nodeType===L;){var f,h=a.firstChild;if("A"!==a.nodeName){for(;h&&h.nodeType===R&&!h.data&&(f=h.nextSibling,f&&"BR"!==f.nodeName);)g(h),h=f;if(!h||"BR"===h.nodeName||h.nodeType===R&&!K)break;a=h}else v(a,N(a)),a=h}s=e._createRange(a,0),e.setSelection(s),e._updatePath(s,!0),a.nodeType===R&&(a=a.parentNode);var p=e._doc,S=e._body;a.offsetTop+a.offsetHeight>(p.documentElement.scrollTop||S.scrollTop)+S.offsetHeight&&a.scrollIntoView(!1),e._docWasChanged()}},backspace:function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(mt(n)){t.preventDefault();var r=ht(n),o=r&&f(r);if(o){if(!o.isContentEditable)return void g(o);for(T(o,r,n),r=o.parentNode;r&&!r.nextSibling;)r=r.parentNode;r&&(r=r.nextSibling)&&B(r),e.setSelection(n)}else if(r){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(Ot,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(kt,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},"delete":function(e,t){e._removeZWS();var n=e.getSelection();if(e._recordUndoState(n),e._getRangeAndRemoveBookmark(n),n.collapsed)if(gt(n)){t.preventDefault();var r=ht(n),o=r&&h(r);if(o){if(!o.isContentEditable)return void g(o);for(T(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&B(o),e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){$t(e)},0);else t.preventDefault(),st(n),e._ensureBottomLine(),e.setSelection(n),e._updatePath(n,!0)},tab:function(e,t){e._removeZWS();var n,r,o=e.getSelection();if(o.collapsed&&mt(o)&>(o)){for(n=ht(o);r=n.parentNode;){if("UL"===r.nodeName||"OL"===r.nodeName){n.previousSibling&&(t.preventDefault(),e.modifyBlocks(Dt,o));break}n=r}t.preventDefault()}},space:function(e){var t=e.getSelection();e._recordUndoState(t),Pt(t.startContainer),e._getRangeAndRemoveBookmark(t),e.setSelection(t)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&H&&U.getSelection().modify&&(Yt["meta-left"]=function(e,t){t.preventDefault(),e._sel.modify("move","backward","lineboundary")},Yt["meta-right"]=function(e,t){t.preventDefault(),e._sel.modify("move","forward","lineboundary")}),Yt[Z+"b"]=Qt("B"),Yt[Z+"i"]=Qt("I"),Yt[Z+"u"]=Qt("U"),Yt[Z+"shift-7"]=Qt("S"),Yt[Z+"shift-5"]=Qt("SUB",{tag:"SUP"}),Yt[Z+"shift-6"]=Qt("SUP",{tag:"SUB"}),Yt[Z+"shift-8"]=Gt("makeUnorderedList"),Yt[Z+"shift-9"]=Gt("makeOrderedList"),Yt[Z+"["]=Gt("decreaseQuoteLevel"),Yt[Z+"]"]=Gt("increaseQuoteLevel"),Yt[Z+"y"]=Gt("redo"),Yt[Z+"z"]=Gt("undo"),Yt[Z+"shift-z"]=Gt("redo"),St._onKey=function(e){var t=e.keyCode,n=qt[t],r="";n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),K&&46===e.which&&(n="."),t>111&&124>t&&(n="f"+(t-111)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-")),e.shiftKey&&(r+="shift-"),n=r+n,Yt[n]&&Yt[n](this,e)},St._getHTML=function(){return this._body.innerHTML},St._setHTML=function(e){var t=this._body;t.innerHTML=e;do C(t);while(t=h(t))},St.getHTML=function(e){var t,n,r,o,i,a=[];if(e&&(i=this.getSelection())&&this._saveRangeToBookmark(i),q)for(t=this._body;t=h(t);)t.textContent||t.querySelector("BR")||(n=this.createElement("BR"),t.appendChild(n),a.push(n));if(r=this._getHTML().replace(/\u200B/g,""),q)for(o=a.length;o--;)g(a[o]);return i&&this._getRangeAndRemoveBookmark(i),r},St.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV");r.innerHTML=e,n.appendChild(N(r)),Mt(n,!0),Zt(n),_(n);for(var o=n;o=h(o);)C(o);for(var i=this._body;t=i.lastChild;)i.removeChild(t);i.appendChild(n),C(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),Q?this._lastSelection=a:this.setSelection(a),this._updatePath(a,!0),this
     },St.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),s(e))it(t,e),t.setStartAfter(e);else{for(var n,r,o=this._body,i=ht(t)||o;i!==o&&!i.nextSibling;)i=i.parentNode;i!==o&&(n=i.parentNode,r=y(n,i.nextSibling,o)),r?(o.insertBefore(e,r),t.setStart(r,0),t.setStart(r,0),ct(t)):(o.appendChild(e),o.appendChild(this.createDefaultBlock()),t.setStart(e,0),t.setEnd(e,0)),this.focus(),this.setSelection(t),this._updatePath(t)}return this},St.insertImage=function(e){var t=this.createElement("IMG",{src:e});return this.insertElement(t),t};var jt=function(e,t,n){return function(){return this[e](t,n),this.focus()}};St.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.styleSheet?(t.appendChild(n),n.styleSheet.cssText=e):(n.appendChild(this._doc.createTextNode(e)),t.appendChild(n))}return this},St.bold=jt("changeFormat",{tag:"B"}),St.italic=jt("changeFormat",{tag:"I"}),St.underline=jt("changeFormat",{tag:"U"}),St.strikethrough=jt("changeFormat",{tag:"S"}),St.subscript=jt("changeFormat",{tag:"SUB"},{tag:"SUP"}),St.superscript=jt("changeFormat",{tag:"SUP"},{tag:"SUB"}),St.removeBold=jt("changeFormat",null,{tag:"B"}),St.removeItalic=jt("changeFormat",null,{tag:"I"}),St.removeUnderline=jt("changeFormat",null,{tag:"U"}),St.removeStrikethrough=jt("changeFormat",null,{tag:"S"}),St.removeSubscript=jt("changeFormat",null,{tag:"SUB"}),St.removeSuperscript=jt("changeFormat",null,{tag:"SUP"}),St.makeLink=function(e){var t=this.getSelection();if(t.collapsed){var n=e.indexOf(":")+1;if(n)for(;"/"===e[n];)n+=1;it(t,this._doc.createTextNode(e.slice(n)))}return this.changeFormat({tag:"A",attributes:{href:e}},{tag:"A"},t),this.focus()},St.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},St.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},St.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()},St.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color: "+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},St.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},St.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()},St.setTextDirection=function(e){return this.forEachBlock(function(t){t.className=(t.className.split(/\s+/).filter(function(e){return!/dir/.test(e)}).join(" ")+" dir-"+e).trim(),t.dir=e},!0),this.focus()},St.increaseQuoteLevel=jt("modifyBlocks",Bt),St.decreaseQuoteLevel=jt("modifyBlocks",kt),St.makeUnorderedList=jt("modifyBlocks",Rt),St.makeOrderedList=jt("modifyBlocks",xt),St.removeList=jt("modifyBlocks",At),St.increaseListLevel=jt("modifyBlocks",Dt),St.decreaseListLevel=jt("modifyBlocks",Ot),top!==U?(U.editor=new k(e),U.onEditorLoad&&(U.onEditorLoad(U.editor),U.onEditorLoad=null)):U.Squire=k}(document);
    \ No newline at end of file
    diff --git a/source/Editor.js b/source/Editor.js
    index d73137b..da7eb1f 100644
    --- a/source/Editor.js
    +++ b/source/Editor.js
    @@ -339,11 +339,10 @@ proto._updatePathOnEvent = function () {
     // --- Focus ---
     
     proto.focus = function () {
    -    // FF seems to need the body to be focussed
    -    // (at least on first load).
    -    if ( isGecko ) {
    -        this._body.focus();
    -    }
    +    // FF seems to need the body to be focussed (at least on first load).
    +    // Chrome also now needs body to be focussed in order to show the cursor
    +    // (otherwise it is focussed, but the cursor doesn't appear).
    +    this._body.focus();
         this._win.focus();
         return this;
     };
    
    From cd30857ba4dd12449286be727aa9de1fde2a8f02 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Rafa=C5=82=20Filipek?= 
    Date: Mon, 8 Dec 2014 10:45:30 +0100
    Subject: [PATCH 19/24] Convention
    
    ---
     License.txt => LICENSE | 0
     Readme.md => README.md | 0
     2 files changed, 0 insertions(+), 0 deletions(-)
     rename License.txt => LICENSE (100%)
     rename Readme.md => README.md (100%)
    
    diff --git a/License.txt b/LICENSE
    similarity index 100%
    rename from License.txt
    rename to LICENSE
    diff --git a/Readme.md b/README.md
    similarity index 100%
    rename from Readme.md
    rename to README.md
    
    From 608c498f95760ba24b7484045d74ab13f676c4d3 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Rafa=C5=82=20Filipek?= 
    Date: Mon, 8 Dec 2014 10:45:52 +0100
    Subject: [PATCH 20/24] Missing bower.json
    
    ---
     bower.json | 25 +++++++++++++++++++++++++
     1 file changed, 25 insertions(+)
     create mode 100644 bower.json
    
    diff --git a/bower.json b/bower.json
    new file mode 100644
    index 0000000..2f23d4f
    --- /dev/null
    +++ b/bower.json
    @@ -0,0 +1,25 @@
    +{
    +  "name": "Squire",
    +  "version": "0.0.1",
    +  "homepage": "https://github.com/neilj/Squire",
    +  "authors": [
    +    "Neil Jenkins "
    +  ],
    +  "description": "Squire is an HTML5 rich text editor, which provides powerful cross-browser normalisation, whilst being supremely lightweight and flexible.",
    +  "main": "build/squire.js",
    +  "keywords": [
    +    "wysiwyg",
    +    "editor",
    +    "text",
    +    "html",
    +    "squire"
    +  ],
    +  "license": "MIT",
    +  "ignore": [
    +    "**/.*",
    +    "node_modules",
    +    "bower_components",
    +    "test",
    +    "tests"
    +  ]
    +}
    
    From 9107a34ee5228d88e6521c0ea7466d892145491c Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Rafa=C5=82=20Filipek?= 
    Date: Mon, 8 Dec 2014 10:46:01 +0100
    Subject: [PATCH 21/24] Missing package.json
    
    ---
     package.json | 29 +++++++++++++++++++++++++++++
     1 file changed, 29 insertions(+)
     create mode 100644 package.json
    
    diff --git a/package.json b/package.json
    new file mode 100644
    index 0000000..85d5259
    --- /dev/null
    +++ b/package.json
    @@ -0,0 +1,29 @@
    +{
    +  "name": "Squire",
    +  "version": "0.0.1",
    +  "description": "Squire is an HTML5 rich text editor, which provides powerful cross-browser normalisation, whilst being supremely lightweight and flexible.",
    +  "main": "build/squire.js",
    +  "scripts": {
    +    "test": "echo \"Error: no test specified\" && exit 1"
    +  },
    +  "repository": {
    +    "type": "git",
    +    "url": "https://github.com/neilj/Squire.git"
    +  },
    +  "keywords": [
    +    "wysiwyg",
    +    "editor",
    +    "text",
    +    "html",
    +    "squire"
    +  ],
    +  "author": "Neil Jenkins",
    +  "license": "MIT",
    +  "bugs": {
    +    "url": "https://github.com/neilj/Squire/issues"
    +  },
    +  "homepage": "https://github.com/neilj/Squire",
    +  "devDependencies": {
    +    "uglify-js": "^2.4.15"
    +  }
    +}
    
    From 65e2f62073bf3e9d6867f92699ef6e9bef1ee031 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Rafa=C5=82=20Filipek?= 
    Date: Mon, 8 Dec 2014 10:46:15 +0100
    Subject: [PATCH 22/24] Default .gitignore
    
    ---
     .gitignore | 2 ++
     1 file changed, 2 insertions(+)
     create mode 100644 .gitignore
    
    diff --git a/.gitignore b/.gitignore
    new file mode 100644
    index 0000000..a088b6f
    --- /dev/null
    +++ b/.gitignore
    @@ -0,0 +1,2 @@
    +node_modules
    +bower_components
    
    From 0394b4c3d87add7073006c90f10d0e7e5c93eb57 Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Rafa=C5=82=20Filipek?= 
    Date: Mon, 8 Dec 2014 10:46:35 +0100
    Subject: [PATCH 23/24] Updated Makefile
    
    ---
     Makefile | 7 +++++--
     1 file changed, 5 insertions(+), 2 deletions(-)
    
    diff --git a/Makefile b/Makefile
    index 7218dd2..b3991f2 100644
    --- a/Makefile
    +++ b/Makefile
    @@ -1,6 +1,9 @@
     .PHONY: all build clean
     
    -all: build
    +all: install build
    +
    +intall:
    +	npm install
     
     clean:
     	rm -rf build
    @@ -12,7 +15,7 @@ build/squire-raw.js: source/intro.js source/Constants.js source/TreeWalker.js so
     	cat $^ >$@
     
     build/squire.js: build/squire-raw.js
    -	uglifyjs $^ -c -m -o $@
    +	./node_modules/uglify-js/bin/uglifyjs $^ -c -m -o $@
     
     build/document.html: source/document.html
     	mkdir -p $(@D)
    
    From 6f5344040053544753a706604f5dd7a8c07dd87e Mon Sep 17 00:00:00 2001
    From: Neil Jenkins 
    Date: Tue, 9 Dec 2014 11:00:28 +1100
    Subject: [PATCH 24/24] Minor license/readme update.
    
    ---
     LICENSE   | 6 ++++--
     README.md | 2 +-
     2 files changed, 5 insertions(+), 3 deletions(-)
    
    diff --git a/LICENSE b/LICENSE
    index c5f4f6b..06cfb74 100644
    --- a/LICENSE
    +++ b/LICENSE
    @@ -1,4 +1,6 @@
    -Copyright © 2011 by Neil Jenkins
    +The MIT License (MIT)
    +
    +Copyright © 2011–2014 by Neil Jenkins
     
     Permission is hereby granted, free of charge, to any person obtaining a copy
     of this software and associated documentation files (the "Software"), to
    @@ -16,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    -IN THE SOFTWARE.
    \ No newline at end of file
    +IN THE SOFTWARE.
    diff --git a/README.md b/README.md
    index cb0c7d0..22cb6c3 100644
    --- a/README.md
    +++ b/README.md
    @@ -7,7 +7,7 @@ Unlike other HTML5 rich text editors, Squire was written as a component for writ
     
     ### Lightweight ###
     
    -* Only 10KB of JS after minification and gzip (33KB before gzip).
    +* Only 11.5KB of JS after minification and gzip (35KB before gzip).
     * Does not include its own XHR wrapper, widget library or lightbox overlays.
     * No dependencies.
     * No UI for a toolbar is supplied, allowing you to integrate seamlessly with the