Skip to content
Permalink
Browse files

Merge pull request #416 from gnarf37/ticket_6652

CSS: Remove filter from style when setting opacity to 1 - Fixes #6652 - R
  • Loading branch information...
dmethvin committed Aug 4, 2011
2 parents b5a16ea + 5b0c306 commit 8d5c874227a65434a694b97148577fd4f93ab264
Showing with 39 additions and 6 deletions.
  1. +17 −6 src/css.js
  2. +2 −0 test/data/testsuite.css
  3. +3 −0 test/index.html
  4. +17 −0 test/unit/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;
@@ -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); }
@@ -226,6 +226,9 @@ <h2 id="qunit-userAgent"></h2>
<div id="t2037">
<div><div class="hidden">hidden</div></div>
</div>
<div id="t6652">
<div></div>
</div>
</div>

<div id="tabindex-tests">
@@ -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() {

0 comments on commit 8d5c874

Please sign in to comment.
You can’t perform that action at this time.