diff --git a/bonzo.js b/bonzo.js index 6327c7e..a1606cf 100644 --- a/bonzo.js +++ b/bonzo.js @@ -838,7 +838,7 @@ var el = this[0] , de = el.ownerDocument.documentElement , bcr = el.getBoundingClientRect() - , scroll = getWindowScroll() + , scroll = getWindowScroll(el) , width = el.offsetWidth , height = el.offsetHeight , top = bcr.top + scroll.y - Math.max(0, de && de.clientTop, doc.body.clientTop) @@ -1046,8 +1046,16 @@ return element === win || (/^(?:body|html)$/i).test(element.tagName) } - function getWindowScroll() { - return { x: win.pageXOffset || html.scrollLeft, y: win.pageYOffset || html.scrollTop } + function getWindowScroll(el) { + var elBody, elHtml + if(el === undefined) { + elBody = doc.body, + elHtml = html; + } else { + elBody = el.ownerDocument.body, + elHtml = elBody.parentNode; + } + return { x: elBody.scrollLeft || elHtml.scrollLeft, y: elBody.scrollTop || elHtml.scrollTop } } function createScriptFromHtml(html) { @@ -1060,7 +1068,8 @@ /** * @param {Array.|Element|Node|string} els * @return {Bonzo} - */ + */ + function bonzo(els) { return new Bonzo(els) } diff --git a/bonzo.min.js b/bonzo.min.js index 39caa23..a7521e7 100644 --- a/bonzo.min.js +++ b/bonzo.min.js @@ -3,4 +3,4 @@ * https://github.com/ded/bonzo * License MIT */ -(function(e,t,n){typeof module!="undefined"&&module.exports?module.exports=n():typeof define=="function"&&define.amd?define(n):t[e]=n()})("bonzo",this,function(){function D(e){return e&&e.nodeName&&(e.nodeType==1||e.nodeType==11)}function P(e,t,n){var r,i,s;if(typeof e=="string")return et.create(e);D(e)&&(e=[e]);if(n){s=[];for(r=0,i=e.length;r0?Q(s,r):r)},null,r)},this,r),s.length=i,B(o,function(e){s[--i]=e},null,!r),s}function V(e,t,n){var r=et(e),i=r.css("position"),s=r.offset(),o="relative",u=i==o,a=[parseInt(r.css("left"),10),parseInt(r.css("top"),10)];i=="static"&&(r.css("position",o),i=o),isNaN(a[0])&&(a[0]=u?0:e.offsetLeft),isNaN(a[1])&&(a[1]=u?0:e.offsetTop),t!=null&&(e.style.left=t-s.left+a[0]+E),n!=null&&(e.style.top=n-s.top+a[1]+E)}function $(e,t){return typeof t=="function"?t(e):t}function J(t,n,r){var i=this[0];return i?t==null&&n==null?(G(i)?Y():{x:i.scrollLeft,y:i.scrollTop})[r]:(G(i)?e.scrollTo(t,n):(t!=null&&(i.scrollLeft=t),n!=null&&(i.scrollTop=n)),this):this}function K(e){this.length=0;if(e){e=typeof e!="string"&&!e.nodeType&&typeof e.length!="undefined"?e:[e],this.length=e.length;for(var t=0;t/,u=["","
",1],a=["","
",3],f=["",1],l=["_","",0,1],c={thead:u,tbody:u,tfoot:u,colgroup:u,caption:u,tr:["","
",2],th:a,td:a,col:["","
",2],fieldset:["
","
",1],legend:["
","
",2],option:f,optgroup:f,script:l,style:l,link:l,param:l,base:l},h=/^(checked|selected|disabled)$/,p=/msie/i.test(navigator.userAgent),d,v,m,g={},y=0,b=/^-?[\d\.]+$/,w=/^data-(.+)$/,E="px",S="setAttribute",x="getAttribute",T="getElementsByTagName",N=function(){var e=t.createElement("p");return e.innerHTML='x
',{hrefExtended:e[T]("a")[0][x]("href")!="#x",autoTbody:e[T]("tbody").length!==0,computedStyle:t.defaultView&&t.defaultView.getComputedStyle,cssFloat:e[T]("table")[0].style.styleFloat?"styleFloat":"cssFloat",transform:function(){var t=["transform","webkitTransform","MozTransform","OTransform","msTransform"],n;for(n=0;n]+)/),i=t.createElement("div"),s=[],u=n?c[n[1].toLowerCase()]:null,a=u?u[2]+1:1,f=u&&u[3],l=r,h=N.autoTbody&&u&&u[0]==""&&!/0?Q(s,r):r)},null,r)},this,r),s.length=i,B(o,function(e){s[--i]=e},null,!r),s}function V(e,t,n){var r=et(e),i=r.css("position"),s=r.offset(),o="relative",u=i==o,a=[parseInt(r.css("left"),10),parseInt(r.css("top"),10)];i=="static"&&(r.css("position",o),i=o),isNaN(a[0])&&(a[0]=u?0:e.offsetLeft),isNaN(a[1])&&(a[1]=u?0:e.offsetTop),t!=null&&(e.style.left=t-s.left+a[0]+E),n!=null&&(e.style.top=n-s.top+a[1]+E)}function $(e,t){return typeof t=="function"?t(e):t}function J(t,n,r){var i=this[0];return i?t==null&&n==null?(G(i)?Y():{x:i.scrollLeft,y:i.scrollTop})[r]:(G(i)?e.scrollTo(t,n):(t!=null&&(i.scrollLeft=t),n!=null&&(i.scrollTop=n)),this):this}function K(e){this.length=0;if(e){e=typeof e!="string"&&!e.nodeType&&typeof e.length!="undefined"?e:[e],this.length=e.length;for(var t=0;t/,u=["
","
",1],a=["","
",3],f=["",1],l=["_","",0,1],c={thead:u,tbody:u,tfoot:u,colgroup:u,caption:u,tr:["","
",2],th:a,td:a,col:["","
",2],fieldset:["
","
",1],legend:["
","
",2],option:f,optgroup:f,script:l,style:l,link:l,param:l,base:l},h=/^(checked|selected|disabled)$/,p=/msie/i.test(navigator.userAgent),d,v,m,g={},y=0,b=/^-?[\d\.]+$/,w=/^data-(.+)$/,E="px",S="setAttribute",x="getAttribute",T="getElementsByTagName",N=function(){var e=t.createElement("p");return e.innerHTML='x
',{hrefExtended:e[T]("a")[0][x]("href")!="#x",autoTbody:e[T]("tbody").length!==0,computedStyle:t.defaultView&&t.defaultView.getComputedStyle,cssFloat:e[T]("table")[0].style.styleFloat?"styleFloat":"cssFloat",transform:function(){var t=["transform","webkitTransform","MozTransform","OTransform","msTransform"],n;for(n=0;n]+)/),i=t.createElement("div"),s=[],u=n?c[n[1].toLowerCase()]:null,a=u?u[2]+1:1,f=u&&u[3],l=r,h=N.autoTbody&&u&&u[0]==""&&!/|Element|Node|string} els * @return {Bonzo} - */ + */ + function bonzo(els) { return new Bonzo(els) }