Sha256: e1cf9cbf8d50ee235e4beca1b91fce8ae0e6dbe859c86ea1233f97e04ab10b84

Contents?: true

Size: 1.54 KB

Versions: 33

Compression:

Stored size: 1.54 KB

Contents

---
layout: compress
permalink: /assets/js/dist/:basename.min.js
---

if ('serviceWorker' in navigator) {
  const isEnabled = '{{ site.pwa.enabled }}' === 'true';

  if (isEnabled) {
    const swUrl = '{{ '/sw.min.js' | relative_url }}';
    const $notification = $('#notification');
    const $btnRefresh = $('#notification .toast-body>button');

    navigator.serviceWorker.register(swUrl).then((registration) => {
      {% comment %}In case the user ignores the notification{% endcomment %}
      if (registration.waiting) {
        $notification.toast('show');
      }

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

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

    let refreshing = false;

    {% comment %}Detect controller change and refresh all the opened tabs{% endcomment %}
    navigator.serviceWorker.addEventListener('controllerchange', () => {
      if (!refreshing) {
        window.location.reload();
        refreshing = true;
      }
    });
  } else {
    navigator.serviceWorker.getRegistrations().then(function (registrations) {
      for (let registration of registrations) {
        registration.unregister();
      }
    });
  }
}

Version data entries

33 entries across 33 versions & 3 rubygems

Version Path
jekyll-theme-chirpy-6.5.5 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-4.0.0 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-4.0.0.pre.beta2 assets/js/pwa/app.js
doc-theme-0.1.0 assets/js/pwa/app.js
jekyll-theme-chirpy-6.5.3 assets/js/pwa/app.js
jekyll-theme-chirpy-6.5.2 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-3.2.0 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-3.2.0.pre.beta3 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-3.2.0.pre.beta2 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-3.2.0.pre.beta1 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-3.1.4 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-3.1.2 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-3.1.1 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-3.1.0 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-3.0.1 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-3.0.0 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-1.0.2 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-1.0.1 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-1.0.0 assets/js/pwa/app.js
jekyll-theme-chirpy-customized-upe-0.1.2 assets/js/pwa/app.js