From 19985dbb8c0aa66dc4bf7905abc1148de909097d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Tue, 11 Jan 2022 12:35:47 +0100 Subject: prvi-commit --- admin/survey/modules/mod_WPN/frontend/sw.js | 124 ++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 admin/survey/modules/mod_WPN/frontend/sw.js (limited to 'admin/survey/modules/mod_WPN/frontend/sw.js') diff --git a/admin/survey/modules/mod_WPN/frontend/sw.js b/admin/survey/modules/mod_WPN/frontend/sw.js new file mode 100644 index 0000000..f20d9ac --- /dev/null +++ b/admin/survey/modules/mod_WPN/frontend/sw.js @@ -0,0 +1,124 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +var cacheName = 'CSv4'; + +var cachedFiles = [ + /*'/frontend/', + '/index.html', + '/manifest.json', + '/js/main.js', + '/js/production.css', + '/css/main.css' + '/frontend/css/normalize.min.css', + '/frontend/img/cassidy.jpg', + '/frontend/img/cramer.jpg', + '/frontend/img/duffy.jpg', + '/frontend/img/gabor.jpg', + '/frontend/img/aths.png', + '/frontend/img/share.png', + '/frontend/apple-touch-icon.png', + '/frontend/android-chrome-192x192.png'*/ +]; + +self.addEventListener('install', function(evt){ + console.log('Service Worker Install Event'); + //Add the file to the cache + evt.waitUntil( + caches.open(cacheName).then(function(cache){ + console.log('Caching Files'); + return cache.addAll(cachedFiles); + }).then(function(){ + return self.skipWaiting(); + }).catch(function(err){ + console.log('Cache Failed', err); + }) + ); +}); + +self.addEventListener('activate', function(evt){ + console.log('Service Worker Activated'); + evt.waitUntil( + caches.keys().then(function(keyList){ + return Promise.all(keyList.map(function(key){ + if(key !== cacheName){ + console.log('Removing Old Cache', key); + return caches.delete(key) + } + })); + }) + ); + return self.clients.claim(); +}); + +/*self.addEventListener('fetch', function(evt){ + console.log('Fetch Event' + evt.request.url); + evt.respondWith( + caches.match(evt.request).then(function(response){ + return response || fetch(evt.request); + }) + ); +});*/ + +function closeNotification(msg, evt){ + console.log(msg, evt.notification.data); + evt.notification.close(); +} + +self.addEventListener('notificationclose', function(evt){ + closeNotification('Notification Closed', evt); +}); + +self.addEventListener('notificationclick', function(evt){ + if(evt.action !== 'close'){ + evt.waitUntil( + self.clients.matchAll({type: 'window', includeUncontrolled: 'true'}).then(function(allClients){ + console.log(allClients); + var matchingClient = null; + for(var i = 0; i