summaryrefslogtreecommitdiff
path: root/resources/src/jquery/jquery.color.js
blob: a3cc8fc3af0d4020865e2a24dc5feaa7acd31584 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
 * jQuery Color Animations
 *
 * @author John Resig, 2007
 * @author Krinkle, 2011
 * Released under the MIT and GPL licenses.
 *
 * - 2011-01-05: Forked for MediaWiki. See also jQuery.colorUtil plugin
 */
( function ( $ ) {

	function getColor( elem, attr ) {
		/*jshint boss:true */
		var color;

		do {
			color = $.css( elem, attr );

			// Keep going until we find an element that has color, or we hit the body
			if ( color !== '' && color !== 'transparent' || $.nodeName( elem, 'body' ) ) {
				break;
			}

			attr = 'backgroundColor';
		} while ( elem = elem.parentNode );

		return $.colorUtil.getRGB( color );
	}

	// We override the animation for all of these color styles
	$.each( [
		'backgroundColor',
		'borderBottomColor',
		'borderLeftColor',
		'borderRightColor',
		'borderTopColor',
		'color',
		'outlineColor'
	], function ( i, attr ) {
		$.fx.step[ attr ] = function ( fx ) {
			if ( !fx.colorInit ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = $.colorUtil.getRGB( fx.end );
				fx.colorInit = true;
			}

			fx.elem.style[ attr ] = 'rgb(' + [
				Math.max( Math.min( parseInt( ( fx.pos * ( fx.end[ 0 ] - fx.start[ 0 ] ) ) + fx.start[ 0 ], 10 ), 255 ), 0 ),
				Math.max( Math.min( parseInt( ( fx.pos * ( fx.end[ 1 ] - fx.start[ 1 ] ) ) + fx.start[ 1 ], 10 ), 255 ), 0 ),
				Math.max( Math.min( parseInt( ( fx.pos * ( fx.end[ 2 ] - fx.start[ 2 ] ) ) + fx.start[ 2 ], 10 ), 255 ), 0 )
			].join( ',' ) + ')';
		};
	} );

}( jQuery ) );