Commit 9fc18e15 authored by Duilio Protti's avatar Duilio Protti Committed by Sindre Sorhus

Close GH-924: Spine - cancel editing on escape keypress. Fixes #789

parent 5b1af514
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.7.1
(function() {
var TodoApp,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
......@@ -43,10 +43,10 @@
this.routes({
'/:filter': function(param) {
this.filter = param.filter;
/*
TODO: Need to figure out why the route doesn't trigger `change` event
*/
*/
Todo.trigger('refresh');
return this.filters.removeClass('selected').filter("[href='#/" + this.filter + "']").addClass('selected');
}
......@@ -97,11 +97,11 @@
TodoApp.prototype.toggleAll = function(e) {
return Todo.each(function(todo) {
/*
TODO: Model updateAttribute sometimes won't stick:
https://github.com/maccman/spine/issues/219
*/
*/
todo.updateAttribute('completed', e.target.checked);
return todo.trigger('update', todo);
});
......
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.7.1
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.Todos = (function(_super) {
var ENTER_KEY, TPL;
var ENTER_KEY, ESCAPE_KEY, TPL;
__extends(Todos, _super);
ENTER_KEY = 13;
ESCAPE_KEY = 27;
TPL = Handlebars.compile($('#todo-template').html());
Todos.prototype.elements = {
......@@ -21,6 +23,7 @@
'click .destroy': 'remove',
'click .toggle': 'toggleStatus',
'dblclick label': 'edit',
'keydown .edit': 'revertEditOnEscape',
'keyup .edit': 'finishEditOnEnter',
'blur .edit': 'finishEdit'
};
......@@ -67,6 +70,17 @@
}
};
Todos.prototype.revertEdit = function() {
this.el.removeClass('editing');
return this.editElem.val(this.todo.title);
};
Todos.prototype.revertEditOnEscape = function(e) {
if (e.which === ESCAPE_KEY) {
return this.revertEdit();
}
};
return Todos;
})(Spine.Controller);
......
// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.7.1
(function() {
var _ref,
__hasProp = {}.hasOwnProperty,
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
window.Todo = (function(_super) {
__extends(Todo, _super);
function Todo() {
_ref = Todo.__super__.constructor.apply(this, arguments);
return _ref;
return Todo.__super__.constructor.apply(this, arguments);
}
Todo.configure('Todo', 'title', 'completed');
......@@ -29,11 +27,11 @@
};
Todo.destroyCompleted = function() {
var todo, _i, _len, _ref1, _results;
_ref1 = this.completed();
var todo, _i, _len, _ref, _results;
_ref = this.completed();
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
todo = _ref1[_i];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
todo = _ref[_i];
_results.push(todo.destroy());
}
return _results;
......
class window.Todos extends Spine.Controller
ENTER_KEY = 13
ESCAPE_KEY = 27
TPL = Handlebars.compile $('#todo-template').html()
elements:
......@@ -9,6 +10,7 @@ class window.Todos extends Spine.Controller
'click .destroy': 'remove'
'click .toggle': 'toggleStatus'
'dblclick label': 'edit'
'keydown .edit': 'revertEditOnEscape'
'keyup .edit': 'finishEditOnEnter'
'blur .edit': 'finishEdit'
......@@ -38,3 +40,11 @@ class window.Todos extends Spine.Controller
finishEditOnEnter: (e) ->
@finishEdit() if e.which is ENTER_KEY
revertEdit: ->
@el.removeClass 'editing'
@editElem.val(@todo.title)
revertEditOnEscape: (e) ->
@revertEdit() if e.which is ESCAPE_KEY
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