mirror of
https://github.com/zen-browser/components.git
synced 2025-07-07 21:49: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;
|
||||
},
|
||||
|
||||
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() {
|
||||
for (let i = 0; i < this.hoverableElements.length; i++) {
|
||||
let target = this.hoverableElements[i].element;
|
||||
|
@ -198,19 +185,43 @@ var gZenCompactModeManager = {
|
|||
this.clearFlashTimeout('has-hover' + target.id);
|
||||
window.requestAnimationFrame(() => target.setAttribute('zen-has-hover', 'true'));
|
||||
});
|
||||
|
||||
target.addEventListener('mouseleave', (event) => {
|
||||
const screenEdgeCrossed = this._getCrossedEdge(event.pageX, event.pageY, event.target);
|
||||
if (!screenEdgeCrossed) return;
|
||||
for (let entry of this.hoverableElements) {
|
||||
if (this.shouldCloseFromEdge(entry.screenEdge, screenEdgeCrossed)) {
|
||||
this.closeEntry(entry, entry.element);
|
||||
}
|
||||
if (this.hoverableElements[i].keepHoverDuration) {
|
||||
this.flashElement(target, keepHoverDuration, 'has-hover' + target.id, 'zen-has-hover');
|
||||
} else {
|
||||
this._removeHoverFrames[target.id] = window.requestAnimationFrame(() => target.removeAttribute('zen-has-hover'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
posX = Math.max(targetBox.left, Math.min(posX, targetBox.right));
|
||||
posY = Math.max(targetBox.top, Math.min(posY, targetBox.bottom));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue