From 025f2c63e487e069215b2a03ded2b98198904af9 Mon Sep 17 00:00:00 2001 From: louisremi Date: Tue, 1 Mar 2011 00:54:15 +0100 Subject: [PATCH 1/6] fixing both #8403 and #8401: jQuery \"bulldozes\" other IE filters when setting opacity --- src/css.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/css.js b/src/css.js index 8a982312..9fdba3b7 100644 --- a/src/css.js +++ b/src/css.js @@ -221,7 +221,8 @@ if ( !jQuery.support.opacity ) { }, set: function( elem, value ) { - var style = elem.style; + var style = elem.style, + currentStyle = elem.currentStyle; // IE has trouble with opacity if it does not have layout // Force it by setting the zoom level @@ -231,11 +232,11 @@ if ( !jQuery.support.opacity ) { var opacity = jQuery.isNaN(value) ? "" : "alpha(opacity=" + value * 100 + ")", - filter = style.filter || ""; + filter = currentStyle && currentStyle.filter || style.filter || ""; style.filter = ralpha.test(filter) ? filter.replace(ralpha, opacity) : - style.filter + ' ' + opacity; + filter + ' ' + opacity; } }; } From c6b891fb1c909a2791ba7a4d745940858bd7b94f Mon Sep 17 00:00:00 2001 From: louisremi Date: Mon, 7 Mar 2011 14:43:08 +0100 Subject: [PATCH 2/6] Adding unit tests for #8403 --- test/data/testsuite.css | 2 +- test/unit/css.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/data/testsuite.css b/test/data/testsuite.css index cffaaa46..02900681 100644 --- a/test/data/testsuite.css +++ b/test/data/testsuite.css @@ -1,5 +1,5 @@ /* for testing opacity set in styles in IE */ -ol#empty { opacity: 0; filter:Alpha(opacity=0); } +ol#empty { opacity: 0; filter:Alpha(opacity=0) progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffff0000', EndColorStr='#ffffffff'); } div#fx-tests h4 { background: red; diff --git a/test/unit/css.js b/test/unit/css.js index 555f1357..87466187 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1,7 +1,7 @@ module("css", { teardown: moduleTeardown }); test("css(String|Hash)", function() { - expect(41); + expect(42); equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"'); @@ -58,6 +58,7 @@ test("css(String|Hash)", function() { equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" ); jQuery('#empty').css({ opacity: '1' }); equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" ); + ok( ~jQuery('#empty')[0].currentStyle.filter.indexOf('gradient'), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" ); var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild'); From 6ddc3816dd23fd0d3b9328b2cb4648589884a206 Mon Sep 17 00:00:00 2001 From: louisremi Date: Mon, 11 Apr 2011 21:05:15 +0200 Subject: [PATCH 3/6] limit this test to browsers not supporting opacity --- test/unit/css.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unit/css.js b/test/unit/css.js index 87466187..c85f432f 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1,7 +1,7 @@ module("css", { teardown: moduleTeardown }); test("css(String|Hash)", function() { - expect(42); + expect( jQuery.support.opacity ? 41 : 42 ); equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"'); @@ -58,7 +58,9 @@ test("css(String|Hash)", function() { equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" ); jQuery('#empty').css({ opacity: '1' }); equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" ); - ok( ~jQuery('#empty')[0].currentStyle.filter.indexOf('gradient'), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" ); + if ( !jQuery.support.opacity ) { + ok( ~jQuery('#empty')[0].currentStyle.filter.indexOf('gradient'), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" ); + } var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild'); From d7104422017b26eb7bdbf4fc325ab16d561c40ce Mon Sep 17 00:00:00 2001 From: louisremi Date: Mon, 11 Apr 2011 21:14:41 +0200 Subject: [PATCH 4/6] the expected number of assertions shouldn't contain a condition --- test/unit/css.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/css.js b/test/unit/css.js index c85f432f..c21beb80 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1,7 +1,7 @@ module("css", { teardown: moduleTeardown }); test("css(String|Hash)", function() { - expect( jQuery.support.opacity ? 41 : 42 ); + expect( 42 ); equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"'); @@ -58,9 +58,9 @@ test("css(String|Hash)", function() { equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" ); jQuery('#empty').css({ opacity: '1' }); equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" ); - if ( !jQuery.support.opacity ) { + jQuery.support.opacity ? + ok(true, "Requires the same number of tests"): ok( ~jQuery('#empty')[0].currentStyle.filter.indexOf('gradient'), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" ); - } var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild'); From 930731ba0fbf8d2fc21e77283e3a8c332ac44570 Mon Sep 17 00:00:00 2001 From: louisremi Date: Mon, 11 Apr 2011 21:33:15 +0200 Subject: [PATCH 5/6] Double quote is the new simple quote --- test/unit/css.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/css.js b/test/unit/css.js index c21beb80..d68aff85 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -60,7 +60,7 @@ test("css(String|Hash)", function() { equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" ); jQuery.support.opacity ? ok(true, "Requires the same number of tests"): - ok( ~jQuery('#empty')[0].currentStyle.filter.indexOf('gradient'), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" ); + ok( ~jQuery("#empty")[0].currentStyle.filter.indexOf("gradient"), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" ); var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild'); From 581fa824200448361be534680a920d8144476aa7 Mon Sep 17 00:00:00 2001 From: louisremi Date: Mon, 11 Apr 2011 21:44:29 +0200 Subject: [PATCH 6/6] double quotes, again --- src/css.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/css.js b/src/css.js index 9fdba3b7..e2c31c81 100644 --- a/src/css.js +++ b/src/css.js @@ -236,7 +236,7 @@ if ( !jQuery.support.opacity ) { style.filter = ralpha.test(filter) ? filter.replace(ralpha, opacity) : - filter + ' ' + opacity; + filter + " " + opacity; } }; }