2013-01-14 18:34:37 -05:00
|
|
|
/* Copyright © 2011-2012 by Neil Jenkins. Licensed under the MIT license. *//*global navigator, window */var UA=function(e){"use strict";var t=navigator.userAgent,n=!!e.opera,r=/Trident\//.test(t),i=/WebKit\//.test(t);return{isOpera:n,isIE8:e.ie===8,isIE:r,isGecko:/Gecko\//.test(t),isWebKit:i,isIOS:/iP(?:ad|hone|od)/.test(t),useTextFixer:r||n,cantFocusEmptyTextNodes:r||i,losesSelectionOnBlur:r}}(window),DOMTreeWalker=function(){"use strict";var e={1:1,2:2,3:4,8:128,9:256,11:1024},t=1,n=function(e,t,n){this.root=this.currentNode=e,this.nodeType=t,this.filter=n};return n.prototype.nextNode=function(){var n=this.currentNode,r=this.root,i=this.nodeType,s=this.filter,o;for(;;){o=n.firstChild;while(!o&&n){if(n===r)break;o=n.nextSibling,o||(n=n.parentNode)}if(!o)return null;if(e[o.nodeType]&i&&s(o)===t)return this.currentNode=o,o;n=o}},n.prototype.previousNode=function(){var n=this.currentNode,r=this.root,i=this.nodeType,s=this.filter,o;for(;;){if(n===r)return null;o=n.previousSibling;if(o)while(n=o.lastChild)o=n;else o=n.parentNode;if(!o)return null;if(e[o.nodeType]&i&&s(o)===t)return this.currentNode=o,o;n=o}},n}();(function(e,t){"use strict";var n=function(e,t){var n=e.length,r,i;while(n--){r=e[n].prototype;for(i in t)r[i]=t[i]}},r=function(e,t){var n=e.length;while(n--)if(!t(e[n]))return!1;return!0},i=function(){return!1},s=function(){return!0},o=/^(?: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)$/,u={BR:1,IMG:1,INPUT:1},a=function(e,t){var n=t.parentNode;return n&&n.replaceChild(e,t),e},f=1,l=3,c=1,h=1,p=3,d=function(e){return e.isBlock()?h:p};n(window.Node?[Node]:[Text,Element,HTMLDocument],{isInline:i,isBlock:i,isContainer:i,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 a(e,this),this},replaces:function(e){return a(this,e),this},nearest:function(e,t){var n=this.parentNode;return n?n.nearest(e,t):null},getPreviousBlock:function(){var e=this.ownerDocument,n=new t(e.body,c,d,!1);return n.currentNode=this,n.previousNode()},getNextBlock:function(){var e=this.ownerDocument,n=new t(e.body,c,d,!1);return n.currentNode=this,n.nextNode()},split:function(e,t){return e},mergeContainers:function(){}}),n([Text],{isLeaf:i,isInline:s,getLength:function(){return this.length},isLike:function(e){return e.nodeType===l},split:function(e,t){var n=this;return n===t?e:n.parentNode.split(n.splitText(e),t)}}),n([Element],{isLeaf:function(){return!!u[this.nodeName]},isInline:function(){return o.test(this.nodeName)},isBlock:function(){return!this.isInline()&&r(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 a(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===f);return null},isLike:function(e){return e.nodeType===f&&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,s,o;while(n--){i=t[n],s=n&&t[n-1];if(n&&i.isInline()&&i.isLike(s)&&!u[i.nodeName])e.startContainer===i&&(e.startContainer=s,e.startOffset+=s.getLength()),e.endContainer===i&&(e.endContainer=s,e.endOffset+=s.getLength()),e.startContainer===this&&(e.startOffset>n?e.startOffset-=1:e.startOffset===n&&(e.startContainer=s,e.startOffset=s.getLength())),e.endContainer===this&&(e.endOffset>n?e.endOffse
|