files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
globals: {
- jQuery: true
+ jQuery: true,
}
}
},
});
},
shortcutPressed: function(shortcut, object) {
- if (shortcut.action) shortcut.action(object.element, shortcut, object.type);
+ if (shortcut.action) return shortcut.action(object.element, shortcut, object.type, object.options);
},
onRebindShortcut: 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
},
- addObject: function(element, type) {
+ addObject: function(element, type, options) {
var manager = this;
object = {
element:element,
mousetrap: Mousetrap(element),
remove: function() { manager.removeObject(this); },
add: function() { manager.addObject(this.element, this.type); },
+ options: options,
};
_.chain(this.shortcuts).where({'object': type}).each(_.partial(this.bindShortcut, _, object), this).value();
if (!_.contains(this.boundObjects)) this.boundObjects.push(object);
* @depend ../library/shortcut.js
*/
-
// Integrates "Shortcuts" library with backbone views, to allow events in the form "Shortcut(id, description, default keycombo)": action
// Shortcut selectors are not supported
(function (View, Shortcut) {
});
}
function delegateMousetrapEvents(events, objectType) {
- for (var key in events) {
- var method = events[key];
- if (!_.isFunction(method)) method = this[events[key]];
- if (!method) continue;
+ _.each(events, function(method, key) {
+ if (!_.isFunction(method)) method = this[method];
+ if (!method) return;
var match = key.match(ShortcutRegex);
- delegate.call(this, match[1], match[2], match[3], objectType, _.bind(method, this));
- }
+ /* jshint loopfunc: true */
+ delegate.call(this, match[1], match[2], match[3], objectType, function(element, shortcut, type, options) {
+ return method.call(options.view, element, shortcut, type, options);
+ } );
+ }, this);
this.shortcutObjects = this.shortcutObjects || [];
if (objectType === "global") {
- Shortcut.globalObject = this.$el[0];
+ Shortcut.globalObject = this.el;
this._shortcutObject = Shortcut.globalObject;
} else {
- this._shortcutObject = Shortcut.addObject(this.$el[0], objectType);
+ this._shortcutObject = Shortcut.addObject(this.el, objectType, { view: this });
}
}
View.delegateEvents = function(events) {
/**
* @depend ../library/cursorToEnd.js
- * @depend ../library/viewShortcuts.js
+ //* @depend ../library/viewShortcuts.js
*/
decodeText: function(encodedText) {
return $("<div/>").html(encodedText).text();
},
- toggleComplete: function(e) {
+ toggleComplete: function() {
this.stopEditingText();
this.model.toggleComplete();
var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false});
+ if (!next) return false;
next.getView().startEditingText();
+ return false; // Don't propogate
},
- backspace: function(e) {
+ backspace: function() {
if (this.model.hasChildren()) {
return;
}
return;
}
if (this.model.get("text") === "") {
- e.preventDefault();
this.model.remove(this.model.collection);
previousNode.getView().startEditingText({"atEnd":true});
+ return false;
} else if (this.isFocusAtBeginning()) {
- e.preventDefault();
var text = this.model.get("text");
this.model.remove(this.model.collection);
var focusReminderElement = $('<span class="focus"></span>');
previousNode.setText(previousNode.get("text") + '<span class="focus"></span>' + text);
previousNode.getView().startEditingText({"atMarker": ".focus"});
+ return false;
}
},
"delete": function(e) {
if (this.model.hasChildren()) {
return;
}
- var previousNode = this.model.previousNode(this.model.collection);
- if (!previousNode) {
+ var nextNode = this.model.nextNode(this.model.collection);
+ if (!nextNode) {
return;
}
if (this.model.get("text") === "") {
- e.preventDefault();
this.model.remove(this.model.collection);
- previousNode.getView().startEditingText({"atEnd":true});
+ nextNode.getView().startEditingText();
+ return false;
}
},
textChange: function(e) {
});
},
shortcutPressed: function(shortcut, object) {
- if (shortcut.action) shortcut.action(object.element, shortcut, object.type);
+ if (shortcut.action) return shortcut.action(object.element, shortcut, object.type, object.options);
},
onRebindShortcut: 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
},
- addObject: function(element, type) {
+ addObject: function(element, type, options) {
var manager = this;
object = {
element:element,
mousetrap: Mousetrap(element),
remove: function() { manager.removeObject(this); },
add: function() { manager.addObject(this.element, this.type); },
+ options: options,
};
_.chain(this.shortcuts).where({'object': type}).each(_.partial(this.bindShortcut, _, object), this).value();
if (!_.contains(this.boundObjects)) this.boundObjects.push(object);
* @depend ../library/shortcut.js
*/
-
// Integrates "Shortcuts" library with backbone views, to allow events in the form "Shortcut(id, description, default keycombo)": action
// Shortcut selectors are not supported
(function (View, Shortcut) {
});
}
function delegateMousetrapEvents(events, objectType) {
- for (var key in events) {
- var method = events[key];
- if (!_.isFunction(method)) method = this[events[key]];
- if (!method) continue;
+ _.each(events, function(method, key) {
+ if (!_.isFunction(method)) method = this[method];
+ if (!method) return;
var match = key.match(ShortcutRegex);
- delegate.call(this, match[1], match[2], match[3], objectType, _.bind(method, this));
- }
+ /* jshint loopfunc: true */
+ delegate.call(this, match[1], match[2], match[3], objectType, function(element, shortcut, type, options) {
+ return method.call(options.view, element, shortcut, type, options);
+ } );
+ }, this);
this.shortcutObjects = this.shortcutObjects || [];
if (objectType === "global") {
- Shortcut.globalObject = this.$el[0];
+ Shortcut.globalObject = this.el;
this._shortcutObject = Shortcut.globalObject;
} else {
- this._shortcutObject = Shortcut.addObject(this.$el[0], objectType);
+ this._shortcutObject = Shortcut.addObject(this.el, objectType, { view: this });
}
}
View.delegateEvents = function(events) {
/**
* @depend ../library/cursorToEnd.js
- * @depend ../library/viewShortcuts.js
+ //* @depend ../library/viewShortcuts.js
*/
decodeText: function(encodedText) {
return $("<div/>").html(encodedText).text();
},
- toggleComplete: function(e) {
+ toggleComplete: function() {
this.stopEditingText();
this.model.toggleComplete();
var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false});
+ if (!next) return false;
next.getView().startEditingText();
+ return false; // Don't propogate
},
- backspace: function(e) {
+ backspace: function() {
if (this.model.hasChildren()) {
return;
}
return;
}
if (this.model.get("text") === "") {
- e.preventDefault();
this.model.remove(this.model.collection);
previousNode.getView().startEditingText({"atEnd":true});
+ return false;
} else if (this.isFocusAtBeginning()) {
- e.preventDefault();
var text = this.model.get("text");
this.model.remove(this.model.collection);
var focusReminderElement = $('<span class="focus"></span>');
previousNode.setText(previousNode.get("text") + '<span class="focus"></span>' + text);
previousNode.getView().startEditingText({"atMarker": ".focus"});
+ return false;
}
},
"delete": function(e) {
if (this.model.hasChildren()) {
return;
}
- var previousNode = this.model.previousNode(this.model.collection);
- if (!previousNode) {
+ var nextNode = this.model.nextNode(this.model.collection);
+ if (!nextNode) {
return;
}
if (this.model.get("text") === "") {
- e.preventDefault();
this.model.remove(this.model.collection);
- previousNode.getView().startEditingText({"atEnd":true});
+ nextNode.getView().startEditingText();
+ return false;
}
},
textChange: function(e) {
});
},
shortcutPressed: function(shortcut, object) {
- if (shortcut.action) shortcut.action(object.element, shortcut, object.type);
+ if (shortcut.action) return shortcut.action(object.element, shortcut, object.type, object.options);
},
onRebindShortcut: 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
},
- addObject: function(element, type) {
+ addObject: function(element, type, options) {
var manager = this;
object = {
element:element,
mousetrap: Mousetrap(element),
remove: function() { manager.removeObject(this); },
add: function() { manager.addObject(this.element, this.type); },
+ options: options,
};
_.chain(this.shortcuts).where({'object': type}).each(_.partial(this.bindShortcut, _, object), this).value();
if (!_.contains(this.boundObjects)) this.boundObjects.push(object);
* @depend ../library/shortcut.js
*/
-
// Integrates "Shortcuts" library with backbone views, to allow events in the form "Shortcut(id, description, default keycombo)": action
// Shortcut selectors are not supported
(function (View, Shortcut) {
});
}
function delegateMousetrapEvents(events, objectType) {
- for (var key in events) {
- var method = events[key];
- if (!_.isFunction(method)) method = this[events[key]];
- if (!method) continue;
+ _.each(events, function(method, key) {
+ if (!_.isFunction(method)) method = this[method];
+ if (!method) return;
var match = key.match(ShortcutRegex);
- delegate.call(this, match[1], match[2], match[3], objectType, _.bind(method, this));
- }
+ /* jshint loopfunc: true */
+ delegate.call(this, match[1], match[2], match[3], objectType, function(element, shortcut, type, options) {
+ return method.call(options.view, element, shortcut, type, options);
+ } );
+ }, this);
this.shortcutObjects = this.shortcutObjects || [];
if (objectType === "global") {
- Shortcut.globalObject = this.$el[0];
+ Shortcut.globalObject = this.el;
this._shortcutObject = Shortcut.globalObject;
} else {
- this._shortcutObject = Shortcut.addObject(this.$el[0], objectType);
+ this._shortcutObject = Shortcut.addObject(this.el, objectType, { view: this });
}
}
View.delegateEvents = function(events) {
/**
* @depend ../library/cursorToEnd.js
- * @depend ../library/viewShortcuts.js
+ //* @depend ../library/viewShortcuts.js
*/
decodeText: function(encodedText) {
return $("<div/>").html(encodedText).text();
},
- toggleComplete: function(e) {
+ toggleComplete: function() {
this.stopEditingText();
this.model.toggleComplete();
var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false});
+ if (!next) return false;
next.getView().startEditingText();
+ return false; // Don't propogate
},
- backspace: function(e) {
+ backspace: function() {
if (this.model.hasChildren()) {
return;
}
return;
}
if (this.model.get("text") === "") {
- e.preventDefault();
this.model.remove(this.model.collection);
previousNode.getView().startEditingText({"atEnd":true});
+ return false;
} else if (this.isFocusAtBeginning()) {
- e.preventDefault();
var text = this.model.get("text");
this.model.remove(this.model.collection);
var focusReminderElement = $('<span class="focus"></span>');
previousNode.setText(previousNode.get("text") + '<span class="focus"></span>' + text);
previousNode.getView().startEditingText({"atMarker": ".focus"});
+ return false;
}
},
"delete": function(e) {
if (this.model.hasChildren()) {
return;
}
- var previousNode = this.model.previousNode(this.model.collection);
- if (!previousNode) {
+ var nextNode = this.model.nextNode(this.model.collection);
+ if (!nextNode) {
return;
}
if (this.model.get("text") === "") {
- e.preventDefault();
this.model.remove(this.model.collection);
- previousNode.getView().startEditingText({"atEnd":true});
+ nextNode.getView().startEditingText();
+ return false;
}
},
textChange: function(e) {