From b5d6db09eda14f063febf953a157a6f927c21096 Mon Sep 17 00:00:00 2001 From: Gaurav Agarwal Date: Thu, 24 Feb 2022 04:55:55 +0530 Subject: [PATCH] Removed zimArchive's dependency on uiUtil --- www/js/app.js | 10 ++++++++-- www/js/lib/zimArchive.js | 19 ++++++++++--------- www/js/lib/zimArchiveLoader.js | 14 ++++++++------ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index e1570484..4684e69b 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1111,6 +1111,9 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys settingsStore.setItem("lastSelectedArchive", archiveDirectory, Infinity); // The archive is set : go back to home page to start searching $("#btnHome").click(); + }, function (message, label) { + // callbackError which is called in case of an error + uiUtil.systemAlert(message, label); }); } @@ -1199,6 +1202,9 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys // The archive is set : go back to home page to start searching $("#btnHome").click(); document.getElementById('downloadInstruction').style.display = 'none'; + }, function (message, label) { + // callbackError which is called in case of an error + uiUtil.systemAlert(message, label); }); } @@ -1673,12 +1679,12 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys Array.prototype.slice.call(iframe.querySelectorAll('a, area')).forEach(function (anchor) { // Attempts to access any properties of 'this' with malformed URLs causes app crash in Edge/UWP [kiwix-js #430] try { - var testHref = anchor.href; + var href = anchor.href; } catch (err) { console.error('Malformed href caused error:' + err.message); return; } - var href = anchor.getAttribute('href'); + href = anchor.getAttribute('href'); if (href === null || href === undefined || /^javascript:/i.test(anchor.protocol)) return; var anchorTarget = href.match(regexpLocalAnchorHref); if (href.length === 0) { diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 985eb401..eaef9682 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -20,8 +20,8 @@ * along with Kiwix (file LICENSE-GPLv3.txt). If not, see */ 'use strict'; -define(['zimfile', 'zimDirEntry', 'util', 'utf8', 'uiUtil'], - function(zimfile, zimDirEntry, util, utf8, uiUtil) { +define(['zimfile', 'zimDirEntry', 'util', 'utf8'], + function(zimfile, zimDirEntry, util, utf8) { /** * ZIM Archive @@ -49,8 +49,9 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8', 'uiUtil'], * @param {StorageFirefoxOS|Array} storage Storage (in this case, the path must be given) or Array of Files (path parameter must be omitted) * @param {String} path The Storage path for an OS that requires this to be specified * @param {callbackZIMArchive} callbackReady The function to call when the archive is ready to use + * @param {callbackZIMArchive} callbackError The function to call when an error occurs */ - function ZIMArchive(storage, path, callbackReady) { + function ZIMArchive(storage, path, callbackReady, callbackError) { var that = this; that._file = null; that._language = ""; //@TODO @@ -91,16 +92,16 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8', 'uiUtil'], } else { if (/.*zim..$/.test(path)) { // split archive - that._searchArchiveParts(storage, path.slice(0, -2)).then(function(fileArray) { + that._searchArchiveParts(storage, path.slice(0, -2)).then(function (fileArray) { createZimfile(fileArray); - }, function(error) { - uiUtil.systemAlert("Error reading files in split archive " + path + ": " + error, "Error reading archive files"); + }).catch(function (error) { + callbackError("Error reading files in split archive " + path + ": " + error, "Error reading archive files"); }); } else { - storage.get(path).then(function(file) { + storage.get(path).then(function (file) { createZimfile([file]); - }, function(error) { - uiUtil.systemAlert("Error reading ZIM file " + path + " : " + error, "Error reading archive file"); + }).catch(function (error) { + callbackError("Error reading ZIM file " + path + " : " + error, "Error reading archive file"); }); } } diff --git a/www/js/lib/zimArchiveLoader.js b/www/js/lib/zimArchiveLoader.js index bb31c28f..d74f3432 100644 --- a/www/js/lib/zimArchiveLoader.js +++ b/www/js/lib/zimArchiveLoader.js @@ -27,21 +27,23 @@ define(['zimArchive', 'jquery', 'uiUtil'], * Create a ZIMArchive from DeviceStorage location * @param {DeviceStorage} storage * @param {String} path - * @param {callbackZIMArchive} callback + * @param {callbackZIMArchive} callbackReady + * @param {callbackZIMArchive} callbackError * @returns {ZIMArchive} */ - function loadArchiveFromDeviceStorage(storage, path, callback) { - return new zimArchive.ZIMArchive(storage, path, callback); + function loadArchiveFromDeviceStorage(storage, path, callbackReady, callbackError) { + return new zimArchive.ZIMArchive(storage, path, callbackReady, callbackError); }; /** * Create a ZIMArchive from Files * @param {Array.} files - * @param {callbackZIMArchive} callback + * @param {callbackZIMArchive} callbackReady + * @param {callbackZIMArchive} callbackError * @returns {ZIMArchive} */ - function loadArchiveFromFiles(files, callback) { + function loadArchiveFromFiles(files, callbackReady, callbackError) { if (files.length >= 1) { - return new zimArchive.ZIMArchive(files, null, callback); + return new zimArchive.ZIMArchive(files, null, callbackReady, callbackError); } };