diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index aa6d71f1..ad1f029b 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -15,9 +15,9 @@ jobs: - uses: actions/checkout@v4 - name: Install jshint run: | - sudo npm install -g jshint@2.13.3 + sudo npm install -g jshint@2.13.6 - name: Run jshint - run: jshint ui/static/js/*.js + run: jshint internal/ui/static/js/*.js golangci: name: Golang Linter diff --git a/internal/ui/static/js/app.js b/internal/ui/static/js/app.js index 658b869c..0909562e 100644 --- a/internal/ui/static/js/app.js +++ b/internal/ui/static/js/app.js @@ -28,49 +28,49 @@ function onAuxClick(selector, callback, noPreventDefault) { // make logo element as button on mobile layout function checkMenuToggleModeByLayout() { const logoElement = document.querySelector(".logo"); - const homePageLinkElement = document.querySelector(".logo > a") - if (!logoElement) return - const logoToggleButtonLabel = logoElement.getAttribute("data-toggle-button-label") + const homePageLinkElement = document.querySelector(".logo > a"); + if (!logoElement) return; + const logoToggleButtonLabel = logoElement.getAttribute("data-toggle-button-label"); const navMenuElement = document.getElementById("header-menu"); - const navMenuElementIsExpanded = navMenuElement.classList.contains("js-menu-show") + const navMenuElementIsExpanded = navMenuElement.classList.contains("js-menu-show"); if (document.documentElement.clientWidth < 620) { logoElement.setAttribute("role", "button"); logoElement.setAttribute("tabindex", "0"); - logoElement.setAttribute("aria-label", logoToggleButtonLabel) + logoElement.setAttribute("aria-label", logoToggleButtonLabel); if (navMenuElementIsExpanded) { - logoElement.setAttribute("aria-expanded", "true") + logoElement.setAttribute("aria-expanded", "true"); } else { - logoElement.setAttribute("aria-expanded", "false") + logoElement.setAttribute("aria-expanded", "false"); } - homePageLinkElement.setAttribute("tabindex", "-1") + homePageLinkElement.setAttribute("tabindex", "-1"); } else { logoElement.removeAttribute("role"); logoElement.removeAttribute("tabindex"); logoElement.removeAttribute("aria-expanded"); - logoElement.removeAttribute("aria-label") + logoElement.removeAttribute("aria-label"); homePageLinkElement.removeAttribute("tabindex"); } } function fixVoiceOverDetailsSummaryBug() { - const detailsElements = document.querySelectorAll("details") + const detailsElements = document.querySelectorAll("details"); detailsElements.forEach((details) => { - const summaryElement = details.querySelector("summary") - summaryElement.setAttribute("role", "button") - setSummaryAriaExpandedByDetails(details, summaryElement) + const summaryElement = details.querySelector("summary"); + summaryElement.setAttribute("role", "button"); + setSummaryAriaExpandedByDetails(details, summaryElement); details.addEventListener("toggle", () => { - setSummaryAriaExpandedByDetails(details, summaryElement) - }) - }) + setSummaryAriaExpandedByDetails(details, summaryElement); + }); + }); function setSummaryAriaExpandedByDetails(details, summary) { if (details.open) { - summary.setAttribute("aria-expanded", "true") + summary.setAttribute("aria-expanded", "true"); } else { - summary.setAttribute("aria-expanded", "false") + summary.setAttribute("aria-expanded", "false"); } } } @@ -78,20 +78,21 @@ function fixVoiceOverDetailsSummaryBug() { // Show and hide the main menu on mobile devices. function toggleMainMenu(event) { if (event.type === "keydown" && !(event.key === "Enter" || event.key === " ")) { - return + return; } + if (event.currentTarget.getAttribute("role")) { - event.preventDefault() + event.preventDefault(); } let menu = document.querySelector(".header nav ul"); let menuToggleButton = document.querySelector(".logo"); if (menu.classList.contains("js-menu-show")) { - menu.classList.remove("js-menu-show") - menuToggleButton.setAttribute("aria-expanded", false) + 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.add("js-menu-show"); + menuToggleButton.setAttribute("aria-expanded", true); } } @@ -352,7 +353,7 @@ function handleFetchOriginalContent() { return; } - let previousElement = element.cloneNode(true) + let previousElement = element.cloneNode(true); element.innerHTML = '' + element.dataset.labelLoading + ''; let request = new RequestBuilder(element.dataset.fetchContentUrl); @@ -572,7 +573,7 @@ function isListView() { function findEntry(element) { if (isListView()) { if (element) { - return element.closest(".item") + return element.closest(".item"); } else { return document.querySelector(".current-item"); } diff --git a/internal/ui/static/js/bootstrap.js b/internal/ui/static/js/bootstrap.js index fcc4d648..53793a4c 100644 --- a/internal/ui/static/js/bootstrap.js +++ b/internal/ui/static/js/bootstrap.js @@ -52,7 +52,7 @@ document.addEventListener("DOMContentLoaded", () => { if (WebAuthnHandler.isWebAuthnSupported()) { const webauthnHandler = new WebAuthnHandler(); - onClick("#webauthn-delete", () => { webauthnHandler.removeAllCredentials() }); + onClick("#webauthn-delete", () => { webauthnHandler.removeAllCredentials(); }); let registerButton = document.getElementById("webauthn-register"); if (registerButton != null) { @@ -112,12 +112,12 @@ document.addEventListener("DOMContentLoaded", () => { } }, true); - checkMenuToggleModeByLayout() - window.addEventListener("resize", checkMenuToggleModeByLayout, { passive: true }) + checkMenuToggleModeByLayout(); + window.addEventListener("resize", checkMenuToggleModeByLayout, { passive: true }); - fixVoiceOverDetailsSummaryBug() + fixVoiceOverDetailsSummaryBug(); - const logoElement = document.querySelector(".logo") + const logoElement = document.querySelector(".logo"); logoElement.addEventListener("click", (event) => toggleMainMenu(event)); logoElement.addEventListener("keydown", (event) => toggleMainMenu(event)); diff --git a/internal/ui/static/js/touch_handler.js b/internal/ui/static/js/touch_handler.js index 4e2657cb..37c14e86 100644 --- a/internal/ui/static/js/touch_handler.js +++ b/internal/ui/static/js/touch_handler.js @@ -31,7 +31,7 @@ class TouchHandler { return element; } - return element.closest(".entry-swipe") + return element.closest(".entry-swipe"); } onItemTouchStart(event) {