]>
Commit | Line | Data |
---|---|---|
f0cfe83e AD |
1 | define("dijit/form/_ToggleButtonMixin", [ |
2 | "dojo/_base/declare", // declare | |
3 | "dojo/dom-attr" // domAttr.set | |
4 | ], function(declare, domAttr){ | |
5 | ||
6 | // module: | |
7 | // dijit/form/_ToggleButtonMixin | |
8 | ||
9 | return declare("dijit.form._ToggleButtonMixin", null, { | |
10 | // summary: | |
11 | // A mixin to provide functionality to allow a button that can be in two states (checked or not). | |
12 | ||
13 | // checked: Boolean | |
14 | // Corresponds to the native HTML `<input>` element's attribute. | |
15 | // In markup, specified as "checked='checked'" or just "checked". | |
16 | // True if the button is depressed, or the checkbox is checked, | |
17 | // or the radio button is selected, etc. | |
18 | checked: false, | |
19 | ||
20 | // aria-pressed for toggle buttons, and aria-checked for checkboxes | |
21 | _aria_attr: "aria-pressed", | |
22 | ||
23 | _onClick: function(/*Event*/ evt){ | |
24 | var original = this.checked; | |
25 | this._set('checked', !original); // partially set the toggled value, assuming the toggle will work, so it can be overridden in the onclick handler | |
26 | var ret = this.inherited(arguments); // the user could reset the value here | |
27 | this.set('checked', ret ? this.checked : original); // officially set the toggled or user value, or reset it back | |
28 | return ret; | |
29 | }, | |
30 | ||
31 | _setCheckedAttr: function(/*Boolean*/ value, /*Boolean?*/ priorityChange){ | |
32 | this._set("checked", value); | |
33 | var node = this.focusNode || this.domNode; | |
34 | domAttr.set(node, "checked", !!value); // "mixed" -> true | |
35 | if(value){ | |
36 | node.setAttribute("checked", ""); | |
37 | }else{ | |
38 | node.removeAttribute("checked"); | |
39 | } | |
40 | node.setAttribute(this._aria_attr, String(value)); // aria values should be strings | |
41 | this._handleOnChange(value, priorityChange); | |
42 | }, | |
43 | ||
44 | reset: function(){ | |
45 | // summary: | |
46 | // Reset the widget's value to what it was at initialization time | |
47 | ||
48 | this._hasBeenBlurred = false; | |
49 | ||
50 | // set checked state to original setting | |
51 | this.set('checked', this.params.checked || false); | |
52 | } | |
53 | }); | |
54 | ||
55 | }); |