1 | define([ |
---|
2 | "dojo/_base/declare", // declare |
---|
3 | "dojo/dom-class", // domClass.toggle |
---|
4 | "./CheckedMenuItem" |
---|
5 | ], function(declare, domClass, CheckedMenuItem){ |
---|
6 | |
---|
7 | // module: |
---|
8 | // dijit/RadioButtonMenuItem |
---|
9 | |
---|
10 | return declare("dijit.RadioButtonMenuItem", CheckedMenuItem, { |
---|
11 | // summary: |
---|
12 | // A radio-button-like menu item for toggling on and off |
---|
13 | |
---|
14 | // Use both base classes so we get styles like dijitMenuItemDisabled |
---|
15 | baseClass: "dijitMenuItem dijitRadioMenuItem", |
---|
16 | |
---|
17 | role: "menuitemradio", |
---|
18 | |
---|
19 | // checkedChar: String |
---|
20 | // Character (or string) used in place of radio button icon when display in high contrast mode |
---|
21 | checkedChar: "*", |
---|
22 | |
---|
23 | // group: String |
---|
24 | // Toggling on a RadioMenuItem in a given group toggles off the other RadioMenuItems in that group. |
---|
25 | group: "", |
---|
26 | |
---|
27 | // mapping from group name to checked widget within that group (or null if no widget is checked) |
---|
28 | _currentlyChecked: {}, |
---|
29 | |
---|
30 | _setCheckedAttr: function(/*Boolean*/ checked){ |
---|
31 | // summary: |
---|
32 | // Hook so attr('checked', bool) works. |
---|
33 | // Sets the class and state for the check box. |
---|
34 | |
---|
35 | if(checked && this.group && this._currentlyChecked[this.group] && this._currentlyChecked[this.group] != this){ |
---|
36 | // if another RadioMenuItem in my group is checked, uncheck it |
---|
37 | this._currentlyChecked[this.group].set("checked", false); |
---|
38 | } |
---|
39 | |
---|
40 | this.inherited(arguments); |
---|
41 | |
---|
42 | // set the currently checked widget to this, or null if we are clearing the currently checked widget |
---|
43 | if(this.group){ |
---|
44 | if(checked){ |
---|
45 | this._currentlyChecked[this.group] = this; |
---|
46 | }else if(this._currentlyChecked[this.group] == this){ |
---|
47 | this._currentlyChecked[this.group] = null; |
---|
48 | } |
---|
49 | } |
---|
50 | }, |
---|
51 | |
---|
52 | _onClick: function(evt){ |
---|
53 | // summary: |
---|
54 | // Clicking this item toggles it on. If it's already on, then clicking does nothing. |
---|
55 | // tags: |
---|
56 | // private |
---|
57 | |
---|
58 | if(!this.disabled && !this.checked){ |
---|
59 | this.set("checked", true); |
---|
60 | this.onChange(true); |
---|
61 | } |
---|
62 | this.onClick(evt); |
---|
63 | } |
---|
64 | }); |
---|
65 | }); |
---|