From b5d417a9bb6f2c0c4628914399f1503f8bba7a82 Mon Sep 17 00:00:00 2001 From: Kin Blas Date: Thu, 10 Feb 2011 17:10:39 -0800 Subject: [PATCH] Added a reset timer for unblocking the mouse event handlers. This was necessary because Blackberry does not dispatch a touchend event if the touch resulted in a scroll of the page. --- experiments/fast-click/jquery.mobile.mouse.js | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/experiments/fast-click/jquery.mobile.mouse.js b/experiments/fast-click/jquery.mobile.mouse.js index 5b7f8c5c..3eb3bbc4 100644 --- a/experiments/fast-click/jquery.mobile.mouse.js +++ b/experiments/fast-click/jquery.mobile.mouse.js @@ -42,6 +42,7 @@ function MouseEventSequencer(element) this.activeHandlers = {}; this.ignoreMouseEvents = false; this.didScroll = false; + this.resetTimerID = 0; } $.extend(MouseEventSequencer.prototype, { @@ -144,10 +145,29 @@ $.extend(MouseEventSequencer.prototype, { } } } - return this.element.trigger(event, data); + this.element.trigger(event, data); + return event.isDefaultPrevented(); + }, + + startResetTimer: function() { + var self = this; + this.clearResetTimer(); + this.resetTimerID = setTimeout(function(){ + self.resetTimerID = 0; + self.ignoreMouseEvents = false; + }, 2000); + }, + + clearResetTimer: function() { + if (this.resetTimerID){ + clearTimeout(this.resetTimerID); + this.resetTimerID = 0; + } }, handleTouchStart: function(event, data){ + this.clearResetTimer(); + this.ignoreMouseEvents = true; this.didScroll = false; @@ -161,6 +181,7 @@ $.extend(MouseEventSequencer.prototype, { handleTouchMove: function(event, data){ this.didScroll = true; this.trigger("vmousemove", event, data); + this.startResetTimer(); }, handleTouchEnd: function(event, data){ @@ -168,10 +189,15 @@ $.extend(MouseEventSequencer.prototype, { this.element.unbind("touchend", sequencerEventCallback); this.trigger("vmouseup", event, data); - if (!this.didScroll) - this.trigger("vclick", event, data); + if (!this.didScroll){ + if (this.trigger("vclick", event, data)){ + // prevent the pending click. + } + } this.trigger("vmouseout", event, data); this.didScroll = false; + + this.startResetTimer(); } });