getColor reports inaccurate color for transparent elements in Webkit

getColor reports inaccurate color for transparent elements in Webkit

I realize that getColor (from jquery.effects.core.js) is not an exposed function, but I did notice something odd about the logic which leads to it reporting incorrectly for transparent elements on Webkit. I copied getColor, getRGB and the 'colors' variable out into a simple example file with the latest jQuery and following contents:

  1. <div id="red" style="background-color:red;">
  2. <div id="trans">
  3. Some text.
  4. </div>
  5. </div>

And with the following call:

  1. alert(getColor($('#trans').get(0),'backgroundColor'));

Webkit (Chrome) will alert 255,255,255 while Firefox will alert 255,0,0

This is because there are two places in the code that handle transparency. Firefox (and I assume IE) transparency is caught in the do/while loop in getColor while Webkit transparency falls through to getRGB and is caught with a regular expression, thus returning colors['transparent'], which happens to be white. 

Shouldn't getColor also handle the Webkit transparency something like this:

  1. if ( color != '' && color != 'transparent' && color != 'rgba(0, 0, 0, 0)' || $.nodeName(elem, "body") )

I saw mention of exposing getColor publicly and figured that this might be worth addressing before it's up for general use.