Module: Extras/OfflineNotification

Extra - Offline Notification

Renders a small notification bar at the very top of when the browser reports no network connection. It lets users know they are viewing a cached, offline copy of the site and that some features may be unavailable until a connection is restored.

This complements the service worker's offline cache: the service worker serves previously fetched content while the connection is down, and this notification keeps users informed of the offline state.

Initialization

To load this plugin, add it to the extras block of your config.php or theme settings.php:

'extras' => [
    // ...

    'offline-notification' => [],

    // ...
],
Since:
  • 6.0.0
Author:
  • Charlie Powell
License:
  • The MIT License (MIT)
Source:
See:

Members

(inner, constant) PAGE_LOAD_TIME :DOMHighResTimeStamp

Time the script started so we can ignore sub-2-second flickers during page load/reload.

Type:
  • DOMHighResTimeStamp
Source:

(inner, constant) cms :Object|null

Reference to the CMS instance.

window.CMS is set when the CMS core boots (see src/app/main.js). The guard below also covers the edge case where this script runs before the core is ready.

Type:
  • Object | null
Source:

(inner) notificationElement :HTMLElement|null

The notification element currently in the document body, or null.

Type:
  • HTMLElement | null
Source:

(inner, constant) options :Object

Options resolved for this plugin.

Type:
  • Object
Source:

(inner) wasOffline :boolean

Used to track if a connection was lost and subsequently reconnected.

Type:
  • boolean
Source:

Methods

(inner) extraOption(name, key, defaultValue) → {*}

Safely fetch a single extra option.

Parameters:
Name Type Description
name string

Plugin name

key string

Option key

defaultValue *
Source:
Returns:
Type
*

(inner) hideNotification()

Removes the notification element from the document body.

Source:

(inner) loadStyles()

Adds the plugin's default stylesheet to the document head if enabled and not already present.

Source:

(inner) showNotification()

Builds and inserts the notification element as the first child of .

Source:

(inner) updateNotification()

Syncs the notification visibility with the current network state.

Source: