From fc51e14b810474fe9ed0b03bed5eddc82e9f7fde Mon Sep 17 00:00:00 2001 From: Brandon Aaron Date: Tue, 18 Dec 2007 03:53:09 +0000 Subject: [PATCH] width and height methods are now working properly --- src/core.js | 20 +++++++++++------- test/index.html | 4 +++- test/unit/core.js | 53 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/core.js b/src/core.js index 1e4f92490..4decf3e4d 100644 --- a/src/core.js +++ b/src/core.js @@ -764,9 +764,10 @@ jQuery.extend({ // A method for quickly swapping in/out CSS properties to get correct calculations swap: function( elem, options, callback ) { + var old = {}; // Remember the old values, and insert the new ones for ( var name in options ) { - elem.style[ "old" + name ] = elem.style[ name ]; + old[ name ] = elem.style[ name ]; elem.style[ name ] = options[ name ]; } @@ -774,24 +775,29 @@ jQuery.extend({ // Revert the old values for ( var name in options ) - elem.style[ name ] = elem.style[ "old" + name ]; + elem.style[ name ] = old[ name ]; }, css: function( elem, name, force ) { if ( name == "width" || name == "height" ) { - var width, height, props = { position: "absolute", visibility: "hidden", display:"block" }; + var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; function getWH() { - width = elem.clientWidth; - height = elem.clientHeight; + val = name == "width" ? elem.offsetWidth : elem.offsetHeight; + var padding = 0, border = 0; + jQuery.each( which, function() { + padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; + border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; + }); + val -= Math.round(padding + border); } if ( jQuery(elem).is(":visible") ) getWH(); else jQuery.swap( elem, props, getWH ); - - return name == "width" ? width : height; + + return val; } return jQuery.curCSS( elem, name, force ); diff --git a/test/index.html b/test/index.html index e854101c9..bca5f5baf 100644 --- a/test/index.html +++ b/test/index.html @@ -20,7 +20,9 @@

-
+
+
+