diff options
author | Alex Shpak <alex-shpak@users.noreply.github.com> | 2020-04-12 20:50:03 +0200 |
---|---|---|
committer | Alex Shpak <alex-shpak@users.noreply.github.com> | 2020-04-12 20:50:03 +0200 |
commit | 9719692512325b5f88de666281ba286343408010 (patch) | |
tree | 2551be94373e26f668f8756bee493c9b11ee48e0 /assets | |
parent | e4e43bd9b12a3e37f0d3c2760ea7f867ba8273a7 (diff) |
Introduce serviceWorker, disabled by default
Diffstat (limited to 'assets')
-rw-r--r-- | assets/search.js | 17 | ||||
-rw-r--r-- | assets/sw-register.js | 6 |
2 files changed, 20 insertions, 3 deletions
diff --git a/assets/search.js b/assets/search.js index d6ae18b..0393d2c 100644 --- a/assets/search.js +++ b/assets/search.js @@ -12,20 +12,27 @@ document.addEventListener('keypress', focusSearchFieldOnKeyPress); - function focusSearchFieldOnKeyPress(e) { + /** + * @param {Event} event + */ + function focusSearchFieldOnKeyPress(event) { if (input === document.activeElement) { return; } - const characterPressed = String.fromCharCode(e.charCode); + const characterPressed = String.fromCharCode(event.charCode); if (!isHotkey(characterPressed)) { return; } input.focus(); - e.preventDefault(); + event.preventDefault(); } + /** + * @param {String} character + * @returns {Boolean} + */ function isHotkey(character) { const dataHotkeys = input.getAttribute('data-hotkeys') || ''; return dataHotkeys.indexOf(character) >= 0; @@ -63,6 +70,10 @@ }); } + /** + * @param {String} src + * @param {Function} callback + */ function loadScript(src, callback) { const script = document.createElement('script'); script.defer = true; diff --git a/assets/sw-register.js b/assets/sw-register.js new file mode 100644 index 0000000..583532c --- /dev/null +++ b/assets/sw-register.js @@ -0,0 +1,6 @@ +if (navigator.serviceWorker) { + navigator.serviceWorker.register( + "{{ "/sw.js" | relURL }}", + { scope: "{{ "/" | relURL }}" } + ); +} |