Reputation: 10145
I like Meteor's "event map" approach (http://docs.meteor.com/#eventmaps) for organizing UI event handlers, and was wondering if this or similar is available as a third-party plugin for use outside of Meteor?
Example:
Template.login.events = {
// Fires when any element is clicked
'click': function (event) { ... },
// Fires when any element with the 'accept' class is clicked
'click .accept': function (event) { ... },
// Fires when 'accept' is clicked, or a key is pressed
'keydown, click .accept': function (event) { ... }
}
Upvotes: 1
Views: 2124
Reputation: 6177
Have a look at my answer on this question: Pass named function to an events map
It is exactly what you have asked.
Upvotes: 0
Reputation: 10145
Looks like jQuery supports very similar syntax:
$('.link').on({
click: function() {
t.find('div').show();
},
mouseout: function() {
t.find('div').hide();
}
});
Seems good enough :-)
Upvotes: 2