forked from dojo/dijit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadioMenuItem.js
73 lines (63 loc) · 2.01 KB
/
RadioMenuItem.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
63
64
65
66
67
68
69
70
71
72
73
define([
"dojo/_base/array", // array.forEach
"dojo/_base/declare", // declare
"dojo/dom-class", // domClass.toggle
"dojo/query!css2", // query
"./CheckedMenuItem",
"./registry" // registry.getEnclosingWidget
], function(array, declare, domClass, query, CheckedMenuItem, registry){
// module:
// dijit/RadioButtonMenuItem
return declare("dijit.RadioButtonMenuItem", CheckedMenuItem, {
// summary:
// A radio-button-like menu item for toggling on and off
// Use both base classes so we get styles like dijitMenuItemDisabled
baseClass: "dijitMenuItem dijitRadioMenuItem",
role: "menuitemradio",
// checkedChar: String
// Character (or string) used in place of radio button icon when display in high contrast mode
checkedChar: "*",
// group: String
// Toggling on a RadioMenuItem in a given group toggles off the other RadioMenuItems in that group.
group: "",
_setGroupAttr: "domNode", // needs to be set as an attribute so dojo/query can find it
_setCheckedAttr: function(/*Boolean*/ checked){
// If I am being checked then have to deselect currently checked items
this.inherited(arguments);
if(!this._created){
return;
}
if(checked && this.group){
array.forEach(this._getRelatedWidgets(), function(widget){
if(widget != this && widget.checked){
widget.set('checked', false);
}
}, this);
}
},
_onClick: function(evt){
// summary:
// Clicking this item toggles it on. If it's already on, then clicking does nothing.
// tags:
// private
if(!this.disabled && !this.checked){
this.set("checked", true);
this.onChange(true);
}
this.onClick(evt);
},
_getRelatedWidgets: function(){
// Private function needed to help iterate over all radio menu items in a group.
var ary = [];
query("[group=" + this.group + "][role=" + this.role + "]").forEach(
function(menuItemNode){
var widget = registry.getEnclosingWidget(menuItemNode);
if(widget){
ary.push(widget);
}
}
);
return ary;
}
});
});