Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created August 11, 2011 21:52
Show Gist options
  • Save jeremyckahn/1140887 to your computer and use it in GitHub Desktop.
Save jeremyckahn/1140887 to your computer and use it in GitHub Desktop.
A function to make Backbone Views touch-ready
/**
* Asesses all of the events handlers bound on an View and makes touch event equivalents.
*
* Dependencies: Backbone, jQuery, Ben Alman's Outside Events jQuery plugin updated to support "touchstart"
*
* @param {Backbone.View} view
*/
function touchify (view) {
_.each(view.events, function (value, key) {
_.each({'mouseleave': 'touchstartoutside', 'mouseenter': 'touchstart'}, function (eventValue, eventKey) {
var regex;
regex = new RegExp(eventKey);
if (regex.test(key)) {
this.events[key.replace(regex, eventValue)] = value;
}
}, view);
}, view);
view.delegateEvents();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment