Ticket #2281: rgba.diff
File rgba.diff, 3.4 KB (added by , 15 years ago) |
---|
-
jquery.color.js
12 12 if ( fx.state == 0 ) { 13 13 fx.start = getColor( fx.elem, attr ); 14 14 fx.end = getRGB( fx.end ); 15 if ( fx.start[3] || fx.end[3] ) { // if one is rgba, make sure both are 16 fx.start[3] = fx.start[3] || 1; 17 fx.end[3] = fx.end[3] || 1; 18 } 15 19 } 16 20 17 fx.elem.style[attr] = "rgb(" + [ 18 Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0), 19 Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0), 20 Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0) 21 ].join(",") + ")"; 21 fx.elem.style[attr] = ( fx.end[3] ? 'rgba(' : 'rgb(' ) + 22 Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0) + ',' + 23 Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0) + ',' + 24 Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0) + 25 ( fx.end[3] ? ',' + 26 Math.max(Math.min( parseFloat((fx.pos * (fx.end[3] - fx.start[3])) + fx.start[3]), 1), 0) : '') + 27 ')'; 22 28 } 23 29 }); 24 30 … … 50 56 if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color)) 51 57 return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)]; 52 58 53 // Look for rgba( 0, 0, 0, 0) == transparent in Safari 354 if (result = /rgba\( 0, 0, 0, 0\)/.exec(color))55 return colors['transparent']59 // Look for rgba(num,num,num,alpha) 60 if (result = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([01]*(?:\.[0-9]+)?)\s*\)/.exec(color)) 61 return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3]), parseFloat(result[4])]; 56 62 63 // Look for rgba(num%,num%,num%,alpha) 64 if (result = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([01]*(?:\.[0-9]+)?)\s*\)/.exec(color)) 65 return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55, parseFloat(result[4])]; 66 57 67 // Otherwise, we're most likely dealing with a named color 58 return colors[jQuery.trim(color).toLowerCase()] ;68 return colors[jQuery.trim(color).toLowerCase()] || [255,255,255]; 59 69 } 60 70 61 71 function getColor(elem, attr) { 62 72 var color; 73 var rgba = /rgba\(\s*0,\s*0,\s*0,\s*0\s*\)/; // transparent 63 74 64 75 do { 65 76 color = jQuery.curCSS(elem, attr); 66 77 67 78 // Keep going until we find an element that has color, or we hit the body 68 if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )79 if ( color != '' && color != 'transparent' && !color.match(rgba) || jQuery.nodeName(elem, "body") ) 69 80 break; 70 81 71 82 attr = "backgroundColor"; … … 121 132 red:[255,0,0], 122 133 silver:[192,192,192], 123 134 white:[255,255,255], 124 yellow:[255,255,0], 125 transparent: [255,255,255] 135 yellow:[255,255,0] 126 136 }; 127 137 128 138 })(jQuery);