From e42a552d43baccee40a443043d01eb8ef698765f Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sat, 13 Oct 2018 12:21:36 +0100 Subject: [PATCH] Fix article search messages Former-commit-id: 09c7876e62222d3a017272ff7a4e103b11c1c5df [formerly 9712cae5383a9d42c323ada1e306f5ce44c514e3] Former-commit-id: 6234669e864111e75db441299edb5affededcf64 --- www/js/app.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index e044d2f9..929f27e5 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1624,7 +1624,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module' */ function searchDirEntriesFromPrefix(prefix) { if (selectedArchive !== null && selectedArchive.isReady()) { - selectedArchive.findDirEntriesWithPrefix(prefix.trim(), MAX_SEARCH_RESULT_SIZE, populateListOfArticles); + selectedArchive.findDirEntriesWithPrefix(prefix.trim(), MAX_SEARCH_RESULT_SIZE + 1, populateListOfArticles); } else { $('#searchingArticles').hide(); // We have to remove the focus from the search field, @@ -1641,18 +1641,14 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module' * @param {Array.} dirEntryArray * @param {Integer} maxArticles */ - function populateListOfArticles(dirEntryArray, maxArticles) { + function populateListOfArticles(dirEntryArray) { var articleListHeaderMessageDiv = $('#articleListHeaderMessage'); - var nbDirEntry = 0; - if (dirEntryArray) { - nbDirEntry = dirEntryArray.length; - } - + var nbDirEntry = dirEntryArray ? dirEntryArray.length : 0; var message; - if (maxArticles >= 0 && nbDirEntry >= maxArticles) { - message = maxArticles + " first articles below (refine your search)."; + if (nbDirEntry >= MAX_SEARCH_RESULT_SIZE) { + message = "First " + MAX_SEARCH_RESULT_SIZE + " articles below (refine your search):"; } else { - message = nbDirEntry + " articles found."; + message = nbDirEntry + " articles found:"; } if (nbDirEntry === 0) { message = "No articles found."; @@ -1660,12 +1656,11 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module' articleListHeaderMessageDiv.html(message); - var articleListDiv = $('#articleList'); var articleListDivHtml = ""; - for (var i = 0; i < dirEntryArray.length; i++) { + var listLength = dirEntryArray.length < MAX_SEARCH_RESULT_SIZE ? dirEntryArray.length : MAX_SEARCH_RESULT_SIZE; + for (var i = 0; i < listLength; i++) { var dirEntry = dirEntryArray[i]; - articleListDivHtml += "" + dirEntry.title + ""; }