mirror of
https://github.com/kennethreitz/kjvstudy.org.git
synced 2026-06-05 23:00:16 +00:00
Disable PDF buttons when offline
- PDF links/buttons are greyed out (40% opacity) when offline - Adds strikethrough and "not-allowed" cursor - Shows tooltip "PDF unavailable offline" - Prevents click events - Re-enables automatically when back online 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user