From 1cd958752cee7bb68c4cbc53607f7af89cc8f018 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Thu, 29 Aug 2019 11:11:44 +0100 Subject: [PATCH] Simplify article loading in SW mode #558 (#559) Closes #558. --- www/js/app.js | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index 31f39caf..77220837 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -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()) {