Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove old offset code

  • Loading branch information...
commit 4b0e240daeef6376baae3be69b9c61e4d40fda13 1 parent 41056ab
@mikesherov authored
Showing with 14 additions and 103 deletions.
  1. +10 −52 src/offset.js
  2. +4 −27 src/support.js
  3. +0 −24 test/unit/support.js
View
62 src/offset.js
@@ -1,18 +1,20 @@
(function( jQuery ) {
var getOffset,
- rtable = /^t(?:able|d|h)$/i,
- rroot = /^(?:body|html)$/i;
+ rroot = /^(?:body|html)$/i,
+ noOffset = { top: 0, left: 0 };
if ( "getBoundingClientRect" in document.documentElement ) {
- getOffset = function( elem, doc, docElem, box ) {
+ getOffset = function( elem, doc, docElem ) {
+ var box;
+
try {
box = elem.getBoundingClientRect();
} catch(e) {}
// Make sure we're not dealing with a disconnected DOM node
if ( !box || !jQuery.contains( docElem, elem ) ) {
- return box ? { top: box.top, left: box.left } : { top: 0, left: 0 };
+ return box ? { top: box.top, left: box.left } : noOffset;
}
var body = doc.body,
@@ -29,56 +31,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 noOffset;
}
+ var point = window.webkitConvertPointFromNodeToPage( elem, new WebKitPoint(0, 0));
+ return { top: point.y, left: point.x };
- return { top: top, left: left };
};
}
View
31 src/support.js
@@ -178,9 +178,8 @@ jQuery.support = (function() {
// Run tests that need a body at doc ready
jQuery(function() {
- var container, outer, inner, table, td, offsetSupport,
- marginDiv, conMarginTop, style, html, positionTopLeftWidthHeight,
- paddingMarginBorderVisibility, paddingMarginBorder,
+ var container, offsetSupport,
+ conMarginTop = 1,
body = document.getElementsByTagName("body")[0];
if ( !body ) {
@@ -188,17 +187,8 @@ jQuery.support = (function() {
return;
}
- conMarginTop = 1;
- paddingMarginBorder = "padding:0;margin:0;border:";
- positionTopLeftWidthHeight = "position:absolute;top:0;left:0;width:1px;height:1px;";
- paddingMarginBorderVisibility = paddingMarginBorder + "0;visibility:hidden;";
- style = "style='" + positionTopLeftWidthHeight + paddingMarginBorder + "5px solid #000;";
- html = "<div " + style + "display:block;'><div style='" + paddingMarginBorder + "0;display:block;overflow:hidden;'></div></div>" +
- "<table " + style + "' cellpadding='0' cellspacing='0'>" +
- "<tr><td></td></tr></table>";
-
container = document.createElement("div");
- container.style.cssText = paddingMarginBorderVisibility + "width:0;height:0;position:static;top:0;margin-top:" + conMarginTop + "px";
+ container.style.cssText = "visibility:hidden;border:0;width:0;height:0;position:static;top:0;margin-top:" + conMarginTop + "px";
body.insertBefore( container, body.firstChild );
// Construct the test element
@@ -260,23 +250,10 @@ jQuery.support = (function() {
support.shrinkWrapBlocks = ( div.offsetWidth !== 3 );
}
- div.style.cssText = positionTopLeftWidthHeight + paddingMarginBorderVisibility;
- div.innerHTML = html;
-
- outer = div.firstChild;
- inner = outer.firstChild;
- td = outer.nextSibling.firstChild.firstChild;
-
offsetSupport = {
- doesNotAddBorder: ( inner.offsetTop !== 5 ),
- doesAddBorderForTableAndCells: ( td.offsetTop === 5 )
+ doesNotIncludeMarginInBodyOffset: ( body.offsetTop !== conMarginTop )
};
- inner.style.position = "fixed";
- inner.style.top = "20px";
-
- // safari subtracts parent border width here which is 5px
- offsetSupport.fixedPosition = ( inner.offsetTop === 20 || inner.offsetTop === 15 );
inner.style.position = inner.style.top = "";
outer.style.overflow = "hidden";
View
24 test/unit/support.js
@@ -98,10 +98,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
- "doesNotAddBorder":true,
- "doesAddBorderForTableAndCells":false,
- "fixedPosition":true,
- "subtractsBorderForOverflowNotVisible":false,
"doesNotIncludeMarginInBodyOffset":true
};
for ( i in expected ) {
@@ -141,10 +137,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets":false,
"ajax":true,
"cors":false,
- "doesNotAddBorder":false,
- "doesAddBorderForTableAndCells":true,
- "fixedPosition":true,
- "subtractsBorderForOverflowNotVisible":false,
"doesNotIncludeMarginInBodyOffset":true
};
for ( i in expected ) {
@@ -164,11 +156,8 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"cors": false,
"cssFloat": false,
"deleteExpando": false,
- "doesAddBorderForTableAndCells": true,
- "doesNotAddBorder": true,
"doesNotIncludeMarginInBodyOffset": true,
"enctype": true,
- "fixedPosition": true,
"focusinBubbles": true,
"getSetAttribute": false,
"hrefNormalized": false,
@@ -186,7 +175,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableMarginRight": true,
"shrinkWrapBlocks": false,
"submitBubbles": false,
- "subtractsBorderForOverflowNotVisible": false,
"tbody": false,
"style": false
};
@@ -227,10 +215,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets":false,
"ajax":true,
"cors":false,
- "doesNotAddBorder":true,
- "doesAddBorderForTableAndCells":true,
- "fixedPosition":false,
- "subtractsBorderForOverflowNotVisible":false,
"doesNotIncludeMarginInBodyOffset":true
};
for ( i in expected ) {
@@ -270,10 +254,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
- "doesNotAddBorder":true,
- "doesAddBorderForTableAndCells":false,
- "fixedPosition":true,
- "subtractsBorderForOverflowNotVisible":false,
"doesNotIncludeMarginInBodyOffset":true
};
for ( i in expected ) {
@@ -313,10 +293,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
- "doesNotAddBorder":true,
- "doesAddBorderForTableAndCells":true,
- "fixedPosition":true,
- "subtractsBorderForOverflowNotVisible":false,
"doesNotIncludeMarginInBodyOffset":true
};
for ( i in expected ) {
Please sign in to comment.
Something went wrong with that request. Please try again.