Skip to content

Commit

Permalink
Attempts to get wombat working (failed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaifroid committed Jun 16, 2023
1 parent d349d10 commit c9a80ca
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit c9a80ca

Please sign in to comment.