Skip to content

Instantly share code, notes, and snippets.

@hqman
Forked from gryzzly/backbone-touch-click.js
Created April 8, 2013 09:54
Show Gist options
  • Save hqman/5335651 to your computer and use it in GitHub Desktop.
Save hqman/5335651 to your computer and use it in GitHub Desktop.
var down = "touchup" in window ? "touchup" : "click";
var abstractView = Backbone.View.extend({
// we don't want both click and touch handlers
// delegated on touch-enabled devices
events: function () {
"click .toggler" : "foo",
"touchup .toggler" : "bar"
},
initialize: function () {
// we can do this instead
this.events = this.events || {};
this.events[down + ' .toggler'] = "foo";
// … list more events here
this.delegateEvents();
}
});
// This does solve the problem but this doesn't look good
//
// We could do something like jQuery special event, but Zepto,
// that is used on mobile devices doesn't support special events
//
// So seamless "down .toggler" : "foo", that would work by registering
// "special" jQuery event will not work with Zepto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment