From c78a3ba6577b6735137abcd5c01a35ca28c33660 Mon Sep 17 00:00:00 2001 From: yiminghe Date: Mon, 22 Oct 2012 11:40:37 +0800 Subject: [PATCH] Fix #12685. Handle inconsistent opacity for ie < 9. Close gh-1005. --- AUTHORS.txt | 1 + src/css.js | 10 ++++++---- test/unit/css.js | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 0a06fece5..dea7ef995 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -153,3 +153,4 @@ Jay Merrifield Allen J Schmidt Jr Marcel Greter Matthias Jäggli +Yiming He diff --git a/src/css.js b/src/css.js index 6dd13efdf..1723223e5 100644 --- a/src/css.js +++ b/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 @@ -535,7 +535,9 @@ 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 @@ -543,8 +545,8 @@ if ( !jQuery.support.opacity ) { // 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; } } diff --git a/test/unit/css.js b/test/unit/css.js index ec1af1dd5..3dc9653ba 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -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("").appendTo(fixture), + el = jQuery("
").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" ); +}); + } -- 2.39.5