From f2a20716f33b3bd4b95d87ae2f361dd64e3f0077 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Wed, 19 Jun 2019 08:59:28 +0100 Subject: [PATCH] Make breakoutlink work in SW mode Former-commit-id: 059500d9c47cec0054781516f24e49a6ab1fdc35 [formerly 4bf9c0f0f82afe0b1eec8b33fadb3a315fdcc521] Former-commit-id: ee9de0114ad006de1494397017279d19479048e0 --- www/js/app.js | 4 ++++ www/js/lib/uiUtil.js | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index 3c4a887f..00ad7b32 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -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 diff --git a/www/js/lib/uiUtil.js b/www/js/lib/uiUtil.js index db0b8d70..d71cd9c8 100644 --- a/www/js/lib/uiUtil.js +++ b/www/js/lib/uiUtil.js @@ -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 = '' + desc + ''; + div.innerHTML = '' + desc + ''; 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