Skip to content

Commit fd671ab

Browse files
Fix issue where Element#getOffsetParent would sometimes return the root HTML element in old IE. [close prototypejs#239]
1 parent 6493bdc commit fd671ab

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/prototype/dom/layout.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,18 +1052,23 @@
10521052
function getOffsetParent(element) {
10531053
element = $(element);
10541054

1055+
// Ensure we never return the root HTML tag.
1056+
function selfOrBody(element) {
1057+
return isHtml(element) ? $(document.body) : $(element);
1058+
}
1059+
10551060
// For unusual cases like these, we standardize on returning the BODY
10561061
// element as the offset parent.
10571062
if (isDocument(element) || isDetached(element) || isBody(element) || isHtml(element))
10581063
return $(document.body);
10591064

10601065
// IE reports offset parent incorrectly for inline elements.
10611066
var isInline = (Element.getStyle(element, 'display') === 'inline');
1062-
if (!isInline && element.offsetParent) return $(element.offsetParent);
1067+
if (!isInline && element.offsetParent) return selfOrBody(element.offsetParent);
10631068

10641069
while ((element = element.parentNode) && element !== document.body) {
10651070
if (Element.getStyle(element, 'position') !== 'static') {
1066-
return isHtml(element) ? $(document.body) : $(element);
1071+
return selfOrBody(element);
10671072
}
10681073
}
10691074

@@ -1559,7 +1564,6 @@
15591564

15601565
var currentLayout = element.getLayout();
15611566

1562-
console.log('this far?');
15631567
// Use content box when setting width/height. If padding/border are
15641568
// different between source and target, that's for the user to fix;
15651569
// there's no good option for us.

0 commit comments

Comments
 (0)