summaryrefslogtreecommitdiff
path: root/static/js
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-02-11 12:48:01 +0530
committerBobby <[email protected]>2026-02-11 12:48:01 +0530
commit2c567dd96712a887b42cf4df3bdaa9f5f2b51a43 (patch)
tree82c408110dff2898e64688111b08c1d79043d247 /static/js
parent519a4a81bc3ae4738835a1fcb7cfaf72a06bf13b (diff)
downloadcafe-2c567dd96712a887b42cf4df3bdaa9f5f2b51a43.tar.xz
cafe-2c567dd96712a887b42cf4df3bdaa9f5f2b51a43.zip
Refactor homepage and error templates, add service worker and manifest for PWA support
Diffstat (limited to 'static/js')
-rw-r--r--static/js/app.js23
-rw-r--r--static/js/worker.js22
2 files changed, 45 insertions, 0 deletions
diff --git a/static/js/app.js b/static/js/app.js
new file mode 100644
index 0000000..f1ec61e
--- /dev/null
+++ b/static/js/app.js
@@ -0,0 +1,23 @@
+if ('serviceWorker' in navigator) {
+ window.addEventListener('load', () => {
+ navigator.serviceWorker.register('/worker.js')
+ .then(registration => {
+ console.log('ServiceWorker registered:', registration);
+ })
+ .catch(error => {
+ console.log('ServiceWorker registration failed:', error);
+ });
+ });
+}
+
+let deferredPrompt;
+window.addEventListener('beforeinstallprompt', (e) => {
+ e.preventDefault();
+ deferredPrompt = e;
+});
+
+document.body.addEventListener('htmx:afterSwap', (event) => {
+ event.detail.elt.querySelectorAll('.animate-slide-up').forEach((el, i) => {
+ el.style.animationDelay = `${i * 0.1}s`;
+ });
+}); \ No newline at end of file
diff --git a/static/js/worker.js b/static/js/worker.js
new file mode 100644
index 0000000..84d94df
--- /dev/null
+++ b/static/js/worker.js
@@ -0,0 +1,22 @@
+const CACHE_NAME = 'cafe';
+const urlsToCache = [
+ '/',
+ '/static/css/style.css',
+ '/static/js/htmx.min.js',
+ '/static/js/app.js',
+ '/static/manifest.json'
+];
+
+self.addEventListener('install', (event) => {
+ event.waitUntil(
+ caches.open(CACHE_NAME)
+ .then((cache) => cache.addAll(urlsToCache))
+ );
+});
+
+self.addEventListener('fetch', (event) => {
+ event.respondWith(
+ caches.match(event.request)
+ .then((response) => response || fetch(event.request))
+ );
+}); \ No newline at end of file