]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/anim/anim-color.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / anim / anim-color.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('anim-color', function(Y) {
9
10 /**
11  * Adds support for color properties in <code>to</code>
12  * and <code>from</code> attributes.
13  * @module anim
14  * @submodule anim-color
15  */
16
17 var NUM = Number;
18
19 Y.Anim.behaviors.color = {
20     set: function(anim, att, from, to, elapsed, duration, fn) {
21         from = Y.Color.re_RGB.exec(Y.Color.toRGB(from));
22         to = Y.Color.re_RGB.exec(Y.Color.toRGB(to));
23
24         if (!from || from.length < 3 || !to || to.length < 3) {
25             Y.error('invalid from or to passed to color behavior');
26         }
27
28         anim._node.setStyle(att, 'rgb(' + [
29             Math.floor(fn(elapsed, NUM(from[1]), NUM(to[1]) - NUM(from[1]), duration)),
30             Math.floor(fn(elapsed, NUM(from[2]), NUM(to[2]) - NUM(from[2]), duration)),
31             Math.floor(fn(elapsed, NUM(from[3]), NUM(to[3]) - NUM(from[3]), duration))
32         ].join(', ') + ')');
33     },
34     
35     // TODO: default bgcolor const
36     get: function(anim, att) {
37         var val = anim._node.getComputedStyle(att);
38         val = (val === 'transparent') ? 'rgb(255, 255, 255)' : val;
39         return val;
40     }
41 };
42
43 Y.each(['backgroundColor',
44         'borderColor',
45         'borderTopColor',
46         'borderRightColor', 
47         'borderBottomColor', 
48         'borderLeftColor'],
49         function(v, i) {
50             Y.Anim.behaviors[v] = Y.Anim.behaviors.color;
51         }
52 );
53
54
55 }, '3.3.0' ,{requires:['anim-base']});