Merge pull request #940 from kiwix/fix_for_issue912

PDF-friendly book home button in the viewer
This commit is contained in:
Kelson 2023-06-08 15:48:11 +02:00 committed by GitHub
commit 144945cfe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View File

@ -204,14 +204,30 @@ function handle_visual_viewport_change() {
contentIframe.height = wh - contentIframe.offsetTop - 4; contentIframe.height = wh - contentIframe.offsetTop - 4;
} }
function setIframeUrl(path) {
try {
// Don't do anything if we are already at the requested URL.
// This is needed to break the infinite ping-pong played by
// handle_location_hash_change() and handle_content_url_change()
// (when either top-window or content window/iframe URL changes the other
// one is updated too).
if ( path == contentIframe.contentWindow.location.pathname )
return;
} catch ( error ) {
// This happens in Firefox when a PDF file is displayed in the iframe
// (sandboxing of the iframe content and cross-origin mismatch with the
// builtin PDF viewer result in preventing access to the attributes of
// contentIframe.contentWindow.location).
// Fall through and load the requested URL.
}
contentIframe.contentWindow.location.replace(path);
}
function handle_location_hash_change() { function handle_location_hash_change() {
const hash = window.location.hash.slice(1); const hash = window.location.hash.slice(1);
console.log("handle_location_hash_change: " + hash); console.log("handle_location_hash_change: " + hash);
updateCurrentBookIfNeeded(hash); updateCurrentBookIfNeeded(hash);
const iframeContentUrl = userUrl2IframeUrl(hash); setIframeUrl(userUrl2IframeUrl(hash));
if ( iframeContentUrl != contentIframe.contentWindow.location.pathname ) {
contentIframe.contentWindow.location.replace(iframeContentUrl);
}
updateSearchBoxForLocationChange(); updateSearchBoxForLocationChange();
previousScrollTop = Infinity; previousScrollTop = Infinity;
history.replaceState(viewerState, null); history.replaceState(viewerState, null);

View File

@ -73,7 +73,7 @@ const ResourceCollection resources200Compressible{
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/taskbar.css" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/taskbar.css" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/taskbar.css?cacheid=bbdaf425" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/taskbar.css?cacheid=bbdaf425" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/viewer.js" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/viewer.js" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/viewer.js?cacheid=b9a574d4" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/viewer.js?cacheid=725c95a2" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/fonts/Poppins.ttf" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/fonts/Poppins.ttf" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/fonts/Poppins.ttf?cacheid=af705837" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/fonts/Poppins.ttf?cacheid=af705837" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/fonts/Roboto.ttf" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/fonts/Roboto.ttf" },
@ -312,7 +312,7 @@ R"EXPECTEDRESULT( <link type="text/css" href="./skin/taskbar.css?cacheid=bbda
<link type="text/css" href="./skin/css/autoComplete.css?cacheid=08951e06" rel="Stylesheet" /> <link type="text/css" href="./skin/css/autoComplete.css?cacheid=08951e06" rel="Stylesheet" />
<script type="module" src="./skin/i18n.js?cacheid=2cf0f8c5" defer></script> <script type="module" src="./skin/i18n.js?cacheid=2cf0f8c5" defer></script>
<script type="text/javascript" src="./skin/languages.js?cacheid=648526e1" defer></script> <script type="text/javascript" src="./skin/languages.js?cacheid=648526e1" defer></script>
<script type="text/javascript" src="./skin/viewer.js?cacheid=b9a574d4" defer></script> <script type="text/javascript" src="./skin/viewer.js?cacheid=725c95a2" defer></script>
<script type="text/javascript" src="./skin/autoComplete.min.js?cacheid=1191aaaf"></script> <script type="text/javascript" src="./skin/autoComplete.min.js?cacheid=1191aaaf"></script>
const blankPageUrl = root + "/skin/blank.html?cacheid=6b1fa032"; const blankPageUrl = root + "/skin/blank.html?cacheid=6b1fa032";
<img src="./skin/langSelector.svg?cacheid=00b59961"> <img src="./skin/langSelector.svg?cacheid=00b59961">