~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yuilib/3.13.0/anim-color/anim-color.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.13.0 (build 508226d)
 
3
Copyright 2013 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
 
 
8
YUI.add('anim-color', function (Y, NAME) {
 
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.getUpdatedColorValue = function(fromColor, toColor, elapsed, duration,  fn)
 
20
{
 
21
    fromColor = Y.Color.re_RGB.exec(Y.Color.toRGB(fromColor));
 
22
    toColor = Y.Color.re_RGB.exec(Y.Color.toRGB(toColor));
 
23
 
 
24
    if (!fromColor || fromColor.length < 3 || !toColor || toColor.length < 3) {
 
25
        Y.error('invalid from or to passed to color behavior');
 
26
    }
 
27
 
 
28
    return 'rgb(' + [
 
29
        Math.floor(fn(elapsed, NUM(fromColor[1]), NUM(toColor[1]) - NUM(fromColor[1]), duration)),
 
30
        Math.floor(fn(elapsed, NUM(fromColor[2]), NUM(toColor[2]) - NUM(fromColor[2]), duration)),
 
31
        Math.floor(fn(elapsed, NUM(fromColor[3]), NUM(toColor[3]) - NUM(fromColor[3]), duration))
 
32
    ].join(', ') + ')';
 
33
};
 
34
 
 
35
Y.Anim.behaviors.color = {
 
36
    set: function(anim, att, from, to, elapsed, duration, fn) {
 
37
        anim._node.setStyle(att, Y.Anim.getUpdatedColorValue(from, to, elapsed, duration, fn));
 
38
    },
 
39
 
 
40
    // TODO: default bgcolor const
 
41
    get: function(anim, att) {
 
42
        var val = anim._node.getComputedStyle(att);
 
43
        val = (val === 'transparent') ? 'rgb(255, 255, 255)' : val;
 
44
        return val;
 
45
    }
 
46
};
 
47
 
 
48
Y.each(['backgroundColor',
 
49
        'borderColor',
 
50
        'borderTopColor',
 
51
        'borderRightColor',
 
52
        'borderBottomColor',
 
53
        'borderLeftColor'],
 
54
        function(v) {
 
55
            Y.Anim.behaviors[v] = Y.Anim.behaviors.color;
 
56
        }
 
57
);
 
58
 
 
59
 
 
60
}, '3.13.0', {"requires": ["anim-base"]});