diff --git a/kjvstudy_org/templates/base.html b/kjvstudy_org/templates/base.html index e784bbf..c7bb7ba 100644 --- a/kjvstudy_org/templates/base.html +++ b/kjvstudy_org/templates/base.html @@ -2314,7 +2314,7 @@ } } - // Offline/Online indicator + // Offline/Online indicator and PDF button handling function updateOnlineStatus() { var indicator = document.getElementById('offline-indicator'); if (!indicator) { @@ -2325,16 +2325,50 @@ document.body.appendChild(indicator); } + // Find all PDF links/buttons + var pdfLinks = document.querySelectorAll('a[href*="/pdf"], .pdf-btn, a[href$=".pdf"]'); + if (!navigator.onLine) { indicator.style.display = 'block'; + // Disable PDF buttons when offline + pdfLinks.forEach(function(link) { + link.dataset.originalHref = link.href; + link.removeAttribute('href'); + link.style.opacity = '0.4'; + link.style.cursor = 'not-allowed'; + link.style.textDecoration = 'line-through'; + link.title = 'PDF unavailable offline'; + link.addEventListener('click', preventClick); + }); } else { indicator.style.display = 'none'; + // Re-enable PDF buttons when online + pdfLinks.forEach(function(link) { + if (link.dataset.originalHref) { + link.href = link.dataset.originalHref; + } + link.style.opacity = ''; + link.style.cursor = ''; + link.style.textDecoration = ''; + link.title = ''; + link.removeEventListener('click', preventClick); + }); } } + function preventClick(e) { + e.preventDefault(); + e.stopPropagation(); + } + window.addEventListener('online', updateOnlineStatus); window.addEventListener('offline', updateOnlineStatus); - updateOnlineStatus(); + // Run after DOM is ready to catch all PDF links + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', updateOnlineStatus); + } else { + updateOnlineStatus(); + } })();