From 99e7ad4bf0bef625776c8052d77c9e112096b357 Mon Sep 17 00:00:00 2001 From: Eric Rowell Date: Fri, 10 Jan 2014 22:58:55 -0800 Subject: [PATCH] added back compat Factor method and plugged in the methods that changed with the 5.0.0 release --- src/Factory.js | 7 +++++++ src/Node.js | 14 ++++++++++---- src/Shape.js | 13 +++++++++++++ src/shapes/Sprite.js | 6 ++++++ src/shapes/Wedge.js | 6 ++++++ test/unit/Node-test.js | 2 +- test/unit/Shape-test.js | 6 ++++++ 7 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/Factory.js b/src/Factory.js index e8a8df86..e02dc5d2 100644 --- a/src/Factory.js +++ b/src/Factory.js @@ -124,6 +124,13 @@ return this[getter](); } } + }, + backCompat: function(constructor, methods) { + var key; + + for (key in methods) { + constructor.prototype[key] = constructor.prototype[methods[key]]; + } } }; })(); \ No newline at end of file diff --git a/src/Node.js b/src/Node.js index 7f526dd4..c82bbc79 100644 --- a/src/Node.js +++ b/src/Node.js @@ -132,14 +132,14 @@ * height: 200
* });

* - * // cache a node and show a red border around the bounding box
+ * // cache a node and draw a red border around the bounding box
* // for debugging purposes
* node.cache({
* x: -30,
* y: -30,
* width: 100,
* height: 200,
- * showBorder: true
+ * drawBorder: true
* }); */ cache: function(config) { @@ -148,7 +148,7 @@ y = conf.y || 0, width = conf.width || this.width(), height = conf.height || this.height(), - showBorder = conf.showBorder || false, + drawBorder = conf.drawBorder || false, cachedSceneCanvas = new Kinetic.SceneCanvas({ pixelRatio: 1, width: width, @@ -179,7 +179,7 @@ // this will draw a red border around the cached box for // debugging purposes - if (showBorder) { + if (drawBorder) { sceneContext = cachedSceneCanvas.getContext(); sceneContext.save(); sceneContext.beginPath(); @@ -1928,6 +1928,12 @@ * node.transformsEnabled('all'); */ + Kinetic.Factory.backCompat(Kinetic.Node, { + rotateDeg: 'rotate', + setRotationDeg: 'setRotation', + getRotationDeg: 'getRotation' + }); + Kinetic.Collection.mapMethods([ 'on', 'off', diff --git a/src/Shape.js b/src/Shape.js index fa6a1c86..18b9f706 100644 --- a/src/Shape.js +++ b/src/Shape.js @@ -1486,4 +1486,17 @@ * @returns {Number} */ + Kinetic.Factory.backCompat(Kinetic.Shape, { + dashArray: 'dash', + getDashArray: 'getDash', + setDashArray: 'getDash', + + drawFunc: 'sceneFunc', + getDrawFunc: 'getSceneFunc', + setDrawFunc: 'setSceneFunc', + + drawHitFunc: 'hitFunc', + getDrawHitFunc: 'getHitFunc', + setDrawHitFunc: 'setHitFunc' + }); })(); diff --git a/src/shapes/Sprite.js b/src/shapes/Sprite.js index 453eed53..1ab1fe39 100644 --- a/src/shapes/Sprite.js +++ b/src/shapes/Sprite.js @@ -250,4 +250,10 @@ * // set frame rate to 2 frames per second
* sprite.frameRate(2); */ + + Kinetic.Factory.backCompat(Kinetic.Sprite, { + index: 'frameIndex', + getIndex: 'getFrameIndex', + setIndex: 'setFrameIndex' + }); })(); diff --git a/src/shapes/Wedge.js b/src/shapes/Wedge.js index a4ce9e84..f2539b1f 100644 --- a/src/shapes/Wedge.js +++ b/src/shapes/Wedge.js @@ -95,4 +95,10 @@ * // draw wedge clockwise
* wedge.clockwise(true); */ + + Kinetic.Factory.backCompat(Kinetic.Wedge, { + angleDeg: 'angle', + getAngleDeg: 'getAngle', + setAngleDeg: 'setAngle' + }); })(); diff --git a/test/unit/Node-test.js b/test/unit/Node-test.js index 2ef315dd..7831a7b2 100644 --- a/test/unit/Node-test.js +++ b/test/unit/Node-test.js @@ -2884,7 +2884,7 @@ suite('Node', function() { y: -74, width: 148, height: 148, - showBorder: true + drawBorder: true }).offset({ x: 74, y: 74 diff --git a/test/unit/Shape-test.js b/test/unit/Shape-test.js index 442c715c..5b900166 100644 --- a/test/unit/Shape-test.js +++ b/test/unit/Shape-test.js @@ -569,4 +569,10 @@ suite('Shape', function() { layer.hitCanvas._canvas.style.border='2px solid black'; }); + test('back compat', function() { + assert.notEqual(Kinetic.Shape.prototype.dashArray, undefined); + assert.notEqual(Kinetic.Shape.prototype.setDashArray, undefined); + assert.notEqual(Kinetic.Shape.prototype.getDashArray, undefined); + }); + }); \ No newline at end of file