Created
August 11, 2011 21:52
-
-
Save jeremyckahn/1140887 to your computer and use it in GitHub Desktop.
A function to make Backbone Views touch-ready
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
/** | |
* 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