2011-12-06 20:25:38 +00:00
|
|
|
jQuery.fn.offset = function( options ) {
|
|
|
|
if ( arguments.length ) {
|
|
|
|
return options === undefined ?
|
|
|
|
this :
|
|
|
|
this.each(function( i ) {
|
|
|
|
jQuery.offset.setOffset( this, options, i );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-08-19 19:53:09 +00:00
|
|
|
var docElem, win,
|
2012-05-27 16:37:35 +00:00
|
|
|
elem = this[ 0 ],
|
2013-01-15 21:54:40 +00:00
|
|
|
box = { top: 0, left: 0 },
|
2011-12-06 20:25:38 +00:00
|
|
|
doc = elem && elem.ownerDocument;
|
|
|
|
|
|
|
|
if ( !doc ) {
|
2012-07-10 03:06:51 +00:00
|
|
|
return;
|
2011-12-06 20:25:38 +00:00
|
|
|
}
|
|
|
|
|
2012-05-27 16:37:35 +00:00
|
|
|
docElem = doc.documentElement;
|
|
|
|
|
2012-09-14 14:14:40 +00:00
|
|
|
// Make sure it's not a disconnected DOM node
|
|
|
|
if ( !jQuery.contains( docElem, elem ) ) {
|
|
|
|
return box;
|
2012-05-27 16:37:35 +00:00
|
|
|
}
|
|
|
|
|
2012-09-14 14:14:40 +00:00
|
|
|
// If we don't have gBCR, just use 0,0 rather than error
|
|
|
|
// BlackBerry 5, iOS 3 (original iPhone)
|
2013-01-24 04:25:29 +00:00
|
|
|
if ( typeof elem.getBoundingClientRect !== core_strundefined ) {
|
2012-09-14 14:14:40 +00:00
|
|
|
box = elem.getBoundingClientRect();
|
|
|
|
}
|
2012-05-27 16:37:35 +00:00
|
|
|
win = getWindow( doc );
|
2012-09-14 14:14:40 +00:00
|
|
|
return {
|
2013-01-15 21:54:40 +00:00
|
|
|
top: box.top + win.pageYOffset - docElem.clientTop,
|
|
|
|
left: box.left + win.pageXOffset - docElem.clientLeft
|
2012-09-14 14:14:40 +00:00
|
|
|
};
|
2011-12-06 20:25:38 +00:00
|
|
|
};
|
|
|
|
|
2011-10-31 16:33:55 +00:00
|
|
|
jQuery.offset = {
|
2008-11-10 02:39:03 +00:00
|
|
|
|
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
|
|
|
|
2013-01-15 21:54:40 +00:00
|
|
|
curOffset = curElem.offset();
|
|
|
|
curCSSTop = jQuery.css( elem, "top" );
|
|
|
|
curCSSLeft = jQuery.css( elem, "left" );
|
|
|
|
calculatePosition = ( position === "absolute" || position === "fixed" ) && ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
|
2010-03-23 00:11:37 +00:00
|
|
|
|
2013-01-15 21:54:40 +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
|
|
|
}
|
|
|
|
|
2010-01-07 19:07:21 +00:00
|
|
|
if ( jQuery.isFunction( options ) ) {
|
|
|
|
options = options.call( elem, i, curOffset );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
jQuery.fn.extend({
|
2011-09-20 01:03:41 +00:00
|
|
|
|
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
|
|
|
|
2012-10-17 17:40:52 +00:00
|
|
|
var offsetParent, offset,
|
2013-01-15 21:54:40 +00:00
|
|
|
elem = this[ 0 ],
|
|
|
|
parentOffset = { top: 0, left: 0 };
|
2009-03-17 20:50:17 +00:00
|
|
|
|
2013-01-15 21:54:40 +00:00
|
|
|
// Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is it's only offset parent
|
2012-10-17 17:40:52 +00:00
|
|
|
if ( jQuery.css( elem, "position" ) === "fixed" ) {
|
2013-01-15 21:54:40 +00:00
|
|
|
// We assume that getBoundingClientRect is available when computed position is fixed
|
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 {
|
|
|
|
// Get *real* offsetParent
|
|
|
|
offsetParent = this.offsetParent();
|
|
|
|
|
|
|
|
// Get correct offsets
|
|
|
|
offset = this.offset();
|
2012-08-19 19:53:09 +00:00
|
|
|
if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
|
2012-10-17 17:40:52 +00:00
|
|
|
parentOffset = offsetParent.offset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add offsetParent borders
|
2013-01-15 21:54:40 +00:00
|
|
|
parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
|
2012-12-10 23:25:23 +00:00
|
|
|
parentOffset.left += jQuery.css( offsetParent[ 0 ], "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
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
offsetParent: function() {
|
2009-12-22 00:58:13 +00:00
|
|
|
return this.map(function() {
|
2012-08-19 19:53:09 +00:00
|
|
|
var offsetParent = this.offsetParent || document.documentElement;
|
2013-01-15 21:54:40 +00:00
|
|
|
|
2012-08-19 19:53:09 +00:00
|
|
|
while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position") === "static" ) ) {
|
2009-07-25 16:04:30 +00:00
|
|
|
offsetParent = offsetParent.offsetParent;
|
|
|
|
}
|
2013-01-15 21:54:40 +00:00
|
|
|
|
2012-08-19 19:53:09 +00:00
|
|
|
return offsetParent || document.documentElement;
|
2009-07-25 16:04:30 +00:00
|
|
|
});
|
2008-04-29 03:26:06 +00:00
|
|
|
}
|
2008-03-15 18:53:40 +00:00
|
|
|
});
|
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
|
|
|
|
// Create scrollLeft and scrollTop methods
|
2011-12-06 20:25:38 +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 ) {
|
2011-12-06 20:25:38 +00:00
|
|
|
return jQuery.access( this, function( elem, method, val ) {
|
|
|
|
var win = getWindow( elem );
|
|
|
|
|
|
|
|
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(
|
2013-01-15 21:54:40 +00:00
|
|
|
!top ? val : window.pageXOffset,
|
|
|
|
top ? val : window.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
|
|
|
}
|
2011-12-06 20:25:38 +00:00
|
|
|
}, method, val, arguments.length, null );
|
2008-04-29 03:26:06 +00:00
|
|
|
};
|
2008-04-30 19:35:17 +00:00
|
|
|
});
|
2009-07-24 22:32:53 +00:00
|
|
|
|
|
|
|
function getWindow( elem ) {
|
2013-01-15 21:54:40 +00:00
|
|
|
return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
|
2009-07-24 22:32:53 +00:00
|
|
|
}
|