From 1ae8fb4bfa356cd14ab2a038bd86d7b49fada359 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 8 Oct 2020 22:44:55 -0400 Subject: [PATCH] Modal updates 2 (#901) * Fix incorrect visible value * Focus element when visibility is set * Add isVisible function --- ext/bg/js/settings/modal.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ext/bg/js/settings/modal.js b/ext/bg/js/settings/modal.js index f9a8ec6b..55f73406 100644 --- a/ext/bg/js/settings/modal.js +++ b/ext/bg/js/settings/modal.js @@ -29,11 +29,23 @@ class Modal extends EventDispatcher { return this._node; } + isVisible() { + if (this._useJqueryModal()) { + return !!(this._getWrappedNode().data('bs.modal') || {}).isShown; + } else { + return this._node.classList.contains(this._visibleClassName); + } + } + setVisible(value) { + value = !!value; if (this._useJqueryModal()) { this._getWrappedNode().modal(value ? 'show' : 'hide'); } else { - this._node.classList.toggle(this._visibleClassName, value); + const {classList} = this._node; + if (classList.contains(this._visibleClassName) === value) { return; } + classList.toggle(this._visibleClassName, value); + if (value) { this._node.focus(); } } } @@ -86,7 +98,7 @@ class Modal extends EventDispatcher { const visible = this._node.classList.contains(this._visibleClassName); if (this._visible === visible) { return; } this._visible = visible; - this.trigger('visibilityChanged', {visible: false}); + this.trigger('visibilityChanged', {visible}); } _useJqueryModal() {