-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelector.js
69 lines (65 loc) · 1.75 KB
/
Selector.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
import Component from "./Component.js"
import ObjectHelper from "./Helpers/ObjectHelper.js"
import Input from "./Input.js";
export default class Selector extends Input {
constructor() {
super()
this.selectorOptions = []
}
static copyConfig = ObjectHelper.merge(Component.copyConfig, {
includeProperties: {
selectorOptions: true,
},
})
addOption(option) {
for (let i = 0; ; i++) {
if (this.selectorOptions[i] == undefined) {
this.selectorOptions[i] = option
break
}
}
if (this.isBuilt) this.addOptionToContainer(option)
return this
}
createHTMLElement() {
this.container = document.createElement("select")
this.container.style.pointerEvents = "all"
this.container.style.position = "absolute"
}
addOptionToContainer(option) {
let optionContainer = document.createElement("option")
optionContainer.value = option.value
optionContainer.innerText = option.text
this.container.appendChild(optionContainer)
return this
}
refreshOptions() {
this.container.innerText = ""
for (let option of this.selectorOptions) {
if (option != undefined) {
this.addOptionToContainer(option)
}
}
}
removeOptionByValue(value) {
for (let i = 0; i < this.selectorOptions.length; i++) {
if (this.selectorOptions[i] != undefined && this.selectorOptions[i].value == value) {
delete this.selectorOptions[i]
this.refrestOptions()
break
}
}
}
build() {
super.build()
this.refreshOptions()
this.isBuilt = true
return this
}
}
export class Option {
constructor(value, text) {
this.value = value
this.text = text
}
}