diff --git a/src/css.js b/src/css.js index cb7df9f80f..efd8816535 100644 --- a/src/css.js +++ b/src/css.js @@ -211,18 +211,29 @@ if ( !jQuery.support.opacity ) { set: function( elem, value ) { var style = elem.style, - currentStyle = elem.currentStyle; + currentStyle = elem.currentStyle, + opacity = jQuery.isNaN( value ) ? "" : "alpha(opacity=" + value * 100 + ")", + filter = currentStyle && currentStyle.filter || style.filter || ""; // IE has trouble with opacity if it does not have layout // Force it by setting the zoom level style.zoom = 1; - // Set the alpha filter to set the opacity - var opacity = jQuery.isNaN( value ) ? - "" : - "alpha(opacity=" + value * 100 + ")", - filter = currentStyle && currentStyle.filter || style.filter || ""; + // if setting opacity to 1, and no other filters exist - attempt to remove filter attribute #6652 + if ( value >= 1 && jQuery.trim( filter.replace( ralpha, "" ) ) === "" ) { + + // Setting style.filter to null, "" & " " still leave "filter:" in the cssText + // if "filter:" is present at all, clearType is disabled, we want to avoid this + // style.removeAttribute is IE Only, but so apparently is this code path... + style.removeAttribute( "filter" ); + + // if there there is no filter style applied in a css rule, we are done + if ( currentStyle && !currentStyle.filter ) { + return; + } + } + // otherwise, set new filter values style.filter = ralpha.test( filter ) ? filter.replace( ralpha, opacity ) : filter + " " + opacity; diff --git a/test/data/testsuite.css b/test/data/testsuite.css index 295740f5c3..8c88a93348 100644 --- a/test/data/testsuite.css +++ b/test/data/testsuite.css @@ -121,3 +121,5 @@ dfn { display: none; } /* #9239 Attach a background to the body( avoid crashes in removing the test element in support ) */ body, div { background: url(http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif) no-repeat -1000px 0; } +/* #6652 REMOVE FILTER:ALPHA(OPACITY=100) AFTER ANIMATION */ +#t6652 div { filter: alpha(opacity=50); } diff --git a/test/index.html b/test/index.html index f3f235e093..a001e7435c 100644 --- a/test/index.html +++ b/test/index.html @@ -226,6 +226,9 @@

+
+
+
diff --git a/test/unit/css.js b/test/unit/css.js index f421f7bd4b..c01acdd685 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -259,6 +259,23 @@ if ( !jQuery.support.opacity ) { jQuery("#foo").css("filter", filterVal3).css("opacity", 1); ok( jQuery("#foo").css("filter").indexOf(filterVal3) !== -1, "Setting opacity in IE doesn't clobber other filters" ); }); + + test( "Setting opacity to 1 properly removes filter: style (#6652)", function() { + var rfilter = /filter:[^;]*/i, + test = jQuery( "#t6652" ).css( "opacity", 1 ), + test2 = test.find( "div" ).css( "opacity", 1 ); + + function hasFilter( elem ) { + var match = rfilter.exec( elem[0].style.cssText ); + if ( match ) { + return true; + } + return false; + } + expect( 2 ); + ok( !hasFilter( test ), "Removed filter attribute on element without filter in stylesheet" ); + ok( hasFilter( test2 ), "Filter attribute remains on element that had filter in stylesheet" ); + }); } test("css(String, Function)", function() {