From 35b1f61bdadbb8bae8712e4940f7d72e99aa7a21 Mon Sep 17 00:00:00 2001 From: Eric Rowell Date: Sun, 19 May 2013 21:48:48 -0700 Subject: [PATCH] tied className into toJSON and create. deprecated shapeType property and getShapeType method --- src/Node.js | 35 ++++++-------------- src/Shape.js | 10 +----- src/plugins/Label.js | 2 +- src/plugins/Path.js | 2 +- src/plugins/RegularPolygon.js | 2 +- src/plugins/Star.js | 2 +- src/plugins/TextPath.js | 2 +- src/shapes/Blob.js | 2 +- src/shapes/Circle.js | 2 +- src/shapes/Image.js | 2 +- src/shapes/Line.js | 2 +- src/shapes/Polygon.js | 2 +- src/shapes/Rect.js | 2 +- src/shapes/Spline.js | 2 +- src/shapes/Sprite.js | 2 +- src/shapes/Text.js | 3 +- src/shapes/Wedge.js | 2 +- tests/js/unit/containerTests.js | 4 +-- tests/js/unit/plugins/pathTests.js | 2 +- tests/js/unit/plugins/regularPolygonTests.js | 2 +- tests/js/unit/plugins/starTests.js | 2 +- tests/js/unit/plugins/textPathTests.js | 2 +- tests/js/unit/shapes/blobTests.js | 2 +- tests/js/unit/shapes/circleTests.js | 2 +- tests/js/unit/shapes/imageTests.js | 2 +- tests/js/unit/shapes/lineTests.js | 2 +- tests/js/unit/shapes/polygonTests.js | 2 +- tests/js/unit/shapes/rectTests.js | 2 +- tests/js/unit/shapes/splineTests.js | 2 +- tests/js/unit/shapes/spriteTests.js | 2 +- tests/js/unit/shapes/textTests.js | 2 +- tests/js/unit/shapes/wedgeTests.js | 2 +- 32 files changed, 43 insertions(+), 65 deletions(-) diff --git a/src/Node.js b/src/Node.js index 495d2ff3..2fbac6a6 100644 --- a/src/Node.js +++ b/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])); } } diff --git a/src/Shape.js b/src/Shape.js index 87d2755f..446afd1c 100644 --- a/src/Shape.js +++ b/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]; diff --git a/src/plugins/Label.js b/src/plugins/Label.js index 9e38550a..7e12a28a 100644 --- a/src/plugins/Label.js +++ b/src/plugins/Label.js @@ -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) { diff --git a/src/plugins/Path.js b/src/plugins/Path.js index 636baa7b..3b6fbff7 100644 --- a/src/plugins/Path.js +++ b/src/plugins/Path.js @@ -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()); diff --git a/src/plugins/RegularPolygon.js b/src/plugins/RegularPolygon.js index 28c74d88..b0a72232 100644 --- a/src/plugins/RegularPolygon.js +++ b/src/plugins/RegularPolygon.js @@ -30,7 +30,7 @@ // call super constructor Kinetic.Shape.call(this, config); - this.shapeType = 'RegularPolygon'; + this.className = 'RegularPolygon'; this._setDrawFuncs(); }, drawFunc: function(canvas) { diff --git a/src/plugins/Star.js b/src/plugins/Star.js index a1f63413..40c09a98 100644 --- a/src/plugins/Star.js +++ b/src/plugins/Star.js @@ -32,7 +32,7 @@ // call super constructor Kinetic.Shape.call(this, config); - this.shapeType = 'Star'; + this.className = 'Star'; this._setDrawFuncs(); }, drawFunc: function(canvas) { diff --git a/src/plugins/TextPath.js b/src/plugins/TextPath.js index f9dc8866..75e222b5 100644 --- a/src/plugins/TextPath.js +++ b/src/plugins/TextPath.js @@ -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); diff --git a/src/shapes/Blob.js b/src/shapes/Blob.js index 595458ef..7b3bda17 100644 --- a/src/shapes/Blob.js +++ b/src/shapes/Blob.js @@ -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(); diff --git a/src/shapes/Circle.js b/src/shapes/Circle.js index bc8d2351..005af604 100644 --- a/src/shapes/Circle.js +++ b/src/shapes/Circle.js @@ -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) { diff --git a/src/shapes/Image.js b/src/shapes/Image.js index 1e2f1971..bb8fdb8a 100644 --- a/src/shapes/Image.js +++ b/src/shapes/Image.js @@ -37,7 +37,7 @@ // call super constructor Kinetic.Shape.call(this, config); - this.shapeType = IMAGE; + this.className = IMAGE; this._setDrawFuncs(); }, drawFunc: function(canvas) { diff --git a/src/shapes/Line.js b/src/shapes/Line.js index db552c7e..99f4bb2c 100644 --- a/src/shapes/Line.js +++ b/src/shapes/Line.js @@ -41,7 +41,7 @@ // call super constructor Kinetic.Shape.call(this, config); - this.shapeType = 'Line'; + this.className = 'Line'; this._setDrawFuncs(); }, drawFunc: function(canvas) { diff --git a/src/shapes/Polygon.js b/src/shapes/Polygon.js index d5efb186..9b7f3dd7 100644 --- a/src/shapes/Polygon.js +++ b/src/shapes/Polygon.js @@ -27,7 +27,7 @@ // call super constructor Kinetic.Shape.call(this, config); - this.shapeType = 'Polygon'; + this.className = 'Polygon'; this._setDrawFuncs(); }, drawFunc: function(canvas) { diff --git a/src/shapes/Rect.js b/src/shapes/Rect.js index ebcfdcf2..f6e2ecd9 100644 --- a/src/shapes/Rect.js +++ b/src/shapes/Rect.js @@ -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) { diff --git a/src/shapes/Spline.js b/src/shapes/Spline.js index 88abe751..6ca62565 100644 --- a/src/shapes/Spline.js +++ b/src/shapes/Spline.js @@ -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(); diff --git a/src/shapes/Sprite.js b/src/shapes/Sprite.js index 2b3168c0..5c8a5fca 100644 --- a/src/shapes/Sprite.js +++ b/src/shapes/Sprite.js @@ -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(); diff --git a/src/shapes/Text.js b/src/shapes/Text.js index 38a52832..dfcbc6e8 100644 --- a/src/shapes/Text.js +++ b/src/shapes/Text.js @@ -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 diff --git a/src/shapes/Wedge.js b/src/shapes/Wedge.js index 13b2692c..b44e373b 100644 --- a/src/shapes/Wedge.js +++ b/src/shapes/Wedge.js @@ -31,7 +31,7 @@ // call super constructor Kinetic.Shape.call(this, config); - this.shapeType = 'Wedge'; + this.className = 'Wedge'; this._setDrawFuncs(); }, drawFunc: function(canvas) { diff --git a/tests/js/unit/containerTests.js b/tests/js/unit/containerTests.js index c1c87aa0..3c3b1a31 100644 --- a/tests/js/unit/containerTests.js +++ b/tests/js/unit/containerTests.js @@ -111,9 +111,9 @@ Test.Modules.CONTAINER = { var node; node = stage.get('#myCircle')[0]; - test(node.shapeType === 'Circle', 'shape type should be Circle'); + test(node.className === 'Circle', 'className should be Circle'); node = layer.get('.myRect')[0]; - test(node.shapeType === 'Rect', 'shape type should be rect'); + test(node.className === 'Rect', 'className should be rect'); node = layer.get('#myLayer')[0]; test(node === undefined, 'node should be undefined'); node = stage.get('#myLayer')[0]; diff --git a/tests/js/unit/plugins/pathTests.js b/tests/js/unit/plugins/pathTests.js index edd917cc..3f4ee7be 100644 --- a/tests/js/unit/plugins/pathTests.js +++ b/tests/js/unit/plugins/pathTests.js @@ -46,7 +46,7 @@ Test.Modules.PATH = { path.setData('M200,100h100v50z'); - test(path.getShapeType() === 'Path', 'shape type should be Path'); + test(path.getClassName() === 'Path', 'getClassName should be Path'); }, 'add path with line cap and line join': function(containerId) { diff --git a/tests/js/unit/plugins/regularPolygonTests.js b/tests/js/unit/plugins/regularPolygonTests.js index 3c48e7a0..b66acfdb 100644 --- a/tests/js/unit/plugins/regularPolygonTests.js +++ b/tests/js/unit/plugins/regularPolygonTests.js @@ -25,7 +25,7 @@ Test.Modules.REGULAR_POLYGON = { layer.add(poly); stage.add(layer); - test(poly.getShapeType() === 'RegularPolygon', 'shape type should be RegularPolygon'); + test(poly.getClassName() === 'RegularPolygon', 'sgetClassName should be RegularPolygon'); }, 'add regular polygon square': function(containerId) { diff --git a/tests/js/unit/plugins/starTests.js b/tests/js/unit/plugins/starTests.js index b98a8c02..ba4d33f7 100644 --- a/tests/js/unit/plugins/starTests.js +++ b/tests/js/unit/plugins/starTests.js @@ -30,7 +30,7 @@ Test.Modules.STAR = { layer.add(star); stage.add(layer); - test(star.getShapeType() === 'Star', 'shape type should be Star'); + test(star.getClassName() === 'Star', 'getClassName should be Star'); }, 'add five point star with line join and shadow': function(containerId) { var stage = new Kinetic.Stage({ diff --git a/tests/js/unit/plugins/textPathTests.js b/tests/js/unit/plugins/textPathTests.js index 499f54e7..af0fd6ce 100644 --- a/tests/js/unit/plugins/textPathTests.js +++ b/tests/js/unit/plugins/textPathTests.js @@ -34,7 +34,7 @@ Test.Modules['TEXT PATH'] = { layer.add(textpath); stage.add(layer); - test(textpath.getShapeType() === 'TextPath', 'shape type should be TextPath'); + test(textpath.getClassName() === 'TextPath', 'getClassName should be TextPath'); }, 'Render Text Along two connected Bezier': function(containerId) { var stage = new Kinetic.Stage({ diff --git a/tests/js/unit/shapes/blobTests.js b/tests/js/unit/shapes/blobTests.js index 6ed57706..d2d4008a 100644 --- a/tests/js/unit/shapes/blobTests.js +++ b/tests/js/unit/shapes/blobTests.js @@ -60,7 +60,7 @@ Test.Modules.BLOB = { test(blob1.getTension() === 0.8, 'blob1 tension should be 0.8'); test(blob2.getTension() === 1.2, 'blob2 tension should be 1.2'); - test(blob1.getShapeType() === 'Blob', 'shape type should be Blob'); + test(blob1.getClassName() === 'Blob', 'getClassName should be Blob'); } diff --git a/tests/js/unit/shapes/circleTests.js b/tests/js/unit/shapes/circleTests.js index bcbbc321..6b44761a 100644 --- a/tests/js/unit/shapes/circleTests.js +++ b/tests/js/unit/shapes/circleTests.js @@ -33,7 +33,7 @@ Test.Modules.CIRCLE = { test(attrs.strokeWidth === 4, 'strokeWidth attr should be strokeWidth'); test(attrs.name === 'myCircle', 'name attr should be myCircle'); test(attrs.draggable === true, 'draggable attr should be true'); - test(circle.getShapeType() === 'Circle', 'shape type should be Circle'); + test(circle.getClassName() === 'Circle', 'getClassName should be Circle'); }, 'add circle with pattern fill': function(containerId) { var imageObj = new Image(); diff --git a/tests/js/unit/shapes/imageTests.js b/tests/js/unit/shapes/imageTests.js index f676b5ed..2385b1db 100644 --- a/tests/js/unit/shapes/imageTests.js +++ b/tests/js/unit/shapes/imageTests.js @@ -118,7 +118,7 @@ Test.Modules.IMAGE = { //document.body.appendChild(layer.bufferCanvas.element) - test(darth.getShapeType() === 'Image', 'shape type should be Image'); + test(darth.getClassName() === 'Image', 'getClassName should be Image'); }; imageObj.src = '../assets/darth-vader.jpg'; diff --git a/tests/js/unit/shapes/lineTests.js b/tests/js/unit/shapes/lineTests.js index b7072bf2..b56fdb5e 100644 --- a/tests/js/unit/shapes/lineTests.js +++ b/tests/js/unit/shapes/lineTests.js @@ -47,7 +47,7 @@ Test.Modules.LINE = { line.setPoints([73, 160, 340, 23]); test(line.getPoints()[0].x === 73, 'first point x should be 73'); - test(line.getShapeType() === 'Line', 'shape type should be Line'); + test(line.getClassName() === 'Line', 'getClassName should be Line'); }, 'test default ponts array for two lines': function(containerId) { var stage = new Kinetic.Stage({ diff --git a/tests/js/unit/shapes/polygonTests.js b/tests/js/unit/shapes/polygonTests.js index d9c1449f..0d11996d 100644 --- a/tests/js/unit/shapes/polygonTests.js +++ b/tests/js/unit/shapes/polygonTests.js @@ -37,7 +37,7 @@ Test.Modules.POLYGON - { layer.add(poly); stage.add(layer); - test(poly.getShapeType() === 'Polygon', 'shape type should be Polygon'); + test(poly.getClassName() === 'Polygon', 'getClassName should be Polygon'); } }; diff --git a/tests/js/unit/shapes/rectTests.js b/tests/js/unit/shapes/rectTests.js index 59114c41..ae5d01c5 100644 --- a/tests/js/unit/shapes/rectTests.js +++ b/tests/js/unit/shapes/rectTests.js @@ -25,7 +25,7 @@ Test.Modules.RECT = { layer.add(rect); stage.add(layer); - test(rect.getShapeType() === 'Rect', 'shape type should be Rect'); + test(rect.getClassName() === 'Rect', 'className should be Rect'); }, 'add stroke rect': function(containerId) { var stage = new Kinetic.Stage({ diff --git a/tests/js/unit/shapes/splineTests.js b/tests/js/unit/shapes/splineTests.js index 66cccfed..f9fbb205 100644 --- a/tests/js/unit/shapes/splineTests.js +++ b/tests/js/unit/shapes/splineTests.js @@ -79,7 +79,7 @@ Test.Modules.SPLINE = { //console.log(layer.toDataURL()); testDataUrl(layer.toDataURL(), 'curvy lines', 'problem with curvy lines'); - test(line1.getShapeType() === 'Spline', 'shape type should be Spline'); + test(line1.getClassName() === 'Spline', 'getClassName should be Spline'); }, 'create from points represented as a flat array': function(containerId) { diff --git a/tests/js/unit/shapes/spriteTests.js b/tests/js/unit/shapes/spriteTests.js index e1280f9f..0d6c298a 100644 --- a/tests/js/unit/shapes/spriteTests.js +++ b/tests/js/unit/shapes/spriteTests.js @@ -112,7 +112,7 @@ Test.Modules.SPRITE = { }, 3000); //document.body.appendChild(layer.bufferCanvas.element) - test(sprite.getShapeType() === 'Sprite', 'shape type should be Sprite'); + test(sprite.getClassName() === 'Sprite', 'getClassName should be Sprite'); test(sprite.getIndex() === 0, 'sprite index should default to 0'); }; diff --git a/tests/js/unit/shapes/textTests.js b/tests/js/unit/shapes/textTests.js index ef12cfae..f2b8444c 100644 --- a/tests/js/unit/shapes/textTests.js +++ b/tests/js/unit/shapes/textTests.js @@ -55,7 +55,7 @@ Test.Modules.Text = { layer.add(group); stage.add(layer); - test(text.getShapeType() === 'Text', 'shape type should be Text'); + test(text.getClassName() === 'Text', 'getClassName should be Text'); }, 'text getters and setters': function(containerId) { var stage = new Kinetic.Stage({ diff --git a/tests/js/unit/shapes/wedgeTests.js b/tests/js/unit/shapes/wedgeTests.js index e8ea50d6..8a325a1d 100644 --- a/tests/js/unit/shapes/wedgeTests.js +++ b/tests/js/unit/shapes/wedgeTests.js @@ -24,7 +24,7 @@ Test.Modules.Wedge = { //console.log(layer.toDataURL()); testDataUrl(layer.toDataURL(), 'wedge', 'problem rendering wedge'); - test(wedge.getShapeType() === 'Wedge', 'shape type should be Wedge'); + test(wedge.getClassName() === 'Wedge', 'getClassName should be Wedge'); }, 'set wedge angle using degrees': function(containerId) { var stage = new Kinetic.Stage({