/* * Portions of this file are based on pieces of Yahoo User Interface Library * Copyright (c) 2007, Yahoo! Inc. All rights reserved. * YUI licensed under the BSD License: * http://developer.yahoo.net/yui/license.txt * <script type="text/javascript"> * */ (function() { Roo.lib.ColorAnim = function(el, attributes, duration, method) { Roo.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method); }; Roo.extend(Roo.lib.ColorAnim, Roo.lib.AnimBase); var fly = Roo.lib.AnimBase.fly; var Y = Roo.lib; var superclass = Y.ColorAnim.superclass; var proto = Y.ColorAnim.prototype; proto.toString = function() { var el = this.getEl(); var id = el.id || el.tagName; return ("ColorAnim " + id); }; proto.patterns.color = /color$/i; proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i; proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i; proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i; proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/; proto.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; }; // since this uses fly! - it cant be in ColorAnim (which does not have fly yet..) proto.getAttribute = function(attr) { var el = this.getEl(); if (this.patterns.color.test(attr)) { var val = fly(el).getStyle(attr); if (this.patterns.transparent.test(val)) { var parent = el.parentNode; val = fly(parent).getStyle(attr); while (parent && this.patterns.transparent.test(val)) { parent = parent.parentNode; val = fly(parent).getStyle(attr); if (parent.tagName.toUpperCase() == 'HTML') { val = '#fff'; } } } } else { val = superclass.getAttribute.call(this, attr); } return val; }; proto.getAttribute = function(attr) { var el = this.getEl(); if (this.patterns.color.test(attr)) { var val = fly(el).getStyle(attr); if (this.patterns.transparent.test(val)) { var parent = el.parentNode; val = fly(parent).getStyle(attr); while (parent && this.patterns.transparent.test(val)) { parent = parent.parentNode; val = fly(parent).getStyle(attr); if (parent.tagName.toUpperCase() == 'HTML') { val = '#fff'; } } } } else { val = superclass.getAttribute.call(this, attr); } return val; }; proto.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; }; proto.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; } }; })();