aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-10-18 19:48:44 -0400
committerGitHub <noreply@github.com>2020-10-18 19:48:44 -0400
commit69e5ea61388519c59c30f8fa4b225d82ff120bc7 (patch)
tree45b07f47c3e6cb921219d4f860fd4bd9f76b034f /ext/bg/js/settings
parent9fa2ebddc8144c172ce872d60d1b94ed57ac6f7d (diff)
Popup menu updates (#942)
* Expose isClosed property * Add popupMenu to detail * Return true if closed, false otherwise * Add closed event to PopupMenu
Diffstat (limited to 'ext/bg/js/settings')
-rw-r--r--ext/bg/js/settings/popup-menu.js25
1 files 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 <https://www.gnu.org/licenses/>.
*/
-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;
}
}