diff --git a/www/js/app.js b/www/js/app.js index a8eb25344..4ec502258 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1551,6 +1551,13 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys return true; } + // Import the Wombat script + // var Wombat; + // var wombatScript = document.createElement('script'); + // wombatScript.type = 'text/javascript'; + // wombatScript.src = document.location.href.replace(/[^/]+$/, '') + 'js/lib/wombat.js'; + // document.head.appendChild(wombatScript); + /** * Read the article corresponding to the given dirEntry * @param {DirEntry} dirEntry The directory entry of the article to read @@ -1579,15 +1586,23 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys document.getElementById('cachingAssets').textContent = 'Caching assets...'; document.getElementById('cachingAssets').style.display = 'none'; document.getElementById('searchingArticles').style.display = 'none'; + var doc = iframeArticleContent.contentDocument ? iframeArticleContent.contentDocument : null; + // Insert the Wombat script to rewrite dynamic URLs + // doc.head.appendChild(wombatScript); + // wombatScript.onload = function () { + // iframeArticleContent.contentWindow._WBWombatInit({}); + // } + // var innerHtml = iframeArticleContent.contentDocument.documentElement.innerHTML; + // innerHtml = Wombat.rewriteHtml(innerHtml); + // iframeArticleContent.contentDocument.documentElement.innerHTML = innerHtml; // Set the requested appTheme uiUtil.applyAppTheme(params.appTheme); // Display the iframe content document.getElementById('articleContent').style.display = ''; // Deflect drag-and-drop of ZIM file on the iframe to Config if (!params.disableDragAndDrop) { - var doc = iframeArticleContent.contentDocument ? iframeArticleContent.contentDocument.documentElement : null; - var docBody = doc ? doc.getElementsByTagName('body') : null; - docBody = docBody ? docBody[0] : null; + // var doc = iframeArticleContent.contentDocument ? iframeArticleContent.contentDocument.documentElement : null; + var docBody = doc ? doc.body : null; if (docBody) { docBody.addEventListener('dragover', handleIframeDragover); docBody.addEventListener('drop', handleIframeDrop); @@ -1633,12 +1648,20 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys } }; - if(! isDirEntryExpectedToBeDisplayed(dirEntry)){ + if (!isDirEntryExpectedToBeDisplayed(dirEntry)) { return; } - + // Add the correct prefixes so that the wabac Service Worker can recognize and transform the iframe document when loaded + var zimitPrefix = ''; + if (selectedArchive._file.zimType === 'zimit' && /[CA]/.test(dirEntry.namespace)) { + zimitPrefix = 'mp_/'; + encodedUrl = 'https://' + encodeURI(dirEntry.url); + } // 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.name + '/' + dirEntry.namespace + '/' + encodedUrl; + iframeArticleContent.src = "../" + selectedArchive._file.name + "/" + dirEntry.namespace + "/" + zimitPrefix + encodedUrl; + // Wombat = new window._WBWombat(iframeArticleContent.contentWindow, {}); + // Wombat.initIframeWombat(iframeArticleContent); + } else { // In jQuery mode, we read the article content in the backend and manually insert it in the iframe if (dirEntry.isRedirect()) {