Better algo to select target window for article

Fexes #639
This commit is contained in:
Jaifroid 2024-08-14 07:28:11 +01:00
parent a551275f20
commit d8d5507d57

View File

@ -4952,9 +4952,9 @@ function readArticle (dirEntry) {
// Only update for expectedArticleURLToBeDisplayed. // Only update for expectedArticleURLToBeDisplayed.
appstate.expectedArticleURLToBeDisplayed = dirEntry.namespace + '/' + dirEntry.url; appstate.expectedArticleURLToBeDisplayed = dirEntry.namespace + '/' + dirEntry.url;
params.pagesLoaded++; params.pagesLoaded++;
// Select the correct target window for the article, defaulting to the iframe
articleContainer = appstate.target === 'window' ? articleWindow : iframe;
// We must remove focus from UI elements in order to deselect whichever one was clicked (in both Restricted and SW modes), // We must remove focus from UI elements in order to deselect whichever one was clicked (in both Restricted and SW modes),
// articleContainer = articleContainer || articleWindow;
articleContainer = (articleWindow.self !== articleWindow.top) ? iframe : articleWindow;
if (!params.isLandingPage && articleContainer.contentWindow) articleContainer.contentWindow.focus(); if (!params.isLandingPage && articleContainer.contentWindow) articleContainer.contentWindow.focus();
uiUtil.pollSpinner() uiUtil.pollSpinner()
// Show the spinner with a loading message // Show the spinner with a loading message
@ -5242,14 +5242,15 @@ function filterClickEvent (event) {
} }
// Remove any Kiwix Popovers that may be hanging around // Remove any Kiwix Popovers that may be hanging around
popovers.removeKiwixPopoverDivs(event.target.ownerDocument); popovers.removeKiwixPopoverDivs(event.target.ownerDocument);
if (params.contentInjectionMode === 'jquery') return;
// Trap clicks in the iframe to restore Fullscreen mode // Trap clicks in the iframe to restore Fullscreen mode
if (params.lockDisplayOrientation) refreshFullScreen(event); if (params.lockDisplayOrientation) refreshFullScreen(event);
if (clickedAnchor) { if (clickedAnchor) {
// Get the window of the clicked anchor // Get the window of the clicked anchor
articleWindow = clickedAnchor.ownerDocument.defaultView; articleWindow = clickedAnchor.ownerDocument.defaultView;
// Determine if the window is in an iframe // Select the correct target window for the article, defaulting to the iframe
articleContainer = (articleWindow.self !== articleWindow.top) ? iframe : articleWindow; articleContainer = articleWindow.self === articleWindow.top ? articleWindow : iframe;
appstate.target = articleContainer === articleWindow ? 'window' : 'iframe';
if (params.contentInjectionMode === 'jquery') return;
// This prevents any popover from being displayed when the user clicks on a link // This prevents any popover from being displayed when the user clicks on a link
clickedAnchor.articleisloading = true; clickedAnchor.articleisloading = true;
// Check for Zimit links that would normally be handled by the Replay Worker // Check for Zimit links that would normally be handled by the Replay Worker
@ -5311,6 +5312,7 @@ var unhideArticleContainer = function () {
iframe.style.height = 'auto'; iframe.style.height = 'auto';
resizeIFrame(); resizeIFrame();
// Scroll down and up to kickstart lazy loading which might not happen if brower has been slow to display the content // Scroll down and up to kickstart lazy loading which might not happen if brower has been slow to display the content
if (!(/zimit/.test(params.zimType) || appstate.pureMode)) {
articleWindow.scrollBy(0, 5); articleWindow.scrollBy(0, 5);
setTimeout(function () { setTimeout(function () {
articleWindow.scrollBy(0, -5); articleWindow.scrollBy(0, -5);
@ -5319,6 +5321,7 @@ var unhideArticleContainer = function () {
} }
} }
} }
}
// The main article loader for Service Worker mode // The main article loader for Service Worker mode
var articleLoadedSW = function (dirEntry, container) { var articleLoadedSW = function (dirEntry, container) {