From 29fffdccd01d24fc0400da5e9528976a1f9805a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gert=20K=2E=20S=C3=B8nderby?= Date: Wed, 25 Nov 2015 15:39:29 +0100 Subject: [PATCH] Enter press at end of PRE will break line. --- build/squire-raw.js | 13 +++++++++---- build/squire.js | 4 ++-- source/Editor.js | 5 +++-- source/KeyHandlers.js | 8 ++++++-- test/squire.spec.js | 6 +++--- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/build/squire-raw.js b/build/squire-raw.js index 5cd9b7d..632b60a 100644 --- a/build/squire-raw.js +++ b/build/squire-raw.js @@ -1327,10 +1327,14 @@ var keyHandlers = { } if ( /^PRE|CODE|SAMP$/.test( block.nodeName ) ) { + if ( !getNodeAfter( range.endContainer, range.endOffset ).nodeValue[ range.endOffset ] ) { + insertNodeInRange( range, self._doc.createTextNode( '\n\n' ) ); + } else { + insertNodeInRange( range, self._doc.createTextNode( '\n' ) ); + } // Inside a preformatted block, insert a linebreak, and done. - insertNodeInRange( range, self._doc.createTextNode( '\n' ) ); - range.collapse( false ); block.normalize(); + range.collapse( false ); self.setSelection( range ); self._updatePath( range, true ); return; @@ -3545,7 +3549,7 @@ var getTextFromHTMLFragment = function ( self, frag ) { // Strip down to text only lines.push( node.textContent ); } - return self._doc.createTextNode( lines.join( '\n' ) || '\n' ); + return self._doc.createTextNode( lines.join( '\n' ) || '' ); }; var makePreformatted = function ( frag ) { @@ -3553,7 +3557,8 @@ var makePreformatted = function ( frag ) { this._config.tagAttributes.pre, [ this.createElement( 'INPUT', { id: startSelectionId, type: 'hidden' } ), getTextFromHTMLFragment( this, frag ), - this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' } ) + this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' } ), + this._doc.createTextNode( '\n' ) ] ); }; diff --git a/build/squire.js b/build/squire.js index 03b1a25..002e2d8 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!a(e)&&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&&!!ie[e.nodeName]}function s(e){return oe.test(e.nodeName)}function d(e){var t=e.nodeType;return(t===A||t===R)&&!s(e)&&r(e.childNodes,s)}function l(e){var t=e.nodeType;return!(t!==A&&t!==R||s(e)||d(e))}function c(e){var t=e.ownerDocument,r=new n(t.body,P,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,a=e.parentNode;return a&&e.nodeType===A?(t=p(a),t+=(t?">":"")+e.nodeName,(n=e.id)&&(t+="#"+n),(r=e.className.trim())&&(o=r.split(/\s\s*/),o.sort(),t+=".",t+=o.join(".")),(i=e.dir)&&(t+="[dir="+i+"]")):t=a?p(a):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function m(e){var t=e.parentNode;return t&&t.removeChild(e),e}function v(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function C(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function N(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 S(e){var t,n,r=e.ownerDocument,o=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=x(r).createDefaultBlock(),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;X&&n&&n.nodeType===D&&!n.data;)e.removeChild(n),n=e.firstChild;n||(X?(t=r.createTextNode(H),x(r)._didAddZWS()):t=r.createTextNode(""))}else if($){for(;e.nodeType!==D&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===D?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=N(r,"BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function y(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null,c=x(a)._config;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=N(a,c.blockTag,c.blockAttributes)),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=N(a,c.blockTag,c.blockAttributes)),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&y(r);return d&&e.appendChild(S(d)),e}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===D&&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))),m(n),n.nodeType===D?r.appendData(n.data):l.push(C(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());T(n,t)}}function b(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;m(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)),T(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),G&&(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=N(a,"DIV"),n.appendChild(C(r)),r.appendChild(n)}m(e),t=!l(e),r.appendChild(C(e)),t&&y(r),o&&E(o)}else s&&(r=N(a,"DIV"),e.insertBefore(r,o),S(r))}function x(e){for(var t,n=We.length;n--;)if(t=We[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 k(e,t){var n,r=e.defaultView,o=e.body;this._win=r,this._doc=e,this._body=o,this._events={},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),r.addEventListener("focus",this,!1),r.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,ee?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(o,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._awaitingPaste=!1,this.addEventListener(Z?"beforecut":"cut",Me),this.addEventListener("copy",He),this.addEventListener(Z?"beforepaste":"paste",ze),this.addEventListener(G?"keypress":"keydown",_e),this._keyHandlers=Object.create(xe),this.setConfig(t),Z&&(r.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}),o.setAttribute("contenteditable","true");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}We.push(this),this.setHTML("")}function O(e,t,n){var r,o;for(r=t.firstChild;r;r=o){if(o=r.nextSibling,s(r)){if(r.nodeType===D||"BR"===r.nodeName||"IMG"===r.nodeName){n.appendChild(r);continue}}else if(d(r)){n.appendChild(e.createDefaultBlock([O(e,r,e._doc.createDocumentFragment())]));continue}O(e,r,n)}return n}var L=2,A=1,D=3,R=11,P=1,I=4,U=0,w=1,F=2,M=3,H="​",z=e.defaultView,W=navigator.userAgent,q=/iP(?:ad|hone|od)/.test(W),K=/Mac OS X/.test(W),V=/Gecko\//.test(W),Z=/Trident\/[456]\./.test(W),G=!!z.opera,j=/Edge\//.test(W),Q=!j&&/WebKit\//.test(W),Y=K?"meta-":"ctrl-",$=Z||G,X=Z||Q,J=Z,ee="undefined"!=typeof MutationObserver,te=/[^ \t\r\n]/,ne=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var re={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(re[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(re[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(re[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var oe=/^(?:#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)$/,ie={BR:1,IMG:1,INPUT:1},ae=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},se=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(w,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(U,r)<1,s=e.compareBoundaryPoints(F,r)>-1;return a&&s},ue=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==D&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==D&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==D&&(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))},pe=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=ne.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=ne.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ge=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=ae(n,e.startOffset),t=h(t)),t&&he(e,t,!0)?t:null},me=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=se(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&&he(e,t,!0)?t:null},ve=new n(null,I|P,function(e){return e.nodeType===D?te.test(e.data):"IMG"===e.nodeName}),Ce=function(e){var t=e.startContainer,n=e.startOffset;if(ve.root=null,t.nodeType===D){if(n)return!1;ve.currentNode=t}else ve.currentNode=se(t,n);return ve.root=ge(e),!ve.previousNode()},Ne=function(e){var t,n=e.endContainer,r=e.endOffset;if(ve.root=null,n.nodeType===D){if(t=n.data.length,t&&t>r)return!1;ve.currentNode=n}else ve.currentNode=ae(n,r);return ve.root=me(e),!ve.nextNode()},Se=function(e){var t,n=ge(e),r=me(e);n&&r&&(t=n.parentNode,e.setStart(t,ne.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,ne.call(t.childNodes,r)+1))},ye={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},_e=function(e){var t=e.keyCode,n=ye[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),G&&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),ce(o),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},Te=function(e){return function(t,n){n.preventDefault(),t[e]()}},be=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)}},Ee=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===D&&(r=r.parentNode),n=r;s(n)&&(!n.textContent||n.textContent===H);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,ne.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),d(n)||(n=f(n)),S(n),ue(t)),"BODY"===r.nodeName&&(r=r.firstChild)&&"BR"===r.nodeName&&m(r),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(o){e.didError(o)}},xe={enter:function(e,t,n){var r,o,i;if(t.preventDefault(),e._recordUndoState(n),ct(n.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||ce(n),r=ge(n),!r||/^T[HD]$/.test(r.nodeName))return de(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if(/^PRE|CODE|SAMP$/.test(r.nodeName))return de(n,e._doc.createTextNode("\n")),n.collapse(!1),r.normalize(),e.setSelection(n),void e._updatePath(n,!0);if((o=u(r,"LI"))&&(r=o),!r.textContent){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(it,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Je,n)}for(i=Ye(e,r,n.startContainer,n.startOffset),Ze(r),Ie(r),S(r);i.nodeType===A;){var a,s=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===H)){s=e._doc.createTextNode(""),v(i,s),i=s;break}for(;s&&s.nodeType===D&&!s.data&&(a=s.nextSibling,a&&"BR"!==a.nodeName);)m(s),s=a;if(!s||"BR"===s.nodeName||s.nodeType===D&&!G)break;i=s}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Ce(n)){t.preventDefault();var r,o=ge(n);if(!o)return;if(y(o.parentNode),r=f(o)){if(!r.isContentEditable)return void m(r);for(b(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n)}else if(o){if(u(o,"UL")||u(o,"OL"))return e.modifyBlocks(it,n);if(u(o,"BLOCKQUOTE"))return e.modifyBlocks(Xe,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Ee(e)},0);else t.preventDefault(),ce(n),Ee(e,n)},"delete":function(e,t,n){var r,o,i,a,s,d;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Ne(n)){if(t.preventDefault(),r=ge(n),!r)return;if(y(r.parentNode),o=h(r)){if(!o.isContentEditable)return void m(o);for(b(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{if(i=n.cloneRange(),pe(n,e._body),a=n.endContainer,s=n.endOffset,a.nodeType===A&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),m(d),ue(n),void Ee(e,n);e.setSelection(i),setTimeout(function(){Ee(e)},0)}else t.preventDefault(),ce(n),Ee(e,n)},tab:function(e,t,n){var r,o;if(e._removeZWS(),n.collapsed&&Ce(n))for(r=ge(n);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(ot,n));break}r=o}},"shift-tab":function(e,t,n){if(e._removeZWS(),n.collapsed&&Ce(n)){var r=n.startContainer;(u(r,"UL")||u(r,"OL"))&&(t.preventDefault(),e.modifyBlocks(it,n))}},space:function(e,t,n){var r,o;e._recordUndoState(n),ct(n.startContainer),e._getRangeAndRemoveBookmark(n),r=n.endContainer,o=r.parentNode,n.collapsed&&"A"===o.nodeName&&!r.nextSibling&&n.endOffset===g(r)&&n.setStartAfter(o),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};K&&V&&(xe["meta-left"]=function(e,t){t.preventDefault();var n=Ve(e);n&&n.modify&&n.modify("move","backward","lineboundary")},xe["meta-right"]=function(e,t){t.preventDefault();var n=Ve(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),K||(xe.pageup=function(e){e.moveCursorToStart()},xe.pagedown=function(e){e.moveCursorToEnd()}),xe[Y+"shift-m"]=function(e,t,n){t.preventDefault(),e.hasFormat("pre",null,n)?e.removePreformatted():e.makePreformatted()},xe[Y+"b"]=be("B"),xe[Y+"i"]=be("I"),xe[Y+"u"]=be("U"),xe[Y+"shift-7"]=be("S"),xe[Y+"shift-5"]=be("SUB",{tag:"SUP"}),xe[Y+"shift-6"]=be("SUP",{tag:"SUB"}),xe[Y+"shift-8"]=Te("makeUnorderedList"),xe[Y+"shift-9"]=Te("makeOrderedList"),xe[Y+"["]=Te("decreaseQuoteLevel"),xe[Y+"]"]=Te("increaseQuoteLevel"),xe[Y+"y"]=Te("redo"),xe[Y+"z"]=Te("undo"),xe[Y+"shift-z"]=Te("redo");var Be={1:10,2:13,3:16,4:18,5:24,6:32,7:48},ke={backgroundColor:{regexp:te,replace:function(e,t){return N(e,"SPAN",{"class":"highlight",style:"background-color:"+t})}},color:{regexp:te,replace:function(e,t){return N(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return N(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return N(e,"I")}},fontFamily:{regexp:te,replace:function(e,t){return N(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:te,replace:function(e,t){return N(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},Oe=function(e){return function(t,n){var r=N(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(C(t)),r}},Le={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in ke)r=ke[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:Oe("B"),EM:Oe("I"),STRIKE:Oe("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=N(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=N(c,"SPAN",{"class":"size",style:"font-size:"+Be[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=N(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=N(c,"SPAN")),t.replaceChild(a,e),i.appendChild(C(e)),i},TT:function(e,t){var n=N(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(C(e)),n}},Ae=/^(?: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)$/,De=/^(?:HEAD|META|STYLE)/,Re=new n(null,I|P,function(){return!0}),Pe=function ht(e){var t,n,r,o,i,a,d,l,c,f,h,u,p=e.childNodes;for(t=e;s(t);)t=t.parentNode;for(Re.root=t,n=0,r=p.length;r>n;n+=1)if(o=p[n],i=o.nodeName,a=o.nodeType,d=Le[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(De.test(i)){e.removeChild(o),n-=1,r-=1;continue}if(!Ae.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(C(o),o);continue}}l&&ht(o)}else{if(a===D){if(h=o.data,c=!te.test(h.charAt(0)),f=!te.test(h.charAt(h.length-1)),!c&&!f)continue;if(c){for(Re.currentNode=o;(u=Re.previousPONode())&&(i=u.nodeName,!("IMG"===i||"#text"===i&&/\S/.test(u.data)));)if(!s(u)){u=null;break}u||(h=h.replace(/^\s+/g,""))}if(f){for(Re.currentNode=o;(u=Re.nextNode())&&!("IMG"===i||"#text"===i&&/\S/.test(u.data));)if(!s(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},Ie=function ut(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==A||a(t)?t.nodeType!==D||t.data||e.removeChild(t):(ut(t),s(t)&&!t.firstChild&&e.removeChild(t))},Ue=function(e){return e.nodeType===A?"BR"===e.nodeName:te.test(e.data)},we=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,P|I,Ue),t.currentNode=e,!!t.nextNode()},Fe=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=we(o[t]);for(;a--;)n=o[a],r=n.parentNode,r&&(i[a]?s(r)||y(r):m(n))},Me=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._body,i=this;this.saveUndoState(n),!j&&t?(pe(n,o),r.appendChild(ce(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()):setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0),this.setSelection(n)},He=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");!j&&t&&(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},ze=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,f=this;if(!j&&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,!j&&o&&(ne.call(o,"text/html")>-1||!V&&ne.call(o,"text/plain")>-1&&ne.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._body,u=this.getSelection(),p=u.startContainer,g=u.startOffset,v=u.endContainer,C=u.endOffset,N=ge(u),S=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(h.scrollTop+(N?N.getBoundingClientRect().top:0))+"px; right: 150%; width: 1px; height: 1px;"});h.appendChild(S),u.selectNodeContents(S),this.setSelection(u),setTimeout(function(){try{f._awaitingPaste=!1;for(var e,t,n="",r=S;S=r;)r=S.nextSibling,m(S),e=S.firstChild,e&&e===S.lastChild&&"DIV"===e.nodeName&&(S=e),n+=S.innerHTML;t=f._createRange(p,g,v,C),f.setSelection(t),n&&f.insertHTML(n,!0)}catch(o){f.didError(o)}},0)},We=[],qe=k.prototype;qe.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},qe.createElement=function(e,t,n){return N(this._doc,e,t,n)},qe.createDefaultBlock=function(e){var t=this._config;return S(this.createElement(t.blockTag,t.blockAttributes,e))},qe.didError=function(e){console.log(e)},qe.getDocument=function(){return this._doc};var Ke={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};qe.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},qe.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)Ke[e]||n.removeEventListener(e,this,!0);this._mutation&&this._mutation.disconnect();for(var o=We.length;o--;)We[o]===this&&We.splice(o,1)},qe.handleEvent=function(e){this.fireEvent(e.type,e)},qe.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ke[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)},qe.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],Ke[e]||this._doc.removeEventListener(e,this,!1))}return this},qe._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},qe.scrollRangeIntoView=function(e){var t,n,r=e.getBoundingClientRect();if(r&&!r.top&&(t=this._doc.createElement("SPAN"),e=e.cloneRange(),de(e,t),r=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),n.normalize()),r){var o=this._win,i=o.innerHeight,a=r.top;a>i&&o.scrollBy(0,a-i+20),this.fireEvent("scrollPointIntoView",{x:r.left,y:a})}},qe._moveCursorTo=function(e){var t=this._body,n=this._createRange(t,e?0:t.childNodes.length);return ue(n),this.setSelection(n),this},qe.moveCursorToStart=function(){return this._moveCursorTo(!0)},qe.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var Ve=function(e){return e._win.getSelection()||null};qe.setSelection=function(e){if(e){q&&this._win.focus();var t=Ve(this);t&&(t.removeAllRanges(),t.addRange(e),this.scrollRangeIntoView(e))}return this},qe.getSelection=function(){var e,t,n,r=Ve(this);return r&&r.rangeCount?(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n),this._lastSelection=e):e=this._lastSelection,e||(e=this._createRange(this._body.firstChild,0)),e},qe.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,I|P,function(e){return he(t,e,!0)}),o=t.startContainer,i=t.endContainer,a=r.currentNode=o,d="",l=!1;for(r.filter(a)||(a=r.nextNode());a;)a.nodeType===D?(e=a.data,e&&/\S/.test(e)&&(a===i&&(e=e.slice(0,t.endOffset)),a===o&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===a.nodeName||l&&!s(a))&&(d+="\n",l=!1),a=r.nextNode();return d},qe.getPath=function(){return this._path};var Ze=function(e){for(var t,r,o,i=new n(e,I,function(){return!0},!1);r=i.nextNode();)for(;(o=r.data.indexOf(H))>-1;){if(1===r.length){do t=r.parentNode,t.removeChild(r),r=t,i.currentNode=t;while(s(r)&&!g(r));break}r.deleteData(o,1)}};qe._didAddZWS=function(){this._hasZWS=!0},qe._removeZWS=function(){this._hasZWS&&(Ze(this._body),this._hasZWS=!1)},qe._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}))),e.collapsed||this.fireEvent("select")},qe._updatePathOnEvent=function(){this._updatePath(this.getSelection())},qe.focus=function(){return G||this._body.focus(),this._win.focus(),this},qe.blur=function(){return V&&this._body.blur(),top.focus(),this};var Ge="squire-selection-start",je="squire-selection-end";qe._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ge,type:"hidden"}),r=this.createElement("INPUT",{id:je,type:"hidden"});de(e,n),e.collapse(!1),de(e,r),n.compareDocumentPosition(r)&L&&(n.id=je,r.id=Ge,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},qe._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ge),r=t.getElementById(je);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:ne.call(i.childNodes,n),endOffset:ne.call(a.childNodes,r)};i===a&&(s.endOffset-=1),m(n),m(r),T(i,s),i!==a&&T(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ue(e),o&&e.collapse(!0)}return e||null},qe._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},qe._docWasChanged=function(){return ee&&this._ignoreChange?void(this._ignoreChange=!1):(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),void this.fireEvent("input"))},qe._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},qe.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;!r.collapsed&&r.startContainer.nodeType===D&&r.startOffset===r.startContainer.length&&r.startContainer.nextSibling&&r.setStartBefore(r.startContainer.nextSibling),!r.collapsed&&r.endContainer.nodeType===D&&0===r.endOffset&&r.endContainer.previousSibling&&r.setEndAfter(r.endContainer.previousSibling);var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===D)return!1;o=new n(a,I,function(e){return he(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},qe.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===D)for(n.nodeType===D&&(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},qe._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),de(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{if(i=new n(r.commonAncestorContainer,I|P,function(e){return(e.nodeType===D||"BR"===e.nodeName||"IMG"===e.nodeName)&&he(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,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!==D&&(c.nodeType===D?(s=c,l=c.length):(s=c.parentNode,l=1)),r=this._createRange(a,d,s,l)}return r},qe._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(X?(i=a.createTextNode(H),this._didAddZWS()):i=a.createTextNode(""),de(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(!he(n,e,!1)){var r,o,i=e.nodeType===D;if(!he(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)}},g=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return he(n,r,!0)&&o(r,e,t)});r||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];v(n,t),t.appendChild(n)}),g.forEach(function(e){v(e,C(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return T(d,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},qe.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),ee||this._docWasChanged(),this):void 0};var Qe={DT:"DD",DD:"DT",LI:"LI"},Ye=function(e,t,n,r){var i=Qe[t.nodeName],a=null,s=_(n,r,t.parentNode),d=e._config;return i||(i=d.blockTag,a=d.blockAttributes),o(s,i,a)||(t=N(s.ownerDocument,i,a),s.dir&&(t.dir=s.dir),v(s,t),t.appendChild(C(s)),s=t),s};qe.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=ge(n),o=me(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),ee||this._docWasChanged()),this},qe.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Se(t);var n,r=this._body;return pe(t,r),n=le(t,r),de(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],v(s,C(s));y(i),v(o,i)}return e},ot=function(e){var t,n,r,o,i,a,s=e.querySelectorAll("LI"),d=this._config.tagAttributes,c=d.li;for(t=0,n=s.length;n>t;t+=1)r=s[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||(a=d[o.toLowerCase()],v(r,this.createElement("LI",c,[i=this.createElement(o,a)]))),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),y(e),e},at=function(e,t){for(var n,r=c(t),o=[];n=r.nextNode();)o.push(n.textContent);return e._doc.createTextNode(o.join("\n")||"\n")},st=function(e){return this.createElement("PRE",this._config.tagAttributes.pre,[this.createElement("INPUT",{id:Ge,type:"hidden"}),at(this,e),this.createElement("INPUT",{id:je,type:"hidden"})])},dt=function(e){var t=this._doc.createRange(),n=e.querySelector("#"+Ge),r=e.querySelector("#"+je);if(!n||!r)return e;t.setStartBefore(n),t.setEndAfter(r);var o=e.querySelectorAll("pre");if(0===o.length)return e;var i=o[0],a=o[o.length-1],s=t.startContainer,d=t.startOffset,l=t.endContainer,c=t.endOffset,f=[];if(n.nextSibling===r){var h,p=n.previousSibling;if(p&&p.nodeType===D){var g=p.nodeValue.lastIndexOf("\n");-1!==g?(h=p.splitText(g),p.parentNode.insertBefore(n,h)):p.parentNode.insertBefore(n,p),t.setStartBefore(n),d=t.startOffset,s=t.startContainer}var m=r.nextSibling;if(m&&m.nodeType===D){var C=m.nodeValue.indexOf("\n");-1!==C?(h=m.splitText(C+1),m.parentNode.insertBefore(r,h)):m.nextSibling?m.parentNode.insertBefore(r,m.nextSibling):m.parentNode.appendChild(r),t.setEndBefore(r),c=t.endOffset,l=t.endContainer}s.normalize()}u(l,"PRE")===a&&c0&&(_(s,d,i.parentNode),f.push(s)),o=e.querySelectorAll("pre"),t.setStartBefore(n),t.setEndAfter(r);for(var N,S=this,y=0;y]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i,ct=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,I,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=lt.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)};qe.insertHTML=function(e,t){var n=this.getSelection(),r=this._doc.createDocumentFragment(),o=this.createElement("DIV");o.innerHTML=e,r.appendChild(u(n.commonAncestorContainer,"PRE")?at(this,o):C(o)),this.saveUndoState(n);try{var i=r,a={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1};for(ct(r),Pe(r),Fe(r),Ie(r),r.normalize();i=h(i);)S(i);t&&this.fireEvent("willPaste",a),a.defaultPrevented||(fe(n,a.fragment),ee||this._docWasChanged(),n.collapse(!1),this._ensureBottomLine()),this.setSelection(n),this._updatePath(n,!0)}catch(s){this.didError(s)}return this},qe.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 ft=function(e,t,n){return function(){return this[e](t,n),this.focus()}};qe.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},qe.bold=ft("changeFormat",{tag:"B"}),qe.italic=ft("changeFormat",{tag:"I"}),qe.underline=ft("changeFormat",{tag:"U"}),qe.strikethrough=ft("changeFormat",{tag:"S"}),qe.subscript=ft("changeFormat",{tag:"SUB"},{tag:"SUP"}),qe.superscript=ft("changeFormat",{tag:"SUP"},{tag:"SUB"}),qe.removeBold=ft("changeFormat",null,{tag:"B"}),qe.removeItalic=ft("changeFormat",null,{tag:"I"}),qe.removeUnderline=ft("changeFormat",null,{tag:"U"}),qe.removeStrikethrough=ft("changeFormat",null,{tag:"S"}),qe.removeSubscript=ft("changeFormat",null,{tag:"SUB"}),qe.removeSuperscript=ft("changeFormat",null,{tag:"SUP"}),qe.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;de(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},qe.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},qe.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},qe.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()},qe.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},qe.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},qe.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()},qe.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},qe.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=e.commonAncestorContainer;t&&!d(t);)t=t.parentNode;if(t||(Se(e),t=this._body),t.nodeType===D)return this;this.saveUndoState(e),pe(e,t);for(var n,r,o,i=t.ownerDocument,a=e.startContainer,s=e.startOffset,l=e.endContainer,c=e.endOffset,f=i.createDocumentFragment(),h=i.createDocumentFragment(),u=_(l,c,t),p=_(a,s,t);p!==u;)n=p.nextSibling,f.appendChild(p),p=n;return O(this,f,h),h.normalize(),p=h.firstChild,n=h.lastChild,o=t.childNodes,p?(t.insertBefore(h,u),s=ne.call(o,p),c=ne.call(o,n)+1):(s=ne.call(o,u),c=s),r={startContainer:t,startOffset:s,endContainer:t,endOffset:c},T(t,r),e.setStart(r.startContainer,r.startOffset),e.setEnd(r.endContainer,r.endOffset),ue(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},qe.increaseQuoteLevel=ft("modifyBlocks",$e),qe.decreaseQuoteLevel=ft("modifyBlocks",Xe),qe.makeUnorderedList=ft("modifyBlocks",tt),qe.makeOrderedList=ft("modifyBlocks",nt),qe.removeList=ft("modifyBlocks",rt),qe.makePreformatted=ft("modifyBlocks",st),qe.removePreformatted=ft("modifyBlocks",dt),qe.increaseListLevel=ft("modifyBlocks",ot),qe.decreaseListLevel=ft("modifyBlocks",it),"object"==typeof exports?module.exports=k:"function"==typeof define&&define.amd?define(function(){return k}):(z.Squire=k,top!==z&&"true"===e.documentElement.getAttribute("data-squireinit")&&(z.editor=new k(e),z.onEditorLoad&&(z.onEditorLoad(z.editor),z.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,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!a(e)&&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&&!!ie[e.nodeName]}function s(e){return oe.test(e.nodeName)}function d(e){var t=e.nodeType;return(t===A||t===R)&&!s(e)&&r(e.childNodes,s)}function l(e){var t=e.nodeType;return!(t!==A&&t!==R||s(e)||d(e))}function c(e){var t=e.ownerDocument,r=new n(t.body,P,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,a=e.parentNode;return a&&e.nodeType===A?(t=p(a),t+=(t?">":"")+e.nodeName,(n=e.id)&&(t+="#"+n),(r=e.className.trim())&&(o=r.split(/\s\s*/),o.sort(),t+=".",t+=o.join(".")),(i=e.dir)&&(t+="[dir="+i+"]")):t=a?p(a):"",t}function g(e){var t=e.nodeType;return t===A?e.childNodes.length:e.length||0}function m(e){var t=e.parentNode;return t&&t.removeChild(e),e}function v(e,t){var n=e.parentNode;n&&n.replaceChild(t,e)}function C(e){for(var t=e.ownerDocument.createDocumentFragment(),n=e.childNodes,r=n?n.length:0;r--;)t.appendChild(e.firstChild);return t}function N(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 S(e){var t,n,r=e.ownerDocument,o=e;if("BODY"===e.nodeName&&((n=e.firstChild)&&"BR"!==n.nodeName||(t=x(r).createDefaultBlock(),n?e.replaceChild(t,n):e.appendChild(t),e=t,t=null)),s(e)){for(n=e.firstChild;X&&n&&n.nodeType===D&&!n.data;)e.removeChild(n),n=e.firstChild;n||(X?(t=r.createTextNode(H),x(r)._didAddZWS()):t=r.createTextNode(""))}else if($){for(;e.nodeType!==D&&!a(e);){if(n=e.firstChild,!n){t=r.createTextNode("");break}e=n}e.nodeType===D?/^ +$/.test(e.data)&&(e.data=""):a(e)&&e.parentNode.insertBefore(r.createTextNode(""),e)}else if(!e.querySelector("BR"))for(t=N(r,"BR");(n=e.lastElementChild)&&!s(n);)e=n;return t&&e.appendChild(t),o}function y(e){var t,n,r,o,i=e.childNodes,a=e.ownerDocument,d=null,c=x(a)._config;for(t=0,n=i.length;n>t;t+=1)r=i[t],o="BR"===r.nodeName,!o&&s(r)?(d||(d=N(a,c.blockTag,c.blockAttributes)),d.appendChild(r),t-=1,n-=1):(o||d)&&(d||(d=N(a,c.blockTag,c.blockAttributes)),S(d),o?e.replaceChild(d,r):(e.insertBefore(d,r),t+=1,n+=1),d=null),l(r)&&y(r);return d&&e.appendChild(S(d)),e}function _(e,t,n){var r,o,i,a=e.nodeType;if(a===D&&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))),m(n),n.nodeType===D?r.appendData(n.data):l.push(C(n));else if(n.nodeType===A){for(o=l.length;o--;)n.appendChild(l.pop());T(n,t)}}function b(e,t,n){for(var r,o,i,a=t;1===a.parentNode.childNodes.length;)a=a.parentNode;m(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)),T(e,i),n.setStart(i.startContainer,i.startOffset),n.collapse(!0),G&&(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=N(a,"DIV"),n.appendChild(C(r)),r.appendChild(n)}m(e),t=!l(e),r.appendChild(C(e)),t&&y(r),o&&E(o)}else s&&(r=N(a,"DIV"),e.insertBefore(r,o),S(r))}function x(e){for(var t,n=We.length;n--;)if(t=We[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){var n,r=e.defaultView,o=e.body;this._win=r,this._doc=e,this._body=o,this._events={},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),r.addEventListener("focus",this,!1),r.addEventListener("blur",this,!1),this._undoIndex=-1,this._undoStack=[],this._undoStackLength=0,this._isInUndoState=!1,this._ignoreChange=!1,ee?(n=new MutationObserver(this._docWasChanged.bind(this)),n.observe(o,{childList:!0,attributes:!0,characterData:!0,subtree:!0}),this._mutation=n):this.addEventListener("keyup",this._keyUpDetectChange),this._awaitingPaste=!1,this.addEventListener(Z?"beforecut":"cut",Me),this.addEventListener("copy",He),this.addEventListener(Z?"beforepaste":"paste",ze),this.addEventListener(G?"keypress":"keydown",_e),this._keyHandlers=Object.create(xe),this.setConfig(t),Z&&(r.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}),o.setAttribute("contenteditable","true");try{e.execCommand("enableObjectResizing",!1,"false"),e.execCommand("enableInlineTableEditing",!1,"false")}catch(i){}We.push(this),this.setHTML("")}function k(e,t,n){var r,o;for(r=t.firstChild;r;r=o){if(o=r.nextSibling,s(r)){if(r.nodeType===D||"BR"===r.nodeName||"IMG"===r.nodeName){n.appendChild(r);continue}}else if(d(r)){n.appendChild(e.createDefaultBlock([k(e,r,e._doc.createDocumentFragment())]));continue}k(e,r,n)}return n}var L=2,A=1,D=3,R=11,P=1,I=4,U=0,w=1,F=2,M=3,H="​",z=e.defaultView,W=navigator.userAgent,q=/iP(?:ad|hone|od)/.test(W),V=/Mac OS X/.test(W),K=/Gecko\//.test(W),Z=/Trident\/[456]\./.test(W),G=!!z.opera,j=/Edge\//.test(W),Q=!j&&/WebKit\//.test(W),Y=V?"meta-":"ctrl-",$=Z||G,X=Z||Q,J=Z,ee="undefined"!=typeof MutationObserver,te=/[^ \t\r\n]/,ne=Array.prototype.indexOf;Object.create||(Object.create=function(e){var t=function(){};return t.prototype=e,new t});var re={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(re[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(re[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(re[e.nodeType]&r&&o(e))return this.currentNode=e,e;t=e}};var oe=/^(?:#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)$/,ie={BR:1,IMG:1,INPUT:1},ae=function(e,t){for(var n=e.childNodes;t&&e.nodeType===A;)e=n[t-1],n=e.childNodes,t=n.length;return e},se=function(e,t){if(e.nodeType===A){var n=e.childNodes;if(t-1,i=e.compareBoundaryPoints(w,r)<1;return!o&&!i}var a=e.compareBoundaryPoints(U,r)<1,s=e.compareBoundaryPoints(F,r)>-1;return a&&s},ue=function(e){for(var t,n=e.startContainer,r=e.startOffset,o=e.endContainer,i=e.endOffset;n.nodeType!==D&&(t=n.childNodes[r],t&&!a(t));)n=t,r=0;if(i)for(;o.nodeType!==D&&(t=o.childNodes[i-1],t&&!a(t));)o=t,i=g(o);else for(;o.nodeType!==D&&(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))},pe=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=ne.call(n.childNodes,r),r=n;for(;i!==t&&a===g(i);)n=i.parentNode,a=ne.call(n.childNodes,i)+1,i=n;e.setStart(r,o),e.setEnd(i,a)},ge=function(e){var t,n=e.startContainer;return s(n)?t=f(n):d(n)?t=n:(t=ae(n,e.startOffset),t=h(t)),t&&he(e,t,!0)?t:null},me=function(e){var t,n,r=e.endContainer;if(s(r))t=f(r);else if(d(r))t=r;else{if(t=se(r,e.endOffset),!t)for(t=r.ownerDocument.body;n=t.lastChild;)t=n;t=f(t)}return t&&he(e,t,!0)?t:null},ve=new n(null,I|P,function(e){return e.nodeType===D?te.test(e.data):"IMG"===e.nodeName}),Ce=function(e){var t=e.startContainer,n=e.startOffset;if(ve.root=null,t.nodeType===D){if(n)return!1;ve.currentNode=t}else ve.currentNode=se(t,n);return ve.root=ge(e),!ve.previousNode()},Ne=function(e){var t,n=e.endContainer,r=e.endOffset;if(ve.root=null,n.nodeType===D){if(t=n.data.length,t&&t>r)return!1;ve.currentNode=n}else ve.currentNode=ae(n,r);return ve.root=me(e),!ve.nextNode()},Se=function(e){var t,n=ge(e),r=me(e);n&&r&&(t=n.parentNode,e.setStart(t,ne.call(t.childNodes,n)),t=r.parentNode,e.setEnd(t,ne.call(t.childNodes,r)+1))},ye={8:"backspace",9:"tab",13:"enter",32:"space",33:"pageup",34:"pagedown",37:"left",39:"right",46:"delete",219:"[",221:"]"},_e=function(e){var t=e.keyCode,n=ye[t],r="",o=this.getSelection();e.defaultPrevented||(n||(n=String.fromCharCode(t).toLowerCase(),/^[A-Za-z0-9]$/.test(n)||(n="")),G&&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),ce(o),this._ensureBottomLine(),this.setSelection(o),this._updatePath(o,!0)))},Te=function(e){return function(t,n){n.preventDefault(),t[e]()}},be=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)}},Ee=function(e,t){try{t||(t=e.getSelection());var n,r=t.startContainer;for(r.nodeType===D&&(r=r.parentNode),n=r;s(n)&&(!n.textContent||n.textContent===H);)r=n,n=r.parentNode;r!==n&&(t.setStart(n,ne.call(n.childNodes,r)),t.collapse(!0),n.removeChild(r),d(n)||(n=f(n)),S(n),ue(t)),"BODY"===r.nodeName&&(r=r.firstChild)&&"BR"===r.nodeName&&m(r),e._ensureBottomLine(),e.setSelection(t),e._updatePath(t,!0)}catch(o){e.didError(o)}},xe={enter:function(e,t,n){var r,o,i;if(t.preventDefault(),e._recordUndoState(n),ct(n.startContainer),e._removeZWS(),e._getRangeAndRemoveBookmark(n),n.collapsed||ce(n),r=ge(n),!r||/^T[HD]$/.test(r.nodeName))return de(n,e.createElement("BR")),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if(/^PRE|CODE|SAMP$/.test(r.nodeName))return se(n.endContainer,n.endOffset).nodeValue[n.endOffset]?de(n,e._doc.createTextNode("\n")):de(n,e._doc.createTextNode("\n\n")),r.normalize(),n.collapse(!1),e.setSelection(n),void e._updatePath(n,!0);if((o=u(r,"LI"))&&(r=o),!r.textContent){if(u(r,"UL")||u(r,"OL"))return e.modifyBlocks(it,n);if(u(r,"BLOCKQUOTE"))return e.modifyBlocks(Je,n)}for(i=Ye(e,r,n.startContainer,n.startOffset),Ze(r),Ie(r),S(r);i.nodeType===A;){var a,s=i.firstChild;if("A"===i.nodeName&&(!i.textContent||i.textContent===H)){s=e._doc.createTextNode(""),v(i,s),i=s;break}for(;s&&s.nodeType===D&&!s.data&&(a=s.nextSibling,a&&"BR"!==a.nodeName);)m(s),s=a;if(!s||"BR"===s.nodeName||s.nodeType===D&&!G)break;i=s}n=e._createRange(i,0),e.setSelection(n),e._updatePath(n,!0)},backspace:function(e,t,n){if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Ce(n)){t.preventDefault();var r,o=ge(n);if(!o)return;if(y(o.parentNode),r=f(o)){if(!r.isContentEditable)return void m(r);for(b(r,o,n),o=r.parentNode;o&&!o.nextSibling;)o=o.parentNode;o&&(o=o.nextSibling)&&E(o),e.setSelection(n)}else if(o){if(u(o,"UL")||u(o,"OL"))return e.modifyBlocks(it,n);if(u(o,"BLOCKQUOTE"))return e.modifyBlocks(Xe,n);e.setSelection(n),e._updatePath(n,!0)}}else e.setSelection(n),setTimeout(function(){Ee(e)},0);else t.preventDefault(),ce(n),Ee(e,n)},"delete":function(e,t,n){var r,o,i,a,s,d;if(e._removeZWS(),e.saveUndoState(n),n.collapsed)if(Ne(n)){if(t.preventDefault(),r=ge(n),!r)return;if(y(r.parentNode),o=h(r)){if(!o.isContentEditable)return void m(o);for(b(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{if(i=n.cloneRange(),pe(n,e._body),a=n.endContainer,s=n.endOffset,a.nodeType===A&&(d=a.childNodes[s],d&&"IMG"===d.nodeName))return t.preventDefault(),m(d),ue(n),void Ee(e,n);e.setSelection(i),setTimeout(function(){Ee(e)},0)}else t.preventDefault(),ce(n),Ee(e,n)},tab:function(e,t,n){var r,o;if(e._removeZWS(),n.collapsed&&Ce(n))for(r=ge(n);o=r.parentNode;){if("UL"===o.nodeName||"OL"===o.nodeName){r.previousSibling&&(t.preventDefault(),e.modifyBlocks(ot,n));break}r=o}},"shift-tab":function(e,t,n){if(e._removeZWS(),n.collapsed&&Ce(n)){var r=n.startContainer;(u(r,"UL")||u(r,"OL"))&&(t.preventDefault(),e.modifyBlocks(it,n))}},space:function(e,t,n){var r,o;e._recordUndoState(n),ct(n.startContainer),e._getRangeAndRemoveBookmark(n),r=n.endContainer,o=r.parentNode,n.collapsed&&"A"===o.nodeName&&!r.nextSibling&&n.endOffset===g(r)&&n.setStartAfter(o),e.setSelection(n)},left:function(e){e._removeZWS()},right:function(e){e._removeZWS()}};V&&K&&(xe["meta-left"]=function(e,t){t.preventDefault();var n=Ke(e);n&&n.modify&&n.modify("move","backward","lineboundary")},xe["meta-right"]=function(e,t){t.preventDefault();var n=Ke(e);n&&n.modify&&n.modify("move","forward","lineboundary")}),V||(xe.pageup=function(e){e.moveCursorToStart()},xe.pagedown=function(e){e.moveCursorToEnd()}),xe[Y+"shift-m"]=function(e,t,n){t.preventDefault(),e.hasFormat("pre",null,n)?e.removePreformatted():e.makePreformatted()},xe[Y+"b"]=be("B"),xe[Y+"i"]=be("I"),xe[Y+"u"]=be("U"),xe[Y+"shift-7"]=be("S"),xe[Y+"shift-5"]=be("SUB",{tag:"SUP"}),xe[Y+"shift-6"]=be("SUP",{tag:"SUB"}),xe[Y+"shift-8"]=Te("makeUnorderedList"),xe[Y+"shift-9"]=Te("makeOrderedList"),xe[Y+"["]=Te("decreaseQuoteLevel"),xe[Y+"]"]=Te("increaseQuoteLevel"),xe[Y+"y"]=Te("redo"),xe[Y+"z"]=Te("undo"),xe[Y+"shift-z"]=Te("redo");var Be={1:10,2:13,3:16,4:18,5:24,6:32,7:48},Oe={backgroundColor:{regexp:te,replace:function(e,t){return N(e,"SPAN",{"class":"highlight",style:"background-color:"+t})}},color:{regexp:te,replace:function(e,t){return N(e,"SPAN",{"class":"colour",style:"color:"+t})}},fontWeight:{regexp:/^bold/i,replace:function(e){return N(e,"B")}},fontStyle:{regexp:/^italic/i,replace:function(e){return N(e,"I")}},fontFamily:{regexp:te,replace:function(e,t){return N(e,"SPAN",{"class":"font",style:"font-family:"+t})}},fontSize:{regexp:te,replace:function(e,t){return N(e,"SPAN",{"class":"size",style:"font-size:"+t})}}},ke=function(e){return function(t,n){var r=N(t.ownerDocument,e);return n.replaceChild(r,t),r.appendChild(C(t)),r}},Le={SPAN:function(e,t){var n,r,o,i,a,s,d=e.style,l=e.ownerDocument;for(n in Oe)r=Oe[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:ke("B"),EM:ke("I"),STRIKE:ke("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=N(c,"SPAN",{"class":"font",style:"font-family:"+s}),a=n,i=n),d&&(r=N(c,"SPAN",{"class":"size",style:"font-size:"+Be[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=N(c,"SPAN",{"class":"colour",style:"color:"+l}),a||(a=o),i&&i.appendChild(o),i=o),a||(a=i=N(c,"SPAN")),t.replaceChild(a,e),i.appendChild(C(e)),i},TT:function(e,t){var n=N(e.ownerDocument,"SPAN",{"class":"font",style:'font-family:menlo,consolas,"courier new",monospace'});return t.replaceChild(n,e),n.appendChild(C(e)),n}},Ae=/^(?: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)$/,De=/^(?:HEAD|META|STYLE)/,Re=new n(null,I|P,function(){return!0}),Pe=function ht(e){var t,n,r,o,i,a,d,l,c,f,h,u,p=e.childNodes;for(t=e;s(t);)t=t.parentNode;for(Re.root=t,n=0,r=p.length;r>n;n+=1)if(o=p[n],i=o.nodeName,a=o.nodeType,d=Le[i],a===A){if(l=o.childNodes.length,d)o=d(o,e);else{if(De.test(i)){e.removeChild(o),n-=1,r-=1;continue}if(!Ae.test(i)&&!s(o)){n-=1,r+=l-1,e.replaceChild(C(o),o);continue}}l&&ht(o)}else{if(a===D){if(h=o.data,c=!te.test(h.charAt(0)),f=!te.test(h.charAt(h.length-1)),!c&&!f)continue;if(c){for(Re.currentNode=o;(u=Re.previousPONode())&&(i=u.nodeName,!("IMG"===i||"#text"===i&&/\S/.test(u.data)));)if(!s(u)){u=null;break}u||(h=h.replace(/^\s+/g,""))}if(f){for(Re.currentNode=o;(u=Re.nextNode())&&!("IMG"===i||"#text"===i&&/\S/.test(u.data));)if(!s(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},Ie=function ut(e){for(var t,n=e.childNodes,r=n.length;r--;)t=n[r],t.nodeType!==A||a(t)?t.nodeType!==D||t.data||e.removeChild(t):(ut(t),s(t)&&!t.firstChild&&e.removeChild(t))},Ue=function(e){return e.nodeType===A?"BR"===e.nodeName:te.test(e.data)},we=function(e){for(var t,r=e.parentNode;s(r);)r=r.parentNode;return t=new n(r,P|I,Ue),t.currentNode=e,!!t.nextNode()},Fe=function(e){var t,n,r,o=e.querySelectorAll("BR"),i=[],a=o.length;for(t=0;a>t;t+=1)i[t]=we(o[t]);for(;a--;)n=o[a],r=n.parentNode,r&&(i[a]?s(r)||y(r):m(n))},Me=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div"),o=this._body,i=this;this.saveUndoState(n),!j&&t?(pe(n,o),r.appendChild(ce(n,o)),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault()):setTimeout(function(){try{i._ensureBottomLine()}catch(e){i.didError(e)}},0),this.setSelection(n)},He=function(e){var t=e.clipboardData,n=this.getSelection(),r=this.createElement("div");!j&&t&&(r.appendChild(n.cloneContents()),t.setData("text/html",r.innerHTML),t.setData("text/plain",r.innerText||r.textContent),e.preventDefault())},ze=function(e){var t,n,r,o,i,a=e.clipboardData,s=a&&a.items,d=!1,l=!1,c=null,f=this;if(!j&&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,!j&&o&&(ne.call(o,"text/html")>-1||!K&&ne.call(o,"text/plain")>-1&&ne.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._body,u=this.getSelection(),p=u.startContainer,g=u.startOffset,v=u.endContainer,C=u.endOffset,N=ge(u),S=this.createElement("DIV",{style:"position: absolute; overflow: hidden; top:"+(h.scrollTop+(N?N.getBoundingClientRect().top:0))+"px; right: 150%; width: 1px; height: 1px;"});h.appendChild(S),u.selectNodeContents(S),this.setSelection(u),setTimeout(function(){try{f._awaitingPaste=!1;for(var e,t,n="",r=S;S=r;)r=S.nextSibling,m(S),e=S.firstChild,e&&e===S.lastChild&&"DIV"===e.nodeName&&(S=e),n+=S.innerHTML;t=f._createRange(p,g,v,C),f.setSelection(t),n&&f.insertHTML(n,!0)}catch(o){f.didError(o)}},0)},We=[],qe=O.prototype;qe.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},qe.createElement=function(e,t,n){return N(this._doc,e,t,n)},qe.createDefaultBlock=function(e){var t=this._config;return S(this.createElement(t.blockTag,t.blockAttributes,e))},qe.didError=function(e){console.log(e)},qe.getDocument=function(){return this._doc};var Ve={focus:1,blur:1,pathChange:1,select:1,input:1,undoStateChange:1};qe.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},qe.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)Ve[e]||n.removeEventListener(e,this,!0);this._mutation&&this._mutation.disconnect();for(var o=We.length;o--;)We[o]===this&&We.splice(o,1)},qe.handleEvent=function(e){this.fireEvent(e.type,e)},qe.addEventListener=function(e,t){var n=this._events[e];return t?(n||(n=this._events[e]=[],Ve[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)},qe.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],Ve[e]||this._doc.removeEventListener(e,this,!1))}return this},qe._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},qe.scrollRangeIntoView=function(e){var t,n,r=e.getBoundingClientRect();if(r&&!r.top&&(t=this._doc.createElement("SPAN"),e=e.cloneRange(),de(e,t),r=t.getBoundingClientRect(),n=t.parentNode,n.removeChild(t),n.normalize()),r){var o=this._win,i=o.innerHeight,a=r.top;a>i&&o.scrollBy(0,a-i+20),this.fireEvent("scrollPointIntoView",{x:r.left,y:a})}},qe._moveCursorTo=function(e){var t=this._body,n=this._createRange(t,e?0:t.childNodes.length);return ue(n),this.setSelection(n),this},qe.moveCursorToStart=function(){return this._moveCursorTo(!0)},qe.moveCursorToEnd=function(){return this._moveCursorTo(!1)};var Ke=function(e){return e._win.getSelection()||null};qe.setSelection=function(e){if(e){q&&this._win.focus();var t=Ke(this);t&&(t.removeAllRanges(),t.addRange(e),this.scrollRangeIntoView(e))}return this},qe.getSelection=function(){var e,t,n,r=Ke(this);return r&&r.rangeCount?(e=r.getRangeAt(0).cloneRange(),t=e.startContainer,n=e.endContainer,t&&a(t)&&e.setStartBefore(t),n&&a(n)&&e.setEndBefore(n),this._lastSelection=e):e=this._lastSelection,e||(e=this._createRange(this._body.firstChild,0)),e},qe.getSelectedText=function(){var e,t=this.getSelection(),r=new n(t.commonAncestorContainer,I|P,function(e){return he(t,e,!0)}),o=t.startContainer,i=t.endContainer,a=r.currentNode=o,d="",l=!1;for(r.filter(a)||(a=r.nextNode());a;)a.nodeType===D?(e=a.data,e&&/\S/.test(e)&&(a===i&&(e=e.slice(0,t.endOffset)),a===o&&(e=e.slice(t.startOffset)),d+=e,l=!0)):("BR"===a.nodeName||l&&!s(a))&&(d+="\n",l=!1),a=r.nextNode();return d},qe.getPath=function(){return this._path};var Ze=function(e){for(var t,r,o,i=new n(e,I,function(){return!0},!1);r=i.nextNode();)for(;(o=r.data.indexOf(H))>-1;){if(1===r.length){do t=r.parentNode,t.removeChild(r),r=t,i.currentNode=t;while(s(r)&&!g(r));break}r.deleteData(o,1)}};qe._didAddZWS=function(){this._hasZWS=!0},qe._removeZWS=function(){this._hasZWS&&(Ze(this._body),this._hasZWS=!1)},qe._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}))),e.collapsed||this.fireEvent("select")},qe._updatePathOnEvent=function(){this._updatePath(this.getSelection())},qe.focus=function(){return G||this._body.focus(),this._win.focus(),this},qe.blur=function(){return K&&this._body.blur(),top.focus(),this};var Ge="squire-selection-start",je="squire-selection-end";qe._saveRangeToBookmark=function(e){var t,n=this.createElement("INPUT",{id:Ge,type:"hidden"}),r=this.createElement("INPUT",{id:je,type:"hidden"});de(e,n),e.collapse(!1),de(e,r),n.compareDocumentPosition(r)&L&&(n.id=je,r.id=Ge,t=n,n=r,r=t),e.setStartAfter(n),e.setEndBefore(r)},qe._getRangeAndRemoveBookmark=function(e){var t=this._doc,n=t.getElementById(Ge),r=t.getElementById(je);if(n&&r){var o,i=n.parentNode,a=r.parentNode,s={startContainer:i,endContainer:a,startOffset:ne.call(i.childNodes,n),endOffset:ne.call(a.childNodes,r)};i===a&&(s.endOffset-=1),m(n),m(r),T(i,s),i!==a&&T(a,s),e||(e=t.createRange()),e.setStart(s.startContainer,s.startOffset),e.setEnd(s.endContainer,s.endOffset),o=e.collapsed,ue(e),o&&e.collapse(!0)}return e||null},qe._keyUpDetectChange=function(e){var t=e.keyCode;e.ctrlKey||e.metaKey||e.altKey||!(16>t||t>20)||!(33>t||t>45)||this._docWasChanged()},qe._docWasChanged=function(){return ee&&this._ignoreChange?void(this._ignoreChange=!1):(this._isInUndoState&&(this._isInUndoState=!1,this.fireEvent("undoStateChange",{canUndo:!0,canRedo:!1})),void this.fireEvent("input"))},qe._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},qe.hasFormat=function(e,t,r){if(e=e.toUpperCase(),t||(t={}),!r&&!(r=this.getSelection()))return!1;!r.collapsed&&r.startContainer.nodeType===D&&r.startOffset===r.startContainer.length&&r.startContainer.nextSibling&&r.setStartBefore(r.startContainer.nextSibling),!r.collapsed&&r.endContainer.nodeType===D&&0===r.endOffset&&r.endContainer.previousSibling&&r.setEndAfter(r.endContainer.previousSibling);var o,i,a=r.commonAncestorContainer;if(u(a,e,t))return!0;if(a.nodeType===D)return!1;o=new n(a,I,function(e){return he(r,e,!0)},!1);for(var s=!1;i=o.nextNode();){if(!u(i,e,t))return!1;s=!0}return s},qe.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===D)for(n.nodeType===D&&(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},qe._addFormat=function(e,t,r){var o,i,a,s,d,l,c,f;if(r.collapsed)o=S(this.createElement(e,t)),de(r,o),r.setStart(o.firstChild,o.firstChild.length),r.collapse(!0);else{if(i=new n(r.commonAncestorContainer,I|P,function(e){return(e.nodeType===D||"BR"===e.nodeName||"IMG"===e.nodeName)&&he(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,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!==D&&(c.nodeType===D?(s=c,l=c.length):(s=c.parentNode,l=1)),r=this._createRange(a,d,s,l)}return r},qe._removeFormat=function(e,t,n,r){this._saveRangeToBookmark(n);var i,a=this._doc;n.collapsed&&(X?(i=a.createTextNode(H),this._didAddZWS()):i=a.createTextNode(""),de(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(!he(n,e,!1)){var r,o,i=e.nodeType===D;if(!he(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)}},g=Array.prototype.filter.call(d.getElementsByTagName(e),function(r){return he(n,r,!0)&&o(r,e,t)});r||g.forEach(function(e){p(e,e)}),u.forEach(function(e){var t=e[0].cloneNode(!1),n=e[1];v(n,t),t.appendChild(n)}),g.forEach(function(e){v(e,C(e))}),this._getRangeAndRemoveBookmark(n),i&&n.collapse(!1);var m={startContainer:n.startContainer,startOffset:n.startOffset,endContainer:n.endContainer,endOffset:n.endOffset};return T(d,m),n.setStart(m.startContainer,m.startOffset),n.setEnd(m.endContainer,m.endOffset),n},qe.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),ee||this._docWasChanged(),this):void 0};var Qe={DT:"DD",DD:"DT",LI:"LI"},Ye=function(e,t,n,r){var i=Qe[t.nodeName],a=null,s=_(n,r,t.parentNode),d=e._config;return i||(i=d.blockTag,a=d.blockAttributes),o(s,i,a)||(t=N(s.ownerDocument,i,a),s.dir&&(t.dir=s.dir),v(s,t),t.appendChild(C(s)),s=t),s};qe.forEachBlock=function(e,t,n){if(!n&&!(n=this.getSelection()))return this;t&&this.saveUndoState(n);var r=ge(n),o=me(n);if(r&&o)do if(e(r)||r===o)break;while(r=h(r));return t&&(this.setSelection(n),this._updatePath(n,!0),ee||this._docWasChanged()),this},qe.modifyBlocks=function(e,t){if(!t&&!(t=this.getSelection()))return this;this._isInUndoState?this._saveRangeToBookmark(t):this._recordUndoState(t),Se(t);var n,r=this._body;return pe(t,r),n=le(t,r),de(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],v(s,C(s));y(i),v(o,i)}return e},ot=function(e){var t,n,r,o,i,a,s=e.querySelectorAll("LI"),d=this._config.tagAttributes,c=d.li;for(t=0,n=s.length;n>t;t+=1)r=s[t],l(r.firstChild)||(o=r.parentNode.nodeName,i=r.previousSibling,i&&(i=i.lastChild)&&i.nodeName===o||(a=d[o.toLowerCase()],v(r,this.createElement("LI",c,[i=this.createElement(o,a)]))),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),y(e),e},at=function(e,t){for(var n,r=c(t),o=[];n=r.nextNode();)o.push(n.textContent);return e._doc.createTextNode(o.join("\n")||"")},st=function(e){return this.createElement("PRE",this._config.tagAttributes.pre,[this.createElement("INPUT",{id:Ge,type:"hidden"}),at(this,e),this.createElement("INPUT",{id:je,type:"hidden"}),this._doc.createTextNode("\n")])},dt=function(e){var t=this._doc.createRange(),n=e.querySelector("#"+Ge),r=e.querySelector("#"+je);if(!n||!r)return e;t.setStartBefore(n),t.setEndAfter(r);var o=e.querySelectorAll("pre");if(0===o.length)return e;var i=o[0],a=o[o.length-1],s=t.startContainer,d=t.startOffset,l=t.endContainer,c=t.endOffset,f=[];if(n.nextSibling===r){var h,p=n.previousSibling;if(p&&p.nodeType===D){var g=p.nodeValue.lastIndexOf("\n");-1!==g?(h=p.splitText(g),p.parentNode.insertBefore(n,h)):p.parentNode.insertBefore(n,p),t.setStartBefore(n),d=t.startOffset,s=t.startContainer}var m=r.nextSibling;if(m&&m.nodeType===D){var C=m.nodeValue.indexOf("\n");-1!==C?(h=m.splitText(C+1),m.parentNode.insertBefore(r,h)):m.nextSibling?m.parentNode.insertBefore(r,m.nextSibling):m.parentNode.appendChild(r),t.setEndBefore(r),c=t.endOffset,l=t.endContainer}s.normalize()}u(l,"PRE")===a&&c0&&(_(s,d,i.parentNode),f.push(s)),o=e.querySelectorAll("pre"),t.setStartBefore(n),t.setEndAfter(r);for(var N,S=this,y=0;y]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)/i,ct=function(e){for(var t,r,o,i,a,s,d,l=e.ownerDocument,c=new n(e,I,function(e){return!u(e,"A")},!1);t=c.nextNode();)for(r=t.data,o=t.parentNode;i=lt.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)};qe.insertHTML=function(e,t){var n=this.getSelection(),r=this._doc.createDocumentFragment(),o=this.createElement("DIV");o.innerHTML=e,r.appendChild(u(n.commonAncestorContainer,"PRE")?at(this,o):C(o)),this.saveUndoState(n);try{var i=r,a={fragment:r,preventDefault:function(){this.defaultPrevented=!0},defaultPrevented:!1};for(ct(r),Pe(r),Fe(r),Ie(r),r.normalize();i=h(i);)S(i);t&&this.fireEvent("willPaste",a),a.defaultPrevented||(fe(n,a.fragment),ee||this._docWasChanged(),n.collapse(!1),this._ensureBottomLine()),this.setSelection(n),this._updatePath(n,!0)}catch(s){this.didError(s)}return this},qe.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 ft=function(e,t,n){return function(){return this[e](t,n),this.focus()}};qe.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},qe.bold=ft("changeFormat",{tag:"B"}),qe.italic=ft("changeFormat",{tag:"I"}),qe.underline=ft("changeFormat",{tag:"U"}),qe.strikethrough=ft("changeFormat",{tag:"S"}),qe.subscript=ft("changeFormat",{tag:"SUB"},{tag:"SUP"}),qe.superscript=ft("changeFormat",{tag:"SUP"},{tag:"SUB"}),qe.removeBold=ft("changeFormat",null,{tag:"B"}),qe.removeItalic=ft("changeFormat",null,{tag:"I"}),qe.removeUnderline=ft("changeFormat",null,{tag:"U"}),qe.removeStrikethrough=ft("changeFormat",null,{tag:"S"}),qe.removeSubscript=ft("changeFormat",null,{tag:"SUB"}),qe.removeSuperscript=ft("changeFormat",null,{tag:"SUP"}),qe.makeLink=function(e,t){var n=this.getSelection();if(n.collapsed){var r=e.indexOf(":")+1;if(r)for(;"/"===e[r];)r+=1;de(n,this._doc.createTextNode(e.slice(r)))}return t||(t={}),t.href=e,this.changeFormat({tag:"A",attributes:t},{tag:"A"},n),this.focus()},qe.removeLink=function(){return this.changeFormat(null,{tag:"A"},this.getSelection(),!0),this.focus()},qe.setFontFace=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+e+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),this.focus()},qe.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()},qe.setTextColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"colour",style:"color:"+e}},{tag:"SPAN",attributes:{"class":"colour"}}),this.focus()},qe.setHighlightColour=function(e){return this.changeFormat({tag:"SPAN",attributes:{"class":"highlight",style:"background-color:"+e}},{tag:"SPAN",attributes:{"class":"highlight"}}),this.focus()},qe.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()},qe.setTextDirection=function(e){return this.forEachBlock(function(t){t.dir=e},!0),this.focus()},qe.removeAllFormatting=function(e){if(!e&&!(e=this.getSelection())||e.collapsed)return this;for(var t=e.commonAncestorContainer;t&&!d(t);)t=t.parentNode;if(t||(Se(e),t=this._body),t.nodeType===D)return this;this.saveUndoState(e),pe(e,t);for(var n,r,o,i=t.ownerDocument,a=e.startContainer,s=e.startOffset,l=e.endContainer,c=e.endOffset,f=i.createDocumentFragment(),h=i.createDocumentFragment(),u=_(l,c,t),p=_(a,s,t);p!==u;)n=p.nextSibling,f.appendChild(p),p=n;return k(this,f,h),h.normalize(),p=h.firstChild,n=h.lastChild,o=t.childNodes,p?(t.insertBefore(h,u),s=ne.call(o,p),c=ne.call(o,n)+1):(s=ne.call(o,u),c=s),r={startContainer:t,startOffset:s,endContainer:t,endOffset:c},T(t,r),e.setStart(r.startContainer,r.startOffset),e.setEnd(r.endContainer,r.endOffset),ue(e),this.setSelection(e),this._updatePath(e,!0),this.focus()},qe.increaseQuoteLevel=ft("modifyBlocks",$e),qe.decreaseQuoteLevel=ft("modifyBlocks",Xe),qe.makeUnorderedList=ft("modifyBlocks",tt),qe.makeOrderedList=ft("modifyBlocks",nt),qe.removeList=ft("modifyBlocks",rt),qe.makePreformatted=ft("modifyBlocks",st),qe.removePreformatted=ft("modifyBlocks",dt),qe.increaseListLevel=ft("modifyBlocks",ot),qe.decreaseListLevel=ft("modifyBlocks",it),"object"==typeof exports?module.exports=O:"function"==typeof define&&define.amd?define(function(){return O}):(z.Squire=O,top!==z&&"true"===e.documentElement.getAttribute("data-squireinit")&&(z.editor=new O(e),z.onEditorLoad&&(z.onEditorLoad(z.editor),z.onEditorLoad=null)))}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 9dba370..06c90e8 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -1346,7 +1346,7 @@ var getTextFromHTMLFragment = function ( self, frag ) { // Strip down to text only lines.push( node.textContent ); } - return self._doc.createTextNode( lines.join( '\n' ) || '\n' ); + return self._doc.createTextNode( lines.join( '\n' ) || '' ); }; var makePreformatted = function ( frag ) { @@ -1354,7 +1354,8 @@ var makePreformatted = function ( frag ) { this._config.tagAttributes.pre, [ this.createElement( 'INPUT', { id: startSelectionId, type: 'hidden' } ), getTextFromHTMLFragment( this, frag ), - this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' } ) + this.createElement( 'INPUT', { id: endSelectionId, type: 'hidden' } ), + this._doc.createTextNode( '\n' ) ] ); }; diff --git a/source/KeyHandlers.js b/source/KeyHandlers.js index 4f6bddd..db7956b 100644 --- a/source/KeyHandlers.js +++ b/source/KeyHandlers.js @@ -176,10 +176,14 @@ var keyHandlers = { } if ( /^PRE|CODE|SAMP$/.test( block.nodeName ) ) { + if ( !getNodeAfter( range.endContainer, range.endOffset ).nodeValue[ range.endOffset ] ) { + insertNodeInRange( range, self._doc.createTextNode( '\n\n' ) ); + } else { + insertNodeInRange( range, self._doc.createTextNode( '\n' ) ); + } // Inside a preformatted block, insert a linebreak, and done. - insertNodeInRange( range, self._doc.createTextNode( '\n' ) ); - range.collapse( false ); block.normalize(); + range.collapse( false ); self.setSelection( range ); self._updatePath( range, true ); return; diff --git a/test/squire.spec.js b/test/squire.spec.js index 8eb903b..2601009 100644 --- a/test/squire.spec.js +++ b/test/squire.spec.js @@ -204,7 +204,7 @@ describe('Squire RTE', function () { expect(editor, 'to contain HTML', startHTML); editor.moveCursorToStart(); editor.makePreformatted(); - expect(editor, 'to contain HTML', '
one two three four five
'); + expect(editor, 'to contain HTML', '
one two three four five\n
'); }); it('adds an empty PRE element', function () { @@ -222,7 +222,7 @@ describe('Squire RTE', function () { expect(editor, 'to contain HTML', startHTML); selectAll(editor); editor.makePreformatted(); - expect(editor, 'to contain HTML', '
one two\nthree four\nfive
'); + expect(editor, 'to contain HTML', '
one two\nthree four\nfive\n
'); }); it('expands existing PRE tags to encompass selection', function () { @@ -231,7 +231,7 @@ describe('Squire RTE', function () { expect(editor, 'to contain HTML', startHTML); selectAll(editor); editor.makePreformatted(); - expect(editor, 'to contain HTML', '
abc\n\none two three four five\n
'); + expect(editor, 'to contain HTML', '
abc\n\none two three four five\n\n
'); }); });