mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
added some tween unit tests. all tween methods now return this
This commit is contained in:
14
src/Tween.js
14
src/Tween.js
@@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
for (key in config) {
|
for (key in config) {
|
||||||
if (blacklist[key] === undefined) {
|
if (blacklist[key] === undefined) {
|
||||||
this._addAttrs(key, config[key]);
|
this._addAttr(key, config[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
Kinetic.Tween.tweens = {};
|
Kinetic.Tween.tweens = {};
|
||||||
|
|
||||||
Kinetic.Tween.prototype = {
|
Kinetic.Tween.prototype = {
|
||||||
_addAttrs: function(key, end) {
|
_addAttr: function(key, end) {
|
||||||
var node = this.node,
|
var node = this.node,
|
||||||
nodeId = node._id,
|
nodeId = node._id,
|
||||||
start, diff, tweenId, n, len, startVal, endVal;
|
start, diff, tweenId, n, len, startVal, endVal;
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add to tween map
|
// add to tween map
|
||||||
start = node['get' + Kinetic.Util._capitalize(key)]();
|
start = node.getAttr(key);
|
||||||
|
|
||||||
if (Kinetic.Util._isArray(end)) {
|
if (Kinetic.Util._isArray(end)) {
|
||||||
end = Kinetic.Util._getPoints(end);
|
end = Kinetic.Util._getPoints(end);
|
||||||
@@ -147,7 +147,7 @@
|
|||||||
newVal = start + (diff * i);
|
newVal = start + (diff * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
node['set' + Kinetic.Util._capitalize(key)](newVal);
|
node.setAttr(key, newVal);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_addListeners: function() {
|
_addListeners: function() {
|
||||||
@@ -178,6 +178,7 @@
|
|||||||
*/
|
*/
|
||||||
play: function() {
|
play: function() {
|
||||||
this.tween.play();
|
this.tween.play();
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* reverse
|
* reverse
|
||||||
@@ -186,6 +187,7 @@
|
|||||||
*/
|
*/
|
||||||
reverse: function() {
|
reverse: function() {
|
||||||
this.tween.reverse();
|
this.tween.reverse();
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* reset
|
* reset
|
||||||
@@ -196,6 +198,7 @@
|
|||||||
var node = this.node;
|
var node = this.node;
|
||||||
this.tween.reset();
|
this.tween.reset();
|
||||||
(node.getLayer() || node.getLayers()).draw();
|
(node.getLayer() || node.getLayers()).draw();
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* seek
|
* seek
|
||||||
@@ -207,6 +210,7 @@
|
|||||||
var node = this.node;
|
var node = this.node;
|
||||||
this.tween.seek(t * 1000);
|
this.tween.seek(t * 1000);
|
||||||
(node.getLayer() || node.getLayers()).draw();
|
(node.getLayer() || node.getLayers()).draw();
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* pause
|
* pause
|
||||||
@@ -215,6 +219,7 @@
|
|||||||
*/
|
*/
|
||||||
pause: function() {
|
pause: function() {
|
||||||
tween.pause();
|
tween.pause();
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* finish
|
* finish
|
||||||
@@ -225,6 +230,7 @@
|
|||||||
var node = this.node;
|
var node = this.node;
|
||||||
this.tween.finish();
|
this.tween.finish();
|
||||||
(node.getLayer() || node.getLayers()).draw();
|
(node.getLayer() || node.getLayers()).draw();
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* destroy
|
* destroy
|
||||||
|
@@ -25,6 +25,19 @@ Test.Modules.TWEEN = {
|
|||||||
test(++finishCount <= 1, 'finishCount should not exceed 1');
|
test(++finishCount <= 1, 'finishCount should not exceed 1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tweens = 0;
|
||||||
|
var attrs = 0;
|
||||||
|
|
||||||
|
for (var key in Kinetic.Tween.tweens) {
|
||||||
|
tweens++;
|
||||||
|
}
|
||||||
|
for (var key in Kinetic.Tween.attrs) {
|
||||||
|
attrs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
test(tweens === 0, 'should be no tweens');
|
||||||
|
test(attrs === 0, 'should be no attrs');
|
||||||
|
|
||||||
var tween = new Kinetic.Tween({
|
var tween = new Kinetic.Tween({
|
||||||
node: circle,
|
node: circle,
|
||||||
duration: 0.2,
|
duration: 0.2,
|
||||||
@@ -33,5 +46,20 @@ Test.Modules.TWEEN = {
|
|||||||
onFinish: onFinish
|
onFinish: onFinish
|
||||||
}).play();
|
}).play();
|
||||||
|
|
||||||
|
var tweens = 0;
|
||||||
|
var attrs = 0;
|
||||||
|
for (var key in Kinetic.Tween.tweens) {
|
||||||
|
tweens++;
|
||||||
|
}
|
||||||
|
for (var key in Kinetic.Tween.attrs[circle._id][tween._id]) {
|
||||||
|
attrs++;
|
||||||
|
}
|
||||||
|
|
||||||
|
test(tweens === 1, 'should one tween');
|
||||||
|
test(attrs === 2, 'should two attrs');
|
||||||
|
|
||||||
|
test(Kinetic.Tween.attrs[circle._id][tween._id].x !== undefined, 'x should not be undefined');
|
||||||
|
test(Kinetic.Tween.attrs[circle._id][tween._id].y !== undefined, 'y should not be undefined');
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
Reference in New Issue
Block a user