2015-08-16 06:59:58 +00:00
|
|
|
define( [
|
2013-10-15 14:40:48 +00:00
|
|
|
"./core",
|
|
|
|
"./core/access",
|
2014-09-11 20:18:34 +00:00
|
|
|
"./var/documentElement",
|
2017-06-23 04:14:43 +00:00
|
|
|
"./var/isWindow",
|
2013-10-15 14:40:48 +00:00
|
|
|
"./core/init",
|
|
|
|
"./css",
|
|
|
|
"./selector" // contains
|
2019-05-13 20:25:11 +00:00
|
|
|
], function( jQuery, access, documentElement, isWindow ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
|
2016-04-25 18:25:08 +00:00
|
|
|
"use strict";
|
|
|
|
|
2011-10-31 16:33:55 +00:00
|
|
|
jQuery.offset = {
|
2010-01-07 19:08:32 +00:00
|
|
|
setOffset: function( elem, options, i ) {
|
2013-01-15 21:54:40 +00:00
|
|
|
var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
|
|
|
|
position = jQuery.css( elem, "position" ),
|
|
|
|
curElem = jQuery( elem ),
|
|
|
|
props = {};
|
2010-03-23 00:11:37 +00:00
|
|
|
|
2013-01-15 21:54:40 +00:00
|
|
|
// Set position first, in-case top/left are set even on static elem
|
2010-03-23 00:11:37 +00:00
|
|
|
if ( position === "static" ) {
|
2009-12-22 01:13:16 +00:00
|
|
|
elem.style.position = "relative";
|
2009-09-15 19:15:04 +00:00
|
|
|
}
|
2010-03-23 00:11:37 +00:00
|
|
|
|
2015-06-15 15:02:08 +00:00
|
|
|
curOffset = curElem.offset();
|
2013-01-15 21:54:40 +00:00
|
|
|
curCSSTop = jQuery.css( elem, "top" );
|
|
|
|
curCSSLeft = jQuery.css( elem, "left" );
|
2013-09-06 18:31:18 +00:00
|
|
|
calculatePosition = ( position === "absolute" || position === "fixed" ) &&
|
2015-08-16 06:59:58 +00:00
|
|
|
( curCSSTop + curCSSLeft ).indexOf( "auto" ) > -1;
|
2010-03-23 00:11:37 +00:00
|
|
|
|
2014-04-25 22:26:36 +00:00
|
|
|
// Need to be able to calculate position if either
|
|
|
|
// top or left is auto and position is either absolute or fixed
|
2010-03-23 00:11:37 +00:00
|
|
|
if ( calculatePosition ) {
|
|
|
|
curPosition = curElem.position();
|
2011-01-15 12:56:20 +00:00
|
|
|
curTop = curPosition.top;
|
|
|
|
curLeft = curPosition.left;
|
2013-01-15 21:54:40 +00:00
|
|
|
|
2011-01-15 12:56:20 +00:00
|
|
|
} else {
|
|
|
|
curTop = parseFloat( curCSSTop ) || 0;
|
|
|
|
curLeft = parseFloat( curCSSLeft ) || 0;
|
2010-03-23 00:11:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 20:56:09 +00:00
|
|
|
if ( typeof options === "function" ) {
|
2014-11-11 13:27:44 +00:00
|
|
|
|
|
|
|
// Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
|
|
|
|
options = options.call( elem, i, jQuery.extend( {}, curOffset ) );
|
2010-01-07 19:07:21 +00:00
|
|
|
}
|
|
|
|
|
2011-10-27 19:33:21 +00:00
|
|
|
if ( options.top != null ) {
|
|
|
|
props.top = ( options.top - curOffset.top ) + curTop;
|
2010-03-23 00:05:08 +00:00
|
|
|
}
|
2011-10-27 19:33:21 +00:00
|
|
|
if ( options.left != null ) {
|
|
|
|
props.left = ( options.left - curOffset.left ) + curLeft;
|
2010-03-23 00:05:08 +00:00
|
|
|
}
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-22 01:13:16 +00:00
|
|
|
if ( "using" in options ) {
|
2009-09-15 19:15:04 +00:00
|
|
|
options.using.call( elem, props );
|
2013-01-15 21:54:40 +00:00
|
|
|
|
2009-09-15 19:15:04 +00:00
|
|
|
} else {
|
|
|
|
curElem.css( props );
|
|
|
|
}
|
2008-11-10 02:39:03 +00:00
|
|
|
}
|
2011-10-31 16:33:55 +00:00
|
|
|
};
|
2008-03-15 18:53:40 +00:00
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
jQuery.fn.extend( {
|
2017-04-24 16:15:39 +00:00
|
|
|
|
|
|
|
// offset() relates an element's border box to the document origin
|
2013-09-09 16:13:41 +00:00
|
|
|
offset: function( options ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2015-05-05 15:31:39 +00:00
|
|
|
// Preserve chaining for setter
|
2013-09-09 16:13:41 +00:00
|
|
|
if ( arguments.length ) {
|
|
|
|
return options === undefined ?
|
|
|
|
this :
|
2015-08-16 06:59:58 +00:00
|
|
|
this.each( function( i ) {
|
2013-09-09 16:13:41 +00:00
|
|
|
jQuery.offset.setOffset( this, options, i );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-09-09 16:13:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 16:15:39 +00:00
|
|
|
var rect, win,
|
2015-05-05 15:31:39 +00:00
|
|
|
elem = this[ 0 ];
|
2013-09-09 16:13:41 +00:00
|
|
|
|
2015-05-05 15:31:39 +00:00
|
|
|
if ( !elem ) {
|
2013-09-09 16:13:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-13 06:32:11 +00:00
|
|
|
// Return zeros for disconnected and hidden (display: none) elements (gh-2310)
|
2019-04-29 20:56:09 +00:00
|
|
|
// Support: IE <=11+
|
2015-06-16 15:21:58 +00:00
|
|
|
// Running getBoundingClientRect on a
|
|
|
|
// disconnected node in IE throws an error
|
|
|
|
if ( !elem.getClientRects().length ) {
|
|
|
|
return { top: 0, left: 0 };
|
|
|
|
}
|
|
|
|
|
2017-04-24 16:15:39 +00:00
|
|
|
// Get document-relative position by adding viewport scroll to viewport-relative gBCR
|
2015-05-05 15:16:29 +00:00
|
|
|
rect = elem.getBoundingClientRect();
|
2017-04-24 16:15:39 +00:00
|
|
|
win = elem.ownerDocument.defaultView;
|
2016-12-13 06:32:11 +00:00
|
|
|
return {
|
2017-04-24 16:15:39 +00:00
|
|
|
top: rect.top + win.pageYOffset,
|
|
|
|
left: rect.left + win.pageXOffset
|
2016-12-13 06:32:11 +00:00
|
|
|
};
|
2013-09-09 16:13:41 +00:00
|
|
|
},
|
2011-09-20 01:03:41 +00:00
|
|
|
|
2017-04-24 16:15:39 +00:00
|
|
|
// position() relates an element's margin box to its offset parent's padding box
|
|
|
|
// This corresponds to the behavior of CSS absolute positioning
|
2008-04-29 03:26:06 +00:00
|
|
|
position: function() {
|
2012-10-17 17:40:52 +00:00
|
|
|
if ( !this[ 0 ] ) {
|
2012-07-10 03:06:51 +00:00
|
|
|
return;
|
2009-12-22 00:58:13 +00:00
|
|
|
}
|
2009-03-17 20:50:17 +00:00
|
|
|
|
2017-04-24 16:15:39 +00:00
|
|
|
var offsetParent, offset, doc,
|
2013-01-15 21:54:40 +00:00
|
|
|
elem = this[ 0 ],
|
|
|
|
parentOffset = { top: 0, left: 0 };
|
2009-03-17 20:50:17 +00:00
|
|
|
|
2017-04-24 16:15:39 +00:00
|
|
|
// position:fixed elements are offset from the viewport, which itself always has zero offset
|
2012-10-17 17:40:52 +00:00
|
|
|
if ( jQuery.css( elem, "position" ) === "fixed" ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2017-04-24 16:15:39 +00:00
|
|
|
// Assume position:fixed implies availability of getBoundingClientRect
|
2012-10-17 17:40:52 +00:00
|
|
|
offset = elem.getBoundingClientRect();
|
2013-01-15 21:54:40 +00:00
|
|
|
|
2012-10-17 17:40:52 +00:00
|
|
|
} else {
|
2017-04-24 16:15:39 +00:00
|
|
|
offset = this.offset();
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2017-04-24 16:15:39 +00:00
|
|
|
// Account for the *real* offset parent, which can be the document or its root element
|
|
|
|
// when a statically positioned element is identified
|
|
|
|
doc = elem.ownerDocument;
|
|
|
|
offsetParent = elem.offsetParent || doc.documentElement;
|
|
|
|
while ( offsetParent &&
|
|
|
|
( offsetParent === doc.body || offsetParent === doc.documentElement ) &&
|
|
|
|
jQuery.css( offsetParent, "position" ) === "static" ) {
|
2012-10-17 17:40:52 +00:00
|
|
|
|
2017-04-24 16:15:39 +00:00
|
|
|
offsetParent = offsetParent.parentNode;
|
|
|
|
}
|
|
|
|
if ( offsetParent && offsetParent !== elem && offsetParent.nodeType === 1 ) {
|
|
|
|
|
|
|
|
// Incorporate borders into its offset, since they are outside its content origin
|
|
|
|
parentOffset = jQuery( offsetParent ).offset();
|
2017-07-10 16:12:49 +00:00
|
|
|
parentOffset.top += jQuery.css( offsetParent, "borderTopWidth", true );
|
|
|
|
parentOffset.left += jQuery.css( offsetParent, "borderLeftWidth", true );
|
2012-10-17 17:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-17 20:50:17 +00:00
|
|
|
|
2012-10-17 17:40:52 +00:00
|
|
|
// Subtract parent offsets and element margins
|
2009-04-21 19:19:28 +00:00
|
|
|
return {
|
2013-01-15 21:54:40 +00:00
|
|
|
top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
|
|
|
|
left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
|
2009-03-17 20:50:17 +00:00
|
|
|
};
|
2008-04-29 03:26:06 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2015-01-13 05:12:14 +00:00
|
|
|
// 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
|
2008-04-29 03:26:06 +00:00
|
|
|
offsetParent: function() {
|
2015-08-16 06:59:58 +00:00
|
|
|
return this.map( function() {
|
2015-01-13 05:12:14 +00:00
|
|
|
var offsetParent = this.offsetParent;
|
2013-01-15 21:54:40 +00:00
|
|
|
|
2015-01-13 05:12:14 +00:00
|
|
|
while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) {
|
2009-07-25 16:04:30 +00:00
|
|
|
offsetParent = offsetParent.offsetParent;
|
|
|
|
}
|
2013-01-15 21:54:40 +00:00
|
|
|
|
2014-09-11 20:18:34 +00:00
|
|
|
return offsetParent || documentElement;
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2008-04-29 03:26:06 +00:00
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2008-03-15 18:53:40 +00:00
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
// Create scrollLeft and scrollTop methods
|
2013-09-11 01:08:01 +00:00
|
|
|
jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
|
2013-01-15 21:54:40 +00:00
|
|
|
var top = "pageYOffset" === prop;
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2011-01-18 17:40:07 +00:00
|
|
|
jQuery.fn[ method ] = function( val ) {
|
2013-09-09 15:26:21 +00:00
|
|
|
return access( this, function( elem, method, val ) {
|
2016-12-19 17:00:46 +00:00
|
|
|
|
|
|
|
// Coalesce documents and windows
|
|
|
|
var win;
|
2017-06-23 04:14:43 +00:00
|
|
|
if ( isWindow( elem ) ) {
|
2016-12-19 17:00:46 +00:00
|
|
|
win = elem;
|
|
|
|
} else if ( elem.nodeType === 9 ) {
|
|
|
|
win = elem.defaultView;
|
|
|
|
}
|
2011-12-06 20:25:38 +00:00
|
|
|
|
|
|
|
if ( val === undefined ) {
|
2013-01-15 21:54:40 +00:00
|
|
|
return win ? win[ prop ] : elem[ method ];
|
2011-01-10 01:51:20 +00:00
|
|
|
}
|
2009-12-22 00:58:13 +00:00
|
|
|
|
2011-01-10 01:51:20 +00:00
|
|
|
if ( win ) {
|
|
|
|
win.scrollTo(
|
2014-12-21 02:52:17 +00:00
|
|
|
!top ? val : win.pageXOffset,
|
|
|
|
top ? val : win.pageYOffset
|
2011-01-10 01:51:20 +00:00
|
|
|
);
|
2011-04-12 20:13:56 +00:00
|
|
|
|
2011-01-10 01:51:20 +00:00
|
|
|
} else {
|
2011-12-06 20:25:38 +00:00
|
|
|
elem[ method ] = val;
|
2011-01-10 01:51:20 +00:00
|
|
|
}
|
2015-11-09 23:14:59 +00:00
|
|
|
}, method, val, arguments.length );
|
2008-04-29 03:26:06 +00:00
|
|
|
};
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2009-07-24 22:32:53 +00:00
|
|
|
|
2013-09-09 01:25:27 +00:00
|
|
|
return jQuery;
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|