Debian Codegraph @

dojox/mvc/tests/WidgetList_tests/test_mvc_Menu.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4
5 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
6
7 <title>Menu System Test</title>
8
9 <style type="text/css">
10 @import "../../../../dijit/themes/claro/document.css";
11 @import "../../../../dijit/tests/css/dijitTests.css";
12
13 body { padding: 0; }
14
15 /* styling for left-hand-side navigation menu to become a column equal to length of page */
16 #formattingTable {
17 border: 0;
18 border-spacing: 0;
19 }
20 #contentContainer { padding: 2em; }
21
22 #navMenu {
23 /* make the sidebar menu blend in with the whole sidebar */
24 border: none;
25 }
26 </style>
27
28 <!-- required: a default dijit theme: -->
29 <link id="themeStyles" rel="stylesheet" href="../../../../dijit/themes/claro/claro.css"/>
30
31 <!-- required: dojo.js -->
32 <script type="text/javascript" src="../../../../dojo/dojo.js"
33 data-dojo-config="parseOnLoad: 0, isDebug: 1, async: 1, mvc: {debugBindings: 1}"></script>
34
35 <!-- not needed, for testing alternate themes -->
36 <script type="text/javascript" src="../../../../dijit/tests/_testCommon.js"></script>
37
38 <script type="text/javascript">
39 require([
40 "dojo/_base/declare",
41 "dojo/_base/lang",
42 "dojo/aspect",
43 "dojo/dom",
44 "dojo/parser", // scan page for widgets and instantiate them
45 "dojo/when",
46 "dojox/mvc/at",
47 "dijit/Menu",
48 "dijit/MenuItem",
49 "dijit/PopupMenuItem",
50 "dijit/PopupMenuBarItem",
51 "dijit/CheckedMenuItem",
52 "dijit/MenuSeparator",
53 "dojox/mvc/getStateful",
54 "dojox/mvc/WidgetList",
55 "dijit/MenuBar",
56 "dijit/MenuBarItem",
57 "dijit/ColorPalette",
58 "dijit/form/TextBox",
59 "dijit/dijit", // optimize: load dijit layer
60 "dojo/domReady!"
61 ], function(declare, lang, aspect, dom, parser, when, at, Menu, MenuItem, PopupMenuItem, PopupMenuBarItem, CheckedMenuItem, MenuSeparator, getStateful, WidgetList){
62 var mixin = declare(null, {
63 _getPropertiesAttr: function(){
64 var list = this.inherited(arguments);
65 return ["children", "popupType"].concat(list);
66 },
67
68 startup: function(){
69 this.popup = new Menu(); // Stop PopupMenuItem.startup() from attempting to find popup from DOM
70 this.inherited(arguments);
71 this.popup.destroy();
72 this.popup = null;
73 if(this.popupType){
74 this.popup = new (lang.getObject(this.popupType) || require(this.popupType))(this.params);
75 }else if(this.children){
76 this.popup = new (declare([Menu, WidgetList], {childType: getChildMenuType, childParams: getChildMenuParams}))(this.params);
77 }
78 if(this.popupType || this.children){
79 this.ownerDocumentBody.appendChild(this.popup.domNode);
80 this.popup.startup();
81 this.popup.domNode.style.display = "none";
82 }
83 }
84 });
85
86 declare("dojox.mvc.tests.PopupMenuItem", [PopupMenuItem, mixin]);
87 declare("dojox.mvc.tests.PopupMenuBarItem", [PopupMenuBarItem, mixin]);
88
89 getChildMenuType = function(parent){
90 return this.children || this.popupType ? (parent._isMenuBar ? "dojox.mvc.tests.PopupMenuBarItem" : "dojox.mvc.tests.PopupMenuItem") :
91 this.isSeparator ? "dijit/MenuSeparator" :
92 this.checked !== void 0 ? "dijit/CheckedMenuItem" :
93 parent._isMenuBar ? "dijit/MenuBarItem" :
94 "dijit/MenuItem";
95 };
96
97 getChildMenuParams = function(){
98 return {"*": at(this.target, "*")};
99 };
100
101 updateButtons = function(created){
102 dom.byId("prog_menu").innerHTML = created ? "This div has a programmatic context menu on it that's different to the page menu." : "No programmatic menu on this div, should get page level menu.";
103 dom.byId("createButton").disabled = created;
104 dom.byId("destroyButton").disabled = !created;
105 };
106
107 var separatorItem = {isSeparator: true},
108 disabledItem = {label: "Disabled Item", disabled: true, onClick: function(){ alert("this should NOT appear"); }},
109 differentPopupItem = {label: "Different popup", popupType: "dijit/ColorPalette"},
110 enabledSubmenuItem = {
111 label: "{E}nabled Submenu",
112 children: [
113 {label: "Submenu Item One", onClick: function(){ console.log("Submenu 1!") }},
114 {label: "Submenu Item Two", onClick: function(){ console.log("Submenu 2!") }},
115 {label: "Deeper Submenu", children: [
116 {label: "Sub-sub-menu Item One", onClick: function(){ console.log("Sub-submenu 1!") }},
117 {label: "Sub-sub-menu Item Two", onClick: function(){ console.log("Sub-submenu 2!") }}
118 ]}
119 ]
120 }, disabledSubmenuItem = {
121 label: "Disabled Submenu",
122 disabled: true,
123 children: [
124 {label: "Submenu Item One", onClick: function(){ console.log("Submenu 1!") }},
125 {label: "Submenu Item Two", onClick: function(){ console.log("Submenu 2!") }}
126 ]
127 }, checkedMenuItems = [
128 {label: "Checked", checked: true, onChange: function(val){ console.log("Now set to " + val); }},
129 {label: "Not Checked", checked: false},
130 {label: "Checked Disabled", checked: true, disabled: true}
131 ], editMenuItems = [
132 {label: "C{u}t", iconClass: "dijitEditorIcon dijitEditorIconCut", onClick: function(){ console.log("not actually cutting anything, just a test!") }, accelKey: "Ctrl+X"},
133 {label: "{C}opy", iconClass: "dijitEditorIcon dijitEditorIconCopy", onClick: function(){ console.log("not actually copying anything, just a test!") }, accelKey: "Ctrl+C"},
134 {label: "{P}aste", iconClass: "dijitEditorIcon dijitEditorIconPaste", onClick: function(){ console.log("not actually pasting anything, just a test!") }, accelKey: "Ctrl+V"}
135 ];
136
137 menubarData = getStateful([
138 {
139 label: "{F}ile",
140 accessKey: "F",
141 children: [
142 {label: "{N}ew"},
143 {label: "{O}pen"},
144 separatorItem,
145 {label: "{S}ave", iconClass:"dijitEditorIconSave"},
146 {label: "Save {A}s..."}
147 ]
148 },
149 {
150 label: "{E}dit",
151 accessKey: "E",
152 children: editMenuItems
153 },
154 {
155 label: "{V}iew",
156 accessKey: "V",
157 children: [
158 {label: "Normal"},
159 {label: "Outline"},
160 {
161 label: "{Z}oom",
162 children: [
163 {label: "50%"},
164 {label: "75%"},
165 {label: "100%"},
166 {label: "150%"},
167 {label: "200%"}
168 ]
169 }
170 ]
171 },
172 {
173 label: "{H}elp",
174 accessKey: "H",
175 children: [
176 {label: "Help Topics"},
177 {label: "About dojox/mvc"}
178 ]
179 },
180 {label: "{D}isabled", accessKey: "D", disabled: true, children: [{label: "You should not see this"}]},
181 {label: "E{m}pty", accessKey: "M", children: []},
182 {label: "Click me! ({Z})", accessKey: "Z", onClick: function(){ console.log("no submenu, just a clickable MenuItem"); }}
183 ]);
184
185 windowContextMenuData = getStateful([
186 {label: "Context Menu", onClick: function(){ console.log("Hello world"); }},
187 separatorItem,
188 disabledItem
189 ].concat(editMenuItems).concat([
190 separatorItem,
191 enabledSubmenuItem,
192 disabledSubmenuItem,
193 differentPopupItem,
194 separatorItem
195 ]).concat(checkedMenuItems).concat([
196 separatorItem,
197 {label: "Bigger Submenu", children: [
198 {label: "Item One"},
199 {label: "Item Two"},
200 {label: "Item Three"},
201 {label: "Item Four"},
202 {label: "Item Five"},
203 {label: "Item Six"},
204 {label: "Item Seven"},
205 {label: "Item Eight"},
206 {label: "Item Nine"},
207 {label: "Item Ten"}
208 ]}
209 ]));
210
211 leftClickContextMenuData = getStateful([
212 {label: "Left Click Menu", disabled: true},
213 {label: "Enabled Item", onClick: function(){ console.log("Hello world"); }},
214 disabledItem,
215 separatorItem
216 ].concat(editMenuItems).concat([
217 separatorItem,
218 enabledSubmenuItem,
219 disabledSubmenuItem,
220 differentPopupItem
221 ]));
222
223 navMenuData = getStateful([
224 {label: "Drama", iconClass: "dijitEditorIcon dijitEditorIconPaste", onClick: function(){ console.log("drama!"); }},
225 {label: "Cut", iconClass: "dijitEditorIcon dijitEditorIconCut", onClick: function(){ console.log("not actually cutting anything, just a test!") }},
226 {label: "Copy", iconClass: "dijitEditorIcon dijitEditorIconCopy", onClick: function(){ console.log("not actually copying anything, just a test!") }},
227 {label: "Paste", iconClass: "dijitEditorIcon dijitEditorIconPaste", onClick: function(){ console.log("not actually pasting anything, just a test!") }},
228 separatorItem,
229 enabledSubmenuItem,
230 disabledSubmenuItem,
231 differentPopupItem,
232 separatorItem
233 ].concat(checkedMenuItems));
234
235 createMenu = function(){
236 // create a menu programmatically
237 function fClick(){console.log("clicked!")}
238
239 pMenu = new (declare([Menu, WidgetList], {
240 childType: getChildMenuType,
241 childParams: getChildMenuParams
242 }))({
243 targetNodeIds: ["prog_menu"],
244 id: "progMenu",
245 children: getStateful([
246 {label: "Programmatic Context Menu", disabled: true},
247 separatorItem,
248 {label: "Simple menu item", onClick: fClick, accelKey: "Shift+S"},
249 {label: "Another menu item", onClick: fClick, accelKey: "Ctrl+A"},
250 {label: "With an icon", iconClass: "dijitEditorIcon dijitEditorIconCut", onClick: fClick},
251 {label: "dojo/aspect clicking", accelKey: "Alt+D"},
252 {label: "checkable menu item", checked: false},
253 enabledSubmenuItem
254 ])
255 });
256 pMenu.startup();
257
258 aspect.after(pMenu.getChildren()[5], "onClick", function(){ console.log("click! handler created via dojo/aspect" )});
259
260 updateButtons(true);
261
262 dom.byId("prog_menu").innerHTML="This div has a programmatic context menu on it that's different to the page menu.";
263
264 dom.byId("createButton").disabled = true;
265 dom.byId("destroyButton").disabled = false;
266 };
267
268 destroyMenu = function(){
269 pMenu.destroyRecursive();
270 updateButtons(false);
271 };
272
273 when(parser.parse(), function(){
274 // need to explicitly update our buttons states, otherwise the
275 // browser will remember the last states of them before reloading
276 // (so a programmatic menu is created, reload, and "the create
277 // programmatic menu" button is still in disabled state)
278 updateButtons(false);
279 });
280 });
281 </script>
282 </head>
283 <body class="claro" role="main">
284 <div id="windowContextMenu"
285 data-dojo-type="dijit/Menu"
286 data-dojo-mixins="dojox/mvc/WidgetList"
287 data-dojo-props='contextMenuForWindow: true, style: "display: none;", children: windowContextMenuData, childType: getChildMenuType, childParams: getChildMenuParams'>
288 </div>
289
290 <div id="leftClickContextMenu"
291 data-dojo-type="dijit/Menu"
292 data-dojo-mixins="dojox/mvc/WidgetList"
293 data-dojo-props='leftClickToOpen: true, targetNodeIds: ["input2"], style: "display: none;", children: leftClickContextMenuData, childType: getChildMenuType, childParams: getChildMenuParams'>
294 </div>
295
296 <table id="formattingTable" role="presentation">
297 <tr>
298 <td style="width:0;">
299 <!-- This is here for tabIndex testing.
300 Use textarea since Chrome 1.0 likes it better for TABing and
301 because it has innerText property and because it doesn't mess
302 with the URL when clicked -->
303 <textarea aria-label="random link" id="link" tabIndex="0" readOnly class="dijitReset" style="font-family:monospace;font-size:12px;width:84px;text-decoration:underline;overflow:hidden;background-color:transparent;" rows=1>random link</textarea>
304 </td>
305 <td id="menuBarContainer" style="width:100%;">
306 <div id="menubar"
307 data-dojo-type="dijit/MenuBar"
308 data-dojo-mixins="dojox/mvc/WidgetList"
309 data-dojo-props="children: menubarData, childType: getChildMenuType, childParams: getChildMenuParams">
310 </div>
311 </td>
312 </tr>
313 <tr>
314 <td id="navMenuContainer" class="dijitMenu" style="vertical-align:top; width:0;">
315 <h3 style="margin-bottom: 2em;">Navigation menu:</h3>
316 <div id="navMenu" aria-label="navigation"
317 data-dojo-type="dijit/Menu"
318 data-dojo-mixins="dojox/mvc/WidgetList"
319 data-dojo-props="children: navMenuData, childType: getChildMenuType, childParams: getChildMenuParams">
320 </div>
321 </td>
322
323 <td style="padding: 1em" id="contentContainer">
324
325 <h1 class="testTitle">Dijit Menu System Test</h1>
326
327 <p>This page contains:</p>
328 <ul>
329 <li>"Navigation bar" Menu widget on left, a.k.a vertical MenuBar
330 <li>MenuBar on top
331 <li>page level context menu (right-click anywhere on page)
332 <li>form widget context menu (right-click on textbox widget)</li>
333 <li>left click context menu (left click on input on far right)
334 <li>Example of programatically created menu
335 <li>Note: while some accelerator (shortcut) keys are displayed in the context menu, they are not actually hooked up to the corresponding actions (if any), they need to be setup explicitly by the user
336 </ul>
337
338 <h3>Form</h3>
339
340 <form>
341 <p style="float:right; text-align: right;">
342 left click to open the menu for this input:<br/>
343 Note: because of the window contextMenu, make sure you get<br/>
344 the right menu by verifying the left<br/>
345 click one starts with "Left Click Menu"<br/>
346 at the very top.
347 <input aria-label="input2" id=input2 value="top-right"/>
348 </p>
349 <input aria-label="input1" id=input1 value="top-left"/>
350 <textarea aria-label="textara" id=textarea>hello there!</textarea><br>
351 <select aria-label="select">
352 <option>check if i</option>
353 <option>bleed through</option>
354 <option>on IE6</option>
355 </select>
356 <button id=button>push me</button><br>
357 <input data-dojo-type="dijit/form/TextBox" aria-label="focus test" id="formwidget" data-dojo-props='style:"width:25em;", value:"dijit.form._FormWidget focus test"'/>
358 </form>
359
360 <div id="prog_menu" style="clear: both; border:1px solid blue; padding:10px; margin:20px 0;">
361 Click button below to create special menu on this div.
362 </div>
363 <button id="createButton" onclick="createMenu();">create programmatic menu</button>
364 <button id="destroyButton" onclick="destroyMenu();" disabled>destroy programmatic menu</button>
365
366 <div style="height:500px"></div>
367 <p>(this space intentionally left blank to aid testing with controls
368 at the bottom of the browser window)</p>
369 <div style="height:500px"></div>
370 <input id=input3 aria-label="input3" value="bottom-left"/>
371 <p style="text-align:right"><input aria-label="input4" id=input4 value="bottom-right"/></p>
372
373 <p>See also: <a href="form/test_Button.html">form/test_Button</a>
374 (PopupMenu is used with DropDownButton and ComboButton)</p>
375
376 <h3>Mouse opening tests</h3>
377
378 <ul>
379 <li>Right click on the client area of the page (ctrl-click for Macintosh). Menu should open.</li>
380 <li>Right click on each of the form controls above. Menu should open.</li>
381 <li>Right click near the right hand window border. Menu should open to the left of the pointer.</li>
382 <li>Right click near the bottom window border. Menu should open above the pointer.</li>
383 </ul>
384
385
386 <h3>Mouse hover tests</h3>
387
388 <ul>
389 <li>Hover over the first item with the pointer. Item should highlight and get focus.</li>
390 <li>Hover over the second (disabled) item. Item should highlight and get focus.</li>
391 <li>Separator items should not highlight on hover - no items should highlight in this case.</li>
392 </ul>
393
394
395 <h3>Mouse click tests</h3>
396
397 <ul>
398 <li>Click on the first menu item. console.log should log the message "Hello world". The menu should dissapear.</li>
399 <li>Click on the second menu item (disabled). Should not do anything - focus should remain on the disabled item.</li>
400 <li>Click anywhere outside the menu. Menu should close. Focus will be set by the browser based on where the user clicks.</li>
401 </ul>
402
403
404 <h3>Mouse submenu tests</h3>
405
406 <ul>
407 <li>Hover over the "Enabled Submenu" item. Item should highlight and then pop open a submenu after a short (500ms) delay.</li>
408 <li>Hover over any of the other menu items. Submenu should close immediately and deselect the submenu parent item. The newly hovered item should become selected.</li>
409 <li>Hover over the "Disabled Submenu" item. Item should highlight, but no submenu should appear.</li>
410 <li>Clicking on the "Enabled Submenu" item before the submenu has opened (you'll have to be quick!) should immediatley open the submenu.</li>
411 <li>Clicking on the "Enabled Submenu" item <i>after</i> the submenu has opened should have no effect - the item is still selected and the submenu still open.</li>
412 <li>Hover over submenu item 1. Should select it - the parent menu item should stay selected also.</li>
413 <li>Hover over submenu item 2. Should select it - the parent menu item should stay selected also.</li>
414 </ul>
415
416
417 <h3>Keyboard opening tests</h3>
418
419 <ul>
420 <li>On Windows: press shift-f10 with focus on any of the form controls. Should open the menu.</li>
421 <li>On Windows: press the context menu key (located on the right of the space bar on North American keyboards) with focus on any of the form controls. Should open the menu.</li>
422 <li>On Firefox on the Mac: press ctrl-space with focus on any of the form controls. Should open the menu.</li>
423 </ul>
424
425
426 <h3>Keyboard closing tests</h3>
427
428 <ul>
429 <li>Open the menu.</li>
430 <li>Press tab. Should close the menu and return focus to where it was before the menu was opened.</li>
431 <li>Open the menu.</li>
432 <li>Press escape. Should close the menu and return focus to where it was before the menu was opened.</li>
433 </ul>
434
435
436 <h3>Keyboard navigation tests</h3>
437
438 <ul>
439 <li>Open the menu.</li>
440 <li>Pressing up or down arrow should cycle focus through the items in that menu.</li>
441 <li>Pressing enter or space should invoke the menu item.</li>
442 <li>Disabled items receive focus but no action is taken upon pressing enter or space.</li>
443 </ul>
444
445
446 <h3>Keyboard submenu tests</h3>
447
448 <ul>
449 <li>Open the menu.</li>
450 <li>The first item should become selected.</li>
451 <li>Press the right arrow key. Nothing should happen.</li>
452 <li>Press the left arrow key. Nothing should happen.</li>
453 <li>Press the down arrow until "Enabled Submenu" is selected. The submenu should not appear.</li>
454 <li>Press enter. The submenu should appear with the first item selected.</li>
455 <li>Press escape. The submenu should vanish - "Enabled Submenu" should remain selected.</li>
456 <li>Press the right arrow key. The submenu should appear with the first item selected.</li>
457 <li>Press the right arrow key. Nothing should happen.</li>
458 <li>Press the left arrow key. The submenu should close - "Enabled Submenu" should remain selected.</li>
459 <li>Press the left arrow key. The menu should <i>not</i> close and "Enabled Submenu" should remain selected.</li>
460 <li>Press escape. The menu should close and focus should be returned to where it was before the menu was opened.</li>
461 </ul>
462 </td>
463 </tr>
464 </table>
465 </body>
466 </html>