Commit 1d9089af authored by Sindre Sorhus's avatar Sindre Sorhus

Merge pull request #929 from dprotti/backbonerequire789

Backbone-require - cancel editing on escape keypress
parents d910f948 7f17a7b3
......@@ -7,6 +7,7 @@ define([], function () {
TodoFilter: '', // empty, active, completed
// What is the enter key constant?
ENTER_KEY: 13
ENTER_KEY: 13,
ESCAPE_KEY: 27
};
});
......@@ -20,6 +20,7 @@ define([
'dblclick label': 'edit',
'click .destroy': 'clear',
'keypress .edit': 'updateOnEnter',
'keydown .edit': 'revertOnEscape',
'blur .edit': 'close'
},
......@@ -93,6 +94,16 @@ define([
}
},
// If you're pressing `escape` we revert your change by simply leaving
// the `editing` state.
revertOnEscape: function (e) {
if (e.which === Common.ESCAPE_KEY) {
this.$el.removeClass('editing');
// Also reset the hidden input back to the original value.
this.$input.val(this.model.get('title'));
}
},
// Remove the item, destroy the model from *localStorage* and delete its view.
clear: function () {
this.model.destroy();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment