From 2da9801bac2ee843b58ac5cf07ee587e34ab7a76 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Tue, 10 Sep 2024 17:03:04 +0400 Subject: [PATCH] Fixed ctrl-clicking of links for Zimit2 ZIMs Zimit2 ZIMs employ Wombat for client-side rewriting of URLs. The latter interferes with our approach of handling in the viewer CTRL/SHIFT-clicks on links inside articles. This commit disables Wombat temporarily while changing the href attribute of the clicked link. --- static/skin/viewer.js | 9 ++++++++- test/server.cpp | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/static/skin/viewer.js b/static/skin/viewer.js index 4da7a895..baa620ef 100644 --- a/static/skin/viewer.js +++ b/static/skin/viewer.js @@ -335,6 +335,13 @@ function getRealHref(target) { return target_href; } +function setHrefAvoidingWombatRewriting(target, url) { + const old_no_rewrite = target._no_rewrite; + target._no_rewrite = true; + target.setAttribute("href", url); + target._no_rewrite = old_no_rewrite; +} + function onClickEvent(e) { const iframeDocument = contentIframe.contentDocument; const target = matchingAncestorElement(e.target, iframeDocument, "a"); @@ -351,7 +358,7 @@ function onClickEvent(e) { if ( e.ctrlKey || e.shiftKey ) { // The link will be loaded in a new tab/window - update the link // and let the browser handle the rest. - target.setAttribute("href", possiblyBlockedLink); + setHrefAvoidingWombatRewriting(target, possiblyBlockedLink); } else { // Load the external URL in the viewer window (rather than iframe) contentIframe.contentWindow.parent.location = possiblyBlockedLink; diff --git a/test/server.cpp b/test/server.cpp index 555ba3c1..3e0646f0 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -75,7 +75,7 @@ const ResourceCollection resources200Compressible{ { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/taskbar.css" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/taskbar.css?cacheid=80d56607" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/viewer.js" }, - { STATIC_CONTENT, "/ROOT%23%3F/skin/viewer.js?cacheid=215635fd" }, + { STATIC_CONTENT, "/ROOT%23%3F/skin/viewer.js?cacheid=aca897b0" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/fonts/Poppins.ttf" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/fonts/Poppins.ttf?cacheid=af705837" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/fonts/Roboto.ttf" }, @@ -324,7 +324,7 @@ R"EXPECTEDRESULT( - + const blankPageUrl = root + "/skin/blank.html?cacheid=6b1fa032";