Răsfoiți Sursa

refactor(js): minor improvements in `app.js`

- 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
Julien Voisin 1 an în urmă
părinte
comite
1e54a073d3
1 a modificat fișierele cu 3 adăugiri și 4 ștergeri
  1. 3 4
      internal/ui/static/js/app.js

+ 3 - 4
internal/ui/static/js/app.js

@@ -71,12 +71,11 @@ function toggleMainMenu(event) {
     const menu = document.querySelector(".header nav ul");
     const menu = document.querySelector(".header nav ul");
     const menuToggleButton = document.querySelector(".logo");
     const menuToggleButton = document.querySelector(".logo");
     if (menu.classList.contains("js-menu-show")) {
     if (menu.classList.contains("js-menu-show")) {
-        menu.classList.remove("js-menu-show");
         menuToggleButton.setAttribute("aria-expanded", false);
         menuToggleButton.setAttribute("aria-expanded", false);
     } else {
     } else {
-        menu.classList.add("js-menu-show");
         menuToggleButton.setAttribute("aria-expanded", true);
         menuToggleButton.setAttribute("aria-expanded", true);
     }
     }
+    menu.classList.toggle("js-menu-show");
 }
 }
 
 
 // Handle click events for the main menu (<li> and <a>).
 // Handle click events for the main menu (<li> and <a>).
@@ -662,7 +661,7 @@ function showToast(label, iconElement) {
         const toastElementWrapper = document.getElementById("toast-wrapper");
         const toastElementWrapper = document.getElementById("toast-wrapper");
         if (toastElementWrapper) {
         if (toastElementWrapper) {
             toastElementWrapper.classList.remove('toast-animate');
             toastElementWrapper.classList.remove('toast-animate');
-            setTimeout(function () {
+            setTimeout(() => {
                 toastElementWrapper.classList.add('toast-animate');
                 toastElementWrapper.classList.add('toast-animate');
             }, 100);
             }, 100);
         }
         }
@@ -782,7 +781,7 @@ function handleMediaControl(button) {
     enclosures.forEach((enclosure) => {
     enclosures.forEach((enclosure) => {
         switch (action) {
         switch (action) {
         case "seek":
         case "seek":
-            enclosure.currentTime = enclosure.currentTime + value > 0 ? enclosure.currentTime + value : 0;
+            enclosure.currentTime = Math.min(enclosure.currentTime + value, 0);
             break;
             break;
         case "speed":
         case "speed":
             // I set a floor speed of 0.25 to avoid too slow speed where it gives the impression it stopped.
             // I set a floor speed of 0.25 to avoid too slow speed where it gives the impression it stopped.