PDA

View Full Version : tap if not a doubletap



merrells
3 Oct 2010, 3:39 PM
I want tap to do one thing and doubletap another thing. If I catch both, with on(...), then I get a tap, and then a bit later a doubletap, which causes a bit of confusion. Is there a way, in the framework, to ask for a tap _or_ a doubletap instead of both? If not, then how would I go about implementing that..... catch the tap... start a timer to run the tap code when it expires... and then if a doubletap comes in then it aborts the timer and runs the doubletap code. Looks like the default maximum time between taps for a doubletap is 800ms.... hmm quite long... anyone else been here before?

John

merrells
3 Oct 2010, 6:13 PM
Answering my own question....


afterRender: function() {
XXX.superclass.afterRender.call(this);
this.getEl().on('tap',this.onTapOrDoubleTap,this);
},

doubleTapThreshold: 500,

onTapOrDoubleTap: function(e,t) {
if (this.tapStartTime && e.time-this.tapStartTime<this.doubleTapThreshold) {
clearTimeout(this.timer)
this.onDoubleTap(e,t);
} else {
this.tapStartTime = new Date();
this.timer= Ext.defer(this.onTap,this.doubleTapThreshold,this,[e,t]);
}
},