From 630a7c4e4f5dcffd04f5c210c9a3be383758ec6d Mon Sep 17 00:00:00 2001 From: Neil Jenkins Date: Tue, 24 Jul 2012 15:54:05 +1000 Subject: [PATCH] Tidy IE8 range code. --- build/ie8.js | 2 +- source/ie8range.js | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/build/ie8.js b/build/ie8.js index bbbc2a5..b6c8353 100644 --- a/build/ie8.js +++ b/build/ie8.js @@ -1 +1 @@ -/* Copyright © 2011-2012 by Neil Jenkins. Licensed under the MIT license. */(function(a){Array.prototype.indexOf=function(a,b){var c=this.length;for(var d=b<0?Math.max(0,c+b):b||0;d>>0;if(typeof a!="function")throw new TypeError;for(var d=0;dj?1:0;k=g;while(l=k.parentNode){if(l===i)return a.call(l.childNodes,k)i.sourceIndex?1:0}},document.createRange=function(){return new Range};var h=function(a,b){return a===b||f(a,b)},i=function(a){var b=a.nodeType;return b===3||b===4||b===8},j=function(a,b){this.node=a,this.offset=b},k=function(a){var b=a.parentElement(),c,d,e,f;return c=a.duplicate(),c.collapse(!0),d=c.parentElement(),c=a.duplicate(),c.collapse(!1),e=c.parentElement(),f=d===e?d:g(d,e),f===b?f:g(b,f)},l=function(b,c,d,e){var f=b.duplicate();f.collapse(d);var g=f.parentElement();h(c,g)||(g=c);if(!g.canHaveHTML)return new j(g.parentNode,a.call(g.parentNode.childNodes,g));var k=document.createElement("span"),l=d?"StartToStart":"StartToEnd",m,n,o,p,q;do g.insertBefore(k,k.previousSibling),f.moveToElementText(k),m=f.compareEndPoints(l,b);while(m>0&&k.previousSibling);q=k.nextSibling;if(m===-1&&q&&i(q)){f.setEndPoint(d?"EndToStart":"EndToEnd",b);var r;if(/[\r\n]/.test(q.data)||/[\r\n]/.test(f.text)){var s=f.duplicate(),t=s.text.replace(/\r\n/g,"\r").length;r=s.moveStart("character",t);while((m=s.compareEndPoints("StartToEnd",s))===-1)r+=1,s.moveStart("character",1)}else r=f.text.length;p=new j(q,r)}else n=(e||!d)&&k.previousSibling,o=(e||d)&&k.nextSibling,o&&i(o)?p=new j(o,0):n&&i(n)?(n.data,p=new j(n,n.length)):p=new j(g,a.call(g.childNodes,k));return k.parentNode.removeChild(k),p},m=function(a,b){var c,d,e=a.offset,f=document,g,h,j=f.body.createTextRange(),k=i(a.node);return k?(c=a.node,d=c.parentNode):(h=a.node.childNodes,c=e>>0;if(typeof e!="function")throw new TypeError;for(var r=0;rf?1:0;l=o;while(c=l.parentNode){if(c===a)return e.call(c.childNodes,l)a.sourceIndex?1:0}},document.createRange=function(){return new Range};var o=function(e,t){return e===t||i(e,t)},u=function(e){var t=e.nodeType;return t===3||t===4||t===8},a=function(e,t){this.node=e,this.offset=t},f=function(e){var t=e.parentElement(),n,r,i,o;return n=e.duplicate(),n.collapse(!0),r=n.parentElement(),n=e.duplicate(),n.collapse(!1),i=n.parentElement(),o=r===i?r:s(r,i),o===t?o:s(t,o)},l=function(t,n,r,i){var s=t.duplicate();s.collapse(r);var f=s.parentElement();o(n,f)||(f=n);if(!f.canHaveHTML)return new a(f.parentNode,e.call(f.parentNode.childNodes,f));var l=document.createElement("span"),c=r?"StartToStart":"StartToEnd",h,p,d,v,m;do f.insertBefore(l,l.previousSibling),s.moveToElementText(l),h=s.compareEndPoints(c,t);while(h>0&&l.previousSibling);m=l.nextSibling;if(h===-1&&m&&u(m)){s.setEndPoint(r?"EndToStart":"EndToEnd",t);var g;if(/[\r\n]/.test(m.data)||/[\r\n]/.test(s.text)){var y=s.duplicate(),b=y.text.replace(/\r\n/g,"\r").length;g=y.moveStart("character",b);while((h=y.compareEndPoints("StartToEnd",y))===-1)g+=1,y.moveStart("character",1)}else g=s.text.length;v=new a(m,g)}else p=(i||!r)&&l.previousSibling,d=(i||r)&&l.nextSibling,d&&u(d)?v=new a(d,0):p&&u(p)?v=new a(p,p.data.length):v=new a(f,e.call(f.childNodes,l));return l.parentNode.removeChild(l),v},c=function(e,t){var n,r,i=e.offset,s=document,o,a,f=s.body.createTextRange(),l=u(e.node);return l?(n=e.node,r=n.parentNode):(a=e.node.childNodes,n=i