applying event throttling logic to mousemove and touchmove only

This commit is contained in:
Eric Rowell 2012-05-28 12:12:26 -07:00
parent 3c72f8240b
commit a29d1520ae
3 changed files with 66 additions and 46 deletions

54
dist/kinetic-core.js vendored
View File

@ -2005,22 +2005,11 @@ Kinetic.Stage.prototype = {
return false;
},
_handleStageEvent: function(evt) {
var throttle = this.attrs.throttle;
var date = new Date();
var time = date.getTime();
var timeDiff = time - this.lastEventTime;
var tt = 1000 / throttle;
if(timeDiff >= tt) {
this._handleStageEventContinue(evt);
}
},
/**
* handle incoming event
* @param {Event} evt
*/
_handleStageEventContinue: function(evt) {
_handleStageEvent: function(evt) {
var date = new Date();
var time = date.getTime();
this.lastEventTime = time;
@ -2083,9 +2072,20 @@ Kinetic.Stage.prototype = {
}, false);
this.content.addEventListener('mousemove', function(evt) {
that.mouseUp = false;
that.mouseDown = false;
that._handleStageEvent(evt);
/*
* throttle mousemove
*/
var throttle = that.attrs.throttle;
var date = new Date();
var time = date.getTime();
var timeDiff = time - that.lastEventTime;
var tt = 1000 / throttle;
if(timeDiff >= tt) {
that.mouseUp = false;
that.mouseDown = false;
that._handleStageEvent(evt);
}
}, false);
this.content.addEventListener('mouseup', function(evt) {
@ -2094,11 +2094,10 @@ Kinetic.Stage.prototype = {
that._handleStageEvent(evt);
that.clickStart = false;
}, false);
/*
this.content.addEventListener('mouseover', function(evt) {
that._handleStageEvent(evt);
}, false);
*/
this.content.addEventListener('mouseover', function(evt) {
that._handleStageEvent(evt);
}, false);
this.content.addEventListener('mouseout', function(evt) {
// if there's a current target shape, run mouseout handlers
@ -2125,8 +2124,19 @@ Kinetic.Stage.prototype = {
}, false);
this.content.addEventListener('touchmove', function(evt) {
evt.preventDefault();
that._handleStageEvent(evt);
/*
* throttle touchmove
*/
var throttle = that.attrs.throttle;
var date = new Date();
var time = date.getTime();
var timeDiff = time - that.lastEventTime;
var tt = 1000 / throttle;
if(timeDiff >= tt) {
evt.preventDefault();
that._handleStageEvent(evt);
}
}, false);
this.content.addEventListener('touchend', function(evt) {

File diff suppressed because one or more lines are too long

View File

@ -551,22 +551,11 @@ Kinetic.Stage.prototype = {
return false;
},
_handleStageEvent: function(evt) {
var throttle = this.attrs.throttle;
var date = new Date();
var time = date.getTime();
var timeDiff = time - this.lastEventTime;
var tt = 1000 / throttle;
if(timeDiff >= tt) {
this._handleStageEventContinue(evt);
}
},
/**
* handle incoming event
* @param {Event} evt
*/
_handleStageEventContinue: function(evt) {
_handleStageEvent: function(evt) {
var date = new Date();
var time = date.getTime();
this.lastEventTime = time;
@ -629,9 +618,20 @@ Kinetic.Stage.prototype = {
}, false);
this.content.addEventListener('mousemove', function(evt) {
that.mouseUp = false;
that.mouseDown = false;
that._handleStageEvent(evt);
/*
* throttle mousemove
*/
var throttle = that.attrs.throttle;
var date = new Date();
var time = date.getTime();
var timeDiff = time - that.lastEventTime;
var tt = 1000 / throttle;
if(timeDiff >= tt) {
that.mouseUp = false;
that.mouseDown = false;
that._handleStageEvent(evt);
}
}, false);
this.content.addEventListener('mouseup', function(evt) {
@ -640,11 +640,10 @@ Kinetic.Stage.prototype = {
that._handleStageEvent(evt);
that.clickStart = false;
}, false);
/*
this.content.addEventListener('mouseover', function(evt) {
that._handleStageEvent(evt);
}, false);
*/
this.content.addEventListener('mouseover', function(evt) {
that._handleStageEvent(evt);
}, false);
this.content.addEventListener('mouseout', function(evt) {
// if there's a current target shape, run mouseout handlers
@ -671,8 +670,19 @@ Kinetic.Stage.prototype = {
}, false);
this.content.addEventListener('touchmove', function(evt) {
evt.preventDefault();
that._handleStageEvent(evt);
/*
* throttle touchmove
*/
var throttle = that.attrs.throttle;
var date = new Date();
var time = date.getTime();
var timeDiff = time - that.lastEventTime;
var tt = 1000 / throttle;
if(timeDiff >= tt) {
evt.preventDefault();
that._handleStageEvent(evt);
}
}, false);
this.content.addEventListener('touchend', function(evt) {