From 565fb86430a1d5b52fe42f65a75bcc0e1f955d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 10 Feb 2013 09:37:40 -0800 Subject: [PATCH] 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. --- src/color/GradientColor.js | 2 ++ src/core/Base.js | 5 +++++ src/item/Item.js | 8 ++------ src/project/Symbol.js | 2 ++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/color/GradientColor.js b/src/color/GradientColor.js index 1486f16a..8971a4e7 100644 --- a/src/color/GradientColor.js +++ b/src/color/GradientColor.js @@ -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); diff --git a/src/core/Base.js b/src/core/Base.js index d182ae3b..96d9fc9c 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -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. diff --git a/src/item/Item.js b/src/item/Item.js index c0f7bee1..f15ff9e1 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -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. diff --git a/src/project/Symbol.js b/src/project/Symbol.js index 95040136..eb7cb1ff 100644 --- a/src/project/Symbol.js +++ b/src/project/Symbol.js @@ -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);