-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
234 lines (190 loc) · 5.84 KB
/
main.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
(() => {
function isMatch(text, keyword) {
function splitKorean(text) {
const CHO = "ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ"
const JUNG = "ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ"
const JONG = " ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ"
const splitedArr = text.split('')
for (let i = splitedArr.length - 1; i >= 0; i--) {
let num = text.charCodeAt(i)
if (num >= 0xAC00 && num <= 0xD7A3) {
num -= 0xAC00
let curCho = Math.floor(num / JONG.length / JUNG.length)
let curJung = Math.floor(num / JONG.length % JUNG.length)
let curJong = num % JONG.length
let splitedChr
if (curJong !== 0)
splitedChr = [CHO[curCho], JUNG[curJung], JONG[curJong]]
else
splitedChr = [CHO[curCho], JUNG[curJung]]
splitedArr.splice(i, 1, ...splitedChr)
}
}
return splitedArr.join('')
}
return splitKorean(text.toLowerCase()).includes(splitKorean(keyword.toLowerCase()))
}
const input = document.createElement('input')
input.style =
`margin: 8px;
width: 150px;
height: 24px;
font-size: 14px;
border-radius: 12px;
outline: none;
border: 0;
background-color: rgb(220, 220, 220);
padding: 0 9px;
font-weight: bold;
color: #2c313d;`
let selectedElem = null
function getElemList() {
let listElem = input.parentElement
let scrollbar = listElem.querySelector('div').querySelector('div')
listElem.prepend(input)
if (scrollbar && scrollbar.className.includes('scrollbar'))
listElem = scrollbar.querySelector(".rcs-inner-container")
else
scrollbar = null
return listElem.querySelector("div").children
}
function activedNextSibling(elem) {
elem = elem.nextElementSibling
while (elem) {
if (getComputedStyle(elem).display !== 'hidden')
return elem
elem = elem.nextElementSibling
}
return null
}
function activedPrevSibling(elem) {
elem = elem.previousElementSibling
while (elem) {
if (getComputedStyle(elem).display !== 'hidden')
return elem
elem = elem.previousElementSibling
}
return null
}
input.oninput = (e) => {
const val = e.target.value
let listElem = e.target.parentElement
let scrollbar = listElem.querySelector('div').querySelector('div')
if (scrollbar.className.includes('scrollbar'))
listElem = scrollbar.querySelector(".rcs-inner-container")
else
scrollbar = null
let list = listElem.querySelector("div").children
let totalCount = list.length
let newSelection = false
if (!val.length) {
for (let i of list) {
i.style.display = ''
}
changeSelectedElem(list[0])
}
else {
for (let i of list) {
if (isMatch(i.innerText, val)) {
if (!newSelection) {
changeSelectedElem(i)
newSelection = true
}
i.style.display = ''
}
else {
i.style.display = 'none'
totalCount--
}
}
if (!newSelection)
changeSelectedElem(null)
}
if (scrollbar) {
const innerListElem = listElem.querySelector("div")
if (totalCount <= 5) {
scrollbar.style.height = ''
listElem.style.marginRight = '-20px'
innerListElem.style.marginRight = ''
for (let i of list)
i.style.marginRight = 'auto'
}
else {
scrollbar.style.height = '260px'
listElem.style.marginRight = '0px'
listElem.style.marginRight = '-17px'
innerListElem.style.marginRight = '0px'
for (let i of list)
i.style.marginRight = ''
}
listElem.dispatchEvent(new Event('scroll', { bubbles: true }))
}
}
input.onkeydown = (e) => {
switch (e.code) {
case 'Enter': {
selectedElem?.click()
break
}
case 'ArrowDown': {
let elemList = getElemList()
let next = activedNextSibling(selectedElem)
changeSelectedElem(next ?? elemList[0])
selectedElem.tabIndex = 0
selectedElem.focus()
selectedElem.tabIndex = -1
input.focus()
break
}
case 'ArrowUp': {
let elemList = getElemList()
let prev = activedPrevSibling(selectedElem)
changeSelectedElem(prev ?? elemList[elemList.length - 1])
selectedElem.tabIndex = 0
selectedElem.focus()
selectedElem.tabIndex = -1
input.focus()
break
}
}
}
function changeSelectedElem(elem) {
if (elem === selectedElem)
return
fakeElemNoHover(selectedElem)
selectedElem = elem
fakeElemHover(elem)
}
function fakeElemNoHover(elem) {
if (!elem) return
elem.style.color = '#2c313d'
elem.style.backgroundColor = '#fff'
elem.style.borderBottomColor = '#000'
}
function fakeElemHover(elem) {
if (!elem) return
elem.style.color = '#4f80ff'
elem.style.backgroundColor = '#ecf8ff'
elem.style.borderBottomColor = '#4f80ff'
}
const _renderOptions = Entry.FieldDropdownDynamic.prototype.renderOptions
Entry.FieldDropdownDynamic.prototype.renderOptions = function (...args) {
const ret = _renderOptions.call(this, ...args)
input.value = ""
this.dropdownWidget._container.querySelector(".widget > div > div").prepend(input)
let list = getElemList()
for (let i of list) {
i.onmousemove = i.onmouseover = (e) => {
changeSelectedElem(e.target)
}
}
changeSelectedElem(list[0])
input.focus()
return ret
}
const _destroyOption = Entry.FieldDropdownDynamic.prototype.destroyOption
Entry.FieldDropdownDynamic.prototype.destroyOption = function (...args) {
selectedElem = null
return _destroyOption.call(this, ...args)
}
})()