Commit adeabde7 authored by Pascal Hartig's avatar Pascal Hartig

Merge pull request #509 from petermichaux/gh-pages

whitespace fix and allow escape key to cancel edit mode of a todo
parents 6f41dab0 89c59e10
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<footer id="info"> <footer id="info">
<p>Double-click to edit a todo</p> <p>Double-click to edit a todo</p>
<p>Created by <a href="http://github.com/petermichaux">Peter Michaux</a></p> <p>Created by <a href="http://github.com/petermichaux">Peter Michaux</a></p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p> <p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer> </footer>
</body> </body>
......
...@@ -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