diff options
Diffstat (limited to 'assets/js/src')
| -rw-r--r-- | assets/js/src/application.js | 15 | ||||
| -rw-r--r-- | assets/js/src/pwa.js | 30 |
2 files changed, 35 insertions, 10 deletions
diff --git a/assets/js/src/application.js b/assets/js/src/application.js index e1b9721a0..9c236b7c4 100644 --- a/assets/js/src/application.js +++ b/assets/js/src/application.js @@ -96,15 +96,10 @@ .tooltip('_fixTitle') }) + anchors.options = { + icon: '#' + } + anchors.add('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5') + $('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5').wrapInner('<div></div>') }) - }(jQuery)) - -;(function () { - 'use strict' - - anchors.options = { - icon: '#' - } - anchors.add('.bd-content > h2, .bd-content > h3, .bd-content > h4, .bd-content > h5') -}()) diff --git a/assets/js/src/pwa.js b/assets/js/src/pwa.js new file mode 100644 index 000000000..5e1a43b08 --- /dev/null +++ b/assets/js/src/pwa.js @@ -0,0 +1,30 @@ +/* eslint no-console:off */ + +(function setupSW() { + 'use strict' + + if ('serviceWorker' in navigator) { + window.addEventListener('load', function () { + navigator.serviceWorker.register('/sw.js').then(function (registration) { // eslint-disable-line compat/compat + console.log('ServiceWorker registration successful with scope: ', registration.scope) + registration.onupdatefound = function () { + var installingWorker = registration.installing + installingWorker.onstatechange = function () { + switch (installingWorker.state) { + case 'installed': + if (navigator.serviceWorker.controller) { // eslint-disable-line compat/compat + console.log('new update available') + location.reload(true) + } + break + + default: + } + } + } + }).catch(function (err) { + console.log('ServiceWorker registration failed: ', err) + }) + }) + } +}()) |
