Commit 89c59e10 authored by Peter Michaux's avatar Peter Michaux

allow escape key to end edit mode of a todo

parent 7bd29bc5
...@@ -13,9 +13,15 @@ maria.Controller.subclass(checkit, 'TodoController', { ...@@ -13,9 +13,15 @@ maria.Controller.subclass(checkit, 'TodoController', {
this.getView().showEdit(); this.getView().showEdit();
}, },
onKeyupEdit: function(evt) { onKeyupEdit: function(evt) {
if (checkit.isEnterKeyCode(evt.keyCode)) { var keyCode = evt.keyCode;
if (checkit.isEnterKeyCode(keyCode)) {
this.onBlurEdit(); this.onBlurEdit();
} }
else if (checkit.isEscapeKeyCode(keyCode)) {
var view = this.getView();
view.resetEdit();
view.showDisplay();
}
}, },
onBlurEdit: function() { onBlurEdit: function() {
var model = this.getModel(); var model = this.getModel();
......
...@@ -16,3 +16,7 @@ checkit.escapeHTML = function(str) { ...@@ -16,3 +16,7 @@ checkit.escapeHTML = function(str) {
checkit.isEnterKeyCode = function(keyCode) { checkit.isEnterKeyCode = function(keyCode) {
return keyCode === 13; return keyCode === 13;
}; };
checkit.isEscapeKeyCode = function(keyCode) {
return keyCode === 27;
};
...@@ -24,9 +24,13 @@ maria.ElementView.subclass(checkit, 'TodoView', { ...@@ -24,9 +24,13 @@ maria.ElementView.subclass(checkit, 'TodoView', {
update: function() { update: function() {
this.buildData(); this.buildData();
}, },
showEdit: function() { resetEdit: function() {
var input = this.find('.edit'); var input = this.find('.edit');
input.value = this.getModel().getTitle(); input.value = this.getModel().getTitle();
},
showEdit: function() {
this.resetEdit();
var input = this.find('.edit');
aristocrat.addClass(this.find('li'), 'editing'); aristocrat.addClass(this.find('li'), 'editing');
input.focus(); input.focus();
}, },
......
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