Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'libs/bower_components/jquery/src/offset.js')
-rw-r--r--libs/bower_components/jquery/src/offset.js119
1 files changed, 63 insertions, 56 deletions
diff --git a/libs/bower_components/jquery/src/offset.js b/libs/bower_components/jquery/src/offset.js
index 42d07eb4f5..08a4543e43 100644
--- a/libs/bower_components/jquery/src/offset.js
+++ b/libs/bower_components/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,22 +11,13 @@ define([
"./core/init",
"./css",
"./selector" // contains
-], function( jQuery, strundefined, access, rnumnonpx, curCSS, addGetHookIf, support ) {
-
-// BuildExclude
-curCSS = curCSS.curCSS;
-
-var docElem = window.document.documentElement;
+], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support ) {
/**
* Gets a window from an element
*/
function getWindow( elem ) {
- return jQuery.isWindow( elem ) ?
- elem :
- elem.nodeType === 9 ?
- elem.defaultView || elem.parentWindow :
- false;
+ return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
}
jQuery.offset = {
@@ -35,7 +27,7 @@ jQuery.offset = {
curElem = jQuery( elem ),
props = {};
- // set position first, in-case top/left are set even on static elem
+ // Set position first, in-case top/left are set even on static elem
if ( position === "static" ) {
elem.style.position = "relative";
}
@@ -44,20 +36,24 @@ jQuery.offset = {
curCSSTop = jQuery.css( elem, "top" );
curCSSLeft = jQuery.css( elem, "left" );
calculatePosition = ( position === "absolute" || position === "fixed" ) &&
- jQuery.inArray("auto", [ curCSSTop, curCSSLeft ] ) > -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
+ // Need to be able to calculate position if either
+ // top or left is auto and position is either absolute or fixed
if ( calculatePosition ) {
curPosition = curElem.position();
curTop = curPosition.top;
curLeft = curPosition.left;
+
} else {
curTop = parseFloat( curCSSTop ) || 0;
curLeft = parseFloat( curCSSLeft ) || 0;
}
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 ) {
@@ -69,25 +65,26 @@ jQuery.offset = {
if ( "using" in options ) {
options.using.call( elem, props );
+
} else {
curElem.css( props );
}
}
};
-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,
- box = { top: 0, left: 0 },
elem = this[ 0 ],
+ box = { top: 0, left: 0 },
doc = elem && elem.ownerDocument;
if ( !doc ) {
@@ -101,15 +98,11 @@ jQuery.fn.extend({
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();
- }
+ box = elem.getBoundingClientRect();
win = getWindow( doc );
return {
- top: box.top + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ),
- left: box.left + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 )
+ top: box.top + win.pageYOffset - docElem.clientTop,
+ left: box.left + win.pageXOffset - docElem.clientLeft
};
},
@@ -119,14 +112,18 @@ jQuery.fn.extend({
}
var offsetParent, offset,
- parentOffset = { top: 0, left: 0 },
- elem = this[ 0 ];
+ 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" ) {
- // we assume that getBoundingClientRect is available when computed position is fixed
+
+ // Assume getBoundingClientRect is there when computed position is fixed
offset = elem.getBoundingClientRect();
+
} else {
+
// Get *real* offsetParent
offsetParent = this.offsetParent();
@@ -137,75 +134,85 @@ jQuery.fn.extend({
}
// Add offsetParent borders
- parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
+ parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
}
// Subtract parent offsets and element margins
- // note: when an element has margin: auto the offsetLeft and marginLeft
- // are the same in Safari causing offset.left to incorrectly be 0
return {
- top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
- left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true)
+ top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
+ left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
};
},
+ // 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 ) {
- var top = /Y/.test( prop );
+ var top = "pageYOffset" === prop;
jQuery.fn[ method ] = function( val ) {
return access( this, function( elem, method, val ) {
var win = getWindow( elem );
if ( val === undefined ) {
- return win ? (prop in win) ? win[ prop ] :
- win.document.documentElement[ method ] :
- elem[ method ];
+ return win ? win[ prop ] : elem[ method ];
}
if ( win ) {
win.scrollTo(
- !top ? val : jQuery( win ).scrollLeft(),
- top ? val : jQuery( win ).scrollTop()
+ !top ? val : win.pageXOffset,
+ top ? val : win.pageYOffset
);
} else {
elem[ method ] = val;
}
- }, method, val, arguments.length, null );
+ }, method, val, arguments.length );
};
-});
+} );
+// 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
-// getComputedStyle returns percent when specified for top/left/bottom/right
-// rather than make the css module depend on the offset module, we just check for it here
+// Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
+// getComputedStyle returns percent when specified for top/left/bottom/right;
+// rather than make the css module depend on the offset module, just check for it here
jQuery.each( [ "top", "left" ], function( i, prop ) {
jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
function( elem, computed ) {
if ( computed ) {
computed = curCSS( elem, prop );
- // if curCSS returns percentage, fallback to offset
+
+ // If curCSS returns percentage, fallback to offset
return rnumnonpx.test( computed ) ?
jQuery( elem ).position()[ prop ] + "px" :
computed;
}
}
);
-});
+} );
return jQuery;
-});
+} );