aboutsummaryrefslogtreecommitdiffstats
path: root/src/offset.js
diff options
context:
space:
mode:
authorMike Sherov <mike.sherov@gmail.com>2012-04-05 21:51:27 -0400
committerDave Methvin <dave.methvin@gmail.com>2012-04-05 21:55:28 -0400
commit77536f5cb2ab042ac8be40ba59f36d8f3bd7e4d1 (patch)
tree1085e8ca438ac0dde625080c9b202eee8b6822a6 /src/offset.js
parent91a6d9dafc402e78b76d1ea41d70480b42dfde60 (diff)
downloadjquery-77536f5cb2ab042ac8be40ba59f36d8f3bd7e4d1.tar.gz
jquery-77536f5cb2ab042ac8be40ba59f36d8f3bd7e4d1.zip
Fix #10996, simplify offset code by forsaking ancient browsers.
Diffstat (limited to 'src/offset.js')
-rw-r--r--src/offset.js57
1 files changed, 7 insertions, 50 deletions
diff --git a/src/offset.js b/src/offset.js
index 6433a5b7a..69c4d72ad 100644
--- a/src/offset.js
+++ b/src/offset.js
@@ -1,11 +1,12 @@
(function( jQuery ) {
var getOffset,
- rtable = /^t(?:able|d|h)$/i,
rroot = /^(?:body|html)$/i;
if ( "getBoundingClientRect" in document.documentElement ) {
- getOffset = function( elem, doc, docElem, box ) {
+ getOffset = function( elem, doc, docElem ) {
+ var box;
+
try {
box = elem.getBoundingClientRect();
} catch(e) {}
@@ -29,56 +30,12 @@ if ( "getBoundingClientRect" in document.documentElement ) {
} else {
getOffset = function( elem, doc, docElem ) {
- var computedStyle,
- offsetParent = elem.offsetParent,
- prevOffsetParent = elem,
- body = doc.body,
- defaultView = doc.defaultView,
- prevComputedStyle = defaultView ? defaultView.getComputedStyle( elem, null ) : elem.currentStyle,
- top = elem.offsetTop,
- left = elem.offsetLeft;
-
- while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) {
- if ( jQuery.support.fixedPosition && prevComputedStyle.position === "fixed" ) {
- break;
- }
-
- computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle;
- top -= elem.scrollTop;
- left -= elem.scrollLeft;
-
- if ( elem === offsetParent ) {
- top += elem.offsetTop;
- left += elem.offsetLeft;
-
- if ( jQuery.support.doesNotAddBorder && !(jQuery.support.doesAddBorderForTableAndCells && rtable.test(elem.nodeName)) ) {
- top += parseFloat( computedStyle.borderTopWidth ) || 0;
- left += parseFloat( computedStyle.borderLeftWidth ) || 0;
- }
-
- prevOffsetParent = offsetParent;
- offsetParent = elem.offsetParent;
- }
-
- if ( jQuery.support.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) {
- top += parseFloat( computedStyle.borderTopWidth ) || 0;
- left += parseFloat( computedStyle.borderLeftWidth ) || 0;
- }
-
- prevComputedStyle = computedStyle;
- }
-
- if ( prevComputedStyle.position === "relative" || prevComputedStyle.position === "static" ) {
- top += body.offsetTop;
- left += body.offsetLeft;
- }
-
- if ( jQuery.support.fixedPosition && prevComputedStyle.position === "fixed" ) {
- top += Math.max( docElem.scrollTop, body.scrollTop );
- left += Math.max( docElem.scrollLeft, body.scrollLeft );
+ if ( !jQuery.contains( docElem, elem ) ) {
+ return { top: 0, left: 0 };
}
+ var point = getWindow( doc ).webkitConvertPointFromNodeToPage( elem, new WebKitPoint( 0, 0 ) );
+ return { top: point.y, left: point.x };
- return { top: top, left: left };
};
}