* Merged (added) SwiftFileBackend class from branch.
[mediawiki.git] / resources / jquery / jquery.color.js
blob8a619b5cc81f37bf3154b5f8034f5fa9fef6ae41
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 (which has to be loaded first!)
7  */
8 (function( $ ) {
10         // We override the animation for all of these color styles
11         $.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'],
12                 function( i, attr ) {
13                         $.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                                 }
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         );
28         function getColor(elem, attr) {
29                 var color;
31                 do {
32                         color = $.curCSS(elem, attr);
34                         // Keep going until we find an element that has color, or we hit the body
35                         if ( color != '' && color != 'transparent' || $.nodeName(elem, 'body') )
36                                 break;
38                         attr = 'backgroundColor';
39                 } while ( elem = elem.parentNode );
41                 return $.colorUtil.getRGB(color);
42         };
44 } )( jQuery );