mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-08-04 03:48:41 -04:00
Some eslint suggestions
This commit is contained in:
parent
16f5f75309
commit
d2271e472c
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/* global params */
|
/* global params, assetsCache */
|
||||||
/* eslint-disable indent */
|
/* eslint-disable indent */
|
||||||
|
|
||||||
import uiUtil from './uiUtil.js';
|
import uiUtil from './uiUtil.js';
|
||||||
@ -31,7 +31,7 @@ var deprecatedKeys = [
|
|||||||
var keyPrefix = params.keyPrefix;
|
var keyPrefix = params.keyPrefix;
|
||||||
|
|
||||||
// Tests for available Storage APIs (document.cookie or localStorage) and returns the best available of these
|
// Tests for available Storage APIs (document.cookie or localStorage) and returns the best available of these
|
||||||
function getBestAvailableStorageAPI() {
|
function getBestAvailableStorageAPI () {
|
||||||
// DEV: In FF extensions, cookies are blocked since at least FF 68.6 but possibly since FF 55 [kiwix-js #612]
|
// DEV: In FF extensions, cookies are blocked since at least FF 68.6 but possibly since FF 55 [kiwix-js #612]
|
||||||
var type = 'none';
|
var type = 'none';
|
||||||
// First test for localStorage API support
|
// First test for localStorage API support
|
||||||
@ -73,7 +73,7 @@ function getBestAvailableStorageAPI() {
|
|||||||
* Or, if a parameter is supplied, deletes or disables the object
|
* Or, if a parameter is supplied, deletes or disables the object
|
||||||
* @param {String} object Optional name of the object to disable or delete ('cookie', 'localStorage', 'cacheAPI')
|
* @param {String} object Optional name of the object to disable or delete ('cookie', 'localStorage', 'cacheAPI')
|
||||||
*/
|
*/
|
||||||
function reset(object) {
|
function reset (object) {
|
||||||
var performReset = function () {
|
var performReset = function () {
|
||||||
// 1. Clear any cookie entries
|
// 1. Clear any cookie entries
|
||||||
if (!object || object === 'cookie') {
|
if (!object || object === 'cookie') {
|
||||||
@ -158,7 +158,7 @@ function reset(object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gets cache names from Service Worker, as we cannot rely on having them in params.cacheNames
|
// Gets cache names from Service Worker, as we cannot rely on having them in params.cacheNames
|
||||||
function getCacheNames(callback) {
|
function getCacheNames (callback) {
|
||||||
if (navigator.serviceWorker && navigator.serviceWorker.controller) {
|
if (navigator.serviceWorker && navigator.serviceWorker.controller) {
|
||||||
var channel = new MessageChannel();
|
var channel = new MessageChannel();
|
||||||
channel.port1.onmessage = function (event) {
|
channel.port1.onmessage = function (event) {
|
||||||
@ -174,7 +174,7 @@ function getCacheNames(callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deregisters all Service Workers and reboots the app
|
// Deregisters all Service Workers and reboots the app
|
||||||
function _reloadApp() {
|
function _reloadApp () {
|
||||||
var reboot = function () {
|
var reboot = function () {
|
||||||
console.debug('Performing app reload...');
|
console.debug('Performing app reload...');
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@ -223,7 +223,7 @@ var settingsStore = {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (params.storeType !== 'local_storage') {
|
if (params.storeType !== 'local_storage') {
|
||||||
return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[-.+*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
|
return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
|
||||||
} else {
|
} else {
|
||||||
return localStorage.getItem(keyPrefix + sKey);
|
return localStorage.getItem(keyPrefix + sKey);
|
||||||
}
|
}
|
||||||
@ -233,21 +233,21 @@ var settingsStore = {
|
|||||||
if (!sKey || /^(?:expires|max-age|path|domain|secure)$/i.test(sKey)) {
|
if (!sKey || /^(?:expires|max-age|path|domain|secure)$/i.test(sKey)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var sExpires = "";
|
var sExpires = '';
|
||||||
if (vEnd) {
|
if (vEnd) {
|
||||||
switch (vEnd.constructor) {
|
switch (vEnd.constructor) {
|
||||||
case Number:
|
case Number:
|
||||||
sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
|
sExpires = vEnd === Infinity ? '; expires=Fri, 31 Dec 9999 23:59:59 GMT' : '; max-age=' + vEnd;
|
||||||
break;
|
break;
|
||||||
case String:
|
case String:
|
||||||
sExpires = "; expires=" + vEnd;
|
sExpires = '; expires=' + vEnd;
|
||||||
break;
|
break;
|
||||||
case Date:
|
case Date:
|
||||||
sExpires = "; expires=" + vEnd.toUTCString();
|
sExpires = '; expires=' + vEnd.toUTCString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
|
document.cookie = encodeURIComponent(sKey) + '=' + encodeURIComponent(sValue) + sExpires + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '') + (bSecure ? '; secure' : '');
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem(keyPrefix + sKey, sValue);
|
localStorage.setItem(keyPrefix + sKey, sValue);
|
||||||
}
|
}
|
||||||
@ -258,7 +258,7 @@ var settingsStore = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (params.storeType !== 'local_storage') {
|
if (params.storeType !== 'local_storage') {
|
||||||
document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "");
|
document.cookie = encodeURIComponent(sKey) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT' + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '');
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem(keyPrefix + sKey);
|
localStorage.removeItem(keyPrefix + sKey);
|
||||||
}
|
}
|
||||||
@ -269,12 +269,14 @@ var settingsStore = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (params.storeType !== 'local_storage') {
|
if (params.storeType !== 'local_storage') {
|
||||||
return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[-.+*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
|
return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + '\\s*\\=')).test(document.cookie);
|
||||||
} else {
|
} else {
|
||||||
return localStorage.getItem(keyPrefix + sKey) !== null;
|
return localStorage.getItem(keyPrefix + sKey) !== null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_cookieKeys: function () {
|
_cookieKeys: function () {
|
||||||
|
// Disabling linter check because this is library code
|
||||||
|
// eslint-disable-next-line no-useless-backreference
|
||||||
var aKeys = document.cookie.replace(/((?:^|\s*;)[^=]+)(?=;|$)|^\s*|\s*(?:=[^;]*)?(?:\1|$)/g, '').split(/\s*(?:=[^;]*)?;\s*/);
|
var aKeys = document.cookie.replace(/((?:^|\s*;)[^=]+)(?=;|$)|^\s*|\s*(?:=[^;]*)?(?:\1|$)/g, '').split(/\s*(?:=[^;]*)?;\s*/);
|
||||||
for (var nLen = aKeys.length, nIdx = 0; nIdx < nLen; nIdx++) {
|
for (var nLen = aKeys.length, nIdx = 0; nIdx < nLen; nIdx++) {
|
||||||
aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]);
|
aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]);
|
||||||
@ -284,7 +286,7 @@ var settingsStore = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// One-off migration of storage settings from cookies to localStorage
|
// One-off migration of storage settings from cookies to localStorage
|
||||||
function _migrateStorageSettings() {
|
function _migrateStorageSettings () {
|
||||||
console.log('Migrating Settings Store from cookies to localStorage...');
|
console.log('Migrating Settings Store from cookies to localStorage...');
|
||||||
var cookieKeys = settingsStore._cookieKeys();
|
var cookieKeys = settingsStore._cookieKeys();
|
||||||
// Note that because migration occurs before setting params.storeType, settingsStore.getItem() will get the item from
|
// Note that because migration occurs before setting params.storeType, settingsStore.getItem() will get the item from
|
||||||
|
@ -1149,7 +1149,7 @@ function reportSearchProviderToAPIStatusPanel (provider) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Warn the user that he/she clicked on an external link, and open it in a new tab
|
* Warn the user that they clicked on an external link, and open it in a new tab
|
||||||
*
|
*
|
||||||
* @param {Event} event The click event (on an anchor) to handle (optional, but if not provided, clickedAnchor must be provided)
|
* @param {Event} event The click event (on an anchor) to handle (optional, but if not provided, clickedAnchor must be provided)
|
||||||
* @param {Element} clickedAnchor The DOM anchor that has been clicked (optional, defaults to event.target)
|
* @param {Element} clickedAnchor The DOM anchor that has been clicked (optional, defaults to event.target)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user