diff --git a/public/index.html b/public/index.html index b10dd7c..b4f37fb 100644 --- a/public/index.html +++ b/public/index.html @@ -2,24 +2,24 @@ - + - + + + + + - - + - + - + oma @@ -31,13 +31,13 @@
+ + + + + -->
@@ -54,11 +54,11 @@
+ home + folder + bookmark + person + -->
home @@ -72,59 +72,19 @@
- - + + - + - + + + - - + + diff --git a/public/main.js b/public/main.js new file mode 100644 index 0000000..26d07f0 --- /dev/null +++ b/public/main.js @@ -0,0 +1,63 @@ +/****************************************************** + * Main JavaScript file - Entry point of all JS files * + ******************************************************/ + +// NOTE: ServiceWorker Registration +if ('serviceWorker' in navigator) { + window.addEventListener('load', function () { + // Register a service worker hosted at the root of the + // site using the default scope ('/'). + return navigator.serviceWorker.register('/serviceWorker.js', { + scope: '/' + }).then(function (registration) { + return console.log('Service worker registration succeeded: ', registration); + }).catch(function (error) { + return console.log('Service worker registration failed: ', error); + }); + }); +} else { + console.log('Service workers are not supported.'); +} + +// NOTE: Set Bootstrap materialdesign +document.addEventListener("DOMContentLoaded", function () { + $('body').bootstrapMaterialDesign(); +}, false); +/* +$(document).ready(function() { + $('body').bootstrapMaterialDesign(); +}); +*/ + +// NOTE: Define routes +const routes = [{ + path: "/home", + component: RouterHome + }, + { + path: "/folder", + component: RouterFolder + }, + { + path: "/bookmark", + component: RouterBookmark + }, + { + path: "/profil", + component: RouterProfil + }, + { + path: "/entry/:what/:id", + component: RouterEntry + }, + { + path: "/entry/:what", + component: RouterEntry + }, + ]; + /* + const router = new VueRouter({ + routes + }); + */ + diff --git a/public/serviceWorker.js b/public/serviceWorker.js index d24de20..a9aea5d 100644 --- a/public/serviceWorker.js +++ b/public/serviceWorker.js @@ -1,39 +1,51 @@ 'use strict'; -// TODO: Instance var/const for version control and cache list +// NOTE: StaticCacheName & FilesToCache list +const staticCacheName = 'omapp-v1.0.0'; +const filesToCache = [ + '/', + '/index.html', + '/style.css', + '/main.js', + '/favicon.ico', + '/lib/', + '/lib/jquery-3.3.1.min.js', + '/lib/vue.js', + '/lib/vue-router.js' +]; -// NOTE: Registration -if ('serviceWorker' in navigator) { - // Register a service worker hosted at the root of the - // site using the default scope. - navigator.serviceWorker.register('/serviceWorker.js', { - scope: '/' - }).then(function (registration) { - return console.log('Service worker registration succeeded: ', registration); - }).catch(function (error) { - // registration failed - return console.log('Service worker registration failed: ', error); - }); -} else { - console.log('Service workers are not supported.'); -} +// NOTE: Registration done in main.js // NOTE: Install and activate: Populating cache self.addEventListener('install', function (event) { + console.log('Service worker installing...'); event.waitUntil( - caches.open('v1').then(function (cache) { - return cache.addAll([ - '/', - '/index.html', - '/style.css' - ]); + console.log('Trying to install service worker and static cache files.'); caches.open(staticCacheName).then(function (cache) { + return cache.addAll(filesToCache); }) ); }); -// NOTE: Fetch structure -self.addEventListener('fetch', function(event) { - +// NOTE: Activate structure and delete older cache versions +self.addEventListener('activate', function (event) { + console.log('Activating new service worker...'); + const cacheWhitelist = [staticCacheName]; + event.waitUntil( + caches.keys().then(function (cacheNames) { + return Promise.all( + cacheNames.map(function (cacheName) { + if (cacheWhitelist.indexOf(cacheName) === -1) { + return caches.delete(cacheName); + } + }) + ); + }) + ); }); -// NOTE: Activate structure <- TODO: Delete older cache versions + +// NOTE: Fetch structure // TODO: Setup fetching method +self.addEventListener('fetch', function (event) { + console.log('Fetch event for ', event.request.url); + // Perform some task +});