Add support for Item#data serialization.

This commit is contained in:
Jürg Lehni 2013-03-19 17:52:46 -07:00
parent 16b60d1b9e
commit 9c38a76525
2 changed files with 14 additions and 4 deletions

View file

@ -59,6 +59,14 @@ this.Base = Base.inject(/** @lends Base# */{
return Base.exportJson(this, options);
},
// To support JSON.stringify:
toJSON: function() {
// TODO: We should probably have exportJson() / importJson() deal with
// objects rather than strings too, so we can just delegate to those
// here.
return Base.serialize(this);
},
/**
* #_set() is part of the mechanism for constructors which take one object
* literal describing all the properties to be set on the created instance.

View file

@ -45,7 +45,8 @@ var Item = this.Item = Base.extend(Callback, {
blendMode: 'normal',
opacity: 1,
guide: false,
clipMask: false
clipMask: false,
data: {}
},
initialize: function(point) {
@ -142,15 +143,16 @@ var Item = this.Item = Base.extend(Callback, {
for (var key in fields) {
var value = that[key];
if (!Base.equals(value, fields[key]))
props[key] = Base.serialize(value, options, compact,
dictionary);
props[key] = Base.serialize(value, options,
// Do not use compact mode for data
compact && key !== 'data', dictionary);
}
}
// Serialize fields that this Item subclass defines first
serialize(this._serializeFields, true);
// Serialize style fields, but only if they differ from defaults.
// Use no compacting there, since colors always need their type
// Do not use compact mode here, since colors always need their type
// identifiers.
// Do not serialize styles on Groups and Layers, since they just unify
// their children's own styles.