From 072a2d9fce2b846e76defef0f72e49e7ab9a5104 Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Thu, 24 Mar 2016 13:45:36 +1100 Subject: [PATCH] Add getCursorPosition method, remove scrollRangeIntoView Scrolling depends so much on the integration. Better to allow the cursor position to be fetched, and then the integration can do the scrolling when it wants (for example on each "input" event). --- README.md | 5 +++++ build/squire-raw.js | 25 +++++++++++++------------ build/squire.js | 4 ++-- source/Editor.js | 25 +++++++++++++------------ 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index abf0bd0..5d9c003 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,11 @@ Returns the path through the DOM tree from the `` element to the current c Returns an object containing the active font family, size, colour and background colour for the the current cursor position, if any are set. The property names are respectively `family`, `size`, `color` and `backgroundColor`. It looks at style attributes to detect this, so will not detect `` tags or non-inline styles. If a selection across multiple elements has been made, it will return an empty object. +### getCursorPosition + +Returns a bounding client rect (top/left/right/bottom properties relative to +the viewport) for the current selection/cursor. + ### getSelection Returns a [W3C Range object](https://developer.mozilla.org/en-US/docs/Web/API/Range) representing the current selection/cursor position. diff --git a/build/squire-raw.js b/build/squire-raw.js index f6e2ef4..5c8c7c1 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -2390,8 +2390,7 @@ proto.getDocument = function () { // document node, since these events are fired in a custom manner by the // editor code. var customEvents = { - pathChange: 1, select: 1, input: 1, - undoStateChange: 1, scrollPointIntoView: 1 + pathChange: 1, select: 1, input: 1, undoStateChange: 1 }; proto.fireEvent = function ( type, event ) { @@ -2504,26 +2503,29 @@ proto._createRange = return domRange; }; -proto.scrollRangeIntoView = function ( range ) { +proto.getCursorPosition = function ( range ) { + if ( !range && !( range = this.getSelection() ) ) { + return null; + } // Get the bounding rect var rect = range.getBoundingClientRect(); var node, parent; if ( rect && !rect.top ) { + this._ignoreChange = true; node = this._doc.createElement( 'SPAN' ); - range = range.cloneRange(); + node.textContent = ZWS; insertNodeInRange( range, node ); rect = node.getBoundingClientRect(); parent = node.parentNode; parent.removeChild( node ); - parent.normalize(); - } - // And fire event for integrations to use - if ( rect ) { - this.fireEvent( 'scrollPointIntoView', { - x: rect.left, - y: rect.top + mergeInlines( parent, { + startContainer: range.startContainer, + endContainer: range.endContainer, + startOffset: range.startOffset, + endOffset: range.endOffset }); } + return rect; }; proto._moveCursorTo = function ( toStart ) { @@ -2557,7 +2559,6 @@ proto.setSelection = function ( range ) { if ( sel ) { sel.removeAllRanges(); sel.addRange( range ); - this.scrollRangeIntoView( range ); } } return this; diff --git a/build/squire.js b/build/squire.js index a9fd8fd..679aa9c 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){return e.nodeType===D&&!!st[e.nodeName]}function i(e){return at.test(e.nodeName)}function a(e){var t=e.nodeType;return(t===D||t===U)&&!i(e)&&r(e.childNodes,i)}function s(e){var t=e.nodeType;return!(t!==D&&t!==U||i(e)||a(e))}function d(e,t){var r=new n(t,P,a,!1);return r.currentNode=e,r}function l(e,t){return e=d(e,t).previousNode(),e!==t?e:null}function c(e,t){return e=d(e,t).nextNode(),e!==t?e:null}function f(e,t){return!o(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function h(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 u(e,t,n,r){for(;e&&e!==t;){if(h(e,n,r))return e;e=e.parentNode}return null}function p(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function g(e,t){var n,r,o,i,a,s=e.parentNode;return e===t?n="":(n=g(s,t),e.nodeType===D&&(n+=(n?">":"")+e.nodeName,(r=e.id)&&(n+="#"+r),(o=e.className.trim())&&(i=o.split(/\s\s*/),i.sort(),n+=".",n+=i.join(".")),(a=e.dir)&&(n+="[dir="+a+"]"))),n}function m(e){var t=e.nodeType;return t===D?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(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 _(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=k(a).createDefaultBlock(),r?e.replaceChild(n,r):e.appendChild(n),e=n,n=null)),i(e)){for(r=e.firstChild;et&&r&&r.nodeType===R&&!r.data;)e.removeChild(r),r=e.firstChild;r||(et?(n=a.createTextNode(z),k(a)._didAddZWS()):n=a.createTextNode(""))}else if(J){for(;e.nodeType!==R&&!o(e);){if(r=e.firstChild,!r){n=a.createTextNode("");break}e=r}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):o(e)&&e.parentNode.insertBefore(a.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=S(a,"BR");(r=e.lastElementChild)&&!i(r);)e=r;return n&&e.appendChild(n),s}function y(e,t){var n,r,o,a,d=e.childNodes,l=e.ownerDocument,c=null,f=k(l)._config;for(n=0,r=d.length;r>n;n+=1)o=d[n],a="BR"===o.nodeName,!a&&i(o)?(c||(c=S(l,f.blockTag,f.blockAttributes)),c.appendChild(o),n-=1,r-=1):(a||c)&&(c||(c=S(l,f.blockTag,f.blockAttributes)),_(c,t),a?e.replaceChild(c,o):(e.insertBefore(c,o),n+=1,r+=1),c=null),s(o)&&y(o,t);return c&&e.appendChild(_(c,t)),e}function T(e,t,n,r){var o,i,a,s=e.nodeType;if(s===R&&e!==n)return T(e.parentNode,e.splitText(t),n,r);if(s===D){if("number"==typeof t&&(t=ts?t.startOffset-=1:t.startOffset===s&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=r,t.endOffset=m(r))),v(n),n.nodeType===R?r.appendData(n.data):d.push(N(n));else if(n.nodeType===D){for(o=d.length;o--;)n.appendChild(d.pop());b(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(N(t)),b(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Q&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function x(e,t){var n,r,o=e.previousSibling,i=e.firstChild,a=e.ownerDocument,d="LI"===e.nodeName;if(!d||i&&/^[OU]L$/.test(i.nodeName))if(o&&f(o,e)){if(!s(o)){if(!d)return;r=S(a,"DIV"),r.appendChild(N(o)),o.appendChild(r)}v(e),n=!s(e),o.appendChild(N(e)),n&&y(o,t),i&&x(i,t)}else d&&(o=S(a,"DIV"),e.insertBefore(o,i),_(o,t))}function k(e){for(var t,n=qt.length;n--;)if(t=qt[n],t._doc===e)return t;return null}function B(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?B(e[n],r):r;return e}function O(e,t){e.nodeType===I&&(e=e.body);var n,r=e.ownerDocument,o=r.defaultView;this._win=o,this._doc=r,this._root=e,this._events={},this._lastSelection=null,tt&&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),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,nt?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._awaitingPaste=!1,this.addEventListener(j?"beforecut":"cut",Wt),this.addEventListener("copy",zt),this.addEventListener(j?"beforepaste":"paste",Kt),this.addEventListener(Q?"keypress":"keydown",bt),this._keyHandlers=Object.create(Bt),this.setConfig(t),j&&(o.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}),e.setAttribute("contenteditable","true");try{r.execCommand("enableObjectResizing",!1,"false"),r.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}qt.push(this),this.setHTML("")}function L(e,t,n){var r,o;for(r=t.firstChild;r;r=o){if(o=r.nextSibling,i(r)){if(r.nodeType===R||"BR"===r.nodeName||"IMG"===r.nodeName){n.appendChild(r);continue}}else if(a(r)){n.appendChild(e.createDefaultBlock([L(e,r,e._doc.createDocumentFragment())]));continue}L(e,r,n)}return n}var A=2,D=1,R=3,I=9,U=11,P=1,w=4,F=0,M=1,H=2,W=3,z="​",K=e.defaultView,q=navigator.userAgent,V=/iP(?:ad|hone|od)/.test(q),Z=/Mac OS X/.test(q),G=/Gecko\//.test(q),j=/Trident\/[456]\./.test(q),Q=!!K.opera,$=/Edge\//.test(q),Y=!$&&/WebKit\//.test(q),X=Z?"meta-":"ctrl-",J=j||Q,et=j||Y,tt=j,nt="undefined"!=typeof MutationObserver,rt=/[^ \t\r\n]/,ot=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var it={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(it[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(it[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)e=t.previousSibling,e||(t=t.parentNode);if(!e)return null;if(it[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var at=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|U|VAR|WBR)$/,st={BR:1,IMG:1,INPUT:1},dt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===D;)e=n[t-1],n=e.childNodes,t=n.length;return e},lt=function(e,t){if(e.nodeType===D){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(M,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(F,r)<1,s=e.compareBoundaryPoints(H,r)>-1;return a&&s},gt=function(e){for(var t,n=e.startContainer,r=e.startOffset,i=e.endContainer,a=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!o(t));)n=t,r=0;if(a)for(;i.nodeType!==R&&(t=i.childNodes[a-1],t&&!o(t));)i=t,a=m(i);else for(;i.nodeType!==R&&(t=i.firstChild,t&&!o(t));)i=t;e.collapsed?(e.setStart(i,a),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(i,a))},mt=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=ot.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=ot.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},vt=function(e,t){var n,r=e.startContainer;return i(r)?n=l(r,t):a(r)?n=r:(n=dt(r,e.startOffset),n=c(n,t)),n&&pt(e,n,!0)?n:null},Ct=function(e,t){var n,r,o=e.endContainer;if(i(o))n=l(o,t);else if(a(o))n=o;else{if(n=lt(o,e.endOffset),!n)for(n=t;r=n.lastChild;)n=r;n=l(n,t)}return n&&pt(e,n,!0)?n:null},Nt=new n(null,w|P,function(e){return e.nodeType===R?rt.test(e.data):"IMG"===e.nodeName}),St=function(e,t){var n=e.startContainer,r=e.startOffset;if(Nt.root=null,n.nodeType===R){if(r)return!1;Nt.currentNode=n}else Nt.currentNode=lt(n,r);return Nt.root=vt(e,t),!Nt.previousNode()},_t=function(e,t){var n,r=e.endContainer,o=e.endOffset;if(Nt.root=null,r.nodeType===R){if(n=r.data.length,n&&n>o)return!1;Nt.currentNode=r}else Nt.currentNode=dt(r,o);return Nt.root=Ct(e,t),!Nt.nextNode()},yt=function(e,t){var n,r=vt(e,t),o=Ct(e,t);r&&o&&(n=r.parentNode,e.setStart(n,ot.call(n.childNodes,r)),n=o.parentNode,e.setEnd(n,ot.call(n.childNodes,o)+1))},Tt={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},bt=function(e){var t=e.keyCode,n=Tt[t],r="",o=this.getSelection();e.defaultPrevented||(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)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-")),e.shiftKey&&(r+="shift-"),n=r+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,o):1!==n.length||o.collapsed||(this.saveUndoState(o),ht(o,this._root),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},Et=function(e){return function(t,n){n.preventDefault(),t[e]()}},xt=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)}},kt=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===R&&(r=r.parentNode),n=r;i(n)&&(!n.textContent||n.textContent===z);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,ot.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),a(n)||(n=l(n,e._root)),_(n,e._root),gt(t)),r===e._root&&(r=r.firstChild)&&"BR"===r.nodeName&&v(r),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(o){e.didError(o)}},Bt={enter:function(e,t,n){var r,o,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),cn(n.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||ht(n,a),r=vt(n,a),!r||/^T[HD]$/.test(r.nodeName))return ct(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((o=u(r,a,"LI"))&&(r=o),!r.textContent){if(u(r,a,"UL")||u(r,a,"OL"))return e.modifyBlocks(dn,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(tn,n)}for(i=Xt(e,r,n.startContainer,n.startOffset),jt(r),wt(r),_(r,a);i.nodeType===D;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===z)){d=e._doc.createTextNode(""),C(i,d),i=d;break}for(;d&&d.nodeType===R&&!d.data&&(s=d.nextSibling,s&&"BR"!==s.nodeName);)v(d),d=s;if(!d||"BR"===d.nodeName||d.nodeType===R&&!Q)break;i=d}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){var r=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(St(n,r)){t.preventDefault();var o,i=vt(n,r);if(!i)return;if(y(i.parentNode,r),o=l(i,r)){if(!o.isContentEditable)return void v(o);for(E(o,i,n),i=o.parentNode;i&&!i.nextSibling;)i=i.parentNode;i&&(i=i.nextSibling)&&x(i,r),e.setSelection(n)}else if(i){if(u(i,r,"UL")||u(i,r,"OL"))return e.modifyBlocks(dn,n);if(u(i,r,"BLOCKQUOTE"))return e.modifyBlocks(en,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){kt(e)},0);else t.preventDefault(),ht(n,r),kt(e,n)},"delete":function(e,t,n){var r,o,i,a,s,d,l=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(_t(n,l)){if(t.preventDefault(),r=vt(n,l),!r)return;if(y(r.parentNode,l),o=c(r,l)){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)&&x(o,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(i=n.cloneRange(),mt(n,e._root),a=n.endContainer,s=n.endOffset,a.nodeType===D&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),v(d),gt(n),void kt(e,n);e.setSelection(i),setTimeout(function(){kt(e)},0)}else t.preventDefault(),ht(n,l),kt(e,n)},tab:function(e,t,n){var r,o,i=e._root;if(e._removeZWS(),n.collapsed&&St(n,i))for(r=vt(n,i);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(sn,n));break}r=o}},"shift-tab":function(e,t,n){var r,o=e._root;e._removeZWS(),n.collapsed&&St(n,o)&&(r=n.startContainer,(u(r,o,"UL")||u(r,o,"OL"))&&(t.preventDefault(),e.modifyBlocks(dn,n)))},space:function(e,t,n){var r,o;e._recordUndoState(n),cn(n.startContainer),e._getRangeAndRemoveBookmark(n),r=n.endContainer,o=r.parentNode,n.collapsed&&"A"===o.nodeName&&!r.nextSibling&&n.endOffset===m(r)&&n.setStartAfter(o),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};Z&&G&&(Bt["meta-left"]=function(e,t){t.preventDefault();var n=Gt(e);n&&n.modify&&n.modify("move","backward","lineboundary")},Bt["meta-right"]=function(e,t){t.preventDefault();var n=Gt(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),Z||(Bt.pageup=function(e){e.moveCursorToStart()},Bt.pagedown=function(e){e.moveCursorToEnd()}),Bt[X+"b"]=xt("B"),Bt[X+"i"]=xt("I"),Bt[X+"u"]=xt("U"),Bt[X+"shift-7"]=xt("S"),Bt[X+"shift-5"]=xt("SUB",{tag:"SUP"}),Bt[X+"shift-6"]=xt("SUP",{tag:"SUB"}),Bt[X+"shift-8"]=Et("makeUnorderedList"),Bt[X+"shift-9"]=Et("makeOrderedList"),Bt[X+"["]=Et("decreaseQuoteLevel"),Bt[X+"]"]=Et("increaseQuoteLevel"),Bt[X+"y"]=Et("redo"),Bt[X+"z"]=Et("undo"),Bt[X+"shift-z"]=Et("redo");var Ot={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Lt={backgroundColor:{regexp:rt,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color:"+t})}},color:{regexp:rt,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:rt,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:rt,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},At=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Dt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Lt)r=Lt[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:At("B"),EM:At("I"),STRIKE:At("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:"+Ot[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}},Rt=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|UL)$/,It=/^(?:HEAD|META|STYLE)/,Ut=new n(null,w|P,function(){return!0}),Pt=function hn(e){var t,n,r,o,a,s,d,l,c,f,h,u,p=e.childNodes;for(t=e;i(t);)t=t.parentNode;for(Ut.root=t,n=0,r=p.length;r>n;n+=1)if(o=p[n],a=o.nodeName,s=o.nodeType,d=Dt[a],s===D){if(l=o.childNodes.length,d)o=d(o,e);else{if(It.test(a)){e.removeChild(o),n-=1,r-=1;continue}if(!Rt.test(a)&&!i(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}}l&&hn(o)}else{if(s===R){if(h=o.data,c=!rt.test(h.charAt(0)),f=!rt.test(h.charAt(h.length-1)),!c&&!f)continue;if(c){for(Ut.currentNode=o;(u=Ut.previousPONode())&&(a=u.nodeName,!("IMG"===a||"#text"===a&&/\S/.test(u.data)));)if(!i(u)){u=null;break}u||(h=h.replace(/^\s+/g,""))}if(f){for(Ut.currentNode=o;(u=Ut.nextNode())&&!("IMG"===a||"#text"===a&&/\S/.test(u.data));)if(!i(u)){u=null;break}u||(h=h.replace(/^\s+/g,""))}if(h){o.data=h;continue}}e.removeChild(o),n-=1,r-=1}return e},wt=function un(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==D||o(t)?t.nodeType!==R||t.data||e.removeChild(t):(un(t),i(t)&&!t.firstChild&&e.removeChild(t))},Ft=function(e){return e.nodeType===D?"BR"===e.nodeName:rt.test(e.data)},Mt=function(e){for(var t,r=e.parentNode;i(r);)r=r.parentNode;return t=new n(r,P|w,Ft),t.currentNode=e,!!t.nextNode()},Ht=function(e,t){var n,r,o,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=Mt(a[n]);for(;d--;)r=a[d],o=r.parentNode,o&&(s[d]?i(o)||y(o,t):v(r))},Wt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._root,i=this;this.saveUndoState(n),$||V||!t?setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0):(mt(n,o),r.appendChild(ht(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},zt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");$||V||!t||(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},Kt=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,f=this;if(!$&&s){for(e.preventDefault(),t=s.length;t--;){if(n=s[t],r=n.type,"text/html"===r)return void n.getAsString(function(e){f.insertHTML(e,!0)});"text/plain"===r&&(c=n),/^image\/.*/.test(r)&&(l=!0)}return void(l?(this.fireEvent("dragover",{dataTransfer:a,preventDefault:function(){d=!0}}),d&&this.fireEvent("drop",{dataTransfer:a})):c&&n.getAsString(function(e){f.insertPlainText(e,!0)}))}if(o=a&&a.types,!$&&o&&(ot.call(o,"text/html")>-1||!G&&ot.call(o,"text/plain")>-1&&ot.call(o,"text/rtf")<0))return e.preventDefault(),void((i=a.getData("text/html"))?this.insertHTML(i,!0):(i=a.getData("text/plain"))&&this.insertPlainText(i,!0));this._awaitingPaste=!0;var h=this._doc.body,u=this.getSelection(),p=u.startContainer,g=u.startOffset,m=u.endContainer,C=u.endOffset,N=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});h.appendChild(N),u.selectNodeContents(N),this.setSelection(u),setTimeout(function(){try{f._awaitingPaste=!1;for(var e,t,n="",r=N;N=r;)r=N.nextSibling,v(N),e=N.firstChild,e&&e===N.lastChild&&"DIV"===e.nodeName&&(N=e),n+=N.innerHTML;t=f._createRange(p,g,m,C),f.setSelection(t),n&&f.insertHTML(n,!0)}catch(o){f.didError(o)}},0)},qt=[],Vt=O.prototype;Vt.setConfig=function(e){return e=B({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},Vt.createElement=function(e,t,n){return S(this._doc,e,t,n)},Vt.createDefaultBlock=function(e){var t=this._config;return _(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},Vt.didError=function(e){console.log(e)},Vt.getDocument=function(){return this._doc};var Zt={pathChange:1,select:1,input:1,undoStateChange:1,scrollPointIntoView:1};Vt.fireEvent=function(e,t){var n,r,o=this._events[e];if(o)for(t||(t={}),t.type!==e&&(t.type=e),o=o.slice(),n=o.length;n--;){r=o[n];try{r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(i){i.details="Squire: fireEvent error. Event type: "+e,this.didError(i)}}return this},Vt.destroy=function(){var e,t=this._root,n=this._events;for(e in n)Zt[e]||t.removeEventListener(e,this,!0);this._mutation&&this._mutation.disconnect();for(var r=qt.length;r--;)qt[r]===this&&qt.splice(r,1)},Vt.handleEvent=function(e){this.fireEvent(e.type,e)},Vt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Zt[e]||this._root.addEventListener(e,this,!0)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Vt.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],Zt[e]||this._root.removeEventListener(e,this,!0))}return this},Vt._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},Vt.scrollRangeIntoView=function(e){var t,n,r=e.getBoundingClientRect();r&&!r.top&&(t=this._doc.createElement("SPAN"),e=e.cloneRange(),ct(e,t),r=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),n.normalize()),r&&this.fireEvent("scrollPointIntoView",{x:r.left,y:r.top})},Vt._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return gt(n),this.setSelection(n),this},Vt.moveCursorToStart=function(){return this._moveCursorTo(!0)},Vt.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var Gt=function(e){return e._win.getSelection()||null};Vt.setSelection=function(e){if(e){V&&this._win.focus();var t=Gt(this);t&&(t.removeAllRanges(),t.addRange(e),this.scrollRangeIntoView(e))}return this},Vt.getSelection=function(){var e,t,n,r=Gt(this),i=this._root;return r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&o(t)&&e.setStartBefore(t),n&&o(n)&&e.setEndBefore(n)),e&&p(i,e.commonAncestorContainer)?this._lastSelection=e:e=this._lastSelection,e||(e=this._createRange(i.firstChild,0)),e},Vt.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,w|P,function(e){return pt(t,e,!0)}),o=t.startContainer,a=t.endContainer,s=r.currentNode=o,d="",l=!1;for(r.filter(s)||(s=r.nextNode());s;)s.nodeType===R?(e=s.data,e&&/\S/.test(e)&&(s===a&&(e=e.slice(0,t.endOffset)),s===o&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===s.nodeName||l&&!i(s))&&(d+="\n",l=!1),s=r.nextNode();return d},Vt.getPath=function(){return this._path};var jt=function(e){for(var t,r,o,a=new n(e,w,function(){return!0},!1);r=a.nextNode();)for(;(o=r.data.indexOf(z))>-1;){if(1===r.length){do t=r.parentNode,t.removeChild(r),r=t,a.currentNode=t;while(i(r)&&!m(r));break}r.deleteData(o,1)}};Vt._didAddZWS=function(){this._hasZWS=!0},Vt._removeZWS=function(){this._hasZWS&&(jt(this._root),this._hasZWS=!1)},Vt._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?g(o,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},Vt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Vt.focus=function(){return this._root.focus(),this},Vt.blur=function(){return this._root.blur(),this};var Qt="squire-selection-start",$t="squire-selection-end";Vt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Qt,type:"hidden"}),r=this.createElement("INPUT",{id:$t,type:"hidden"});ct(e,n),e.collapse(!1),ct(e,r),n.compareDocumentPosition(r)&A&&(n.id=$t,r.id=Qt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Vt._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+Qt),r=t.querySelector("#"+$t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:ot.call(i.childNodes,n),endOffset:ot.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),b(i,s),i!==a&&b(a,s),e||(e=this._doc.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,gt(e),o&&e.collapse(!0)}return e||null},Vt._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},Vt._docWasChanged=function(){return nt&&this._ignoreChange?void(this._ignoreChange=!1):(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),void this.fireEvent("input"))},Vt._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},Vt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;!r.collapsed&&r.startContainer.nodeType===R&&r.startOffset===r.startContainer.length&&r.startContainer.nextSibling&&r.setStartBefore(r.startContainer.nextSibling),!r.collapsed&&r.endContainer.nodeType===R&&0===r.endOffset&&r.endContainer.previousSibling&&r.setEndAfter(r.endContainer.previousSibling);var o,i,a=this._root,s=r.commonAncestorContainer;if(u(s,a,e,t))return!0;if(s.nodeType===R)return!1;o=new n(s,w,function(e){return pt(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},Vt.getFontInfo=function(e){var n,r,o,i={color:t,backgroundColor:t,family:t,size:t},a=0;if(!e&&!(e=this.getSelection()))return i;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===R)for(n.nodeType===R&&(n=n.parentNode);4>a&&n;)(r=n.style)&&(!i.color&&(o=r.color)&&(i.color=o,a+=1),!i.backgroundColor&&(o=r.backgroundColor)&&(i.backgroundColor=o,a+=1),!i.family&&(o=r.fontFamily)&&(i.family=o,a+=1),!i.size&&(o=r.fontSize)&&(i.size=o,a+=1)),n=n.parentNode;return i},Vt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f,h=this._root;if(r.collapsed)o=_(this.createElement(e,t),h),ct(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{if(i=new n(r.commonAncestorContainer,w|P,function(e){return(e.nodeType===R||"BR"===e.nodeName||"IMG"===e.nodeName)&&pt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,i.filter(a)||(a=i.nextNode(),d=0),!a)return r;do c=i.currentNode,f=!u(c,h,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),C(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(c.nodeType===R?(s=c,l=c.length):(s=c.parentNode,l=1)),r=this._createRange(a,d,s,l)}return r},Vt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var o,a=this._doc;n.collapsed&&(et?(o=a.createTextNode(z),this._didAddZWS()):o=a.createTextNode(""),ct(n,o));for(var s=n.commonAncestorContainer;i(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,f=n.endOffset,u=[],p=function(e,t){if(!pt(n,e,!1)){var r,o,i=e.nodeType===R;if(!pt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===c&&f!==e.length&&u.push([t,e.splitText(f)]),e===d&&l&&(e.splitText(l),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(r){return pt(n,r,!0)&&h(r,e,t)});r||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,N(e))}),this._getRangeAndRemoveBookmark(n),o&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return b(s,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},Vt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this.saveUndoState(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),nt||this._docWasChanged(),this):void 0};var Yt={DT:"DD",DD:"DT",LI:"LI"},Xt=function(e,t,n,r){var o=Yt[t.nodeName],i=null,a=T(n,r,t.parentNode,e._root),s=e._config; -return o||(o=s.blockTag,i=s.blockAttributes),h(a,o,i)||(t=S(a.ownerDocument,o,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(N(a)),a=t),a};Vt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,o=vt(n,r),i=Ct(n,r);if(o&&i)do if(e(o)||o===i)break;while(o=c(o,r));return t&&(this.setSelection(n),this._updatePath(n,!0),nt||this._docWasChanged()),this},Vt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t);var n,r=this._root;return yt(t,r),mt(t,r),n=ft(t,r,r),ct(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],C(s,N(s));y(i,this._root),C(o,i)}return e},sn=function(e){var t,n,r,o,i,a,d=e.querySelectorAll("LI"),l=this._config.tagAttributes,c=l.li;for(t=0,n=d.length;n>t;t+=1)r=d[t],s(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||(a=l[o.toLowerCase()],C(r,this.createElement("LI",c,[i=this.createElement(o,a)]))),i.appendChild(r));return e},dn=function(e){var t=this._root,n=e.querySelectorAll("LI");return Array.prototype.filter.call(n,function(e){return!s(e.firstChild)}).forEach(function(n){var r,o=n.parentNode,i=o.parentNode,a=n.firstChild,d=a;for(n.previousSibling&&(o=T(o,n,i,t));d&&(r=d.nextSibling,!s(d));)i.insertBefore(d,o),d=r;for("LI"===i.nodeName&&a.previousSibling&&T(i,a,i.parentNode,t);n!==e&&!n.childNodes.length;)o=n.parentNode,o.removeChild(n),n=o},this),y(e,t),e};Vt._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},Vt.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},Vt._getHTML=function(){return this._root.innerHTML},Vt._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do _(n,t);while(n=c(n,t));this._ignoreChange=!0},Vt.getHTML=function(e){var t,n,r,o,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),J)for(t=this._root,n=t;n=c(n,t);)n.textContent||n.querySelector("BR")||(r=this.createElement("BR"),n.appendChild(r),s.push(r));if(o=this._getHTML().replace(/\u200B/g,""),J)for(i=s.length;i--;)v(s[i]);return a&&this._getRangeAndRemoveBookmark(a),o},Vt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),o=this._root;r.innerHTML=e,n.appendChild(N(r)),Pt(n),Ht(n,o),y(n,o);for(var i=n;i=c(i,o);)_(i,o);for(this._ignoreChange=!0;t=o.lastChild;)o.removeChild(t);o.appendChild(n),_(o,o),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var a=this._getRangeAndRemoveBookmark()||this._createRange(o.firstChild,0);return this.saveUndoState(a),this._lastSelection=a,this._updatePath(a,!0),this},Vt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),i(e))ct(t,e),t.setStartAfter(e);else{for(var n,r,o=this._root,a=vt(t,o)||o;a!==o&&!a.nextSibling;)a=a.parentNode;a!==o&&(n=a.parentNode,r=T(n,a.nextSibling,o,o)),r?o.insertBefore(e,r):(o.appendChild(e),r=this.createDefaultBlock(),o.appendChild(r)),t.setStart(r,0),t.setEnd(r,0),gt(t)}return this.focus(),this.setSelection(t),this._updatePath(t),this},Vt.insertImage=function(e,t){var n=this.createElement("IMG",B({src:e},t));return this.insertElement(n),n};var ln=/\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,cn=function(e,t){for(var r,o,i,a,s,d,l,c=e.ownerDocument,f=new n(e,w,function(e){return!u(e,t,"A")},!1);r=f.nextNode();)for(o=r.data,i=r.parentNode;a=ln.exec(o);)s=a.index,d=s+a[0].length,s&&(l=c.createTextNode(o.slice(0,s)),i.insertBefore(l,r)),l=c.createElement("A"),l.textContent=o.slice(s,d),l.href=a[1]?/^(?:ht|f)tps?:/.test(a[1])?a[1]:"http://"+a[1]:"mailto:"+a[2],i.insertBefore(l,r),r.data=o=o.slice(d)};Vt.insertHTML=function(e,t){var n=this.getSelection(),r=this._doc.createDocumentFragment(),o=this.createElement("DIV");o.innerHTML=e,r.appendChild(N(o)),this.saveUndoState(n);try{var i=this._root,a=r,s={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1};for(cn(r,i),Pt(r),Ht(r,i),wt(r),r.normalize();a=c(a,i);)_(a,i);t&&this.fireEvent("willPaste",s),s.defaultPrevented||(ut(n,s.fragment,i),nt||this._docWasChanged(),n.collapse(!1),this._ensureBottomLine()),this.setSelection(n),this._updatePath(n,!0)}catch(d){this.didError(d)}return this},Vt.insertPlainText=function(e,t){var n,r,o,i=e.split("\n");for(n=0,r=i.length;r>n;n+=1)o=i[n],o=o.split("&").join("&").split("<").join("<").split(">").join(">").replace(/ (?= )/g," "),n&&r>n+1&&(o="
"+(o||"
")+"
"),i[n]=o;return this.insertHTML(i.join(""),t)};var fn=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Vt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.appendChild(this._doc.createTextNode(e)),t.appendChild(n)}return this},Vt.bold=fn("changeFormat",{tag:"B"}),Vt.italic=fn("changeFormat",{tag:"I"}),Vt.underline=fn("changeFormat",{tag:"U"}),Vt.strikethrough=fn("changeFormat",{tag:"S"}),Vt.subscript=fn("changeFormat",{tag:"SUB"},{tag:"SUP"}),Vt.superscript=fn("changeFormat",{tag:"SUP"},{tag:"SUB"}),Vt.removeBold=fn("changeFormat",null,{tag:"B"}),Vt.removeItalic=fn("changeFormat",null,{tag:"I"}),Vt.removeUnderline=fn("changeFormat",null,{tag:"U"}),Vt.removeStrikethrough=fn("changeFormat",null,{tag:"S"}),Vt.removeSubscript=fn("changeFormat",null,{tag:"SUB"}),Vt.removeSuperscript=fn("changeFormat",null,{tag:"SUP"}),Vt.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;ct(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},Vt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Vt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Vt.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()},Vt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Vt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Vt.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()},Vt.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},Vt.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=this._root,n=e.commonAncestorContainer;n&&!a(n);)n=n.parentNode;if(n||(yt(e,t),n=t),n.nodeType===R)return this;this.saveUndoState(e),mt(e,n);for(var r,o,i,s=n.ownerDocument,d=e.startContainer,l=e.startOffset,c=e.endContainer,f=e.endOffset,h=s.createDocumentFragment(),u=s.createDocumentFragment(),p=T(c,f,n,t),g=T(d,l,n,t);g!==p;)r=g.nextSibling,h.appendChild(g),g=r;return L(this,h,u),u.normalize(),g=u.firstChild,r=u.lastChild,i=n.childNodes,g?(n.insertBefore(u,p),l=ot.call(i,g),f=ot.call(i,r)+1):(l=ot.call(i,p),f=l),o={startContainer:n,startOffset:l,endContainer:n,endOffset:f},b(n,o),e.setStart(o.startContainer,o.startOffset),e.setEnd(o.endContainer,o.endOffset),gt(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},Vt.increaseQuoteLevel=fn("modifyBlocks",Jt),Vt.decreaseQuoteLevel=fn("modifyBlocks",en),Vt.makeUnorderedList=fn("modifyBlocks",rn),Vt.makeOrderedList=fn("modifyBlocks",on),Vt.removeList=fn("modifyBlocks",an),Vt.increaseListLevel=fn("modifyBlocks",sn),Vt.decreaseListLevel=fn("modifyBlocks",dn),"object"==typeof exports?module.exports=O:"function"==typeof define&&define.amd?define(function(){return O}):(K.Squire=O,top!==K&&"true"===e.documentElement.getAttribute("data-squireinit")&&(K.editor=new O(e),K.onEditorLoad&&(K.onEditorLoad(K.editor),K.onEditorLoad=null)))}(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){return e.nodeType===D&&!!st[e.nodeName]}function i(e){return at.test(e.nodeName)}function a(e){var t=e.nodeType;return(t===D||t===I)&&!i(e)&&r(e.childNodes,i)}function s(e){var t=e.nodeType;return!(t!==D&&t!==I||i(e)||a(e))}function d(e,t){var r=new n(t,P,a,!1);return r.currentNode=e,r}function l(e,t){return e=d(e,t).previousNode(),e!==t?e:null}function c(e,t){return e=d(e,t).nextNode(),e!==t?e:null}function f(e,t){return!o(e)&&e.nodeType===t.nodeType&&e.nodeName===t.nodeName&&e.className===t.className&&(!e.style&&!t.style||e.style.cssText===t.style.cssText)}function h(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 u(e,t,n,r){for(;e&&e!==t;){if(h(e,n,r))return e;e=e.parentNode}return null}function p(e,t){for(;t;){if(t===e)return!0;t=t.parentNode}return!1}function g(e,t){var n,r,o,i,a,s=e.parentNode;return e===t?n="":(n=g(s,t),e.nodeType===D&&(n+=(n?">":"")+e.nodeName,(r=e.id)&&(n+="#"+r),(o=e.className.trim())&&(i=o.split(/\s\s*/),i.sort(),n+=".",n+=i.join(".")),(a=e.dir)&&(n+="[dir="+a+"]"))),n}function m(e){var t=e.nodeType;return t===D?e.childNodes.length:e.length||0}function v(e){var t=e.parentNode;return t&&t.removeChild(e),e}function C(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 _(e,t){var n,r,a=e.ownerDocument,s=e;if(e===t&&((r=e.firstChild)&&"BR"!==r.nodeName||(n=k(a).createDefaultBlock(),r?e.replaceChild(n,r):e.appendChild(n),e=n,n=null)),i(e)){for(r=e.firstChild;et&&r&&r.nodeType===R&&!r.data;)e.removeChild(r),r=e.firstChild;r||(et?(n=a.createTextNode(z),k(a)._didAddZWS()):n=a.createTextNode(""))}else if(J){for(;e.nodeType!==R&&!o(e);){if(r=e.firstChild,!r){n=a.createTextNode("");break}e=r}e.nodeType===R?/^ +$/.test(e.data)&&(e.data=""):o(e)&&e.parentNode.insertBefore(a.createTextNode(""),e)}else if(!e.querySelector("BR"))for(n=S(a,"BR");(r=e.lastElementChild)&&!i(r);)e=r;return n&&e.appendChild(n),s}function y(e,t){var n,r,o,a,d=e.childNodes,l=e.ownerDocument,c=null,f=k(l)._config;for(n=0,r=d.length;r>n;n+=1)o=d[n],a="BR"===o.nodeName,!a&&i(o)?(c||(c=S(l,f.blockTag,f.blockAttributes)),c.appendChild(o),n-=1,r-=1):(a||c)&&(c||(c=S(l,f.blockTag,f.blockAttributes)),_(c,t),a?e.replaceChild(c,o):(e.insertBefore(c,o),n+=1,r+=1),c=null),s(o)&&y(o,t);return c&&e.appendChild(_(c,t)),e}function T(e,t,n,r){var o,i,a,s=e.nodeType;if(s===R&&e!==n)return T(e.parentNode,e.splitText(t),n,r);if(s===D){if("number"==typeof t&&(t=ts?t.startOffset-=1:t.startOffset===s&&(t.startContainer=r,t.startOffset=m(r))),t.endContainer===e&&(t.endOffset>s?t.endOffset-=1:t.endOffset===s&&(t.endContainer=r,t.endOffset=m(r))),v(n),n.nodeType===R?r.appendData(n.data):d.push(N(n));else if(n.nodeType===D){for(o=d.length;o--;)n.appendChild(d.pop());b(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(N(t)),b(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),Q&&(r=e.lastChild)&&"BR"===r.nodeName&&e.removeChild(r)}function x(e,t){var n,r,o=e.previousSibling,i=e.firstChild,a=e.ownerDocument,d="LI"===e.nodeName;if(!d||i&&/^[OU]L$/.test(i.nodeName))if(o&&f(o,e)){if(!s(o)){if(!d)return;r=S(a,"DIV"),r.appendChild(N(o)),o.appendChild(r)}v(e),n=!s(e),o.appendChild(N(e)),n&&y(o,t),i&&x(i,t)}else d&&(o=S(a,"DIV"),e.insertBefore(o,i),_(o,t))}function k(e){for(var t,n=qt.length;n--;)if(t=qt[n],t._doc===e)return t;return null}function O(e,t){var n,r;e||(e={});for(n in t)r=t[n],e[n]=r&&r.constructor===Object?O(e[n],r):r;return e}function B(e,t){e.nodeType===U&&(e=e.body);var n,r=e.ownerDocument,o=r.defaultView;this._win=o,this._doc=r,this._root=e,this._events={},this._lastSelection=null,tt&&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),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,nt?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(e,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._awaitingPaste=!1,this.addEventListener(j?"beforecut":"cut",Wt),this.addEventListener("copy",zt),this.addEventListener(j?"beforepaste":"paste",Kt),this.addEventListener(Q?"keypress":"keydown",bt),this._keyHandlers=Object.create(Ot),this.setConfig(t),j&&(o.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}),e.setAttribute("contenteditable","true");try{r.execCommand("enableObjectResizing",!1,"false"),r.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}qt.push(this),this.setHTML("")}function L(e,t,n){var r,o;for(r=t.firstChild;r;r=o){if(o=r.nextSibling,i(r)){if(r.nodeType===R||"BR"===r.nodeName||"IMG"===r.nodeName){n.appendChild(r);continue}}else if(a(r)){n.appendChild(e.createDefaultBlock([L(e,r,e._doc.createDocumentFragment())]));continue}L(e,r,n)}return n}var A=2,D=1,R=3,U=9,I=11,P=1,w=4,F=0,M=1,H=2,W=3,z="​",K=e.defaultView,q=navigator.userAgent,Z=/iP(?:ad|hone|od)/.test(q),G=/Mac OS X/.test(q),V=/Gecko\//.test(q),j=/Trident\/[456]\./.test(q),Q=!!K.opera,$=/Edge\//.test(q),Y=!$&&/WebKit\//.test(q),X=G?"meta-":"ctrl-",J=j||Q,et=j||Y,tt=j,nt="undefined"!=typeof MutationObserver,rt=/[^ \t\r\n]/,ot=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var it={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(it[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(it[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}},n.prototype.previousPONode=function(){for(var e,t=this.currentNode,n=this.root,r=this.nodeType,o=this.filter;;){for(e=t.lastChild;!e&&t&&t!==n;)e=t.previousSibling,e||(t=t.parentNode);if(!e)return null;if(it[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var at=/^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|U|VAR|WBR)$/,st={BR:1,IMG:1,INPUT:1},dt=function(e,t){for(var n=e.childNodes;t&&e.nodeType===D;)e=n[t-1],n=e.childNodes,t=n.length;return e},lt=function(e,t){if(e.nodeType===D){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(M,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(F,r)<1,s=e.compareBoundaryPoints(H,r)>-1;return a&&s},gt=function(e){for(var t,n=e.startContainer,r=e.startOffset,i=e.endContainer,a=e.endOffset;n.nodeType!==R&&(t=n.childNodes[r],t&&!o(t));)n=t,r=0;if(a)for(;i.nodeType!==R&&(t=i.childNodes[a-1],t&&!o(t));)i=t,a=m(i);else for(;i.nodeType!==R&&(t=i.firstChild,t&&!o(t));)i=t;e.collapsed?(e.setStart(i,a),e.setEnd(n,r)):(e.setStart(n,r),e.setEnd(i,a))},mt=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=ot.call(n.childNodes,r),r=n;for(;i!==t&&a===m(i);)n=i.parentNode,a=ot.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},vt=function(e,t){var n,r=e.startContainer;return i(r)?n=l(r,t):a(r)?n=r:(n=dt(r,e.startOffset),n=c(n,t)),n&&pt(e,n,!0)?n:null},Ct=function(e,t){var n,r,o=e.endContainer;if(i(o))n=l(o,t);else if(a(o))n=o;else{if(n=lt(o,e.endOffset),!n)for(n=t;r=n.lastChild;)n=r;n=l(n,t)}return n&&pt(e,n,!0)?n:null},Nt=new n(null,w|P,function(e){return e.nodeType===R?rt.test(e.data):"IMG"===e.nodeName}),St=function(e,t){var n=e.startContainer,r=e.startOffset;if(Nt.root=null,n.nodeType===R){if(r)return!1;Nt.currentNode=n}else Nt.currentNode=lt(n,r);return Nt.root=vt(e,t),!Nt.previousNode()},_t=function(e,t){var n,r=e.endContainer,o=e.endOffset;if(Nt.root=null,r.nodeType===R){if(n=r.data.length,n&&n>o)return!1;Nt.currentNode=r}else Nt.currentNode=dt(r,o);return Nt.root=Ct(e,t),!Nt.nextNode()},yt=function(e,t){var n,r=vt(e,t),o=Ct(e,t);r&&o&&(n=r.parentNode,e.setStart(n,ot.call(n.childNodes,r)),n=o.parentNode,e.setEnd(n,ot.call(n.childNodes,o)+1))},Tt={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},bt=function(e){var t=e.keyCode,n=Tt[t],r="",o=this.getSelection();e.defaultPrevented||(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)),"backspace"!==n&&"delete"!==n&&(e.altKey&&(r+="alt-"),e.ctrlKey&&(r+="ctrl-"),e.metaKey&&(r+="meta-")),e.shiftKey&&(r+="shift-"),n=r+n,this._keyHandlers[n]?this._keyHandlers[n](this,e,o):1!==n.length||o.collapsed||(this.saveUndoState(o),ht(o,this._root),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},Et=function(e){return function(t,n){n.preventDefault(),t[e]()}},xt=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)}},kt=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===R&&(r=r.parentNode),n=r;i(n)&&(!n.textContent||n.textContent===z);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,ot.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),a(n)||(n=l(n,e._root)),_(n,e._root),gt(t)),r===e._root&&(r=r.firstChild)&&"BR"===r.nodeName&&v(r),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(o){e.didError(o)}},Ot={enter:function(e,t,n){var r,o,i,a=e._root;if(t.preventDefault(),e._recordUndoState(n),cn(n.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||ht(n,a),r=vt(n,a),!r||/^T[HD]$/.test(r.nodeName))return ct(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((o=u(r,a,"LI"))&&(r=o),!r.textContent){if(u(r,a,"UL")||u(r,a,"OL"))return e.modifyBlocks(dn,n);if(u(r,a,"BLOCKQUOTE"))return e.modifyBlocks(tn,n)}for(i=Xt(e,r,n.startContainer,n.startOffset),jt(r),wt(r),_(r,a);i.nodeType===D;){var s,d=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===z)){d=e._doc.createTextNode(""),C(i,d),i=d;break}for(;d&&d.nodeType===R&&!d.data&&(s=d.nextSibling,s&&"BR"!==s.nodeName);)v(d),d=s;if(!d||"BR"===d.nodeName||d.nodeType===R&&!Q)break;i=d}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){var r=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(St(n,r)){t.preventDefault();var o,i=vt(n,r);if(!i)return;if(y(i.parentNode,r),o=l(i,r)){if(!o.isContentEditable)return void v(o);for(E(o,i,n),i=o.parentNode;i&&!i.nextSibling;)i=i.parentNode;i&&(i=i.nextSibling)&&x(i,r),e.setSelection(n)}else if(i){if(u(i,r,"UL")||u(i,r,"OL"))return e.modifyBlocks(dn,n);if(u(i,r,"BLOCKQUOTE"))return e.modifyBlocks(en,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){kt(e)},0);else t.preventDefault(),ht(n,r),kt(e,n)},"delete":function(e,t,n){var r,o,i,a,s,d,l=e._root;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(_t(n,l)){if(t.preventDefault(),r=vt(n,l),!r)return;if(y(r.parentNode,l),o=c(r,l)){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)&&x(o,l),e.setSelection(n),e._updatePath(n,!0)}}else{if(i=n.cloneRange(),mt(n,e._root),a=n.endContainer,s=n.endOffset,a.nodeType===D&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),v(d),gt(n),void kt(e,n);e.setSelection(i),setTimeout(function(){kt(e)},0)}else t.preventDefault(),ht(n,l),kt(e,n)},tab:function(e,t,n){var r,o,i=e._root;if(e._removeZWS(),n.collapsed&&St(n,i))for(r=vt(n,i);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(sn,n));break}r=o}},"shift-tab":function(e,t,n){var r,o=e._root;e._removeZWS(),n.collapsed&&St(n,o)&&(r=n.startContainer,(u(r,o,"UL")||u(r,o,"OL"))&&(t.preventDefault(),e.modifyBlocks(dn,n)))},space:function(e,t,n){var r,o;e._recordUndoState(n),cn(n.startContainer),e._getRangeAndRemoveBookmark(n),r=n.endContainer,o=r.parentNode,n.collapsed&&"A"===o.nodeName&&!r.nextSibling&&n.endOffset===m(r)&&n.setStartAfter(o),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};G&&V&&(Ot["meta-left"]=function(e,t){t.preventDefault();var n=Vt(e);n&&n.modify&&n.modify("move","backward","lineboundary")},Ot["meta-right"]=function(e,t){t.preventDefault();var n=Vt(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),G||(Ot.pageup=function(e){e.moveCursorToStart()},Ot.pagedown=function(e){e.moveCursorToEnd()}),Ot[X+"b"]=xt("B"),Ot[X+"i"]=xt("I"),Ot[X+"u"]=xt("U"),Ot[X+"shift-7"]=xt("S"),Ot[X+"shift-5"]=xt("SUB",{tag:"SUP"}),Ot[X+"shift-6"]=xt("SUP",{tag:"SUB"}),Ot[X+"shift-8"]=Et("makeUnorderedList"),Ot[X+"shift-9"]=Et("makeOrderedList"),Ot[X+"["]=Et("decreaseQuoteLevel"),Ot[X+"]"]=Et("increaseQuoteLevel"),Ot[X+"y"]=Et("redo"),Ot[X+"z"]=Et("undo"),Ot[X+"shift-z"]=Et("redo");var Bt={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Lt={backgroundColor:{regexp:rt,replace:function(e,t){return S(e,"SPAN",{"class":"highlight",style:"background-color:"+t})}},color:{regexp:rt,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:rt,replace:function(e,t){return S(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:rt,replace:function(e,t){return S(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},At=function(e){return function(t,n){var r=S(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(N(t)),r}},Dt={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Lt)r=Lt[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:At("B"),EM:At("I"),STRIKE:At("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:"+Bt[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}},Rt=/^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|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=/^(?:HEAD|META|STYLE)/,It=new n(null,w|P,function(){return!0}),Pt=function hn(e){var t,n,r,o,a,s,d,l,c,f,h,u,p=e.childNodes;for(t=e;i(t);)t=t.parentNode;for(It.root=t,n=0,r=p.length;r>n;n+=1)if(o=p[n],a=o.nodeName,s=o.nodeType,d=Dt[a],s===D){if(l=o.childNodes.length,d)o=d(o,e);else{if(Ut.test(a)){e.removeChild(o),n-=1,r-=1;continue}if(!Rt.test(a)&&!i(o)){n-=1,r+=l-1,e.replaceChild(N(o),o);continue}}l&&hn(o)}else{if(s===R){if(h=o.data,c=!rt.test(h.charAt(0)),f=!rt.test(h.charAt(h.length-1)),!c&&!f)continue;if(c){for(It.currentNode=o;(u=It.previousPONode())&&(a=u.nodeName,!("IMG"===a||"#text"===a&&/\S/.test(u.data)));)if(!i(u)){u=null;break}u||(h=h.replace(/^\s+/g,""))}if(f){for(It.currentNode=o;(u=It.nextNode())&&!("IMG"===a||"#text"===a&&/\S/.test(u.data));)if(!i(u)){u=null;break}u||(h=h.replace(/^\s+/g,""))}if(h){o.data=h;continue}}e.removeChild(o),n-=1,r-=1}return e},wt=function un(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==D||o(t)?t.nodeType!==R||t.data||e.removeChild(t):(un(t),i(t)&&!t.firstChild&&e.removeChild(t))},Ft=function(e){return e.nodeType===D?"BR"===e.nodeName:rt.test(e.data)},Mt=function(e){for(var t,r=e.parentNode;i(r);)r=r.parentNode;return t=new n(r,P|w,Ft),t.currentNode=e,!!t.nextNode()},Ht=function(e,t){var n,r,o,a=e.querySelectorAll("BR"),s=[],d=a.length;for(n=0;d>n;n+=1)s[n]=Mt(a[n]);for(;d--;)r=a[d],o=r.parentNode,o&&(s[d]?i(o)||y(o,t):v(r))},Wt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._root,i=this;this.saveUndoState(n),$||Z||!t?setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0):(mt(n,o),r.appendChild(ht(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()),this.setSelection(n)},zt=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");$||Z||!t||(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},Kt=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,f=this;if(!$&&s){for(e.preventDefault(),t=s.length;t--;){if(n=s[t],r=n.type,"text/html"===r)return void n.getAsString(function(e){f.insertHTML(e,!0)});"text/plain"===r&&(c=n),/^image\/.*/.test(r)&&(l=!0)}return void(l?(this.fireEvent("dragover",{dataTransfer:a,preventDefault:function(){d=!0}}),d&&this.fireEvent("drop",{dataTransfer:a})):c&&n.getAsString(function(e){f.insertPlainText(e,!0)}))}if(o=a&&a.types,!$&&o&&(ot.call(o,"text/html")>-1||!V&&ot.call(o,"text/plain")>-1&&ot.call(o,"text/rtf")<0))return e.preventDefault(),void((i=a.getData("text/html"))?this.insertHTML(i,!0):(i=a.getData("text/plain"))&&this.insertPlainText(i,!0));this._awaitingPaste=!0;var h=this._doc.body,u=this.getSelection(),p=u.startContainer,g=u.startOffset,m=u.endContainer,C=u.endOffset,N=this.createElement("DIV",{contenteditable:"true",style:"position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"});h.appendChild(N),u.selectNodeContents(N),this.setSelection(u),setTimeout(function(){try{f._awaitingPaste=!1;for(var e,t,n="",r=N;N=r;)r=N.nextSibling,v(N),e=N.firstChild,e&&e===N.lastChild&&"DIV"===e.nodeName&&(N=e),n+=N.innerHTML;t=f._createRange(p,g,m,C),f.setSelection(t),n&&f.insertHTML(n,!0)}catch(o){f.didError(o)}},0)},qt=[],Zt=B.prototype;Zt.setConfig=function(e){return e=O({blockTag:"DIV",blockAttributes:null,tagAttributes:{blockquote:null,ul:null,ol:null,li:null}},e),e.blockTag=e.blockTag.toUpperCase(),this._config=e,this},Zt.createElement=function(e,t,n){return S(this._doc,e,t,n)},Zt.createDefaultBlock=function(e){var t=this._config;return _(this.createElement(t.blockTag,t.blockAttributes,e),this._root)},Zt.didError=function(e){console.log(e)},Zt.getDocument=function(){return this._doc};var Gt={pathChange:1,select:1,input:1,undoStateChange:1};Zt.fireEvent=function(e,t){var n,r,o=this._events[e];if(o)for(t||(t={}),t.type!==e&&(t.type=e),o=o.slice(),n=o.length;n--;){r=o[n];try{r.handleEvent?r.handleEvent(t):r.call(this,t)}catch(i){i.details="Squire: fireEvent error. Event type: "+e,this.didError(i)}}return this},Zt.destroy=function(){var e,t=this._root,n=this._events;for(e in n)Gt[e]||t.removeEventListener(e,this,!0);this._mutation&&this._mutation.disconnect();for(var r=qt.length;r--;)qt[r]===this&&qt.splice(r,1)},Zt.handleEvent=function(e){this.fireEvent(e.type,e)},Zt.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Gt[e]||this._root.addEventListener(e,this,!0)),n.push(t),this):(this.didError({name:"Squire: addEventListener with null or undefined fn",message:"Event type: "+e}),this)},Zt.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],Gt[e]||this._root.removeEventListener(e,this,!0))}return this},Zt._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},Zt.getCursorPosition=function(e){if(!e&&!(e=this.getSelection()))return null;var t,n,r=e.getBoundingClientRect();return r&&!r.top&&(this._ignoreChange=!0,t=this._doc.createElement("SPAN"),t.textContent=z,ct(e,t),r=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),b(n,{startContainer:e.startContainer,endContainer:e.endContainer,startOffset:e.startOffset,endOffset:e.endOffset})),r},Zt._moveCursorTo=function(e){var t=this._root,n=this._createRange(t,e?0:t.childNodes.length);return gt(n),this.setSelection(n),this},Zt.moveCursorToStart=function(){return this._moveCursorTo(!0)},Zt.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var Vt=function(e){return e._win.getSelection()||null};Zt.setSelection=function(e){if(e){Z&&this._win.focus();var t=Vt(this);t&&(t.removeAllRanges(),t.addRange(e))}return this},Zt.getSelection=function(){var e,t,n,r=Vt(this),i=this._root;return r&&r.rangeCount&&(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&o(t)&&e.setStartBefore(t),n&&o(n)&&e.setEndBefore(n)),e&&p(i,e.commonAncestorContainer)?this._lastSelection=e:e=this._lastSelection,e||(e=this._createRange(i.firstChild,0)),e},Zt.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,w|P,function(e){return pt(t,e,!0)}),o=t.startContainer,a=t.endContainer,s=r.currentNode=o,d="",l=!1;for(r.filter(s)||(s=r.nextNode());s;)s.nodeType===R?(e=s.data,e&&/\S/.test(e)&&(s===a&&(e=e.slice(0,t.endOffset)),s===o&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===s.nodeName||l&&!i(s))&&(d+="\n",l=!1),s=r.nextNode();return d},Zt.getPath=function(){return this._path};var jt=function(e){for(var t,r,o,a=new n(e,w,function(){return!0},!1);r=a.nextNode();)for(;(o=r.data.indexOf(z))>-1;){if(1===r.length){do t=r.parentNode,t.removeChild(r),r=t,a.currentNode=t;while(i(r)&&!m(r));break}r.deleteData(o,1)}};Zt._didAddZWS=function(){this._hasZWS=!0},Zt._removeZWS=function(){this._hasZWS&&(jt(this._root),this._hasZWS=!1)},Zt._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?g(o,this._root):"(selection)":"",this._path!==n&&(this._path=n,this.fireEvent("pathChange",{path:n}))),e.collapsed||this.fireEvent("select")},Zt._updatePathOnEvent=function(){this._updatePath(this.getSelection())},Zt.focus=function(){return this._root.focus(),this},Zt.blur=function(){return this._root.blur(),this};var Qt="squire-selection-start",$t="squire-selection-end";Zt._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Qt,type:"hidden"}),r=this.createElement("INPUT",{id:$t,type:"hidden"});ct(e,n),e.collapse(!1),ct(e,r),n.compareDocumentPosition(r)&A&&(n.id=$t,r.id=Qt,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},Zt._getRangeAndRemoveBookmark=function(e){var t=this._root,n=t.querySelector("#"+Qt),r=t.querySelector("#"+$t);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:ot.call(i.childNodes,n),endOffset:ot.call(a.childNodes,r)};i===a&&(s.endOffset-=1),v(n),v(r),b(i,s),i!==a&&b(a,s),e||(e=this._doc.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,gt(e),o&&e.collapse(!0)}return e||null},Zt._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},Zt._docWasChanged=function(){return nt&&this._ignoreChange?void(this._ignoreChange=!1):(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),void this.fireEvent("input"))},Zt._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},Zt.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;!r.collapsed&&r.startContainer.nodeType===R&&r.startOffset===r.startContainer.length&&r.startContainer.nextSibling&&r.setStartBefore(r.startContainer.nextSibling),!r.collapsed&&r.endContainer.nodeType===R&&0===r.endOffset&&r.endContainer.previousSibling&&r.setEndAfter(r.endContainer.previousSibling);var o,i,a=this._root,s=r.commonAncestorContainer;if(u(s,a,e,t))return!0;if(s.nodeType===R)return!1;o=new n(s,w,function(e){return pt(r,e,!0)},!1);for(var d=!1;i=o.nextNode();){if(!u(i,a,e,t))return!1;d=!0}return d},Zt.getFontInfo=function(e){var n,r,o,i={color:t,backgroundColor:t,family:t,size:t},a=0;if(!e&&!(e=this.getSelection()))return i;if(n=e.commonAncestorContainer,e.collapsed||n.nodeType===R)for(n.nodeType===R&&(n=n.parentNode);4>a&&n;)(r=n.style)&&(!i.color&&(o=r.color)&&(i.color=o,a+=1),!i.backgroundColor&&(o=r.backgroundColor)&&(i.backgroundColor=o,a+=1),!i.family&&(o=r.fontFamily)&&(i.family=o,a+=1),!i.size&&(o=r.fontSize)&&(i.size=o,a+=1)),n=n.parentNode;return i},Zt._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f,h=this._root;if(r.collapsed)o=_(this.createElement(e,t),h),ct(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{if(i=new n(r.commonAncestorContainer,w|P,function(e){return(e.nodeType===R||"BR"===e.nodeName||"IMG"===e.nodeName)&&pt(r,e,!0)},!1),a=r.startContainer,d=r.startOffset,s=r.endContainer,l=r.endOffset,i.currentNode=a,i.filter(a)||(a=i.nextNode(),d=0),!a)return r;do c=i.currentNode,f=!u(c,h,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),C(c,o),o.appendChild(c));while(i.nextNode());s.nodeType!==R&&(c.nodeType===R?(s=c,l=c.length):(s=c.parentNode,l=1)),r=this._createRange(a,d,s,l)}return r},Zt._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var o,a=this._doc;n.collapsed&&(et?(o=a.createTextNode(z),this._didAddZWS()):o=a.createTextNode(""),ct(n,o));for(var s=n.commonAncestorContainer;i(s);)s=s.parentNode;var d=n.startContainer,l=n.startOffset,c=n.endContainer,f=n.endOffset,u=[],p=function(e,t){if(!pt(n,e,!1)){var r,o,i=e.nodeType===R;if(!pt(n,e,!0))return void("INPUT"===e.nodeName||i&&!e.data||u.push([t,e]));if(i)e===c&&f!==e.length&&u.push([t,e.splitText(f)]),e===d&&l&&(e.splitText(l),u.push([t,e]));else for(r=e.firstChild;r;r=o)o=r.nextSibling,p(r,t)}},g=Array.prototype.filter.call(s.getElementsByTagName(e),function(r){return pt(n,r,!0)&&h(r,e,t)});r||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];C(n,t),t.appendChild(n)}),g.forEach(function(e){C(e,N(e))}),this._getRangeAndRemoveBookmark(n),o&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return b(s,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},Zt.changeFormat=function(e,t,n,r){return n||(n=this.getSelection())?(this.saveUndoState(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),nt||this._docWasChanged(),this):void 0 +};var Yt={DT:"DD",DD:"DT",LI:"LI"},Xt=function(e,t,n,r){var o=Yt[t.nodeName],i=null,a=T(n,r,t.parentNode,e._root),s=e._config;return o||(o=s.blockTag,i=s.blockAttributes),h(a,o,i)||(t=S(a.ownerDocument,o,i),a.dir&&(t.dir=a.dir),C(a,t),t.appendChild(N(a)),a=t),a};Zt.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=this._root,o=vt(n,r),i=Ct(n,r);if(o&&i)do if(e(o)||o===i)break;while(o=c(o,r));return t&&(this.setSelection(n),this._updatePath(n,!0),nt||this._docWasChanged()),this},Zt.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t);var n,r=this._root;return yt(t,r),mt(t,r),n=ft(t,r,r),ct(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],C(s,N(s));y(i,this._root),C(o,i)}return e},sn=function(e){var t,n,r,o,i,a,d=e.querySelectorAll("LI"),l=this._config.tagAttributes,c=l.li;for(t=0,n=d.length;n>t;t+=1)r=d[t],s(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||(a=l[o.toLowerCase()],C(r,this.createElement("LI",c,[i=this.createElement(o,a)]))),i.appendChild(r));return e},dn=function(e){var t=this._root,n=e.querySelectorAll("LI");return Array.prototype.filter.call(n,function(e){return!s(e.firstChild)}).forEach(function(n){var r,o=n.parentNode,i=o.parentNode,a=n.firstChild,d=a;for(n.previousSibling&&(o=T(o,n,i,t));d&&(r=d.nextSibling,!s(d));)i.insertBefore(d,o),d=r;for("LI"===i.nodeName&&a.previousSibling&&T(i,a,i.parentNode,t);n!==e&&!n.childNodes.length;)o=n.parentNode,o.removeChild(n),n=o},this),y(e,t),e};Zt._ensureBottomLine=function(){var e=this._root,t=e.lastElementChild;t&&t.nodeName===this._config.blockTag&&a(t)||e.appendChild(this.createDefaultBlock())},Zt.setKeyHandler=function(e,t){return this._keyHandlers[e]=t,this},Zt._getHTML=function(){return this._root.innerHTML},Zt._setHTML=function(e){var t=this._root,n=t;n.innerHTML=e;do _(n,t);while(n=c(n,t));this._ignoreChange=!0},Zt.getHTML=function(e){var t,n,r,o,i,a,s=[];if(e&&(a=this.getSelection())&&this._saveRangeToBookmark(a),J)for(t=this._root,n=t;n=c(n,t);)n.textContent||n.querySelector("BR")||(r=this.createElement("BR"),n.appendChild(r),s.push(r));if(o=this._getHTML().replace(/\u200B/g,""),J)for(i=s.length;i--;)v(s[i]);return a&&this._getRangeAndRemoveBookmark(a),o},Zt.setHTML=function(e){var t,n=this._doc.createDocumentFragment(),r=this.createElement("DIV"),o=this._root;r.innerHTML=e,n.appendChild(N(r)),Pt(n),Ht(n,o),y(n,o);for(var i=n;i=c(i,o);)_(i,o);for(this._ignoreChange=!0;t=o.lastChild;)o.removeChild(t);o.appendChild(n),_(o,o),this._undoIndex=-1,this._undoStack.length=0,this._undoStackLength=0,this._isInUndoState=!1;var a=this._getRangeAndRemoveBookmark()||this._createRange(o.firstChild,0);return this.saveUndoState(a),this._lastSelection=a,this._updatePath(a,!0),this},Zt.insertElement=function(e,t){if(t||(t=this.getSelection()),t.collapse(!0),i(e))ct(t,e),t.setStartAfter(e);else{for(var n,r,o=this._root,a=vt(t,o)||o;a!==o&&!a.nextSibling;)a=a.parentNode;a!==o&&(n=a.parentNode,r=T(n,a.nextSibling,o,o)),r?o.insertBefore(e,r):(o.appendChild(e),r=this.createDefaultBlock(),o.appendChild(r)),t.setStart(r,0),t.setEnd(r,0),gt(t)}return this.focus(),this.setSelection(t),this._updatePath(t),this},Zt.insertImage=function(e,t){var n=this.createElement("IMG",O({src:e},t));return this.insertElement(n),n};var ln=/\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,cn=function(e,t){for(var r,o,i,a,s,d,l,c=e.ownerDocument,f=new n(e,w,function(e){return!u(e,t,"A")},!1);r=f.nextNode();)for(o=r.data,i=r.parentNode;a=ln.exec(o);)s=a.index,d=s+a[0].length,s&&(l=c.createTextNode(o.slice(0,s)),i.insertBefore(l,r)),l=c.createElement("A"),l.textContent=o.slice(s,d),l.href=a[1]?/^(?:ht|f)tps?:/.test(a[1])?a[1]:"http://"+a[1]:"mailto:"+a[2],i.insertBefore(l,r),r.data=o=o.slice(d)};Zt.insertHTML=function(e,t){var n=this.getSelection(),r=this._doc.createDocumentFragment(),o=this.createElement("DIV");o.innerHTML=e,r.appendChild(N(o)),this.saveUndoState(n);try{var i=this._root,a=r,s={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1};for(cn(r,i),Pt(r),Ht(r,i),wt(r),r.normalize();a=c(a,i);)_(a,i);t&&this.fireEvent("willPaste",s),s.defaultPrevented||(ut(n,s.fragment,i),nt||this._docWasChanged(),n.collapse(!1),this._ensureBottomLine()),this.setSelection(n),this._updatePath(n,!0)}catch(d){this.didError(d)}return this},Zt.insertPlainText=function(e,t){var n,r,o,i=e.split("\n");for(n=0,r=i.length;r>n;n+=1)o=i[n],o=o.split("&").join("&").split("<").join("<").split(">").join(">").replace(/ (?= )/g," "),n&&r>n+1&&(o="
"+(o||"
")+"
"),i[n]=o;return this.insertHTML(i.join(""),t)};var fn=function(e,t,n){return function(){return this[e](t,n),this.focus()}};Zt.addStyles=function(e){if(e){var t=this._doc.documentElement.firstChild,n=this.createElement("STYLE",{type:"text/css"});n.appendChild(this._doc.createTextNode(e)),t.appendChild(n)}return this},Zt.bold=fn("changeFormat",{tag:"B"}),Zt.italic=fn("changeFormat",{tag:"I"}),Zt.underline=fn("changeFormat",{tag:"U"}),Zt.strikethrough=fn("changeFormat",{tag:"S"}),Zt.subscript=fn("changeFormat",{tag:"SUB"},{tag:"SUP"}),Zt.superscript=fn("changeFormat",{tag:"SUP"},{tag:"SUB"}),Zt.removeBold=fn("changeFormat",null,{tag:"B"}),Zt.removeItalic=fn("changeFormat",null,{tag:"I"}),Zt.removeUnderline=fn("changeFormat",null,{tag:"U"}),Zt.removeStrikethrough=fn("changeFormat",null,{tag:"S"}),Zt.removeSubscript=fn("changeFormat",null,{tag:"SUB"}),Zt.removeSuperscript=fn("changeFormat",null,{tag:"SUP"}),Zt.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;ct(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},Zt.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},Zt.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},Zt.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()},Zt.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},Zt.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},Zt.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()},Zt.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},Zt.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=this._root,n=e.commonAncestorContainer;n&&!a(n);)n=n.parentNode;if(n||(yt(e,t),n=t),n.nodeType===R)return this;this.saveUndoState(e),mt(e,n);for(var r,o,i,s=n.ownerDocument,d=e.startContainer,l=e.startOffset,c=e.endContainer,f=e.endOffset,h=s.createDocumentFragment(),u=s.createDocumentFragment(),p=T(c,f,n,t),g=T(d,l,n,t);g!==p;)r=g.nextSibling,h.appendChild(g),g=r;return L(this,h,u),u.normalize(),g=u.firstChild,r=u.lastChild,i=n.childNodes,g?(n.insertBefore(u,p),l=ot.call(i,g),f=ot.call(i,r)+1):(l=ot.call(i,p),f=l),o={startContainer:n,startOffset:l,endContainer:n,endOffset:f},b(n,o),e.setStart(o.startContainer,o.startOffset),e.setEnd(o.endContainer,o.endOffset),gt(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},Zt.increaseQuoteLevel=fn("modifyBlocks",Jt),Zt.decreaseQuoteLevel=fn("modifyBlocks",en),Zt.makeUnorderedList=fn("modifyBlocks",rn),Zt.makeOrderedList=fn("modifyBlocks",on),Zt.removeList=fn("modifyBlocks",an),Zt.increaseListLevel=fn("modifyBlocks",sn),Zt.decreaseListLevel=fn("modifyBlocks",dn),"object"==typeof exports?module.exports=B:"function"==typeof define&&define.amd?define(function(){return B}):(K.Squire=B,top!==K&&"true"===e.documentElement.getAttribute("data-squireinit")&&(K.editor=new B(e),K.onEditorLoad&&(K.onEditorLoad(K.editor),K.onEditorLoad=null)))}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 6ad4083..c5ea5ba 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -186,8 +186,7 @@ proto.getDocument = function () { // document node, since these events are fired in a custom manner by the // editor code. var customEvents = { - pathChange: 1, select: 1, input: 1, - undoStateChange: 1, scrollPointIntoView: 1 + pathChange: 1, select: 1, input: 1, undoStateChange: 1 }; proto.fireEvent = function ( type, event ) { @@ -300,26 +299,29 @@ proto._createRange = return domRange; }; -proto.scrollRangeIntoView = function ( range ) { +proto.getCursorPosition = function ( range ) { + if ( !range && !( range = this.getSelection() ) ) { + return null; + } // Get the bounding rect var rect = range.getBoundingClientRect(); var node, parent; if ( rect && !rect.top ) { + this._ignoreChange = true; node = this._doc.createElement( 'SPAN' ); - range = range.cloneRange(); + node.textContent = ZWS; insertNodeInRange( range, node ); rect = node.getBoundingClientRect(); parent = node.parentNode; parent.removeChild( node ); - parent.normalize(); - } - // And fire event for integrations to use - if ( rect ) { - this.fireEvent( 'scrollPointIntoView', { - x: rect.left, - y: rect.top + mergeInlines( parent, { + startContainer: range.startContainer, + endContainer: range.endContainer, + startOffset: range.startOffset, + endOffset: range.endOffset }); } + return rect; }; proto._moveCursorTo = function ( toStart ) { @@ -353,7 +355,6 @@ proto.setSelection = function ( range ) { if ( sel ) { sel.removeAllRanges(); sel.addRange( range ); - this.scrollRangeIntoView( range ); } } return this;