Simplify article loading in SW mode #558 (#559)

Closes #558.
This commit is contained in:
Jaifroid 2019-08-29 11:11:44 +01:00 committed by GitHub
parent 7f9ddc5a07
commit 1cd958752c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -900,36 +900,31 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
var encodedUrl = dirEntry.url.replace(/[^/]+/g, function(matchedSubstring) {
return encodeURIComponent(matchedSubstring);
});
var iframeArticleContent = document.getElementById('articleContent');
iframeArticleContent.onload = function() {
// The iframe is empty, show spinner on load of landing page
$("#searchingArticles").show();
$("#articleList").empty();
$('#articleListHeaderMessage').empty();
$('#articleListWithHeader').hide();
$("#prefix").val("");
iframeArticleContent.onload = function() {
// The content is fully loaded by the browser : we can hide the spinner
$("#searchingArticles").hide();
// Deflect drag-and-drop of ZIM file on the iframe to Config
var doc = iframeArticleContent.contentDocument ? iframeArticleContent.contentDocument.documentElement : null;
var docBody = doc ? doc.getElementsByTagName('body') : null;
docBody = docBody ? docBody[0] : null;
if (docBody) {
docBody.addEventListener('dragover', handleIframeDragover);
docBody.addEventListener('drop', handleIframeDrop);
}
if (iframeArticleContent.contentWindow) iframeArticleContent.contentWindow.onunload = function() {
$("#searchingArticles").show();
};
};
// We put the ZIM filename as a prefix in the URL, so that browser caches are separate for each ZIM file
iframeArticleContent.src = "../" + selectedArchive._file._files[0].name + "/" + dirEntry.namespace + "/" + encodedUrl;
// The content is fully loaded by the browser : we can hide the spinner
$("#searchingArticles").hide();
// Display the iframe content
$("#articleContent").show();
// Deflect drag-and-drop of ZIM file on the iframe to Config
var doc = iframeArticleContent.contentDocument ? iframeArticleContent.contentDocument.documentElement : null;
var docBody = doc ? doc.getElementsByTagName('body') : null;
docBody = docBody ? docBody[0] : null;
if (docBody) {
docBody.addEventListener('dragover', handleIframeDragover);
docBody.addEventListener('drop', handleIframeDrop);
}
// Reset UI when the article is unloaded
if (iframeArticleContent.contentWindow) iframeArticleContent.contentWindow.onunload = function() {
$("#articleList").empty();
$('#articleListHeaderMessage').empty();
$('#articleListWithHeader').hide();
$("#prefix").val("");
$("#searchingArticles").show();
};
};
iframeArticleContent.src = "article.html";
// We put the ZIM filename as a prefix in the URL, so that browser caches are separate for each ZIM file
iframeArticleContent.src = "../" + selectedArchive._file._files[0].name + "/" + dirEntry.namespace + "/" + encodedUrl;
} else {
// In jQuery mode, we read the article content in the backend and manually insert it in the iframe
if (dirEntry.isRedirect()) {