diff --git a/www/js/app.js b/www/js/app.js
index 4ec502258..d5d15e30b 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -30,8 +30,8 @@
// This uses require.js to structure javascript:
// http://requirejs.org/docs/api.html#define
-define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesystemAccess'],
- function($, zimArchiveLoader, uiUtil, settingsStore, abstractFilesystemAccess) {
+define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore', 'abstractFilesystemAccess'],
+ function ($, zimArchiveLoader, uiUtil, settingsStore, abstractFilesystemAccess) {
/**
* The delay (in milliseconds) between two "keepalive" messages sent to the ServiceWorker (so that it is not stopped
* by the browser, and keeps the MessageChannel to communicate with the application)
@@ -125,7 +125,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
* It is also possible for DEV (or user) to launch the app with certain settings, or to unset potentially
* problematic settings, by crafting the querystring appropriately.
*/
- (function overrideParams() {
+ (function overrideParams () {
var regexpUrlParams = /[?&]([^=]+)=([^&]+)/g;
var matches = regexpUrlParams.exec(window.location.search);
while (matches) {
@@ -164,7 +164,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
// Since contentInjectionMode can be overriden when returning from remote PWA to extension (for example), we have to prevent an infinite loop
// with code that warns the user to turn off the App Cache bypass in jQuery mode. Note that to turn OFF the bypass, we have to set the VALUE to true
- params.appCache = params.contentInjectionMode === 'jquery' ? true : params.appCache;
+ params.appCache = params.contentInjectionMode === 'jquery' ? true : params.appCache;
/**
* Set the State and UI settings associated with parameters defined above
@@ -205,7 +205,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
// Unique identifier of the article expected to be displayed
var expectedArticleURLToBeDisplayed = '';
-
+
// define and store dark preference for matchMedia
var darkPreference = window.matchMedia('(prefers-color-scheme:dark)');
// if 'prefers-color-scheme' is not supported in the browser, then the "auto" options are not displayed to the user
@@ -219,14 +219,14 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
uiUtil.applyAppTheme(params.appTheme);
// Whenever the system theme changes, call applyAppTheme function
- darkPreference.onchange = function() {
+ darkPreference.onchange = function () {
uiUtil.applyAppTheme(params.appTheme);
}
/**
* Resize the IFrame height, so that it fills the whole available height in the window
*/
- function resizeIFrame() {
+ function resizeIFrame () {
var headerStyles = getComputedStyle(document.getElementById('top'));
var iframe = document.getElementById('articleContent');
var region = document.getElementById('search-article');
@@ -235,7 +235,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
region.style.height = window.innerHeight + 'px';
} else {
// IE cannot retrieve computed headerStyles till the next paint, so we wait a few ticks
- setTimeout(function() {
+ setTimeout(function () {
// Get header height *including* its bottom margin
var headerHeight = parseFloat(headerStyles.height) + parseFloat(headerStyles.marginBottom);
iframe.style.height = window.innerHeight - headerHeight + 'px';
@@ -249,7 +249,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
// Define behavior of HTML elements
var searchArticlesFocused = false;
- $('#searchArticles').on('click', function() {
+ $('#searchArticles').on('click', function () {
var prefix = document.getElementById('prefix').value;
// Do not initiate the same search if it is already in progress
if (appstate.search.prefix === prefix && !/^(cancelled|complete)$/.test(appstate.search.status)) return;
@@ -264,17 +264,17 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
// This flag is set to true in the mousedown event below
searchArticlesFocused = false;
});
- $('#searchArticles').on('mousedown', function() {
+ $('#searchArticles').on('mousedown', function () {
// We set the flag so that the blur event of #prefix can know that the searchArticles button has been clicked
searchArticlesFocused = true;
});
- $('#formArticleSearch').on('submit', function() {
+ $('#formArticleSearch').on('submit', function () {
document.getElementById('searchArticles').click();
return false;
});
// Handle keyboard events in the prefix (article search) field
var keyPressHandled = false;
- $('#prefix').on('keydown', function(e) {
+ $('#prefix').on('keydown', function (e) {
// If user presses Escape...
// IE11 returns "Esc" and the other browsers "Escape"; regex below matches both
if (/^Esc/.test(e.key)) {
@@ -325,25 +325,25 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
}
});
// Search for titles as user types characters
- $('#prefix').on('keyup', function(e) {
+ $('#prefix').on('keyup', function (e) {
if (selectedArchive !== null && selectedArchive.isReady()) {
// Prevent processing by keyup event if we already handled the keypress in keydown event
if (keyPressHandled) { keyPressHandled = false; } else { onKeyUpPrefix(e); }
}
});
// Restore the search results if user goes back into prefix field
- $('#prefix').on('focus', function() {
+ $('#prefix').on('focus', function () {
if (document.getElementById('prefix').value !== '') { document.getElementById('articleListWithHeader').style.display = ''; }
});
// Hide the search results if user moves out of prefix field
- $('#prefix').on('blur', function() {
+ $('#prefix').on('blur', function () {
if (!searchArticlesFocused) {
appstate.search.status = 'cancelled';
document.getElementById('searchingArticles').style.display = 'none';
document.getElementById('articleListWithHeader').style.display = 'none';
}
});
- $('#btnRandomArticle').on('click', function() {
+ $('#btnRandomArticle').on('click', function () {
document.getElementById('prefix').value = '';
goToRandomArticle();
document.getElementById('welcomeText').style.display = 'none';
@@ -351,30 +351,30 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
$('.navbar-collapse').collapse('hide');
});
- $('#btnRescanDeviceStorage').on('click', function() {
+ $('#btnRescanDeviceStorage').on('click', function () {
searchForArchivesInStorage();
});
// Bottom bar :
- $('#btnBack').on('click', function() {
+ $('#btnBack').on('click', function () {
history.back();
return false;
});
- $('#btnForward').on('click', function() {
+ $('#btnForward').on('click', function () {
history.forward();
return false;
});
- $('#btnHomeBottom').on('click', function() {
+ $('#btnHomeBottom').on('click', function () {
document.getElementById('btnHome').click();
return false;
});
- $('#btnTop').on('click', function() {
+ $('#btnTop').on('click', function () {
var articleContent = document.getElementById('articleContent');
- articleContent.contentWindow.scrollTo({top: 0, behavior: 'smooth'});
+ articleContent.contentWindow.scrollTo({ top: 0, behavior: 'smooth' });
// We return true, so that the link to #top is still triggered (useful in the About section)
return true;
});
// Top menu :
- $('#btnHome').on('click', function() {
+ $('#btnHome').on('click', function () {
// Highlight the selected section in the navbar
document.getElementById('liHomeNav').setAttribute('class', 'active');
document.getElementById('liConfigureNav').setAttribute('class', '');
@@ -396,7 +396,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
document.getElementById('prefix').value = '';
document.getElementById('prefix').focus();
var articleList = document.getElementById('articleList');
- var articleListHeaderMessage = document.getElementById('articleListHeaderMessage');
+ var articleListHeaderMessage = document.getElementById('articleListHeaderMessage');
while (articleList.firstChild) articleList.removeChild(articleList.firstChild);
while (articleListHeaderMessage.firstChild) articleListHeaderMessage.removeChild(articleListHeaderMessage.firstChild);
document.getElementById('searchingArticles').style.display = 'none';
@@ -413,7 +413,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
setTimeout(resizeIFrame, 400);
return false;
});
- $('#btnConfigure').on('click', function() {
+ $('#btnConfigure').on('click', function () {
// Highlight the selected section in the navbar
document.getElementById('liHomeNav').setAttribute('class', '');
document.getElementById('liConfigureNav').setAttribute('class', 'active');
@@ -440,7 +440,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
setTimeout(resizeIFrame, 400);
return false;
});
- $('#btnAbout').on('click', function() {
+ $('#btnAbout').on('click', function () {
// Highlight the selected section in the navbar
document.getElementById('liHomeNav').setAttribute('class', '');
document.getElementById('liConfigureNav').setAttribute('class', '');
@@ -465,7 +465,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
setTimeout(resizeIFrame, 400);
return false;
});
- $('input:radio[name=contentInjectionMode]').on('change', function() {
+ $('input:radio[name=contentInjectionMode]').on('change', function () {
// Do the necessary to enable or disable the Service Worker
setContentInjectionMode(this.value);
});
@@ -502,7 +502,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
document.getElementById('disableDragAndDropCheck').addEventListener('change', function () {
params.disableDragAndDrop = !!this.checked;
settingsStore.setItem('disableDragAndDrop', params.disableDragAndDrop, Infinity);
- uiUtil.systemAlert('
We will now attempt to reload the app to apply the new setting.
' +
+ uiUtil.systemAlert('
We will now attempt to reload the app to apply the new setting.
' +
'
(If you cancel, then the setting will only be applied when you next start the app.)
', 'Reload app', true).then(function (result) {
if (result) {
window.location.reload();
@@ -550,12 +550,12 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
}
});
var titleSearchRangeVal = document.getElementById('titleSearchRangeVal');
- document.getElementById('titleSearchRange').addEventListener('change', function(e) {
+ document.getElementById('titleSearchRange').addEventListener('change', function (e) {
settingsStore.setItem('maxSearchResultsSize', e.target.value, Infinity);
params.maxSearchResultsSize = e.target.value;
titleSearchRangeVal.textContent = e.target.value;
});
- document.getElementById('titleSearchRange').addEventListener('input', function(e) {
+ document.getElementById('titleSearchRange').addEventListener('input', function (e) {
titleSearchRangeVal.textContent = e.target.value;
});
document.getElementById('modesLink').addEventListener('click', function () {
@@ -572,25 +572,25 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
console.log('Checking for updates to the PWA...');
uiUtil.checkUpdateStatus(appstate);
}, 10000);
-
- //Adds an event listener to kiwix logo and bottom navigation bar which gets triggered when these elements are dragged.
- //Returning false prevents their dragging (which can cause some unexpected behavior)
- //Doing that in javascript is the only way to make it cross-browser compatible
- document.getElementById('kiwixLogo').ondragstart=function () {return false;}
- document.getElementById('navigationButtons').ondragstart=function () {return false;}
-
- //focus search bar (#prefix) if Home key is pressed
- function focusPrefixOnHomeKey(event) {
- //check if home key is pressed
+
+ // Adds an event listener to kiwix logo and bottom navigation bar which gets triggered when these elements are dragged.
+ // Returning false prevents their dragging (which can cause some unexpected behavior)
+ // Doing that in javascript is the only way to make it cross-browser compatible
+ document.getElementById('kiwixLogo').ondragstart = function () { return false; }
+ document.getElementById('navigationButtons').ondragstart = function () { return false; }
+
+ // focus search bar (#prefix) if Home key is pressed
+ function focusPrefixOnHomeKey (event) {
+ // check if home key is pressed
if (event.key === 'Home') {
// wait to prevent interference with scrolling (default action)
- setTimeout(function() {
+ setTimeout(function () {
document.getElementById('prefix').focus();
- },0);
+ }, 0);
}
}
- //switch on/off the feature to use Home Key to focus search bar
- function switchHomeKeyToFocusSearchBar() {
+ // switch on/off the feature to use Home Key to focus search bar
+ function switchHomeKeyToFocusSearchBar () {
var iframeContentWindow = document.getElementById('articleContent').contentWindow;
// Test whether iframe is accessible (because if not, we do not want to throw an error at this point, before we can tell the user what is wrong)
var isIframeAccessible = true;
@@ -603,15 +603,15 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
if (!isIframeAccessible) return;
// when the feature is in active state
if (params.useHomeKeyToFocusSearchBar) {
- //Handle Home key press inside window(outside iframe) to focus #prefix
+ // Handle Home key press inside window(outside iframe) to focus #prefix
window.addEventListener('keydown', focusPrefixOnHomeKey);
- //only for initial empty iFrame loaded using `src` attribute
- //in any other case listener gets removed on reloading of iFrame content
+ // only for initial empty iFrame loaded using `src` attribute
+ // in any other case listener gets removed on reloading of iFrame content
iframeContentWindow.addEventListener('keydown', focusPrefixOnHomeKey);
} else {
// When the feature is not active, remove event listener for window (outside iframe)
window.removeEventListener('keydown', focusPrefixOnHomeKey);
- //if feature is deactivated and no zim content is loaded yet
+ // if feature is deactivated and no zim content is loaded yet
iframeContentWindow.removeEventListener('keydown', focusPrefixOnHomeKey);
}
}
@@ -619,7 +619,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
/**
* Checks whether we need to display an alert that the default Content Injection Mode has now been switched to ServiceWorker Mode
*/
- function checkAndDisplayInjectionModeChangeAlert() {
+ function checkAndDisplayInjectionModeChangeAlert () {
var message;
if (!params.defaultModeChangeAlertDisplayed && isServiceWorkerAvailable() && isServiceWorkerReady()) {
message = ['
We have switched you to ServiceWorker mode (this is now the default). ' +
@@ -650,7 +650,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
/**
* Displays or refreshes the API status shown to the user
*/
- function refreshAPIStatus() {
+ function refreshAPIStatus () {
var apiStatusPanel = document.getElementById('apiStatusDiv');
apiStatusPanel.classList.remove('card-success', 'card-warning', 'card-danger');
var apiPanelClass = 'card-success';
@@ -701,7 +701,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
}
apiName = params.decompressorAPI.errorStatus || apiName || 'Not initialized';
// innerHTML is used here because the API name may contain HTML entities like
- decompAPIStatusDiv.innerHTML = 'Decompressor API: ' + apiName ;
+ decompAPIStatusDiv.innerHTML = 'Decompressor API: ' + apiName;
// Update Search Provider
uiUtil.reportSearchProviderToAPIStatusPanel(params.searchProvider);
// Update PWA origin
@@ -721,7 +721,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
* If Service Worker is not available, the attributes of the memory cache are returned instead
* @returns {Promise