Make breakoutlink work in SW mode

Former-commit-id: 059500d9c47cec0054781516f24e49a6ab1fdc35 [formerly 4bf9c0f0f82afe0b1eec8b33fadb3a315fdcc521]
Former-commit-id: ee9de0114ad006de1494397017279d19479048e0
This commit is contained in:
Jaifroid 2019-06-19 08:59:28 +01:00
parent 34bf2182e8
commit f2a20716f3
2 changed files with 7 additions and 4 deletions

View File

@ -2138,6 +2138,10 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'images', 'cookies', 'q', 'trans
iframeArticleContent.contentWindow.onunload = function () {
$("#searchingArticles").show();
};
if (params.allowHTMLExtraction) {
var determinedTheme = params.cssTheme == 'auto' ? cssUIThemeGetOrSet('auto') : params.cssTheme;
uiUtil.insertBreakoutLink(determinedTheme);
}
};
iframeArticleContent.src = '../' + dirEntry.namespace + "/" + encodeURIComponent(dirEntry.url);
// Display the iframe content

View File

@ -357,13 +357,12 @@ define(['util'], function(util) {
function insertBreakoutLink(mode) {
var desc = "Open article in new tab or window";
var iframe = document.getElementById('articleContent').contentDocument;
// This code provides an absolute link - keep for reference. Removes the file and any query string from href
// var prefix = window.location.href.replace(/^((?!.*\?).*\/|.*\/(?=[^\/]*\?)).*$/, '$1');
// But in Kiwix JS Windows, we can easily get the relative path of the current document:
// This code provides an absolute link, removing the file and any query string from href (we need this because of SW mode)
var prefix = window.location.href.replace(/^((?!.*\?).*\/|.*\/(?=[^\/]*\?)).*$/, '$1');
var div = document.createElement('div');
div.style.cssText = 'top: 10px; right: 25px; position: relative; z-index: 2; float: right;';
div.id = "openInTab";
div.innerHTML = '<a href="#"><img id="breakoutLink" src="img/icons/' + (mode == 'light' ? 'new_window.svg' : 'new_window_lb.svg') + '" width="30" height="30" alt="' + desc + '" title="' + desc + '"></a>';
div.innerHTML = '<a href="#"><img id="breakoutLink" src="' + prefix + 'img/icons/' + (mode == 'light' ? 'new_window.svg' : 'new_window_lb.svg') + '" width="30" height="30" alt="' + desc + '" title="' + desc + '"></a>';
iframe.body.insertBefore(div, iframe.body.firstChild);
var openInTab = iframe.getElementById('openInTab');
// Have to use jQuery here becasue e.preventDefault is not working properly in some browsers