diff options
author | Mike Sherov <mike.sherov@gmail.com> | 2011-12-06 16:23:22 -0500 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2011-12-06 16:23:22 -0500 |
commit | 2c1d2b1a4dc74c6487d9f5dd0ecafd34358163a1 (patch) | |
tree | cdb9377f62cbd7cbda0d209eec9d68e5b5b27687 /src | |
parent | 0fcfac7568823a4eec4e5dd7b9bf527a8ec04f5c (diff) | |
download | jquery-2c1d2b1a4dc74c6487d9f5dd0ecafd34358163a1.tar.gz jquery-2c1d2b1a4dc74c6487d9f5dd0ecafd34358163a1.zip |
Fix #10754. Have jQuery.swap() return the value of its callback.
Diffstat (limited to 'src')
-rw-r--r-- | src/css.js | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/css.js b/src/css.js index b6c5607e4..b07f5316b 100644 --- a/src/css.js +++ b/src/css.js @@ -140,20 +140,23 @@ jQuery.extend({ // A method for quickly swapping in/out CSS properties to get correct calculations swap: function( elem, options, callback ) { - var old = {}; + var old = {}, + ret, name; // Remember the old values, and insert the new ones - for ( var name in options ) { + for ( name in options ) { old[ name ] = elem.style[ name ]; elem.style[ name ] = options[ name ]; } - callback.call( elem ); + ret = callback.call( elem ); // Revert the old values for ( name in options ) { elem.style[ name ] = old[ name ]; } + + return ret; } }); @@ -163,18 +166,14 @@ jQuery.curCSS = jQuery.css; jQuery.each(["height", "width"], function( i, name ) { jQuery.cssHooks[ name ] = { get: function( elem, computed, extra ) { - var val; - if ( computed ) { if ( elem.offsetWidth !== 0 ) { return getWH( elem, name, extra ); } else { - jQuery.swap( elem, cssShow, function() { - val = getWH( elem, name, extra ); + return jQuery.swap( elem, cssShow, function() { + return getWH( elem, name, extra ); }); } - - return val; } }, @@ -243,15 +242,13 @@ jQuery(function() { get: function( elem, computed ) { // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right // Work around by temporarily setting element display to inline-block - var ret; - jQuery.swap( elem, { "display": "inline-block" }, function() { + return jQuery.swap( elem, { "display": "inline-block" }, function() { if ( computed ) { - ret = curCSS( elem, "margin-right", "marginRight" ); + return curCSS( elem, "margin-right", "marginRight" ); } else { - ret = elem.style.marginRight; + return elem.style.marginRight; } }); - return ret; } }; } |