-
Notifications
You must be signed in to change notification settings - Fork 36
/
Toggle.js
58 lines (51 loc) · 1.17 KB
/
Toggle.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
/** @module deliteful/Toggle */
define([
"dcl/dcl",
"delite/CssState"
], function (dcl, CssState) {
/**
* A base class for 2-state form widgets.
* @class module:deliteful/Toggle
* @abstract
* @augments module:delite/CssState
*/
return dcl(CssState, /** @lends module:deliteful/Toggle# */ {
/**
* Indicates whether this widget is checked.
* @member {boolean}
* @default false
*/
checked: false,
/**
* The widget value that is sent to forms.
* @member {string}
* @default "on"
*/
value: "on",
connectedCallback: function () {
this._initState = this.checked;
},
afterFormResetCallback: function () {
this.checked = this._initState;
},
afterInitializeRendering: function () {
// CssState does not handle focused property any more
this.on("focus", function () {
this.addClass("d-focused");
}.bind(this), this.focusNode);
this.on("blur", function () {
this.removeClass("d-focused");
}.bind(this), this.focusNode);
},
/**
* Toggles the state of this widget.
* @method
*/
toggle: function () {
if (!this.disabled) {
this.checked = !this.checked;
this.emit("change");
}
}
});
});