Bug 1588516 - Find calendar AppMenu buttons in the palette when not in the toolbar. r=pmorris
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 20 Nov 2019 10:39:18 +1300
changeset 37565 1bc27f2370ac65e0c44e42575b06b91bef105aec
parent 37564 6406591e99ed80248375a71f58bde1295cd56138
child 37566 dbf07a17aee31be33e83c6e0c7e7527a9611c30e
push id396
push userclokep@gmail.com
push dateMon, 06 Jan 2020 23:11:57 +0000
reviewerspmorris
bugs1588516
Bug 1588516 - Find calendar AppMenu buttons in the palette when not in the toolbar. r=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");