Skip to content

Commit

Permalink
Fixes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 4, 2019
1 parent 690b532 commit 806cec5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<name>Cookbook</name>
<summary>An integrated cookbook using schema.org JSON files as recipes</summary>
<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>
<version>0.1.7</version>
<version>0.1.8</version>
<licence>agpl</licence>
<author mail="em@il.jeppez.app" >Jeppe Zapp</author>
<namespace>Cookbook</namespace>
Expand Down
35 changes: 33 additions & 2 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ var Content = function (cookbook) {

$('#app-content-wrapper form .icon-add').off('click');
$('#app-content-wrapper form .icon-add').click(self.onAddListItem);

$('#app-content-wrapper form ul li input[type="text"]').off('keypress');
$('#app-content-wrapper form ul li input[type="text"]').on('keypress', self.onListInputKeyDown);

$('#app-content-wrapper form').off('submit');
$('#app-content-wrapper form').submit(self.onUpdateRecipe);
Expand All @@ -159,6 +162,9 @@ var Content = function (cookbook) {
self.updateListItems = function(e) {
$('#app-content-wrapper form .icon-delete').off('click');
$('#app-content-wrapper form .icon-delete').click(self.onDeleteListItem);

$('#app-content-wrapper form ul li input[type="text"]').off('keypress');
$('#app-content-wrapper form ul li input[type="text"]').on('keypress', self.onListInputKeyDown);
}

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

e.currentTarget.parentElement.parentElement.removeChild(e.currentTarget.parentElement);
};

/**
* Event: Keydown on a list itme input
*/
self.onListInputKeyDown = function(e) {
if(e.keyCode === 13 || e.keyCode === 10) {
e.preventDefault();

var $li = $(e.currentTarget).parents('li');
var $ul = $li.parents('ul');

if($li.index() >= $ul.children('li').length) {
self.onAddListItem(e);

} else {
$ul.children('li').eq($li.index()).find('input').focus();

}
}
};

/**
* Event: Click add list item
*/
self.onAddListItem = function(e) {
e.preventDefault();

var html = $(e.currentTarget).parents('ul').find('template').html();
var $ul = $(e.currentTarget).parents('ul');
var $add = $ul.find('.icon-add');
var template = $ul.find('template').html();

var $item = $(template).insertBefore($add);

$(html).insertBefore($(e.currentTarget));
$item.find('input').focus();

self.updateListItems();
};
Expand Down Expand Up @@ -353,6 +383,7 @@ var Nav = function (cookbook) {
// Reindex recipes
$('#reindex-recipes').off('click');
$('#reindex-recipes').click(self.onReindexRecipes);

};
}

Expand Down

0 comments on commit 806cec5

Please sign in to comment.