diff --git a/build/squire.js b/build/squire.js index b776692..dee1a7e 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,{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):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(c20)&&(b<33||b>45)&&S()});var T=function(a){R||(O+=1,Of.endOffset?p.splitText(f.endOffset):n=f.endOffset),p===f.startContainer&&(q&&f.startOffset?p=p.splitText(f.startOffset):m=f.startOffset),q&&(o(b,c).wraps(p),n=p.length),l=p,k||(k=l);while(p=j.nextNode());f=v(k,m,l,n)}return f},Y=function(b,c,e,f){L(e),e.collapsed&&e._insertNode(a.createTextNode(""));var g=e.commonAncestorContainer;while(g.isInline())g=g.parentNode;var h=e.startContainer,i=e.startOffset,j=e.endContainer,k=e.endOffset,l=[],m=function p(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)&&l.push([b,a]);return}if(c)a===j&&k!==a.length&&l.push([b,a.splitText(k)]),a===h&&i&&(a.splitText(i),l.push([b,a]));else for(f=a.firstChild;f;f=g)g=f.nextSibling,p(f,b)},n=Array.prototype.filter.call(g.getElementsByTagName(b),function(a){return e.containsNode(a,!0)&&a.is(b,c)});f||n.forEach(function(a){m(a,a)}),l.forEach(function(a){a[0].cloneNode(!1).wraps(a[1])}),n.forEach(function(a){a.replaceWith(a.empty())}),e=N();var o={startContainer:e.startContainer,startOffset:e.startOffset,endContainer:e.endContainer,endOffset:e.endOffset};return g.mergeInlines(o),e.setStart(o.startContainer,o.startOffset),e.setEnd(o.endContainer,o.endOffset),e},Z=function(a,b,c,d){if(!c&&!(c=y()))return;T(c),N(c),b&&(c=Y(b.tag.toUpperCase(),b.attributes||{},c,d)),a&&(c=X(a.tag.toUpperCase(),a.attributes||{},c)),D(c),C(0,!0),S()},$=function(a,b,c){if(!c&&!(c=y()))return;b&&(T(c),N(c));var d=c.getStartBlock(),e=c.getEndBlock();if(d&&e)for(;;){if(a(d)||d===e)break;d=d.getNextBlock()}b&&(D(c),C(0,!0),S())},_=function(a,b){if(!b&&!(b=y()))return;k||j.setAttribute("contenteditable","false"),R?L(b):T(b),b.expandToBlockBoundaries(),b.moveBoundariesUpTree(j);var c=b._extractContents(j);b._insertNode(a(c)),b.endOffset]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i,bk=function(a){var b=a.ownerDocument,c=b.createTreeWalker(a,e,function(a){return a.nearest("A")?h:g},!1),d,f,i,j,k,l,m;while(d=c.nextNode()){f=d.data.split(bj),j=f.length;if(j>1){l=d.parentNode,m=d.nextSibling;for(i=0;i(a.documentElement.scrollTop||j.scrollTop)+j.offsetHeight&&i.scrollIntoView(!1),S()},backspace:function(a){var b=y();if(!b.collapsed)a.preventDefault(),b._deleteContents(),D(b),C(0,!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(),D(b)}else{if(c.nearest("UL")||c.nearest("OL"))return _(bg,b);if(c.nearest("BLOCKQUOTE"))return _(bb,b);D(b),C(0,!0)}}},"delete":function(a){var b=y();if(!b.collapsed)a.preventDefault(),b._deleteContents(),D(b),C(0,!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(),D(b),C(0,!0)}}},space:function(){var a=y();T(a),N(a),D(a)},"ctrl-b":bv("B"),"ctrl-i":bv("I"),"ctrl-u":bv("U"),"ctrl-y":bu(V),"ctrl-z":bu(U),"ctrl-shift-z":bu(V)};t("keydown",function(a){var b=a.keyCode||a.which,c=bt[b]||String.fromCharCode(b).toLowerCase(),d="";111]*>([\s\S]*?)<\/style>/gi,by=function(a){return function(){return a.apply(null,arguments),this}},bz=function(a,b,c){return function(){return a(b,c),E(),this}};i.editor={addEventListener:by(t),removeEventListener:by(u),focus:by(E),blur:by(F),getDocument:function(){return a},addStyles:function(b){if(b){var c=o("STYLE",{type:"text/css"});c.appendChild(a.createTextNode(b)),a.documentElement.firstChild.appendChild(c)}return this},getHTML:function(){var a=[],b,c,d,e;if(n){b=j;while(b=b.getNextBlock())!b.textContent&&!b.querySelector("BR")&&(c=o("BR"),b.appendChild(c),a.push(c))}d=G();if(n){e=a.length;while(e--)a[e].detach()}return d},setHTML:function(b){var c=a.createDocumentFragment(),d=o("DIV"),e;d.innerHTML=b,c.appendChild(d.empty()),bo(c,!0),bq(c),bp(c,"DIV");var f=c;while(f=f.getNextBlock())f.fixCursor();while(e=j.lastChild)j.removeChild(e);j.appendChild(c),j.fixCursor(),O=-1,P=[],Q=0,R=!1;var g=v(j.firstChild,0);return T(g),D(N(g)),C(0,!0),this},getSelectedText:function(){return y().getTextContent()},insertImage:function(a){var b=o("IMG",{src:a});return I(b),b},getPath:function(){return B},getSelection:y,setSelection:by(D),undo:by(U),redo:by(V),hasFormat:W,changeFormat:by(Z),bold:bz(Z,{tag:"B"}),italic:bz(Z,{tag:"I"}),underline:bz(Z,{tag:"U"}),removeBold:bz(Z,null,{tag:"B"}),removeItalic:bz(Z,null,{tag:"I"}),removeUnderline:bz(Z,null,{tag:"U"}),makeLink:function(b){b=encodeURI(b);var c=y();if(c.collapsed){var d=b.indexOf(":")+1;if(d)while(b[d]==="/")d+=1;c._insertNode(a.createTextNode(b.slice(d)))}return Z({tag:"A",attributes:{href:b}},{tag:"A"},c),E(),this},removeLink:function(){return Z(null,{tag:"A"},y(),!0),E(),this},setFontFace:function(a){return Z({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+a+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),E(),this},setFontSize:function(a){return Z({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+(typeof a=="number"?a+"px":a)}},{tag:"SPAN",attributes:{"class":"size"}}),E(),this},setTextColour:function(a){return Z({tag:"SPAN",attributes:{"class":"colour",style:"color: "+a}},{tag:"SPAN",attributes:{"class":"colour"}}),E(),this},setHighlightColour:function(a){return Z({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+a}},{tag:"SPAN",attributes:{"class":"highlight"}}),E(),this},setTextAlignment:function(a){return $(function(b){b.className="align-"+a,b.style.textAlign=a},!0),E(),this},forEachBlock:by($),modifyBlocks:by(_),incQuoteLevel:bz(_,ba),decQuoteLevel:bz(_,bb),makeUnorderedList:bz(_,be),makeOrderedList:bz(_,bf),removeList:bz(_,bg)},j.setAttribute("contenteditable","true"),i.editor.setHTML(""),i.onEditorLoad&&(i.onEditorLoad(i.editor),delete i.onEditorLoad)}(document); \ 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,{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):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(c20)&&(b<33||b>45)&&S()});var T=function(a){R||(O+=1,Of.endOffset?p.splitText(f.endOffset):n=f.endOffset),p===f.startContainer&&(q&&f.startOffset?p=p.splitText(f.startOffset):m=f.startOffset),q&&(o(b,c).wraps(p),n=p.length),l=p,k||(k=l);while(p=j.nextNode());f=v(k,m,l,n)}return f},Y=function(b,c,e,f){L(e),e.collapsed&&e._insertNode(a.createTextNode(""));var g=e.commonAncestorContainer;while(g.isInline())g=g.parentNode;var h=e.startContainer,i=e.startOffset,j=e.endContainer,k=e.endOffset,l=[],m=function p(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)&&l.push([b,a]);return}if(c)a===j&&k!==a.length&&l.push([b,a.splitText(k)]),a===h&&i&&(a.splitText(i),l.push([b,a]));else for(f=a.firstChild;f;f=g)g=f.nextSibling,p(f,b)},n=Array.prototype.filter.call(g.getElementsByTagName(b),function(a){return e.containsNode(a,!0)&&a.is(b,c)});f||n.forEach(function(a){m(a,a)}),l.forEach(function(a){a[0].cloneNode(!1).wraps(a[1])}),n.forEach(function(a){a.replaceWith(a.empty())}),e=N();var o={startContainer:e.startContainer,startOffset:e.startOffset,endContainer:e.endContainer,endOffset:e.endOffset};return g.mergeInlines(o),e.setStart(o.startContainer,o.startOffset),e.setEnd(o.endContainer,o.endOffset),e},Z=function(a,b,c,d){if(!c&&!(c=y()))return;T(c),N(c),b&&(c=Y(b.tag.toUpperCase(),b.attributes||{},c,d)),a&&(c=X(a.tag.toUpperCase(),a.attributes||{},c)),D(c),C(0,!0),S()},$=function(a,b,c){if(!c&&!(c=y()))return;b&&(T(c),N(c));var d=c.getStartBlock(),e=c.getEndBlock();if(d&&e)for(;;){if(a(d)||d===e)break;d=d.getNextBlock()}b&&(D(c),C(0,!0),S())},_=function(a,b){if(!b&&!(b=y()))return;k||j.setAttribute("contenteditable","false"),R?L(b):T(b),b.expandToBlockBoundaries(),b.moveBoundariesUpTree(j);var c=b._extractContents(j);b._insertNode(a(c)),b.endOffset]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i,bk=function(a){var b=a.ownerDocument,c=b.createTreeWalker(a,e,function(a){return a.nearest("A")?h:g},!1),d,f,i,j,k,l,m;while(d=c.nextNode()){f=d.data.split(bj),j=f.length;if(j>1){l=d.parentNode,m=d.nextSibling;for(i=0;i(a.documentElement.scrollTop||j.scrollTop)+j.offsetHeight&&i.scrollIntoView(!1),S()},backspace:function(a){var b=y();if(!b.collapsed)a.preventDefault(),b._deleteContents(),D(b),C(0,!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(),D(b)}else{if(c.nearest("UL")||c.nearest("OL"))return _(bg,b);if(c.nearest("BLOCKQUOTE"))return _(bb,b);D(b),C(0,!0)}}},"delete":function(a){var b=y();if(!b.collapsed)a.preventDefault(),b._deleteContents(),D(b),C(0,!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(),D(b),C(0,!0)}}},space:function(){var a=y();T(a),N(a),D(a)},"ctrl-b":bv("B"),"ctrl-i":bv("I"),"ctrl-u":bv("U"),"ctrl-y":bu(V),"ctrl-z":bu(U),"ctrl-shift-z":bu(V)};t("keydown",function(a){var b=a.keyCode||a.which,c=bt[b]||String.fromCharCode(b).toLowerCase(),d="";111]*>([\s\S]*?)<\/style>/gi,by=function(a){return function(){return a.apply(null,arguments),this}},bz=function(a,b,c){return function(){return a(b,c),E(),this}};i.editor={addEventListener:by(t),removeEventListener:by(u),focus:by(E),blur:by(F),getDocument:function(){return a},addStyles:function(b){if(b){var c=o("STYLE",{type:"text/css"});c.appendChild(a.createTextNode(b)),a.documentElement.firstChild.appendChild(c)}return this},getHTML:function(){var a=[],b,c,d,e;if(n){b=j;while(b=b.getNextBlock())!b.textContent&&!b.querySelector("BR")&&(c=o("BR"),b.appendChild(c),a.push(c))}d=G();if(n){e=a.length;while(e--)a[e].detach()}return d},setHTML:function(b){var c=a.createDocumentFragment(),d=o("DIV"),e;d.innerHTML=b,c.appendChild(d.empty()),bo(c,!0),bq(c),bp(c,"DIV");var f=c;while(f=f.getNextBlock())f.fixCursor();while(e=j.lastChild)j.removeChild(e);j.appendChild(c),j.fixCursor(),O=-1,P=[],Q=0,R=!1;var g=v(j.firstChild,0);return T(g),D(N(g)),C(0,!0),this},getSelectedText:function(){return y().getTextContent()},insertImage:function(a){var b=o("IMG",{src:a});return I(b),b},getPath:function(){return B},getSelection:y,setSelection:by(D),undo:by(U),redo:by(V),hasFormat:W,changeFormat:by(Z),bold:bz(Z,{tag:"B"}),italic:bz(Z,{tag:"I"}),underline:bz(Z,{tag:"U"}),removeBold:bz(Z,null,{tag:"B"}),removeItalic:bz(Z,null,{tag:"I"}),removeUnderline:bz(Z,null,{tag:"U"}),makeLink:function(b){b=encodeURI(b);var c=y();if(c.collapsed){var d=b.indexOf(":")+1;if(d)while(b[d]==="/")d+=1;c._insertNode(a.createTextNode(b.slice(d)))}return Z({tag:"A",attributes:{href:b}},{tag:"A"},c),E(),this},removeLink:function(){return Z(null,{tag:"A"},y(),!0),E(),this},setFontFace:function(a){return Z({tag:"SPAN",attributes:{"class":"font",style:"font-family: "+a+", sans-serif;"}},{tag:"SPAN",attributes:{"class":"font"}}),E(),this},setFontSize:function(a){return Z({tag:"SPAN",attributes:{"class":"size",style:"font-size: "+(typeof a=="number"?a+"px":a)}},{tag:"SPAN",attributes:{"class":"size"}}),E(),this},setTextColour:function(a){return Z({tag:"SPAN",attributes:{"class":"colour",style:"color: "+a}},{tag:"SPAN",attributes:{"class":"colour"}}),E(),this},setHighlightColour:function(a){return Z({tag:"SPAN",attributes:{"class":"highlight",style:"background-color: "+a}},{tag:"SPAN",attributes:{"class":"highlight"}}),E(),this},setTextAlignment:function(a){return $(function(b){b.className="align-"+a,b.style.textAlign=a},!0),E(),this},forEachBlock:by($),modifyBlocks:by(_),incQuoteLevel:bz(_,ba),decQuoteLevel:bz(_,bb),makeUnorderedList:bz(_,be),makeOrderedList:bz(_,bf),removeList:bz(_,bg)},j.setAttribute("contenteditable","true"),i.editor.setHTML(""),i.onEditorLoad&&(i.onEditorLoad(i.editor),delete i.onEditorLoad)}(document); \ No newline at end of file diff --git a/source/Editor.js b/source/Editor.js index 2df3a79..2645db2 100644 --- a/source/Editor.js +++ b/source/Editor.js @@ -187,6 +187,9 @@ // --- Focus --- var focus = function () { + // FF seems to need the body to be focussed + // (at least on first load). + body.focus(); win.focus(); };