Problem commit, consider reverting

Former-commit-id: cf6626fcd0909892e7c021dfa0c1a3c6c3cbf527 [formerly db78a66908febd8f4e09a4adc6023f1166b4774e]
Former-commit-id: 48c3118eba049ad7fc35b4cc8c8d82cd7476bf6e
This commit is contained in:
Jaifroid 2019-08-08 13:38:32 +01:00
parent 675cb6342e
commit a638c4eed3
3 changed files with 38 additions and 29 deletions

View File

@ -1988,6 +1988,25 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
}, 500);
}
function listenForSearchKeys() {
//Listen to iframe key presses for in-page search
document.getElementById('articleContent').contentWindow.addEventListener('keyup', function (e) {
//Alt-F for search in article, also patches Ctrl-F for apps that do not have access to browser search
if ((e.ctrlKey || e.altKey) && e.which == 70) {
document.getElementById('findText').click();
}
});
document.getElementById('articleContent').contentWindow.addEventListener('keydown', function (e) {
//Ctrl-P to patch printing support, so iframe gets printed
if (e.ctrlKey && e.which == 80) {
e.stopPropagation();
e.preventDefault();
printIntercept();
}
}, true);
}
/**
* Search the index for DirEntries with title that start with the given prefix (implemented
@ -2259,8 +2278,9 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
//Load lastPageVisit if it is the currently requested page
if (!htmlContent) {
if (params.rememberLastPage && typeof Storage !== "undefined" &&
dirEntry.namespace + '/' + dirEntry.url == decodeURIComponent(params.lastPageVisit.replace(/@kiwixKey@.+/, ""))) {
var lastPage = '';
if (params.rememberLastPage && params.lastPageVisit) lastPage = decodeURIComponent(params.lastPageVisit.replace(/@kiwixKey@.+/, ""));
if (params.rememberLastPage && typeof Storage !== "undefined" && dirEntry.namespace + '/' + dirEntry.url == lastPage) {
if (!params.lastPageHTML) {
try {
params.lastPageHTML = localStorage.getItem('lastPageHTML');
@ -2272,6 +2292,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
}
if (/<html[^>]*>/.test(htmlContent)) {
console.log("Fast article retrieval from localStorage...");
//if (~lastPage.indexOf(params.cachedStartPage)) params.isLandingPage = true;
setTimeout(function () {
displayArticleInForm(dirEntry, htmlContent);
});
@ -2305,6 +2326,8 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
// The content is ready : we can hide the spinner
setTab();
setupTableOfContents();
listenForSearchKeys();
//checkToolbar();
}
if (/manual|progressive/.test(params.imageDisplayMode)) images.prepareImagesServiceWorker();
@ -2662,6 +2685,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
//Preload stylesheets [kiwix-js #149]
//Set up blobArray of promises
var prefix = document.location.href.replace(/index\.html(?:$|[#?].*$)/, '');
var cssArray = htmlArticle.match(regexpSheetHref);
var blobArray = [];
var cssSource = params.cssSource;
@ -2675,10 +2699,10 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
//Extract CSS URLs from given array of links
function getBLOB(arr) {
var prefix = document.location.href.replace(/index\.html(?:$|[#?].*$)/, '');
var testCSS = arr.join();
zimType = /-\/s\/style\.css/i.test(testCSS) ? "desktop" : zimType;
zimType = /-\/static\/main\.css/i.test(testCSS) ? "desktop-stx" : zimType; //Support stackexchange
zimType = /gutenberg\.css/i.test(testCSS) ? "desktop-gtb" : zimType; //Support Gutenberg
zimType = /minerva|mobile/i.test(testCSS) ? "mobile" : zimType;
cssSource = cssSource == "auto" ? zimType : cssSource; //Default to in-built zimType if user has selected automatic detection of styles
if (/minerva|inserted.style.mobile/i.test(testCSS) && (cssCache || zimType != cssSource)) {
@ -2740,7 +2764,6 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
}
function injectCSS() {
var prefix = document.location.href.replace(/index\.html(?:$|[#?].*$)/, '');
// We have to count the blobArray elements because some may have been spliced out
// See https://stackoverflow.com/questions/28811911/find-array-length-in-javascript
var blobArrayLength = blobArray.filter(function () { return true; }).length;
@ -2757,7 +2780,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
break;
}
}
testBlob = match && /blob:/i.test(blobArray[j][1]) ? blobArray[j][1] : prefix + blobArray[i]; //Whoa!!! Steady on!
testBlob = match && /blob:/i.test(blobArray[j][1]) ? blobArray[j][1] : blobArray[i]; //Whoa!!! Steady on!
resultsArray[i] = cssArray[i].replace(/(?:data-kiwixurl|href)\s*=\s*["']([^"']+)/i, 'href="' +
testBlob + '" data-kiwixhref="$1'); //Store the original URL for later use
//DEV note: do not attempt to add onload="URL.revokeObjectURL...)": see [kiwix.js #284]
@ -2952,23 +2975,8 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
}
checkToolbar();
//Listen to iframe key presses for in-page search
document.getElementById('articleContent').contentWindow.addEventListener('keyup', function (e) {
//Alt-F for search in article, also patches Ctrl-F for apps that do not have access to browser search
if ((e.ctrlKey || e.altKey) && e.which == 70) {
document.getElementById('findText').click();
}
});
document.getElementById('articleContent').contentWindow.addEventListener('keydown', function (e) {
//Ctrl-P to patch printing support, so iframe gets printed
if (e.ctrlKey && e.which == 80) {
e.stopPropagation();
e.preventDefault();
printIntercept();
}
}, true);
listenForSearchKeys();
var currentProtocol = location.protocol;
var currentHost = location.host;
// Percent-encode dirEntry.url and add regex escape character \ to the RegExp special characters - see https://www.regular-expressions.info/characters.html;

View File

@ -32,10 +32,10 @@ var state = {};
// Parameters that define overall operation of app
var params = {};
params['version'] = "0.9.9.92 Beta-dev"; //DEV: do not set this dynamically -- it is compared to the cookie "version" in order to show first-time info, and the cookie is updated in app.js
params['packagedFile'] = false; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename (for split files, give the first chunk *.zimaa) and place file(s) in default storage
params['archivePath'] = false; //The directory containing the packaged archive(s) (relative to app's root directory)
params['fileVersion'] = false; //Use generic name for actual file, and give version here
params['cachedStartPage'] = false; //If you have cached the start page for quick start, give its URI here
params['packagedFile'] = "wikipedia_en_100.zim"; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename (for split files, give the first chunk *.zimaa) and place file(s) in default storage
params['archivePath'] = "archives"; //The directory containing the packaged archive(s) (relative to app's root directory)
params['fileVersion'] = "wikipedia_en_100_2019-01 (Jan-2019)"; //Use generic name for actual file, and give version here
params['cachedStartPage'] = "index.htm"; //If you have cached the start page for quick start, give its URI here
params['kiwixDownloadLink'] = "https://download.kiwix.org/zim/"; //Include final slash
params['results'] = params['results'] || 50; //Number of search results to display

View File

@ -226,11 +226,12 @@ define(['util'], function(util) {
var alertHTML =
'<div id="activeContent" class="alert alert-warning alert-dismissible fade in">' +
'<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>' +
'<strong>Unable to display active content:</strong> To use Archive Index <b><i>type a space</b></i> in the box above. ' +
'&nbsp;[<a id="stop" href="#displaySettingsDiv" class="alert-link">Permanently hide</a>]' +
'<strong>Unable to display active content:</strong> To use Archive Index <b><i>type a space</b></i> in the box above, or else ' +
'<a id="swModeLink" href="#contentInjectionModeDiv" class="alert-link">switch to Service Worker mode</a> ' +
'if your platform supports it. &nbsp;[<a id="stop" href="#displaySettingsDiv" class="alert-link">Permanently hide</a>]' +
'</div>';
document.getElementById('alertBoxHeader').innerHTML = alertHTML;
['stop'].forEach(function (id) {
['swModeLink', 'stop'].forEach(function(id) {
// Define event listeners for both hyperlinks in alert box: these take the user to the Config tab and highlight
// the options that the user needs to select
document.getElementById(id).addEventListener('click', function () {