2 * jQuery Color Animations
3 * Copyright 2007 John Resig
4 * Released under the MIT and GPL licenses.
9 // We override the animation for all of these color styles
10 jQuery
.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i
,attr
){
11 jQuery
.fx
.step
[attr
] = function(fx
){
12 if ( fx
.state
== 0 ) {
13 fx
.start
= getColor( fx
.elem
, attr
);
14 fx
.end
= getRGB( fx
.end
);
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)
25 // Color Conversion functions from highlightFade
26 // By Blair Mitchelmore
27 // http://jquery.offput.ca/highlightFade/
29 // Parse strings looking for color tuples [255,255,255]
30 function getRGB(color
) {
33 // Check if we're already dealing with an array of colors
34 if ( color
&& color
.constructor == Array
&& color
.length
== 3 )
37 // Look for rgb(num,num,num)
38 if (result
= /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color
))
39 return [parseInt(result
[1]), parseInt(result
[2]), parseInt(result
[3])];
41 // Look for rgb(num%,num%,num%)
42 if (result
= /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color
))
43 return [parseFloat(result
[1])*2.55, parseFloat(result
[2])*2.55, parseFloat(result
[3])*2.55];
46 if (result
= /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color
))
47 return [parseInt(result
[1],16), parseInt(result
[2],16), parseInt(result
[3],16)];
50 if (result
= /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color
))
51 return [parseInt(result
[1]+result
[1],16), parseInt(result
[2]+result
[2],16), parseInt(result
[3]+result
[3],16)];
53 // Otherwise, we're most likely dealing with a named color
54 return colors
[jQuery
.trim(color
).toLowerCase()];
57 function getColor(elem
, attr
) {
61 color
= jQuery
.curCSS(elem
, attr
);
63 // Keep going until we find an element that has color, or we hit the body
64 if ( color
!= '' && color
!= 'transparent' || jQuery
.nodeName(elem
, "body") )
67 attr
= "backgroundColor";
68 } while ( elem
= elem
.parentNode
);
73 // Some named colors to work with
74 // From Interface by Stefan Petre
75 // http://interface.eyecon.ro/
87 darkgrey
:[169,169,169],
89 darkkhaki
:[189,183,107],
90 darkmagenta
:[139,0,139],
91 darkolivegreen
:[85,107,47],
92 darkorange
:[255,140,0],
93 darkorchid
:[153,50,204],
95 darksalmon
:[233,150,122],
96 darkviolet
:[148,0,211],
102 lightblue
:[173,216,230],
103 lightcyan
:[224,255,255],
104 lightgreen
:[144,238,144],
105 lightgrey
:[211,211,211],
106 lightpink
:[255,182,193],
107 lightyellow
:[255,255,224],
118 silver
:[192,192,192],