Skip to content

Instantly share code, notes, and snippets.

@isaacrankin
Last active August 29, 2015 14:06
Show Gist options
  • Save isaacrankin/408eb9383afe43e4b33f to your computer and use it in GitHub Desktop.
Save isaacrankin/408eb9383afe43e4b33f to your computer and use it in GitHub Desktop.
Bind touch or mouse events in a Backbone view.
var ExampleView = Backbone.View.extend({
el: '.example',
events: function(){
var action = (Modernizr.touch) ? 'touchend' : 'click',
events = {};
events[ action + ' .btn'] = 'doSomething';
return events;
},
doSomething: function(e){
window.alert('do something');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment