Bug 1588516 - Find calendar AppMenu buttons in the palette when not in the toolbar. r+a=pmorris
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 20 Nov 2019 10:39:18 +1300
changeset 37295 c5e0a5542802fa67c10f1bf93b340027ad46630b
parent 37294 c3531523b298f793d91eae93d447a388d56cd97e
child 37296 100d596fc5d4984704d40ba194190bc817065907
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
bugs1588516
Bug 1588516 - Find calendar AppMenu buttons in the palette when not in the toolbar. r+a=pmorris
calendar/base/content/calendar-chrome-startup.js
--- a/calendar/base/content/calendar-chrome-startup.js
+++ b/calendar/base/content/calendar-chrome-startup.js
@@ -148,21 +148,34 @@ var calendarWindowPrefs = {
     }
   },
 };
 
 /**
  * Set up calendar appmenu buttons by adding event listeners to the buttons.
  */
 function setUpCalendarAppMenuButtons() {
-  ["calendar-appmenu-button", "task-appmenu-button", "calendar-item-appmenu-button"].forEach(id => {
-    const button = document.getElementById(id);
-    button.addEventListener("mousedown", PanelUI);
-    button.addEventListener("keypress", PanelUI);
-  });
+  function setUpButton(id, toolboxId) {
+    let button = document.getElementById(id);
+    if (!button) {
+      // If not in the document, the button should be in the toolbox palette,
+      // which isn't part of the document.
+      let toolbox = document.getElementById(toolboxId);
+      button = toolbox.palette.querySelector(`#${id}`);
+    }
+
+    if (button) {
+      button.addEventListener("mousedown", PanelUI);
+      button.addEventListener("keypress", PanelUI);
+    }
+  }
+
+  setUpButton("calendar-appmenu-button", "calendar-toolbox");
+  setUpButton("task-appmenu-button", "task-toolbox");
+  setUpButton("calendar-item-appmenu-button", "event-toolbox");
 }
 
 /**
  * Event listener used to refresh the "Events and Tasks" menu/view in the appmenu.
  */
 function refreshEventsAndTasksMenu(event) {
   changeMenuForTask(event);
   setupDeleteMenuitem("appmenu_ltnDeleteSelectedCalendar");