X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=src%2Foffset.js;h=f80574eeae562a4207c9c2a52c6a23bc55d2c51f;hb=a49e6b63131e292bc1c31ee98b300ba87ce99162;hp=d12921dffc7baca43773d411889ed23fcc53aa96;hpb=6cb2945837ccca55204191a8e7a70b2b2486c28e;p=jquery.git diff --git a/src/offset.js b/src/offset.js index d12921d..f80574e 100644 --- a/src/offset.js +++ b/src/offset.js @@ -2,16 +2,16 @@ if ( "getBoundingClientRect" in document.documentElement ) { jQuery.fn.offset = function( options ) { var elem = this[0]; - if ( !elem || !elem.ownerDocument ) { - return null; - } - if ( options ) { - return this.each(function() { - jQuery.offset.setOffset( this, options ); + return this.each(function( i ) { + jQuery.offset.setOffset( this, options, i ); }); } + if ( !elem || !elem.ownerDocument ) { + return null; + } + if ( elem === elem.ownerDocument.body ) { return jQuery.offset.bodyOffset( elem ); } @@ -28,16 +28,16 @@ if ( "getBoundingClientRect" in document.documentElement ) { jQuery.fn.offset = function( options ) { var elem = this[0]; - if ( !elem || !elem.ownerDocument ) { - return null; - } - if ( options ) { - return this.each(function() { - jQuery.offset.setOffset( this, options ); + return this.each(function( i ) { + jQuery.offset.setOffset( this, options, i ); }); } + if ( !elem || !elem.ownerDocument ) { + return null; + } + if ( elem === elem.ownerDocument.body ) { return jQuery.offset.bodyOffset( elem ); } @@ -137,7 +137,7 @@ jQuery.offset = { return { top: top, left: left }; }, - setOffset: function( elem, options ) { + setOffset: function( elem, options, i ) { // set position first, in-case top/left are set even on static elem if ( /static/.test( jQuery.curCSS( elem, "position" ) ) ) { elem.style.position = "relative"; @@ -145,11 +145,16 @@ jQuery.offset = { var curElem = jQuery( elem ), curOffset = curElem.offset(), curTop = parseInt( jQuery.curCSS( elem, "top", true ), 10 ) || 0, - curLeft = parseInt( jQuery.curCSS( elem, "left", true ), 10) || 0, - props = { - top: (options.top - curOffset.top) + curTop, - left: (options.left - curOffset.left) + curLeft - }; + curLeft = parseInt( jQuery.curCSS( elem, "left", true ), 10 ) || 0; + + if ( jQuery.isFunction( options ) ) { + options = options.call( elem, i, curOffset ); + } + + var props = { + top: (options.top - curOffset.top) + curTop, + left: (options.left - curOffset.left) + curLeft + }; if ( "using" in options ) { options.using.call( elem, props );