Backbone.js + Keymaster.js = Backbone.Shortcuts.
- Development Version 1.031 kb, full source code
- Production Version 0.577 kb, packed and gzipped
- Underscore.js ~> 1.3.1 for
_.extend()
function - Backbone.js ~> 0.9.1 for
Backbone
class - Keymaster.js ~> 1.0.2 for keyboard shortcuts functionality
HTML
Place snippets inside of the <head>...</head>
tags.
<script src="underscore.min.js"></script>
<script src="backbone.min.js"></script>
<script src="keymaster.min.js"></script>
<script src="backbone.shortcuts.min.js"></script>
JavaScript
var ShortcutKeys = Backbone.Shortcuts.extend({
shortcuts: {
"ctrl+r" : "reloadPage"
},
reloadPage: function() {
alert("Reloaded!!");
}
});
var shortcuts = new ShortcutKeys;
CoffeeScript
class ShortcutKeys extends Backbone.Shortcuts
shortcuts:
"ctrl+r" : "reloadPage"
reloadPage: -> alert "Reload!!!"
shortcuts = new ShortcutKeys
Finally, you can press Ctrl + r
to execute reloadPage()
function to see the alert message.
You have to _.extend
the this
as desination and new Backbone.Shortcuts
as source then finally call the delegate function this.delegateShortcuts();
.
Bryan Goines, @bryangoines
Backbone.Shortcuts is licensed under MIT license.