diff --git a/build/squire.js b/build/squire.js index 604fbf3..ac007be 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1 +1 @@ -/* Copyright © 2011-2012 by Neil Jenkins. Licensed under the MIT license. */(function(e){"use strict";var t=!e.createTreeWalker;window.ie===9&&(t=!0),t||function(){var n=e.createElement("div"),r=e.createTextNode("");n.appendChild(r);var i=n.cloneNode(!0),s=n.cloneNode(!0),o=n.cloneNode(!0),u=e.createTreeWalker(n,1,function(e){return 1},!1);n.appendChild(i),n.appendChild(s),n.appendChild(o),u.currentNode=o,u.previousNode()!==s&&(t=!0)}();if(!t)return;var n={1:1,2:2,3:4,8:128,9:256,11:1024},r=1,i=function(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n};i.prototype.nextNode=function(){var e=this.currentNode,t=this.root,i=this.nodeType,s=this.filter,o;for(;;){o=e.firstChild;while(!o&&e){if(e===t)break;o=e.nextSibling,o||(e=e.parentNode)}if(!o)return null;if(n[o.nodeType]&i&&s(o)===r)return this.currentNode=o,o;e=o}},i.prototype.previousNode=function(){var e=this.currentNode,t=this.root,i=this.nodeType,s=this.filter,o;for(;;){if(e===t)return null;o=e.previousSibling;if(o)while(e=o.lastChild)o=e;else o=e.parentNode;if(!o)return null;if(n[o.nodeType]&i&&s(o)===r)return this.currentNode=o,o;e=o}},e.createTreeWalker=function(e,t,n){return new i(e,t,n)}})(document),function(){"use strict";var e=function(e,t){var n=e.length,r,i;while(n--){r=e[n].prototype;for(i in t)r[i]=t[i]}},t=function(e,t){var n=e.length;while(n--)if(!t(e[n]))return!1;return!0},n=function(){return!1},r=function(){return!0},i=/^(?:A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:FN|EL)|EM|FONT|HR|I(?:NPUT|MG|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:U[BP]|PAN|TRONG|AMP)|U)$/,s={BR:1,IMG:1,INPUT:1},o=function(e,t){var n=t.parentNode;return n&&n.replaceChild(e,t),e},u=1,a=3,f=1,l=1,c=3,h=function(e){return e.isBlock()?l:c},p=!!window.opera||!!window.ie,d=/WebKit/.test(navigator.userAgent)||!!window.ie;e(window.Node?[Node]:[Text,Element,HTMLDocument],{isInline:n,isBlock:n,isContainer:n,getPath:function(){var e=this.parentNode;return e?e.getPath():""},detach:function(){var e=this.parentNode;return e&&e.removeChild(this),this},replaceWith:function(e){return o(e,this),this},replaces:function(e){return o(this,e),this},nearest:function(e,t){var n=this.parentNode;return n?n.nearest(e,t):null},getPreviousBlock:function(){var e=this.ownerDocument,t=e.createTreeWalker(e.body,f,h,!1);return t.currentNode=this,t.previousNode()},getNextBlock:function(){var e=this.ownerDocument,t=e.createTreeWalker(e.body,f,h,!1);return t.currentNode=this,t.nextNode()},split:function(e,t){return e},mergeContainers:function(){}}),e([Text],{isLeaf:n,isInline:r,getLength:function(){return this.length},isLike:function(e){return e.nodeType===a},split:function(e,t){var n=this;return n===t?e:n.parentNode.split(n.splitText(e),t)}}),e([Element],{isLeaf:function(){return!!s[this.nodeName]},isInline:function(){return i.test(this.nodeName)},isBlock:function(){return!this.isInline()&&t(this.childNodes,function(e){return e.isInline()})},isContainer:function(){return!this.isInline()&&!this.isBlock()},getLength:function(){return this.childNodes.length},getPath:function(){var e=this.nodeName;if(e==="BODY")return e;var t=this.parentNode.getPath(),n=this.id,r=this.className.trim();return t+=">"+e,n&&(t+="#"+n),r&&(r=r.split(/\s\s*/),r.sort(),t+=".",t+=r.join(".")),t},wraps:function(e){return o(this,e).appendChild(e),this},empty:function(){var e=this.ownerDocument.createDocumentFragment(),t=this.childNodes.length;while(t--)e.appendChild(this.firstChild);return e},is:function(e,t){if(this.nodeName!==e)return!1;var n;for(n in t)if(this.getAttribute(n)!==t[n])return!1;return!0},nearest:function(e,t){var n=this;do if(n.is(e,t))return n;while((n=n.parentNode)&&n.nodeType===u);return null},isLike:function(e){return e.nodeType===u&&e.nodeName===this.nodeName&&e.className===this.className&&e.style.cssText===this.style.cssText},mergeInlines:function(e){var t=this.childNodes,n=t.length,r=[],i,o,f;while(n--){i=t[n],o=n&&t[n-1];if(n&&i.isInline()&&i.isLike(o)&&!s[i.nodeName])e.startContainer===i&&(e.startContainer=o,e.startOffset+=o.getLength()),e.endContainer===i&&(e.endContainer=o,e.endOffset+=o.getLength()),e.startContainer===this&&(e.startOffset>n?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.isLeaf())break;e=s,t=0}if(i)while(n.nodeType!==r){s=n.childNodes[i-1];if(!s||s.isLeaf())break;n=s,i=n.getLength()}else while(n.nodeType!==r){s=n.firstChild;if(!s||s.isLeaf())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(){a.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)}}else setTimeout(_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)}}else setTimeout(_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="."),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.isLeaf())break;e=s,t=0}if(i)while(n.nodeType!==r){s=n.childNodes[i-1];if(!s||s.isLeaf())break;n=s,i=n.getLength()}else while(n.nodeType!==r){s=n.firstChild;if(!s||s.isLeaf())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()}},j,F,I="",q=function(e,t){M&&!t&&B(e);var n=e.startContainer,r=e.endContainer,i;if(t||n!==j||r!==F)j=n,F=r,i=n&&r?n===r?r.getPath():"(selection)":"",I!==i&&(I=i,S("pathChange",{path:i}));n!==r&&S("select")},R=function(){q(O())};T("keyup",R),T("mouseup",R);var U=function(){p&&a.focus(),u.focus()},z=function(){a.blur()};u.addEventListener("focus",x,!1),u.addEventListener("blur",x,!1);var W=function(){return a.innerHTML},X=function(e){var t=a;t.innerHTML=e;do t.fixCursor();while(t=t.getNextBlock())},V=function(e,t){t||(t=O()),t.collapse(!0),t._insertNode(e),t.setStartAfter(e),A(t),q(t)},$=Array.prototype.indexOf,J="ss-"+Date.now()+"-"+Math.random(),K="es-"+Date.now()+"-"+Math.random(),Q=function(e){var n=b("INPUT",{id:J,type:"hidden"}),r=b("INPUT",{id:K,type:"hidden"}),i;e._insertNode(n),e.collapse(!1),e._insertNode(r),n.compareDocumentPosition(r)&t&&(n.id=K,r.id=J,i=n,n=r,r=i),e.setStartAfter(n),e.setEndBefore(r)},G=function(t){var n=e.getElementById(J),r=e.getElementById(K);if(n&&r){var i=n.parentNode,s=r.parentNode,o,u={startContainer:i,endContainer:s,startOffset:$.call(i.childNodes,n),endOffset:$.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},Y,Z,et,tt,nt=function(){tt&&(tt=!1,S("undoStateChange",{canUndo:!0,canRedo:!1})),S("input")};T("keyup",function(e){var t=e.keyCode;!e.ctrlKey&&!e.metaKey&&!e.altKey&&(t<16||t>20)&&(t<33||t>45)&&nt()});var rt=function(e){tt||(Y+=1,Yu.endOffset?d.splitText(u.endOffset):p=u.endOffset),d===u.startContainer&&(v&&u.startOffset?d=d.splitText(u.startOffset):h=u.startOffset),v&&(b(t,n).wraps(d),p=d.length),c=d,l||(l=c);while(d=f.nextNode());u=C(l,h,c,p)}return u},at=function(t,n,i,s){Q(i);var o;i.collapsed&&(g?(o=e.createTextNode("​"),H(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())}),G(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},ft=function(e,t,n,r){if(!n&&!(n=O()))return;rt(n),G(n),t&&(n=at(t.tag.toUpperCase(),t.attributes||{},n,r)),e&&(n=ut(e.tag.toUpperCase(),e.attributes||{},n)),A(n),q(n,!0),nt()},lt={DIV:"DIV",PRE:"DIV",H1:"DIV",H2:"DIV",H3:"DIV",H4:"DIV",H5:"DIV",H6:"DIV",P:"DIV",DT:"DD",DD:"DT",LI:"LI"},ct=function(e,t,n){var r=lt[e.nodeName],i=t.split(n,e.parentNode);return i.nodeName!==r&&(e=b(r),e.className=i.dir==="rtl"?"dir-rtl":"",e.dir=i.dir,e.replaces(i).appendChild(i.empty()),i=e),i},ht=function(e,t,n){if(!n&&!(n=O()))return;t&&(rt(n),G(n));var r=n.getStartBlock(),i=n.getEndBlock();if(r&&i)for(;;){if(e(r)||r===i)break;r=r.getNextBlock()}t&&(A(n),q(n,!0),nt())},pt=function(e,t){if(!t&&!(t=O()))return;l||a.setAttribute("contenteditable","false"),tt?Q(t):rt(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,St=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(Et),f=u.length;if(f>1){c=r.parentNode,h=r.nextSibling;for(a=0;a(e.documentElement.scrollTop||a.scrollTop)+a.offsetHeight&&f.scrollIntoView(!1),nt()},backspace:function(e){var t=O();if(!t.collapsed)e.preventDefault(),t._deleteContents(),A(t),q(t,!0);else if(t.startsAtBlockBoundary()){e.preventDefault();var n=t.getStartBlock(),r=n.getPreviousBlock();if(r){if(!r.isContentEditable){r.detach();return}r.mergeWithBlock(n,t),n=r.parentNode;while(n&&!n.nextSibling)n=n.parentNode;n&&(n=n.nextSibling)&&n.mergeContainers(),A(t)}else{if(n.nearest("UL")||n.nearest("OL"))return pt(wt,t);if(n.nearest("BLOCKQUOTE"))return pt(vt,t);A(t),q(t,!0)}}else setTimeout(Pt,0)},"delete":function(e){var t=O();if(!t.collapsed)e.preventDefault(),t._deleteContents(),A(t),q(t,!0);else if(t.endsAtBlockBoundary()){e.preventDefault();var n=t.getStartBlock(),r=n.getNextBlock();if(r){if(!r.isContentEditable){r.detach();return}n.mergeWithBlock(r,t),r=n.parentNode;while(r&&!r.nextSibling)r=r.parentNode;r&&(r=r.nextSibling)&&r.mergeContainers(),A(t),q(t,!0)}}else setTimeout(Pt,0)},space:function(){var e=O();rt(e),G(e),A(e)},"ctrl-b":Dt("B"),"ctrl-i":Dt("I"),"ctrl-u":Dt("U"),"ctrl-y":_t(st),"ctrl-z":_t(it),"ctrl-shift-z":_t(st)};T(l?"keypress":"keydown",function(e){var t=e.keyCode,n=Mt[t]||String.fromCharCode(t).toLowerCase(),r="";l&&e.which===46&&(n="."),111 20 ) && ( code < 33 || code > 45 ) ) { - // If you select all in IE8 then type, it makes a P; replace it with - // a DIV. - var firstChild = body.firstChild; - if ( win.ie === 8 && firstChild.nodeName === 'P' ) { - saveRangeToBookmark( getSelection() ); - firstChild.replaceWith( createElement( 'DIV', [ - firstChild.empty() - ]) ); - setSelection( getRangeAndRemoveBookmark() ); - } docWasChanged(); } }); @@ -727,6 +719,37 @@ // --- Block formatting --- + var tagAfterSplit = { + DIV: 'DIV', + PRE: 'DIV', + H1: 'DIV', + H2: 'DIV', + H3: 'DIV', + H4: 'DIV', + H5: 'DIV', + H6: 'DIV', + P: 'DIV', + DT: 'DD', + DD: 'DT', + LI: 'LI' + }; + + var splitBlock = function ( block, node, offset ) { + var splitTag = tagAfterSplit[ block.nodeName ], + nodeAfterSplit = node.split( offset, block.parentNode ); + + // Make sure the new node is the correct type. + if ( nodeAfterSplit.nodeName !== splitTag ) { + block = createElement( splitTag ); + block.className = nodeAfterSplit.dir === 'rtl' ? 'dir-rtl' : ''; + block.dir = nodeAfterSplit.dir; + block.replaces( nodeAfterSplit ) + .appendChild( nodeAfterSplit.empty() ); + nodeAfterSplit = block; + } + return nodeAfterSplit; + }; + var forEachBlock = function ( fn, mutates, range ) { if ( !range && !( range = getSelection() ) ) { return; @@ -912,37 +935,6 @@ return frag; }; - var tagAfterSplit = { - DIV: 'DIV', - PRE: 'DIV', - H1: 'DIV', - H2: 'DIV', - H3: 'DIV', - H4: 'DIV', - H5: 'DIV', - H6: 'DIV', - P: 'DIV', - DT: 'DD', - DD: 'DT', - LI: 'LI' - }; - - var splitBlock = function ( block, node, offset ) { - var splitTag = tagAfterSplit[ block.nodeName ], - nodeAfterSplit = node.split( offset, block.parentNode ); - - // Make sure the new node is the correct type. - if ( nodeAfterSplit.nodeName !== splitTag ) { - block = createElement( splitTag ); - block.className = nodeAfterSplit.dir === 'rtl' ? 'dir-rtl' : ''; - block.dir = nodeAfterSplit.dir; - block.replaces( nodeAfterSplit ) - .appendChild( nodeAfterSplit.empty() ); - nodeAfterSplit = block; - } - return nodeAfterSplit; - }; - // --- Clean --- var linkRegExp = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:[\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,4}))/i; @@ -1363,6 +1355,21 @@ } }; + // If you select all in IE8 then type, it makes a P; replace it with + // a DIV. + if ( isIE8 ) { + addEventListener( 'keyup', function ( event ) { + var firstChild = body.firstChild; + if ( firstChild.nodeName === 'P' ) { + saveRangeToBookmark( getSelection() ); + firstChild.replaceWith( createElement( 'DIV', [ + firstChild.empty() + ]) ); + setSelection( getRangeAndRemoveBookmark() ); + } + }); + } + var keyHandlers = { enter: function ( event ) { // We handle this ourselves @@ -1454,7 +1461,7 @@ // Focus cursor // If there's a / etc. at the beginning of the split // make sure we focus inside it. - while ( nodeAfterSplit.nodeType === ELEMENT_NODE) { + while ( nodeAfterSplit.nodeType === ELEMENT_NODE ) { var child = nodeAfterSplit.firstChild, next; @@ -1517,6 +1524,12 @@ previous = current.getPreviousBlock(); // Must not be at the very beginning of the text area. if ( previous ) { + // If not editable, just delete whole block. + if ( !previous.isContentEditable ) { + previous.detach(); + return; + } + // Otherwise merge. previous.mergeWithBlock( current, range ); // If deleted line between containers, merge newly adjacent // containers. @@ -1566,6 +1579,12 @@ next = current.getNextBlock(); // Must not be at the very end of the text area. if ( next ) { + // If not editable, just delete whole block. + if ( !next.isContentEditable ) { + next.detach(); + return; + } + // Otherwise merge. current.mergeWithBlock( next, range ); // If deleted line between containers, merge newly adjacent // containers.