From 930c8f26653a2b86ab7c6bd06fabe2a9e52e7616 Mon Sep 17 00:00:00 2001 From: Thomas Fuchs Date: Tue, 27 Mar 2007 18:04:59 +0000 Subject: [PATCH] Fix an issue with Element.getDimensions with some element types on non IE-browsers. Closes #7683. [Andrew Dupont] --- CHANGELOG | 2 ++ src/dom.js | 33 +++++++++++++++++++-------------- test/unit/dom.html | 7 +++++++ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3691cfc..099530f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix an issue with Element.getDimensions with some element types on non IE-browsers. Closes #7683. [Andrew Dupont] + * Fix Form.disable to work again on non-form elements. Closes #6887. [Mislav Marohnić] * Fix an issue with String.prototype.endsWith. Closes #7822. [altblue] diff --git a/src/dom.js b/src/dom.js index 7c4de17..bfa5649 100644 --- a/src/dom.js +++ b/src/dom.js @@ -346,23 +346,28 @@ Element.Methods = { element = $(element); var display = $(element).getStyle('display'); if (display != 'none' && display != null) // Safari bug - return {width: element.offsetWidth, height: element.offsetHeight}; - + return { width: element.offsetWidth, height: element.offsetHeight }; + // All *Width and *Height properties give 0 on elements with display none, // so enable the element temporarily - var els = element.style; - var originalVisibility = els.visibility; - var originalPosition = els.position; - var originalDisplay = els.display; - els.visibility = 'hidden'; - els.position = 'absolute'; - els.display = 'block'; - var originalWidth = element.clientWidth; + var els = element.style, original = {}; + + $w('display position visibility height width').each( function(name) { + original[name] = els[name]; + }); + + els.visibility = 'hidden'; + els.display = 'block'; + + Position.absolutize(element); + var originalWidth = element.clientWidth; var originalHeight = element.clientHeight; - els.display = originalDisplay; - els.position = originalPosition; - els.visibility = originalVisibility; - return {width: originalWidth, height: originalHeight}; + Position.relativize(element); + + $w('display position visibility height width').each( function(name) { + els[name] = original[name] || ''; + }); + return { width: originalWidth, height: originalHeight }; }, makePositioned: function(element) { diff --git a/test/unit/dom.html b/test/unit/dom.html index 0719f78..fcfe85e 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -253,6 +253,11 @@ +
+ +
+ +

@@ -826,6 +831,8 @@ assertIdentical(200, $('dimensions-visible-pos-abs').getDimensions().width); assertIdentical(100, $('dimensions-display-none-pos-abs').getDimensions().height); assertIdentical(200, $('dimensions-display-none-pos-abs').getDimensions().width); + + assert($('dimensions-nestee').getDimensions().width <= 500, 'check for proper dimensions of hidden child elements'); $('dimensions-td').hide(); assertIdentical(100, $('dimensions-td').getDimensions().height);