From 41824547d5e3abe6ffcc3877219fd83c157577c0 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Mar 2025 18:15:34 +0800 Subject: [PATCH 01/13] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Button/PopConfirmButton.razor.js | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js index def41f9a6af..be099157a72 100644 --- a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js +++ b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js @@ -1,4 +1,4 @@ -import { getDescribedElement, getDescribedOwner, hackTooltip, hackPopover, isDisabled } from "../../modules/utility.js" +import { getDescribedElement, getDescribedOwner, hackTooltip, hackPopover, isDisabled, registerBootstrapBlazorModule } from "../../modules/utility.js" import { showTooltip, removeTooltip } from "./Button.razor.js" import Data from "../../modules/data.js" import EventHandler from "../../modules/event-handler.js" @@ -87,17 +87,19 @@ export function init(id) { } } - if (!window.bb_confirm) { - window.bb_confirm = { - handle: false, - items: [] + const module = registerBootstrapBlazorModule('PopConfirmButton', { + handle: false, + items: [], + registerClosePopupHandler: function () { + if (this.handle === false) { + this.handle = true; + + EventHandler.on(document, 'click', confirm.closeConfirm); + } } - } - if (!window.bb_confirm.handle) { - window.bb_confirm.handle = true - EventHandler.on(document, 'click', confirm.closeConfirm); - } - window.bb_confirm.items.push(id) + }); + module.registerClosePopupHandler(); + module.items.push(id); } export function showConfirm(id) { @@ -144,15 +146,15 @@ export function dispose(id) { const confirm = Data.get(id) Data.remove(id) - if (confirm) { - window.bb_confirm.items.pop(id) - if (window.bb_confirm.items.length === 0) { - delete window.bb_confirm - EventHandler.off(document, 'click', confirm.closeConfirm) - } - if (confirm.popover) { - confirm.popover.dispose(); - } + const { popover } = confirm ?? {}; + if (popover) { + popover.dispose(); + } + + const { PopConfirmButton } = window.BootstrapBlazor; + PopConfirmButton.items.pop(id) + if (PopConfirmButton.items.length === 0) { + EventHandler.off(document, 'click', confirm.closeConfirm) } } From f55e35819b5ae1ae96fbef79f98bcafb3cfe944f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Mar 2025 18:15:47 +0800 Subject: [PATCH 02/13] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E9=94=80?= =?UTF-8?q?=E6=AF=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Button/DialButton.razor.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/BootstrapBlazor/Components/Button/DialButton.razor.js b/src/BootstrapBlazor/Components/Button/DialButton.razor.js index f4afdd305a8..c1e8a188c41 100644 --- a/src/BootstrapBlazor/Components/Button/DialButton.razor.js +++ b/src/BootstrapBlazor/Components/Button/DialButton.razor.js @@ -17,24 +17,18 @@ export function init(id) { toggle(el, list) }) - if (!window.bb_dial_button) { - window.bb_dial_button = true - - EventHandler.on(document, 'click', e => closePopup(e)); - } - const module = registerBootstrapBlazorModule('DialButton', { hooked: false, + items: [], registerClosePopupHandler: function () { if (this.hooked === false) { this.hooked = true; - - EventHandler.on(document, 'click', e => closePopup(e)); + EventHandler.on(document, 'click', closePopup); } } }); module.registerClosePopupHandler(); - + module.items.push(id); } export function update(id) { @@ -56,9 +50,17 @@ export function dispose(id) { Data.remove(id) if (dial) { - EventHandler.off(dial.button, 'click') - EventHandler.off(dial.list, 'animationend') + const { button, list } = dial; + EventHandler.off(button, 'click') + EventHandler.off(list, 'animationend') + } + + const { DialButton } = window.BootstrapBlazor; + DialButton.items.pop(id) + if (DialButton.items.length === 0) { + EventHandler.off(document, 'click', closePopup) } + } const toggle = (el, list) => { From 2706b13e114884ef0f7dc511efa16cc1bb6a1dc6 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Mar 2025 18:22:11 +0800 Subject: [PATCH 03/13] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E7=B2=BE=E7=AE=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Button/DialButton.razor.js | 1 - .../Components/Button/SlideButton.razor.js | 32 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/BootstrapBlazor/Components/Button/DialButton.razor.js b/src/BootstrapBlazor/Components/Button/DialButton.razor.js index c1e8a188c41..2b2b6d9b57a 100644 --- a/src/BootstrapBlazor/Components/Button/DialButton.razor.js +++ b/src/BootstrapBlazor/Components/Button/DialButton.razor.js @@ -60,7 +60,6 @@ export function dispose(id) { if (DialButton.items.length === 0) { EventHandler.off(document, 'click', closePopup) } - } const toggle = (el, list) => { diff --git a/src/BootstrapBlazor/Components/Button/SlideButton.razor.js b/src/BootstrapBlazor/Components/Button/SlideButton.razor.js index 9e8594a1925..6af6dddd8bd 100644 --- a/src/BootstrapBlazor/Components/Button/SlideButton.razor.js +++ b/src/BootstrapBlazor/Components/Button/SlideButton.razor.js @@ -1,4 +1,5 @@ -import Data from "../../modules/data.js" +import { registerBootstrapBlazorModule } from "../../modules/utility.js" +import Data from "../../modules/data.js" import EventHandler from "../../modules/event-handler.js" export function init(id) { @@ -23,11 +24,19 @@ export function init(id) { list.classList.remove('show') }) - if (!window.bb_slide_button) { - window.bb_slide_button = true + const module = registerBootstrapBlazorModule('SlideButton', { + handle: false, + items: [], + registerClosePopupHandler: function () { + if (this.handle === false) { + this.handle = true; - EventHandler.on(document, 'click', e => closePopup(e)); - } + EventHandler.on(document, 'click', closePopup); + } + } + }); + module.registerClosePopupHandler(); + module.items.push(id); } export function update(id) { @@ -42,10 +51,17 @@ export function dispose(id) { Data.remove(id) if (slide) { - EventHandler.off(slide.button, 'click') - EventHandler.off(slide.list, 'click', '.btn-close') - EventHandler.off(slide.list, 'click', '.slide-item') + const { button, list } = slide ?? {}; + EventHandler.off(button, 'click'); + EventHandler.off(list, 'click'); } + + const { SlideButton } = window.BootstrapBlazor; + SlideButton.items.pop(id) + if (SlideButton.items.length === 0) { + EventHandler.off(document, 'click', closePopup) + } + } const reset = slide => { From 7dc648af176896bc62024f23a6a3e588beb95bbf Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Mar 2025 18:36:15 +0800 Subject: [PATCH 04/13] =?UTF-8?q?refactor:=20base-popover=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Button/SlideButton.razor.js | 1 - .../Components/Select/Select.razor.js | 3 +++ .../wwwroot/modules/base-popover.js | 27 ++++++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/BootstrapBlazor/Components/Button/SlideButton.razor.js b/src/BootstrapBlazor/Components/Button/SlideButton.razor.js index 6af6dddd8bd..b7cbe41e09f 100644 --- a/src/BootstrapBlazor/Components/Button/SlideButton.razor.js +++ b/src/BootstrapBlazor/Components/Button/SlideButton.razor.js @@ -61,7 +61,6 @@ export function dispose(id) { if (SlideButton.items.length === 0) { EventHandler.off(document, 'click', closePopup) } - } const reset = slide => { diff --git a/src/BootstrapBlazor/Components/Select/Select.razor.js b/src/BootstrapBlazor/Components/Select/Select.razor.js index 3c8b992d092..3731aafcb19 100644 --- a/src/BootstrapBlazor/Components/Select/Select.razor.js +++ b/src/BootstrapBlazor/Components/Select/Select.razor.js @@ -50,5 +50,8 @@ export function dispose(id) { if (select) { unregisterSelect(select); + if (select.popover) { + Popover.dispose(select.popover); + } } } diff --git a/src/BootstrapBlazor/wwwroot/modules/base-popover.js b/src/BootstrapBlazor/wwwroot/modules/base-popover.js index a2b7b47c532..b0f369d742f 100644 --- a/src/BootstrapBlazor/wwwroot/modules/base-popover.js +++ b/src/BootstrapBlazor/wwwroot/modules/base-popover.js @@ -1,4 +1,4 @@ -import { getDescribedElement, getDescribedOwner, hackTooltip, hackPopover, isDisabled } from "./utility.js" +import { getDescribedElement, getDescribedOwner, hackTooltip, hackPopover, isDisabled, registerBootstrapBlazorModule } from "./utility.js" import EventHandler from "./event-handler.js" const Popover = { @@ -131,7 +131,7 @@ const Popover = { } } - const closePopover = e => { + popover.closePopover = e => { const selector = `.${popover.class}.show`; const el = e.target; if (el.closest(selector)) { @@ -161,11 +161,20 @@ const Popover = { } }) - if (!window.bb_dropdown) { - window.bb_dropdown = true + const module = registerBootstrapBlazorModule('Popover', { + handle: false, + items: [], + registerClosePopupHandler: function () { + if (this.handle === false) { + this.handle = true; + + EventHandler.on(document, 'click', popover.closePopover); + } + } + }); + module.registerClosePopupHandler(); + module.items.push(popover); - EventHandler.on(document, 'click', closePopover); - } // update handler if (popover.toggleMenu) { @@ -207,6 +216,12 @@ const Popover = { EventHandler.off(popover.el, 'hide.bs.popover') EventHandler.off(popover.el, 'click', '.dropdown-toggle') EventHandler.off(popover.toggleMenu, 'click', '.dropdown-item') + + const { Popover } = window.BootstrapBlazor; + Popover.items.pop(popover) + if (Popover.items.length === 0) { + EventHandler.off(document, 'click', popover.closePopover) + } } else { EventHandler.off(popover.el, 'show.bs.dropdown') From 744b5166ea942e9f9f9c3709d3d12e54a0620e43 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Mar 2025 11:08:30 +0800 Subject: [PATCH 05/13] =?UTF-8?q?refactor:=20registerBootstrapBlazorModule?= =?UTF-8?q?=20=E9=87=8D=E6=9E=84=E7=B2=BE=E7=AE=80=E5=A4=96=E9=9D=A2?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/modules/utility.js | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/utility.js b/src/BootstrapBlazor/wwwroot/modules/utility.js index 7e203f6e7fe..b07890577cd 100644 --- a/src/BootstrapBlazor/wwwroot/modules/utility.js +++ b/src/BootstrapBlazor/wwwroot/modules/utility.js @@ -815,10 +815,33 @@ const deepMerge = (obj1, obj2, skipNull = true) => { return obj1; } -export function registerBootstrapBlazorModule(name, module) { +export function registerBootstrapBlazorModule(name, identifier, callback) { window.BootstrapBlazor ??= {}; - window.BootstrapBlazor[name] ??= deepMerge(window.BootstrapBlazor[name] ?? {}, module); - return window.BootstrapBlazor[name]; + window.BootstrapBlazor[name] ??= { + _init: false, + _items: [], + register: function (identifier, callback) { + if (identifier) { + this._items.push(identifier); + } + if (this._init === false) { + this._init = true; + callback(); + } + return this; + }, + dispose: function (identifier, callback) { + const index = this._items.indexOf(identifier); + if (index > -1) { + this._items.splice(index, 1); + } + if (this._items.length === 0) { + callback(); + } + } + }; + + return window.BootstrapBlazor[name].register(identifier, callback); } export function setTitle(title) { From 1c17f9c26e411e5f82532a6d6da97d76e7fe1772 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Mar 2025 11:08:54 +0800 Subject: [PATCH 06/13] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Button/DialButton.razor.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/BootstrapBlazor/Components/Button/DialButton.razor.js b/src/BootstrapBlazor/Components/Button/DialButton.razor.js index 2b2b6d9b57a..559eef56295 100644 --- a/src/BootstrapBlazor/Components/Button/DialButton.razor.js +++ b/src/BootstrapBlazor/Components/Button/DialButton.razor.js @@ -16,19 +16,9 @@ export function init(id) { EventHandler.on(button, 'click', () => { toggle(el, list) }) - - const module = registerBootstrapBlazorModule('DialButton', { - hooked: false, - items: [], - registerClosePopupHandler: function () { - if (this.hooked === false) { - this.hooked = true; - EventHandler.on(document, 'click', closePopup); - } - } + registerBootstrapBlazorModule('DialButton', id, () => { + EventHandler.on(document, 'click', closePopup); }); - module.registerClosePopupHandler(); - module.items.push(id); } export function update(id) { @@ -56,10 +46,9 @@ export function dispose(id) { } const { DialButton } = window.BootstrapBlazor; - DialButton.items.pop(id) - if (DialButton.items.length === 0) { + DialButton.dispose(id, () => { EventHandler.off(document, 'click', closePopup) - } + }); } const toggle = (el, list) => { From 7174bdae3149143d973bb2c1926765e2aaa48026 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Mar 2025 11:10:02 +0800 Subject: [PATCH 07/13] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Button/SlideButton.razor.js | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/BootstrapBlazor/Components/Button/SlideButton.razor.js b/src/BootstrapBlazor/Components/Button/SlideButton.razor.js index b7cbe41e09f..a6e87484e40 100644 --- a/src/BootstrapBlazor/Components/Button/SlideButton.razor.js +++ b/src/BootstrapBlazor/Components/Button/SlideButton.razor.js @@ -23,20 +23,9 @@ export function init(id) { EventHandler.on(list, 'click', '.slide-item', e => { list.classList.remove('show') }) - - const module = registerBootstrapBlazorModule('SlideButton', { - handle: false, - items: [], - registerClosePopupHandler: function () { - if (this.handle === false) { - this.handle = true; - - EventHandler.on(document, 'click', closePopup); - } - } + registerBootstrapBlazorModule('SlideButton', id, () => { + EventHandler.on(document, 'click', closePopup) }); - module.registerClosePopupHandler(); - module.items.push(id); } export function update(id) { @@ -57,10 +46,9 @@ export function dispose(id) { } const { SlideButton } = window.BootstrapBlazor; - SlideButton.items.pop(id) - if (SlideButton.items.length === 0) { + SlideButton.dispose(id, () => { EventHandler.off(document, 'click', closePopup) - } + }); } const reset = slide => { From a42af4c8f122f3048519c89e465e98469204cb5e Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Mar 2025 11:10:56 +0800 Subject: [PATCH 08/13] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Button/PopConfirmButton.razor.js | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js index be099157a72..cc6527c27ab 100644 --- a/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js +++ b/src/BootstrapBlazor/Components/Button/PopConfirmButton.razor.js @@ -1,7 +1,7 @@ import { getDescribedElement, getDescribedOwner, hackTooltip, hackPopover, isDisabled, registerBootstrapBlazorModule } from "../../modules/utility.js" -import { showTooltip, removeTooltip } from "./Button.razor.js" import Data from "../../modules/data.js" import EventHandler from "../../modules/event-handler.js" +export { showTooltip, removeTooltip } from "./Button.razor.js" const config = { class: 'popover-confirm', @@ -62,7 +62,7 @@ export function init(id) { EventHandler.on(el, 'inserted.bs.popover', confirm.inserted) EventHandler.on(el, 'hide.bs.popover', confirm.hide) - confirm.checkCancel = el => { + const checkCancel = el => { // check button let self = el === confirm.el || el.closest('.dropdown-toggle') === confirm.el self = self && confirm.popover && confirm.popover._isShown() @@ -74,7 +74,7 @@ export function init(id) { confirm.closeConfirm = e => { const el = e.target - if (!confirm.checkCancel(el)) { + if (!checkCancel(el)) { document.querySelectorAll(config.popoverSelector).forEach(function (ele) { const element = getDescribedOwner(ele) if (element) { @@ -87,19 +87,9 @@ export function init(id) { } } - const module = registerBootstrapBlazorModule('PopConfirmButton', { - handle: false, - items: [], - registerClosePopupHandler: function () { - if (this.handle === false) { - this.handle = true; - - EventHandler.on(document, 'click', confirm.closeConfirm); - } - } + registerBootstrapBlazorModule('PopConfirmButton', id, () => { + EventHandler.on(document, 'click', confirm.closeConfirm); }); - module.registerClosePopupHandler(); - module.items.push(id); } export function showConfirm(id) { @@ -152,13 +142,7 @@ export function dispose(id) { } const { PopConfirmButton } = window.BootstrapBlazor; - PopConfirmButton.items.pop(id) - if (PopConfirmButton.items.length === 0) { + PopConfirmButton.dispose(id, () => { EventHandler.off(document, 'click', confirm.closeConfirm) - } -} - -export { - showTooltip, - removeTooltip + }); } From 27d62b6d9767e5f8b40e2965aef53b39b255199f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Mar 2025 11:13:08 +0800 Subject: [PATCH 09/13] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/modules/base-popover.js | 44 +++++++------------ 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/base-popover.js b/src/BootstrapBlazor/wwwroot/modules/base-popover.js index b0f369d742f..eb56a9ef373 100644 --- a/src/BootstrapBlazor/wwwroot/modules/base-popover.js +++ b/src/BootstrapBlazor/wwwroot/modules/base-popover.js @@ -131,6 +131,17 @@ const Popover = { } } + + EventHandler.on(el, 'show.bs.popover', showPopover) + EventHandler.on(el, 'inserted.bs.popover', insertedPopover) + EventHandler.on(el, 'hide.bs.popover', hidePopover) + EventHandler.on(el, 'click', popover.toggleClass, active) + EventHandler.on(popover.toggleMenu, 'click', '.dropdown-item', e => { + if (popover.popover._config.autoClose !== 'outside') { + popover.hide() + } + }) + popover.closePopover = e => { const selector = `.${popover.class}.show`; const el = e.target; @@ -150,31 +161,9 @@ const Popover = { } }); } - - EventHandler.on(el, 'show.bs.popover', showPopover) - EventHandler.on(el, 'inserted.bs.popover', insertedPopover) - EventHandler.on(el, 'hide.bs.popover', hidePopover) - EventHandler.on(el, 'click', popover.toggleClass, active) - EventHandler.on(popover.toggleMenu, 'click', '.dropdown-item', e => { - if (popover.popover._config.autoClose !== 'outside') { - popover.hide() - } - }) - - const module = registerBootstrapBlazorModule('Popover', { - handle: false, - items: [], - registerClosePopupHandler: function () { - if (this.handle === false) { - this.handle = true; - - EventHandler.on(document, 'click', popover.closePopover); - } - } + registerBootstrapBlazorModule('Popover', el, () => { + EventHandler.on(document, 'click', popover.closePopover); }); - module.registerClosePopupHandler(); - module.items.push(popover); - // update handler if (popover.toggleMenu) { @@ -218,10 +207,9 @@ const Popover = { EventHandler.off(popover.toggleMenu, 'click', '.dropdown-item') const { Popover } = window.BootstrapBlazor; - Popover.items.pop(popover) - if (Popover.items.length === 0) { - EventHandler.off(document, 'click', popover.closePopover) - } + Popover.dispose(popover, () => { + EventHandler.off(document, 'click', popover.closePopover); + }); } else { EventHandler.off(popover.el, 'show.bs.dropdown') From 301c65b9c0d6cfaf8a7b2aa762c56cd4c4610a29 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Mar 2025 11:13:53 +0800 Subject: [PATCH 10/13] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/modules/utility.js | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/utility.js b/src/BootstrapBlazor/wwwroot/modules/utility.js index b07890577cd..58604cff047 100644 --- a/src/BootstrapBlazor/wwwroot/modules/utility.js +++ b/src/BootstrapBlazor/wwwroot/modules/utility.js @@ -571,23 +571,16 @@ const hackPopover = (popover, css) => { } const hackTooltip = function () { - const tooltip = registerBootstrapBlazorModule('Tooltip', { - hooked: false, - hackDispose: function () { - if (this.hooked === false) { - this.hooked = true; - - const originalDispose = bootstrap.Tooltip.prototype.dispose; - bootstrap.Tooltip.prototype.dispose = function () { - originalDispose.call(this); - // fix https://github.com/twbs/bootstrap/issues/37474 - this._activeTrigger = {}; - this._element = document.createElement('noscript'); // placeholder with no behavior - } - } + const mock = () => { + const originalDispose = bootstrap.Tooltip.prototype.dispose; + bootstrap.Tooltip.prototype.dispose = function () { + originalDispose.call(this); + // fix https://github.com/twbs/bootstrap/issues/37474 + this._activeTrigger = {}; + this._element = document.createElement('noscript'); // placeholder with no behavior } - }); - tooltip.hackDispose(); + } + registerBootstrapBlazorModule('Tooltip', null, mock); } const setIndeterminate = (object, state) => { From 678ee727e5f83a617671e1352ff3bff65a63b8d7 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Mar 2025 11:17:48 +0800 Subject: [PATCH 11/13] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutoComplete/AutoComplete.razor.js | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js index cfca16f9777..ef02ab29562 100644 --- a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js +++ b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js @@ -72,29 +72,22 @@ export function init(id, invoke) { filterCallback(v); }); - const module = registerBootstrapBlazorModule('AutoComplete', { - hooked: false, - registerCloseDropdownHandler: function () { - if (this.hooked === false) { - this.hooked = true; - - EventHandler.on(document, 'click', e => { - [...document.querySelectorAll('.auto-complete.show')].forEach(a => { - const ac = e.target.closest('.auto-complete'); - if (ac === a) { - return; - } - - const el = a.querySelector('[data-bs-toggle="bb.dropdown"]'); - if (el === null) { - a.classList.remove('show'); - } - }); - }); + ac.closePopover = e => { + [...document.querySelectorAll('.auto-complete.show')].forEach(a => { + const ac = e.target.closest('.auto-complete'); + if (ac === a) { + return; } - } + + const el = a.querySelector('[data-bs-toggle="bb.dropdown"]'); + if (el === null) { + a.classList.remove('show'); + } + }); + } + registerBootstrapBlazorModule('AutoComplete', id, () => { + EventHandler.on(document, 'click', ac.closePopover); }); - module.registerCloseDropdownHandler(); } const handlerKeyup = (ac, e) => { @@ -168,6 +161,11 @@ export function dispose(id) { EventHandler.off(input, 'blur'); Input.dispose(input); } + + const { AutoComplete } = window.BootstrapBlazor; + AutoComplete.dispose(id, () => { + EventHandler.off(document, 'click', ac.closePopover); + }); } const scrollIntoView = (el, item) => { From 8d9c2df9b039ccd7d595015a0ef5ee0db0f7634a Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Mar 2025 11:20:37 +0800 Subject: [PATCH 12/13] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/wwwroot/modules/utility.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/utility.js b/src/BootstrapBlazor/wwwroot/modules/utility.js index 58604cff047..807f5ed1871 100644 --- a/src/BootstrapBlazor/wwwroot/modules/utility.js +++ b/src/BootstrapBlazor/wwwroot/modules/utility.js @@ -824,9 +824,11 @@ export function registerBootstrapBlazorModule(name, identifier, callback) { return this; }, dispose: function (identifier, callback) { - const index = this._items.indexOf(identifier); - if (index > -1) { - this._items.splice(index, 1); + if (identifier) { + const index = this._items.indexOf(identifier); + if (index > -1) { + this._items.splice(index, 1); + } } if (this._items.length === 0) { callback(); From 6c0e7621382b1b088595aa5da33e56ae36b5488d Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Mon, 3 Mar 2025 11:35:30 +0800 Subject: [PATCH 13/13] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/modules/utility.js | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/utility.js b/src/BootstrapBlazor/wwwroot/modules/utility.js index 807f5ed1871..0cb54fb72a0 100644 --- a/src/BootstrapBlazor/wwwroot/modules/utility.js +++ b/src/BootstrapBlazor/wwwroot/modules/utility.js @@ -813,25 +813,22 @@ export function registerBootstrapBlazorModule(name, identifier, callback) { window.BootstrapBlazor[name] ??= { _init: false, _items: [], - register: function (identifier, callback) { - if (identifier) { - this._items.push(identifier); + register: function (id, cb) { + if (id) { + this._items.push(id); } if (this._init === false) { this._init = true; - callback(); + cb(); } return this; }, - dispose: function (identifier, callback) { - if (identifier) { - const index = this._items.indexOf(identifier); - if (index > -1) { - this._items.splice(index, 1); - } + dispose: function (id, cb) { + if (id) { + this._items = this._items.filter(item => item !== id); } - if (this._items.length === 0) { - callback(); + if (this._items.length === 0 && cb) { + cb(); } } };