Tweak PWA mobile loading indicator

* Don't show the loading indicator when intercepted href="#" links have
  been clicked (e.g. like buttons, settings tabs)
This commit is contained in:
Noah Petherbridge 2024-08-24 19:08:40 -07:00
parent def9f6ddcf
commit 2cf4405ce0

View File

@ -16,7 +16,11 @@ document.addEventListener('DOMContentLoaded', () => {
const spinner = document.querySelector("#nonshy-pwa-loader"); const spinner = document.querySelector("#nonshy-pwa-loader");
(document.querySelectorAll("a, form") || []).forEach(node => { (document.querySelectorAll("a, form") || []).forEach(node => {
// Links: only on-site ones. // Links: only on-site ones.
if (node.tagName === 'A' && node.target === '_blank') return; if (node.tagName === 'A') {
let href = node.attributes.href?.textContent;
if (!href) return;
if (node.target === '_blank' || href.indexOf('#') === 0 || href.indexOf(location.pathname) === 0) return;
}
// Show our spinner on click or submit. // Show our spinner on click or submit.
node.addEventListener(node.tagName === 'A' ? 'click' : 'submit', () => { node.addEventListener(node.tagName === 'A' ? 'click' : 'submit', () => {