This commit is contained in:
Anton Lavrenov
2020-05-08 09:59:35 -05:00
parent a2adcf5f17
commit d5481b1b72
78 changed files with 3714 additions and 3711 deletions

View File

@@ -1,6 +1,6 @@
suite('DragAndDropEvents', function() {
suite('DragAndDropEvents', function () {
// ======================================================
test('test dragstart, dragmove, dragend', function(done) {
test('test dragstart, dragmove, dragend', function (done) {
var stage = addStage();
var layer = new Konva.Layer();
@@ -12,7 +12,7 @@ suite('DragAndDropEvents', function() {
strokeWidth: 4,
fill: 'green',
stroke: 'black',
opacity: 0.5
opacity: 0.5,
});
var circle = new Konva.Circle({
@@ -22,7 +22,7 @@ suite('DragAndDropEvents', function() {
strokeWidth: 4,
fill: 'red',
stroke: 'black',
opacity: 0.5
opacity: 0.5,
});
circle.setDraggable(true);
@@ -37,20 +37,20 @@ suite('DragAndDropEvents', function() {
var mouseup = false;
var events = [];
circle.on('dragstart', function() {
circle.on('dragstart', function () {
dragStart = true;
});
circle.on('dragmove', function() {
circle.on('dragmove', function () {
dragMove = true;
});
circle.on('dragend', function() {
circle.on('dragend', function () {
dragEnd = true;
events.push('dragend');
});
circle.on('mouseup', function() {
circle.on('mouseup', function () {
events.push('mouseup');
});
@@ -62,7 +62,7 @@ suite('DragAndDropEvents', function() {
*/
stage.simulateMouseDown({
x: 380,
y: 98
y: 98,
});
assert(!dragStart, 'dragstart event should not have been triggered 3');
//assert.equal(!dragMove, 'dragmove event should not have been triggered');
@@ -71,10 +71,10 @@ suite('DragAndDropEvents', function() {
assert(!Konva.isDragging(), ' isDragging() should be false 5');
assert(Konva.isDragReady(), ' isDragReady()) should be true 6');
setTimeout(function() {
setTimeout(function () {
stage.simulateMouseMove({
x: 100,
y: 98
y: 98,
});
assert(Konva.isDragging(), ' isDragging() should be true 7');
@@ -86,7 +86,7 @@ suite('DragAndDropEvents', function() {
stage.simulateMouseUp({
x: 100,
y: 98
y: 98,
});
assert(dragStart, 'dragstart event was not triggered 11');
@@ -117,7 +117,7 @@ suite('DragAndDropEvents', function() {
});
// ======================================================
test('destroy shape while dragging', function(done) {
test('destroy shape while dragging', function (done) {
var stage = addStage();
var layer = new Konva.Layer();
@@ -128,7 +128,7 @@ suite('DragAndDropEvents', function() {
strokeWidth: 4,
fill: 'green',
stroke: 'black',
opacity: 0.5
opacity: 0.5,
});
var circle = new Konva.Circle({
@@ -138,7 +138,7 @@ suite('DragAndDropEvents', function() {
strokeWidth: 4,
fill: 'red',
stroke: 'black',
opacity: 0.5
opacity: 0.5,
});
circle.setDraggable(true);
@@ -149,11 +149,11 @@ suite('DragAndDropEvents', function() {
var dragEnd = false;
circle.on('dragend', function() {
circle.on('dragend', function () {
dragEnd = true;
});
circle.on('mouseup', function() {
circle.on('mouseup', function () {
//console.log('mouseup');
events.push('mouseup');
});
@@ -163,15 +163,15 @@ suite('DragAndDropEvents', function() {
stage.simulateMouseDown({
x: 380,
y: 98
y: 98,
});
assert(!circle.isDragging(), 'circle should not be dragging');
setTimeout(function() {
setTimeout(function () {
stage.simulateMouseMove({
x: 100,
y: 98
y: 98,
});
assert(circle.isDragging(), 'circle should be dragging');
@@ -193,7 +193,7 @@ suite('DragAndDropEvents', function() {
});
// ======================================================
test('click should not occur after drag and drop', function(done) {
test('click should not occur after drag and drop', function (done) {
var stage = addStage();
var layer = new Konva.Layer();
@@ -204,7 +204,7 @@ suite('DragAndDropEvents', function() {
strokeWidth: 4,
fill: 'green',
stroke: 'black',
draggable: true
draggable: true,
});
layer.add(circle);
@@ -212,29 +212,29 @@ suite('DragAndDropEvents', function() {
var clicked = false;
circle.on('click', function() {
circle.on('click', function () {
//console.log('click');
clicked = true;
});
circle.on('dblclick', function() {
circle.on('dblclick', function () {
//console.log('dblclick');
});
stage.simulateMouseDown({
x: 40,
y: 40
y: 40,
});
setTimeout(function() {
setTimeout(function () {
stage.simulateMouseMove({
x: 100,
y: 100
y: 100,
});
stage.simulateMouseUp({
x: 100,
y: 100
y: 100,
});
assert(!clicked, 'click event should not have been fired');
@@ -244,7 +244,7 @@ suite('DragAndDropEvents', function() {
});
// ======================================================
test('drag and drop distance', function(done) {
test('drag and drop distance', function (done) {
var stage = addStage();
var layer = new Konva.Layer();
@@ -255,7 +255,7 @@ suite('DragAndDropEvents', function() {
strokeWidth: 4,
fill: 'green',
stroke: 'black',
draggable: true
draggable: true,
});
layer.add(circle);
@@ -265,23 +265,23 @@ suite('DragAndDropEvents', function() {
stage.simulateMouseDown({
x: 40,
y: 40
y: 40,
});
setTimeout(function() {
setTimeout(function () {
stage.simulateMouseMove({
x: 40,
y: 42
y: 42,
});
assert(!circle.isDragging(), 'still not dragging');
stage.simulateMouseMove({
x: 40,
y: 45
y: 45,
});
assert(circle.isDragging(), 'now circle is dragging');
stage.simulateMouseUp({
x: 41,
y: 45
y: 45,
});
done();
@@ -289,7 +289,7 @@ suite('DragAndDropEvents', function() {
});
// ======================================================
test('cancel drag and drop by setting draggable to false', function(done) {
test('cancel drag and drop by setting draggable to false', function (done) {
var stage = addStage();
var layer = new Konva.Layer();
var circle = new Konva.Circle({
@@ -299,26 +299,26 @@ suite('DragAndDropEvents', function() {
strokeWidth: 4,
fill: 'red',
stroke: 'black',
draggable: true
draggable: true,
});
var dragStart = false;
var dragMove = false;
var dragEnd = false;
circle.on('dragstart', function() {
circle.on('dragstart', function () {
dragStart = true;
});
circle.on('dragmove', function() {
circle.on('dragmove', function () {
dragMove = true;
});
circle.on('dragend', function() {
circle.on('dragend', function () {
dragEnd = true;
});
circle.on('mousedown', function() {
circle.on('mousedown', function () {
circle.setDraggable(false);
});
@@ -332,18 +332,18 @@ suite('DragAndDropEvents', function() {
*/
stage.simulateMouseDown({
x: 380,
y: 100
y: 100,
});
setTimeout(function() {
setTimeout(function () {
stage.simulateMouseMove({
x: 100,
y: 100
y: 100,
});
stage.simulateMouseUp({
x: 100,
y: 100
y: 100,
});
assert.equal(circle.getPosition().x, 380, 'circle x should be 380');
@@ -353,10 +353,10 @@ suite('DragAndDropEvents', function() {
});
// ======================================================
test('drag and drop layer', function(done) {
test('drag and drop layer', function (done) {
var stage = addStage();
var layer = new Konva.Layer({
sceneFunc: function() {
sceneFunc: function () {
var context = this.getContext();
context.beginPath();
context.moveTo(200, 50);
@@ -366,21 +366,21 @@ suite('DragAndDropEvents', function() {
context.fillStyle = 'blue';
context.fill(context);
},
draggable: true
draggable: true,
});
var circle1 = new Konva.Circle({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
radius: 70,
fill: 'red'
fill: 'red',
});
var circle2 = new Konva.Circle({
x: 400,
y: stage.getHeight() / 2,
radius: 70,
fill: 'green'
fill: 'green',
});
layer.add(circle1);
@@ -395,18 +395,18 @@ suite('DragAndDropEvents', function() {
*/
stage.simulateMouseDown({
x: 399,
y: 96
y: 96,
});
setTimeout(function() {
setTimeout(function () {
stage.simulateMouseMove({
x: 210,
y: 109
y: 109,
});
stage.simulateMouseUp({
x: 210,
y: 109
y: 109,
});
//console.log(layer.getPosition())
@@ -419,13 +419,13 @@ suite('DragAndDropEvents', function() {
});
// ======================================================
test('drag and drop stage', function(done) {
test('drag and drop stage', function (done) {
var container = document.createElement('div'),
stage = new Konva.Stage({
container: container,
width: 578,
height: 200,
draggable: true
draggable: true,
});
konvaContainer.appendChild(container);
@@ -438,7 +438,7 @@ suite('DragAndDropEvents', function() {
x: 100,
y: 100,
radius: 70,
fill: 'red'
fill: 'red',
});
layer.add(circle);
@@ -454,18 +454,18 @@ suite('DragAndDropEvents', function() {
*/
stage.simulateMouseDown({
x: 0,
y: 100
y: 100,
});
setTimeout(function() {
setTimeout(function () {
stage.simulateMouseMove({
x: 300,
y: 110
y: 110,
});
stage.simulateMouseUp({
x: 300,
y: 110
y: 110,
});
assert.equal(stage.getX(), 300);
@@ -475,10 +475,10 @@ suite('DragAndDropEvents', function() {
}, 20);
});
test('click should not start drag&drop', function() {
test('click should not start drag&drop', function () {
var stage = addStage();
var layer = new Konva.Layer({
draggable: true
draggable: true,
});
var circle = new Konva.Circle({
@@ -489,29 +489,29 @@ suite('DragAndDropEvents', function() {
stroke: 'black',
strokeWidth: 4,
name: 'myCircle',
draggable: true
draggable: true,
});
layer.add(circle);
stage.add(layer);
var dragstart = 0;
circle.on('dragstart', function() {
circle.on('dragstart', function () {
dragstart += 1;
});
var dragmove = 0;
circle.on('dragmove', function() {
circle.on('dragmove', function () {
dragmove += 1;
});
var dragend = 0;
circle.on('dragend', function() {
circle.on('dragend', function () {
dragend += 1;
});
var click = 0;
circle.on('click', function() {
circle.on('click', function () {
click += 1;
});
stage.simulateMouseDown({ x: 70, y: 70 });
@@ -523,11 +523,10 @@ suite('DragAndDropEvents', function() {
assert.equal(dragend, 0, 'dragend not triggered');
});
test('drag&drop should not fire click', function() {
test('drag&drop should not fire click', function () {
var stage = addStage();
var layer = new Konva.Layer({
draggable: true
draggable: true,
});
var circle = new Konva.Circle({
@@ -538,29 +537,29 @@ suite('DragAndDropEvents', function() {
stroke: 'black',
strokeWidth: 4,
name: 'myCircle',
draggable: true
draggable: true,
});
layer.add(circle);
stage.add(layer);
var dragstart = 0;
circle.on('dragstart', function() {
circle.on('dragstart', function () {
dragstart += 1;
});
var dragmove = 0;
circle.on('dragmove', function() {
circle.on('dragmove', function () {
dragmove += 1;
});
var dragend = 0;
circle.on('dragend', function() {
circle.on('dragend', function () {
dragend += 1;
});
var click = 0;
circle.on('click', function() {
circle.on('click', function () {
click += 1;
});
stage.simulateMouseDown({ x: 70, y: 70 });
@@ -573,11 +572,10 @@ suite('DragAndDropEvents', function() {
assert.equal(dragend, 1, 'dragend not triggered');
});
test('drag events should not trigger on a click even if we stop drag on dragstart', function() {
test('drag events should not trigger on a click even if we stop drag on dragstart', function () {
var stage = addStage();
var layer = new Konva.Layer({
draggable: true
draggable: true,
});
var circle = new Konva.Circle({
@@ -588,30 +586,30 @@ suite('DragAndDropEvents', function() {
stroke: 'black',
strokeWidth: 4,
name: 'myCircle',
draggable: true
draggable: true,
});
layer.add(circle);
stage.add(layer);
var dragstart = 0;
circle.on('dragstart', function() {
circle.on('dragstart', function () {
circle.stopDrag();
dragstart += 1;
});
var dragmove = 0;
circle.on('dragmove', function() {
circle.on('dragmove', function () {
dragmove += 1;
});
var dragend = 0;
circle.on('dragend', function() {
circle.on('dragend', function () {
dragend += 1;
});
var click = 0;
circle.on('click', function() {
circle.on('click', function () {
click += 1;
});
stage.simulateMouseDown({ x: 70, y: 70 });

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
/* eslint-disable max-nested-callbacks */
// TODO: repair it
suite.skip('PointerEvents', function() {
suite.skip('PointerEvents', function () {
Konva._pointerEventsEnabled = true;
// ======================================================
test('pointerdown pointerup pointermove', function(done) {
test('pointerdown pointerup pointermove', function (done) {
var stage = addStage();
var layer = new Konva.Layer();
var circle = new Konva.Circle({
@@ -12,7 +12,7 @@ suite.skip('PointerEvents', function() {
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4
strokeWidth: 4,
});
// mobile events
@@ -23,15 +23,15 @@ suite.skip('PointerEvents', function() {
/*
* mobile
*/
circle.on('pointerdown', function() {
circle.on('pointerdown', function () {
pointerdown = true;
});
circle.on('pointerup', function() {
circle.on('pointerup', function () {
pointerup = true;
});
circle.on('pointermove', function() {
circle.on('pointermove', function () {
pointermove = true;
});
@@ -45,7 +45,7 @@ suite.skip('PointerEvents', function() {
clientX: 289,
clientY: 100 + top,
pointerId: 1,
preventDefault: function() {}
preventDefault: function () {},
});
assert(pointerdown, '1) pointerdown should be true');
@@ -55,7 +55,7 @@ suite.skip('PointerEvents', function() {
// pointerup circle
stage._pointerup({
touches: [],
preventDefault: function() {}
preventDefault: function () {},
});
assert(pointerdown, '2) pointerdown should be true');
@@ -67,10 +67,10 @@ suite.skip('PointerEvents', function() {
touches: [
{
clientX: 289,
clientY: 100 + top
}
clientY: 100 + top,
},
],
preventDefault: function() {}
preventDefault: function () {},
});
assert(pointerdown, '3) pointerdown should be true');
@@ -80,7 +80,7 @@ suite.skip('PointerEvents', function() {
// pointerup circle to triger dbltap
stage._pointerup({
touches: [],
preventDefault: function() {}
preventDefault: function () {},
});
// end drag is tied to document mouseup and pointerup event
// which can't be simulated. call _endDrag manually
@@ -90,16 +90,16 @@ suite.skip('PointerEvents', function() {
assert(!pointermove, '4) pointermove should be false');
assert(pointerup, '4) pointerup should be true');
setTimeout(function() {
setTimeout(function () {
// pointermove circle
stage._pointermove({
touches: [
{
clientX: 290,
clientY: 100 + top
}
clientY: 100 + top,
},
],
preventDefault: function() {}
preventDefault: function () {},
});
assert(pointerdown, '5) pointerdown should be true');
@@ -111,7 +111,7 @@ suite.skip('PointerEvents', function() {
});
// ======================================================
test('pointer capture', function(done) {
test('pointer capture', function (done) {
var stage = addStage();
var layer = new Konva.Layer();
var circle = new Konva.Circle({
@@ -120,7 +120,7 @@ suite.skip('PointerEvents', function() {
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4
strokeWidth: 4,
});
var circle2 = new Konva.Circle({
@@ -129,7 +129,7 @@ suite.skip('PointerEvents', function() {
radius: 20,
fill: 'red',
stroke: 'black',
strokeWidth: 4
strokeWidth: 4,
});
// mobile events
@@ -139,21 +139,21 @@ suite.skip('PointerEvents', function() {
var pointerup = false;
var pointermove = false;
circle2.on('pointerdown', function() {
circle2.on('pointerdown', function () {
otherDownCount++;
});
circle.on('pointerdown', function(event) {
circle.on('pointerdown', function (event) {
downCount++;
this.setPointerCapture(event.pointerId);
});
circle.on('pointerup', function(evt) {
circle.on('pointerup', function (evt) {
assert(this.hasPointerCapture(evt.pointerId), 'circle released capture');
pointerup = true;
});
circle.on('pointermove', function(evt) {
circle.on('pointermove', function (evt) {
assert(this.hasPointerCapture(evt.pointerId), 'circle has capture');
pointermove = true;
});
@@ -169,7 +169,7 @@ suite.skip('PointerEvents', function() {
clientX: 289,
clientY: 10 + top,
pointerId: 0,
preventDefault: function() {}
preventDefault: function () {},
});
assert(otherDownCount === 1, '6) otherDownCount should be 1');
@@ -182,7 +182,7 @@ suite.skip('PointerEvents', function() {
clientX: 289,
clientY: 100 + top,
pointerId: 1,
preventDefault: function() {}
preventDefault: function () {},
});
assert(otherDownCount === 1, '7) otherDownCount should be 1');
@@ -195,7 +195,7 @@ suite.skip('PointerEvents', function() {
clientX: 289,
clientY: 10 + top,
pointerId: 1,
preventDefault: function() {}
preventDefault: function () {},
});
assert(otherDownCount === 1, '8) otherDownCount should be 1');
@@ -203,13 +203,13 @@ suite.skip('PointerEvents', function() {
assert(!pointermove, '8) pointermove should be false');
assert(!pointerup, '8) pointerup should be true');
setTimeout(function() {
setTimeout(function () {
// pointermove over circle 2
stage._pointermove({
clientX: 290,
clientY: 10 + top,
pointerId: 1,
preventDefault: function() {}
preventDefault: function () {},
});
assert(otherDownCount === 1, '9) otherDownCount should be 1');
@@ -217,14 +217,14 @@ suite.skip('PointerEvents', function() {
stage._pointerup({
pointerId: 1,
preventDefault: function() {}
preventDefault: function () {},
});
stage._pointerdown({
clientX: 289,
clientY: 10 + top,
pointerId: 1,
preventDefault: function() {}
preventDefault: function () {},
});
assert(otherDownCount === 2, '10) otherDownCount should be 1');

View File

@@ -1,6 +1,6 @@
suite('TouchEvents', function() {
suite('TouchEvents', function () {
// ======================================================
test('stage content touch events', function() {
test('stage content touch events', function () {
var stage = addStage();
var layer = new Konva.Layer();
var circle = new Konva.Circle({
@@ -10,7 +10,7 @@ suite('TouchEvents', function() {
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myCircle'
name: 'myCircle',
});
layer.add(circle);
@@ -20,31 +20,31 @@ suite('TouchEvents', function() {
var top = stage.content.getBoundingClientRect().top;
circle.on('touchstart', function() {
circle.on('touchstart', function () {
circleTouchstart++;
});
circle.on('touchend', function() {
circle.on('touchend', function () {
circleTouchend++;
});
stage.on('contentTouchstart', function() {
stage.on('contentTouchstart', function () {
stageContentTouchstart++;
});
stage.on('contentTouchend', function() {
stage.on('contentTouchend', function () {
stageContentTouchend++;
});
stage.on('contentTouchmove', function() {
stage.on('contentTouchmove', function () {
stageContentTouchmove++;
});
stage.on('contentTap', function() {
stage.on('contentTap', function () {
stageContentTap++;
});
stage.on('contentDbltap', function() {
stage.on('contentDbltap', function () {
stageContentDbltap++;
});
@@ -67,7 +67,7 @@ suite('TouchEvents', function() {
});
// ======================================================
test('touchstart touchend touchmove tap dbltap', function(done) {
test('touchstart touchend touchmove tap dbltap', function (done) {
var stage = addStage();
var layer = new Konva.Layer();
var circle = new Konva.Circle({
@@ -76,7 +76,7 @@ suite('TouchEvents', function() {
radius: 70,
fill: 'red',
stroke: 'black',
strokeWidth: 4
strokeWidth: 4,
});
// mobile events
@@ -89,29 +89,29 @@ suite('TouchEvents', function() {
/*
* mobile
*/
circle.on('touchstart', function() {
circle.on('touchstart', function () {
touchstart = true;
//log('touchstart');
//alert('touchstart')
});
circle.on('touchend', function() {
circle.on('touchend', function () {
touchend = true;
//alert('touchend')
//log('touchend');
});
circle.on('touchmove', function() {
circle.on('touchmove', function () {
touchmove = true;
//log('touchmove');
});
circle.on('tap', function(evt) {
circle.on('tap', function (evt) {
tap = true;
//log('tap');
});
circle.on('dbltap', function() {
circle.on('dbltap', function () {
dbltap = true;
//log('dbltap');
});
@@ -166,7 +166,7 @@ suite('TouchEvents', function() {
assert(tap, '11) tap should be true');
assert(dbltap, '11) dbltap should be true');
setTimeout(function() {
setTimeout(function () {
// touchmove circle
stage.simulateTouchMove([], [{ x: 289, y: 100, id: 0 }]);
@@ -181,7 +181,7 @@ suite('TouchEvents', function() {
});
// test for https://github.com/konvajs/konva/issues/156
test('touchstart out of shape, then touch end inside shape', function() {
test('touchstart out of shape, then touch end inside shape', function () {
var stage = addStage();
var layer = new Konva.Layer();
var circle = new Konva.Circle({
@@ -191,7 +191,7 @@ suite('TouchEvents', function() {
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myCircle'
name: 'myCircle',
});
layer.add(circle);
@@ -201,15 +201,15 @@ suite('TouchEvents', function() {
var top = stage.content.getBoundingClientRect().top;
circle.on('touchend', function() {
circle.on('touchend', function () {
circleTouchend++;
});
stage.on('contentTouchstart', function() {
stage.on('contentTouchstart', function () {
stageContentTouchstart++;
});
stage.on('contentTouchend', function() {
stage.on('contentTouchend', function () {
stageContentTouchend++;
});
@@ -221,7 +221,7 @@ suite('TouchEvents', function() {
assert.equal(circleTouchend, 1);
});
test('tap on one shape, then fast tap on another shape should no trigger double tap', function() {
test('tap on one shape, then fast tap on another shape should no trigger double tap', function () {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
@@ -233,7 +233,7 @@ suite('TouchEvents', function() {
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myCircle'
name: 'myCircle',
});
layer.add(circle1);
@@ -245,7 +245,7 @@ suite('TouchEvents', function() {
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myCircle'
name: 'myCircle',
});
layer.add(circle2);
@@ -256,13 +256,13 @@ suite('TouchEvents', function() {
var circle2Tap = 0;
var circle2DoubleTap = 0;
circle1.on('tap', function() {
circle1.on('tap', function () {
circle1Tap++;
});
circle2.on('tap', function() {
circle2.on('tap', function () {
circle2Tap++;
});
circle2.on('dbltap', function() {
circle2.on('dbltap', function () {
circle2DoubleTap++;
});
@@ -289,7 +289,7 @@ suite('TouchEvents', function() {
);
});
test('multitouch - register all touches', function() {
test('multitouch - register all touches', function () {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
@@ -302,7 +302,7 @@ suite('TouchEvents', function() {
stroke: 'black',
strokeWidth: 4,
name: 'myCircle1',
draggable: true
draggable: true,
});
layer.add(circle1);
@@ -314,7 +314,7 @@ suite('TouchEvents', function() {
stroke: 'black',
strokeWidth: 4,
name: 'myCircle2',
draggable: true
draggable: true,
});
layer.add(circle2);
@@ -325,30 +325,30 @@ suite('TouchEvents', function() {
var touchEnd = 0;
var touchEnd2 = 0;
circle1.on('touchstart', function() {
circle1.on('touchstart', function () {
touchStart++;
});
circle1.on('touchmove', function() {
circle1.on('touchmove', function () {
touchMove++;
});
circle1.on('touchend', function() {
circle1.on('touchend', function () {
touchEnd++;
});
circle2.on('touchend', function() {
circle2.on('touchend', function () {
touchEnd2++;
});
var stageTouchStart = 0;
var stageTouchMove = 0;
var stageTouchEnd = 0;
stage.on('touchstart', function() {
stage.on('touchstart', function () {
stageTouchStart++;
});
stage.on('touchmove', function() {
stage.on('touchmove', function () {
stageTouchMove++;
});
stage.on('touchend', function() {
stage.on('touchend', function () {
stageTouchEnd++;
});
@@ -363,7 +363,10 @@ suite('TouchEvents', function() {
// make second touch
stage.simulateTouchStart(
[{ x: 100, y: 100, id: 0 }, { x: 210, y: 100, id: 1 }],
[
{ x: 100, y: 100, id: 0 },
{ x: 210, y: 100, id: 1 },
],
[{ x: 210, y: 100, id: 1 }]
);
@@ -381,8 +384,14 @@ suite('TouchEvents', function() {
// now try to make two touches at the same time
// TODO: should we trigger touch end first?
stage.simulateTouchStart(
[{ x: 100, y: 100, id: 0 }, { x: 210, y: 100, id: 1 }],
[{ x: 100, y: 100, id: 0 }, { x: 210, y: 100, id: 1 }]
[
{ x: 100, y: 100, id: 0 },
{ x: 210, y: 100, id: 1 },
],
[
{ x: 100, y: 100, id: 0 },
{ x: 210, y: 100, id: 1 },
]
);
assert.equal(stageTouchStart, 3, 'should trigger one more touch');
@@ -396,12 +405,15 @@ suite('TouchEvents', function() {
assert.deepEqual(stage.getPointerPosition(), { x: 100, y: 100 });
assert.deepEqual(stage.getPointersPositions(), [
{ x: 100, y: 100, id: 0 },
{ x: 210, y: 100, id: 1 }
{ x: 210, y: 100, id: 1 },
]);
// move one finger
stage.simulateTouchMove(
[{ x: 100, y: 100, id: 0 }, { x: 220, y: 100, id: 1 }],
[
{ x: 100, y: 100, id: 0 },
{ x: 220, y: 100, id: 1 },
],
[{ x: 220, y: 100, id: 1 }]
);
assert.equal(touchMove, 0, 'should not trigger touch move on circle');
@@ -409,8 +421,14 @@ suite('TouchEvents', function() {
// move two fingers
stage.simulateTouchMove(
[{ x: 100, y: 100, id: 0 }, { x: 220, y: 100, id: 1 }],
[{ x: 100, y: 100, id: 0 }, { x: 220, y: 100, id: 1 }]
[
{ x: 100, y: 100, id: 0 },
{ x: 220, y: 100, id: 1 },
],
[
{ x: 100, y: 100, id: 0 },
{ x: 220, y: 100, id: 1 },
]
);
assert.equal(touchMove, 1, 'should trigger touch move on circle');
assert.equal(
@@ -421,7 +439,10 @@ suite('TouchEvents', function() {
stage.simulateTouchEnd(
[],
[{ x: 100, y: 100, id: 0 }, { x: 220, y: 100, id: 1 }]
[
{ x: 100, y: 100, id: 0 },
{ x: 220, y: 100, id: 1 },
]
);
assert.equal(touchEnd, 1);
assert.equal(stageTouchEnd, 1);
@@ -429,7 +450,10 @@ suite('TouchEvents', function() {
// try two touch ends on both shapes
stage.simulateTouchEnd(
[],
[{ x: 100, y: 100, id: 0 }, { x: 100, y: 170, id: 1 }]
[
{ x: 100, y: 100, id: 0 },
{ x: 100, y: 170, id: 1 },
]
);
assert.equal(touchEnd, 2);
@@ -438,7 +462,7 @@ suite('TouchEvents', function() {
assert.equal(stageTouchEnd, 3);
});
test('can capture touch events', function() {
test('can capture touch events', function () {
Konva.captureTouchEventsEnabled = true;
var stage = addStage();
var layer = new Konva.Layer();
@@ -451,7 +475,7 @@ suite('TouchEvents', function() {
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myCircle1'
name: 'myCircle1',
});
layer.add(circle1);
@@ -461,13 +485,13 @@ suite('TouchEvents', function() {
var touchMove = 0;
var touchEnd = 0;
circle1.on('touchstart', function(e) {
circle1.on('touchstart', function (e) {
touchStart++;
});
circle1.on('touchmove', function() {
circle1.on('touchmove', function () {
touchMove++;
});
circle1.on('touchend', function() {
circle1.on('touchend', function () {
touchEnd++;
});
@@ -485,14 +509,23 @@ suite('TouchEvents', function() {
// add another finger
stage.simulateTouchStart(
[{ x: 180, y: 100, id: 0 }, { x: 100, y: 100, id: 1 }],
[
{ x: 180, y: 100, id: 0 },
{ x: 100, y: 100, id: 1 },
],
[{ x: 100, y: 100, id: 1 }]
);
// move all out
stage.simulateTouchMove(
[{ x: 185, y: 100, id: 0 }, { x: 190, y: 100, id: 1 }],
[{ x: 185, y: 100, id: 0 }, { x: 190, y: 100, id: 1 }]
[
{ x: 185, y: 100, id: 0 },
{ x: 190, y: 100, id: 1 },
],
[
{ x: 185, y: 100, id: 0 },
{ x: 190, y: 100, id: 1 },
]
);
// should trigger just one more touchmove
assert.equal(touchMove, 2, 'second touchmove');
@@ -500,7 +533,10 @@ suite('TouchEvents', function() {
// remove fingers
stage.simulateTouchEnd(
[],
[{ x: 185, y: 100, id: 0 }, { x: 190, y: 100, id: 1 }]
[
{ x: 185, y: 100, id: 0 },
{ x: 190, y: 100, id: 1 },
]
);
assert.equal(touchEnd, 1, 'first touchend');
@@ -512,7 +548,7 @@ suite('TouchEvents', function() {
Konva.captureTouchEventsEnabled = false;
});
test('tap and double tap should trigger just once on stage', function() {
test('tap and double tap should trigger just once on stage', function () {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
@@ -524,7 +560,7 @@ suite('TouchEvents', function() {
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myCircle1'
name: 'myCircle1',
});
layer.add(circle1);
layer.draw();
@@ -532,12 +568,12 @@ suite('TouchEvents', function() {
var tap = 0;
var dbltap = 0;
stage.on('tap', function(e) {
stage.on('tap', function (e) {
assert.equal(e.target, circle1);
tap += 1;
});
stage.on('dbltap', function(e) {
stage.on('dbltap', function (e) {
assert.equal(e.target, circle1);
dbltap += 1;
});
@@ -562,7 +598,7 @@ suite('TouchEvents', function() {
assert.equal(dbltap, 1, 'no dbltap triggered');
});
test('drag and second tap should not trigger dbltap', function() {
test('drag and second tap should not trigger dbltap', function () {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
@@ -575,7 +611,7 @@ suite('TouchEvents', function() {
stroke: 'black',
strokeWidth: 4,
name: 'myCircle1',
draggable: true
draggable: true,
});
layer.add(circle1);
layer.draw();
@@ -584,16 +620,16 @@ suite('TouchEvents', function() {
var dbltap = 0;
var dragmove = 0;
stage.on('tap', function(e) {
stage.on('tap', function (e) {
assert.equal(e.target, circle1);
tap += 1;
});
stage.on('dbltap', function(e) {
stage.on('dbltap', function (e) {
dbltap += 1;
});
stage.on('dragmove', function(e) {
stage.on('dragmove', function (e) {
dragmove += 1;
});
@@ -624,7 +660,7 @@ suite('TouchEvents', function() {
assert.equal(dbltap, 0, 'no dbltap triggered');
});
test('tap should give pointer position', function() {
test('tap should give pointer position', function () {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
@@ -637,7 +673,7 @@ suite('TouchEvents', function() {
stroke: 'black',
strokeWidth: 4,
name: 'myCircle1',
draggable: true
draggable: true,
});
layer.add(circle1);
layer.draw();
@@ -645,14 +681,14 @@ suite('TouchEvents', function() {
var tap = 0;
var click = 0;
stage.on('tap', function(e) {
stage.on('tap', function (e) {
assert.equal(e.target, circle1);
assert.equal(stage.getPointerPosition().x, 100);
assert.equal(stage.getPointerPosition().y, 100);
tap += 1;
});
stage.on('click', function(e) {
stage.on('click', function (e) {
click += 1;
});