From e53369a5a2001b445dc73948ccc1ef1c3da7fe85 Mon Sep 17 00:00:00 2001 From: Abhishek Das Date: Mon, 25 Mar 2013 01:17:16 +0530 Subject: [PATCH] Insert new task when ENTER is pressed --- index.html | 2 +- javascripts/app.js | 1 + javascripts/views/task.js | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 3a297fa..5f6ad11 100644 --- a/index.html +++ b/index.html @@ -31,7 +31,7 @@ diff --git a/javascripts/app.js b/javascripts/app.js index 5e89968..860b05d 100644 --- a/javascripts/app.js +++ b/javascripts/app.js @@ -1,4 +1,5 @@ var app = app || {}; +var ENTER_KEY = 13; $(function(){ diff --git a/javascripts/views/task.js b/javascripts/views/task.js index 959ff5d..4d2a34e 100644 --- a/javascripts/views/task.js +++ b/javascripts/views/task.js @@ -31,8 +31,13 @@ var app = app || {}; this.$el.removeClass('editing'); }, - add: function() { - this.$input.blur(); + add: function(e) { + if (e.which === ENTER_KEY) { + this.$input.blur(); + var render = new app.TaskView({model: new app.Task()}).render(); + render.$el.insertAfter(this.$el); + render.$input.focus(); + } } });