mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 02:37:59 +08:00
implemented stage content mobile events and added functional tests
This commit is contained in:
@@ -130,4 +130,102 @@ suite('Events', function() {
|
||||
|
||||
assert.equal(stageContentMouseover, 1);
|
||||
});
|
||||
|
||||
test('stage content touch events', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Kinetic.Layer();
|
||||
var circle = new Kinetic.Circle({
|
||||
x: 100,
|
||||
y: 100,
|
||||
radius: 70,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myCircle'
|
||||
});
|
||||
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
var circleTouchstart =
|
||||
circleTouchend =
|
||||
stageContentTouchstart =
|
||||
stageContentTouchend =
|
||||
stageContentTouchmove =
|
||||
stageContentTap =
|
||||
stageContentDbltap =
|
||||
0;
|
||||
|
||||
var top = stage.content.getBoundingClientRect().top;
|
||||
|
||||
|
||||
circle.on('touchstart', function() {
|
||||
circleTouchstart++;
|
||||
});
|
||||
|
||||
circle.on('touchend', function() {
|
||||
circleTouchend++;
|
||||
});
|
||||
|
||||
stage.on('contentTouchstart', function() {
|
||||
stageContentTouchstart++;
|
||||
});
|
||||
|
||||
stage.on('contentTouchend', function() {
|
||||
stageContentTouchend++;
|
||||
});
|
||||
|
||||
stage.on('contentTouchmove', function() {
|
||||
stageContentTouchmove++;
|
||||
});
|
||||
|
||||
stage.on('contentTap', function() {
|
||||
stageContentTap++;
|
||||
});
|
||||
|
||||
stage.on('contentDbltap', function() {
|
||||
stageContentDbltap++;
|
||||
});
|
||||
|
||||
stage._touchstart({
|
||||
clientX: 100,
|
||||
clientY: 100 + top
|
||||
});
|
||||
|
||||
stage._touchend({
|
||||
clientX: 100,
|
||||
clientY: 100 + top
|
||||
});
|
||||
|
||||
assert.equal(circleTouchstart, 1, 1);
|
||||
assert.equal(circleTouchend, 1, 2);
|
||||
assert.equal(stageContentTouchstart, 1, 3);
|
||||
assert.equal(stageContentTouchend, 1, 4);
|
||||
assert.equal(stageContentDbltap, 1, 5);
|
||||
|
||||
stage._touchstart({
|
||||
clientX: 1,
|
||||
clientY: 1 + top
|
||||
});
|
||||
stage._touchend({
|
||||
clientX: 1,
|
||||
clientY: 1 + top
|
||||
});
|
||||
|
||||
assert.equal(stageContentTouchstart, 2, 6);
|
||||
assert.equal(stageContentTouchend, 2, 6);
|
||||
|
||||
// trigger double tap
|
||||
stage._touchstart({
|
||||
clientX: 1,
|
||||
clientY: 1 + top
|
||||
});
|
||||
stage._touchend({
|
||||
clientX: 1,
|
||||
clientY: 1 + top
|
||||
});
|
||||
|
||||
assert.equal(stageContentTouchstart, 3, 8);
|
||||
assert.equal(stageContentTouchend, 3, 9);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user