Implement JSON serialization for Gradient and GradientColor.

This commit is contained in:
Jürg Lehni 2013-02-11 19:22:18 -08:00
parent e7bb334c6a
commit 366524d0a7
4 changed files with 19 additions and 2 deletions

View file

@ -320,8 +320,8 @@ var Color = this.Color = Base.extend(new function() {
* @ignore
*/
extend: function(src) {
if (src._type) {
var comps = components[src._type];
var comps = components[src._type];
if (comps) {
// Automatically produce the _components field, adding alpha
src._components = comps.concat(['alpha']);
Base.each(comps, function(name) {

View file

@ -33,6 +33,11 @@ var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
this.type = type || 'linear';
},
_serialize: function(dictionary) {
return dictionary.get(this) || dictionary.set(this, Base.serialize(
[this._type, this._stops, this.type], true, dictionary));
},
/**
* Called by various setters whenever a gradient value changes
*/

View file

@ -16,6 +16,7 @@
* @class The GradientColor object.
*/
var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor# */{
_type: 'gradientcolor',
/**
* Creates a gradient color object.
@ -97,6 +98,13 @@ var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor#
this._hilite);
},
_serialize: function(dictionary) {
var values = [ this.gradient, this._origin, this._destination ];
if (this._hilite)
values.push(this._hilite);
return Base.serialize(values, true, dictionary);
},
/**
* The origin point of the gradient.
*

View file

@ -53,6 +53,10 @@ var GradientStop = this.GradientStop = Base.extend(/** @lends GradientStop# */{
return new GradientStop(this._color.clone(), this._rampPoint);
},
_serialize: function(dictionary) {
return Base.serialize([this._color, this._rampPoint], false, dictionary);
},
/**
* Called by various setters whenever a value changes
*/