tied className into toJSON and create. deprecated shapeType property and getShapeType method

This commit is contained in:
Eric Rowell
2013-05-19 21:48:48 -07:00
parent 7069bf9e0c
commit 35b1f61bda
32 changed files with 43 additions and 65 deletions

View File

@@ -661,8 +661,8 @@
}
}
obj.className = this.className;
obj.nodeType = this.nodeType;
obj.shapeType = this.shapeType;
return obj;
},
@@ -817,8 +817,8 @@
*/
clone: function(obj) {
// instantiate new node
var classType = this.shapeType || this.nodeType,
node = new Kinetic[classType](this.attrs),
var className = this.getClassName(),
node = new Kinetic[className](this.attrs),
key, allListeners, len, n, listener;
// copy over listeners
@@ -963,7 +963,7 @@
* @memberof Kinetic.Node.prototype
*/
getClassName: function() {
return this.className || this.shapeType || this.nodeType;
return this.className || this.nodeType;
},
/**
* get the node type, which may return Stage, Layer, Group, or Node
@@ -1324,33 +1324,20 @@
return this._createNode(JSON.parse(json), container);
};
Kinetic.Node._createNode = function(obj, container) {
var type, no, len, n;
// determine type
if(obj.nodeType === SHAPE) {
// add custom shape
if(obj.shapeType === undefined) {
type = SHAPE;
}
// add standard shape
else {
type = obj.shapeType;
}
}
else {
type = obj.nodeType;
}
var className = Kinetic.Node.prototype.getClassName.call(obj),
children = obj.children,
no, len, n;
// if container was passed in, add it to attrs
if(container) {
obj.attrs.container = container;
}
no = new Kinetic[type](obj.attrs);
if(obj.children) {
len = obj.children.length;
no = new Kinetic[className](obj.attrs);
if(children) {
len = children.length;
for(n = 0; n < len; n++) {
no.add(this._createNode(obj.children[n]));
no.add(this._createNode(children[n]));
}
}

View File

@@ -71,7 +71,7 @@
return !!(this.getFill() || this.getFillPatternImage() || this.getFillLinearGradientColorStops() || this.getFillRadialGradientColorStops());
},
_get: function(selector) {
return this.nodeType === selector || this.shapeType === selector ? [this] : [];
return this.className === selector || this.nodeType === selector ? [this] : [];
},
/**
* determines if point is in the shape, regardless if other shapes are on top of it. Note: because
@@ -174,14 +174,6 @@
disableDashArray: function() {
this._setAttr('dashArrayEnabled', false);
},
/**
* get shape type. Ex. 'Circle', 'Rect', 'Text', etc.
* @method
* @memberof Kinetic.Shape.prototype
*/
getShapeType: function() {
return this.shapeType;
},
destroy: function() {
Kinetic.Node.prototype.destroy.call(this);
delete Kinetic.Global.shapes[this.colorKey];

View File

@@ -187,7 +187,7 @@
_initTag: function(config) {
this.createAttrs();
Kinetic.Shape.call(this, config);
this.shapeType = 'Tag';
this.className = 'Tag';
this._setDrawFuncs();
},
drawFunc: function(canvas) {

View File

@@ -29,7 +29,7 @@
// call super constructor
Kinetic.Shape.call(this, config);
this.shapeType = 'Path';
this.className = 'Path';
this._setDrawFuncs();
this.dataArray = Kinetic.Path.parsePathData(this.getData());

View File

@@ -30,7 +30,7 @@
// call super constructor
Kinetic.Shape.call(this, config);
this.shapeType = 'RegularPolygon';
this.className = 'RegularPolygon';
this._setDrawFuncs();
},
drawFunc: function(canvas) {

View File

@@ -32,7 +32,7 @@
// call super constructor
Kinetic.Shape.call(this, config);
this.shapeType = 'Star';
this.className = 'Star';
this._setDrawFuncs();
},
drawFunc: function(canvas) {

View File

@@ -55,7 +55,7 @@
this._fillFunc = _fillFunc;
this._strokeFunc = _strokeFunc;
this.shapeType = 'TextPath';
this.className = 'TextPath';
this._setDrawFuncs();
this.dataArray = Kinetic.Path.parsePathData(this.attrs.data);

View File

@@ -28,7 +28,7 @@
_initBlob: function(config) {
// call super constructor
Kinetic.Spline.call(this, config);
this.shapeType = 'Blob';
this.className = 'Blob';
},
drawFunc: function(canvas) {
var points = this.getPoints(), length = points.length, context = canvas.getContext(), tension = this.getTension();

View File

@@ -36,7 +36,7 @@
this.createAttrs();
// call super constructor
Kinetic.Shape.call(this, config);
this.shapeType = 'Circle';
this.className = 'Circle';
this._setDrawFuncs();
},
drawFunc: function(canvas) {

View File

@@ -37,7 +37,7 @@
// call super constructor
Kinetic.Shape.call(this, config);
this.shapeType = IMAGE;
this.className = IMAGE;
this._setDrawFuncs();
},
drawFunc: function(canvas) {

View File

@@ -41,7 +41,7 @@
// call super constructor
Kinetic.Shape.call(this, config);
this.shapeType = 'Line';
this.className = 'Line';
this._setDrawFuncs();
},
drawFunc: function(canvas) {

View File

@@ -27,7 +27,7 @@
// call super constructor
Kinetic.Shape.call(this, config);
this.shapeType = 'Polygon';
this.className = 'Polygon';
this._setDrawFuncs();
},
drawFunc: function(canvas) {

View File

@@ -25,7 +25,7 @@
_initRect: function(config) {
this.createAttrs();
Kinetic.Shape.call(this, config);
this.shapeType = 'Rect';
this.className = 'Rect';
this._setDrawFuncs();
},
drawFunc: function(canvas) {

View File

@@ -52,7 +52,7 @@
this.createAttrs();
// call super constructor
Kinetic.Line.call(this, config);
this.shapeType = 'Spline';
this.className = 'Spline';
},
drawFunc: function(canvas) {
var points = this.getPoints(), length = points.length, context = canvas.getContext(), tension = this.getTension();

View File

@@ -76,7 +76,7 @@
// call super constructor
Kinetic.Shape.call(this, config);
this.shapeType = 'Sprite';
this.className = 'Sprite';
this._setDrawFuncs();
this.anim = new Kinetic.Animation();

View File

@@ -78,10 +78,9 @@
// call super constructor
Kinetic.Shape.call(this, config);
this.shapeType = TEXT;
this._fillFunc = _fillFunc;
this._strokeFunc = _strokeFunc;
this.shapeType = TEXT_UPPER;
this.className = TEXT_UPPER;
this._setDrawFuncs();
// update text data for certain attr changes

View File

@@ -31,7 +31,7 @@
// call super constructor
Kinetic.Shape.call(this, config);
this.shapeType = 'Wedge';
this.className = 'Wedge';
this._setDrawFuncs();
},
drawFunc: function(canvas) {