-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSelectCity.razor.js
More file actions
85 lines (72 loc) · 2 KB
/
SelectCity.razor.js
File metadata and controls
85 lines (72 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import Data from "../../BootstrapBlazor/modules/data.js"
import EventHandler from "../../BootstrapBlazor/modules/event-handler.js"
import Input from "../../BootstrapBlazor/modules/input.js"
import Popover from "../../BootstrapBlazor/modules/base-popover.js"
export function init(id, invoke, options) {
const el = document.getElementById(id);
if (el === null) {
return
}
const popover = Popover.init(el, {
shownCallback: () => {
if (searchInput != null) {
searchInput.focus();
}
}
});
const region = { el, invoke, options, popover };
initSearch(region);
Data.set(id, region);
}
export function resetSearch(id, search) {
const region = Data.get(id);
if (search) {
initSearch(region)
}
else {
disposeSearch(region);
}
}
const initSearch = region => {
const { el, invoke, options } = region;
const searchInput = el.querySelector(".search-text");
if (searchInput) {
Input.composition(searchInput, async v => {
await invoke.invokeMethodAsync(options.triggerSearch, v);
});
}
const search = el.querySelector(".dropdown-menu-search .clear-icon");
if (search) {
EventHandler.on(search, 'click', async e => {
searchInput.value = '';
await invoke.invokeMethodAsync(options.triggerSearch, '');
});
}
region.searchInput = searchInput;
region.search = search;
}
const disposeSearch = region => {
const { searchInput, search } = region;
if (searchInput) {
Input.dispose(searchInput);
}
if (search) {
EventHandler.off(search, 'click');
}
}
export function hide(id) {
const region = Data.get(id)
const { popover } = region;
if (popover) {
popover.hide();
}
}
export function dispose(id) {
const region = Data.get(id)
Data.remove(id)
const { popover } = region;
if (popover) {
Popover.dispose(popover);
}
disposeSearch(region);
}