11diff --git a/browser/base/content/browser-sidebar.js b/browser/base/content/browser-sidebar.js
2- index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..4da170628abea6eb8b9d3a81385d0d68c4e46449 100644
2+ index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..a08db41af1a11c0c435a0b0ca1d3ecd0633dce23 100644
33--- a/browser/base/content/browser-sidebar.js
44+++ b/browser/base/content/browser-sidebar.js
5- @@ -6,6 +6,10 @@
5+ @@ -6,6 +6,9 @@
66 * SidebarUI controls showing and hiding the browser sidebar.
77 */
88 var SidebarUI = {
9- +
109+ /**
1110+ * @returns {Map<string, { title: string, url?: string, menuId: string, triggerButtonId?: string, iconurl: string, bottom?: string }>}
1211+ */
1312 get sidebars() {
1413 if (this._sidebars) {
1514 return this._sidebars;
16- @@ -19,6 +23 ,7 @@ var SidebarUI = {
15+ @@ -19,6 +22 ,7 @@ var SidebarUI = {
1716 get title() {
1817 return document.getElementById(elementId).getAttribute("label");
1918 },
2019+ bottom: false,
2120 ...rest,
2221 };
2322 }
24- @@ -30,6 +35 ,7 @@ var SidebarUI = {
23+ @@ -30,6 +34 ,7 @@ var SidebarUI = {
2524 elementId: "sidebar-switcher-bookmarks",
2625 url: "chrome://browser/content/places/bookmarksSidebar.xhtml",
2726 menuId: "menu_bookmarksSidebar",
2827+ iconurl: "chrome://global/skin/icons/bookmark-outline.svg",
2928 }),
3029 ],
3130 [
32- @@ -39,6 +45 ,7 @@ var SidebarUI = {
31+ @@ -39,6 +44 ,7 @@ var SidebarUI = {
3332 url: "chrome://browser/content/places/historySidebar.xhtml",
3433 menuId: "menu_historySidebar",
3534 triggerButtonId: "appMenuViewHistorySidebar",
3635+ iconurl: "chrome://browser/skin/history.svg",
3736 }),
3837 ],
3938 [
40- @@ -47,6 +54 ,7 @@ var SidebarUI = {
39+ @@ -47,6 +53 ,7 @@ var SidebarUI = {
4140 elementId: "sidebar-switcher-tabs",
4241 url: "chrome://browser/content/syncedtabs/sidebar.xhtml",
4342 menuId: "menu_tabsSidebar",
4443+ iconurl: "chrome://browser/skin/tab.svg",
4544 }),
4645 ],
4746 ]));
48- @@ -61,6 +69 ,8 @@ var SidebarUI = {
47+ @@ -61,6 +68 ,8 @@ var SidebarUI = {
4948 return (this._browser = document.getElementById("sidebar"));
5049 },
5150 POSITION_START_PREF: "sidebar.position_start",
@@ -54,7 +53,7 @@ index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..4da170628abea6eb8b9d3a81385d0d68
5453 DEFAULT_SIDEBAR_ID: "viewBookmarksSidebar",
5554
5655 // lastOpenedId is set in show() but unlike currentID it's not cleared out on hide
57- @@ -78,6 +88 ,8 @@ var SidebarUI = {
56+ @@ -78,6 +87 ,8 @@ var SidebarUI = {
5857 },
5958 _splitter: null,
6059 _icon: null,
@@ -63,7 +62,7 @@ index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..4da170628abea6eb8b9d3a81385d0d68
6362 _reversePositionButton: null,
6463 _switcherPanel: null,
6564 _switcherTarget: null,
66- @@ -109,11 +121,28 @@ var SidebarUI = {
65+ @@ -109,11 +120,38 @@ var SidebarUI = {
6766 this._switcherPanel = document.getElementById("sidebarMenu-popup");
6867 this._switcherTarget = document.getElementById("sidebar-switcher-target");
6968 this._switcherArrow = document.getElementById("sidebar-switcher-arrow");
@@ -75,24 +74,34 @@ index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..4da170628abea6eb8b9d3a81385d0d68
7574 });
7675
7776+ const sidebaritems = this.sidebars.keys();
78- + const sidebarExtensionVis = Services.prefs.getBoolPref(this.SIDEBAR_EXTENSIONS_PREF, false);
77+ + const sidebarExtensionVis = Services.prefs.getBoolPref(
78+ + this.SIDEBAR_EXTENSIONS_PREF,
79+ + false
80+ + );
7981+ for (const sidebaritem of sidebaritems) {
80- + if(this.sidebars.get(sidebaritem).extensionId && !sidebarExtensionVis) {
82+ + if (this.sidebars.get(sidebaritem).extensionId && !sidebarExtensionVis) {
8183+ return;
8284+ }
83- + this.createSidebarItem(sidebaritem, this.sidebars.get(sidebaritem).iconurl, this.sidebars.get(sidebaritem));
85+ + this.createSidebarItem(
86+ + sidebaritem,
87+ + this.sidebars.get(sidebaritem).iconurl,
88+ + this.sidebars.get(sidebaritem)
89+ + );
8490+ }
8591+
86- + const sidebarVisible = Services.prefs.getBoolPref(this.SIDEBAR_TABS_PREF, true)
87- + this.setSidebarVisibility(sidebarVisible)
92+ + const sidebarVisible = Services.prefs.getBoolPref(
93+ + this.SIDEBAR_TABS_PREF,
94+ + true
95+ + );
96+ + this.setSidebarVisibility(sidebarVisible);
8897+
8998+ // Keep track on the changes of the sidebar visibility
9099+ Services.prefs.addObserver(this.SIDEBAR_TABS_PREF, this);
91100+
92101 this._inited = true;
93102
94103 Services.obs.addObserver(this, "intl:app-locales-changed");
95- @@ -121,6 +150 ,20 @@ var SidebarUI = {
104+ @@ -121,6 +159 ,20 @@ var SidebarUI = {
96105 this._initDeferred.resolve();
97106 },
98107
@@ -101,28 +110,44 @@ index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..4da170628abea6eb8b9d3a81385d0d68
101110+ * @param {boolean} visible Sets the sidebar to be visible or not visible
102111+ */
103112+ setSidebarVisibility(visible) {
104- + const sidebarContainer = document.getElementById(' sidebar-container')
113+ + const sidebarContainer = document.getElementById(" sidebar-container");
105114+
106115+ if (visible) {
107- + sidebarContainer.style.display = ' flex'
116+ + sidebarContainer.style.display = " flex";
108117+ } else {
109- + sidebarContainer.style.display = ' none'
118+ + sidebarContainer.style.display = " none";
110119+ }
111120+ },
112121+
113122 uninit() {
114123 // If this is the last browser window, persist various values that should be
115124 // remembered for after a restart / reopening a browser window.
116- @@ -171,6 +214,55 @@ var SidebarUI = {
125+ @@ -159,9 +211,9 @@ var SidebarUI = {
126+ /**
127+ * The handler for Services.obs.addObserver.
128+ **/
129+ - observe(_subject, topic, _data) {
130+ + observe(_subject, topic, data) {
131+ switch (topic) {
132+ - case "intl:app-locales-changed": {
133+ + case "intl:app-locales-changed":
134+ if (this.isOpen) {
135+ // The <tree> component used in history and bookmarks, but it does not
136+ // support live switching the app locale. Reload the entire sidebar to
137+ @@ -170,7 +222,58 @@ var SidebarUI = {
138+ this._show(this.lastOpenedId);
117139 break;
118140 }
119- }
141+ - }
142+ + break;
120143+
121144+ case "nsPref:changed":
122- + switch (aData ) {
145+ + switch (data ) {
123146+ case this.SIDEBAR_TABS_PREF:
124- + this.setSidebarVisibility(Services.prefs.getBoolPref(this.SIDEBAR_TABS_PREF, true))
125- + break
147+ + this.setSidebarVisibility(
148+ + Services.prefs.getBoolPref(this.SIDEBAR_TABS_PREF, true)
149+ + );
150+ + break;
126151+ }
127152+ break;
128153+ }
@@ -134,21 +159,21 @@ index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..4da170628abea6eb8b9d3a81385d0d68
134159+ return;
135160+ }
136161+
137- + const background = document.createElement("div")
138- + background.classList.add("sidebar-item-background")
162+ + const background = document.createElement("div");
163+ + background.classList.add("sidebar-item-background");
139164+ background.setAttribute("id", `sidebar-background-${id}`);
140165+ background.onclick = () => {
141- + this.toggle(id)
142- + }
143- +
166+ + this.toggle(id);
167+ + };
168+ +
144169+ const iconEl = document.createElement("image");
145170+ iconEl.setAttribute("id", `sidebar-icon-${id}`);
146171+ iconEl.setAttribute("src", `${icon}`);
147172+ iconEl.style.backgroundImage = `url(${icon})`;
148- +
149- + background.append(iconEl)
150173+
151- + if(config.bottom){
174+ + background.append(iconEl);
175+ +
176+ + if (config.bottom) {
152177+ this._sidebarBottomIcons.appendChild(background);
153178+ return;
154179+ }
@@ -159,28 +184,28 @@ index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..4da170628abea6eb8b9d3a81385d0d68
159184+ },
160185+
161186+ deleteSidebarItem(id) {
162- + const background = document.getElementById(`sidebar-background-${id}`)
163- + const icon = document.getElementById(`sidebar-icon-${id}`)
164- + if(background){
165- + background.remove()
187+ + const background = document.getElementById(`sidebar-background-${id}`);
188+ + const icon = document.getElementById(`sidebar-icon-${id}`);
189+ + if (background) {
190+ + background.remove();
166191+ }
167- + if(icon){
168- + icon.remove()
192+ + if (icon) {
193+ + icon.remove();
169194 }
170195 },
171196
172- @@ -521,6 +613 ,10 @@ var SidebarUI = {
197+ @@ -521,6 +624 ,10 @@ var SidebarUI = {
173198 return this._show(commandID).then(() => {
174199 this._loadSidebarExtension(commandID);
175200
176- + // Pulse: Reset sidebar margin to zero to allow for correct animations to
201+ + // Pulse: Reset sidebar margin to zero to allow for correct animations to
177202+ // take place (adapted from dot browser, se below)
178- + this._box.style.marginLeft = ' 0px'
203+ + this._box.style.marginLeft = " 0px";
179204+
180205 if (triggerNode) {
181206 updateToggleControlLabel(triggerNode);
182207 }
183- @@ -618,6 +714,24 @@ var SidebarUI = {
208+ @@ -618,6 +725,26 @@ var SidebarUI = {
184209
185210 this.selectMenuItem("");
186211
@@ -190,22 +215,24 @@ index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..4da170628abea6eb8b9d3a81385d0d68
190215+ // Pulse Browser: Helper stuff for sidebar animation. We can fake sliding in
191216+ // and out by changing the left margin to be a negative value. Then, inside
192217+ // of our css code, we can animate it to close.
193- + this._box.style.marginLeft = `${-Math.abs(this._box.getBoundingClientRect().width)}px`
194- +
218+ + this._box.style.marginLeft = `${-Math.abs(
219+ + this._box.getBoundingClientRect().width
220+ + )}px`;
221+ +
195222+ // We want to fully set it to hidden to slightly improve browser performance
196223+ // when it is hidden. Note that this replaces some of Mozilla's code that
197224+ // would generally be down below
198225+ setTimeout(() => {
199- + this._box.hidden = true
200- + this._splitter.hidden = true
226+ + this._box.hidden = true;
227+ + this._splitter.hidden = true;
201228+
202- + this._box.removeAttribute("checked")
229+ + this._box.removeAttribute("checked");
203230+ }, 170);
204231+
205232 // Replace the document currently displayed in the sidebar with about:blank
206233 // so that we can free memory by unloading the page. We need to explicitly
207234 // create a new content viewer because the old one doesn't get destroyed
208- @@ -626,9 +740 ,6 @@ var SidebarUI = {
235+ @@ -626,9 +753 ,6 @@ var SidebarUI = {
209236 this.browser.setAttribute("src", "about:blank");
210237 this.browser.docShell.createAboutBlankContentViewer(null, null);
211238
@@ -215,7 +242,7 @@ index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..4da170628abea6eb8b9d3a81385d0d68
215242 let selBrowser = gBrowser.selectedBrowser;
216243 selBrowser.focus();
217244 if (triggerNode) {
218- @@ -641,10 +752,21 @@ var SidebarUI = {
245+ @@ -641,10 +765,22 @@ var SidebarUI = {
219246 * none if the argument is an empty string.
220247 */
221248 selectMenuItem(commandID) {
@@ -227,9 +254,10 @@ index 78afa499b4a93fc75e8706a9afb077e2b5ca7428..4da170628abea6eb8b9d3a81385d0d68
227254- let triggerbutton =
228255+ let dropdownTriggerButton =
229256 triggerButtonId && document.getElementById(triggerButtonId);
230- + let sidebarTriggerButton = document.getElementById("sidebar-background-" + id);
231- +
232- +
257+ + let sidebarTriggerButton = document.getElementById(
258+ + "sidebar-background-" + id
259+ + );
260+ +
233261+ setCheckedForItem(id, menu, dropdownTriggerButton);
234262+ setCheckedForItem(id, menu, sidebarTriggerButton);
235263+ }
0 commit comments