diff --git a/pwabuilder-sw.js b/pwabuilder-sw.js index e5b8a681..c46e908b 100644 --- a/pwabuilder-sw.js +++ b/pwabuilder-sw.js @@ -173,7 +173,7 @@ function intercept(event) { // DEV: Electron uses the file:// protocol and hacks it to work with SW, but it has CORS issues when using the Fetch API to fetch local files, // so we must bypass it here if we're fetching a local file if (/^file:/i.test(event.request.url) && ! (regexpZIMUrlWithNamespace.test(event.request.url) && /\.zim\w{0,2}\//i.test(event.request.url))) return; - console.debug('[SW] Service Worker ' + (event.request.method === "GET" ? 'intercepted ' : 'noted ') + event.request.url, event.request.method); + // console.debug('[SW] Service Worker ' + (event.request.method === "GET" ? 'intercepted ' : 'noted ') + event.request.url, event.request.method); if (event.request.method !== "GET") return; event.respondWith( fromCache(event.request).then(function (response) { diff --git a/www/js/app.js b/www/js/app.js index 8e679366..178fd136 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -267,16 +267,17 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett }); // Hide the search results if user moves out of prefix field document.getElementById('prefix').addEventListener('blur', function () { - if (!searchArticlesFocused) { - appstate.search.state = 'cancelled'; - } - // We need to wait one tick for the activeElement to receive focus - setTimeout(function () { - if (!(/^articleList/.test(document.activeElement.id) || /^list-group/.test(document.activeElement.className))) { - document.getElementById('scrollbox').style.height = 0; - document.getElementById('articleListWithHeader').style.display = 'none'; - } - }, 1); + if (!searchArticlesFocused) { + appstate.search.state = 'cancelled'; + } + // We need to wait one tick for the activeElement to receive focus + setTimeout(function () { + if (!(/^articleList/.test(document.activeElement.id) || /^list-group/.test(document.activeElement.className))) { + document.getElementById('scrollbox').style.height = 0; + document.getElementById('articleListWithHeader').style.display = 'none'; + appstate.tempPrefix = ''; + } + }, 1); }); //Add keyboard shortcuts @@ -2749,6 +2750,8 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett } window.timeoutKeyUpPrefix = window.setTimeout(function () { var prefix = document.getElementById('prefix').value; + // console.debug(appstate.tempPrefix); + // console.debug(appstate.search.prefix); if (prefix === appstate.tempPrefix) return; if (prefix && prefix.length > 0 && prefix !== appstate.search.prefix) { appstate.tempPrefix = prefix; diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 29c0e26b..ce759ba4 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -183,17 +183,18 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'], // NB duplicates are removed before processing search array var startArray = []; // Regex below breaks the string into the pattern: group 1: alphanumericsearch; group 2: regex beginning with .* or .+, or contained in (?:regex) - var isPrefixRegExp = search.prefix.match(/^((?:[^(.]|\((?!\?:)|\.(?![*+]))+)(\(\?:.+\)|\.[*+].+)$/); + var isPrefixRegExp = search.prefix.match(/^((?:[^(.]|\((?!\?:)|\.(?![*+]))+)(\(\?:.*\)|\.[*+].*)$/); search.rgxPrefix = null; + var prefix = search.prefix; if (isPrefixRegExp) { // User has initiated a regular expression search - note the only regexp special character allowed in the alphanumeric part is \s - search.prefix = isPrefixRegExp[1].replace(/\\s/g, ' '); + prefix = isPrefixRegExp[1].replace(/\\s/g, ' '); search.rgxPrefix = new RegExp(isPrefixRegExp[1] + isPrefixRegExp[2], 'i'); } // Ensure a search is done on the string exactly as typed - startArray.push(search.prefix); + startArray.push(prefix); // Normalize any spacing and make string all lowercase - var prefix = search.prefix.replace(/\s+/g, ' ').toLocaleLowerCase(); + prefix = prefix.replace(/\s+/g, ' ').toLocaleLowerCase(); // Add lowercase string with initial uppercase (this is a very common pattern) startArray.push(prefix.replace(/^./, function (m) { return m.toLocaleUpperCase(); @@ -301,11 +302,11 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'], }); }, true).then(function(firstIndex) { var dirEntries = []; - console.debug('Scanning for "' + prefix + '"...'); var addDirEntries = function(index, lastTitle) { if (search.status === 'cancelled' || index >= firstIndex + searchWindow || index >= articleCount || lastTitle && !~lastTitle.indexOf(prefix) || search.found >= search.resultSize) { - console.debug('Sacnned ' + (index - firstIndex) + ' titles.' ); + var cnt = index - firstIndex; + if (cnt) console.debug('Sacnned ' + cnt + ' titles for "' + prefix + '"'); return { 'dirEntries': dirEntries, 'nextStart': index