Wrote jquery.colorUtil plugin.
[lhc/web/wiklou.git] / resources / jquery / jquery.color.js
1 /*
2 * jQuery Color Animations
3 * Copyright 2007 John Resig
4 * Released under the MIT and GPL licenses.
5 *
6 * - 2011-01-05: Modified by Krinkle to use the jQuery.colorUtil plugin (needs to be loaded first)
7 */
8
9 (function(jQuery){
10
11 // We override the animation for all of these color styles
12 jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
13 jQuery.fx.step[attr] = function(fx){
14 if ( fx.state == 0 ) {
15 fx.start = getColor( fx.elem, attr );
16 fx.end = $.colorUtil.getRGB( fx.end );
17 }
18
19 fx.elem.style[attr] = "rgb(" + [
20 Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
21 Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
22 Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
23 ].join(",") + ")";
24 }
25 });
26
27 function getColor(elem, attr) {
28 var color;
29
30 do {
31 color = jQuery.curCSS(elem, attr);
32
33 // Keep going until we find an element that has color, or we hit the body
34 if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
35 break;
36
37 attr = "backgroundColor";
38 } while ( elem = elem.parentNode );
39
40 return $.colorUtil.getRGB(color);
41 };
42
43 })(jQuery);