mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 20:29:58 +02:00
Refactor ZenCompactMode to fix flashSidebar timeout bug
This commit is contained in:
parent
b84a9418c2
commit
80a8904bbc
1 changed files with 13 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
||||||
var gZenCompactModeManager = {
|
var gZenCompactModeManager = {
|
||||||
_flashSidebarTimeout: null,
|
_flashSidebarTimeout: {},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
Services.prefs.addObserver('zen.view.compact', this._updateEvent.bind(this));
|
Services.prefs.addObserver('zen.view.compact', this._updateEvent.bind(this));
|
||||||
|
@ -58,31 +58,35 @@ var gZenCompactModeManager = {
|
||||||
|
|
||||||
get hoverableElements() {
|
get hoverableElements() {
|
||||||
return [
|
return [
|
||||||
this.sidebar,
|
|
||||||
document.getElementById('zen-appcontent-navbar-container'),
|
document.getElementById('zen-appcontent-navbar-container'),
|
||||||
|
this.sidebar,
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
flashSidebar(element = null, duration = null) {
|
flashSidebar(element = null, duration = null, id = null) {
|
||||||
if (!element) {
|
if (!element) {
|
||||||
element = this.sidebar;
|
element = this.sidebar;
|
||||||
}
|
}
|
||||||
if (!duration) {
|
if (!duration) {
|
||||||
duration = this.flashSidebarDuration;
|
duration = this.flashSidebarDuration;
|
||||||
}
|
}
|
||||||
|
if (!id) {
|
||||||
|
id = this.sidebar.id;
|
||||||
|
}
|
||||||
let tabPanels = document.getElementById('tabbrowser-tabpanels');
|
let tabPanels = document.getElementById('tabbrowser-tabpanels');
|
||||||
if (element.matches(':hover') || tabPanels.matches("[zen-split-view='true']")) {
|
if (element.matches(':hover') || tabPanels.matches("[zen-split-view='true']")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this._flashSidebarTimeout) {
|
if (this._flashSidebarTimeout[id]) {
|
||||||
clearTimeout(this._flashSidebarTimeout);
|
clearTimeout(this._flashSidebarTimeout[id]);
|
||||||
} else {
|
} else {
|
||||||
window.requestAnimationFrame(() => element.setAttribute('flash-popup', ''));
|
window.requestAnimationFrame(() => element.setAttribute('flash-popup', ''));
|
||||||
}
|
}
|
||||||
this._flashSidebarTimeout = setTimeout(() => {
|
this._flashSidebarTimeout[id] = setTimeout(() => {
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
element.removeAttribute('flash-popup');
|
element.removeAttribute('flash-popup');
|
||||||
this._flashSidebarTimeout = null;
|
element.removeAttribute('zen-has-hover');
|
||||||
|
this._flashSidebarTimeout[id] = null;
|
||||||
});
|
});
|
||||||
}, duration);
|
}, duration);
|
||||||
},
|
},
|
||||||
|
@ -91,12 +95,12 @@ var gZenCompactModeManager = {
|
||||||
for (let i = 0; i < this.hoverableElements.length; i++) {
|
for (let i = 0; i < this.hoverableElements.length; i++) {
|
||||||
this.hoverableElements[i].addEventListener('mouseenter', (event) => {
|
this.hoverableElements[i].addEventListener('mouseenter', (event) => {
|
||||||
let target = this.hoverableElements[i];
|
let target = this.hoverableElements[i];
|
||||||
target.setAttribute('zen-user-hover', 'true');
|
target.setAttribute('zen-has-hover', 'true', target.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.hoverableElements[i].addEventListener('mouseleave', (event) => {
|
this.hoverableElements[i].addEventListener('mouseleave', (event) => {
|
||||||
let target = this.hoverableElements[i];
|
let target = this.hoverableElements[i];
|
||||||
this.flashSidebar(target, this.hideAfterHoverDuration);
|
this.flashSidebar(target, this.hideAfterHoverDuration, target.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue