Add filter to body click to prevent unwanted activations

Former-commit-id: abeb69dd2e954dd2fa2b17e76e08c3ed47661a93 [formerly f719c52ee55215dba6cddc4cdd2e8ff40c9e7331 [formerly c9ac4ed134e59f02fc5ab41efc878a8f3d15017f]]
Former-commit-id: 1186d801de710695d45c7744cdb7029cbda22ebc
Former-commit-id: 423bd9f6c8ba3a737e5b7f3f1375ddd58e55d5f8
This commit is contained in:
Jaifroid 2021-05-24 11:30:21 +01:00
parent 133f7ff30c
commit c1bc794281

View File

@ -1124,7 +1124,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
uiUtil.systemAlert('Enabling this option disables the more advanced tab/window opening option above');
params.windowOpener = false;
settingsStore.setItem('windowOpener', params.windowOpener, Infinity);
setWindowOpenerUI(true);
setWindowOpenerUI();
}
settingsStore.setItem('allowHTMLExtraction', params.allowHTMLExtraction, Infinity);
params.themeChanged = true;
@ -4056,20 +4056,31 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
appstate.target = kiwixTarget;
articleWindow = thisWindow;
articleContainer = thisContainer;
// This detects Ctrl-click, Command-click, the long-press event, and middle-click
if (a.newcontainer && params.windowOpener) {
// We open the new window immediately so that it is a direct result of user action (click)
// and we'll populate it later - this avoids most popup blockers
loadingContainer = true;
articleContainer = window.open('article.html', params.windowOpener === 'tab' ? '_blank' : a.title,
params.windowOpener === 'window' ? 'toolbar=0,location=0,menubar=0,width=800,height=600,resizable=1,scrollbars=1' : null);
appstate.target = 'window';
articleContainer.kiwixType = appstate.target;
articleWindow = articleContainer;
} else if (a.tagName === 'BODY') {
// We have registered a click on the document, but a new tab wasn't requested, so ignore
// and allow any propagated clicks on other elements to run
return;
if (params.windowOpener) {
if (a.tagName === 'BODY') {
// We have registered a click on the document
if (!a.newcontainer) return; // A new tab wasn't requested, so ignore
// If we're not clicking within the scope of an H1, H2, etc., ignore the click
var getClosestHeading = function (el) {
do {
if (/H\d/.test(el.tagName)) return el;
el = el.parentElement || el.parentNode;
} while (el !== null && el.nodeType === 1);
return null;
};
if (!getClosestHeading(e.target)) return;
}
// This processes Ctrl-click, Command-click, the long-press event, and middle-click
if (a.newcontainer) {
// We open the new window immediately so that it is a direct result of user action (click)
// and we'll populate it later - this avoids most popup blockers
loadingContainer = true;
articleContainer = window.open('article.html', params.windowOpener === 'tab' ? '_blank' : a.title,
params.windowOpener === 'window' ? 'toolbar=0,location=0,menubar=0,width=800,height=600,resizable=1,scrollbars=1' : null);
appstate.target = 'window';
articleContainer.kiwixType = appstate.target;
articleWindow = articleContainer;
}
}
e.preventDefault();
e.stopPropagation();