Provide treePath instead (simpler)

Former-commit-id: 633cb3951a69a15a03dcd6aef8c7a5693c6d2d2a [formerly df971366868f296201727f825b63466e31e7ad3b]
Former-commit-id: ac8471635bc8c7a68a15e4ede13787a328c3c9e5
This commit is contained in:
Jaifroid 2019-04-02 12:00:25 +01:00
parent 5973153c14
commit 7f00c31d02

View File

@ -344,12 +344,14 @@ define(['util'], function(util) {
function insertBreakoutLink() { function insertBreakoutLink() {
var desc = "Open article in new tab or window"; var desc = "Open article in new tab or window";
var iframe = document.getElementById('articleContent').contentDocument; var iframe = document.getElementById('articleContent').contentDocument;
// Remove the file and any query string from href // 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'); // var prefix = window.location.href.replace(/^((?!.*\?).*\/|.*\/(?=[^\/]*\?)).*$/, '$1');
// But in Kiwix JS Windows, we can easily get the relative path of the current document:
var treePath = decodeURIComponent(params.lastPageVisit).replace(/[^/]+\/(?:[^/]+$)?/g, "../");
var div = document.createElement('div'); var div = document.createElement('div');
div.style.cssText = 'top: 10px; right: 25px; position: relative; z-index: 2; float: right;'; div.style.cssText = 'top: 10px; right: 25px; position: relative; z-index: 2; float: right;';
div.id = "openInTab"; div.id = "openInTab";
div.innerHTML = '<a href="#"><img src="' + prefix + 'img/icons/new_window.svg" width="30" height="30" alt="' div.innerHTML = '<a href="#"><img src="' + treePath + 'img/icons/new_window.svg" width="30" height="30" alt="'
+ desc + '" title="' + desc + '"></a>'; + desc + '" title="' + desc + '"></a>';
iframe.body.insertBefore(div, iframe.body.firstChild); iframe.body.insertBefore(div, iframe.body.firstChild);
var openInTab = iframe.getElementById('openInTab'); var openInTab = iframe.getElementById('openInTab');