diff --git a/build/squire.js b/build/squire.js index fc79e9a..d78a02b 100644 --- a/build/squire.js +++ b/build/squire.js @@ -1 +1 @@ -/* Copyright © 2011 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.prototype,d;for(d in b)c[d]=b[d]},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;a(Node,{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,{isInline:d,isLeaf: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):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,j=c.compareBoundaryPoints(f,d)<1;return!i&&!j}var k=c.compareBoundaryPoints(e,d)<1,l=c.compareBoundaryPoints(g,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=i(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=j(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(ce.endOffset?p.splitText(e.endOffset):o=e.endOffset),p===e.startContainer&&(q&&e.startOffset?p=p.splitText(e.startOffset):n=e.startOffset),q&&(m(a,b).wraps(p),o=p.length),l=p,k||(k=l);while(p=j.nextNode());e=s(k,n,l,o)}return e},V=function(a,b,d){I(d);var e=d.commonAncestorContainer;while(e.isInline())e=e.parentNode;var f=d.startContainer,g=d.startOffset,h=d.endContainer,i=d.endOffset,j=[],k=function n(a,b){if(d.containsNode(a,!1))return;var e=a.nodeType===c,k,l;if(!d.containsNode(a,!0)){e&&!a.length?a.detach():a.nodeName!=="INPUT"&&j.push([b,a]);return}if(e)a===h&&i!==a.length&&j.push([b,a.splitText(i)]),a===f&&g&&(a.splitText(g),j.push([b,a]));else for(k=a.firstChild;k;k=l)l=k.nextSibling,n(k,b)},l=Array.prototype.filter.call(e.getElementsByTagName(a),function(c){return d.containsNode(c,!0)&&c.is(a,b)});l.forEach(function(a){k(a,a)}),j.forEach(function(a){a[0].cloneNode(!1).wraps(a[1])}),l.forEach(function(a){a.replaceWith(a.empty())}),d=K();var m={startContainer:d.startContainer,startOffset:d.startOffset,endContainer:d.endContainer,endOffset:d.endOffset};return e.mergeInlines(m),d.setStart(m.startContainer,m.startOffset),d.setEnd(m.endContainer,m.endOffset),d},W=function(a,b,c){if(!c&&!(c=v()))return;Q(c),K(c),b&&(c=V(b.tag.toUpperCase(),b.attributes||{},c)),a&&(c=U(a.tag.toUpperCase(),a.attributes||{},c)),A(c),P()},X=function(a,b){if(!b&&!(b=v()))return;Q(b),K(b);var c=b.commonAncestorContainer,d=h.createTreeWalker(c,e,function(a){return b.containsNode(a,!0)&&a.isBlock()?f:g},!1),i;while(i=d.nextNode())a(i);P()},Y=function(a,b){if(!b&&!(b=v()))return;k||j.setAttribute("contenteditable","false"),O?I(b):Q(b),b.expandToBlockBoundaries(),b.moveBoundariesUpTree(j);var c=b._extractContents(j);b._insertNode(a(c)),b.endOffset]*>([\s\S]*?)<\/style>/gi,bq=function(a){return function(){return a.apply(null,arguments),this}},br=function(a,b,c){return function(){return a(b,c),B(),this}};i.editor={addEventListener:bq(o),removeEventListener:bq(p),focus:bq(B),blur:bq(C),getDocument:function(){return h},getHTML:function(){var a=[],b,c,d,e;if(l){b=j;while(b=b.getNextBlock())!b.textContent&&!b.querySelector("BR")&&(c=m("BR"),b.appendChild(c),a.push(c))}d=D();if(l){e=a.length;while(e--)a[e].detach()}return d},setHTML:function(a){var b=h.createDocumentFragment(),c=m("DIV"),d="",e;bp.lastIndex=0,a=a.replace(bp,function(a,b){return d+=b.replace(//g,""),""}),c.innerHTML=a,b.appendChild(c.empty()),bi(b,!0),bk(b),bj(b,"DIV");var f=b;while(f=f.getNextBlock())f.fixCursor();while(e=j.lastChild)j.removeChild(e);if(d){var g=h.documentElement.firstChild,i=m("STYLE",{type:"text/css"});i.styleSheet?(g.appendChild(i),i.styleSheet.cssText=d):(i.appendChild(h.createTextNode(d)),g.appendChild(i))}j.appendChild(b),j.fixCursor(),L=-1,M=[],N=0,O=!1;var k=s(j.firstChild,0);return Q(k),A(K(k)),this},insertImage:function(a){var b=m("IMG",{src:a});return F(b),b},getPath:function(){return y},getSelection:v,setSelection:bq(A),undo:bq(R),redo:bq(S),hasFormat:bq(T),changeFormat:bq(W),bold:br(W,{tag:"B"}),italic:br(W,{tag:"I"}),underline:br(W,{tag:"U"}),removeBold:br(W,null,{tag:"B"}),removeItalic:br(W,null,{tag:"I"}),removeUnderline:br(W,null,{tag:"U"}),makeLink:function(a){return W({tag:"A",attributes:{href:a}},{tag:"A"}),B(),this},setFontFace:function(a){return W({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+a+", sans-serif;"}},{tag:"SPAN","class":"font"}),B(),this},setFontSize:function(a){return W({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+(typeof a=="number"?a+"px":a)}},{tag:"SPAN","class":"size"}),B(),this},setTextAlignment:function(a){return X(function(b){b.style.textAlign=a}),B(),this},modifyBlocks:bq(Y),incQuoteLevel:br(Y,Z),decQuoteLevel:br(Y,$),makeUnorderedList:br(Y,ba),makeOrderedList:br(Y,bb),removeList:br(Y,bc)},j.setAttribute("contenteditable","true"),i.editor.setHTML("")},!1); \ No newline at end of file +/* Copyright © 2011 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.prototype,d;for(d in b)c[d]=b[d]},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;a(Node,{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,{isInline:d,isLeaf: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):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,j=c.compareBoundaryPoints(f,d)<1;return!i&&!j}var k=c.compareBoundaryPoints(e,d)<1,l=c.compareBoundaryPoints(g,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=i(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=j(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(ce.endOffset?p.splitText(e.endOffset):o=e.endOffset),p===e.startContainer&&(q&&e.startOffset?p=p.splitText(e.startOffset):m=e.startOffset),q&&(n(a,b).wraps(p),o=p.length),l=p,k||(k=l);while(p=j.nextNode());e=t(k,m,l,o)}return e},W=function(a,b,d){J(d);var e=d.commonAncestorContainer;while(e.isInline())e=e.parentNode;var f=d.startContainer,g=d.startOffset,h=d.endContainer,i=d.endOffset,j=[],k=function n(a,b){if(d.containsNode(a,!1))return;var e=a.nodeType===c,k,l;if(!d.containsNode(a,!0)){e&&!a.length?a.detach():a.nodeName!=="INPUT"&&j.push([b,a]);return}if(e)a===h&&i!==a.length&&j.push([b,a.splitText(i)]),a===f&&g&&(a.splitText(g),j.push([b,a]));else for(k=a.firstChild;k;k=l)l=k.nextSibling,n(k,b)},l=Array.prototype.filter.call(e.getElementsByTagName(a),function(c){return d.containsNode(c,!0)&&c.is(a,b)});l.forEach(function(a){k(a,a)}),j.forEach(function(a){a[0].cloneNode(!1).wraps(a[1])}),l.forEach(function(a){a.replaceWith(a.empty())}),d=L();var m={startContainer:d.startContainer,startOffset:d.startOffset,endContainer:d.endContainer,endOffset:d.endOffset};return e.mergeInlines(m),d.setStart(m.startContainer,m.startOffset),d.setEnd(m.endContainer,m.endOffset),d},X=function(a,b,c){if(!c&&!(c=w()))return;R(c),L(c),b&&(c=W(b.tag.toUpperCase(),b.attributes||{},c)),a&&(c=V(a.tag.toUpperCase(),a.attributes||{},c)),B(c),Q()},Y=function(a,b){if(!b&&!(b=w()))return;R(b),L(b);var c=b.commonAncestorContainer,d=h.createTreeWalker(c,e,function(a){return b.containsNode(a,!0)&&a.isBlock()?f:g},!1),i;while(i=d.nextNode())a(i);Q()},Z=function(a,b){if(!b&&!(b=w()))return;k||j.setAttribute("contenteditable","false"),P?J(b):R(b),b.expandToBlockBoundaries(),b.moveBoundariesUpTree(j);var c=b._extractContents(j);b._insertNode(a(c)),b.endOffset]*>([\s\S]*?)<\/style>/gi,br=function(a){return function(){return a.apply(null,arguments),this}},bs=function(a,b,c){return function(){return a(b,c),C(),this}};i.editor={addEventListener:br(p),removeEventListener:br(q),focus:br(C),blur:br(D),getDocument:function(){return h},getHTML:function(){var a=[],b,c,d,e;if(m){b=j;while(b=b.getNextBlock())!b.textContent&&!b.querySelector("BR")&&(c=n("BR"),b.appendChild(c),a.push(c))}d=E();if(m){e=a.length;while(e--)a[e].detach()}return d},setHTML:function(a){var b=h.createDocumentFragment(),c=n("DIV"),d="",e;bq.lastIndex=0,a=a.replace(bq,function(a,b){return d+=b.replace(//g,""),""}),c.innerHTML=a,b.appendChild(c.empty()),bj(b,!0),bl(b),bk(b,"DIV");var f=b;while(f=f.getNextBlock())f.fixCursor();while(e=j.lastChild)j.removeChild(e);if(d){var g=h.documentElement.firstChild,i=n("STYLE",{type:"text/css"});i.styleSheet?(g.appendChild(i),i.styleSheet.cssText=d):(i.appendChild(h.createTextNode(d)),g.appendChild(i))}j.appendChild(b),j.fixCursor(),M=-1,N=[],O=0,P=!1;var k=t(j.firstChild,0);return R(k),B(L(k)),this},insertImage:function(a){var b=n("IMG",{src:a});return G(b),b},getPath:function(){return z},getSelection:w,setSelection:br(B),undo:br(S),redo:br(T),hasFormat:br(U),changeFormat:br(X),bold:bs(X,{tag:"B"}),italic:bs(X,{tag:"I"}),underline:bs(X,{tag:"U"}),removeBold:bs(X,null,{tag:"B"}),removeItalic:bs(X,null,{tag:"I"}),removeUnderline:bs(X,null,{tag:"U"}),makeLink:function(a){return X({tag:"A",attributes:{href:a}},{tag:"A"}),C(),this},setFontFace:function(a){return X({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+a+", sans-serif;"}},{tag:"SPAN","class":"font"}),C(),this},setFontSize:function(a){return X({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+(typeof a=="number"?a+"px":a)}},{tag:"SPAN","class":"size"}),C(),this},setTextAlignment:function(a){return Y(function(b){b.style.textAlign=a}),C(),this},modifyBlocks:br(Z),incQuoteLevel:bs(Z,$),decQuoteLevel:bs(Z,_),makeUnorderedList:bs(Z,bb),makeOrderedList:bs(Z,bc),removeList:bs(Z,bd)},j.setAttribute("contenteditable","true"),i.editor.setHTML("")},!1); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 20523bd..6d7a30c 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -21,7 +21,8 @@ document.addEventListener( 'DOMContentLoaded', function () { body = doc.body; var isOpera = !!win.opera; - var useTextFixer = isOpera || !!win.ie; + var isIE = !!win.ie; + var useTextFixer = isOpera || isOpera; // --- DOM Sugar --- @@ -959,14 +960,18 @@ document.addEventListener( 'DOMContentLoaded', function () { // --- Cut and Paste --- - doc.addEventListener( 'cut', function () { + doc.addEventListener( isIE ? 'beforecut' : 'cut', function () { + // Save undo checkpoint + var range = getSelection(); + recordUndoState( range ); + getRangeAndRemoveBookmark( range ); // If all content removed, ensure div at start of body. setTimeout( function () { body.fixCursor(); }, 0 ); }); - doc.addEventListener( 'paste', function () { + doc.addEventListener( isIE ? 'beforepaste' : 'paste', function () { var range = getSelection(), startContainer = range.startContainer, startOffset = range.startOffset,