Skip to content

Commit 806cec5

Browse files
author
root
committed
Fixes #20
1 parent 690b532 commit 806cec5

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>Cookbook</name>
66
<summary>An integrated cookbook using schema.org JSON files as recipes</summary>
77
<description><![CDATA[A library for all your recipes. It uses JSON files following the schema.org recipe format. To add a recipe to the collection, you can paste in the URL of the recipe, and the provided web page will be parsed and downloaded to whichever folder you specify in the app settings.]]></description>
8-
<version>0.1.7</version>
8+
<version>0.1.8</version>
99
<licence>agpl</licence>
1010
<author mail="[email protected]" >Jeppe Zapp</author>
1111
<namespace>Cookbook</namespace>

js/script.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ var Content = function (cookbook) {
139139

140140
$('#app-content-wrapper form .icon-add').off('click');
141141
$('#app-content-wrapper form .icon-add').click(self.onAddListItem);
142+
143+
$('#app-content-wrapper form ul li input[type="text"]').off('keypress');
144+
$('#app-content-wrapper form ul li input[type="text"]').on('keypress', self.onListInputKeyDown);
142145

143146
$('#app-content-wrapper form').off('submit');
144147
$('#app-content-wrapper form').submit(self.onUpdateRecipe);
@@ -159,6 +162,9 @@ var Content = function (cookbook) {
159162
self.updateListItems = function(e) {
160163
$('#app-content-wrapper form .icon-delete').off('click');
161164
$('#app-content-wrapper form .icon-delete').click(self.onDeleteListItem);
165+
166+
$('#app-content-wrapper form ul li input[type="text"]').off('keypress');
167+
$('#app-content-wrapper form ul li input[type="text"]').on('keypress', self.onListInputKeyDown);
162168
}
163169

164170
/**
@@ -169,16 +175,40 @@ var Content = function (cookbook) {
169175

170176
e.currentTarget.parentElement.parentElement.removeChild(e.currentTarget.parentElement);
171177
};
178+
179+
/**
180+
* Event: Keydown on a list itme input
181+
*/
182+
self.onListInputKeyDown = function(e) {
183+
if(e.keyCode === 13 || e.keyCode === 10) {
184+
e.preventDefault();
185+
186+
var $li = $(e.currentTarget).parents('li');
187+
var $ul = $li.parents('ul');
188+
189+
if($li.index() >= $ul.children('li').length) {
190+
self.onAddListItem(e);
191+
192+
} else {
193+
$ul.children('li').eq($li.index()).find('input').focus();
194+
195+
}
196+
}
197+
};
172198

173199
/**
174200
* Event: Click add list item
175201
*/
176202
self.onAddListItem = function(e) {
177203
e.preventDefault();
178204

179-
var html = $(e.currentTarget).parents('ul').find('template').html();
205+
var $ul = $(e.currentTarget).parents('ul');
206+
var $add = $ul.find('.icon-add');
207+
var template = $ul.find('template').html();
208+
209+
var $item = $(template).insertBefore($add);
180210

181-
$(html).insertBefore($(e.currentTarget));
211+
$item.find('input').focus();
182212

183213
self.updateListItems();
184214
};
@@ -353,6 +383,7 @@ var Nav = function (cookbook) {
353383
// Reindex recipes
354384
$('#reindex-recipes').off('click');
355385
$('#reindex-recipes').click(self.onReindexRecipes);
386+
356387
};
357388
}
358389

0 commit comments

Comments
 (0)