Merge "fix some spacing"
[mediawiki.git] / resources / jquery / jquery.color.js
blob8bc45c97c87413e59b6db4f25dd4df9e49fd078f
1 /**
2  * jQuery Color Animations
3  *
4  * @author John Resig, 2007
5  * @author Krinkle, 2011
6  * Released under the MIT and GPL licenses.
7  *
8  * - 2011-01-05: Forked for MediaWiki. See also jQuery.colorUtil plugin
9  */
10 ( function ( $ ) {
12         function getColor( elem, attr ) {
13                 /*jshint boss:true */
14                 var color;
16                 do {
17                         color = $.curCSS( elem, attr );
19                         // Keep going until we find an element that has color, or we hit the body
20                         if ( color !== '' && color !== 'transparent' || $.nodeName( elem, 'body' ) ) {
21                                 break;
22                         }
24                         attr = 'backgroundColor';
25                 } while ( elem = elem.parentNode );
27                 return $.colorUtil.getRGB( color );
28         }
30         // We override the animation for all of these color styles
31         $.each([
32                 'backgroundColor',
33                 'borderBottomColor',
34                 'borderLeftColor',
35                 'borderRightColor',
36                 'borderTopColor',
37                 'color',
38                 'outlineColor'
39         ], function ( i, attr ) {
40                 $.fx.step[attr] = function ( fx ) {
41                         if ( fx.state === 0 ) {
42                                 fx.start = getColor( fx.elem, attr );
43                                 fx.end = $.colorUtil.getRGB( fx.end );
44                         }
46                         fx.elem.style[attr] = 'rgb(' + [
47                                 Math.max( Math.min( parseInt( (fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0], 10 ), 255 ), 0 ),
48                                 Math.max( Math.min( parseInt( (fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1], 10 ), 255 ), 0 ),
49                                 Math.max( Math.min( parseInt( (fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2], 10 ), 255 ), 0 )
50                         ].join( ',' ) + ')';
51                 };
52         } );
54 }( jQuery ) );