Created
November 4, 2011 14:34
-
-
Save kpuputti/1339460 to your computer and use it in GitHub Desktop.
touchstart handlers for backbone clicks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In the events object of the view: | |
// 'touchstart nav a': 'onNavTouchStart', | |
// 'touchmove nav a': 'onNavTouchMove', | |
// 'touchend nav a': 'onNavTouchEnd', | |
onNavTouchStart: function (event) { | |
var href = $(event.target).attr('href'); | |
this.navTouchHref = (href && href !== '#') ? href : null; | |
}, | |
onNavTouchMove: function (event) { | |
this.navTouchHref = null; | |
}, | |
onNavTouchEnd: function (event) { | |
if (!this.navTouchHref) { | |
return; | |
} | |
var href = $(event.target).attr('href'); | |
if (href && href === this.navTouchHref) { | |
event.preventDefault(); | |
location.hash = href; | |
this.navTouchHref = null; | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment