mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-08 11:48:26 -04:00
Provide option to set max search size
Former-commit-id: a34751109938bcd7b17f38b44e9a180119516775 [formerly 30f5d6c9b9b76aed8c7a1db346adf9eb22ac5943] Former-commit-id: 1edd3f260eadfa8ba9d7e86921c4cec09d09b5bc
This commit is contained in:
parent
e676fab6c2
commit
af10ba57d3
@ -652,6 +652,11 @@
|
||||
<input type="text" name="omegaChar" id="omegaCharTxt" value="Z" style="width:2em;color:steelblue;">
|
||||
(these are used to set appropriate alphabet for the Archive Index)
|
||||
</label>
|
||||
<label class="text">
|
||||
<b>Set max number of search results</b> to display:
|
||||
<input type="text" name="maxResults" id="maxResults" value="20" style="width:2em;color:steelblue;">
|
||||
(higher number will result in slower search performance)
|
||||
</label>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" name="allowHTMLExtraction" id="allowHTMLExtractionCheck">
|
||||
<span class="checkmark"></span>
|
||||
|
@ -29,11 +29,6 @@
|
||||
define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cookies', 'q', 'transformStyles', 'kiwixServe'],
|
||||
function ($, zimArchiveLoader, uiUtil, util, utf8, images, cookies, q, transformStyles, kiwixServe) {
|
||||
|
||||
/**
|
||||
* Maximum number of articles to display in a search
|
||||
* @type Integer
|
||||
*/
|
||||
var MAX_SEARCH_RESULT_SIZE = params.results; //This value is controlled in init.js, as are all parameters
|
||||
/**
|
||||
* The delay (in milliseconds) between two "keepalive" messages
|
||||
* sent to the ServiceWorker (so that it is not stopped by
|
||||
@ -897,6 +892,12 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
|
||||
this.value = params.omegaChar;
|
||||
cookies.setItem('omegaChar', params.omegaChar, Infinity);
|
||||
});
|
||||
$('input:text[name=maxResults]').on('change', function (e) {
|
||||
params.maxResults = this.value > 5 ? this.value : 5;
|
||||
params.maxResults = params.maxResults < 50 ? params.maxResults : 50;
|
||||
this.value = params.maxResults;
|
||||
cookies.setItem('maxResults', params.maxResults, Infinity);
|
||||
});
|
||||
$('input:checkbox[name=hideToolbar]').on('change', function (e) {
|
||||
params.hideToolbar = this.checked ? true : false;
|
||||
cookies.setItem('hideToolbar', params.hideToolbar, Infinity);
|
||||
@ -2106,7 +2107,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
|
||||
}
|
||||
showZIMIndex(null, sel);
|
||||
} else {
|
||||
state.selectedArchive.findDirEntriesWithPrefix(prefix.trim(), MAX_SEARCH_RESULT_SIZE, populateListOfArticles);
|
||||
state.selectedArchive.findDirEntriesWithPrefix(prefix.trim(), params.maxResults, populateListOfArticles);
|
||||
}
|
||||
} else {
|
||||
$('#searchingArticles').hide();
|
||||
@ -2119,7 +2120,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts and displays in htmlArticle the first MAX_SEARCH_RESULT_SIZE articles beginning with start
|
||||
* Extracts and displays in htmlArticle the first params.maxResults articles beginning with start
|
||||
* @param {String} start Optional index number to begin the list with
|
||||
* @param {String} prefix Optional search prefix from which to start an alphabetical search
|
||||
*/
|
||||
@ -2131,7 +2132,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
|
||||
prefix = start > 0 ? '' : prefix;
|
||||
}
|
||||
if (state.selectedArchive !== null && state.selectedArchive.isReady()) {
|
||||
state.selectedArchive.findDirEntriesWithPrefixCaseSensitive(prefix, MAX_SEARCH_RESULT_SIZE, function (dirEntryArray, nextStart) {
|
||||
state.selectedArchive.findDirEntriesWithPrefixCaseSensitive(prefix, params.maxResults, function (dirEntryArray, nextStart) {
|
||||
var docBody = document.getElementById('largeModal');
|
||||
var newHtml = "";
|
||||
for (var i = 0; i < dirEntryArray.length; i++) {
|
||||
@ -2140,10 +2141,10 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
|
||||
"'>" + (dirEntry.getTitleOrUrl()) + "</a>";
|
||||
}
|
||||
start = start ? start : 0;
|
||||
var back = start ? '<a href="#" data-start="' + (start - MAX_SEARCH_RESULT_SIZE) +
|
||||
'" class="continueAnchor"><< Previous ' + MAX_SEARCH_RESULT_SIZE + '</a>' : '';
|
||||
var next = dirEntryArray.length === MAX_SEARCH_RESULT_SIZE ? '<a href="#" data-start="' + nextStart +
|
||||
'" class="continueAnchor">Next ' + MAX_SEARCH_RESULT_SIZE + ' >></a>' : '';
|
||||
var back = start ? '<a href="#" data-start="' + (start - params.maxResults) +
|
||||
'" class="continueAnchor"><< Previous ' + params.maxResults + '</a>' : '';
|
||||
var next = dirEntryArray.length === params.maxResults ? '<a href="#" data-start="' + nextStart +
|
||||
'" class="continueAnchor">Next ' + params.maxResults + ' >></a>' : '';
|
||||
var backNext = back ? next ? back + ' | ' + next : back : next;
|
||||
backNext = '<div style="float:right;">' + backNext + '</div>\n';
|
||||
var alphaSelector = [];
|
||||
@ -2240,8 +2241,8 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
|
||||
var articleListHeaderMessageDiv = $('#articleListHeaderMessage');
|
||||
var nbDirEntry = dirEntryArray ? dirEntryArray.length : 0;
|
||||
var message;
|
||||
if (nbDirEntry >= MAX_SEARCH_RESULT_SIZE) {
|
||||
message = 'First ' + MAX_SEARCH_RESULT_SIZE + ' articles below (refine your search).';
|
||||
if (nbDirEntry >= params.maxResults) {
|
||||
message = 'First ' + params.maxResults + ' articles below (refine your search).';
|
||||
} else {
|
||||
message = nbDirEntry + ' articles found.';
|
||||
}
|
||||
@ -2253,7 +2254,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
|
||||
|
||||
var articleListDiv = document.getElementById('articleList');
|
||||
var articleListDivHtml = '';
|
||||
var listLength = dirEntryArray.length < MAX_SEARCH_RESULT_SIZE ? dirEntryArray.length : MAX_SEARCH_RESULT_SIZE;
|
||||
var listLength = dirEntryArray.length < params.maxResults ? dirEntryArray.length : params.maxResults;
|
||||
for (var i = 0; i < listLength; i++) {
|
||||
var dirEntry = dirEntryArray[i];
|
||||
var dirEntryStringId = uiUtil.htmlEscapeChars(dirEntry.toStringId());
|
||||
|
@ -39,7 +39,7 @@ params['cachedStartPage'] = false; //If you have cached the start page for quick
|
||||
params['kiwixDownloadLink'] = "https://download.kiwix.org/zim/"; //Include final slash
|
||||
|
||||
params['cookieSupport'] = checkCookies();
|
||||
params['results'] = 20; //Number of search results to display
|
||||
params['maxResults'] = ~~(getCookie('maxResults') || 20); //Number of search results to display
|
||||
params['relativeFontSize'] = ~~(getCookie('relativeFontSize') || 100); //Sets the initial font size for articles (as a percentage) - user can adjust using zoom buttons
|
||||
params['relativeUIFontSize'] = ~~(getCookie('relativeUIFontSize') || 100); //Sets the initial font size for UI (as a percentage) - user can adjust using slider in Config
|
||||
params['cssSource'] = getCookie('cssSource') || "auto"; //Set default to "auto", "desktop" or "mobile"
|
||||
@ -119,6 +119,7 @@ document.getElementById('hideActiveContentWarningCheck').checked = params.hideAc
|
||||
document.getElementById('allowHTMLExtractionCheck').checked = params.allowHTMLExtraction;
|
||||
document.getElementById('alphaCharTxt').value = params.alphaChar;
|
||||
document.getElementById('omegaCharTxt').value = params.omegaChar;
|
||||
document.getElementById('maxResults').value = params.maxResults;
|
||||
|
||||
var versionSpans = document.getElementsByClassName('version');
|
||||
for (var i = 0; i < versionSpans.length; i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user