mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Override Item.extend() to merge the subclass' _serializeFields with the parent class' _serializeFields.
And have style fields always serialized in non-compact form for Color.
This commit is contained in:
parent
6d39a91c87
commit
489a785171
3 changed files with 23 additions and 12 deletions
|
@ -20,7 +20,20 @@
|
||||||
* is unique to their type, but share the underlying properties and functions
|
* is unique to their type, but share the underlying properties and functions
|
||||||
* that they inherit from Item.
|
* that they inherit from Item.
|
||||||
*/
|
*/
|
||||||
var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
var Item = this.Item = Base.extend(Callback, {
|
||||||
|
statics: {
|
||||||
|
/**
|
||||||
|
* Override Item.extend() to merge the subclass' _serializeFields with
|
||||||
|
* the parent class' _serializeFields.
|
||||||
|
*/
|
||||||
|
extend: function(src) {
|
||||||
|
if (src._serializeFields)
|
||||||
|
src._serializeFields = Base.merge(
|
||||||
|
this.prototype._serializeFields, src._serializeFields);
|
||||||
|
return this.base.apply(this, arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, /** @lends Item# */{
|
||||||
// Provide information about fields to be serialized, with their defaults
|
// Provide information about fields to be serialized, with their defaults
|
||||||
// that can be ommited.
|
// that can be ommited.
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
|
@ -140,18 +153,20 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
var props = {},
|
var props = {},
|
||||||
that = this;
|
that = this;
|
||||||
|
|
||||||
function serialize(fields) {
|
function serialize(fields, compact) {
|
||||||
for (var key in fields) {
|
for (var key in fields) {
|
||||||
var value = that[key];
|
var value = that[key];
|
||||||
if (!Base.equals(value, fields[key]))
|
if (!Base.equals(value, fields[key]))
|
||||||
props[key] = Base.serialize(value, true);
|
props[key] = Base.serialize(value, compact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize fields that this Item subclass defines first
|
// Serialize fields that this Item subclass defines first
|
||||||
serialize(this._serializeFields);
|
serialize(this._serializeFields, true);
|
||||||
// Serialize style fields, but only if they differ from defaults
|
// Serialize style fields, but only if they differ from defaults.
|
||||||
serialize(this._style._defaults);
|
// Use no compacting there, since colors always need their type
|
||||||
|
// identifiers.
|
||||||
|
serialize(this._style._defaults, false);
|
||||||
// There is no compact form for Item serialization, we always keep the
|
// There is no compact form for Item serialization, we always keep the
|
||||||
// type.
|
// type.
|
||||||
return [ this._type, props ];
|
return [ this._type, props ];
|
||||||
|
|
|
@ -20,9 +20,7 @@
|
||||||
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
_type: 'raster',
|
_type: 'raster',
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
name: null,
|
source: null
|
||||||
source: null,
|
|
||||||
matrix: new Matrix()
|
|
||||||
},
|
},
|
||||||
// Raster doesn't make the distinction between the different bounds,
|
// Raster doesn't make the distinction between the different bounds,
|
||||||
// so use the same name for all of them
|
// so use the same name for all of them
|
||||||
|
|
|
@ -21,10 +21,8 @@
|
||||||
var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
_type: 'path',
|
_type: 'path',
|
||||||
_serializeFields: {
|
_serializeFields: {
|
||||||
name: null,
|
|
||||||
segments: [],
|
segments: [],
|
||||||
closed: false,
|
closed: false
|
||||||
matrix: new Matrix()
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue