diff options
author | Dave Methvin <dave.methvin@gmail.com> | 2011-08-04 15:09:31 -0700 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2011-08-04 15:09:31 -0700 |
commit | 8d5c874227a65434a694b97148577fd4f93ab264 (patch) | |
tree | e40fba7d87e8aa9cc045f4ce1973c6ca5565b6f9 | |
parent | b5a16ead1ae2b7449c442c151299f9f456c03942 (diff) | |
parent | 5b0c3060f0f55d39d2251d4f79be58570c5ba029 (diff) | |
download | jquery-8d5c874227a65434a694b97148577fd4f93ab264.tar.gz jquery-8d5c874227a65434a694b97148577fd4f93ab264.zip |
Merge pull request #416 from gnarf37/ticket_6652
CSS: Remove filter from style when setting opacity to 1 - Fixes #6652 - R
-rw-r--r-- | src/css.js | 23 | ||||
-rw-r--r-- | test/data/testsuite.css | 2 | ||||
-rw-r--r-- | test/index.html | 3 | ||||
-rw-r--r-- | test/unit/css.js | 17 |
4 files changed, 39 insertions, 6 deletions
diff --git a/src/css.js b/src/css.js index cb7df9f80..efd881653 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 295740f5c..8c88a9334 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 f3f235e09..a001e7435 100644 --- a/test/index.html +++ b/test/index.html @@ -226,6 +226,9 @@ Z</textarea> <div id="t2037"> <div><div class="hidden">hidden</div></div> </div> + <div id="t6652"> + <div></div> + </div> </div> <div id="tabindex-tests"> diff --git a/test/unit/css.js b/test/unit/css.js index f421f7bd4..c01acdd68 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() { |