-
Notifications
You must be signed in to change notification settings - Fork 36
/
Checkbox.js
62 lines (54 loc) · 1.69 KB
/
Checkbox.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
/** @module deliteful/Checkbox */
define([
"dcl/dcl",
"delite/register",
"delite/FormWidget",
"./Toggle",
"delite/handlebars!./Checkbox/Checkbox.html",
"requirejs-dplugins/css!./Checkbox/Checkbox.css"
], function (dcl, register, FormWidget, Toggle, template) {
/**
* A 2-state checkbox widget similar to an HTML5 input type="checkbox" element.
* @example
* <d-checkbox checked="true"></d-checkbox>
* @class module:deliteful/Checkbox
* @augments module:delite/FormWidget
* @augments module:deliteful/Toggle
*/
return register("d-checkbox", [HTMLElement, FormWidget, Toggle], /** @lends module:deliteful/Checkbox# */ {
/**
* The component css base class.
* @member {string}
* @default "d-checkbox"
*/
baseClass: "d-checkbox",
/**
* If true, then the checkbox displays as indeterminate. Doesn't affect the `checked` property's
* value though.
*/
indeterminate: false,
template: template,
afterInitializeRendering: function () {
this._lbl4 = null;
this.on("click", this._inputClickHandler.bind(this), this.focusNode);
this.on("change", this._inputClickHandler.bind(this), this.focusNode);
},
refreshRendering: function (oldVals) {
// Since d-checked is set programatically, let's set d-indeterminate programatically too.
if ("indeterminate" in oldVals) {
if (this.indeterminate) {
this.classList.add("d-indeterminate");
} else {
this.classList.remove("d-indeterminate");
}
}
},
_inputClickHandler: function (evt) {
this.indeterminate = false;
this.checked = this.focusNode.checked;
// Emit event from my root node rather than from the embedded <input>
evt.stopPropagation();
this.emit(evt.type);
}
});
});