//"click > .checkbox": "toggleComplete",
"input > .text": "textChange",
"blur > .text": "render", // Because the model shouldn't update the view during active editing, add a re-render at the end
- "keydown > .text": "keydown",
+ //"keydown > .text": "keydown",
},
initialize: function() {
this.childViewPositions = [];
comparator: 'id',
});
-// TODO: None of this code has ever been run and doesn't work
// TODO: More documentation
+// TODO: Removing objects/shortcuts/rebinding won't work until this bug is fixed in mousetrap: https://github.com/ccampbell/mousetrap/issues/267
// firstShortcut = Shortcut.registerShortcut("Control + k", function() { console.log("Shortcut pressed."); });
// firstShortcut.rebind("Control + m");
var globalMousetrap = new Mousetrap();
var globalObject = {element: document, type: "global", isGlobal: true, mousetrap: globalMousetrap};
var Shortcut = {
- globalObject: globalObject, // The object passed to callbacks when a global keybinding is invoked.
+ _globalObject: globalObject, // The object passed to callbacks when a global keybinding is invoked.
globalMousetrap: globalMousetrap,
boundObjects: [globalObject],
shortcuts: [],
unbind: function(object) { manager.unbindShortcut(this, object); },
rebind: function(keybinding) { manager.rebindShortcut(this, keybinding); },
object: "global",
- keybinding: "",
+
+ _keybinding: shortcut.keybinding || "",
action: function() {},
boundObjects: [],
ownedByUs: true
});
+ Object.defineProperty(shortcut, "keybinding", {
+ set: function (newKeybinding) { manager.rebindShortcut(shortcut, newKeybinding); },
+ get: function () { return shortcut._keybinding; },
+ });
this.shortcuts.push(shortcut);
_.chain(this.boundObjects).where({'type':shortcut.object}).each(_.partial(this.bindShortcut, shortcut, _), this).value();
return shortcut;
},
unregisterShortcut: function(shortcut) {
- _.each(shortcut.boundObjects, _.partial(this.unbindShortcut, shortcut, _), this); // TODO: This will die under mutation, find a safer 'each' method
+ _.each(_.clone(shortcut.boundObjects), _.partial(this.unbindShortcut, shortcut, _), this);
},
bindShortcut: function(shortcut, object) { // Do not call directly
- object.mousetrap.bind(shortcut.keybinding, _.bind(this.shortcutPressed, this, shortcut, object));
- shortcut.boundObjects.push(object);
+ if (!_.contains(shortcut.boundObjects, object)) {
+ object.mousetrap.bind(shortcut.keybinding, _.bind(this.shortcutPressed, this, shortcut, object));
+ shortcut.boundObjects.push(object);
+ }
},
unbindShortcut: function(shortcut, object) { // Do not call directly with an object
if (!object){
shortcut.boundObjects = _.without(shortcut.boundObjects, object);
},
rebindShortcut: function(shortcut, keybinding) {
- // TODO: figure out a way to do this with 'shorcut.keybinding=' binding
if (keybinding === shortcut.keybinding) return;
var oldKeybinding = shortcut.keybinding;
var objects = shortcut.boundObjects;
shortcut.unbind();
- shorcut.keybinding = keybinding;
+ shorcut._keybinding = keybinding;
_.each(objects, shortcut.bind, shortcut);
if (this.onRebindShortcut) this.onRebindShortcut(shortcut, keybinding, oldKeybinding);
},
});
},
shortcutPressed: function(shortcut, object) {
- if (shortcut.action) shortcut.action(object, object, shortcut);
+ if (shortcut.action) shortcut.action(object.element, shortcut, object.type);
},
onRebindShortcut: function(shortcut, keybinding, oldKeybinding) {
// NOTE: You may want to hook into this if you want to save/load user preferences
element:element,
type:type,
mousetrap: new Mousetrap(element),
- remove: function() { manager.removeObject(this); }
+ remove: function() { manager.removeObject(this); },
+ add: function() { manager.addObject(this.element, this.type); },
};
_.chain(this.shortcuts).where({'object': type}).each(_.partial(this.bindShortcut, _, object), this).value();
if (!_.contains(this.boundObjects)) this.boundObjects.push(object);
_.each(this.shortcuts, _.partial(this.unbindShortcut, _, object), this);
this.boundObjects = _.without(this.boundObjects, object);
},
- changeGlobalObject: function(newObject) {
- // TODO: Figure out how to do this with 'this.globalObject=' binding
+ get globalObject() {
+ return this._globalObject;
+ },
+ set globalObject(newElement) {
this.removeObject(this.globalObject, "global");
- this.globalObject = {
- element: element,
- type: type,
+ this._globalObject = {
+ element: newElement,
+ type: "global",
isGlobal: true,
mousetrap: this.globalMousetrap,
};
- _.chain(this.shortcuts).where({'object': type}).each(function(shortcut) { this.bindShortcut(shortcut, object); }, this).value();
- if (!_.contains(this.boundObjects)) this.boundObjects.push(object);
+ _.chain(this.shortcuts).where({'object': "global"}).each(_.partial(this.bindShortcut, _, this.globalObject), this).value();
+ if (!_.contains(this.boundObjects)) this.boundObjects.push(this.globalObject);
return this.globalObject;
},
pause: function() { // TODO: These require plugin, test
//"click > .checkbox": "toggleComplete",
"input > .text": "textChange",
"blur > .text": "render", // Because the model shouldn't update the view during active editing, add a re-render at the end
- "keydown > .text": "keydown",
+ //"keydown > .text": "keydown",
},
initialize: function() {
this.childViewPositions = [];
comparator: 'id',
});
-// TODO: None of this code has ever been run and doesn't work
// TODO: More documentation
+// TODO: Removing objects/shortcuts/rebinding won't work until this bug is fixed in mousetrap: https://github.com/ccampbell/mousetrap/issues/267
// firstShortcut = Shortcut.registerShortcut("Control + k", function() { console.log("Shortcut pressed."); });
// firstShortcut.rebind("Control + m");
var globalMousetrap = new Mousetrap();
var globalObject = {element: document, type: "global", isGlobal: true, mousetrap: globalMousetrap};
var Shortcut = {
- globalObject: globalObject, // The object passed to callbacks when a global keybinding is invoked.
+ _globalObject: globalObject, // The object passed to callbacks when a global keybinding is invoked.
globalMousetrap: globalMousetrap,
boundObjects: [globalObject],
shortcuts: [],
unbind: function(object) { manager.unbindShortcut(this, object); },
rebind: function(keybinding) { manager.rebindShortcut(this, keybinding); },
object: "global",
- keybinding: "",
+
+ _keybinding: shortcut.keybinding || "",
action: function() {},
boundObjects: [],
ownedByUs: true
});
+ Object.defineProperty(shortcut, "keybinding", {
+ set: function (newKeybinding) { manager.rebindShortcut(shortcut, newKeybinding); },
+ get: function () { return shortcut._keybinding; },
+ });
this.shortcuts.push(shortcut);
_.chain(this.boundObjects).where({'type':shortcut.object}).each(_.partial(this.bindShortcut, shortcut, _), this).value();
return shortcut;
},
unregisterShortcut: function(shortcut) {
- _.each(shortcut.boundObjects, _.partial(this.unbindShortcut, shortcut, _), this); // TODO: This will die under mutation, find a safer 'each' method
+ _.each(_.clone(shortcut.boundObjects), _.partial(this.unbindShortcut, shortcut, _), this);
},
bindShortcut: function(shortcut, object) { // Do not call directly
- object.mousetrap.bind(shortcut.keybinding, _.bind(this.shortcutPressed, this, shortcut, object));
- shortcut.boundObjects.push(object);
+ if (!_.contains(shortcut.boundObjects, object)) {
+ object.mousetrap.bind(shortcut.keybinding, _.bind(this.shortcutPressed, this, shortcut, object));
+ shortcut.boundObjects.push(object);
+ }
},
unbindShortcut: function(shortcut, object) { // Do not call directly with an object
if (!object){
shortcut.boundObjects = _.without(shortcut.boundObjects, object);
},
rebindShortcut: function(shortcut, keybinding) {
- // TODO: figure out a way to do this with 'shorcut.keybinding=' binding
if (keybinding === shortcut.keybinding) return;
var oldKeybinding = shortcut.keybinding;
var objects = shortcut.boundObjects;
shortcut.unbind();
- shorcut.keybinding = keybinding;
+ shorcut._keybinding = keybinding;
_.each(objects, shortcut.bind, shortcut);
if (this.onRebindShortcut) this.onRebindShortcut(shortcut, keybinding, oldKeybinding);
},
});
},
shortcutPressed: function(shortcut, object) {
- if (shortcut.action) shortcut.action(object, object, shortcut);
+ if (shortcut.action) shortcut.action(object.element, shortcut, object.type);
},
onRebindShortcut: function(shortcut, keybinding, oldKeybinding) {
// NOTE: You may want to hook into this if you want to save/load user preferences
element:element,
type:type,
mousetrap: new Mousetrap(element),
- remove: function() { manager.removeObject(this); }
+ remove: function() { manager.removeObject(this); },
+ add: function() { manager.addObject(this.element, this.type); },
};
_.chain(this.shortcuts).where({'object': type}).each(_.partial(this.bindShortcut, _, object), this).value();
if (!_.contains(this.boundObjects)) this.boundObjects.push(object);
_.each(this.shortcuts, _.partial(this.unbindShortcut, _, object), this);
this.boundObjects = _.without(this.boundObjects, object);
},
- changeGlobalObject: function(newObject) {
- // TODO: Figure out how to do this with 'this.globalObject=' binding
+ get globalObject() {
+ return this._globalObject;
+ },
+ set globalObject(newElement) {
this.removeObject(this.globalObject, "global");
- this.globalObject = {
- element: element,
- type: type,
+ this._globalObject = {
+ element: newElement,
+ type: "global",
isGlobal: true,
mousetrap: this.globalMousetrap,
};
- _.chain(this.shortcuts).where({'object': type}).each(function(shortcut) { this.bindShortcut(shortcut, object); }, this).value();
- if (!_.contains(this.boundObjects)) this.boundObjects.push(object);
+ _.chain(this.shortcuts).where({'object': "global"}).each(_.partial(this.bindShortcut, _, this.globalObject), this).value();
+ if (!_.contains(this.boundObjects)) this.boundObjects.push(this.globalObject);
return this.globalObject;
},
pause: function() { // TODO: These require plugin, test
new-window -n timelog "vim ~/documents/paul-timelog"
# 'b' runs a browser
-bind-key b run-shell -b "chromium file:///home/zachary/flowy/dist/main.html"
+bind-key b run-shell -b "chromium file:///home/zachary/flowy/dist/index.html"
# 'd' runs a browser and opens documentation
bind-key d run-shell -b "chromium http://backbonejs.org/"
# 'r' reloads this file (doesn't work because of the sessions and windows at the top)
-// TODO: None of this code has ever been run and doesn't work
// TODO: More documentation
+// TODO: Removing objects/shortcuts/rebinding won't work until this bug is fixed in mousetrap: https://github.com/ccampbell/mousetrap/issues/267
// firstShortcut = Shortcut.registerShortcut("Control + k", function() { console.log("Shortcut pressed."); });
// firstShortcut.rebind("Control + m");
var globalMousetrap = new Mousetrap();
var globalObject = {element: document, type: "global", isGlobal: true, mousetrap: globalMousetrap};
var Shortcut = {
- globalObject: globalObject, // The object passed to callbacks when a global keybinding is invoked.
+ _globalObject: globalObject, // The object passed to callbacks when a global keybinding is invoked.
globalMousetrap: globalMousetrap,
boundObjects: [globalObject],
shortcuts: [],
unbind: function(object) { manager.unbindShortcut(this, object); },
rebind: function(keybinding) { manager.rebindShortcut(this, keybinding); },
object: "global",
- keybinding: "",
+
+ _keybinding: shortcut.keybinding || "",
action: function() {},
boundObjects: [],
ownedByUs: true
});
+ Object.defineProperty(shortcut, "keybinding", {
+ set: function (newKeybinding) { manager.rebindShortcut(shortcut, newKeybinding); },
+ get: function () { return shortcut._keybinding; },
+ });
this.shortcuts.push(shortcut);
_.chain(this.boundObjects).where({'type':shortcut.object}).each(_.partial(this.bindShortcut, shortcut, _), this).value();
return shortcut;
},
unregisterShortcut: function(shortcut) {
- _.each(shortcut.boundObjects, _.partial(this.unbindShortcut, shortcut, _), this); // TODO: This will die under mutation, find a safer 'each' method
+ _.each(_.clone(shortcut.boundObjects), _.partial(this.unbindShortcut, shortcut, _), this);
},
bindShortcut: function(shortcut, object) { // Do not call directly
- object.mousetrap.bind(shortcut.keybinding, _.bind(this.shortcutPressed, this, shortcut, object));
- shortcut.boundObjects.push(object);
+ if (!_.contains(shortcut.boundObjects, object)) {
+ object.mousetrap.bind(shortcut.keybinding, _.bind(this.shortcutPressed, this, shortcut, object));
+ shortcut.boundObjects.push(object);
+ }
},
unbindShortcut: function(shortcut, object) { // Do not call directly with an object
if (!object){
shortcut.boundObjects = _.without(shortcut.boundObjects, object);
},
rebindShortcut: function(shortcut, keybinding) {
- // TODO: figure out a way to do this with 'shorcut.keybinding=' binding
if (keybinding === shortcut.keybinding) return;
var oldKeybinding = shortcut.keybinding;
var objects = shortcut.boundObjects;
shortcut.unbind();
- shorcut.keybinding = keybinding;
+ shorcut._keybinding = keybinding;
_.each(objects, shortcut.bind, shortcut);
if (this.onRebindShortcut) this.onRebindShortcut(shortcut, keybinding, oldKeybinding);
},
});
},
shortcutPressed: function(shortcut, object) {
- if (shortcut.action) shortcut.action(object, object, shortcut);
+ if (shortcut.action) shortcut.action(object.element, shortcut, object.type);
},
onRebindShortcut: function(shortcut, keybinding, oldKeybinding) {
// NOTE: You may want to hook into this if you want to save/load user preferences
element:element,
type:type,
mousetrap: new Mousetrap(element),
- remove: function() { manager.removeObject(this); }
+ remove: function() { manager.removeObject(this); },
+ add: function() { manager.addObject(this.element, this.type); },
};
_.chain(this.shortcuts).where({'object': type}).each(_.partial(this.bindShortcut, _, object), this).value();
if (!_.contains(this.boundObjects)) this.boundObjects.push(object);
_.each(this.shortcuts, _.partial(this.unbindShortcut, _, object), this);
this.boundObjects = _.without(this.boundObjects, object);
},
- changeGlobalObject: function(newObject) {
- // TODO: Figure out how to do this with 'this.globalObject=' binding
+ get globalObject() {
+ return this._globalObject;
+ },
+ set globalObject(newElement) {
this.removeObject(this.globalObject, "global");
- this.globalObject = {
- element: element,
- type: type,
+ this._globalObject = {
+ element: newElement,
+ type: "global",
isGlobal: true,
mousetrap: this.globalMousetrap,
};
- _.chain(this.shortcuts).where({'object': type}).each(function(shortcut) { this.bindShortcut(shortcut, object); }, this).value();
- if (!_.contains(this.boundObjects)) this.boundObjects.push(object);
+ _.chain(this.shortcuts).where({'object': "global"}).each(_.partial(this.bindShortcut, _, this.globalObject), this).value();
+ if (!_.contains(this.boundObjects)) this.boundObjects.push(this.globalObject);
return this.globalObject;
},
pause: function() { // TODO: These require plugin, test
//"click > .checkbox": "toggleComplete",
"input > .text": "textChange",
"blur > .text": "render", // Because the model shouldn't update the view during active editing, add a re-render at the end
- "keydown > .text": "keydown",
+ //"keydown > .text": "keydown",
},
initialize: function() {
this.childViewPositions = [];