Skip to content
Browse files

Fix a handful of test failures in IE.

  • Loading branch information...
1 parent 46b96b9 commit 8369133edc44035fea91c99a41d12884da1a95a1 @savetheclocktower savetheclocktower committed Mar 31, 2010
Showing with 22 additions and 8 deletions.
  1. +22 −8 src/dom/layout.js
View
30 src/dom/layout.js
@@ -21,7 +21,7 @@
if (value === null) {
return null;
}
-
+
// Non-IE browsers will always return pixels if possible.
// (We use parseFloat instead of parseInt because Firefox can return
// non-integer pixel values.)
@@ -38,7 +38,7 @@
value = element.style.pixelLeft;
element.style.left = style;
element.runtimeStyle.left = rStyle;
-
+
return value;
}
@@ -304,9 +304,9 @@
// (b) it has an explicitly-set width, instead of width: auto.
// Either way, it means the element is the width it needs to be
// in order to report an accurate height.
- newWidth = window.parseInt(width, 10);
+ newWidth = getPixelValue(width);
} else if (width && (position === 'absolute' || position === 'fixed')) {
- newWidth = window.parseInt(width, 10);
+ newWidth = getPixelValue(width);
} else {
// If not, that means the element's width depends upon the width of
// its parent.
@@ -716,7 +716,7 @@
* // -> 100
**/
function getDimensions(element) {
- var layout = $(element).getLayout();
+ var layout = $(element).getLayout();
return {
width: layout.get('width'),
height: layout.get('height')
@@ -730,7 +730,11 @@
* `body` element is returned.
**/
function getOffsetParent(element) {
- if (element.offsetParent) return $(element.offsetParent);
+ if (isDetached(element)) return $(document.body);
+
+ // IE reports offset parent incorrectly for inline elements.
+ var isInline = (Element.getStyle(element, 'display') === 'inline');
+ if (!isInline && element.offsetParent) return $(element.offsetParent);
if (element === document.body) return $(element);
while ((element = element.parentNode) && element !== document.body) {
@@ -910,13 +914,20 @@
return element.nodeName.toUpperCase() === 'BODY';
}
+ function isDetached(element) {
+ return element !== document.body &&
+ !Element.descendantOf(element, document.body);
+ }
+
// If the browser supports the nonstandard `getBoundingClientRect`
// (currently only IE and Firefox), it becomes far easier to obtain
// true offsets.
if ('getBoundingClientRect' in document.documentElement) {
Element.addMethods({
viewportOffset: function(element) {
- element = $(element);
+ element = $(element);
+ if (isDetached(element)) return new Element.Offset(0, 0);
+
var rect = element.getBoundingClientRect(),
docEl = document.documentElement;
// The HTML element on IE < 8 has a 2px border by default, giving
@@ -928,14 +939,17 @@
cumulativeOffset: function(element) {
element = $(element);
+ if (isDetached(element)) return new Element.Offset(0, 0);
+
var docOffset = $(document.documentElement).viewportOffset(),
elementOffset = element.viewportOffset();
return elementOffset.relativeTo(docOffset);
},
positionedOffset: function(element) {
element = $(element);
- var parent = element.getOffsetParent();
+ var parent = element.getOffsetParent();
+ if (isDetached(element)) return new Element.Offset(0, 0);
// When the BODY is the offsetParent, IE6 mistakenly reports the
// parent as HTML. Use that as the litmus test to fix another

0 comments on commit 8369133

Please sign in to comment.
Something went wrong with that request. Please try again.