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