forked from BasicPrimitives/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColor.js
More file actions
92 lines (87 loc) · 2.45 KB
/
Color.js
File metadata and controls
92 lines (87 loc) · 2.45 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
86
87
88
89
90
91
92
import { ControlType } from './enums';
export function ColorConfig(id, defaultItem, caption, isNullable, onUpdate) {
this.controlType = ControlType.ColorPicker;
this.id = id;
this.defaultItem = defaultItem;
this.caption = caption;
this.onUpdate = onUpdate;
this.isNullable = isNullable;
};
export function ColorRender() {
this.render = function (config, namespace, value) {
var properties = {
"class": "form-check-input",
"name": namespace + config.id,
"id": namespace + config.id + "IsNullable",
"type": 'checkbox',
"$": function (element) {
element.addEventListener('change', function (event) {
var colorPicker = document.getElementById(namespace + config.id );
if(event.target.checked) {
colorPicker.removeAttribute("disabled");
} else {
colorPicker.setAttribute("disabled", "disabled");
}
config.onUpdate(element, config);
});
}
};
if (value != null) {
properties["checked"] = "checked";
}
var controlBody = ["p"];
if(config.isNullable) {
controlBody.push( ["div",
{
"class": "form-check form-switch"
},
["input",
properties,
],
["label",
{
"class": "form-check-label",
"for": namespace + config.id + "IsNullable"
},
config.caption
]
]);
} else {
controlBody.push(["label",
{
"for": namespace + config.id,
"class": "form-label"
},
config.caption
]);
};
controlBody.push(["input",
{
"type": "color",
"class": "form-control form-control-color",
"id": namespace + config.id,
"value": value,
"title": "Choose your color",
"disabled": (value == null ? "disabled" : ""),
"$": function (element) {
element.addEventListener('change', function () {
config.onUpdate(element, config);
});
}
}
]
);
return controlBody;
};
this.getValue = function (item, namespace) {
if(item.isNullable) {
var checkbox = document.getElementById(namespace + item.id + "IsNullable" );
var isNull = !checkbox.checked;
if(isNull) {
return null;
}
}
var element = document.getElementById(namespace + item.id);
return element.value;
};
};