From b9b87d53c681a8337cdbdbe81f8f4e577e5ec277 Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Wed, 6 Jun 2012 19:03:10 -0400 Subject: [PATCH] Less letterSpacing .animate() fail in IE. Fixes #8627 --- src/css.js | 15 +++++++++++++-- src/effects.js | 15 ++++++++------- test/unit/css.js | 8 ++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/css.js b/src/css.js index 4497878e4..4496594dc 100644 --- a/src/css.js +++ b/src/css.js @@ -15,7 +15,13 @@ var curCSS, iframe, iframeDoc, cssPrefixes = [ "Webkit", "O", "Moz", "ms" ], rposition = /^(top|right|bottom|left)$/, - eventsToggle = jQuery.fn.toggle; + eventsToggle = jQuery.fn.toggle, + + cssNormalTransform = { + letterSpacing: 0, + fontWeight: 400, + lineHeight: 1 + }; // return a css property mapped to a potentially vendor prefixed property function vendorPropName( style, name ) { @@ -235,8 +241,13 @@ jQuery.extend({ val = curCSS( elem, name ); } + //convert "normal" to computed value + if ( val === "normal" && name in cssNormalTransform ) { + val = cssNormalTransform[ name ]; + } + // Return, converting to number if forced or a qualifier was provided and val looks numeric - if ( numeric || extra ) { + if ( numeric || extra !== undefined ) { num = parseFloat( val ); return numeric || jQuery.isNumeric( num ) ? num || 0 : val; } diff --git a/src/effects.js b/src/effects.js index bd2ac816d..9a3e64d41 100644 --- a/src/effects.js +++ b/src/effects.js @@ -365,19 +365,20 @@ Tween.prototype.init.prototype = Tween.prototype; Tween.propHooks = { _default: { get: function( tween ) { - var parsed, result; + var result; if ( tween.elem[ tween.prop ] != null && (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) { return tween.elem[ tween.prop ]; } - result = jQuery.css( tween.elem, tween.prop ); - // Empty strings, null, undefined and "auto" are converted to 0, - // complex values such as "rotate(1rad)" are returned as is, - // simple values such as "10px" are parsed to Float. - return isNaN( parsed = parseFloat( result ) ) ? - !result || result === "auto" ? 0 : result : parsed; + // passing any value as a 4th paramter to .css will automatically + // attempt a parseFloat and fallback to a string if the parse fails + // so, simple values such as "10px" are parsed to Float. + // complex values such as "rotate(1rad)" are returned as is. + result = jQuery.css( tween.elem, tween.prop, false, "" ); + // Empty strings, null, undefined and "auto" are converted to 0. + return !result || result === "auto" ? 0 : result; }, set: function( tween ) { // use step hook for back compat - use cssHook if its there - use .style if its diff --git a/test/unit/css.js b/test/unit/css.js index 8f17ce74a..b030569fb 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -732,6 +732,14 @@ test("css('width') and css('height') should respect box-sizing, see #11004", fun equal( el_dis.css("height"), el_dis.css("height", el_dis.css("height")).css("height"), "css('height') is not respecting box-sizing for disconnected element, see #11004"); }); +test("certain css values of 'normal' should be convertable to a number, see #8627", function() { + var el = jQuery("
test
").appendTo("#qunit-fixture"); + + ok( jQuery.isNumeric( parseFloat( el.css("letterSpacing") ) ), "css('letterSpacing') not convertable to number, see #8627" ); + ok( jQuery.isNumeric( parseFloat( el.css("fontWeight") ) ), "css('fontWeight') not convertable to number, see #8627" ); + ok( jQuery.isNumeric( parseFloat( el.css("lineHeight") ) ), "css('lineHeight') not convertable to number, see #8627" ); +}); + test( "cssHooks - expand", function() { expect( 15 ); var result, -- 2.39.5