From 91c44a3fd1206899c770201916b63ea39cd83f65 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 6 Feb 2020 01:06:23 -0400 Subject: [PATCH] Remove callback function for when redirect. Rename early return condition checking function --- www/js/app.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index aca875f1..d20389a7 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1003,7 +1003,8 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles if (dirEntry.isRedirect()) { // Update expectedArticleURLToBeDisplayed before redirect. selectedArchive.resolveRedirect(dirEntry, function (resolvedDirEntry) { - updatedExpectedURLOnRedirect(resolvedDirEntry, readArticle); + expectedArticleURLToBeDisplayed = resolvedDirEntry.namespace + "/" + resolvedDirEntry.url; + readArticle(resolvedDirEntry); }); } else { params.isLandingPage = false; @@ -1019,7 +1020,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles * Check whether the given URL from given dirEntry equals the expectedArticleURLToBeDisplayed * @param {DirEntry} dirEntry The directory entry of the article to read */ - function entryIsToExpectedBeDisplayed(dirEntry) { + function isDirEntryExpectedToBeDisplayed(dirEntry) { var curArticleURL = dirEntry.namespace + "/" + dirEntry.url; if (expectedArticleURLToBeDisplayed !== curArticleURL) { @@ -1030,18 +1031,6 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles return true; } - - /** - * Update the expectedArticleURLToBeDisplayed after redirect. Fires up the callback function with resolvedDirEntry - * @param {*} resolvedDirEntry The resolvedDirEntry returned from resolvedRedirect() function. - * @param {*} callback The callback function after updating the expectedArticleURLToBeDisplayed. - */ - function updatedExpectedURLOnRedirect(resolvedDirEntry, callback){ - expectedArticleURLToBeDisplayed = resolvedDirEntry.namespace + "/" + resolvedDirEntry.url; - console.debug("On redirect, update expectedArticleURLToBeDisplayed to be :" + expectedArticleURLToBeDisplayed); - callback(resolvedDirEntry); - } - /** * Read the article corresponding to the given dirEntry * @param {DirEntry} dirEntry The directory entry of the article to read @@ -1054,7 +1043,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles // Early return if article's title is not expected to be displayed // Cause an issue if the current dirEntry is redirected from another dirEntry since the urlExpecedToBedisplayed is not updated // before redirecting. - if(! entryIsToExpectedBeDisplayed(dirEntry)){ + if(! isDirEntryExpectedToBeDisplayed(dirEntry)){ console.debug(dirEntry, " is not expected to be displayed. Early retrun in readArticle().") return; } @@ -1100,7 +1089,8 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles if (dirEntry.isRedirect()) { // Update expectedArticleURLToBeDisplayed before redirect then call readArticle. selectedArchive.resolveRedirect(dirEntry, function (resolvedDirEntry) { - updatedExpectedURLOnRedirect(resolvedDirEntry, readArticle) + expectedArticleURLToBeDisplayed = resolvedDirEntry.namespace + "/" + resolvedDirEntry.url; + readArticle(resolvedDirEntry) }); } else { // Line below was inserted to prevent the spinner being hidden, possibly by an async function, when pressing the Random button in quick succession