Skip to content

Commit

Permalink
Fix Element#positionedOffset and Element#getOffsetParent for static e…
Browse files Browse the repository at this point in the history
…lements on IE. DOM unit tests now pass on IE.
  • Loading branch information
madrobby committed Aug 10, 2007
1 parent 2fbb490 commit 5f76c25
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Fix Element#positionedOffset and Element#getOffsetParent for static elements on IE. [Thomas Fuchs]

* Make sure event handlers and their wrappers are removed from the cache by Event.stopObserving. [sam, Severin Heiniger]

* Add line numbers to failures when unit testing in Firefox. Closes #9231. [John Resig]
Expand Down
16 changes: 15 additions & 1 deletion src/dom.js
Expand Up @@ -552,7 +552,7 @@ Element.Methods = {
getOffsetParent: function(element) {
if (element.offsetParent) return $(element.offsetParent);
if (element == document.body) return $(element);

while ((element = element.parentNode) && element != document.body)
if (Element.getStyle(element, 'position') != 'static')
return $(element);
Expand Down Expand Up @@ -735,6 +735,20 @@ if (Prototype.Browser.Opera) {
}

else if (Prototype.Browser.IE) {
['positionedOffset','getOffsetParent'].each(function(method){
Element.Methods[method] = Element.Methods[method].wrap(
function(proceed, element){
element = $(element);
if (element.getStyle('position') == 'static') return proceed(element);
var position = element.getStyle(position);
element.setStyle({position: 'relative'});
var value = proceed(element);
element.setStyle({position: position});
return value;
}
);
});

Element.Methods.getStyle = function(element, style) {
element = $(element);
style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
Expand Down
19 changes: 12 additions & 7 deletions test/unit/dom.html
Expand Up @@ -225,7 +225,7 @@ <h1>Prototype Unit test file</h1>
<div id="style_test_3">blah</div>

<div id="style_test_dimensions_container">
<div id="style_test_dimensions" style="background:#ddd;padding:1px;margin:1px;border:1px solid #00f"><div style="height:5px;background:#eee;width:5px;padding:2px;margin:2px;border:2px solid #0f0"></div>
<div id="style_test_dimensions" style="background:#ddd;padding:1px;margin:1px;border:1px solid #00f"><div style="height:5px;background:#eee;width:5px;padding:2px;margin:2px;border:2px solid #0f0"> </div>
</div>
</div>

Expand Down Expand Up @@ -346,8 +346,8 @@ <h1>Prototype Unit test file</h1>
<div id="body_absolute" style="position: absolute; top: 10px; left: 10px">
<div id="absolute_absolute" style="position: absolute; top: 10px; left:10px"> </div>
<div id="absolute_relative" style="position: relative; top: 10px; left:10px">
<div style="height:10px">test<span id="inline">test</span></div>
<div id="absolute_relative_undefined"> </div>
<div style="height:10px;font-size:2px">test<span id="inline">test</span></div>
<div id="absolute_relative_undefined">XYZ</div>
</div>
</div>
<div id="notInlineAbsoluted"></div>
Expand Down Expand Up @@ -552,8 +552,9 @@ <h1>Prototype Unit test file</h1>
assert(getInnerHTML('wrap-container').startsWith('<div><p'));
element.wrap('div');
assert(getInnerHTML('wrap-container').startsWith('<div><div><p'));
assert(typeof parent.setStyle == 'function');

element.wrap(parent);
assert(Object.isFunction(parent.setStyle));
assert(getInnerHTML('wrap-container').startsWith('<div><div><div><p'));

element.wrap('div', {className: 'wrapper'});
Expand Down Expand Up @@ -1146,9 +1147,13 @@ <h1>Prototype Unit test file</h1>

// getStyle on width/height should return values according to
// the CSS box-model, which doesn't include
// margins, paddings or borders
assertEqual("14px", $('style_test_dimensions').getStyle('width'));
assertEqual("17px", $('style_test_dimensions').getStyle('height'));
// margins, paddings or borders
// TODO: This test fails on IE because there seems to be no way
// to calculate this properly (clientWidth/Height returns 0)
if(!navigator.appVersion.match(/MSIE/)) {
assertEqual("14px", $('style_test_dimensions').getStyle('width'));
assertEqual("17px", $('style_test_dimensions').getStyle('height'));
}
}},

testElementGetOpacity: function() {with(this) {
Expand Down

0 comments on commit 5f76c25

Please sign in to comment.