1 |
efrain |
1 |
YUI.add('anim-color', function (Y, NAME) {
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Adds support for color properties in <code>to</code>
|
|
|
5 |
* and <code>from</code> attributes.
|
|
|
6 |
* @module anim
|
|
|
7 |
* @submodule anim-color
|
|
|
8 |
*/
|
|
|
9 |
|
|
|
10 |
var NUM = Number;
|
|
|
11 |
|
|
|
12 |
Y.Anim.getUpdatedColorValue = function(fromColor, toColor, elapsed, duration, fn)
|
|
|
13 |
{
|
|
|
14 |
fromColor = Y.Color.re_RGB.exec(Y.Color.toRGB(fromColor));
|
|
|
15 |
toColor = Y.Color.re_RGB.exec(Y.Color.toRGB(toColor));
|
|
|
16 |
|
|
|
17 |
if (!fromColor || fromColor.length < 3 || !toColor || toColor.length < 3) {
|
|
|
18 |
Y.error('invalid from or to passed to color behavior');
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
return 'rgb(' + [
|
|
|
22 |
Math.floor(fn(elapsed, NUM(fromColor[1]), NUM(toColor[1]) - NUM(fromColor[1]), duration)),
|
|
|
23 |
Math.floor(fn(elapsed, NUM(fromColor[2]), NUM(toColor[2]) - NUM(fromColor[2]), duration)),
|
|
|
24 |
Math.floor(fn(elapsed, NUM(fromColor[3]), NUM(toColor[3]) - NUM(fromColor[3]), duration))
|
|
|
25 |
].join(', ') + ')';
|
|
|
26 |
};
|
|
|
27 |
|
|
|
28 |
Y.Anim.behaviors.color = {
|
|
|
29 |
set: function(anim, att, from, to, elapsed, duration, fn) {
|
|
|
30 |
anim._node.setStyle(att, Y.Anim.getUpdatedColorValue(from, to, elapsed, duration, fn));
|
|
|
31 |
},
|
|
|
32 |
|
|
|
33 |
// TODO: default bgcolor const
|
|
|
34 |
get: function(anim, att) {
|
|
|
35 |
var val = anim._node.getComputedStyle(att);
|
|
|
36 |
val = (val === 'transparent') ? 'rgb(255, 255, 255)' : val;
|
|
|
37 |
return val;
|
|
|
38 |
}
|
|
|
39 |
};
|
|
|
40 |
|
|
|
41 |
Y.each(['backgroundColor',
|
|
|
42 |
'borderColor',
|
|
|
43 |
'borderTopColor',
|
|
|
44 |
'borderRightColor',
|
|
|
45 |
'borderBottomColor',
|
|
|
46 |
'borderLeftColor'],
|
|
|
47 |
function(v) {
|
|
|
48 |
Y.Anim.behaviors[v] = Y.Anim.behaviors.color;
|
|
|
49 |
}
|
|
|
50 |
);
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
}, '3.18.1', {"requires": ["anim-base"]});
|