Give any item / object that needs to be exported as a definition / symbol its own unique id.

This will be useful in SVG and JSON exporter.
This commit is contained in:
Jürg Lehni 2013-02-10 09:37:40 -08:00
parent 49728665e6
commit 565fb86430
4 changed files with 11 additions and 6 deletions

View file

@ -79,6 +79,8 @@ var GradientColor = this.GradientColor = Color.extend(/** @lends GradientColor#
* path.fillColor = gradientColor;
*/
initialize: function(gradient, origin, destination, hilite) {
// Define this GradientColor's unique id.
this._id = ++Base._uid;
this.gradient = gradient || new Gradient();
this.gradient._addOwner(this);
this.setOrigin(origin);

View file

@ -54,6 +54,11 @@ this.Base = Base.inject(/** @lends Base# */{
_types: {},
/**
* A uniqued id number, which when consumed needs to be increased by one
*/
_uid: 0,
extend: function(src) {
// Override Base.extend() with a version that registers classes that
// define #_type inside the Base._types lookup, for deserialization.

View file

@ -31,7 +31,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
initialize: function(point) {
// Define this Item's unique id.
this._id = ++Item._id;
this._id = ++Base._uid;
// If _project is already set, the item was already moved into the DOM
// hierarchy. Used by Layer, where it's added to project.layers instead
if (!this._project)
@ -270,7 +270,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
}
this._name = name || undefined;
this._changed(/*#=*/ ChangeFlag.ATTRIBUTE);
},
}
/**
* The path style of the item.
@ -312,10 +312,6 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
* var path2 = new Path.Circle(new Point(150, 50), 20);
* path2.style = myStyle;
*/
statics: {
_id: 0
}
}, Base.each(['locked', 'visible', 'blendMode', 'opacity', 'guide'],
// Produce getter/setters for properties. We need setters because we want to
// call _changed() if a property was modified.

View file

@ -57,6 +57,8 @@ var Symbol = this.Symbol = Base.extend(/** @lends Symbol# */{
* }
*/
initialize: function(item) {
// Define this Symbols's unique id.
this._id = ++Base._uid;
this.project = paper.project;
this.project.symbols.push(this);
this.setDefinition(item);