From 69e5ea61388519c59c30f8fa4b225d82ff120bc7 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 18 Oct 2020 19:48:44 -0400 Subject: Popup menu updates (#942) * Expose isClosed property * Add popupMenu to detail * Return true if closed, false otherwise * Add closed event to PopupMenu --- ext/bg/js/settings/popup-menu.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/ext/bg/js/settings/popup-menu.js b/ext/bg/js/settings/popup-menu.js index f9c7c165..cdacd81f 100644 --- a/ext/bg/js/settings/popup-menu.js +++ b/ext/bg/js/settings/popup-menu.js @@ -15,8 +15,9 @@ * along with this program. If not, see . */ -class PopupMenu { +class PopupMenu extends EventDispatcher { constructor(sourceElement, container) { + super(); this._sourceElement = sourceElement; this._container = container; this._menu = container.querySelector('.popup-menu'); @@ -24,6 +25,10 @@ class PopupMenu { this._eventListeners = new EventListenerCollection(); } + get isClosed() { + return this._isClosed; + } + prepare() { const items = this._menu.querySelectorAll('.popup-menu-item'); this._setPosition(items); @@ -41,6 +46,7 @@ class PopupMenu { bubbles: false, cancelable: false, detail: { + popupMenu: this, container: this._container, menu: this._menu } @@ -48,7 +54,7 @@ class PopupMenu { } close() { - this._close(null, 'close'); + return this._close(null, 'close'); } // Private @@ -149,13 +155,14 @@ class PopupMenu { } _close(item, cause) { - if (this._isClosed) { return; } + if (this._isClosed) { return true; } const action = (item !== null ? item.dataset.menuAction : null); const result = this._sourceElement.dispatchEvent(new CustomEvent('menuClosed', { bubbles: false, cancelable: true, detail: { + popupMenu: this, container: this._container, menu: this._menu, item, @@ -163,11 +170,21 @@ class PopupMenu { cause } })); - if (!result) { return; } + if (!result) { return false; } this._eventListeners.removeAllEventListeners(); if (this._container.parentNode !== null) { this._container.parentNode.removeChild(this._container); } + + this.trigger('closed', { + popupMenu: this, + container: this._container, + menu: this._menu, + item, + action, + cause + }); + return true; } } -- cgit v1.2.3