diff --git a/build/squire.js b/build/squire.js index 41a1c04..0e59b91 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1 +1 @@ -/* Copyright © 2011-2012 by Neil Jenkins. Licensed under the MIT license. */(function(a){"use strict";var b=!a.createTreeWalker;window.ie===9&&(b=!0),b||function(){var c=a.createElement("div"),d=a.createTextNode("");c.appendChild(d);var e=c.cloneNode(!0),f=c.cloneNode(!0),g=c.cloneNode(!0),h=a.createTreeWalker(c,1,function(a){return 1},!1);c.appendChild(e),c.appendChild(f),c.appendChild(g),h.currentNode=g,h.previousNode()!==f&&(b=!0)}();if(!b)return;var c={1:1,2:2,3:4,8:128,9:256,11:1024},d=1,e=function(a,b,c){this.root=this.currentNode=a,this.nodeType=b,this.filter=c};e.prototype.nextNode=function(){var a=this.currentNode,b=this.root,e=this.nodeType,f=this.filter,g;for(;;){g=a.firstChild;while(!g&&a){if(a===b)break;g=a.nextSibling,g||(a=a.parentNode)}if(!g)return null;if(c[g.nodeType]&e&&f(g)===d)return this.currentNode=g,g;a=g}},e.prototype.previousNode=function(){var a=this.currentNode,b=this.root,e=this.nodeType,f=this.filter,g;for(;;){if(a===b)return null;g=a.previousSibling;if(g)while(a=g.lastChild)g=a;else g=a.parentNode;if(!g)return null;if(c[g.nodeType]&e&&f(g)===d)return this.currentNode=g,g;a=g}},a.createTreeWalker=function(a,b,c){return new e(a,b,c)}})(document),function(){"use strict";var a=function(a,b){var c=a.length,d,e;while(c--){d=a[c].prototype;for(e in b)d[e]=b[e]}},b=function(a,b){var c=a.length;while(c--)if(!b(a[c]))return!1;return!0},c=function(){return!1},d=function(){return!0},e=/^(?:A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:FN|EL)|EM|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TRONG|AMP)|U)$/,f={BR:1,IMG:1,INPUT:1},g=function(a,b){var c=b.parentNode;return c&&c.replaceChild(a,b),a},h=1,i=3,j=1,k=1,l=3,m=function(a){return a.isBlock()?k:l},n=!!window.opera||!!window.ie,o=/WebKit/.test(navigator.userAgent)||!!window.ie;a(window.Node?[Node]:[Text,Element,HTMLDocument],{isInline:c,isBlock:c,isContainer:c,getPath:function(){var a=this.parentNode;return a?a.getPath():""},detach:function(){var a=this.parentNode;return a&&a.removeChild(this),this},replaceWith:function(a){return g(a,this),this},replaces:function(a){return g(this,a),this},nearest:function(a,b){var c=this.parentNode;return c?c.nearest(a,b):null},getPreviousBlock:function(){var a=this.ownerDocument,b=a.createTreeWalker(a.body,j,m,!1);return b.currentNode=this,b.previousNode()},getNextBlock:function(){var a=this.ownerDocument,b=a.createTreeWalker(a.body,j,m,!1);return b.currentNode=this,b.nextNode()},split:function(a,b){return a},mergeContainers:function(){}}),a([Text],{isLeaf:d,isInline:d,getLength:function(){return this.length},isLike:function(a){return a.nodeType===i},split:function(a,b){var c=this;return c===b?a:c.parentNode.split(c.splitText(a),b)}}),a([Element],{isLeaf:function(){return!!f[this.nodeName]},isInline:function(){return e.test(this.nodeName)},isBlock:function(){return!this.isInline()&&b(this.childNodes,function(a){return a.isInline()})},isContainer:function(){return!this.isInline()&&!this.isBlock()},getLength:function(){return this.childNodes.length},getPath:function(){var a=this.nodeName;if(a==="BODY")return a;var b=this.parentNode.getPath(),c=this.id,d=this.className.trim();return b+=">"+a,c&&(b+="#"+c),d&&(d=d.split(/\s\s*/),d.sort(),b+=".",b+=d.join(".")),b},wraps:function(a){return g(this,a).appendChild(a),this},empty:function(){var a=this.ownerDocument.createDocumentFragment(),b=this.childNodes.length;while(b--)a.appendChild(this.firstChild);return a},is:function(a,b){if(this.nodeName!==a)return!1;var c;for(c in b)if(this.getAttribute(c)!==b[c])return!1;return!0},nearest:function(a,b){var c=this;do if(c.is(a,b))return c;while((c=c.parentNode)&&c.nodeType===h);return null},isLike:function(a){return a.nodeType===h&&a.nodeName===this.nodeName&&a.className===this.className&&a.style.cssText===this.style.cssText},mergeInlines:function(a){var b=this.childNodes,c=b.length,d=[],e,g,j;while(c--){e=b[c],g=c&&b[c-1];if(c&&e.isInline()&&e.isLike(g)&&!f[e.nodeName])a.startContainer===e&&(a.startContainer=g,a.startOffset+=g.getLength()),a.endContainer===e&&(a.endContainer=g,a.endOffset+=g.getLength()),a.startContainer===this&&(a.startOffset>c?a.startOffset-=1:a.startOffset===c&&(a.startContainer=g,a.startOffset=g.getLength())),a.endContainer===this&&(a.endOffset>c?a.endOffset-=1:a.endOffset===c&&(a.endContainer=g,a.endOffset=g.getLength())),e.detach(),e.nodeType===i?g.appendData(e.data.replace(/\u200B/g,"")):d.push(e.empty());else if(e.nodeType===h){j=d.length;while(j--)e.appendChild(d.pop());e.mergeInlines(a)}}},mergeWithBlock:function(a,b){var c=this,d=a,e,f,g;while(d.parentNode.childNodes.length===1)d=d.parentNode;d.detach(),f=c.childNodes.length,e=c.lastChild,e&&e.nodeName==="BR"&&(c.removeChild(e),f-=1),g={startContainer:c,startOffset:f,endContainer:c,endOffset:f},c.appendChild(a.empty()),c.mergeInlines(g),b.setStart(g.startContainer,g.startOffset),b.collapse(!0),window.opera&&(e=c.lastChild)&&e.nodeName==="BR"&&c.removeChild(e)},mergeContainers:function(){var a=this.previousSibling,b=this.firstChild;a&&a.isLike(this)&&a.isContainer()&&(a.appendChild(this.detach().empty()),b&&b.mergeContainers())},split:function(a,b){var c=this;typeof a=="number"&&(a=a-1,f=c.compareBoundaryPoints(h,d)<1;return!e&&!f}var k=c.compareBoundaryPoints(g,d)<1,l=c.compareBoundaryPoints(i,d)>-1;return k&&l},moveBoundariesDownTree:function(){var a=this.startContainer,b=this.startOffset,c=this.endContainer,e=this.endOffset,f;while(a.nodeType!==d){f=a.childNodes[b];if(!f||f.nodeName==="BR")break;a=f,b=0}if(e)while(c.nodeType!==d){f=c.childNodes[e-1];if(!f||f.nodeName==="BR")break;c=f,e=c.getLength()}else while(c.nodeType!==d){f=c.firstChild;if(!f||f.nodeName==="BR")break;c=f}return this.collapsed?(this.setStart(c,e),this.setEnd(a,b)):(this.setStart(a,b),this.setEnd(c,e)),this},moveBoundariesUpTree:function(a){var c=this.startContainer,d=this.startOffset,e=this.endContainer,f=this.endOffset,g;a||(a=this.commonAncestorContainer);while(c!==a&&!d)g=c.parentNode,d=b.call(g.childNodes,c),c=g;while(e!==a&&f===e.getLength())g=e.parentNode,f=b.call(g.childNodes,e)+1,e=g;return this.setStart(c,d),this.setEnd(e,f),this},getStartBlock:function(){var a=this.startContainer,b;return a.isInline()?b=a.getPreviousBlock():a.isBlock()?b=a:(b=k(a,this.startOffset),b=b.getNextBlock()),b&&this.containsNode(b,!0)?b:null},getEndBlock:function(){var a=this.endContainer,b,c;if(a.isInline())b=a.getPreviousBlock();else if(a.isBlock())b=a;else{b=l(a,this.endOffset);if(!b){b=a.ownerDocument.body;while(c=b.lastChild)b=c}b=b.getPreviousBlock()}return b&&this.containsNode(b,!0)?b:null},startsAtBlockBoundary:function(){var a=this.startContainer,c=this.startOffset,d,e;while(a.isInline()){if(c)return!1;d=a.parentNode,c=b.call(d.childNodes,a),a=d}while(c&&(e=a.childNodes[c-1])&&(e.data===""||e.nodeName==="BR"))c-=1;return!c},endsAtBlockBoundary:function(){var a=this.endContainer,c=this.endOffset,d=a.getLength(),e,f;while(a.isInline()){if(c!==d)return!1;e=a.parentNode,c=b.call(e.childNodes,a)+1,a=e,d=a.childNodes.length}while(c-1)a.deleteData(b,1);!a.data&&!a.nextSibling&&!a.previousSibling&&a.parentNode.isInline()&&a.parentNode.detach()}},M=function(a,b){G&&!b&&L(a);var c=a.startContainer,d=a.endContainer,e;if(b||c!==D||d!==E)D=c,E=d,e=c&&d?c===d?d.getPath():"(selection)":"",F!==e&&(F=e,u("pathChange",{path:e}));c!==d&&u("select")},N=function(){M(C())};w("keyup",N),w("mouseup",N);var O=function(){m&&i.focus(),h.focus()},P=function(){h.blur()};h.addEventListener("focus",v,!1),h.addEventListener("blur",v,!1);var Q=function(){return i.innerHTML},R=function(a){var b=i;b.innerHTML=a;do b.fixCursor();while(b=b.getNextBlock())},S=function(a,b){b||(b=C()),b.collapse(!0),b._insertNode(a),b.setStartAfter(a),A(b),M(b)},T="ss-"+Date.now()+"-"+Math.random(),U="es-"+Date.now()+"-"+Math.random(),V=function(a){var c=r("INPUT",{id:T,type:"hidden"}),d=r("INPUT",{id:U,type:"hidden"}),e;a._insertNode(c),a.collapse(!1),a._insertNode(d),c.compareDocumentPosition(d)&b&&(c.id=U,d.id=T,e=c,c=d,d=e),a.setStartAfter(c),a.setEndBefore(d)},W=Array.prototype.indexOf,X=function(b){var c=a.getElementById(T),d=a.getElementById(U);if(c&&d){var e=c.parentNode,f=d.parentNode,g={startContainer:e,endContainer:f,startOffset:W.call(e.childNodes,c),endOffset:W.call(f.childNodes,d)};e===f&&(g.endOffset-=1),c.detach(),d.detach(),e.mergeInlines(g),e!==f&&f.mergeInlines(g),b||(b=a.createRange()),b.setStart(g.startContainer,g.startOffset),b.setEnd(g.endContainer,g.endOffset),b.collapsed||b.moveBoundariesDownTree()}return b},Y,Z,$,_,ab=function(){_&&(_=!1,u("undoStateChange",{canUndo:!0,canRedo:!1})),u("input")};w("keyup",function(a){var b=a.keyCode;if(!a.ctrlKey&&!a.metaKey&&!a.altKey&&(b<16||b>20)&&(b<33||b>45)){var c=i.firstChild;h.ie===8&&c.nodeName==="P"&&(V(C()),c.replaceWith(r("DIV",[c.empty()])),A(X())),ab()}});var bb=function(a){_||(Y+=1,Y<$&&(Z.length=$=Y),a&&V(a),Z[Y]=Q(),$+=1,_=!0)},cb=function(){if(Y!==0||!_){bb(C()),Y-=1,R(Z[Y]);var a=X();a&&A(a),_=!0,u("undoStateChange",{canUndo:Y!==0,canRedo:!0}),u("input")}},db=function(){if(Y+1<$&&_){Y+=1,R(Z[Y]);var a=X();a&&A(a),u("undoStateChange",{canUndo:!0,canRedo:Y+1<$}),u("input")}},eb=function(b,c,h){b=b.toUpperCase(),c||(c={});if(!h&&!(h=C()))return!1;var i=h.commonAncestorContainer,j,k;if(i.nearest(b,c))return!0;if(i.nodeType===d)return!1;j=a.createTreeWalker(i,e,function(a){return h.containsNode(a,!0)?f:g},!1);var l=!1;while(k=j.nextNode()){if(!k.nearest(b,c))return!1;l=!0}return l},fb=function(b,c,h){if(h.collapsed){var i=r(b,c).fixCursor();h._insertNode(i),h.setStart(i.firstChild,i.firstChild.length),h.collapse(!0)}else{var j=a.createTreeWalker(h.commonAncestorContainer,e,function(a){return h.containsNode(a,!0)?f:g},!1),k,l,m=0,n=0,o=j.currentNode=h.startContainer,p;o.nodeType!==d&&(o=j.nextNode());do p=!o.nearest(b,c),o===h.endContainer&&(p&&o.length>h.endOffset?o.splitText(h.endOffset):n=h.endOffset),o===h.startContainer&&(p&&h.startOffset?o=o.splitText(h.startOffset):m=h.startOffset),p&&(r(b,c).wraps(o),n=o.length),l=o,k||(k=l);while(o=j.nextNode());h=y(k,m,l,n)}return h},gb=function(b,c,e,f){V(e);var g;e.collapsed&&(q?(g=a.createTextNode("​"),K(g)):g=a.createTextNode(""),e._insertNode(g));var h=e.commonAncestorContainer;while(h.isInline())h=h.parentNode;var i=e.startContainer,j=e.startOffset,k=e.endContainer,l=e.endOffset,m=[],n=function(a,b){if(e.containsNode(a,!1))return;var c=a.nodeType===d,f,g;if(!e.containsNode(a,!0)){a.nodeName!=="INPUT"&&(!c||a.data)&&m.push([b,a]);return}if(c)a===k&&l!==a.length&&m.push([b,a.splitText(l)]),a===i&&j&&(a.splitText(j),m.push([b,a]));else for(f=a.firstChild;f;f=g)g=f.nextSibling,n(f,b)},o=Array.prototype.filter.call(h.getElementsByTagName(b),function(a){return e.containsNode(a,!0)&&a.is(b,c)});f||o.forEach(function(a){n(a,a)}),m.forEach(function(a){a[0].cloneNode(!1).wraps(a[1])}),o.forEach(function(a){a.replaceWith(a.empty())}),X(e),g&&e.collapse(!1);var p={startContainer:e.startContainer,startOffset:e.startOffset,endContainer:e.endContainer,endOffset:e.endOffset};return h.mergeInlines(p),e.setStart(p.startContainer,p.startOffset),e.setEnd(p.endContainer,p.endOffset),e},hb=function(a,b,c,d){if(!c&&!(c=C()))return;bb(c),X(c),b&&(c=gb(b.tag.toUpperCase(),b.attributes||{},c,d)),a&&(c=fb(a.tag.toUpperCase(),a.attributes||{},c)),A(c),M(c,!0),ab()},ib=function(a,b,c){if(!c&&!(c=C()))return;b&&(bb(c),X(c));var d=c.getStartBlock(),e=c.getEndBlock();if(d&&e)for(;;){if(a(d)||d===e)break;d=d.getNextBlock()}b&&(A(c),M(c,!0),ab())},jb=function(a,b){if(!b&&!(b=C()))return;j||i.setAttribute("contenteditable","false"),_?V(b):bb(b),b.expandToBlockBoundaries(),b.moveBoundariesUpTree(i);var c=b._extractContents(i);b._insertNode(a(c)),b.endOffset]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:[\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,4}))/i,ub=function(a){var b=a.ownerDocument,c=b.createTreeWalker(a,e,function(a){return a.nearest("A")?g:f},!1),d,h,i,j,k,l,m;while(d=c.nextNode()){h=d.data.split(tb),j=h.length;if(j>1){l=d.parentNode,m=d.nextSibling;for(i=0;i(a.documentElement.scrollTop||i.scrollTop)+i.offsetHeight&&k.scrollIntoView(!1),ab()},backspace:function(a){var b=C();if(!b.collapsed)a.preventDefault(),b._deleteContents(),A(b),M(b,!0);else if(b.startsAtBlockBoundary()){a.preventDefault();var c=b.getStartBlock(),d=c.getPreviousBlock();if(d){d.mergeWithBlock(c,b),c=d.parentNode;while(c&&!c.nextSibling)c=c.parentNode;c&&(c=c.nextSibling)&&c.mergeContainers(),A(b)}else{if(c.nearest("UL")||c.nearest("OL"))return jb(qb,b);if(c.nearest("BLOCKQUOTE"))return jb(lb,b);A(b),M(b,!0)}}},"delete":function(a){var b=C();if(!b.collapsed)a.preventDefault(),b._deleteContents(),A(b),M(b,!0);else if(b.endsAtBlockBoundary()){a.preventDefault();var c=b.getStartBlock(),d=c.getNextBlock();if(d){c.mergeWithBlock(d,b),d=c.parentNode;while(d&&!d.nextSibling)d=d.parentNode;d&&(d=d.nextSibling)&&d.mergeContainers(),A(b),M(b,!0)}}},space:function(){var a=C();bb(a),X(a),A(a)},"ctrl-b":Fb("B"),"ctrl-i":Fb("I"),"ctrl-u":Fb("U"),"ctrl-y":Eb(db),"ctrl-z":Eb(cb),"ctrl-shift-z":Eb(db)};w(j?"keypress":"keydown",function(a){var b=a.keyCode,c=Db[b]||String.fromCharCode(b).toLowerCase(),d="";j&&a.which===46&&(c="."),111n?e.startOffset-=1:e.startOffset===n&&(e.startContainer=o,e.startOffset=o.getLength())),e.endContainer===this&&(e.endOffset>n?e.endOffset-=1:e.endOffset===n&&(e.endContainer=o,e.endOffset=o.getLength())),i.detach(),i.nodeType===a?o.appendData(i.data.replace(/\u200B/g,"")):r.push(i.empty());else if(i.nodeType===u){f=r.length;while(f--)i.appendChild(r.pop());i.mergeInlines(e)}}},mergeWithBlock:function(e,t){var n=this,r=e,i,s,o;while(r.parentNode.childNodes.length===1)r=r.parentNode;r.detach(),s=n.childNodes.length,i=n.lastChild,i&&i.nodeName==="BR"&&(n.removeChild(i),s-=1),o={startContainer:n,startOffset:s,endContainer:n,endOffset:s},n.appendChild(e.empty()),n.mergeInlines(o),t.setStart(o.startContainer,o.startOffset),t.collapse(!0),window.opera&&(i=n.lastChild)&&i.nodeName==="BR"&&n.removeChild(i)},mergeContainers:function(){var e=this.previousSibling,t=this.firstChild;e&&e.isLike(this)&&e.isContainer()&&(e.appendChild(this.detach().empty()),t&&t.mergeContainers())},split:function(e,t){var n=this;typeof e=="number"&&(e=e-1,s=n.compareBoundaryPoints(u,r)<1;return!i&&!s}var l=n.compareBoundaryPoints(o,r)<1,c=n.compareBoundaryPoints(a,r)>-1;return l&&c},moveBoundariesDownTree:function(){var e=this.startContainer,t=this.startOffset,n=this.endContainer,i=this.endOffset,s;while(e.nodeType!==r){s=e.childNodes[t];if(!s||s.nodeName==="BR")break;e=s,t=0}if(i)while(n.nodeType!==r){s=n.childNodes[i-1];if(!s||s.nodeName==="BR")break;n=s,i=n.getLength()}else while(n.nodeType!==r){s=n.firstChild;if(!s||s.nodeName==="BR")break;n=s}return this.collapsed?(this.setStart(n,i),this.setEnd(e,t)):(this.setStart(e,t),this.setEnd(n,i)),this},moveBoundariesUpTree:function(e){var n=this.startContainer,r=this.startOffset,i=this.endContainer,s=this.endOffset,o;e||(e=this.commonAncestorContainer);while(n!==e&&!r)o=n.parentNode,r=t.call(o.childNodes,n),n=o;while(i!==e&&s===i.getLength())o=i.parentNode,s=t.call(o.childNodes,i)+1,i=o;return this.setStart(n,r),this.setEnd(i,s),this},getStartBlock:function(){var e=this.startContainer,t;return e.isInline()?t=e.getPreviousBlock():e.isBlock()?t=e:(t=l(e,this.startOffset),t=t.getNextBlock()),t&&this.containsNode(t,!0)?t:null},getEndBlock:function(){var e=this.endContainer,t,n;if(e.isInline())t=e.getPreviousBlock();else if(e.isBlock())t=e;else{t=c(e,this.endOffset);if(!t){t=e.ownerDocument.body;while(n=t.lastChild)t=n}t=t.getPreviousBlock()}return t&&this.containsNode(t,!0)?t:null},startsAtBlockBoundary:function(){var e=this.startContainer,n=this.startOffset,r,i;while(e.isInline()){if(n)return!1;r=e.parentNode,n=t.call(r.childNodes,e),e=r}while(n&&(i=e.childNodes[n-1])&&(i.data===""||i.nodeName==="BR"))n-=1;return!n},endsAtBlockBoundary:function(){var e=this.endContainer,n=this.endOffset,r=e.getLength(),i,s;while(e.isInline()){if(n!==r)return!1;i=e.parentNode,n=t.call(i.childNodes,e)+1,e=i,r=e.childNodes.length}while(n-1)e.deleteData(t,1);!e.data&&!e.nextSibling&&!e.previousSibling&&e.parentNode.isInline()&&e.parentNode.detach()}},F=function(e,t){_&&!t&&j(e);var n=e.startContainer,r=e.endContainer,i;if(t||n!==A||r!==O)A=n,O=r,i=n&&r?n===r?r.getPath():"(selection)":"",M!==i&&(M=i,w("pathChange",{path:i}));n!==r&&w("select")},I=function(){F(L())};S("keyup",I),S("mouseup",I);var q=function(){h&&a.focus(),u.focus()},R=function(){u.blur()};u.addEventListener("focus",E,!1),u.addEventListener("blur",E,!1);var U=function(){return a.innerHTML},z=function(e){var t=a;t.innerHTML=e;do t.fixCursor();while(t=t.getNextBlock())},W=function(e,t){t||(t=L()),t.collapse(!0),t._insertNode(e),t.setStartAfter(e),C(t),F(t)},X="ss-"+Date.now()+"-"+Math.random(),V="es-"+Date.now()+"-"+Math.random(),$=function(e){var n=g("INPUT",{id:X,type:"hidden"}),r=g("INPUT",{id:V,type:"hidden"}),i;e._insertNode(n),e.collapse(!1),e._insertNode(r),n.compareDocumentPosition(r)&t&&(n.id=V,r.id=X,i=n,n=r,r=i),e.setStartAfter(n),e.setEndBefore(r)},J=Array.prototype.indexOf,K=function(t){var n=e.getElementById(X),r=e.getElementById(V);if(n&&r){var i=n.parentNode,s=r.parentNode,o,u={startContainer:i,endContainer:s,startOffset:J.call(i.childNodes,n),endOffset:J.call(s.childNodes,r)};i===s&&(u.endOffset-=1),n.detach(),r.detach(),i.mergeInlines(u),i!==s&&s.mergeInlines(u),t||(t=e.createRange()),t.setStart(u.startContainer,u.startOffset),t.setEnd(u.endContainer,u.endOffset),o=t.collapsed,t.moveBoundariesDownTree(),o&&t.collapse(!0)}return t},Q,G,Y,Z,et=function(){Z&&(Z=!1,w("undoStateChange",{canUndo:!0,canRedo:!1})),w("input")};S("keyup",function(e){var t=e.keyCode;if(!e.ctrlKey&&!e.metaKey&&!e.altKey&&(t<16||t>20)&&(t<33||t>45)){var n=a.firstChild;u.ie===8&&n.nodeName==="P"&&($(L()),n.replaceWith(g("DIV",[n.empty()])),C(K())),et()}});var tt=function(e){Z||(Q+=1,Qu.endOffset?d.splitText(u.endOffset):p=u.endOffset),d===u.startContainer&&(v&&u.startOffset?d=d.splitText(u.startOffset):h=u.startOffset),v&&(g(t,n).wraps(d),p=d.length),c=d,l||(l=c);while(d=f.nextNode());u=T(l,h,c,p)}return u},ot=function(t,n,i,s){$(i);var o;i.collapsed&&(m?(o=e.createTextNode("​"),B(o)):o=e.createTextNode(""),i._insertNode(o));var u=i.commonAncestorContainer;while(u.isInline())u=u.parentNode;var a=i.startContainer,f=i.startOffset,l=i.endContainer,c=i.endOffset,h=[],p=function(e,t){if(i.containsNode(e,!1))return;var n=e.nodeType===r,s,o;if(!i.containsNode(e,!0)){e.nodeName!=="INPUT"&&(!n||e.data)&&h.push([t,e]);return}if(n)e===l&&c!==e.length&&h.push([t,e.splitText(c)]),e===a&&f&&(e.splitText(f),h.push([t,e]));else for(s=e.firstChild;s;s=o)o=s.nextSibling,p(s,t)},d=Array.prototype.filter.call(u.getElementsByTagName(t),function(e){return i.containsNode(e,!0)&&e.is(t,n)});s||d.forEach(function(e){p(e,e)}),h.forEach(function(e){e[0].cloneNode(!1).wraps(e[1])}),d.forEach(function(e){e.replaceWith(e.empty())}),K(i),o&&i.collapse(!1);var v={startContainer:i.startContainer,startOffset:i.startOffset,endContainer:i.endContainer,endOffset:i.endOffset};return u.mergeInlines(v),i.setStart(v.startContainer,v.startOffset),i.setEnd(v.endContainer,v.endOffset),i},ut=function(e,t,n,r){if(!n&&!(n=L()))return;tt(n),K(n),t&&(n=ot(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=st(e.tag.toUpperCase(),e.attributes||{},n)),C(n),F(n,!0),et()},at=function(e,t,n){if(!n&&!(n=L()))return;t&&(tt(n),K(n));var r=n.getStartBlock(),i=n.getEndBlock();if(r&&i)for(;;){if(e(r)||r===i)break;r=r.getNextBlock()}t&&(C(n),F(n,!0),et())},ft=function(e,t){if(!t&&!(t=L()))return;f||a.setAttribute("contenteditable","false"),Z?$(t):tt(t),t.expandToBlockBoundaries(),t.moveBoundariesUpTree(a);var n=t._extractContents(a);t._insertNode(e(n)),t.endOffset]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:[\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,4}))/i,wt=function(e){var t=e.ownerDocument,n=t.createTreeWalker(e,i,function(e){return e.nearest("A")?o:s},!1),r,u,a,f,l,c,h;while(r=n.nextNode()){u=r.data.split(bt),f=u.length;if(f>1){c=r.parentNode,h=r.nextSibling;for(a=0;a(e.documentElement.scrollTop||a.scrollTop)+a.offsetHeight&&l.scrollIntoView(!1),et()},backspace:function(e){var t=L();if(!t.collapsed)e.preventDefault(),t._deleteContents(),C(t),F(t,!0);else if(t.startsAtBlockBoundary()){e.preventDefault();var n=t.getStartBlock(),r=n.getPreviousBlock();if(r){r.mergeWithBlock(n,t),n=r.parentNode;while(n&&!n.nextSibling)n=n.parentNode;n&&(n=n.nextSibling)&&n.mergeContainers(),C(t)}else{if(n.nearest("UL")||n.nearest("OL"))return ft(mt,t);if(n.nearest("BLOCKQUOTE"))return ft(ct,t);C(t),F(t,!0)}}},"delete":function(e){var t=L();if(!t.collapsed)e.preventDefault(),t._deleteContents(),C(t),F(t,!0);else if(t.endsAtBlockBoundary()){e.preventDefault();var n=t.getStartBlock(),r=n.getNextBlock();if(r){n.mergeWithBlock(r,t),r=n.parentNode;while(r&&!r.nextSibling)r=r.parentNode;r&&(r=r.nextSibling)&&r.mergeContainers(),C(t),F(t,!0)}}},space:function(){var e=L();tt(e),K(e),C(e)},"ctrl-b":Mt("B"),"ctrl-i":Mt("I"),"ctrl-u":Mt("U"),"ctrl-y":Ot(rt),"ctrl-z":Ot(nt),"ctrl-shift-z":Ot(rt)};S(f?"keypress":"keydown",function(e){var t=e.keyCode,n=At[t]||String.fromCharCode(t).toLowerCase(),r="";f&&e.which===46&&(n="."),111