Debian Codegraph @

dijit/MenuItem.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare", // declare
3 "dojo/dom", // dom.setSelectable
4 "dojo/dom-attr", // domAttr.set
5 "dojo/dom-class", // domClass.toggle
6 "dojo/_base/kernel", // kernel.deprecated
7 "dojo/sniff", // has("ie")
8 "dojo/_base/lang", // lang.hitch
9 "./_Widget",
10 "./_TemplatedMixin",
11 "./_Contained",
12 "./_CssStateMixin",
13 "dojo/text!./templates/MenuItem.html"
14 ], function(declare, dom, domAttr, domClass, kernel, has, lang,
15 _Widget, _TemplatedMixin, _Contained, _CssStateMixin, template){
16
17 // module:
18 // dijit/MenuItem
19
20 var MenuItem = declare("dijit.MenuItem" + (has("dojo-bidi") ? "_NoBidi" : ""),
21 [_Widget, _TemplatedMixin, _Contained, _CssStateMixin], {
22 // summary:
23 // A line item in a Menu Widget
24
25 // Make 3 columns
26 // icon, label, and expand arrow (BiDi-dependent) indicating sub-menu
27 templateString: template,
28
29 baseClass: "dijitMenuItem",
30
31 // label: String
32 // Menu text as HTML
33 label: "",
34 _setLabelAttr: function(val){
35 this._set("label", val);
36 var shortcutKey = "";
37 var text;
38 var ndx = val.search(/{\S}/);
39 if(ndx >= 0){
40 shortcutKey = val.charAt(ndx + 1);
41 var prefix = val.substr(0, ndx);
42 var suffix = val.substr(ndx + 3);
43 text = prefix + shortcutKey + suffix;
44 val = prefix + '<span class="dijitMenuItemShortcutKey">' + shortcutKey + '</span>' + suffix;
45 }else{
46 text = val;
47 }
48 this.domNode.setAttribute("aria-label", text + " " + this.accelKey);
49 this.containerNode.innerHTML = val;
50 this._set('shortcutKey', shortcutKey);
51 },
52
53 /*=====
54 // shortcutKey: [readonly] String
55 // Single character (underlined when the parent Menu is focused) used to navigate directly to this widget,
56 // also known as [a mnemonic](http://en.wikipedia.org/wiki/Mnemonics_(keyboard%29).
57 // This is denoted in the label by surrounding the single character with {}.
58 // For example, if label="{F}ile", then shortcutKey="F".
59 shortcutKey: "",
60 =====*/
61
62 // iconClass: String
63 // Class to apply to DOMNode to make it display an icon.
64 iconClass: "dijitNoIcon",
65 _setIconClassAttr: { node: "iconNode", type: "class" },
66
67 // accelKey: String
68 // Text for the accelerator (shortcut) key combination, a control, alt, etc. modified keystroke meant to
69 // execute the menu item regardless of where the focus is on the page.
70 //
71 // Note that although Menu can display accelerator keys, there is no infrastructure to actually catch and
72 // execute those accelerators.
73 accelKey: "",
74
75 // disabled: Boolean
76 // If true, the menu item is disabled.
77 // If false, the menu item is enabled.
78 disabled: false,
79
80 _fillContent: function(/*DomNode*/ source){
81 // If button label is specified as srcNodeRef.innerHTML rather than
82 // this.params.label, handle it here.
83 if(source && !("label" in this.params)){
84 this._set('label', source.innerHTML);
85 }
86 },
87
88 buildRendering: function(){
89 this.inherited(arguments);
90 var label = this.id + "_text";
91 domAttr.set(this.containerNode, "id", label); // only needed for backward compat
92 if(this.accelKeyNode){
93 domAttr.set(this.accelKeyNode, "id", this.id + "_accel"); // only needed for backward compat
94 }
95 dom.setSelectable(this.domNode, false);
96 },
97
98 onClick: function(/*Event*/){
99 // summary:
100 // User defined function to handle clicks
101 // tags:
102 // callback
103 },
104
105 focus: function(){
106 // summary:
107 // Focus on this MenuItem
108 try{
109 if(has("ie") == 8){
110 // needed for IE8 which won't scroll TR tags into view on focus yet calling scrollIntoView creates flicker (#10275)
111 this.containerNode.focus();
112 }
113 this.focusNode.focus();
114 }catch(e){
115 // this throws on IE (at least) in some scenarios
116 }
117 },
118
119 _setSelected: function(selected){
120 // summary:
121 // Indicate that this node is the currently selected one
122 // tags:
123 // private
124
125 domClass.toggle(this.domNode, "dijitMenuItemSelected", selected);
126 },
127
128 setLabel: function(/*String*/ content){
129 // summary:
130 // Deprecated. Use set('label', ...) instead.
131 // tags:
132 // deprecated
133 kernel.deprecated("dijit.MenuItem.setLabel() is deprecated. Use set('label', ...) instead.", "", "2.0");
134 this.set("label", content);
135 },
136
137 setDisabled: function(/*Boolean*/ disabled){
138 // summary:
139 // Deprecated. Use set('disabled', bool) instead.
140 // tags:
141 // deprecated
142 kernel.deprecated("dijit.Menu.setDisabled() is deprecated. Use set('disabled', bool) instead.", "", "2.0");
143 this.set('disabled', disabled);
144 },
145
146 _setDisabledAttr: function(/*Boolean*/ value){
147 // summary:
148 // Hook for attr('disabled', ...) to work.
149 // Enable or disable this menu item.
150
151 this.focusNode.setAttribute('aria-disabled', value ? 'true' : 'false');
152 this._set("disabled", value);
153 },
154
155 _setAccelKeyAttr: function(/*String*/ value){
156 // summary:
157 // Hook for attr('accelKey', ...) to work.
158 // Set accelKey on this menu item.
159
160 if(this.accelKeyNode){
161 this.accelKeyNode.style.display = value ? "" : "none";
162 this.accelKeyNode.innerHTML = value;
163 //have to use colSpan to make it work in IE
164 domAttr.set(this.containerNode, 'colSpan', value ? "1" : "2");
165 }
166 this._set("accelKey", value);
167 }
168 });
169
170 if(has("dojo-bidi")){
171 MenuItem = declare("dijit.MenuItem", MenuItem, {
172 _setLabelAttr: function(val){
173 this.inherited(arguments);
174 if(this.textDir === "auto"){
175 this.applyTextDir(this.textDirNode);
176 }
177 }
178 });
179 }
180
181 return MenuItem;
182 });