Skip to content

Instantly share code, notes, and snippets.

@kpuputti
Created November 4, 2011 14:34
Show Gist options
  • Save kpuputti/1339460 to your computer and use it in GitHub Desktop.
Save kpuputti/1339460 to your computer and use it in GitHub Desktop.
touchstart handlers for backbone clicks
// 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