-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getOffsetParent() returns BODY for new hidden elements in IE8 final #156
Comments
Serty Oan indeed IE8 offsetParent is the document.body for display none new elements a partial correction in Element.Methods could be :
anyway still get a problem as i get in IE 8 : |
rvagg 21,21 is because of the 1px border on 'srcele' I guess, I put that in there at the last moment and didn't even notice that it introduced a 1px shift, even without your patch. |
rvagg After switching the example file to 1.6.1 RC2 (http://prototypejs.org/assets/20... and running with my bunch of test browsers I get the following:
I don't think there's really anything different between 1.6.0.3 and 1.6.1 RC2 for this bug but I guess this would be an important issue to address for "IE8 compatibility"? |
rvagg This is still an issue with RC3. So having further dug into the issues involved here I can report the following:
(why are we using lighthouse rather than trac now? this is so much harder to use and navigate... or does it have some special features I'm not aware of that make it really attractive?) |
BillyRayPreachersSon Further debugging shows the problem only seems to exist when certain CSS is in play. If you have a website that uses "margin: 0px auto" to centre itself, and you clone a node's position onto a node that is initially hidden, all browsers except IE8 will play ball. It's also an issue if you remove the auto margins and use left padding on the BODY. Either way, IE6 and IE7, Fx3, etc are all fine - just not IE8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Position cloning bug with IE8</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<style type="text/css">
html, body {
padding: 0px;
margin: 0px;
}
body {
text-align: center;
}
#centreWrapper {
width: 800px;
margin: 0px auto;
text-align: left;
background-color: #CCCCCC;
}
.itemSelectionWrapper {
position: relative;
padding: 20px;
}
.itemSelectorRow {
margin: 10px;
}
div.autocomplete {
position: absolute;
width: 250px;
background-color: #FFFFFF;
border: 1px solid #888888;
margin: 0px;
padding: 0px;
}
div.autocomplete ul,
div.autocomplete li {
list-style-type: none;
margin: 0px;
padding: 0px;
}
</style>
<script type="text/javascript" src="prototype161rc3.js"></script>
<script type="text/javascript">
document.observe('dom:loaded', showClonedBoxes);
function showClonedBoxes() {
cloneAndShow($('theItem'), $('itemSuggestions'));
cloneAndShow($('anotherItem'), $('anotherItemSuggestions'));
}
function cloneAndShow(sourceToClone, clonedNode) {
Element.clonePosition(clonedNode, sourceToClone, {
setHeight: false,
offsetTop: sourceToClone.offsetHeight
});
Element.show(clonedNode);
}
</script>
</head>
<body>
<div id="centreWrapper">
<div class="itemSelectionWrapper">
<form>
<fieldset>
<legend>Item Selection</legend>
<div class="itemSelectorRow">
<label>Item</label>
<input type="text" name="theItem" id="theItem" value="" size="80" />
<div id="itemSuggestions" class="autocomplete" style="display:none;">
<ul><li class="selected"><strong>I</strong>tem 1</li><li class=""><strong>I</strong>tem 2</li><li class=""><strong>I</strong>tem 3</li></ul>
</div>
</div>
</fieldset>
</form>
</div>
<br />
<div class="itemSelectionWrapper">
<form>
<fieldset>
<legend>Another Item Selection</legend>
<div class="itemSelectorRow">
<label>Another Item</label>
<input type="text" name="anotherItem" id="anotherItem" value="" size="80" />
<div id="anotherItemSuggestions" class="autocomplete">
<ul><li class="selected"><strong>I</strong>tem 1</li><li class=""><strong>I</strong>tem 2</li><li class=""><strong>I</strong>tem 3</li></ul>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</body>
</html> Note, I'm running the latest version of IE 8 under Windows XP. |
Steffen Bartsch rvagg's patch works great for my problems with mis-positioned scriptaculous autocompletes in IE8. Is this already on its way into the prototype repository? |
x Vote for rvagg's patch too. |
Shridhar N S rvagg's patch works fine for my problems too. |
Keith Davis how do we vote for patches? |
Jacob Kjeldahl rvagg's patch works for me as well. |
Joey Novak I checked the git repo and this change isn't in there yet. What do we need to do to get it there? Here is a patch file that fixes the git repo if you check it out. diff --git a/src/dom/dom.js b/src/dom/dom.js
index 0f0e247..2a0addf 100644
--- a/src/dom/dom.js
+++ b/src/dom/dom.js
@@ -1291,7 +1291,7 @@ Element.Methods = {
* `body` element is returned.
**/
getOffsetParent: function(element) {
- if (element.offsetParent) return $(element.offsetParent);
+ if (element.offsetParent && Element.visible(element)) return $(element.offsetParent);
if (element == document.body) return $(element);
while ((element = element.parentNode) && element != document.body) |
Dan I tested the patch in IE 8, IE 6, Opera Windows/Linux, Firefox Linux - all seems to work fine |
Stephen Heuer Why was rvagg's fix never be applied to 1.6? The one that Joey Novak even put into a patch file? |
lakshmanan rvag's patch "didn't" work for me. I am using Prototype 1.7.rc2 and scriptaculous 1.8.3 |
Clément Hallet How this patch would be applied on the 1.7 version ? |
Keith Davis Line 3701:
|
Keith Davis I cannot believe this wasn't fixed in 1.7.1!!!! |
Keith Davis Does anyone know if there is any development being on Prototype? |
Yes Prototype is still being actively developed - check the github https://github.com/sstephenson/prototype |
Anthony Mckale This code someone committed works for me, was finding the "Element.visible(element)" hack didn't work unfortunately
|
Looks like this patch was already integrated into the 1.7.2 release - closing |
previous lighthouse ticket #618
by rvagg
If you insert a new element into the DOM that's hidden (display:none;) getOffsetParent() returns BODY no matter where you put it. If it's shown when you insert it it will return the correct element.
This problem does not exist in the IE8 that's in Windows 7 Beta, I'm not sure about the other pre-final releases of IE8 but I suspect this has crept into the final release.
Run attached file to see a demonstration, it uses clonePosition() to demonstrate that getOffsetParent() returns the wrong element for working out the positioning delta and therefore places the element in the wrong place (by a long way).
Work-around is to not use display:none; on your new elements.
See also http://groups.google.com/group/prototype-scriptaculous/browse_thread/thread/186e505aea6873db for mention of this problem.
The text was updated successfully, but these errors were encountered: