Fix Color cloning by adding clone function and using it in Color#initialize.

This commit is contained in:
Jonathan Puckey 2011-05-21 17:13:25 +02:00
parent 0a86c2b34e
commit 024e8eb19b

View file

@ -158,10 +158,11 @@ var Color = this.Color = Base.extend(new function() {
} else {
// Called on a subclass instance. Return the converted
// color.
var color = Color.read(arguments, 0, 1);
return this._colorType
var color = arg._colorType ? arg
: Color.read(arguments, 0, 1);
return (this._colorType !== color._colorType)
? color.convert(this._colorType)
: color;
: color.clone();
}
} else if (typeof arg === 'string') {
var rgbColor = arg.match(/^#[0-9a-f]{3,6}$/i)
@ -196,6 +197,16 @@ var Color = this.Color = Base.extend(new function() {
}
},
clone: function(color) {
var copy = new this.constructor(),
components = this._components;
for (var i = 0, l = components.length; i < l; i++) {
var key = '_' + components[i];
copy[key] = this[key];
}
return copy;
},
convert: function(type) {
return this._colorType == type
? this