aboutsummaryrefslogtreecommitdiffstats
path: root/src/offset.js
diff options
context:
space:
mode:
authorDaniel Gálvez <dgalvez@editablething.com>2012-08-19 21:53:09 +0200
committerDave Methvin <dave.methvin@gmail.com>2012-10-24 23:35:15 -0400
commitb398a68333d5eb9859fabb1ceabe84a1a753760a (patch)
tree22e52195cc6e2c902fc4e1eee3cbbbae182f50af /src/offset.js
parent69e2f068fe7d16c1ccd6cb99c6376f0d8891ea33 (diff)
downloadjquery-b398a68333d5eb9859fabb1ceabe84a1a753760a.tar.gz
jquery-b398a68333d5eb9859fabb1ceabe84a1a753760a.zip
Fix #11542. document.body should not be special in .offset() and document.documentElement is the default element.offsetParent. Close gh-899.
Diffstat (limited to 'src/offset.js')
-rw-r--r--src/offset.js36
1 files changed, 7 insertions, 29 deletions
diff --git a/src/offset.js b/src/offset.js
index 385d8c743..93446eae4 100644
--- a/src/offset.js
+++ b/src/offset.js
@@ -1,5 +1,3 @@
-var rroot = /^(?:body|html)$/i;
-
jQuery.fn.offset = function( options ) {
if ( arguments.length ) {
return options === undefined ?
@@ -9,7 +7,7 @@ jQuery.fn.offset = function( options ) {
});
}
- var docElem, body, win, clientTop, clientLeft, scrollTop, scrollLeft,
+ var docElem, win,
box = { top: 0, left: 0 },
elem = this[ 0 ],
doc = elem && elem.ownerDocument;
@@ -18,10 +16,6 @@ jQuery.fn.offset = function( options ) {
return;
}
- if ( (body = doc.body) === elem ) {
- return jQuery.offset.bodyOffset( elem );
- }
-
docElem = doc.documentElement;
// Make sure it's not a disconnected DOM node
@@ -35,30 +29,14 @@ jQuery.fn.offset = function( options ) {
box = elem.getBoundingClientRect();
}
win = getWindow( doc );
- clientTop = docElem.clientTop || body.clientTop || 0;
- clientLeft = docElem.clientLeft || body.clientLeft || 0;
- scrollTop = win.pageYOffset || docElem.scrollTop;
- scrollLeft = win.pageXOffset || docElem.scrollLeft;
return {
- top: box.top + scrollTop - clientTop,
- left: box.left + scrollLeft - clientLeft
+ top: box.top + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ),
+ left: box.left + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 )
};
};
jQuery.offset = {
- bodyOffset: function( body ) {
- var top = body.offsetTop,
- left = body.offsetLeft;
-
- if ( jQuery.support.doesNotIncludeMarginInBodyOffset ) {
- top += parseFloat( jQuery.css(body, "marginTop") ) || 0;
- left += parseFloat( jQuery.css(body, "marginLeft") ) || 0;
- }
-
- return { top: top, left: left };
- },
-
setOffset: function( elem, options, i ) {
var position = jQuery.css( elem, "position" );
@@ -125,7 +103,7 @@ jQuery.fn.extend({
// Get correct offsets
offset = this.offset();
- if ( !rroot.test( offsetParent[ 0 ].nodeName ) ) {
+ if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
parentOffset = offsetParent.offset();
}
@@ -145,11 +123,11 @@ jQuery.fn.extend({
offsetParent: function() {
return this.map(function() {
- var offsetParent = this.offsetParent || document.body;
- while ( offsetParent && (!rroot.test(offsetParent.nodeName) && jQuery.css(offsetParent, "position") === "static") ) {
+ var offsetParent = this.offsetParent || document.documentElement;
+ while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position") === "static" ) ) {
offsetParent = offsetParent.offsetParent;
}
- return offsetParent || document.body;
+ return offsetParent || document.documentElement;
});
}
});