Files
simple-aircraft-manager-rails/app/javascript/application.js
T
rickyandClaude Opus 5.5 21ef577653 Make the app an installable PWA with an offline page
Manifest, service worker (offline fallback, cached static assets only, no
aircraft pages), new plane icon in all PWA/Apple sizes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 09:51:04 -05:00

27 lines
1.1 KiB
JavaScript

// Configure your import map in config/importmap.rb.
import "@hotwired/turbo-rails"
import "controllers"
import "chartkick"
import "Chart.bundle"
// Chart text and grid colors follow the light/dark theme.
function styleCharts() {
if (!window.Chart) return
const dark = document.documentElement.dataset.theme === "dark"
window.Chart.defaults.color = dark ? "#a3b1c6" : "#64748b"
window.Chart.defaults.borderColor = dark ? "rgba(148, 163, 184, 0.18)" : "rgba(100, 116, 139, 0.15)"
}
function restyleCharts() {
styleCharts()
if (window.Chartkick) window.Chartkick.eachChart((chart) => chart.redraw())
}
styleCharts()
// Charts can be created before this module runs, so restyle after each page load too.
document.addEventListener("turbo:load", restyleCharts)
window.addEventListener("theme:change", restyleCharts)
// Installable app (PWA): the service worker adds an offline page and caches static assets.
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => navigator.serviceWorker.register("/service-worker.js", { scope: "/" }).catch(() => {}))
}