From 2c180ef938201f1213b5c43c8212856d0282e1f0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski?= Date: Mon, 10 Mar 2014 00:59:14 +0100 Subject: [PATCH] Css: Revert 24e587929f62428e1959b10aace6dc4fd65ab397 The workaround to be able to change !important styles broke the browser keeping the old CSS value if the new one was rejected. Patching it would involve a significant perf hit (~33%) so the initial patch needs to be reverted instead. Tests by m_gol & gibson042. Fixes #14836 Closes gh-1532 --- src/css.js | 3 --- test/unit/css.js | 27 ++++++++++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/css.js b/src/css.js index 4d6838a4e..5e22dae00 100644 --- a/src/css.js +++ b/src/css.js @@ -286,9 +286,6 @@ jQuery.extend({ // If a hook was provided, use that value, otherwise just set the specified value if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) { - // Support: Chrome, Safari - // Setting style to blank string required to delete "style: x !important;" - style[ name ] = ""; style[ name ] = value; } diff --git a/test/unit/css.js b/test/unit/css.js index 09839f185..a65bf1dbe 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -204,7 +204,7 @@ test( "css() explicit and relative values", 29, function() { }); test("css(String, Object)", function() { - expect( 19 ); + expect( 20 ); var j, div, display, ret, success; jQuery("#nothiddendiv").css("top", "-1em"); @@ -239,15 +239,18 @@ test("css(String, Object)", function() { equal( ret, div, "Make sure setting undefined returns the original set." ); equal( div.css("display"), display, "Make sure that the display wasn't changed." ); - // Test for Bug #5509 success = true; try { - jQuery("#foo").css("backgroundColor", "rgba(0, 0, 0, 0.1)"); + jQuery( "#foo" ).css( "backgroundColor", "rgba(0, 0, 0, 0.1)" ); } catch (e) { success = false; } - ok( success, "Setting RGBA values does not throw Error" ); + ok( success, "Setting RGBA values does not throw Error (#5509)" ); + + jQuery( "#foo" ).css( "font", "7px/21px sans-serif" ); + strictEqual( jQuery( "#foo" ).css( "line-height" ), "21px", + "Set font shorthand property (#14759)" ); }); test( "css(Array)", function() { @@ -923,10 +926,20 @@ test( ":visible/:hidden selectors", function() { t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] ); }); -test( "Override !important when changing styles (#14394)", function() { +test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function() { + expect( 2 ); + + var el; + el = jQuery( "
" ).css( "color", "black" ).css( "color", "fake value" ); + equal( el.css( "color" ), "black", "The old style is kept when setting an unrecognized value" ); + el = jQuery( "
" ).css( "color", "black" ).css( "color", " " ); + equal( el.css( "color" ), "black", "The old style is kept when setting to a space" ); +}); + +test( "Reset the style if set to an empty string", function() { expect( 1 ); - var el = jQuery( "
" ).css( "display", "none" ); - equal( el.css( "display" ), "none", "New style replaced !important" ); + var el = jQuery( "
" ).css( "color", "black" ).css( "color", "" ); + equal( el.css( "color" ), "", "The style can be reset by setting to an empty string" ); }); asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", 24, function() { -- 2.39.5