Move script section stuff that is implementet on more than one script section on layout

This commit is contained in:
franc
2025-05-05 17:10:05 +02:00
parent 402f5f2fe9
commit dc9a1f1b9c
4 changed files with 15 additions and 17 deletions
@@ -18,6 +18,3 @@
</div>
</form>
@section Scripts {
@await Html.PartialAsync("_ValidationScriptsPartial")
}
@@ -35,8 +35,4 @@
<button type="button" class="btn-add" onclick="addInstruction()">Schritte hinzufügen</button>
@section Scripts {
<script>
setRecipeId('@Model.RecipeId');
</script>
}
@@ -28,8 +28,4 @@
<button type="button" class="btn-add" onclick="addIngredient()">Zutat hinzufügen</button>
@section Scripts {
<script>
recipeId = '@Model.RecipeId';
</script>
}
@@ -63,7 +63,16 @@
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="https://unpkg.com/htmx.org@2.0.4/dist/htmx.js" integrity="sha384-oeUn82QNXPuVkGCkcrInrS1twIxKhkZiFfr2TdiuObZ3n3yIeMiqcRzkIcguaof1" crossorigin="anonymous"></script>
<script>
// Light/Dark mode toggle logic
let recipeId;
@if (ViewData["RecipeId"] != null)
{
<text>recipeId = '@ViewData["RecipeId"]';</text>
}
else if (ViewContext.View.Path.Contains("Recipe/Create") && Model?.CategoryId != null)
{
<text>recipeId = '@Model.CategoryId';</text>
}
const darkModeToggle = document.getElementById('darkModeToggle');
const lightModeToggle = document.getElementById('lightModeToggle');
darkModeToggle.addEventListener('click', () => {
@@ -72,8 +81,8 @@
lightModeToggle.addEventListener('click', () => {
document.body.classList.remove('bg-dark', 'text-white');
});
</script>
<script>
document.body.addEventListener('htmx:configRequest', (event) => {
const token = document.querySelector('input[name="__RequestVerificationToken"]')?.value;
if (token) {
@@ -81,7 +90,7 @@
}
});
</script>
@await Html.PartialAsync("_ValidationScriptsPartial")
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>