Created
February 25, 2011 09:03
-
-
Save shripadk/843550 to your computer and use it in GitHub Desktop.
scrollIntoView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var h=null,i=this;function j(a,b){if(a<b)return-1;else if(a>b)return 1;return 0};var k,l,m,n;function s(){return i.navigator?i.navigator.userAgent:h}n=m=l=k=false;var t;if(t=s()){var u=i.navigator;k=t.indexOf("Opera")==0;l=!k&&t.indexOf("MSIE")!=-1;m=!k&&t.indexOf("WebKit")!=-1;n=!k&&!m&&u.product=="Gecko"}var v=k,w=l,x=n,y=m,z; | |
a:{var A="",B;if(v&&i.opera){var C=i.opera.version;A=typeof C=="function"?C():C}else{if(x)B=/rv\:([^\);]+)(\)|;)/;else if(w)B=/MSIE\s+([^\);]+)(\)|;)/;else y&&(B=/WebKit\/(\S+)/);if(B){var D=B.exec(s());A=D?D[1]:""}}if(w){var E,F=i.document;E=F?F.documentMode:undefined;if(E>parseFloat(A)){z=String(E);break a}}z=A}var G={}; | |
function H(){if(!G["9"]){for(var a=0,b=String(z).replace(/^[\s\xa0]+|[\s\xa0]+$/g,"").split("."),c=String("9").replace(/^[\s\xa0]+|[\s\xa0]+$/g,"").split("."),e=Math.max(b.length,c.length),g=0;a==0&&g<e;g++){var d=b[g]||"",f=c[g]||"",o=RegExp("(\\d*)(\\D*)","g"),p=RegExp("(\\d*)(\\D*)","g");do{var q=o.exec(d)||["","",""],r=p.exec(f)||["","",""];if(q[0].length==0&&r[0].length==0)break;a=j(q[1].length==0?0:parseInt(q[1],10),r[1].length==0?0:parseInt(r[1],10))||j(q[2].length==0,r[2].length==0)||j(q[2], | |
r[2])}while(a==0)}G["9"]=a>=0}};var I;!w||H();w&&H();function J(a,b){this.x=a!==undefined?a:0;this.y=b!==undefined?b:0}J.prototype.toString=function(){return"("+this.x+", "+this.y+")"};function K(a){return a.nodeType==9?a:a.ownerDocument||a.document}function L(a){this.a=a||i.document||document};function M(a,b,c,e){this.top=a;this.right=b;this.bottom=c;this.left=e}M.prototype.toString=function(){return"("+this.top+"t, "+this.right+"r, "+this.bottom+"b, "+this.left+"l)"};function N(a,b){var c=K(a);if(c.defaultView&&c.defaultView.getComputedStyle)if(c=c.defaultView.getComputedStyle(a,h))return c[b]||c.getPropertyValue(b);return""}function O(a){return N(a,"position")||(a.currentStyle?a.currentStyle.position:h)||a.style.position} | |
function P(a){if(w)return a.offsetParent;var b=K(a),c=O(a),e=c=="fixed"||c=="absolute";for(a=a.parentNode;a&&a!=b;a=a.parentNode){c=O(a);e=e&&c=="static"&&a!=b.documentElement&&a!=b.body;if(!e&&(a.scrollWidth>a.clientWidth||a.scrollHeight>a.clientHeight||c=="fixed"||c=="absolute"))return a}return h} | |
function Q(a){var b,c=K(a),e=O(a),g=x&&c.getBoxObjectFor&&!a.getBoundingClientRect&&e=="absolute"&&(b=c.getBoxObjectFor(a))&&(b.screenX<0||b.screenY<0),d=new J(0,0),f;b=c?c.nodeType==9?c:K(c):document;if(f=w)f=(b?new L(K(b)):I||(I=new L)).a.compatMode!="CSS1Compat";f=f?b.body:b.documentElement;if(a==f)return d;if(a.getBoundingClientRect){b=a.getBoundingClientRect();if(w){a=a.ownerDocument;b.left-=a.documentElement.clientLeft+a.body.clientLeft;b.top-=a.documentElement.clientTop+a.body.clientTop}c= | |
(c?new L(K(c)):I||(I=new L)).a;c=!y&&c.compatMode=="CSS1Compat"?c.documentElement:c.body;c=new J(c.scrollLeft,c.scrollTop);d.x=b.left+c.x;d.y=b.top+c.y}else if(c.getBoxObjectFor&&!g){b=c.getBoxObjectFor(a);c=c.getBoxObjectFor(f);d.x=b.screenX-c.screenX;d.y=b.screenY-c.screenY}else{b=a;do{d.x+=b.offsetLeft;d.y+=b.offsetTop;if(b!=a){d.x+=b.clientLeft||0;d.y+=b.clientTop||0}if(y&&O(b)=="fixed"){d.x+=c.body.scrollLeft;d.y+=c.body.scrollTop;break}b=b.offsetParent}while(b&&b!=a);if(v||y&&e=="absolute")d.y-= | |
c.body.offsetTop;for(b=a;(b=P(b))&&b!=c.body&&b!=f;){d.x-=b.scrollLeft;if(!v||b.tagName!="TR")d.y-=b.scrollTop}}return d}var R={thin:2,medium:4,thick:6}; | |
function S(a,b){if((a.currentStyle?a.currentStyle[b+"Style"]:h)=="none")return 0;var c=a.currentStyle?a.currentStyle[b+"Width"]:h;if(c in R)return R[c];var e;if(/^\d+px?$/.test(c))e=parseInt(c,10);else{e=a.style.left;var g=a.runtimeStyle.left;a.runtimeStyle.left=a.currentStyle.left;a.style.left=c;c=a.style.pixelLeft;a.style.left=e;a.runtimeStyle.left=g;e=c}return e};function T(a,b,c){a=typeof a=="string"?document.getElementById(a):a;b=typeof b=="string"?document.getElementById(b):b;var e=Q(a),g=Q(b),d;if(w){var f=S(b,"borderLeft");d=S(b,"borderRight");var o=S(b,"borderTop"),p=S(b,"borderBottom");d=new M(o,d,p,f)}else{f=N(b,"borderLeftWidth");d=N(b,"borderRightWidth");o=N(b,"borderTopWidth");p=N(b,"borderBottomWidth");d=new M(parseFloat(o),parseFloat(d),parseFloat(p),parseFloat(f))}f=e.x-g.x-d.left;e=e.y-g.y-d.top;g=b.clientWidth-a.offsetWidth;a=b.clientHeight- | |
a.offsetHeight;if(c){b.scrollLeft+=f-g/2;b.scrollTop+=e-a/2}else{b.scrollLeft+=Math.min(f,Math.max(f-g,0));b.scrollTop+=Math.min(e,Math.max(e-a,0))}}var U="accelsor.scrollIntoContainerView".split("."),V=i;!(U[0]in V)&&V.execScript&&V.execScript("var "+U[0]);for(var W;U.length&&(W=U.shift());)if(!U.length&&T!==undefined)V[W]=T;else V=V[W]?V[W]:V[W]={}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment