Quick and dirty event wire-ups for JavaScript.
JavaScript port of Fran Lukesh's Hotwire originally created for AS3.
var delegate = {
handleClick: function(e) {},
handleItemSelected: function(e) {},
handleItemDeselected: function(e) {}
};
// Native jQuery
$("ul#tabs")
.bind("click", delegate.handleClick)
.bind("item_selected", delegate.handleItemSelected)
.bind("item_deselected", delegate.handleItemDeselected);
// Using Hotwire
$("ul#tabs").hotwire(delegate, "click", "item_selected", "item_deselected");
Hotwire uses convention to wire up event handlers. Simply give it a delegate where the handlers live and a bunch of events to attach and it'll wire things up.
Wiring up a click event, for example, Hotwire will look on the delegate supplied for a method named "handleClick". Simple. It's not rocket science, but it might save you a few keystrokes.
- Fork the project.
- Make your feature addition or bug fix.
- Add tests for it. This is important so I don't break it in a future version unintentionally.
- Commit.
- Send me a pull request. Bonus points for topic branches.
Copyright (c) 2010 Larry Marburger. See LICENSE for details.