diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2015-08-16 09:59:58 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2015-09-07 20:03:50 +0300 |
commit | 10fdad742a2a6aa9f0e00b3e04fc5264797c53c7 (patch) | |
tree | 6b6d7b1375ff88f4bebbfa0703f7b595eb485df9 /src/offset.js | |
parent | 7aa46e0df8a673e6b00550bbbbed21eed50108b7 (diff) | |
download | jquery-10fdad742a2a6aa9f0e00b3e04fc5264797c53c7.tar.gz jquery-10fdad742a2a6aa9f0e00b3e04fc5264797c53c7.zip |
Build: Update jscs and lint files
Fixes gh-2056
Diffstat (limited to 'src/offset.js')
-rw-r--r-- | src/offset.js | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/offset.js b/src/offset.js index 23a4b2a18..bef2a8fa0 100644 --- a/src/offset.js +++ b/src/offset.js @@ -1,4 +1,4 @@ -define([ +define( [ "./core", "./core/access", "./var/document", @@ -36,7 +36,7 @@ jQuery.offset = { curCSSTop = jQuery.css( elem, "top" ); curCSSLeft = jQuery.css( elem, "left" ); calculatePosition = ( position === "absolute" || position === "fixed" ) && - ( curCSSTop + curCSSLeft ).indexOf("auto") > -1; + ( curCSSTop + curCSSLeft ).indexOf( "auto" ) > -1; // Need to be able to calculate position if either // top or left is auto and position is either absolute or fixed @@ -72,15 +72,16 @@ jQuery.offset = { } }; -jQuery.fn.extend({ +jQuery.fn.extend( { offset: function( options ) { + // Preserve chaining for setter if ( arguments.length ) { return options === undefined ? this : - this.each(function( i ) { + this.each( function( i ) { jQuery.offset.setOffset( this, options, i ); - }); + } ); } var docElem, win, rect, doc, @@ -127,10 +128,12 @@ jQuery.fn.extend({ // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, // because it is its only offset parent if ( jQuery.css( elem, "position" ) === "fixed" ) { + // Assume getBoundingClientRect is there when computed position is fixed offset = elem.getBoundingClientRect(); } else { + // Get *real* offsetParent offsetParent = this.offsetParent(); @@ -166,7 +169,7 @@ jQuery.fn.extend({ // // This logic, however, is not guaranteed and can change at any point in the future offsetParent: function() { - return this.map(function() { + return this.map( function() { var offsetParent = this.offsetParent; while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) { @@ -174,9 +177,9 @@ jQuery.fn.extend({ } return offsetParent || documentElement; - }); + } ); } -}); +} ); // Create scrollLeft and scrollTop methods jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) { @@ -201,7 +204,7 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( } }, method, val, arguments.length, null ); }; -}); +} ); // Support: Safari<7-8+, Chrome<37-44+ // Add the top/left cssHooks using jQuery.fn.position @@ -214,6 +217,7 @@ jQuery.each( [ "top", "left" ], function( i, prop ) { function( elem, computed ) { if ( computed ) { computed = curCSS( elem, prop ); + // If curCSS returns percentage, fallback to offset return rnumnonpx.test( computed ) ? jQuery( elem ).position()[ prop ] + "px" : @@ -221,7 +225,7 @@ jQuery.each( [ "top", "left" ], function( i, prop ) { } } ); -}); +} ); return jQuery; -}); +} ); |