diff --git a/www/js/app.js b/www/js/app.js
index f4927ebb..58745582 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -145,7 +145,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
// This is touch equivalent of Esc above
document.getElementById('prefix').addEventListener('blur', function (e) {
document.getElementById('articleContent').style.position = "fixed";
- }, true);
+ });
//Add keyboard shortcuts
window.addEventListener('keyup', function (e) {
@@ -1697,7 +1697,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
'
' + newHtml + '\n
\n' +
'\n' + backNext + '
' + alphaString + '
\n';
var indexEntries = docBody.querySelectorAll('.list-group-item');
- $(indexEntries).on("click", function (event) {
+ $(indexEntries).on('click', function (event) {
$("#myModal").modal('hide');
handleTitleClick(event);
return false;
@@ -1769,7 +1769,11 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
//});
// Needed so that results show on top of article
document.getElementById('articleContent').style.position = 'static';
- $("#articleList a").on("click", handleTitleClick);
+ // We have to use mousedown instead of click as otherwise the blur event fires first and prevents this event from firing
+ $('#articleList a').on('mousedown', function (e) {
+ handleTitleClick(e);
+ return false;
+ });
$('#searchingArticles').hide();
$('#articleList').show();
$('#articleListWithHeader').show();
@@ -1802,6 +1806,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
if (dirEntry.isRedirect()) {
selectedArchive.resolveRedirect(dirEntry, readArticle);
} else {
+ params.isLandingPage = false;
readArticle(dirEntry);
}
} else {
@@ -2049,7 +2054,11 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
// return "";
//});
// Neutralize all inline scripts for now (later use above), excluding math blocks or react templates
- htmlArticle = htmlArticle.replace(/<(script\b(?![^>]+type\s*=\s*["'](?:math\/|text\/html|[^"']*?math))(?:[^<]|<(?!\/script>))+<\/script)>/ig, "");
+ var containsActiveContent = false;
+ htmlArticle = htmlArticle.replace(/<(script\b(?![^>]+type\s*=\s*["'](?:math\/|text\/html|[^"']*?math))(?:[^<]|<(?!\/script>))+<\/script)>/ig, function (p0, p1) {
+ containsActiveContent = true;
+ return '';
+ });
//Neutralize onload events, as they cause a crash in ZIMs with proprietary UIs
htmlArticle = htmlArticle.replace(/(<[^>]+?)onload\s*=\s*["'][^"']+["']\s*/ig, '$1');
//Neutralize onclick events
@@ -2057,6 +2066,18 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
//Neutralize href="javascript:" links
htmlArticle = htmlArticle.replace(/href\s*=\s*["']javascript:[^"']+["']/gi, 'href=""');
+ // Display an information box if the landing page contains active content
+ if (params.isLandingPage && containsActiveContent) {
+ var alertHTML = '' +
+ '
×' +
+ '
Unable to display active content: To show Content Index, type a space in the box above or click here.' +
+ '
';
+ document.getElementById('alertBoxDiv').innerHTML = alertHTML;
+ document.getElementById('titleIndexLink').addEventListener('click', function () {
+ showZIMIndex(0);
+ });
+ }
+
//MathJax detection:
containsMathTeXRaw = params.useMathJax && !/wikivoyage/.test(params.storedFile) ? /\$\$?((?:[^$<>]|<\s|\s>)+)\$\$?([\s<.,;:?!'")\]])/.test(htmlArticle) : false;
//Simplify any configuration script
@@ -2448,7 +2469,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
//loadJavascript(); //Disabled for now, since it does nothing - also, would have to load before images, ideally through controlled css loads above
insertMediaBlobsJQuery();
- //Document has loaded except for images, so we can now change the startup cookie (and delete) [see init.js]
+ // Document has loaded except for images, so we can now change the startup cookie (and delete) [see init.js]
document.cookie = 'lastPageLoad=success;expires=Thu, 21 Sep 1979 00:00:01 UTC';
}
@@ -3006,6 +3027,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
console.error("Article with title " + title + " not found in the archive");
goToMainArticle();
} else {
+ params.isLandingPage = false;
readArticle(dirEntry);
}
}).fail(function () {
@@ -3025,6 +3047,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
} else {
//Test below supports Stackexchange-family ZIMs, so we don't call up user profiles
if (dirEntry.namespace === 'A' && !/user\//.test(dirEntry.url)) {
+ params.isLandingPage = false;
readArticle(dirEntry);
} else {
// If the random title search did not end up on an article,
@@ -3044,6 +3067,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
$("#welcomeText").show();
} else {
if (dirEntry.namespace === 'A') {
+ params.isLandingPage = true;
readArticle(dirEntry);
} else {
console.error("The main page of this archive does not seem to be an article");
diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js
index b437c137..e498180f 100644
--- a/www/js/lib/zimArchive.js
+++ b/www/js/lib/zimArchive.js
@@ -183,6 +183,7 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
// produces a list of matches starting with first match and then next x dirEntries thereafter
var saveStartIndex = startIndex;
startIndex = startIndex || 0;
+ prefix = prefix || '';
var that = this;
// Vector is used to remember the search direction if we encounter a dirEntry with an empty title
var vector = -1;