mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
tied className into toJSON and create. deprecated shapeType property and getShapeType method
This commit is contained in:
35
src/Node.js
35
src/Node.js
@@ -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]));
|
||||
}
|
||||
}
|
||||
|
||||
|
10
src/Shape.js
10
src/Shape.js
@@ -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];
|
||||
|
@@ -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) {
|
||||
|
@@ -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());
|
||||
|
@@ -30,7 +30,7 @@
|
||||
|
||||
// call super constructor
|
||||
Kinetic.Shape.call(this, config);
|
||||
this.shapeType = 'RegularPolygon';
|
||||
this.className = 'RegularPolygon';
|
||||
this._setDrawFuncs();
|
||||
},
|
||||
drawFunc: function(canvas) {
|
||||
|
@@ -32,7 +32,7 @@
|
||||
|
||||
// call super constructor
|
||||
Kinetic.Shape.call(this, config);
|
||||
this.shapeType = 'Star';
|
||||
this.className = 'Star';
|
||||
this._setDrawFuncs();
|
||||
},
|
||||
drawFunc: function(canvas) {
|
||||
|
@@ -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);
|
||||
|
@@ -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();
|
||||
|
@@ -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) {
|
||||
|
@@ -37,7 +37,7 @@
|
||||
|
||||
// call super constructor
|
||||
Kinetic.Shape.call(this, config);
|
||||
this.shapeType = IMAGE;
|
||||
this.className = IMAGE;
|
||||
this._setDrawFuncs();
|
||||
},
|
||||
drawFunc: function(canvas) {
|
||||
|
@@ -41,7 +41,7 @@
|
||||
|
||||
// call super constructor
|
||||
Kinetic.Shape.call(this, config);
|
||||
this.shapeType = 'Line';
|
||||
this.className = 'Line';
|
||||
this._setDrawFuncs();
|
||||
},
|
||||
drawFunc: function(canvas) {
|
||||
|
@@ -27,7 +27,7 @@
|
||||
|
||||
// call super constructor
|
||||
Kinetic.Shape.call(this, config);
|
||||
this.shapeType = 'Polygon';
|
||||
this.className = 'Polygon';
|
||||
this._setDrawFuncs();
|
||||
},
|
||||
drawFunc: function(canvas) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
@@ -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
|
||||
|
@@ -31,7 +31,7 @@
|
||||
|
||||
// call super constructor
|
||||
Kinetic.Shape.call(this, config);
|
||||
this.shapeType = 'Wedge';
|
||||
this.className = 'Wedge';
|
||||
this._setDrawFuncs();
|
||||
},
|
||||
drawFunc: function(canvas) {
|
||||
|
Reference in New Issue
Block a user