mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Fix Color cloning by adding clone function and using it in Color#initialize.
This commit is contained in:
parent
0a86c2b34e
commit
024e8eb19b
1 changed files with 14 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue