shopping-list/public_html/js/manageRecipe.js

56 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2019-05-19 18:37:00 +02:00
$(document).ready(function () {
$("#addItem").click(addItem);
2019-05-21 16:47:14 +02:00
$("#cancel").click(function () { window.history.back() });
2019-05-19 18:37:00 +02:00
$("input[type=number]").on("focus", function () { $(this).select(); });
$("input[type=text]").on("focus", function () { $(this).select(); });
2019-05-21 09:21:59 +02:00
$(".autocomplete-ingredient").on("input", autocomplete);
2019-06-04 09:15:06 +02:00
$('#recipeDescription').summernote({
2019-06-04 09:56:31 +02:00
height: 300,
dialogsFade: true,
codeviewFilter: true,
codeviewIframeFilter: true,
toolbar: [
['style', ['style', 'bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']],
2019-06-04 09:56:31 +02:00
['font', ['color', 'fontsize']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['misc', ['undo', 'redo']],
2019-06-04 09:56:31 +02:00
['view', ['codeview', 'help']]
]
2019-06-04 09:15:06 +02:00
});
2018-10-24 15:00:27 +02:00
});
2019-05-19 18:37:00 +02:00
function removeItem(elem) {
if ($(".removeItem").length > 1) {
$(elem).parent().parent().parent().parent().remove();
}
if ($(".removeItem").length == 1) {
$(".ingredientRow").find("input[type=text]").val("");
$(".ingredientRow").find("input[type=number]").val("1");
}
}
function addItem() {
var dataID = parseInt($("#addItem").data("count")) + 1;
$("#addItem").data("count", dataID);
2019-05-21 16:47:14 +02:00
2019-05-19 18:37:00 +02:00
var clone = $($(".ingredientRow")[0]).clone();
clone.find("input[type=text]").attr("name", ("ingredient[" + dataID + "][Name]"));
2019-05-21 16:47:14 +02:00
clone.find("input[type=text]").attr("id", ("dropdownMenuAutocomplete-" + dataID));
clone.find(".dropdown-menu").attr("aria-labelledby", ("dropdownMenuAutocomplete-" + dataID));
2019-05-19 18:37:00 +02:00
clone.find("input[type=text]").val("");
2019-05-21 09:21:59 +02:00
clone.find("input[type=text]").on("input", autocomplete);
2019-05-19 18:37:00 +02:00
clone.find("input[type=text]").on("focus", function () { $(this).select(); });
clone.find("input[type=number]").attr("name", ("ingredient[" + dataID + "][Amount]"));
clone.find("input[type=number]").val("1");
clone.find("input[type=number]").on("focus", function () { $(this).select(); });
clone.find("select").attr("name", ("ingredient[" + dataID + "][Unit]"));
$(".ingredientRow").last().after(clone);
clone.find("input[type=number]").focus();
2019-05-21 16:47:14 +02:00
}