From 1e54a073d387e5de509be0c46d155f7ae80fdd67 Mon Sep 17 00:00:00 2001 From: Julien Voisin Date: Sun, 12 Jan 2025 20:54:08 +0000 Subject: [PATCH] refactor(js): minor improvements in `app.js` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use `….classList.toggle` instead of `….classList.add`/`….classList.remove` in a condition - Replace a `function()` with a `() =>` - Use `Math.min` instead of a handwritten condition --- internal/ui/static/js/app.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/ui/static/js/app.js b/internal/ui/static/js/app.js index d2732fff..6df5b0bf 100644 --- a/internal/ui/static/js/app.js +++ b/internal/ui/static/js/app.js @@ -71,12 +71,11 @@ function toggleMainMenu(event) { const menu = document.querySelector(".header nav ul"); const menuToggleButton = document.querySelector(".logo"); if (menu.classList.contains("js-menu-show")) { - menu.classList.remove("js-menu-show"); menuToggleButton.setAttribute("aria-expanded", false); } else { - menu.classList.add("js-menu-show"); menuToggleButton.setAttribute("aria-expanded", true); } + menu.classList.toggle("js-menu-show"); } // Handle click events for the main menu (
  • and ). @@ -662,7 +661,7 @@ function showToast(label, iconElement) { const toastElementWrapper = document.getElementById("toast-wrapper"); if (toastElementWrapper) { toastElementWrapper.classList.remove('toast-animate'); - setTimeout(function () { + setTimeout(() => { toastElementWrapper.classList.add('toast-animate'); }, 100); } @@ -782,7 +781,7 @@ function handleMediaControl(button) { enclosures.forEach((enclosure) => { switch (action) { case "seek": - enclosure.currentTime = enclosure.currentTime + value > 0 ? enclosure.currentTime + value : 0; + enclosure.currentTime = Math.min(enclosure.currentTime + value, 0); break; case "speed": // I set a floor speed of 0.25 to avoid too slow speed where it gives the impression it stopped.