Commit 8d5c8742 authored by Dave Methvin's avatar Dave Methvin

Merge pull request #416 from gnarf37/ticket_6652

CSS: Remove filter from style when setting opacity to 1 - Fixes #6652 - R
parents b5a16ead 5b0c3060
...@@ -211,18 +211,29 @@ if ( !jQuery.support.opacity ) { ...@@ -211,18 +211,29 @@ if ( !jQuery.support.opacity ) {
set: function( elem, value ) { set: function( elem, value ) {
var style = elem.style, 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 // IE has trouble with opacity if it does not have layout
// Force it by setting the zoom level // Force it by setting the zoom level
style.zoom = 1; style.zoom = 1;
// Set the alpha filter to set the opacity // if setting opacity to 1, and no other filters exist - attempt to remove filter attribute #6652
var opacity = jQuery.isNaN( value ) ? if ( value >= 1 && jQuery.trim( filter.replace( ralpha, "" ) ) === "" ) {
"" :
"alpha(opacity=" + value * 100 + ")", // Setting style.filter to null, "" & " " still leave "filter:" in the cssText
filter = currentStyle && currentStyle.filter || style.filter || ""; // 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 ) ? style.filter = ralpha.test( filter ) ?
filter.replace( ralpha, opacity ) : filter.replace( ralpha, opacity ) :
filter + " " + opacity; filter + " " + opacity;
......
...@@ -121,3 +121,5 @@ dfn { display: none; } ...@@ -121,3 +121,5 @@ dfn { display: none; }
/* #9239 Attach a background to the body( avoid crashes in removing the test element in support ) */ /* #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; } 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 @@ Z</textarea> ...@@ -226,6 +226,9 @@ Z</textarea>
<div id="t2037"> <div id="t2037">
<div><div class="hidden">hidden</div></div> <div><div class="hidden">hidden</div></div>
</div> </div>
<div id="t6652">
<div></div>
</div>
</div> </div>
<div id="tabindex-tests"> <div id="tabindex-tests">
......
...@@ -259,6 +259,23 @@ if ( !jQuery.support.opacity ) { ...@@ -259,6 +259,23 @@ if ( !jQuery.support.opacity ) {
jQuery("#foo").css("filter", filterVal3).css("opacity", 1); 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" ); 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() { test("css(String, Function)", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment