mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -05:00
1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
|
/* Copyright © 2011 by Neil Jenkins. Licensed under the MIT license. */(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=function(a,b){var c=b.parentNode;return c&&c.replaceChild(a,b),a},g=1,h=3,i=1,j=1,k=3,l=function(a,b){var c;for(;;){c=a.firstChild;while(!c&&a)c=a.nextSibling,c||(a=a.parentNode);if(c.nodeName==="BODY")return null;if(b(c))return c;a=c}},m=function(a,b){var c;for(;;){c=a.previousSibling;if(c)while(a=c.lastChild)c=a;else c=a.parentNode;if(c.nodeName==="BODY")return null;if(b(c))return c;a=c}},n=function(a){return a.isBlock()},o=!!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 f(a,this),this},replaces:function(a){return f(this,a),this},nearest:function(a,b){var c=this.parentNode;return c?c.nearest(a,b):null},getPreviousBlock:function(){return m(this,n)},getNextBlock:function(){return l(this,n)},split:function(a,b){return a},mergeContainers:function(){}}),a(Text,{isInline:d,getLength:function(){return this.length},isLike:function(a){return a.nodeType===h},split:function(a,b){var c=this;return b(c)?a:c.parentNode.split(c.splitText(a),b)}}),a(Element,{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 f(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===g);return null},isLike:function(a){return a.nodeType===g&&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,f,i;while(c--){e=b[c],f=c&&b[c-1];if(c&&e.isInline()&&e.isLike(f))a.startContainer===e&&(a.startContainer=f,a.startOffset+=f.getLength()),a.endContainer===e&&(a.endContainer=f,a.endOffset+=f.getLength()),a.startContainer===this&&(a.startOffset>c?a.startOffset-=1:a.startOffset===c&&(a.startContainer=f,a.startOffset=f.getLength())),a.endContainer===this&&(a.endOffset>c?a.endOffset-=1:a.endOffset===c&&(a.endContainer=f,a.endOffset=f.getLength())),e.detach(),e.nodeType===h?f.appendData(e.data):d.push(e.empty());else if(e.nodeType===g){i=d.length;while(i--)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=c.childNodes[a]);if(b(c))return a;var d=c.parentNode,e=c.cloneNode(!1),f;while(a)f=a.nextSibling,e.appendChild(a),a=f;return c.fixCursor(),e.fixCursor(),(f=c.nextSib
|