2 * Portions of this file are based on pieces of Yahoo User Interface Library
3 * Copyright (c) 2007, Yahoo! Inc. All rights reserved.
4 * YUI licensed under the BSD License:
5 * http://developer.yahoo.net/yui/license.txt
6 * <script type="text/javascript">
11 Roo.lib.ColorAnim = function(el, attributes, duration, method) {
12 Roo.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
15 Roo.extend(Roo.lib.ColorAnim, Roo.lib.AnimBase);
17 var fly = Roo.lib.AnimBase.fly;
19 var superclass = Y.ColorAnim.superclass;
20 var proto = Y.ColorAnim.prototype;
22 proto.toString = function() {
23 var el = this.getEl();
24 var id = el.id || el.tagName;
25 return ("ColorAnim " + id);
28 proto.patterns.color = /color$/i;
29 proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
30 proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
31 proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
32 proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/;
35 proto.parseColor = function(s) {
40 var c = this.patterns.hex.exec(s);
41 if (c && c.length == 4) {
42 return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
45 c = this.patterns.rgb.exec(s);
46 if (c && c.length == 4) {
47 return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
50 c = this.patterns.hex3.exec(s);
51 if (c && c.length == 4) {
52 return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
57 // since this uses fly! - it cant be in ColorAnim (which does not have fly yet..)
58 proto.getAttribute = function(attr) {
59 var el = this.getEl();
60 if (this.patterns.color.test(attr)) {
61 var val = fly(el).getStyle(attr);
63 if (this.patterns.transparent.test(val)) {
64 var parent = el.parentNode;
65 val = fly(parent).getStyle(attr);
67 while (parent && this.patterns.transparent.test(val)) {
68 parent = parent.parentNode;
69 val = fly(parent).getStyle(attr);
70 if (parent.tagName.toUpperCase() == 'HTML') {
76 val = superclass.getAttribute.call(this, attr);
81 proto.getAttribute = function(attr) {
82 var el = this.getEl();
83 if (this.patterns.color.test(attr)) {
84 var val = fly(el).getStyle(attr);
86 if (this.patterns.transparent.test(val)) {
87 var parent = el.parentNode;
88 val = fly(parent).getStyle(attr);
90 while (parent && this.patterns.transparent.test(val)) {
91 parent = parent.parentNode;
92 val = fly(parent).getStyle(attr);
93 if (parent.tagName.toUpperCase() == 'HTML') {
99 val = superclass.getAttribute.call(this, attr);
105 proto.doMethod = function(attr, start, end) {
108 if (this.patterns.color.test(attr)) {
110 for (var i = 0, len = start.length; i < len; ++i) {
111 val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
114 val = 'rgb(' + Math.floor(val[0]) + ',' + Math.floor(val[1]) + ',' + Math.floor(val[2]) + ')';
117 val = superclass.doMethod.call(this, attr, start, end);
123 proto.setRuntimeAttribute = function(attr) {
124 superclass.setRuntimeAttribute.call(this, attr);
126 if (this.patterns.color.test(attr)) {
127 var attributes = this.attributes;
128 var start = this.parseColor(this.runtimeAttributes[attr].start);
129 var end = this.parseColor(this.runtimeAttributes[attr].end);
131 if (typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined') {
132 end = this.parseColor(attributes[attr].by);
134 for (var i = 0, len = start.length; i < len; ++i) {
135 end[i] = start[i] + end[i];
139 this.runtimeAttributes[attr].start = start;
140 this.runtimeAttributes[attr].end = end;