Add some extra structure to index.html, main.js, serviceWorker.js:
Moved some script code from index.html to main.js + added serviceWorker registration. Added several Comments to index.html with TAGs (supported by brackets plugin). Fixed serviceWorker.js; ServiceWorker is now working and offers offline functionality.
This commit is contained in:
parent
b0971ed56a
commit
c3d8d2c49d
@ -2,24 +2,24 @@
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<!-- NOTE: Meta Tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="Ohm management app">
|
||||
<meta name="keywords" content="">
|
||||
<meta name="author" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<!-- <meta http-equiv="refresh" content="30"> --
|
||||
|
||||
<!--vue:-->
|
||||
<!-- TODO: Doppelte Einträge => siehe Ende Body-Tag -->
|
||||
<!-- <script src="lib/vue.js"> </script>
|
||||
<script src="lib/vue-router.js"> </script>
|
||||
<script src="lib/jquery-3.3.1.min.js"> </script> -->
|
||||
<!-- TODO: vue routes-->
|
||||
<script src="home.js"></script>
|
||||
<script src="folder.js"></script>
|
||||
<script src="bookmark.js"></script>
|
||||
<script src="profil.js"></script>
|
||||
|
||||
<!-- Material Design for Bootstrap fonts and icons -->
|
||||
<!-- CSS_Material Design for Bootstrap fonts and icons -->
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons">
|
||||
|
||||
<!-- Material Design for Bootstrap CSS -->
|
||||
<!-- CSS_Material Design for Bootstrap minified CSS -->
|
||||
<link rel="stylesheet" href="https://unpkg.com/bootstrap-material-design@4.1.1/dist/css/bootstrap-material-design.min.css" integrity="sha384-wXznGJNEXNG1NFsbm0ugrLFMQPWswR3lds2VeinahP8N0zJw9VWSopbjv2x7WCvX" crossorigin="anonymous">
|
||||
|
||||
<title>oma</title>
|
||||
@ -72,59 +72,19 @@
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- Vue.js developmement library-->
|
||||
<!-- NOTE: JavaScript Libs & Files -->
|
||||
<!-- CDN_Vue.js developmement lib -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
|
||||
<!-- Vue.js minified library -->
|
||||
<!-- CDN_Vue.js minified lib -->
|
||||
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.min.js"></script> -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<!-- CDN_jQuery minified lib -->
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
||||
<!-- CDN_Popper.js lib -->
|
||||
<script src="https://unpkg.com/popper.js@1.12.6/dist/umd/popper.js" integrity="sha384-fA23ZRQ3G/J53mElWqVJEGJzU0sTs+SvzG8fXVWP+kJQ1lwFAOkcUOysnlKJC33U" crossorigin="anonymous"></script>
|
||||
<!-- CDN_Bootstrap JS lib -->
|
||||
<script src="https://unpkg.com/bootstrap-material-design@4.1.1/dist/js/bootstrap-material-design.js" integrity="sha384-CauSuKpEqAFajSpkdjv3z9t8E7RlpJ1UP0lKM/+NdtSarroVKu069AlsRPKkFBz9" crossorigin="anonymous"></script>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function(){
|
||||
$('body').bootstrapMaterialDesign();
|
||||
}, false);
|
||||
/*
|
||||
$(document).ready(function() {
|
||||
$('body').bootstrapMaterialDesign();
|
||||
});
|
||||
*/
|
||||
|
||||
</script>
|
||||
<script>
|
||||
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
|
||||
});
|
||||
*/
|
||||
|
||||
</script>
|
||||
<!-- NOTE: Call main.js -->
|
||||
<script src="main.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
|
63
public/main.js
Normal file
63
public/main.js
Normal file
@ -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
|
||||
});
|
||||
*/
|
||||
|
@ -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
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user