mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 04:29:58 +02:00
Refactor ZenCompactMode to add compact view functionality
This commit is contained in:
parent
3c66cbdc24
commit
c80c22c1c2
1 changed files with 72 additions and 0 deletions
72
src/ZenCompactMode.mjs
Normal file
72
src/ZenCompactMode.mjs
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
var gZenCompactModeManager = {
|
||||||
|
_flashSidebarTimeout: null,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
Services.prefs.addObserver('zen.view.compact', this._updateEvent.bind(this));
|
||||||
|
Services.prefs.addObserver('zen.view.compact.toolbar-flash-popup.duration', this._updatedSidebarFlashDuration.bind(this));
|
||||||
|
|
||||||
|
gZenUIManager.addPopupTrackingAttribute(this.sidebar);
|
||||||
|
gZenUIManager.addPopupTrackingAttribute(document.getElementById('zen-appcontent-navbar-container'));
|
||||||
|
},
|
||||||
|
|
||||||
|
get prefefence() {
|
||||||
|
return Services.prefs.getBoolPref('zen.view.compact');
|
||||||
|
},
|
||||||
|
|
||||||
|
set preference(value) {
|
||||||
|
Services.prefs.setBoolPref('zen.view.compact', value);
|
||||||
|
},
|
||||||
|
|
||||||
|
get sidebar() {
|
||||||
|
if (!this._sidebar) {
|
||||||
|
this._sidebar= document.getElementById('navigator-toolbox');
|
||||||
|
}
|
||||||
|
return this._sidebar;
|
||||||
|
},
|
||||||
|
|
||||||
|
_updateEvent() {
|
||||||
|
Services.prefs.setBoolPref('zen.view.sidebar-expanded.on-hover', false);
|
||||||
|
},
|
||||||
|
|
||||||
|
toggle() {
|
||||||
|
this.preference = !this.prefefence;
|
||||||
|
},
|
||||||
|
|
||||||
|
_updatedSidebarFlashDuration() {
|
||||||
|
this._flashSidebarDuration = Services.prefs.getIntPref('zen.view.compact.toolbar-flash-popup.duration');
|
||||||
|
},
|
||||||
|
|
||||||
|
toggleSidebar() {
|
||||||
|
this.sidebar.toggleAttribute('zen-user-show');
|
||||||
|
},
|
||||||
|
|
||||||
|
get flashSidebarDuration() {
|
||||||
|
if (this._flashSidebarDuration) {
|
||||||
|
return this._flashSidebarDuration;
|
||||||
|
}
|
||||||
|
return Services.prefs.getIntPref('zen.view.compact.toolbar-flash-popup.duration');
|
||||||
|
},
|
||||||
|
|
||||||
|
flashSidebar() {
|
||||||
|
let tabPanels = document.getElementById('tabbrowser-tabpanels');
|
||||||
|
if (this.sidebar.matches(':hover') || tabPanels.matches("[zen-split-view='true']")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this._flashSidebarTimeout) {
|
||||||
|
clearTimeout(this._flashSidebarTimeout);
|
||||||
|
} else {
|
||||||
|
window.requestAnimationFrame(() => this.sidebar.setAttribute('flash-popup', ''));
|
||||||
|
}
|
||||||
|
this._flashSidebarTimeout = setTimeout(() => {
|
||||||
|
window.requestAnimationFrame(() => {
|
||||||
|
this.sidebar.removeAttribute('flash-popup');
|
||||||
|
this._flashSidebarTimeout = null;
|
||||||
|
});
|
||||||
|
}, this.flashSidebarDuration);
|
||||||
|
},
|
||||||
|
|
||||||
|
toggleToolbar() {
|
||||||
|
let toolbar = document.getElementById('zen-appcontent-navbar-container');
|
||||||
|
toolbar.toggleAttribute('zen-user-show');
|
||||||
|
},
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue