diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2013-09-09 12:13:41 -0400 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2013-09-09 13:54:46 -0500 |
commit | 99191a510ecb5584addc0391edd56d626067b28a (patch) | |
tree | dd74972f85d47ed898e15dd24dedd722fac47440 /src/offset.js | |
parent | cd4a9cd7fa7093df92e64d5da9f18742254a8ca7 (diff) | |
download | jquery-99191a510ecb5584addc0391edd56d626067b28a.tar.gz jquery-99191a510ecb5584addc0391edd56d626067b28a.zip |
Apply consistent ordering in all modules. -38 bytes. Order modules like functions > jQuery.extend > jQuery.fn.extend.
Diffstat (limited to 'src/offset.js')
-rw-r--r-- | src/offset.js | 87 |
1 files changed, 42 insertions, 45 deletions
diff --git a/src/offset.js b/src/offset.js index f7d5575fe..fc63be731 100644 --- a/src/offset.js +++ b/src/offset.js @@ -8,45 +8,14 @@ define([ var docElem = window.document.documentElement; -jQuery.fn.offset = function( options ) { - if ( arguments.length ) { - return options === undefined ? - this : - this.each(function( i ) { - jQuery.offset.setOffset( this, options, i ); - }); - } - - var docElem, win, - elem = this[ 0 ], - box = { top: 0, left: 0 }, - doc = elem && elem.ownerDocument; - - if ( !doc ) { - return; - } - - docElem = doc.documentElement; - - // Make sure it's not a disconnected DOM node - if ( !jQuery.contains( docElem, elem ) ) { - return box; - } - - // If we don't have gBCR, just use 0,0 rather than error - // BlackBerry 5, iOS 3 (original iPhone) - if ( typeof elem.getBoundingClientRect !== strundefined ) { - box = elem.getBoundingClientRect(); - } - win = getWindow( doc ); - return { - top: box.top + win.pageYOffset - docElem.clientTop, - left: box.left + win.pageXOffset - docElem.clientLeft - }; -}; +/** + * Gets a window from an element + */ +function getWindow( elem ) { + return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView; +} jQuery.offset = { - setOffset: function( elem, options, i ) { var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition, position = jQuery.css( elem, "position" ), @@ -95,8 +64,43 @@ jQuery.offset = { } }; - jQuery.fn.extend({ + offset: function( options ) { + if ( arguments.length ) { + return options === undefined ? + this : + this.each(function( i ) { + jQuery.offset.setOffset( this, options, i ); + }); + } + + var docElem, win, + elem = this[ 0 ], + box = { top: 0, left: 0 }, + doc = elem && elem.ownerDocument; + + if ( !doc ) { + return; + } + + docElem = doc.documentElement; + + // Make sure it's not a disconnected DOM node + if ( !jQuery.contains( docElem, elem ) ) { + return box; + } + + // If we don't have gBCR, just use 0,0 rather than error + // BlackBerry 5, iOS 3 (original iPhone) + if ( typeof elem.getBoundingClientRect !== strundefined ) { + box = elem.getBoundingClientRect(); + } + win = getWindow( doc ); + return { + top: box.top + win.pageYOffset - docElem.clientTop, + left: box.left + win.pageXOffset - docElem.clientLeft + }; + }, position: function() { if ( !this[ 0 ] ) { @@ -147,13 +151,6 @@ jQuery.fn.extend({ } }); -/** - * Gets a window from an element - */ -function getWindow( elem ) { - return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView; -} - // Create scrollLeft and scrollTop methods jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( method, prop ) { var top = "pageYOffset" === prop; |