Sha256: d4dfdcd2857ef548ba4bcf1abd4d2b6edb925f0f5f3d8d1851d3df370bc18663

Contents?: true

Size: 1.38 KB

Versions: 32

Compression:

Stored size: 1.38 KB

Contents

---
layout: compress
permalink: '/app.js'
---

const $notification = $('#notification');
const $btnRefresh = $('#notification .toast-body>button');

if ('serviceWorker' in navigator) {
    /* Registering Service Worker */
    navigator.serviceWorker.register('{{ "/sw.js" | relative_url }}')
        .then(registration => {

            /* in case the user ignores the notification */
            if (registration.waiting) {
                $notification.toast('show');
            }

            registration.addEventListener('updatefound', () => {
                registration.installing.addEventListener('statechange', () => {
                    if (registration.waiting) {
                        if (navigator.serviceWorker.controller) {
                            $notification.toast('show');
                        }
                    }
                });
            });

            $btnRefresh.click(() => {
                if (registration.waiting) {
                    registration.waiting.postMessage('SKIP_WAITING');
                }
                $notification.toast('hide');
            });
        });

    let refreshing = false;

    /* Detect controller change and refresh all the opened tabs */
    navigator.serviceWorker.addEventListener('controllerchange', () => {
        if (!refreshing) {
            window.location.reload();
            refreshing = true;
        }
    });
}

Version data entries

32 entries across 32 versions & 6 rubygems

Version Path
jekyll-theme-chirpy-6.4.2 assets/js/pwa/app.js
jekyll-theme-chirpy-6.4.1 assets/js/pwa/app.js
jekyll-theme-chirpy-6.4.0 assets/js/pwa/app.js
jekyll-theme-coo-6.4 assets/js/pwa/app.js
jekyll-theme-coo-6.3.12 assets/js/pwa/app.js
jekyll-theme-coo-6.3.11 assets/js/pwa/app.js
jekyll-theme-coo-6.3.10 assets/js/pwa/app.js
jekyll-theme-coo-6.3.9 assets/js/pwa/app.js
jekyll-theme-chirpy-6.3.1 assets/js/pwa/app.js
jekyll-theme-chirpy-6.3.0 assets/js/pwa/app.js
jekyll-theme-chirpy-6.2.3 assets/js/pwa/app.js
jekyll-theme-chirpy-6.2.2 assets/js/pwa/app.js
jekyll-theme-chirpy-6.2.1 assets/js/pwa/app.js
jekyll-theme-chirpy-6.2.0 assets/js/pwa/app.js
jekyll-theme-chirpy-birdly-6.1.2 assets/js/pwa/app.js
jekyll-theme-chirpy-birdly-6.1.0 assets/js/pwa/app.js
jekyll-theme-chirpy-birdly-6.1.1 assets/js/pwa/app.js
jekyll-theme-chirpy-6.1.0 assets/js/pwa/app.js
jekyll-theme-chirpy-birdly-6.0.2 assets/js/pwa/app.js
jekyll-theme-chirpy-6.0.1 assets/js/pwa/app.js