ColorAnim.js
(function() {
YAHOO.util.ColorAnim = function(el, attributes, duration, method) {
YAHOO.util.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);
};
YAHOO.extend(YAHOO.util.ColorAnim, YAHOO.util.Anim);
var Y = YAHOO.util;
var superclass = Y.ColorAnim.superclass;
var prototype = Y.ColorAnim.prototype;
prototype.toString = function() {
var el = this.getEl();
var id = el.id || el.tagName;
return ("ColorAnim " + id);
};
prototype.patterns.color = /color$/i;
prototype.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;
prototype.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;
prototype.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;
prototype.parseColor = function(s) {
if (s.length == 3) { return s; }
var c = this.patterns.hex.exec(s);
if (c && c.length == 4) {
return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];
}
c = this.patterns.rgb.exec(s);
if (c && c.length == 4) {
return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];
}
c = this.patterns.hex3.exec(s);
if (c && c.length == 4) {
return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];
}
return null;
};
prototype.getAttribute = function(attr) {
var el = this.getEl();
if ( this.patterns.color.test(attr) ) {
var val = YAHOO.util.Dom.getStyle(el, attr);
if (val == 'transparent') {
var parent = el.parentNode;
val = Y.Dom.getStyle(parent, attr);
while (parent && val == 'transparent') {
parent = parent.parentNode;
val = Y.Dom.getStyle(parent, attr);
if (parent.tagName.toUpperCase() == 'HTML') {
val = 'ffffff';
}
}
}
} else {
val = superclass.getAttribute.call(this, attr);
}
return val;
};
prototype.doMethod = function(attr, start, end) {
var val;
if ( this.patterns.color.test(attr) ) {
val = [];
for (var i = 0, len = start.length; i < len; ++i) {
val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
}
val = 'rgb('+Math.floor(val[0])+','+Math.floor(val[1])+','+Math.floor(val[2])+')';
}
else {
val = superclass.doMethod.call(this, attr, start, end);
}
return val;
};
prototype.setRuntimeAttribute = function(attr) {
superclass.setRuntimeAttribute.call(this, attr);
if ( this.patterns.color.test(attr) ) {
var attributes = this.attributes;
var start = this.parseColor(this.runtimeAttributes[attr].start);
var end = this.parseColor(this.runtimeAttributes[attr].end);
if ( typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined' ) {
end = this.parseColor(attributes[attr].by);
for (var i = 0, len = start.length; i < len; ++i) {
end[i] = start[i] + end[i];
}
}
this.runtimeAttributes[attr].start = start;
this.runtimeAttributes[attr].end = end;
}
};
})();