Add checks to menu double tap so it doesn't fire if the user swipes fast

This commit is contained in:
imakewebthings 2011-08-26 12:22:39 +08:00
parent 6d24a21870
commit 8b997bcb63

View file

@ -76,7 +76,8 @@ on the deck container.
$d.bind('deck.init', function() { $d.bind('deck.init', function() {
var opts = $[deck]('getOptions'), var opts = $[deck]('getOptions'),
touchEndTime = 0; touchEndTime = 0,
currentSlide;
// Bind key events // Bind key events
$d.bind('keydown.deck', function(e) { $d.bind('keydown.deck', function(e) {
@ -86,14 +87,20 @@ on the deck container.
}); });
// Double tap to toggle slide menu for touch devices // Double tap to toggle slide menu for touch devices
$[deck]('getContainer').bind('touchend.deck', function(e) { $[deck]('getContainer').bind('touchstart.deck', function(e) {
currentSlide = $[deck]('getSlide');
})
.bind('touchend.deck', function(e) {
var now = Date.now(); var now = Date.now();
// Ignore this touch event if it caused a nav change (swipe)
if (currentSlide !== $[deck]('getSlide')) return;
if (now - touchEndTime < opts.touch.doubletapWindow) { if (now - touchEndTime < opts.touch.doubletapWindow) {
$[deck]('toggleMenu'); $[deck]('toggleMenu');
e.preventDefault();
} }
touchEndTime = now; touchEndTime = now;
e.preventDefault();
}); });
}) })
.bind('deck.change', function(e, from, to) { .bind('deck.change', function(e, from, to) {