Skip to content

Commit

Permalink
Void the iframe in readArticle function #341 (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaifroid authored Mar 12, 2018
1 parent 8445238 commit 0faae34
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
1 change: 0 additions & 1 deletion www/dummyArticle.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<html>
<head>
<meta charset="utf-8">
<base href="A/">
<title>dummy Article</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ <h3>Expert settings</h3>
<div id="readingArticle" style="display: none;" class="container">
Reading article <span id="articleName"></span> from archive... Please wait <img src="img/spinner.gif" alt="Please wait..." />
</div>
<iframe id="articleContent" src="dummyArticle.html" class="articleIFrame">&nbsp;</iframe>
<iframe id="articleContent" class="articleIFrame"></iframe>
</article>
<footer>
<div id="navigationButtons" class="btn-toolbar">
Expand Down
20 changes: 11 additions & 9 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
selectedArchive.resolveRedirect(dirEntry, readArticle);
}
else {
//Void the iframe
document.getElementById("articleContent").src = "dummyArticle.html";
selectedArchive.readArticle(dirEntry, displayArticleInForm);
}
}
Expand Down Expand Up @@ -826,20 +828,20 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies','abstractFiles
// Fast-replace img src with data-kiwixsrc [kiwix-js #272]
htmlArticle = htmlArticle.replace(/(<img\s+[^>]*\b)src(\s*=)/ig, "$1data-kiwixsrc$2");
}

// Compute base URL
var urlPath = regexpPath.test(dirEntry.url) ? urlPath = dirEntry.url.match(regexpPath)[1] : "";
var baseUrl = dirEntry.namespace + "/" + urlPath;

//Inject base tag into html
htmlArticle = htmlArticle.replace(/(<head[^>]*>\s*)/i, '$1<base href="' + baseUrl + '" />\r\n');

// Display the article inside the web page.
$('#articleContent').contents().find('body').html(htmlArticle);
document.getElementById("articleContent").contentDocument.documentElement.innerHTML = htmlArticle;

// If the ServiceWorker is not useable, we need to fallback to parse the DOM
// to inject math images, and replace some links with javascript calls
if (contentInjectionMode === 'jquery') {

// Compute base URL
var urlPath = regexpPath.test(dirEntry.url) ? urlPath = dirEntry.url.match(regexpPath)[1] : "";
var baseUrl = dirEntry.namespace + "/" + urlPath;
// Create (or replace) the "base" tag with our base URL
$('#articleContent').contents().find('head').find("base").detach();
$('#articleContent').contents().find('head').append("<base href='" + baseUrl + "'>");

var currentProtocol = location.protocol;
var currentHost = location.host;

Expand Down

0 comments on commit 0faae34

Please sign in to comment.