mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 09:09:59 +02:00
Fix floating compact mode: revert logic in ZenCompactMode.mjs, use invisible padding.
This commit is contained in:
parent
f2921d75b4
commit
b0d8e8c484
1 changed files with 31 additions and 20 deletions
|
@ -178,19 +178,6 @@ var gZenCompactModeManager = {
|
||||||
this._flashTimeouts[id] = null;
|
this._flashTimeouts[id] = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
closeEntry(entry, target) {
|
|
||||||
if (entry.keepHoverDuration) {
|
|
||||||
this.flashElement(target, this.hideAfterHoverDuration, 'has-hover' + target.id, 'zen-has-hover');
|
|
||||||
} else {
|
|
||||||
this._removeHoverFrames[target.id] = window.requestAnimationFrame(() => target.removeAttribute('zen-has-hover'));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
shouldCloseFromEdge(expected, actual) {
|
|
||||||
return (expected === 'top' && actual === 'bottom') || (expected === 'bottom' && actual === 'top')
|
|
||||||
|| (expected === 'left' && actual === 'right') || (expected === 'right' && actual === 'left');
|
|
||||||
},
|
|
||||||
|
|
||||||
addMouseActions() {
|
addMouseActions() {
|
||||||
for (let i = 0; i < this.hoverableElements.length; i++) {
|
for (let i = 0; i < this.hoverableElements.length; i++) {
|
||||||
let target = this.hoverableElements[i].element;
|
let target = this.hoverableElements[i].element;
|
||||||
|
@ -198,19 +185,43 @@ var gZenCompactModeManager = {
|
||||||
this.clearFlashTimeout('has-hover' + target.id);
|
this.clearFlashTimeout('has-hover' + target.id);
|
||||||
window.requestAnimationFrame(() => target.setAttribute('zen-has-hover', 'true'));
|
window.requestAnimationFrame(() => target.setAttribute('zen-has-hover', 'true'));
|
||||||
});
|
});
|
||||||
|
|
||||||
target.addEventListener('mouseleave', (event) => {
|
target.addEventListener('mouseleave', (event) => {
|
||||||
const screenEdgeCrossed = this._getCrossedEdge(event.pageX, event.pageY, event.target);
|
if (this.hoverableElements[i].keepHoverDuration) {
|
||||||
if (!screenEdgeCrossed) return;
|
this.flashElement(target, keepHoverDuration, 'has-hover' + target.id, 'zen-has-hover');
|
||||||
for (let entry of this.hoverableElements) {
|
} else {
|
||||||
if (this.shouldCloseFromEdge(entry.screenEdge, screenEdgeCrossed)) {
|
this._removeHoverFrames[target.id] = window.requestAnimationFrame(() => target.removeAttribute('zen-has-hover'));
|
||||||
this.closeEntry(entry, entry.element);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.documentElement.addEventListener('mouseleave', (event) => {
|
||||||
|
const screenEdgeCrossed = this._getCrossedEdge(event.pageX, event.pageY);
|
||||||
|
if (!screenEdgeCrossed) return;
|
||||||
|
for (let entry of this.hoverableElements) {
|
||||||
|
if (screenEdgeCrossed !== entry.screenEdge) continue;
|
||||||
|
const target = entry.element;
|
||||||
|
const boundAxis = entry.screenEdge === 'right' || entry.screenEdge === 'left' ? 'y' : 'x';
|
||||||
|
if (!this._positionInBounds(boundAxis, target, event.pageX, event.pageY, 7)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
window.cancelAnimationFrame(this._removeHoverFrames[target.id]);
|
||||||
|
|
||||||
|
this.flashElement(target, this.hideAfterHoverDuration, 'has-hover' + target.id, 'zen-has-hover');
|
||||||
|
document.addEventListener(
|
||||||
|
'mousemove',
|
||||||
|
() => {
|
||||||
|
if (target.matches(':hover')) return;
|
||||||
|
target.removeAttribute('zen-has-hover');
|
||||||
|
this.clearFlashTimeout('has-hover' + target.id);
|
||||||
|
},
|
||||||
|
{ once: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_getCrossedEdge(posX, posY, element = document.documentElement, maxDistance = 5) {
|
_getCrossedEdge(posX, posY, element = document.documentElement, maxDistance = 10) {
|
||||||
const targetBox = element.getBoundingClientRect();
|
const targetBox = element.getBoundingClientRect();
|
||||||
posX = Math.max(targetBox.left, Math.min(posX, targetBox.right));
|
posX = Math.max(targetBox.left, Math.min(posX, targetBox.right));
|
||||||
posY = Math.max(targetBox.top, Math.min(posY, targetBox.bottom));
|
posY = Math.max(targetBox.top, Math.min(posY, targetBox.bottom));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue