Merge "Skin: Make skins aware of their registered skin name"
[lhc/web/wiklou.git] / resources / src / jquery / jquery.color.js
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 ( $ ) {
11
12 function getColor( elem, attr ) {
13 var color;
14
15 do {
16 color = $.css( elem, attr );
17
18 // Keep going until we find an element that has color, or we hit the body
19 if ( color !== '' && color !== 'transparent' || elem.nodeName.toLowerCase() === 'body' ) {
20 break;
21 }
22
23 attr = 'backgroundColor';
24 // eslint-disable-next-line no-cond-assign
25 } while ( elem = elem.parentNode );
26
27 return $.colorUtil.getRGB( color );
28 }
29
30 // We override the animation for all of these color styles
31 [
32 'backgroundColor',
33 'borderBottomColor',
34 'borderLeftColor',
35 'borderRightColor',
36 'borderTopColor',
37 'color',
38 'outlineColor'
39 ].forEach( function ( attr ) {
40 $.fx.step[ attr ] = function ( fx ) {
41 if ( !fx.colorInit ) {
42 fx.start = getColor( fx.elem, attr );
43 fx.end = $.colorUtil.getRGB( fx.end );
44 fx.colorInit = true;
45 }
46
47 fx.elem.style[ attr ] = 'rgb(' + [
48 Math.max( Math.min( parseInt( ( fx.pos * ( fx.end[ 0 ] - fx.start[ 0 ] ) ) + fx.start[ 0 ], 10 ), 255 ), 0 ),
49 Math.max( Math.min( parseInt( ( fx.pos * ( fx.end[ 1 ] - fx.start[ 1 ] ) ) + fx.start[ 1 ], 10 ), 255 ), 0 ),
50 Math.max( Math.min( parseInt( ( fx.pos * ( fx.end[ 2 ] - fx.start[ 2 ] ) ) + fx.start[ 2 ], 10 ), 255 ), 0 )
51 ].join( ',' ) + ')';
52 };
53 } );
54
55 }( jQuery ) );