From a726d95d0bb324f60de69f44ce79f07c8644611e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=B6ckel?= Date: Wed, 30 Mar 2011 20:52:02 +0000 Subject: [PATCH] Fixed bug with grid element position calculation in firefox - firefox uses fractional height values internally but returns them rounded when using offsetHeight - using getComputedStyle when using firefox fixed the issue. --- phpgwapi/js/egw_action/egw_grid_view.js | 46 +++++++++++++++---- .../js/egw_action/test/test_grid_view.html | 5 +- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/phpgwapi/js/egw_action/egw_grid_view.js b/phpgwapi/js/egw_action/egw_grid_view.js index 2e6c25fc8f..7248477a32 100644 --- a/phpgwapi/js/egw_action/egw_grid_view.js +++ b/phpgwapi/js/egw_action/egw_grid_view.js @@ -615,21 +615,51 @@ egwGridViewContainer.prototype.setPosition = function(_top) /** * Returns the height of the container in pixels and zero if the element is not * visible. The height is clamped to positive values. + * The browser switch is placed at this position as the getHeight function is one + * of the mostly called functions in the whole grid code and should stay + * quite fast. */ -egwGridViewContainer.prototype.getHeight = function() +if ($.browser.mozilla) { - if (this.visible && this.parentNode) + egwGridViewContainer.prototype.getHeight = function() { - if (this.height === false && this.assumedHeight === false) + if (this.visible && this.parentNode) { - this.height = this.parentNode.outerHeight(); - } + if (this.height === false && this.assumedHeight === false) + { + // Firefox sometimes provides fractional pixel values - we are + // forced to use those - we can obtain the fractional pixel height + // by using the window.getComputedStyle function + var styleHeightStr = + getComputedStyle(this.parentNode.context, null).getPropertyValue("height"); + this.height = parseFloat(styleHeightStr.substr(0, styleHeightStr.length - 2)); + } - return this.height !== false ? this.height : this.assumedHeight; + return this.height !== false ? this.height : this.assumedHeight; + } + else + { + return 0; + } } - else +} +else +{ + egwGridViewContainer.prototype.getHeight = function() { - return 0; + if (this.visible && this.parentNode) + { + if (this.height === false && this.assumedHeight === false) + { + this.height = this.parentNode.context.offsetHeight; + } + + return this.height !== false ? this.height : this.assumedHeight; + } + else + { + return 0; + } } } diff --git a/phpgwapi/js/egw_action/test/test_grid_view.html b/phpgwapi/js/egw_action/test/test_grid_view.html index aa8745340d..51225da8ff 100644 --- a/phpgwapi/js/egw_action/test/test_grid_view.html +++ b/phpgwapi/js/egw_action/test/test_grid_view.html @@ -4,6 +4,8 @@ Grid Test + + @@ -22,7 +24,6 @@ - @@ -237,7 +238,7 @@ "entryType": EGW_DATA_TYPE_RANGE, "prefix": "root_elem_", "canHaveChildren": true, - "count": 10 + "count": 1000 } ] );