globalMousetrap: globalMousetrap,
boundObjects: [globalObject],
shortcuts: {},
+ onRebindCallbacks: [],
+ onNewShortcutCallbacks: [],
registerShortcut: function(shortcut) {
if (arguments.length > 1) {
shortcut = {
if (this.shortcuts[shortcut.id]) return this.shortcuts[shortcut.id];
this.shortcuts[shortcut.id] = shortcut;
_.chain(this.boundObjects).where({'type':shortcut.object}).each(_.partial(this.bindShortcut, shortcut, _), this).value();
+ _.each(this.onNewShortcutCallbacks, function(callback) {
+ callback.call(this, shortcut);
+ }, this);
return shortcut;
},
unregisterShortcut: function(shortcut) {
shortcut.unbind();
shortcut._keybinding = keybinding;
_.each(objects, shortcut.bind, shortcut);
- if (this.onRebindShortcut) this.onRebindShortcut(shortcut, keybinding, oldKeybinding);
+ if (this.onRebindCallbacks) {
+ _.each(this.onRebindCallbacks, function(f) {
+ f.call(this, shortcut, keybinding, oldKeybinding);
+ });
+ }
},
userRebindShortcut: function(shortcut, options) {
// Cancels on focus loss or if the user presses the escape key
shortcutPressed: function(shortcut, object) {
if (shortcut.action) return shortcut.action(object.element, shortcut, object.type, object.options);
},
- onRebindShortcut: function(shortcut, keybinding, oldKeybinding) {
+ onNewShortcut: function(f) {
+ this.onNewShortcutCallbacks.push(f);
+ },
+ onRebindShortcut: function(f) {
+ this.onRebindCallbacks.push(f);
+ // function(shortcut, keybinding, oldKeybinding)
// NOTE: You may want to hook into this if you want to save/load user preferences
// shortcut.id is probably what you want and not the whole shortcut
},
object.mousetrap.unpause();
});
},
+ bindShortcutsDisplay: function(element, options) {
+ element.innerHTML = this.displayShortcuts(options);
+ var self = this;
+ this.onRebindShortcut(function() {
+ element.innerHTML = self.displayShortcuts(options);
+ });
+ this.onNewShortcut(function() {
+ element.innerHTML = self.displayShortcuts(options);
+ });
+ },
displayShortcuts: function(options) {
options = _.defaults({}, options, {
objectGrouping: "default", // Display one list, or group under headers by object type? "true" "false", or "default"
var multipleObjectTypes = _.chain(shortcuts).pluck('object').unique().size().value() > 1;
options.objectGrouping = multipleObjectTypes;
}
- return '<h3>Shortcuts</h3><table>' + _.map(options.shortcuts, function(shortcut) {
- return _.template("<tr><td><%= description %></td><td><%= keybindingHtml %></td></tr>")({
+ return '<table class="shortcuts">' + _.map(options.shortcuts, function(shortcut) {
+ return _.template('<tr><td class="shortcut-description"><%= description %></td><td class="shortcut-keybinding"><%= keybindingHtml %></td></tr>')({
description: shortcut.description,
keybindingHtml: this._displayKeybinding(shortcut, options)
});
e.save();
});
});
- Shortcut.onRebindShortcut = function() {
- self.renderShortcuts();
- };
+ Shortcut.bindShortcutsDisplay(this.$("#shortcuts")[0], {allowRebind: true});
this.views = {}; // A list of views for each element in the collection
this.list.fetch();
this.render();
},
render: function() {
- this.renderShortcuts();
return this;
},
- renderShortcuts: function() {
- this.$("#shortcuts").html(Shortcut.displayShortcuts({allowRebind: true}));
- },
addOne: function(todo) {
this.renderTodo(todo);
},
globalMousetrap: globalMousetrap,
boundObjects: [globalObject],
shortcuts: {},
+ onRebindCallbacks: [],
+ onNewShortcutCallbacks: [],
registerShortcut: function(shortcut) {
if (arguments.length > 1) {
shortcut = {
if (this.shortcuts[shortcut.id]) return this.shortcuts[shortcut.id];
this.shortcuts[shortcut.id] = shortcut;
_.chain(this.boundObjects).where({'type':shortcut.object}).each(_.partial(this.bindShortcut, shortcut, _), this).value();
+ _.each(this.onNewShortcutCallbacks, function(callback) {
+ callback.call(this, shortcut);
+ }, this);
return shortcut;
},
unregisterShortcut: function(shortcut) {
shortcut.unbind();
shortcut._keybinding = keybinding;
_.each(objects, shortcut.bind, shortcut);
- if (this.onRebindShortcut) this.onRebindShortcut(shortcut, keybinding, oldKeybinding);
+ if (this.onRebindCallbacks) {
+ _.each(this.onRebindCallbacks, function(f) {
+ f.call(this, shortcut, keybinding, oldKeybinding);
+ });
+ }
},
userRebindShortcut: function(shortcut, options) {
// Cancels on focus loss or if the user presses the escape key
shortcutPressed: function(shortcut, object) {
if (shortcut.action) return shortcut.action(object.element, shortcut, object.type, object.options);
},
- onRebindShortcut: function(shortcut, keybinding, oldKeybinding) {
+ onNewShortcut: function(f) {
+ this.onNewShortcutCallbacks.push(f);
+ },
+ onRebindShortcut: function(f) {
+ this.onRebindCallbacks.push(f);
+ // function(shortcut, keybinding, oldKeybinding)
// NOTE: You may want to hook into this if you want to save/load user preferences
// shortcut.id is probably what you want and not the whole shortcut
},
object.mousetrap.unpause();
});
},
+ bindShortcutsDisplay: function(element, options) {
+ element.innerHTML = this.displayShortcuts(options);
+ var self = this;
+ this.onRebindShortcut(function() {
+ element.innerHTML = self.displayShortcuts(options);
+ });
+ this.onNewShortcut(function() {
+ element.innerHTML = self.displayShortcuts(options);
+ });
+ },
displayShortcuts: function(options) {
options = _.defaults({}, options, {
objectGrouping: "default", // Display one list, or group under headers by object type? "true" "false", or "default"
var multipleObjectTypes = _.chain(shortcuts).pluck('object').unique().size().value() > 1;
options.objectGrouping = multipleObjectTypes;
}
- return '<h3>Shortcuts</h3><table>' + _.map(options.shortcuts, function(shortcut) {
- return _.template("<tr><td><%= description %></td><td><%= keybindingHtml %></td></tr>")({
+ return '<table class="shortcuts">' + _.map(options.shortcuts, function(shortcut) {
+ return _.template('<tr><td class="shortcut-description"><%= description %></td><td class="shortcut-keybinding"><%= keybindingHtml %></td></tr>')({
description: shortcut.description,
keybindingHtml: this._displayKeybinding(shortcut, options)
});
e.save();
});
});
- Shortcut.onRebindShortcut = function() {
- self.renderShortcuts();
- };
+ Shortcut.bindShortcutsDisplay(this.$("#shortcuts")[0], {allowRebind: true});
this.views = {}; // A list of views for each element in the collection
this.list.fetch();
this.render();
},
render: function() {
- this.renderShortcuts();
return this;
},
- renderShortcuts: function() {
- this.$("#shortcuts").html(Shortcut.displayShortcuts({allowRebind: true}));
- },
addOne: function(todo) {
this.renderTodo(todo);
},
globalMousetrap: globalMousetrap,
boundObjects: [globalObject],
shortcuts: {},
+ onRebindCallbacks: [],
+ onNewShortcutCallbacks: [],
registerShortcut: function(shortcut) {
if (arguments.length > 1) {
shortcut = {
if (this.shortcuts[shortcut.id]) return this.shortcuts[shortcut.id];
this.shortcuts[shortcut.id] = shortcut;
_.chain(this.boundObjects).where({'type':shortcut.object}).each(_.partial(this.bindShortcut, shortcut, _), this).value();
+ _.each(this.onNewShortcutCallbacks, function(callback) {
+ callback.call(this, shortcut);
+ }, this);
return shortcut;
},
unregisterShortcut: function(shortcut) {
shortcut.unbind();
shortcut._keybinding = keybinding;
_.each(objects, shortcut.bind, shortcut);
- if (this.onRebindShortcut) this.onRebindShortcut(shortcut, keybinding, oldKeybinding);
+ if (this.onRebindCallbacks) {
+ _.each(this.onRebindCallbacks, function(f) {
+ f.call(this, shortcut, keybinding, oldKeybinding);
+ });
+ }
},
userRebindShortcut: function(shortcut, options) {
// Cancels on focus loss or if the user presses the escape key
shortcutPressed: function(shortcut, object) {
if (shortcut.action) return shortcut.action(object.element, shortcut, object.type, object.options);
},
- onRebindShortcut: function(shortcut, keybinding, oldKeybinding) {
+ onNewShortcut: function(f) {
+ this.onNewShortcutCallbacks.push(f);
+ },
+ onRebindShortcut: function(f) {
+ this.onRebindCallbacks.push(f);
+ // function(shortcut, keybinding, oldKeybinding)
// NOTE: You may want to hook into this if you want to save/load user preferences
// shortcut.id is probably what you want and not the whole shortcut
},
object.mousetrap.unpause();
});
},
+ bindShortcutsDisplay: function(element, options) {
+ element.innerHTML = this.displayShortcuts(options);
+ var self = this;
+ this.onRebindShortcut(function() {
+ element.innerHTML = self.displayShortcuts(options);
+ });
+ this.onNewShortcut(function() {
+ element.innerHTML = self.displayShortcuts(options);
+ });
+ },
displayShortcuts: function(options) {
options = _.defaults({}, options, {
objectGrouping: "default", // Display one list, or group under headers by object type? "true" "false", or "default"
var multipleObjectTypes = _.chain(shortcuts).pluck('object').unique().size().value() > 1;
options.objectGrouping = multipleObjectTypes;
}
- return '<h3>Shortcuts</h3><table>' + _.map(options.shortcuts, function(shortcut) {
- return _.template("<tr><td><%= description %></td><td><%= keybindingHtml %></td></tr>")({
+ return '<table class="shortcuts">' + _.map(options.shortcuts, function(shortcut) {
+ return _.template('<tr><td class="shortcut-description"><%= description %></td><td class="shortcut-keybinding"><%= keybindingHtml %></td></tr>')({
description: shortcut.description,
keybindingHtml: this._displayKeybinding(shortcut, options)
});
e.save();
});
});
- Shortcut.onRebindShortcut = function() {
- self.renderShortcuts();
- };
+ Shortcut.bindShortcutsDisplay(this.$("#shortcuts")[0], {allowRebind: true});
this.views = {}; // A list of views for each element in the collection
this.list.fetch();
this.render();
},
render: function() {
- this.renderShortcuts();
return this;
},
- renderShortcuts: function() {
- this.$("#shortcuts").html(Shortcut.displayShortcuts({allowRebind: true}));
- },
addOne: function(todo) {
this.renderTodo(todo);
},