-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHtmlComponents.js
116 lines (97 loc) · 3.16 KB
/
HtmlComponents.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
function checkbox(parent, id, text, checked=false, disabled=false, onchange=null){
var checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.id = id;
checkbox.checked = checked;
checkbox.disabled = disabled;
checkbox.onchange = onchange;
var label = document.createElement('label');
label.htmlFor = id;
label.appendChild(document.createTextNode(text));
parent.appendChild(checkbox);
parent.appendChild(label);
return checkbox;
}
function br(parent){
var br = document.createElement('br');
parent.appendChild(br)
}
function hr(parent){
var br = document.createElement('hr');
parent.appendChild(br)
}
function select(parent, id, text, items, disabled=false, onchange=null){
var select = document.createElement('select');
select.id = id;
select.disabled = disabled;
select.style = 'float: right;';
select.onchange = onchange;
for(let item of items){
var option = document.createElement('option');
option.value = item.value;
option.innerHTML = item.label;
select.appendChild(option);
}
var label = document.createElement('label');
label.htmlFor = id;
label.appendChild(document.createTextNode(text));
parent.appendChild(label);
parent.appendChild(select);
return select;
}
function labeledTextbox(parent, id, labelText, textboxText='', size=20, disabled = false, readOnly=false, onchange=null){
var input = document.createElement('input');
input.id = id;
input.disabled = disabled;
input.size = size;
input.value = textboxText;
input.style = 'text-align: right; float: right;';
input.readOnly = readOnly;
input.onchange = onchange
var label = document.createElement('label');
label.htmlFor = id;
label.appendChild(document.createTextNode(labelText));
parent.appendChild(label);
parent.appendChild(input);
return input;
}
function textarea(parent, id, text){
var textarea = document.createElement('textarea');
textarea.id = id;
textarea.value = text;
parent.appendChild(textarea);
return textarea;
}
function button(parent, id, text, onclick=null){
let button = document.createElement('input');
button.id = id;
button.type = 'button'
button.value = text;
button.onclick = onclick;
parent.appendChild(button);
return button
}
function colorpicker(parent, id, initialValue){
let colorpicker = document.createElement('input');
colorpicker.id = id;
colorpicker.type = 'color'
colorpicker.value = initialValue;
colorpicker.valueFormat = 'rgb'
parent.appendChild(colorpicker);
return colorpicker
}
function range(parent, id, min, max, initialValue){
let range = document.createElement('input');
range.id = id;
range.type = 'range'
range.value = initialValue;
range.min = min;
range.max = max;
parent.appendChild(range);
return range
}
function onRangeChange(r,f) {
var n,c,m;
r.addEventListener("input",function(e){n=1;c=e.target.value;if(c!=m)f(e);m=c;});
r.addEventListener("change",function(e){if(!n)f(e);});
}