forked from BasicPrimitives/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRange.js
More file actions
65 lines (61 loc) · 2.06 KB
/
Copy pathRange.js
File metadata and controls
65 lines (61 loc) · 2.06 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
import { NumberFormatter } from './Formatters';
import { ControlType } from './enums';
export function RangeConfig(id, defaultItem, caption, min, max, step, onUpdate) {
this.controlType = ControlType.Range;
this.id = id;
this.defaultItem = defaultItem;
this.caption = caption;
this.min = min;
this.max = max;
this.step = step;
this.scale = 1;
if(step < 1.0) {
this.scale = 1 / step;
this.min = min * this.scale;
this.max = max * this.scale;
this.step = step * this.scale;
}
this.onUpdate = onUpdate;
};
export function RangeRender() {
this.render = function (config, namespace, defaultItem) {
var controlBody = ["p",
["label",
{
"for": namespace + config.id,
"class": "form-label",
"id": namespace + config.id + "label"
},
config.caption + ": " + defaultItem
],
["input",
{
type: "range",
class: "form-range",
id: namespace + config.id,
value: ((defaultItem * config.scale).toString()),
min: config.min.toString(),
max: config.max.toString(),
step: config.step.toString(),
"$": function (element) {
element.addEventListener('input', function (event) {
var labelElement = document.getElementById(event.target.id + "label");
labelElement.innerText = config.caption + ": " + NumberFormatter(event.target.value) / config.scale;
});
element.addEventListener('change', function (event) {
var labelElement = document.getElementById(event.target.id + "label");
labelElement.innerText = config.caption + ": " + NumberFormatter(event.target.value) / config.scale;
config.onUpdate(element, config);
});
}
}
]
];
return controlBody;
};
this.getValue = function (item, namespace) {
var element = document.getElementById(namespace + item.id),
result = NumberFormatter(element.value) / item.scale;
return result;
};
};