backbone-shortcuts
v0.0.2
Published
Backbone.js + Keymaster.js = Backbone.Shortcuts
Downloads
4
Readme
Backbone.Shortcuts
Backbone.js + Keymaster.js = Backbone.Shortcuts.
Downloads
- Development Version 1.031 kb, full source code
- Production Version 0.577 kb, packed and gzipped
Dependencies
- 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
Usage
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.
Use Backbone.Shortcuts as Delegation for your Backbone.View
You have to _.extend
the this
as desination and new Backbone.Shortcuts
as source then finally call the delegate function this.delegateShortcuts();
.
Author
Bryan Goines, @bryangoines
License
Backbone.Shortcuts is licensed under MIT license.