Skip to content

Commit 006baed

Browse files
committed
refactor: 精简代码
1 parent 7a76fab commit 006baed

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import { debounce } from "../../modules/utility.js"
1+
import { debounce, registerBootstrapBlazorModule } from "../../modules/utility.js"
22
import { handleKeyUp, select, selectAllByFocus, selectAllByEnter } from "../Input/BootstrapInput.razor.js"
33
import Data from "../../modules/data.js"
44
import EventHandler from "../../modules/event-handler.js"
55
import Input from "../../modules/input.js"
66
import Popover from "../../modules/base-popover.js"
77

8-
if (window.BootstrapBlazor === void 0) {
9-
window.BootstrapBlazor = {};
10-
}
11-
128
export function init(id, invoke) {
139
const el = document.getElementById(id)
1410
const menu = el.querySelector('.dropdown-menu')
@@ -76,31 +72,28 @@ export function init(id, invoke) {
7672
filterCallback(v);
7773
});
7874

79-
if (window.BootstrapBlazor.AutoComplete === void 0) {
80-
window.BootstrapBlazor.AutoComplete = {
81-
hooked: false,
82-
registerCloseDropdownHandler: function () {
83-
if (this.hooked === false) {
84-
this.hooked = true;
85-
86-
EventHandler.on(document, 'click', e => {
87-
[...document.querySelectorAll('.auto-complete.show')].forEach(a => {
88-
const ac = e.target.closest('.auto-complete');
89-
if (ac === a) {
90-
return;
91-
}
92-
93-
const el = a.querySelector('[data-bs-toggle="bb.dropdown"]');
94-
if (el === null) {
95-
a.classList.remove('show');
96-
}
97-
});
75+
registerBootstrapBlazorModule('AutoComplete', {
76+
hooked: false,
77+
registerCloseDropdownHandler: function () {
78+
if (this.hooked === false) {
79+
this.hooked = true;
80+
81+
EventHandler.on(document, 'click', e => {
82+
[...document.querySelectorAll('.auto-complete.show')].forEach(a => {
83+
const ac = e.target.closest('.auto-complete');
84+
if (ac === a) {
85+
return;
86+
}
87+
88+
const el = a.querySelector('[data-bs-toggle="bb.dropdown"]');
89+
if (el === null) {
90+
a.classList.remove('show');
91+
}
9892
});
99-
}
93+
});
10094
}
10195
}
102-
}
103-
96+
});
10497
window.BootstrapBlazor.AutoComplete.registerCloseDropdownHandler();
10598
}
10699

0 commit comments

Comments
 (0)