diff options
Diffstat (limited to 'js/vendor/jquery/src/offset.js')
-rw-r--r-- | js/vendor/jquery/src/offset.js | 76 |
1 files changed, 45 insertions, 31 deletions
diff --git a/js/vendor/jquery/src/offset.js b/js/vendor/jquery/src/offset.js index 4c34fd0ef..4352a9995 100644 --- a/js/vendor/jquery/src/offset.js +++ b/js/vendor/jquery/src/offset.js @@ -1,7 +1,8 @@ -define([ +define( [ "./core", - "./var/strundefined", "./core/access", + "./var/document", + "./var/documentElement", "./css/var/rnumnonpx", "./css/curCSS", "./css/addGetHookIf", @@ -10,9 +11,7 @@ define([ "./core/init", "./css", "./selector" // contains -], function( jQuery, strundefined, access, rnumnonpx, curCSS, addGetHookIf, support ) { - -var docElem = window.document.documentElement; +], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support ) { /** * Gets a window from an element @@ -37,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 @@ -52,7 +51,9 @@ jQuery.offset = { } if ( jQuery.isFunction( options ) ) { - options = options.call( elem, i, curOffset ); + + // Use jQuery.extend here to allow modification of coordinates argument (gh-1848) + options = options.call( elem, i, jQuery.extend( {}, curOffset ) ); } if ( options.top != null ) { @@ -71,14 +72,14 @@ jQuery.offset = { } }; -jQuery.fn.extend({ +jQuery.fn.extend( { offset: function( options ) { if ( arguments.length ) { return options === undefined ? this : - this.each(function( i ) { + this.each( function( i ) { jQuery.offset.setOffset( this, options, i ); - }); + } ); } var docElem, win, @@ -97,11 +98,7 @@ jQuery.fn.extend({ return box; } - // Support: BlackBerry 5, iOS 3 (original iPhone) - // If we don't have gBCR, just use 0,0 rather than error - if ( typeof elem.getBoundingClientRect !== strundefined ) { - box = elem.getBoundingClientRect(); - } + box = elem.getBoundingClientRect(); win = getWindow( doc ); return { top: box.top + win.pageYOffset - docElem.clientTop, @@ -118,12 +115,15 @@ jQuery.fn.extend({ elem = this[ 0 ], parentOffset = { top: 0, left: 0 }; - // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent + // 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(); @@ -134,8 +134,11 @@ jQuery.fn.extend({ } // Add offsetParent borders - parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true ); - parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true ); + // Subtract offsetParent scroll positions + parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true ) - + offsetParent.scrollTop(); + parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true ) - + offsetParent.scrollLeft(); } // Subtract parent offsets and element margins @@ -145,18 +148,28 @@ jQuery.fn.extend({ }; }, + // This method will return documentElement in the following cases: + // 1) For the element inside the iframe without offsetParent, this method will return + // documentElement of the parent window + // 2) For the hidden or detached element + // 3) For body or html element, i.e. in case of the html node - it will return itself + // + // but those exceptions were never presented as a real life use-cases + // and might be considered as more preferable results. + // + // This logic, however, is not guaranteed and can change at any point in the future offsetParent: function() { - return this.map(function() { - var offsetParent = this.offsetParent || docElem; + return this.map( function() { + var offsetParent = this.offsetParent; - while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) { + while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) { offsetParent = offsetParent.offsetParent; } - return offsetParent || docElem; - }); + return offsetParent || documentElement; + } ); } -}); +} ); // Create scrollLeft and scrollTop methods jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) { @@ -172,18 +185,18 @@ jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( if ( win ) { win.scrollTo( - !top ? val : window.pageXOffset, - top ? val : window.pageYOffset + !top ? val : win.pageXOffset, + top ? val : win.pageYOffset ); } else { elem[ method ] = val; } - }, method, val, arguments.length, null ); + }, method, val, arguments.length ); }; -}); +} ); -// Support: Safari<7+, Chrome<37+ +// Support: Safari<7-8+, Chrome<37-44+ // Add the top/left cssHooks using jQuery.fn.position // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280 @@ -194,6 +207,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" : @@ -201,7 +215,7 @@ jQuery.each( [ "top", "left" ], function( i, prop ) { } } ); -}); +} ); return jQuery; -}); +} ); |