Make Color#toString() work for gradients.

This commit is contained in:
Jürg Lehni 2013-04-09 01:26:51 -07:00
parent 5209e97c8d
commit b3256684fb

View file

@ -337,7 +337,7 @@ var Color = this.Color = Base.extend(new function() {
if (this._read && type) if (this._read && type)
read = 1; read = 1;
} }
// Define this GradientColor's unique id. // Define this gradient Color's unique id.
if (type === 'gradient') if (type === 'gradient')
this._id = ++Base._uid; this._id = ++Base._uid;
// Default fallbacks: rgb, black // Default fallbacks: rgb, black
@ -486,9 +486,14 @@ var Color = this.Color = Base.extend(new function() {
toString: function() { toString: function() {
var properties = types[this._type], var properties = types[this._type],
parts = [], parts = [],
isGradient = this._type === 'gradient',
format = Format.number; format = Format.number;
for (var i = 0, l = properties.length; i < l; i++) for (var i = 0, l = properties.length; i < l; i++) {
parts.push(properties[i] + ': ' + format(this._components[i])); var value = this._components[i];
if (value != null)
parts.push(properties[i] + ': '
+ (isGradient ? value : format(value)));
}
if (this._alpha != null) if (this._alpha != null)
parts.push('alpha: ' + format(this._alpha)); parts.push('alpha: ' + format(this._alpha));
return '{ ' + parts.join(', ') + ' }'; return '{ ' + parts.join(', ') + ' }';