jQuery: The Write Less, Do More JavaScript Library

Ticket #204 (closed bug: invalid)

Opened 2 years ago

Last modified 1 year ago

Opacity in IE

Reported by: brandon.aaron@… Assigned to: anonymous
Type: bug Priority: major
Milestone: Component: ajax
Version: Keywords:
Cc: Needs:

Description

I was having all sort of problems with opacity in IE and spent quite a while tracking all the issues down. I wish I could attach the diff but last time I tried attaching a file it errored out. I would love to throw some tests together but I'm already running behind on my project as it is. Hopefully someone else can help out with some testing. One thing to note is that I imagine this will break with other filters applied other than just an alpha filter but so would the current limited support for opacity.

Index: jquery/src/jquery/jquery.js
===================================================================
--- jquery/src/jquery/jquery.js (revision 312)
+++ jquery/src/jquery/jquery.js (working copy)
@@ -1425,14 +1425,20 @@
      });
      return p == "height" ? oHeight : oWidth;
-   } else if ( p == "opacity" && jQuery.browser.msie )
-     return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
+   }
    return jQuery.curCSS( e, p );
  },
  curCSS: function(elem, prop, force) {
    var ret;
+
+   if (prop == 'opacity' && jQuery.browser.msie) {
+     if (elem.style['filter'])
+       return parseFloat(elem.style['filter'].match(/d+/)[0])/100;
+     else
+       return 1;
+   }
    if (!force && elem.style[prop]) {
@@ -1798,6 +1804,16 @@
      disabled: "disabled",
      checked: "checked"
    };
+
+   // normalize opacity for ie ... elem is actually elem.style
+   if (name == 'opacity' && jQuery.browser.msie && value != undefined) {
+     return elem['filter'] = 'alpha(opacity=' + value * 100 + ')';
+   } else if (name == 'opacity' && jQuery.browser.msie) {
+     if (elem['filter'])
+       return parseFloat(elem['filter'].match(/d+/)[0])/100;
+     else
+       return 1;
+   }
    if ( fix[name] ) {
      if ( value != undefined ) elem[fix[name]] = value;

Attachments

Change History

Changed 2 years ago by brandon.aaron@…

UPDATE

On images that have patches of solid black in IE some of the black pixels would switch to white while the alpha filter was applied. To fix this I just removed the alpha filter if the value is 1. This also affects fx.js. Here is the updated diff ... still wish I could just attach it instead of pasting inline.

Index: jquery/src/jquery/jquery.js
===================================================================
--- jquery/src/jquery/jquery.js (revision 312)
+++ jquery/src/jquery/jquery.js (working copy)
@@ -1425,14 +1425,20 @@
      });
      return p == "height" ? oHeight : oWidth;
-   } else if ( p == "opacity" && jQuery.browser.msie )
-     return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
+   }
    return jQuery.curCSS( e, p );
  },
  curCSS: function(elem, prop, force) {
    var ret;
+
+   if (prop == 'opacity' && jQuery.browser.msie) {
+     if (elem.style['filter'])
+       return parseFloat(elem.style['filter'].match(/d+/)[0])/100;
+     else
+       return 1;
+   }
    if (!force && elem.style[prop]) {
@@ -1798,6 +1804,19 @@
      disabled: "disabled",
      checked: "checked"
    };
+
+   // normalize opacity for ie ... elem is actually elem.style
+   if (name == 'opacity' && jQuery.browser.msie && value != undefined) {
+     if (value == 1)
+       return elem['filter'] = '';
+     else
+       return elem['filter'] = 'alpha(opacity=' + value * 100 + ')';
+   } else if (name == 'opacity' && jQuery.browser.msie) {
+     if (elem['filter'])
+       return parseFloat(elem['filter'].match(/d+/)[0])/100;
+     else
+       return 1;
+   }
    if ( fix[name] ) {
      if ( value != undefined ) elem[fix[name]] = value;
Index: jquery/src/fx/fx.js
===================================================================
--- jquery/src/fx/fx.js (revision 312)
+++ jquery/src/fx/fx.js (working copy)
@@ -451,7 +451,10 @@
      if ( prop == "opacity" ) {
        if (jQuery.browser.mozilla && z.now == 1) z.now = 0.9999;
        if (window.ActiveXObject)
-         y.filter = "alpha(opacity=" + z.now*100 + ")";
+         if (z.now == 1)
+           y.filter = "";
+         else
+           y.filter = "alpha(opacity=" + z.now*100 + ")";
        else
          y.opacity = z.now;

Changed 2 years ago by joern

In case you have more updates to this: You could upload your patch somewhere and post a link to it, that would be ok.

Any hints at how a test for this could be written would be very useful.

Changed 2 years ago by joern

  • status changed from new to closed
  • resolution set to fixed

Added fix to SVN, still needs proper testing

Changed 2 years ago by joern

  • priority changed from blocker to critical
  • status changed from closed to reopened
  • resolution deleted

Not yet working, Brandon tries to figure it out.

Changed 2 years ago by brandon.aaron@…

  • cc set to brandon.aaron@gmail.com

This should take care of everything.

New patch on revision 404: http://brandonaaron.net/jquery/opacity/opacity.diff Example/Test: http://brandonaaron.net/jquery/opacity/opacity.html Broken, unpatched revision 396: http://brandonaaron.net/jquery/opacity/opacity.broken.html

Changed 2 years ago by brandon

  • status changed from reopened to closed
  • resolution set to fixed

Fixed in SVN Rev: 407.

Changed 2 years ago by anonymous

  • priority set to blocker
  • status changed from reopened to closed
  • component set to ajax
  • resolution set to invalid
  • type set to bug

SPAMPOLICE

Changed 2 years ago by bankir

  • cc changed from brandon.aaron@gmail.com to prevedz
  • type set to bug

Changed 2 years ago by durisk

  • type deleted

Changed 2 years ago by domovoi

  • type set to bug

Changed 2 years ago by anonymous

  • type deleted

Changed 2 years ago by topgovno

  • type set to bug

Changed 2 years ago by doyihgy

  • type deleted

Changed 2 years ago by mdsedsd

  • type set to bug

Changed 2 years ago by Freda

  • cc changed from prevedz to Freda
  • component set to 1
  • summary changed from [PATCH] IE Opacity issues resolved to Freda
  • priority set to 1
  • version set to 1
  • milestone set to 1
  • keywords set to Freda
  • type set to 1

Changed 2 years ago by mdsgfkds

  • cc changed from goodwork to prevedz

Changed 2 years ago by tralala

  • cc changed from goodwork to prevedz

Changed 2 years ago by hiromax

  • type set to bug

Changed 2 years ago by martishka

  • type deleted

Changed 2 years ago by john

  • cc deleted
  • component set to ajax
  • summary changed from goodwork bnp to Opacity in IE
  • priority set to major
  • keywords deleted
  • type set to bug

Changed 2 years ago by sfgh@…

xaulydptw iofmbh depaiurhs meach sjvt algwo zsfcwau

Note: See TracTickets for help on using tickets.