mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
fixed mousemove event bug, and added a very rigorous functional test to test all of the basic shape events for both desktop and mobile
This commit is contained in:
@@ -42,7 +42,7 @@ Kinetic.Layer.prototype = {
|
||||
var timeDiff = time - this.lastDrawTime;
|
||||
var tt = 1000 / throttle;
|
||||
|
||||
if(timeDiff >= tt) {
|
||||
if(timeDiff >= tt || throttle > 200) {
|
||||
this._draw();
|
||||
|
||||
if(this.drawTimeout !== undefined) {
|
||||
|
53
src/Stage.js
53
src/Stage.js
@@ -381,6 +381,7 @@ Kinetic.Stage.prototype = {
|
||||
var go = Kinetic.GlobalObject;
|
||||
var pos = this.getUserPosition();
|
||||
var el = shape.eventListeners;
|
||||
var that = this;
|
||||
|
||||
if(this.targetShape && shape._id === this.targetShape._id) {
|
||||
this.targetFound = true;
|
||||
@@ -408,12 +409,12 @@ Kinetic.Stage.prototype = {
|
||||
if((!go.drag.moving) || !go.drag.node) {
|
||||
shape._handleEvent('click', evt);
|
||||
|
||||
if(shape.inDoubleClickWindow) {
|
||||
if(this.inDoubleClickWindow) {
|
||||
shape._handleEvent('dblclick', evt);
|
||||
}
|
||||
shape.inDoubleClickWindow = true;
|
||||
this.inDoubleClickWindow = true;
|
||||
setTimeout(function() {
|
||||
shape.inDoubleClickWindow = false;
|
||||
that.inDoubleClickWindow = false;
|
||||
}, this.dblClickWindow);
|
||||
}
|
||||
}
|
||||
@@ -441,23 +442,25 @@ Kinetic.Stage.prototype = {
|
||||
if((!go.drag.moving) || !go.drag.node) {
|
||||
shape._handleEvent('tap', evt);
|
||||
|
||||
if(shape.inDoubleClickWindow) {
|
||||
if(this.inDoubleClickWindow) {
|
||||
shape._handleEvent('dbltap', evt);
|
||||
}
|
||||
shape.inDoubleClickWindow = true;
|
||||
this.inDoubleClickWindow = true;
|
||||
setTimeout(function() {
|
||||
shape.inDoubleClickWindow = false;
|
||||
that.inDoubleClickWindow = false;
|
||||
}, this.dblClickWindow);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
else if(!isDragging && this.touchMove) {
|
||||
shape._handleEvent('touchmove', evt);
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* NOTE: these event handlers require target shape
|
||||
* handling
|
||||
*/
|
||||
|
||||
// handle onmouseover
|
||||
else if(!isDragging && this._isNewTarget(shape, evt)) {
|
||||
/*
|
||||
@@ -475,18 +478,12 @@ Kinetic.Stage.prototype = {
|
||||
this._setTarget(shape);
|
||||
return true;
|
||||
}
|
||||
|
||||
// handle mousemove and touchmove
|
||||
|
||||
else if(!isDragging && this.mouseMove) {
|
||||
shape._handleEvent('mousemove', evt);
|
||||
return true;
|
||||
}
|
||||
|
||||
else if(!isDragging && this.touchMove) {
|
||||
shape._handleEvent('touchmove', evt);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
// handle mouseout condition
|
||||
@@ -627,7 +624,7 @@ else if(!isDragging && this.touchMove) {
|
||||
this.targetShape = undefined;
|
||||
}
|
||||
this.mousePos = undefined;
|
||||
|
||||
|
||||
// end drag and drop
|
||||
this._endDrag(evt);
|
||||
},
|
||||
@@ -639,9 +636,10 @@ else if(!isDragging && this.touchMove) {
|
||||
var timeDiff = time - this.lastEventTime;
|
||||
var tt = 1000 / throttle;
|
||||
|
||||
if(timeDiff >= tt) {
|
||||
if(timeDiff >= tt || throttle > 200) {
|
||||
this.mouseDown = false;
|
||||
this.mouseUp = false;
|
||||
this.mouseMove = true;
|
||||
this._handleStageEvent(evt);
|
||||
}
|
||||
|
||||
@@ -665,7 +663,7 @@ else if(!isDragging && this.touchMove) {
|
||||
this.mouseMove = false;
|
||||
this._handleStageEvent(evt);
|
||||
this.clickStart = false;
|
||||
|
||||
|
||||
// end drag and drop
|
||||
this._endDrag(evt);
|
||||
},
|
||||
@@ -688,7 +686,7 @@ else if(!isDragging && this.touchMove) {
|
||||
this.touchMove = false;
|
||||
this._handleStageEvent(evt);
|
||||
this.tapStart = false;
|
||||
|
||||
|
||||
// end drag and drop
|
||||
this._endDrag(evt);
|
||||
},
|
||||
@@ -701,20 +699,11 @@ else if(!isDragging && this.touchMove) {
|
||||
var timeDiff = time - this.lastEventTime;
|
||||
var tt = 1000 / throttle;
|
||||
|
||||
if(timeDiff >= tt) {
|
||||
/*
|
||||
* need a setTimeout here because iOS
|
||||
* sometimes triggers touchStart and touchMove
|
||||
* simultaenously which causes event detection issues.
|
||||
* The timeout ensures that touchstart events
|
||||
* are handled first followed by touchmove
|
||||
*/
|
||||
setTimeout(function() {
|
||||
evt.preventDefault();
|
||||
that.touchEnd = false;
|
||||
that.touchMove = true;
|
||||
that._handleStageEvent(evt);
|
||||
}, 5);
|
||||
if(timeDiff >= tt || throttle > 200) {
|
||||
evt.preventDefault();
|
||||
that.touchEnd = false;
|
||||
that.touchMove = true;
|
||||
that._handleStageEvent(evt);
|
||||
}
|
||||
|
||||
// start drag and drop
|
||||
|
Reference in New Issue
Block a user