Refactor ZenGlanceChild.sys.mjs to use 'mantain' as the activation method instead of 'hover'

This commit is contained in:
mr. M 2024-10-29 09:51:35 +01:00
parent 8cfb95a3ac
commit 893eead718
No known key found for this signature in database
GPG key ID: CBD57A2AEDBDA1FB

View file

@ -38,7 +38,7 @@ export class ZenGlanceChild extends JSWindowActorChild {
async initiateGlance() { async initiateGlance() {
this.mouseIsDown = false; this.mouseIsDown = false;
const activationMethod = await this.getActivationMethod(); const activationMethod = await this.getActivationMethod();
if (activationMethod === 'hover') { if (activationMethod === 'mantain') {
this.contentWindow.addEventListener('mousedown', this.mouseDownListener); this.contentWindow.addEventListener('mousedown', this.mouseDownListener);
this.contentWindow.addEventListener('mouseup', this.mouseUpListener); this.contentWindow.addEventListener('mouseup', this.mouseUpListener);
@ -67,18 +67,26 @@ export class ZenGlanceChild extends JSWindowActorChild {
} }
handleMouseUp(event) { handleMouseUp(event) {
this.mouseIsDown = false; if (this.hasClicked) {
event.preventDefault();
event.stopPropagation();
this.hasClicked = false;
}
this.mouseIsDown = null;
} }
async handleMouseDown(event) { async handleMouseDown(event) {
if (event.target.tagName !== 'A') { const target = event.target.closest('A');
console.log('target', target);
if (!target) {
return; return;
} }
this.mouseIsDown = true; this.mouseIsDown = target;
const hoverActivationDelay = await this.getHoverActivationDelay(); const hoverActivationDelay = await this.getHoverActivationDelay();
setTimeout(() => { this.contentWindow.setTimeout(() => {
if (this.mouseIsDown) { if (this.mouseIsDown === target) {
this.openGlance(event.target); this.hasClicked = true;
this.openGlance(target);
} }
}, hoverActivationDelay); }, hoverActivationDelay);
} }
@ -94,7 +102,7 @@ export class ZenGlanceChild extends JSWindowActorChild {
return; return;
} else if (activationMethod === 'shift' && !event.shiftKey) { } else if (activationMethod === 'shift' && !event.shiftKey) {
return; return;
} else if (activationMethod === 'hover' || typeof activationMethod === 'undefined') { } else if (activationMethod === 'mantain' || typeof activationMethod === 'undefined') {
return; return;
} }
// get closest A element // get closest A element