Skip to content

Commit

Permalink
Introduced namespace attribute for objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmageddon committed Feb 15, 2020
1 parent 529e370 commit 7f7827e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@
*/
type: 'object',

/**
* Namespace the constructor of the object lies within.
* If set to null, the fabric namespace is used.
*
* @type String
* @default
*/
namespace: null,

/**
* Horizontal origin of transformation of an object (one of "left", "right", "center")
* See http://jsfiddle.net/1ow02gea/244/ on how originX/originY affect objects in groups
Expand Down Expand Up @@ -822,6 +831,7 @@
object = {
type: this.type,
version: fabric.version,
namespace: this.namespace,
originX: this.originX,
originY: this.originY,
left: toFixed(this.left, NUM_FRACTION_DIGITS),
Expand Down Expand Up @@ -1919,7 +1929,7 @@
fabric.Object.NUM_FRACTION_DIGITS = 2;

fabric.Object._fromObject = function(className, object, callback, extraParam) {
var klass = typeof className === 'function' ? className : fabric[className];
var klass = fabric.util.getKlass(className, object.namespace);
object = clone(object, true);
fabric.util.enlivenPatterns([object.fill, object.stroke], function(patterns) {
if (typeof patterns[0] !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion src/util/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@
onLoaded();
return;
}
var klass = fabric.util.getKlass(o.type, namespace);
var klass = fabric.util.getKlass(o.type, o.namespace || namespace);
klass.fromObject(o, function (obj, error) {
error || (enlivenedObjects[index] = obj);
reviver && reviver(o, obj, error);
Expand Down

0 comments on commit 7f7827e

Please sign in to comment.