Skip to content

Commit

Permalink
Fix #12685. Handle inconsistent opacity for ie < 9. Close jquerygh-1005.
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe authored and dmethvin committed Oct 30, 2012
1 parent c01fd57 commit f878694
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Expand Up @@ -153,3 +153,4 @@ Jay Merrifield <fracmak@gmail.com>
Allen J Schmidt Jr <cobrasoft@gmail.com>
Marcel Greter <marcel.greter@ocbnet.ch>
Matthias Jäggli <matthias.jaeggli@gmail.com>
Yiming He <yiminghe@gmail.com>
10 changes: 6 additions & 4 deletions src/css.js
@@ -1,6 +1,6 @@
var curCSS, iframe, iframeDoc,
ralpha = /alpha\([^)]*\)/i,
ropacity = /opacity=([^)]*)/,
ropacity = /opacity\s*=\s*([^)]*)/,
rposition = /^(top|right|bottom|left)$/,
// swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
// see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
Expand Down Expand Up @@ -535,16 +535,18 @@ if ( !jQuery.support.opacity ) {
style.zoom = 1;

// if setting opacity to 1, and no other filters exist - attempt to remove filter attribute #6652
if ( value >= 1 && jQuery.trim( filter.replace( ralpha, "" ) ) === "" &&
// if value === "", then remove inline opacity #12685
if ( ( value >= 1 || value === "" ) &&
jQuery.trim( filter.replace( ralpha, "" ) ) === "" &&
style.removeAttribute ) {

// 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 ) {
// if there is no filter style applied in a css rule or unset inline opacity, we are done
if ( value === "" || currentStyle && !currentStyle.filter ) {
return;
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/unit/css.js
Expand Up @@ -868,4 +868,20 @@ test( "cssHooks - expand", function() {

});

test( "css opacity consistency across browsers (#12685)", function() {
expect( 4 );

var fixture = jQuery("#qunit-fixture"),
style = jQuery("<style>.opacityWithSpaces_t12685 { opacity: 0.1; filter: alpha(opacity = 10); } .opacityNoSpaces_t12685 { opacity: 0.2; filter: alpha(opacity=20); }</style>").appendTo(fixture),
el = jQuery("<div class='opacityWithSpaces_t12685'></div>").appendTo(fixture);

equal( Math.round( el.css("opacity") * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" );
el.removeClass("opacityWithSpaces_t12685").addClass("opacityNoSpaces_t12685");
equal( Math.round( el.css("opacity") * 100 ), 20, "opacity from style sheet (filter:alpha without spaces)" );
el.css( "opacity", 0.3 );
equal( Math.round( el.css("opacity") * 100 ), 30, "override opacity" );
el.css( "opacity", "" );
equal( Math.round( el.css("opacity") * 100 ), 20, "remove opacity override" );
});

}

0 comments on commit f878694

Please sign in to comment.