Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('node-menunav', function (Y, NAME) {
2
 
3
/**
4
* <p>The MenuNav Node Plugin makes it easy to transform existing list-based
5
* markup into traditional, drop down navigational menus that are both accessible
6
* and easy to customize, and only require a small set of dependencies.</p>
7
*
8
*
9
* <p>To use the MenuNav Node Plugin, simply pass a reference to the plugin to a
10
* Node instance's <code>plug</code> method.</p>
11
*
12
* <p>
13
* <code>
14
* &#60;script type="text/javascript"&#62; <br>
15
* <br>
16
* 		//	Call the "use" method, passing in "node-menunav".  This will <br>
17
* 		//	load the script and CSS for the MenuNav Node Plugin and all of <br>
18
* 		//	the required dependencies. <br>
19
* <br>
20
* 		YUI().use("node-menunav", function(Y) { <br>
21
* <br>
22
* 			//	Use the "contentready" event to initialize the menu when <br>
23
* 			//	the subtree of element representing the root menu <br>
24
* 			//	(&#60;div id="menu-1"&#62;) is ready to be scripted. <br>
25
* <br>
26
* 			Y.on("contentready", function () { <br>
27
* <br>
28
* 				//	The scope of the callback will be a Node instance <br>
29
* 				//	representing the root menu (&#60;div id="menu-1"&#62;). <br>
30
* 				//	Therefore, since "this" represents a Node instance, it <br>
31
* 				//	is possible to just call "this.plug" passing in a <br>
32
*				//	reference to the MenuNav Node Plugin. <br>
33
* <br>
34
* 				this.plug(Y.Plugin.NodeMenuNav); <br>
35
* <br>
36
* 			}, "#menu-1"); <br>
37
* <br>
38
* 		}); <br>
39
* <br>
40
* 	&#60;/script&#62; <br>
41
* </code>
42
* </p>
43
*
44
* <p>The MenuNav Node Plugin has several configuration properties that can be
45
* set via an object literal that is passed as a second argument to a Node
46
* instance's <code>plug</code> method.
47
* </p>
48
*
49
* <p>
50
* <code>
51
* &#60;script type="text/javascript"&#62; <br>
52
* <br>
53
* 		//	Call the "use" method, passing in "node-menunav".  This will <br>
54
* 		//	load the script and CSS for the MenuNav Node Plugin and all of <br>
55
* 		//	the required dependencies. <br>
56
* <br>
57
* 		YUI().use("node-menunav", function(Y) { <br>
58
* <br>
59
* 			//	Use the "contentready" event to initialize the menu when <br>
60
* 			//	the subtree of element representing the root menu <br>
61
* 			//	(&#60;div id="menu-1"&#62;) is ready to be scripted. <br>
62
* <br>
63
* 			Y.on("contentready", function () { <br>
64
* <br>
65
* 				//	The scope of the callback will be a Node instance <br>
66
* 				//	representing the root menu (&#60;div id="menu-1"&#62;). <br>
67
* 				//	Therefore, since "this" represents a Node instance, it <br>
68
* 				//	is possible to just call "this.plug" passing in a <br>
69
*				//	reference to the MenuNav Node Plugin. <br>
70
* <br>
71
* 				this.plug(Y.Plugin.NodeMenuNav, { mouseOutHideDelay: 1000 });
72
* <br><br>
73
* 			}, "#menu-1"); <br>
74
* <br>
75
* 		}); <br>
76
* <br>
77
* 	&#60;/script&#62; <br>
78
* </code>
79
* </p>
80
*
81
DEPRECATED. The MenuNav Node Plugin has been deprecated as of YUI 3.9.0. This module will be removed from the library in a future version. If you require functionality similar to the one provided by this module, consider taking a look at the various modules in the YUI Gallery <http://yuilibrary.com/gallery/>.
82
 
83
@module node-menunav
84
@deprecated 3.9.0
85
*/
86
 
87
 
88
	//	Util shortcuts
89
 
90
var UA = Y.UA,
91
	later = Y.later,
92
	getClassName = Y.ClassNameManager.getClassName,
93
 
94
 
95
 
96
	//	Frequently used strings
97
 
98
	MENU = "menu",
99
	MENUITEM = "menuitem",
100
	HIDDEN = "hidden",
101
	PARENT_NODE = "parentNode",
102
	CHILDREN = "children",
103
	OFFSET_HEIGHT = "offsetHeight",
104
	OFFSET_WIDTH = "offsetWidth",
105
	PX = "px",
106
	ID = "id",
107
	PERIOD = ".",
108
	HANDLED_MOUSEOUT = "handledMouseOut",
109
	HANDLED_MOUSEOVER = "handledMouseOver",
110
	ACTIVE = "active",
111
	LABEL = "label",
112
	LOWERCASE_A = "a",
113
	MOUSEDOWN = "mousedown",
114
	KEYDOWN = "keydown",
115
	CLICK = "click",
116
	EMPTY_STRING = "",
117
	FIRST_OF_TYPE = "first-of-type",
118
	ROLE = "role",
119
	PRESENTATION = "presentation",
120
	DESCENDANTS = "descendants",
121
	UI = "UI",
122
	ACTIVE_DESCENDANT = "activeDescendant",
123
	USE_ARIA = "useARIA",
124
	ARIA_HIDDEN = "aria-hidden",
125
	CONTENT = "content",
126
	HOST = "host",
127
	ACTIVE_DESCENDANT_CHANGE = ACTIVE_DESCENDANT + "Change",
128
 
129
 
130
	//	Attribute keys
131
 
132
	AUTO_SUBMENU_DISPLAY = "autoSubmenuDisplay",
133
	MOUSEOUT_HIDE_DELAY = "mouseOutHideDelay",
134
 
135
 
136
	//	CSS class names
137
 
138
	CSS_MENU = getClassName(MENU),
139
	CSS_MENU_HIDDEN = getClassName(MENU, HIDDEN),
140
	CSS_MENU_HORIZONTAL = getClassName(MENU, "horizontal"),
141
	CSS_MENU_LABEL = getClassName(MENU, LABEL),
142
	CSS_MENU_LABEL_ACTIVE = getClassName(MENU, LABEL, ACTIVE),
143
	CSS_MENU_LABEL_MENUVISIBLE = getClassName(MENU, LABEL, (MENU + "visible")),
144
	CSS_MENUITEM = getClassName(MENUITEM),
145
	CSS_MENUITEM_ACTIVE = getClassName(MENUITEM, ACTIVE),
146
 
147
 
148
	//	CSS selectors
149
 
150
	MENU_SELECTOR = PERIOD + CSS_MENU,
151
	MENU_TOGGLE_SELECTOR = (PERIOD + getClassName(MENU, "toggle")),
152
    MENU_CONTENT_SELECTOR = PERIOD + getClassName(MENU, CONTENT),
153
    MENU_LABEL_SELECTOR = PERIOD + CSS_MENU_LABEL,
154
 
155
	STANDARD_QUERY = ">" + MENU_CONTENT_SELECTOR + ">ul>li>a",
156
	EXTENDED_QUERY = ">" + MENU_CONTENT_SELECTOR + ">ul>li>" + MENU_LABEL_SELECTOR + ">a:first-child";
157
 
158
//	Utility functions
159
 
160
 
161
var getPreviousSibling = function (node) {
162
 
163
	var oPrevious = node.previous(),
164
		oChildren;
165
 
166
	if (!oPrevious) {
167
		oChildren = node.get(PARENT_NODE).get(CHILDREN);
168
		oPrevious = oChildren.item(oChildren.size() - 1);
169
	}
170
 
171
 
172
	return oPrevious;
173
 
174
};
175
 
176
 
177
var getNextSibling = function (node) {
178
 
179
	var oNext = node.next();
180
 
181
	if (!oNext) {
182
		oNext = node.get(PARENT_NODE).get(CHILDREN).item(0);
183
	}
184
 
185
	return oNext;
186
 
187
};
188
 
189
 
190
var isAnchor = function (node) {
191
 
192
	var bReturnVal = false;
193
 
194
	if (node) {
195
		bReturnVal = node.get("nodeName").toLowerCase() === LOWERCASE_A;
196
	}
197
 
198
	return bReturnVal;
199
 
200
};
201
 
202
 
203
var isMenuItem = function (node) {
204
 
205
	return node.hasClass(CSS_MENUITEM);
206
 
207
};
208
 
209
 
210
var isMenuLabel = function (node) {
211
 
212
	return node.hasClass(CSS_MENU_LABEL);
213
 
214
};
215
 
216
 
217
var isHorizontalMenu = function (menu) {
218
 
219
	return menu.hasClass(CSS_MENU_HORIZONTAL);
220
 
221
};
222
 
223
 
224
var hasVisibleSubmenu = function (menuLabel) {
225
 
226
	return menuLabel.hasClass(CSS_MENU_LABEL_MENUVISIBLE);
227
 
228
};
229
 
230
 
231
var getItemAnchor = function (node) {
232
 
233
	return isAnchor(node) ? node : node.one(LOWERCASE_A);
234
 
235
};
236
 
237
 
238
var getNodeWithClass = function (node, className, searchAncestors) {
239
 
240
	var oItem;
241
 
242
	if (node) {
243
 
244
		if (node.hasClass(className)) {
245
			oItem = node;
246
		}
247
 
248
		if (!oItem && searchAncestors) {
249
			oItem = node.ancestor((PERIOD + className));
250
		}
251
 
252
	}
253
 
254
	return oItem;
255
 
256
};
257
 
258
 
259
var getParentMenu = function (node) {
260
 
261
	return node.ancestor(MENU_SELECTOR);
262
 
263
};
264
 
265
 
266
var getMenu = function (node, searchAncestors) {
267
 
268
	return getNodeWithClass(node, CSS_MENU, searchAncestors);
269
 
270
};
271
 
272
 
273
var getMenuItem = function (node, searchAncestors) {
274
 
275
	var oItem;
276
 
277
	if (node) {
278
		oItem = getNodeWithClass(node, CSS_MENUITEM, searchAncestors);
279
	}
280
 
281
	return oItem;
282
 
283
};
284
 
285
 
286
var getMenuLabel = function (node, searchAncestors) {
287
 
288
	var oItem;
289
 
290
	if (node) {
291
 
292
		if (searchAncestors) {
293
			oItem = getNodeWithClass(node, CSS_MENU_LABEL, searchAncestors);
294
		}
295
		else {
296
			oItem = getNodeWithClass(node, CSS_MENU_LABEL) ||
297
				node.one((PERIOD + CSS_MENU_LABEL));
298
		}
299
 
300
	}
301
 
302
	return oItem;
303
 
304
};
305
 
306
 
307
var getItem = function (node, searchAncestors) {
308
 
309
	var oItem;
310
 
311
	if (node) {
312
		oItem = getMenuItem(node, searchAncestors) ||
313
			getMenuLabel(node, searchAncestors);
314
	}
315
 
316
	return oItem;
317
 
318
};
319
 
320
 
321
var getFirstItem = function (menu) {
322
 
323
	return getItem(menu.one("li"));
324
 
325
};
326
 
327
 
328
var getActiveClass = function (node) {
329
 
330
	return isMenuItem(node) ? CSS_MENUITEM_ACTIVE : CSS_MENU_LABEL_ACTIVE;
331
 
332
};
333
 
334
 
335
var handleMouseOverForNode = function (node, target) {
336
 
337
	return node && !node[HANDLED_MOUSEOVER] &&
338
		(node.compareTo(target) || node.contains(target));
339
 
340
};
341
 
342
 
343
var handleMouseOutForNode = function (node, relatedTarget) {
344
 
345
	return node && !node[HANDLED_MOUSEOUT] &&
346
		(!node.compareTo(relatedTarget) && !node.contains(relatedTarget));
347
 
348
};
349
 
350
/**
351
* The NodeMenuNav class is a plugin for a Node instance.  The class is used via
352
* the <a href="Node.html#method_plug"><code>plug</code></a> method of Node and
353
* should not be instantiated directly.
354
* @namespace plugin
355
* @class NodeMenuNav
356
*/
357
var NodeMenuNav = function () {
358
 
359
	NodeMenuNav.superclass.constructor.apply(this, arguments);
360
 
361
};
362
 
363
NodeMenuNav.NAME = "nodeMenuNav";
364
NodeMenuNav.NS = "menuNav";
365
 
366
 
367
/**
368
* @property SHIM_TEMPLATE_TITLE
369
* @description String representing the value for the <code>title</code>
370
* attribute for the shim used to prevent <code>&#60;select&#62;</code> elements
371
* from poking through menus in IE 6.
372
* @default "Menu Stacking Shim"
373
* @type String
374
*/
375
NodeMenuNav.SHIM_TEMPLATE_TITLE = "Menu Stacking Shim";
376
 
377
 
378
/**
379
* @property SHIM_TEMPLATE
380
* @description String representing the HTML used to create the
381
* <code>&#60;iframe&#62;</code> shim used to prevent
382
* <code>&#60;select&#62;</code> elements from poking through menus in IE 6.
383
* @default &#34;&#60;iframe frameborder=&#34;0&#34; tabindex=&#34;-1&#34;
384
* class=&#34;yui-shim&#34; title=&#34;Menu Stacking Shim&#34;
385
* src=&#34;javascript:false;&#34;&#62;&#60;/iframe&#62;&#34;
386
* @type String
387
*/
388
 
389
//	<iframe> shim notes:
390
//
391
//	1) Need to set the "frameBorder" property to 0 to suppress the default
392
//	<iframe> border in IE.  (Setting the CSS "border" property alone doesn't
393
//	suppress it.)
394
//
395
//	2) The "src" attribute of the <iframe> is set to "javascript:false;" so
396
//	that it won't load a page inside it, preventing the secure/nonsecure
397
//	warning in IE when using HTTPS.
398
//
399
//	3) Since the role of the <iframe> shim is completely presentational, its
400
//	"tabindex" attribute is set to "-1" and its title attribute is set to
401
//	"Menu Stacking Shim".  Both strategies help users of screen readers to
402
//	avoid mistakenly interacting with the <iframe> shim.
403
 
404
NodeMenuNav.SHIM_TEMPLATE = '<iframe frameborder="0" tabindex="-1" class="' +
405
							getClassName("shim") +
406
							'" title="' + NodeMenuNav.SHIM_TEMPLATE_TITLE +
407
							'" src="javascript:false;"></iframe>';
408
 
409
 
410
NodeMenuNav.ATTRS = {
411
 
412
	/**
413
	* Boolean indicating if use of the WAI-ARIA Roles and States should be
414
	* enabled for the menu.
415
	*
416
	* @attribute useARIA
417
	* @readOnly
418
	* @writeOnce
419
	* @default true
420
	* @type boolean
421
	*/
422
	useARIA: {
423
 
424
		value: true,
425
		writeOnce: true,
426
		lazyAdd: false,
427
		setter: function (value) {
428
 
429
			var oMenu = this.get(HOST),
430
				oMenuLabel,
431
				oMenuToggle,
432
				oSubmenu,
433
				sID;
434
 
435
			if (value) {
436
 
437
				oMenu.set(ROLE, MENU);
438
 
439
				oMenu.all("ul,li," + MENU_CONTENT_SELECTOR).set(ROLE, PRESENTATION);
440
 
441
				oMenu.all((PERIOD + getClassName(MENUITEM, CONTENT))).set(ROLE, MENUITEM);
442
 
443
				oMenu.all((PERIOD + CSS_MENU_LABEL)).each(function (node) {
444
 
445
					oMenuLabel = node;
446
					oMenuToggle = node.one(MENU_TOGGLE_SELECTOR);
447
 
448
					if (oMenuToggle) {
449
						oMenuToggle.set(ROLE, PRESENTATION);
450
						oMenuLabel = oMenuToggle.previous();
451
					}
452
 
453
					oMenuLabel.set(ROLE, MENUITEM);
454
					oMenuLabel.set("aria-haspopup", true);
455
 
456
					oSubmenu = node.next();
457
 
458
					if (oSubmenu) {
459
 
460
						oSubmenu.set(ROLE, MENU);
461
 
462
						oMenuLabel = oSubmenu.previous();
463
						oMenuToggle = oMenuLabel.one(MENU_TOGGLE_SELECTOR);
464
 
465
						if (oMenuToggle) {
466
							oMenuLabel = oMenuToggle;
467
						}
468
 
469
						sID = Y.stamp(oMenuLabel);
470
 
471
						if (!oMenuLabel.get(ID)) {
472
							oMenuLabel.set(ID, sID);
473
						}
474
 
475
						oSubmenu.set("aria-labelledby", sID);
476
						oSubmenu.set(ARIA_HIDDEN, true);
477
 
478
					}
479
 
480
				});
481
 
482
			}
483
 
484
		}
485
 
486
	},
487
 
488
 
489
	/**
490
	* Boolean indicating if submenus are automatically made visible when the
491
	* user mouses over the menu's items.
492
	*
493
	* @attribute autoSubmenuDisplay
494
	* @readOnly
495
	* @writeOnce
496
	* @default true
497
	* @type boolean
498
	*/
499
	autoSubmenuDisplay: {
500
 
501
		value: true,
502
		writeOnce: true
503
 
504
	},
505
 
506
 
507
	/**
508
	* Number indicating the time (in milliseconds) that should expire before a
509
	* submenu is made visible when the user mouses over the menu's label.
510
	*
511
	* @attribute submenuShowDelay
512
	* @readOnly
513
	* @writeOnce
514
	* @default 250
515
	* @type Number
516
	*/
517
	submenuShowDelay: {
518
 
519
		value: 250,
520
		writeOnce: true
521
 
522
	},
523
 
524
 
525
	/**
526
	* Number indicating the time (in milliseconds) that should expire before a
527
	* submenu is hidden when the user mouses out of a menu label heading in the
528
	* direction of a submenu.
529
	*
530
	* @attribute submenuHideDelay
531
	* @readOnly
532
	* @writeOnce
533
	* @default 250
534
	* @type Number
535
	*/
536
	submenuHideDelay: {
537
 
538
		value: 250,
539
		writeOnce: true
540
 
541
	},
542
 
543
 
544
	/**
545
	* Number indicating the time (in milliseconds) that should expire before a
546
	* submenu is hidden when the user mouses out of it.
547
	*
548
	* @attribute mouseOutHideDelay
549
	* @readOnly
550
	* @writeOnce
551
	* @default 750
552
	* @type Number
553
	*/
554
	mouseOutHideDelay: {
555
 
556
		value: 750,
557
		writeOnce: true
558
 
559
	}
560
 
561
};
562
 
563
 
564
Y.extend(NodeMenuNav, Y.Plugin.Base, {
565
 
566
	//	Protected properties
567
 
568
	/**
569
	* @property _rootMenu
570
	* @description Node instance representing the root menu in the menu.
571
	* @default null
572
	* @protected
573
	* @type Node
574
	*/
575
	_rootMenu: null,
576
 
577
 
578
	/**
579
	* @property _activeItem
580
	* @description Node instance representing the menu's active descendent:
581
	* the menuitem or menu label the user is currently interacting with.
582
	* @default null
583
	* @protected
584
	* @type Node
585
	*/
586
	_activeItem: null,
587
 
588
 
589
	/**
590
	* @property _activeMenu
591
	* @description Node instance representing the menu that is the parent of
592
	* the menu's active descendent.
593
	* @default null
594
	* @protected
595
	* @type Node
596
	*/
597
	_activeMenu: null,
598
 
599
 
600
	/**
601
	* @property _hasFocus
602
	* @description Boolean indicating if the menu has focus.
603
	* @default false
604
	* @protected
605
	* @type Boolean
606
	*/
607
	_hasFocus: false,
608
 
609
 
610
	//	In gecko-based browsers a mouseover and mouseout event will fire even
611
	//	if a DOM element moves out from under the mouse without the user
612
	//	actually moving the mouse.  This bug affects NodeMenuNav because the
613
	//	user can hit the Esc key to hide a menu, and if the mouse is over the
614
	//	menu when the user presses Esc, the _onMenuMouseOut handler will be
615
	//	called.  To fix this bug the following flag (_blockMouseEvent) is used
616
	// to block the code in the _onMenuMouseOut handler from executing.
617
 
618
	/**
619
	* @property _blockMouseEvent
620
	* @description Boolean indicating whether or not to handle the
621
	* "mouseover" event.
622
	* @default false
623
	* @protected
624
	* @type Boolean
625
	*/
626
	_blockMouseEvent: false,
627
 
628
 
629
	/**
630
	* @property _currentMouseX
631
	* @description Number representing the current x coordinate of the mouse
632
	* inside the menu.
633
	* @default 0
634
	* @protected
635
	* @type Number
636
	*/
637
	_currentMouseX: 0,
638
 
639
 
640
	/**
641
	* @property _movingToSubmenu
642
	* @description Boolean indicating if the mouse is moving from a menu
643
	* label to its corresponding submenu.
644
	* @default false
645
	* @protected
646
	* @type Boolean
647
	*/
648
	_movingToSubmenu: false,
649
 
650
 
651
	/**
652
	* @property _showSubmenuTimer
653
	* @description Timer used to show a submenu.
654
	* @default null
655
	* @protected
656
	* @type Object
657
	*/
658
	_showSubmenuTimer: null,
659
 
660
 
661
	/**
662
	* @property _hideSubmenuTimer
663
	* @description Timer used to hide a submenu.
664
	* @default null
665
	* @protected
666
	* @type Object
667
	*/
668
	_hideSubmenuTimer: null,
669
 
670
 
671
	/**
672
	* @property _hideAllSubmenusTimer
673
	* @description Timer used to hide a all submenus.
674
	* @default null
675
	* @protected
676
	* @type Object
677
	*/
678
	_hideAllSubmenusTimer: null,
679
 
680
 
681
	/**
682
	* @property _firstItem
683
	* @description Node instance representing the first item (menuitem or menu
684
	* label) in the root menu of a menu.
685
	* @default null
686
	* @protected
687
	* @type Node
688
	*/
689
	_firstItem: null,
690
 
691
 
692
	//	Public methods
693
 
694
 
695
    initializer: function (config) {
696
 
697
		var menuNav = this,
698
			oRootMenu = this.get(HOST),
699
			aHandlers = [],
700
			oDoc;
701
 
702
		Y.log("WARNING: Node-MenuNav is a deprecated module as of YUI 3.9.0. This module will be removed from a later version of the library.", "warn");
703
 
704
		if (oRootMenu) {
705
 
706
			menuNav._rootMenu = oRootMenu;
707
 
708
			oRootMenu.all("ul:first-child").addClass(FIRST_OF_TYPE);
709
 
710
			//	Hide all visible submenus
711
 
712
			oRootMenu.all(MENU_SELECTOR).addClass(CSS_MENU_HIDDEN);
713
 
714
 
715
			//	Wire up all event handlers
716
 
717
			aHandlers.push(oRootMenu.on("mouseover", menuNav._onMouseOver, menuNav));
718
			aHandlers.push(oRootMenu.on("mouseout", menuNav._onMouseOut, menuNav));
719
			aHandlers.push(oRootMenu.on("mousemove", menuNav._onMouseMove, menuNav));
720
			aHandlers.push(oRootMenu.on(MOUSEDOWN, menuNav._toggleSubmenuDisplay, menuNav));
721
			aHandlers.push(Y.on("key", menuNav._toggleSubmenuDisplay, oRootMenu, "down:13", menuNav));
722
			aHandlers.push(oRootMenu.on(CLICK, menuNav._toggleSubmenuDisplay, menuNav));
723
			aHandlers.push(oRootMenu.on("keypress", menuNav._onKeyPress, menuNav));
724
			aHandlers.push(oRootMenu.on(KEYDOWN, menuNav._onKeyDown, menuNav));
725
 
726
			oDoc = oRootMenu.get("ownerDocument");
727
 
728
		    aHandlers.push(oDoc.on(MOUSEDOWN, menuNav._onDocMouseDown, menuNav));
729
			aHandlers.push(oDoc.on("focus", menuNav._onDocFocus, menuNav));
730
 
731
			this._eventHandlers = aHandlers;
732
 
733
			menuNav._initFocusManager();
734
 
735
		}
736
 
737
 
738
    },
739
 
740
	destructor: function () {
741
 
742
		var aHandlers = this._eventHandlers;
743
 
744
		if (aHandlers) {
745
 
746
			Y.Array.each(aHandlers, function (handle) {
747
				handle.detach();
748
			});
749
 
750
			this._eventHandlers = null;
751
 
752
		}
753
 
754
		this.get(HOST).unplug("focusManager");
755
 
756
    },
757
 
758
 
759
 
760
	//	Protected methods
761
 
762
	/**
763
	* @method _isRoot
764
	* @description Returns a boolean indicating if the specified menu is the
765
	* root menu in the menu.
766
	* @protected
767
	* @param {Node} menu Node instance representing a menu.
768
	* @return {Boolean} Boolean indicating if the specified menu is the root
769
	* menu in the menu.
770
	*/
771
	_isRoot: function (menu) {
772
 
773
		return this._rootMenu.compareTo(menu);
774
 
775
	},
776
 
777
 
778
	/**
779
	* @method _getTopmostSubmenu
780
	* @description Returns the topmost submenu of a submenu hierarchy.
781
	* @protected
782
	* @param {Node} menu Node instance representing a menu.
783
	* @return {Node} Node instance representing a menu.
784
	*/
785
	_getTopmostSubmenu: function (menu) {
786
 
787
		var menuNav = this,
788
			oMenu = getParentMenu(menu),
789
			returnVal;
790
 
791
 
792
		if (!oMenu) {
793
			returnVal = menu;
794
		}
795
		else if (menuNav._isRoot(oMenu)) {
796
			returnVal = menu;
797
		}
798
		else {
799
			returnVal = menuNav._getTopmostSubmenu(oMenu);
800
		}
801
 
802
		return returnVal;
803
 
804
	},
805
 
806
 
807
	/**
808
	* @method _clearActiveItem
809
	* @description Clears the menu's active descendent.
810
	* @protected
811
	*/
812
	_clearActiveItem: function () {
813
 
814
		var menuNav = this,
815
			oActiveItem = menuNav._activeItem;
816
 
817
		if (oActiveItem) {
818
			oActiveItem.removeClass(getActiveClass(oActiveItem));
819
		}
820
 
821
		menuNav._activeItem = null;
822
 
823
	},
824
 
825
 
826
	/**
827
	* @method _setActiveItem
828
	* @description Sets the specified menuitem or menu label as the menu's
829
	* active descendent.
830
	* @protected
831
	* @param {Node} item Node instance representing a menuitem or menu label.
832
	*/
833
	_setActiveItem: function (item) {
834
 
835
		var menuNav = this;
836
 
837
		if (item) {
838
 
839
			menuNav._clearActiveItem();
840
 
841
			item.addClass(getActiveClass(item));
842
 
843
			menuNav._activeItem = item;
844
 
845
		}
846
 
847
	},
848
 
849
 
850
	/**
851
	* @method _focusItem
852
	* @description Focuses the specified menuitem or menu label.
853
	* @protected
854
	* @param {Node} item Node instance representing a menuitem or menu label.
855
	*/
856
	_focusItem: function (item) {
857
 
858
		var menuNav = this,
859
			oMenu,
860
			oItem;
861
 
862
		if (item && menuNav._hasFocus) {
863
 
864
			oMenu = getParentMenu(item);
865
			oItem = getItemAnchor(item);
866
 
867
			if (oMenu && !oMenu.compareTo(menuNav._activeMenu)) {
868
				menuNav._activeMenu = oMenu;
869
				menuNav._initFocusManager();
870
			}
871
 
872
			menuNav._focusManager.focus(oItem);
873
 
874
		}
875
 
876
	},
877
 
878
 
879
	/**
880
	* @method _showMenu
881
	* @description Shows the specified menu.
882
	* @protected
883
	* @param {Node} menu Node instance representing a menu.
884
	*/
885
	_showMenu: function (menu) {
886
 
887
		var oParentMenu = getParentMenu(menu),
888
			oLI = menu.get(PARENT_NODE),
889
			aXY = oLI.getXY();
890
 
891
 
892
		if (this.get(USE_ARIA)) {
893
			menu.set(ARIA_HIDDEN, false);
894
		}
895
 
896
 
897
		if (isHorizontalMenu(oParentMenu)) {
898
			aXY[1] = aXY[1] + oLI.get(OFFSET_HEIGHT);
899
		}
900
		else {
901
			aXY[0] = aXY[0] + oLI.get(OFFSET_WIDTH);
902
		}
903
 
904
		menu.setXY(aXY);
905
 
906
		if (UA.ie && UA.ie < 8) {
907
 
908
			if (UA.ie === 6 && !menu.hasIFrameShim) {
909
 
910
				menu.appendChild(Y.Node.create(NodeMenuNav.SHIM_TEMPLATE));
911
				menu.hasIFrameShim = true;
912
 
913
			}
914
 
915
			//	Clear previous values for height and width
916
 
917
			menu.setStyles({ height: EMPTY_STRING, width: EMPTY_STRING });
918
 
919
			//	Set the width and height of the menu's bounding box - this is
920
			//	necessary for IE 6 so that the CSS for the <iframe> shim can
921
			//	simply set the <iframe>'s width and height to 100% to ensure
922
			//	that dimensions of an <iframe> shim are always sync'd to the
923
			//	that of its parent menu.  Specifying a width and height also
924
			//	helps when positioning decorator elements (for creating effects
925
			//	like rounded corners) inside a menu's bounding box in IE 7.
926
 
927
			menu.setStyles({
928
				height: (menu.get(OFFSET_HEIGHT) + PX),
929
				width: (menu.get(OFFSET_WIDTH) + PX) });
930
 
931
		}
932
 
933
		menu.previous().addClass(CSS_MENU_LABEL_MENUVISIBLE);
934
		menu.removeClass(CSS_MENU_HIDDEN);
935
 
936
	},
937
 
938
 
939
	/**
940
	* @method _hideMenu
941
	* @description Hides the specified menu.
942
	* @protected
943
	* @param {Node} menu Node instance representing a menu.
944
	* @param {Boolean} activateAndFocusLabel Boolean indicating if the label
945
	* for the specified
946
	* menu should be focused and set as active.
947
	*/
948
	_hideMenu: function (menu, activateAndFocusLabel) {
949
 
950
		var menuNav = this,
951
			oLabel = menu.previous(),
952
			oActiveItem;
953
 
954
		oLabel.removeClass(CSS_MENU_LABEL_MENUVISIBLE);
955
 
956
 
957
		if (activateAndFocusLabel) {
958
			menuNav._focusItem(oLabel);
959
			menuNav._setActiveItem(oLabel);
960
		}
961
 
962
		oActiveItem = menu.one((PERIOD + CSS_MENUITEM_ACTIVE));
963
 
964
		if (oActiveItem) {
965
			oActiveItem.removeClass(CSS_MENUITEM_ACTIVE);
966
		}
967
 
968
		//	Clear the values for top and left that were set by the call to
969
		//	"setXY" when the menu was shown so that the hidden position
970
		//	specified in the core CSS file will take affect.
971
 
972
		menu.setStyles({ left: EMPTY_STRING, top: EMPTY_STRING });
973
 
974
		menu.addClass(CSS_MENU_HIDDEN);
975
 
976
		if (menuNav.get(USE_ARIA)) {
977
			menu.set(ARIA_HIDDEN, true);
978
		}
979
 
980
	},
981
 
982
 
983
	/**
984
	* @method _hideAllSubmenus
985
	* @description Hides all submenus of the specified menu.
986
	* @protected
987
	* @param {Node} menu Node instance representing a menu.
988
	*/
989
	_hideAllSubmenus: function (menu) {
990
 
991
		var menuNav = this;
992
 
993
		menu.all(MENU_SELECTOR).each(Y.bind(function (submenuNode) {
994
 
995
			menuNav._hideMenu(submenuNode);
996
 
997
		}, menuNav));
998
 
999
	},
1000
 
1001
 
1002
	/**
1003
	* @method _cancelShowSubmenuTimer
1004
	* @description Cancels the timer used to show a submenu.
1005
	* @protected
1006
	*/
1007
	_cancelShowSubmenuTimer: function () {
1008
 
1009
		var menuNav = this,
1010
			oShowSubmenuTimer = menuNav._showSubmenuTimer;
1011
 
1012
		if (oShowSubmenuTimer) {
1013
			oShowSubmenuTimer.cancel();
1014
			menuNav._showSubmenuTimer = null;
1015
		}
1016
 
1017
	},
1018
 
1019
 
1020
	/**
1021
	* @method _cancelHideSubmenuTimer
1022
	* @description Cancels the timer used to hide a submenu.
1023
	* @protected
1024
	*/
1025
	_cancelHideSubmenuTimer: function () {
1026
 
1027
		var menuNav = this,
1028
			oHideSubmenuTimer = menuNav._hideSubmenuTimer;
1029
 
1030
 
1031
		if (oHideSubmenuTimer) {
1032
			oHideSubmenuTimer.cancel();
1033
			menuNav._hideSubmenuTimer = null;
1034
		}
1035
 
1036
	},
1037
 
1038
 
1039
	/**
1040
	* @method _initFocusManager
1041
	* @description Initializes and updates the Focus Manager so that is is
1042
	* always managing descendants of the active menu.
1043
	* @protected
1044
	*/
1045
	_initFocusManager: function () {
1046
 
1047
		var menuNav = this,
1048
			oRootMenu = menuNav._rootMenu,
1049
			oMenu = menuNav._activeMenu || oRootMenu,
1050
			sSelectorBase =
1051
				menuNav._isRoot(oMenu) ? EMPTY_STRING : ("#" + oMenu.get("id")),
1052
			oFocusManager = menuNav._focusManager,
1053
			sKeysVal,
1054
			sDescendantSelector,
1055
			sQuery;
1056
 
1057
		if (isHorizontalMenu(oMenu)) {
1058
 
1059
			sDescendantSelector = sSelectorBase + STANDARD_QUERY + "," +
1060
				sSelectorBase + EXTENDED_QUERY;
1061
 
1062
			sKeysVal = { next: "down:39", previous: "down:37" };
1063
 
1064
		}
1065
		else {
1066
 
1067
			sDescendantSelector = sSelectorBase + STANDARD_QUERY;
1068
			sKeysVal = { next: "down:40", previous: "down:38" };
1069
 
1070
		}
1071
 
1072
 
1073
		if (!oFocusManager) {
1074
 
1075
			oRootMenu.plug(Y.Plugin.NodeFocusManager, {
1076
				descendants: sDescendantSelector,
1077
				keys: sKeysVal,
1078
				circular: true
1079
			});
1080
 
1081
			oFocusManager = oRootMenu.focusManager;
1082
 
1083
			sQuery = "#" + oRootMenu.get("id") + MENU_SELECTOR + " a," +
1084
							MENU_TOGGLE_SELECTOR;
1085
 
1086
			oRootMenu.all(sQuery).set("tabIndex", -1);
1087
 
1088
			oFocusManager.on(ACTIVE_DESCENDANT_CHANGE,
1089
				this._onActiveDescendantChange, oFocusManager, this);
1090
 
1091
			oFocusManager.after(ACTIVE_DESCENDANT_CHANGE,
1092
				this._afterActiveDescendantChange, oFocusManager, this);
1093
 
1094
			menuNav._focusManager = oFocusManager;
1095
 
1096
		}
1097
		else {
1098
 
1099
			oFocusManager.set(ACTIVE_DESCENDANT, -1);
1100
			oFocusManager.set(DESCENDANTS, sDescendantSelector);
1101
			oFocusManager.set("keys", sKeysVal);
1102
 
1103
		}
1104
 
1105
	},
1106
 
1107
 
1108
	//	Event handlers for discrete pieces of pieces of the menu
1109
 
1110
 
1111
	/**
1112
	* @method _onActiveDescendantChange
1113
	* @description "activeDescendantChange" event handler for menu's
1114
	* Focus Manager.
1115
	* @protected
1116
	* @param {Object} event Object representing the Attribute change event.
1117
	* @param {NodeMenuNav} menuNav Object representing the NodeMenuNav instance.
1118
	*/
1119
	_onActiveDescendantChange: function (event, menuNav) {
1120
 
1121
		if (event.src === UI && menuNav._activeMenu &&
1122
				!menuNav._movingToSubmenu) {
1123
 
1124
			menuNav._hideAllSubmenus(menuNav._activeMenu);
1125
 
1126
		}
1127
 
1128
	},
1129
 
1130
 
1131
	/**
1132
	* @method _afterActiveDescendantChange
1133
	* @description "activeDescendantChange" event handler for menu's
1134
	* Focus Manager.
1135
	* @protected
1136
	* @param {Object} event Object representing the Attribute change event.
1137
	* @param {NodeMenuNav} menuNav Object representing the NodeMenuNav instance.
1138
	*/
1139
	_afterActiveDescendantChange: function (event, menuNav) {
1140
 
1141
		var oItem;
1142
 
1143
		if (event.src === UI) {
1144
			oItem = getItem(this.get(DESCENDANTS).item(event.newVal), true);
1145
			menuNav._setActiveItem(oItem);
1146
		}
1147
 
1148
	},
1149
 
1150
 
1151
	/**
1152
	* @method _onDocFocus
1153
	* @description "focus" event handler for the owner document of the MenuNav.
1154
	* @protected
1155
	* @param {Object} event Object representing the DOM event.
1156
	*/
1157
	_onDocFocus: function (event) {
1158
 
1159
		var menuNav = this,
1160
			oActiveItem = menuNav._activeItem,
1161
			oTarget = event.target,
1162
			oMenu;
1163
 
1164
 
1165
		if (menuNav._rootMenu.contains(oTarget)) {	//	The menu has focus
1166
 
1167
			if (menuNav._hasFocus) {
1168
 
1169
				oMenu = getParentMenu(oTarget);
1170
 
1171
				//	If the element that was focused is a descendant of the
1172
				//	root menu, but is in a submenu not currently being
1173
				//	managed by the Focus Manager, update the Focus Manager so
1174
				//	that it is now managing the submenu that is the parent of
1175
				//	the element that was focused.
1176
 
1177
				if (!menuNav._activeMenu.compareTo(oMenu)) {
1178
 
1179
					menuNav._activeMenu = oMenu;
1180
					menuNav._initFocusManager();
1181
					menuNav._focusManager.set(ACTIVE_DESCENDANT, oTarget);
1182
					menuNav._setActiveItem(getItem(oTarget, true));
1183
 
1184
				}
1185
 
1186
			}
1187
			else { //	Initial focus
1188
 
1189
				//	First time the menu has been focused, need to setup focused
1190
				//	state and established active active descendant
1191
 
1192
				menuNav._hasFocus = true;
1193
 
1194
				oActiveItem = getItem(oTarget, true);
1195
 
1196
				if (oActiveItem) {
1197
					menuNav._setActiveItem(oActiveItem);
1198
				}
1199
 
1200
			}
1201
 
1202
		}
1203
		else {	//	The menu has lost focus
1204
 
1205
			menuNav._clearActiveItem();
1206
 
1207
			menuNav._cancelShowSubmenuTimer();
1208
			menuNav._hideAllSubmenus(menuNav._rootMenu);
1209
 
1210
			menuNav._activeMenu = menuNav._rootMenu;
1211
			menuNav._initFocusManager();
1212
 
1213
			menuNav._focusManager.set(ACTIVE_DESCENDANT, 0);
1214
 
1215
			menuNav._hasFocus = false;
1216
 
1217
		}
1218
 
1219
	},
1220
 
1221
 
1222
	/**
1223
	* @method _onMenuMouseOver
1224
	* @description "mouseover" event handler for a menu.
1225
	* @protected
1226
	* @param {Node} menu Node instance representing a menu.
1227
	* @param {Object} event Object representing the DOM event.
1228
	*/
1229
	_onMenuMouseOver: function (menu, event) {
1230
 
1231
		var menuNav = this,
1232
			oHideAllSubmenusTimer = menuNav._hideAllSubmenusTimer;
1233
 
1234
		if (oHideAllSubmenusTimer) {
1235
			oHideAllSubmenusTimer.cancel();
1236
			menuNav._hideAllSubmenusTimer = null;
1237
		}
1238
 
1239
		menuNav._cancelHideSubmenuTimer();
1240
 
1241
		//	Need to update the FocusManager in advance of focus a new
1242
		//	Menu in order to avoid the FocusManager thinking that
1243
		//	it has lost focus
1244
 
1245
		if (menu && !menu.compareTo(menuNav._activeMenu)) {
1246
			menuNav._activeMenu = menu;
1247
 
1248
			if (menuNav._hasFocus) {
1249
				menuNav._initFocusManager();
1250
			}
1251
 
1252
		}
1253
 
1254
		if (menuNav._movingToSubmenu && isHorizontalMenu(menu)) {
1255
			menuNav._movingToSubmenu = false;
1256
		}
1257
 
1258
	},
1259
 
1260
 
1261
	/**
1262
	* @method _hideAndFocusLabel
1263
	* @description Hides all of the submenus of the root menu and focuses the
1264
	* label of the topmost submenu
1265
	* @protected
1266
	*/
1267
	_hideAndFocusLabel: function () {
1268
 
1269
		var	menuNav = this,
1270
			oActiveMenu = menuNav._activeMenu,
1271
			oSubmenu;
1272
 
1273
		menuNav._hideAllSubmenus(menuNav._rootMenu);
1274
 
1275
		if (oActiveMenu) {
1276
 
1277
			//	Focus the label element for the topmost submenu
1278
			oSubmenu = menuNav._getTopmostSubmenu(oActiveMenu);
1279
			menuNav._focusItem(oSubmenu.previous());
1280
 
1281
		}
1282
 
1283
	},
1284
 
1285
 
1286
	/**
1287
	* @method _onMenuMouseOut
1288
	* @description "mouseout" event handler for a menu.
1289
	* @protected
1290
	* @param {Node} menu Node instance representing a menu.
1291
	* @param {Object} event Object representing the DOM event.
1292
	*/
1293
	_onMenuMouseOut: function (menu, event) {
1294
 
1295
		var menuNav = this,
1296
			oActiveMenu = menuNav._activeMenu,
1297
			oRelatedTarget = event.relatedTarget,
1298
			oActiveItem = menuNav._activeItem,
1299
			oParentMenu,
1300
			oMenu;
1301
 
1302
 
1303
		if (oActiveMenu && !oActiveMenu.contains(oRelatedTarget)) {
1304
 
1305
			oParentMenu = getParentMenu(oActiveMenu);
1306
 
1307
 
1308
			if (oParentMenu && !oParentMenu.contains(oRelatedTarget)) {
1309
 
1310
				if (menuNav.get(MOUSEOUT_HIDE_DELAY) > 0) {
1311
 
1312
					menuNav._cancelShowSubmenuTimer();
1313
 
1314
					menuNav._hideAllSubmenusTimer =
1315
 
1316
						later(menuNav.get(MOUSEOUT_HIDE_DELAY),
1317
							menuNav, menuNav._hideAndFocusLabel);
1318
 
1319
				}
1320
 
1321
			}
1322
			else {
1323
 
1324
				if (oActiveItem) {
1325
 
1326
					oMenu = getParentMenu(oActiveItem);
1327
 
1328
					if (!menuNav._isRoot(oMenu)) {
1329
						menuNav._focusItem(oMenu.previous());
1330
					}
1331
 
1332
				}
1333
 
1334
			}
1335
 
1336
		}
1337
 
1338
	},
1339
 
1340
 
1341
	/**
1342
	* @method _onMenuLabelMouseOver
1343
	* @description "mouseover" event handler for a menu label.
1344
	* @protected
1345
	* @param {Node} menuLabel Node instance representing a menu label.
1346
	* @param {Object} event Object representing the DOM event.
1347
	*/
1348
	_onMenuLabelMouseOver: function (menuLabel, event) {
1349
 
1350
		var menuNav = this,
1351
			oActiveMenu = menuNav._activeMenu,
1352
			bIsRoot = menuNav._isRoot(oActiveMenu),
1353
			bUseAutoSubmenuDisplay =
1354
				(menuNav.get(AUTO_SUBMENU_DISPLAY) && bIsRoot || !bIsRoot),
1355
            submenuShowDelay = menuNav.get("submenuShowDelay"),
1356
			oSubmenu;
1357
 
1358
 
1359
        var showSubmenu = function (delay) {
1360
 
1361
			menuNav._cancelHideSubmenuTimer();
1362
			menuNav._cancelShowSubmenuTimer();
1363
 
1364
			if (!hasVisibleSubmenu(menuLabel)) {
1365
 
1366
				oSubmenu = menuLabel.next();
1367
 
1368
				if (oSubmenu) {
1369
					menuNav._hideAllSubmenus(oActiveMenu);
1370
					menuNav._showSubmenuTimer = later(delay, menuNav, menuNav._showMenu, oSubmenu);
1371
				}
1372
 
1373
			}
1374
 
1375
        };
1376
 
1377
 
1378
		menuNav._focusItem(menuLabel);
1379
		menuNav._setActiveItem(menuLabel);
1380
 
1381
 
1382
		if (bUseAutoSubmenuDisplay) {
1383
 
1384
	        if (menuNav._movingToSubmenu) {
1385
 
1386
	            //  If the user is moving diagonally from a submenu to
1387
	            //  another submenu and they then stop and pause on a
1388
	            //  menu label for an amount of time equal to the amount of
1389
	            //  time defined for the display of a submenu then show the
1390
	            //  submenu immediately.
1391
	            //  http://yuilibrary.com/projects/yui3/ticket/2528316
1392
 
1393
	            //Y.message("Pause path");
1394
 
1395
	            menuNav._hoverTimer = later(submenuShowDelay, menuNav, function () {
1396
                    showSubmenu(0);
1397
	            });
1398
 
1399
	        }
1400
	        else {
1401
                showSubmenu(submenuShowDelay);
1402
	        }
1403
 
1404
		}
1405
 
1406
	},
1407
 
1408
 
1409
	/**
1410
	* @method _onMenuLabelMouseOut
1411
	* @description "mouseout" event handler for a menu label.
1412
	* @protected
1413
	* @param {Node} menuLabel Node instance representing a menu label.
1414
	* @param {Object} event Object representing the DOM event.
1415
	*/
1416
	_onMenuLabelMouseOut: function (menuLabel, event) {
1417
 
1418
		var menuNav = this,
1419
			bIsRoot = menuNav._isRoot(menuNav._activeMenu),
1420
			bUseAutoSubmenuDisplay =
1421
				(menuNav.get(AUTO_SUBMENU_DISPLAY) && bIsRoot || !bIsRoot),
1422
 
1423
			oRelatedTarget = event.relatedTarget,
1424
			oSubmenu = menuLabel.next(),
1425
			hoverTimer = menuNav._hoverTimer;
1426
 
1427
        if (hoverTimer) {
1428
            hoverTimer.cancel();
1429
        }
1430
 
1431
		menuNav._clearActiveItem();
1432
 
1433
		if (bUseAutoSubmenuDisplay) {
1434
 
1435
			if (menuNav._movingToSubmenu &&
1436
					!menuNav._showSubmenuTimer && oSubmenu) {
1437
 
1438
				//	If the mouse is moving diagonally toward the submenu and
1439
				//	another submenu isn't in the process of being displayed
1440
				//	(via a timer), then hide the submenu via a timer to give
1441
				//	the user some time to reach the submenu.
1442
 
1443
				menuNav._hideSubmenuTimer =
1444
					later(menuNav.get("submenuHideDelay"), menuNav,
1445
						menuNav._hideMenu, oSubmenu);
1446
 
1447
			}
1448
			else if (!menuNav._movingToSubmenu && oSubmenu && (!oRelatedTarget ||
1449
			        (oRelatedTarget &&
1450
			            !oSubmenu.contains(oRelatedTarget) &&
1451
			            !oRelatedTarget.compareTo(oSubmenu)))) {
1452
 
1453
				//	If the mouse is not moving toward the submenu, cancel any
1454
				//	submenus that might be in the process of being displayed
1455
				//	(via a timer) and hide this submenu immediately.
1456
 
1457
				menuNav._cancelShowSubmenuTimer();
1458
 
1459
				menuNav._hideMenu(oSubmenu);
1460
 
1461
			}
1462
 
1463
		}
1464
 
1465
	},
1466
 
1467
 
1468
	/**
1469
	* @method _onMenuItemMouseOver
1470
	* @description "mouseover" event handler for a menuitem.
1471
	* @protected
1472
	* @param {Node} menuItem Node instance representing a menuitem.
1473
	* @param {Object} event Object representing the DOM event.
1474
	*/
1475
	_onMenuItemMouseOver: function (menuItem, event) {
1476
 
1477
		var menuNav = this,
1478
			oActiveMenu = menuNav._activeMenu,
1479
			bIsRoot = menuNav._isRoot(oActiveMenu),
1480
			bUseAutoSubmenuDisplay =
1481
				(menuNav.get(AUTO_SUBMENU_DISPLAY) && bIsRoot || !bIsRoot);
1482
 
1483
 
1484
		menuNav._focusItem(menuItem);
1485
		menuNav._setActiveItem(menuItem);
1486
 
1487
 
1488
		if (bUseAutoSubmenuDisplay && !menuNav._movingToSubmenu) {
1489
 
1490
			menuNav._hideAllSubmenus(oActiveMenu);
1491
 
1492
		}
1493
 
1494
	},
1495
 
1496
 
1497
	/**
1498
	* @method _onMenuItemMouseOut
1499
	* @description "mouseout" event handler for a menuitem.
1500
	* @protected
1501
	* @param {Node} menuItem Node instance representing a menuitem.
1502
	* @param {Object} event Object representing the DOM event.
1503
	*/
1504
	_onMenuItemMouseOut: function (menuItem, event) {
1505
 
1506
		this._clearActiveItem();
1507
 
1508
	},
1509
 
1510
 
1511
	/**
1512
	* @method _onVerticalMenuKeyDown
1513
	* @description "keydown" event handler for vertical menus.
1514
	* @protected
1515
	* @param {Object} event Object representing the DOM event.
1516
	*/
1517
	_onVerticalMenuKeyDown: function (event) {
1518
 
1519
		var menuNav = this,
1520
			oActiveMenu = menuNav._activeMenu,
1521
			oRootMenu = menuNav._rootMenu,
1522
			oTarget = event.target,
1523
			bPreventDefault = false,
1524
			nKeyCode = event.keyCode,
1525
			oSubmenu,
1526
			oParentMenu,
1527
			oLI,
1528
			oItem;
1529
 
1530
 
1531
		switch (nKeyCode) {
1532
 
1533
			case 37:	//	left arrow
1534
 
1535
				oParentMenu = getParentMenu(oActiveMenu);
1536
 
1537
				if (oParentMenu && isHorizontalMenu(oParentMenu)) {
1538
 
1539
					menuNav._hideMenu(oActiveMenu);
1540
					oLI = getPreviousSibling(oActiveMenu.get(PARENT_NODE));
1541
					oItem = getItem(oLI);
1542
 
1543
					if (oItem) {
1544
 
1545
						if (isMenuLabel(oItem)) {	//	Menu label
1546
 
1547
							oSubmenu = oItem.next();
1548
 
1549
 
1550
							if (oSubmenu) {
1551
 
1552
								menuNav._showMenu(oSubmenu);
1553
								menuNav._focusItem(getFirstItem(oSubmenu));
1554
								menuNav._setActiveItem(getFirstItem(oSubmenu));
1555
 
1556
							}
1557
							else {
1558
 
1559
								menuNav._focusItem(oItem);
1560
								menuNav._setActiveItem(oItem);
1561
 
1562
							}
1563
 
1564
						}
1565
						else {	//	MenuItem
1566
 
1567
							menuNav._focusItem(oItem);
1568
							menuNav._setActiveItem(oItem);
1569
 
1570
						}
1571
 
1572
					}
1573
 
1574
				}
1575
				else if (!menuNav._isRoot(oActiveMenu)) {
1576
					menuNav._hideMenu(oActiveMenu, true);
1577
				}
1578
 
1579
 
1580
				bPreventDefault = true;
1581
 
1582
			break;
1583
 
1584
			case 39:	//	right arrow
1585
 
1586
				if (isMenuLabel(oTarget)) {
1587
 
1588
					oSubmenu = oTarget.next();
1589
 
1590
					if (oSubmenu) {
1591
 
1592
						menuNav._showMenu(oSubmenu);
1593
						menuNav._focusItem(getFirstItem(oSubmenu));
1594
						menuNav._setActiveItem(getFirstItem(oSubmenu));
1595
 
1596
					}
1597
 
1598
				}
1599
				else if (isHorizontalMenu(oRootMenu)) {
1600
 
1601
					oSubmenu = menuNav._getTopmostSubmenu(oActiveMenu);
1602
					oLI = getNextSibling(oSubmenu.get(PARENT_NODE));
1603
					oItem = getItem(oLI);
1604
 
1605
					menuNav._hideAllSubmenus(oRootMenu);
1606
 
1607
					if (oItem) {
1608
 
1609
						if (isMenuLabel(oItem)) {	//	Menu label
1610
 
1611
							oSubmenu = oItem.next();
1612
 
1613
							if (oSubmenu) {
1614
 
1615
								menuNav._showMenu(oSubmenu);
1616
								menuNav._focusItem(getFirstItem(oSubmenu));
1617
								menuNav._setActiveItem(getFirstItem(oSubmenu));
1618
 
1619
							}
1620
							else {
1621
 
1622
								menuNav._focusItem(oItem);
1623
								menuNav._setActiveItem(oItem);
1624
 
1625
							}
1626
 
1627
						}
1628
						else {	//	MenuItem
1629
 
1630
							menuNav._focusItem(oItem);
1631
							menuNav._setActiveItem(oItem);
1632
 
1633
						}
1634
 
1635
					}
1636
 
1637
				}
1638
 
1639
				bPreventDefault = true;
1640
 
1641
			break;
1642
 
1643
		}
1644
 
1645
 
1646
		if (bPreventDefault) {
1647
 
1648
			//	Prevent the browser from scrolling the window
1649
 
1650
			event.preventDefault();
1651
 
1652
		}
1653
 
1654
	},
1655
 
1656
 
1657
	/**
1658
	* @method _onHorizontalMenuKeyDown
1659
	* @description "keydown" event handler for horizontal menus.
1660
	* @protected
1661
	* @param {Object} event Object representing the DOM event.
1662
	*/
1663
	_onHorizontalMenuKeyDown: function (event) {
1664
 
1665
		var menuNav = this,
1666
			oActiveMenu = menuNav._activeMenu,
1667
			oTarget = event.target,
1668
			oFocusedItem = getItem(oTarget, true),
1669
			bPreventDefault = false,
1670
			nKeyCode = event.keyCode,
1671
			oSubmenu;
1672
 
1673
 
1674
		if (nKeyCode === 40) {
1675
 
1676
			menuNav._hideAllSubmenus(oActiveMenu);
1677
 
1678
			if (isMenuLabel(oFocusedItem)) {
1679
 
1680
				oSubmenu = oFocusedItem.next();
1681
 
1682
				if (oSubmenu) {
1683
 
1684
					menuNav._showMenu(oSubmenu);
1685
					menuNav._focusItem(getFirstItem(oSubmenu));
1686
					menuNav._setActiveItem(getFirstItem(oSubmenu));
1687
 
1688
				}
1689
 
1690
				bPreventDefault = true;
1691
 
1692
			}
1693
 
1694
		}
1695
 
1696
 
1697
		if (bPreventDefault) {
1698
 
1699
			//	Prevent the browser from scrolling the window
1700
 
1701
			event.preventDefault();
1702
 
1703
		}
1704
 
1705
	},
1706
 
1707
 
1708
	//	Generic DOM Event handlers
1709
 
1710
 
1711
	/**
1712
	* @method _onMouseMove
1713
	* @description "mousemove" event handler for the menu.
1714
	* @protected
1715
	* @param {Object} event Object representing the DOM event.
1716
	*/
1717
	_onMouseMove: function (event) {
1718
 
1719
		var menuNav = this;
1720
 
1721
		//	Using a timer to set the value of the "_currentMouseX" property
1722
		//	helps improve the reliability of the calculation used to set the
1723
		//	value of the "_movingToSubmenu" property - especially in Opera.
1724
 
1725
		later(10, menuNav, function () {
1726
 
1727
			menuNav._currentMouseX = event.pageX;
1728
 
1729
		});
1730
 
1731
	},
1732
 
1733
 
1734
	/**
1735
	* @method _onMouseOver
1736
	* @description "mouseover" event handler for the menu.
1737
	* @protected
1738
	* @param {Object} event Object representing the DOM event.
1739
	*/
1740
	_onMouseOver: function (event) {
1741
 
1742
		var menuNav = this,
1743
			oTarget,
1744
			oMenu,
1745
			oMenuLabel,
1746
			oParentMenu,
1747
			oMenuItem;
1748
 
1749
 
1750
		if (menuNav._blockMouseEvent) {
1751
			menuNav._blockMouseEvent = false;
1752
		}
1753
		else {
1754
 
1755
			oTarget = event.target;
1756
			oMenu = getMenu(oTarget, true);
1757
			oMenuLabel = getMenuLabel(oTarget, true);
1758
			oMenuItem = getMenuItem(oTarget, true);
1759
 
1760
 
1761
			if (handleMouseOverForNode(oMenu, oTarget)) {
1762
 
1763
				menuNav._onMenuMouseOver(oMenu, event);
1764
 
1765
				oMenu[HANDLED_MOUSEOVER] = true;
1766
				oMenu[HANDLED_MOUSEOUT] = false;
1767
 
1768
				oParentMenu = getParentMenu(oMenu);
1769
 
1770
				if (oParentMenu) {
1771
 
1772
					oParentMenu[HANDLED_MOUSEOUT] = true;
1773
					oParentMenu[HANDLED_MOUSEOVER] = false;
1774
 
1775
				}
1776
 
1777
			}
1778
 
1779
			if (handleMouseOverForNode(oMenuLabel, oTarget)) {
1780
 
1781
				menuNav._onMenuLabelMouseOver(oMenuLabel, event);
1782
 
1783
				oMenuLabel[HANDLED_MOUSEOVER] = true;
1784
				oMenuLabel[HANDLED_MOUSEOUT] = false;
1785
 
1786
			}
1787
 
1788
			if (handleMouseOverForNode(oMenuItem, oTarget)) {
1789
 
1790
				menuNav._onMenuItemMouseOver(oMenuItem, event);
1791
 
1792
				oMenuItem[HANDLED_MOUSEOVER] = true;
1793
				oMenuItem[HANDLED_MOUSEOUT] = false;
1794
 
1795
			}
1796
 
1797
		}
1798
 
1799
	},
1800
 
1801
 
1802
	/**
1803
	* @method _onMouseOut
1804
	* @description "mouseout" event handler for the menu.
1805
	* @protected
1806
	* @param {Object} event Object representing the DOM event.
1807
	*/
1808
	_onMouseOut: function (event) {
1809
 
1810
		var menuNav = this,
1811
			oActiveMenu = menuNav._activeMenu,
1812
			bMovingToSubmenu = false,
1813
			oTarget,
1814
			oRelatedTarget,
1815
			oMenu,
1816
			oMenuLabel,
1817
			oSubmenu,
1818
			oMenuItem;
1819
 
1820
 
1821
		menuNav._movingToSubmenu =
1822
					(oActiveMenu && !isHorizontalMenu(oActiveMenu) &&
1823
						((event.pageX - 5) > menuNav._currentMouseX));
1824
 
1825
		oTarget = event.target;
1826
		oRelatedTarget = event.relatedTarget;
1827
		oMenu = getMenu(oTarget, true);
1828
		oMenuLabel = getMenuLabel(oTarget, true);
1829
		oMenuItem = getMenuItem(oTarget, true);
1830
 
1831
 
1832
		if (handleMouseOutForNode(oMenuLabel, oRelatedTarget)) {
1833
 
1834
			menuNav._onMenuLabelMouseOut(oMenuLabel, event);
1835
 
1836
			oMenuLabel[HANDLED_MOUSEOUT] = true;
1837
			oMenuLabel[HANDLED_MOUSEOVER] = false;
1838
 
1839
		}
1840
 
1841
		if (handleMouseOutForNode(oMenuItem, oRelatedTarget)) {
1842
 
1843
			menuNav._onMenuItemMouseOut(oMenuItem, event);
1844
 
1845
			oMenuItem[HANDLED_MOUSEOUT] = true;
1846
			oMenuItem[HANDLED_MOUSEOVER] = false;
1847
 
1848
		}
1849
 
1850
 
1851
		if (oMenuLabel) {
1852
 
1853
			oSubmenu = oMenuLabel.next();
1854
 
1855
			if (oSubmenu && oRelatedTarget &&
1856
				(oRelatedTarget.compareTo(oSubmenu) ||
1857
					oSubmenu.contains(oRelatedTarget))) {
1858
 
1859
				bMovingToSubmenu = true;
1860
 
1861
			}
1862
 
1863
		}
1864
 
1865
 
1866
		if (handleMouseOutForNode(oMenu, oRelatedTarget) || bMovingToSubmenu) {
1867
 
1868
			menuNav._onMenuMouseOut(oMenu, event);
1869
 
1870
			oMenu[HANDLED_MOUSEOUT] = true;
1871
			oMenu[HANDLED_MOUSEOVER] = false;
1872
 
1873
		}
1874
 
1875
	},
1876
 
1877
 
1878
	/**
1879
	* @method _toggleSubmenuDisplay
1880
	* @description "mousedown," "keydown," and "click" event handler for the
1881
	* menu used to toggle the display of a submenu.
1882
	* @protected
1883
	* @param {Object} event Object representing the DOM event.
1884
	*/
1885
	_toggleSubmenuDisplay: function (event) {
1886
 
1887
		var menuNav = this,
1888
			oTarget = event.target,
1889
			oMenuLabel = getMenuLabel(oTarget, true),
1890
			sType = event.type,
1891
			oAnchor,
1892
			oSubmenu,
1893
			sHref,
1894
			nHashPos,
1895
			nLen,
1896
			sId;
1897
 
1898
 
1899
		if (oMenuLabel) {
1900
 
1901
			oAnchor = isAnchor(oTarget) ? oTarget : oTarget.ancestor(isAnchor);
1902
 
1903
 
1904
			if (oAnchor) {
1905
 
1906
				//	Need to pass "2" as a second argument to "getAttribute" for
1907
				//	IE otherwise IE will return a fully qualified URL for the
1908
				//	value of the "href" attribute.
1909
				//	http://msdn.microsoft.com/en-us/library/ms536429(VS.85).aspx
1910
 
1911
				sHref = oAnchor.getAttribute("href", 2);
1912
				nHashPos = sHref.indexOf("#");
1913
				nLen = sHref.length;
1914
 
1915
				if (nHashPos === 0 && nLen > 1) {
1916
 
1917
					sId = sHref.substr(1, nLen);
1918
					oSubmenu = oMenuLabel.next();
1919
 
1920
					if (oSubmenu && (oSubmenu.get(ID) === sId)) {
1921
 
1922
						if (sType === MOUSEDOWN || sType === KEYDOWN) {
1923
 
1924
							if ((UA.opera || UA.gecko || UA.ie) && sType === KEYDOWN && !menuNav._preventClickHandle) {
1925
 
1926
								//	Prevent the browser from following the URL of
1927
								//	the anchor element
1928
 
1929
								menuNav._preventClickHandle = menuNav._rootMenu.on("click", function (event) {
1930
 
1931
									event.preventDefault();
1932
 
1933
									menuNav._preventClickHandle.detach();
1934
									menuNav._preventClickHandle = null;
1935
 
1936
								});
1937
 
1938
							}
1939
 
1940
							if (sType == MOUSEDOWN) {
1941
 
1942
								//	Prevent the target from getting focused by
1943
								//	default, since the element to be focused will
1944
								//	be determined by weather or not the submenu
1945
								//	is visible.
1946
								event.preventDefault();
1947
 
1948
								//	FocusManager will attempt to focus any
1949
								//	descendant that is the target of the mousedown
1950
								//	event.  Since we want to explicitly control
1951
	 							//	where focus is going, we need to call
1952
								//	"stopImmediatePropagation" to stop the
1953
								//	FocusManager from doing its thing.
1954
								event.stopImmediatePropagation();
1955
 
1956
								//	The "_focusItem" method relies on the
1957
								//	"_hasFocus" property being set to true.  The
1958
								//	"_hasFocus" property is normally set via a
1959
								//	"focus" event listener, but since we've
1960
								//	blocked focus from happening, we need to set
1961
								//	this property manually.
1962
								menuNav._hasFocus = true;
1963
 
1964
							}
1965
 
1966
 
1967
							if (menuNav._isRoot(getParentMenu(oTarget))) {	//	Event target is a submenu label in the root menu
1968
 
1969
								//	Menu label toggle functionality
1970
 
1971
								if (hasVisibleSubmenu(oMenuLabel)) {
1972
 
1973
									menuNav._hideMenu(oSubmenu);
1974
									menuNav._focusItem(oMenuLabel);
1975
									menuNav._setActiveItem(oMenuLabel);
1976
 
1977
								}
1978
								else {
1979
 
1980
									menuNav._hideAllSubmenus(menuNav._rootMenu);
1981
									menuNav._showMenu(oSubmenu);
1982
 
1983
									menuNav._focusItem(getFirstItem(oSubmenu));
1984
									menuNav._setActiveItem(getFirstItem(oSubmenu));
1985
 
1986
								}
1987
 
1988
							}
1989
							else {	//	Event target is a submenu label within a submenu
1990
 
1991
								if (menuNav._activeItem == oMenuLabel) {
1992
 
1993
									menuNav._showMenu(oSubmenu);
1994
									menuNav._focusItem(getFirstItem(oSubmenu));
1995
									menuNav._setActiveItem(getFirstItem(oSubmenu));
1996
 
1997
								}
1998
								else {
1999
 
2000
									if (!oMenuLabel._clickHandle) {
2001
 
2002
										oMenuLabel._clickHandle = oMenuLabel.on("click", function () {
2003
 
2004
											menuNav._hideAllSubmenus(menuNav._rootMenu);
2005
 
2006
											menuNav._hasFocus = false;
2007
											menuNav._clearActiveItem();
2008
 
2009
 
2010
											oMenuLabel._clickHandle.detach();
2011
 
2012
											oMenuLabel._clickHandle = null;
2013
 
2014
										});
2015
 
2016
									}
2017
 
2018
								}
2019
 
2020
							}
2021
 
2022
						}
2023
 
2024
 
2025
						if (sType === CLICK) {
2026
 
2027
							//	Prevent the browser from following the URL of
2028
							//	the anchor element
2029
 
2030
							event.preventDefault();
2031
 
2032
						}
2033
 
2034
					}
2035
 
2036
				}
2037
 
2038
 
2039
			}
2040
 
2041
		}
2042
 
2043
	},
2044
 
2045
 
2046
	/**
2047
	* @method _onKeyPress
2048
	* @description "keypress" event handler for the menu.
2049
	* @protected
2050
	* @param {Object} event Object representing the DOM event.
2051
	*/
2052
	_onKeyPress: function (event) {
2053
 
2054
		switch (event.keyCode) {
2055
 
2056
			case 37:	//	left arrow
2057
			case 38:	//	up arrow
2058
			case 39:	//	right arrow
2059
			case 40:	//	down arrow
2060
 
2061
				//	Prevent the browser from scrolling the window
2062
 
2063
				event.preventDefault();
2064
 
2065
			break;
2066
 
2067
		}
2068
 
2069
	},
2070
 
2071
 
2072
	/**
2073
	* @method _onKeyDown
2074
	* @description "keydown" event handler for the menu.
2075
	* @protected
2076
	* @param {Object} event Object representing the DOM event.
2077
	*/
2078
	_onKeyDown: function (event) {
2079
 
2080
		var menuNav = this,
2081
			oActiveItem = menuNav._activeItem,
2082
			oTarget = event.target,
2083
			oActiveMenu = getParentMenu(oTarget),
2084
			oSubmenu;
2085
 
2086
		if (oActiveMenu) {
2087
 
2088
			menuNav._activeMenu = oActiveMenu;
2089
 
2090
			if (isHorizontalMenu(oActiveMenu)) {
2091
				menuNav._onHorizontalMenuKeyDown(event);
2092
			}
2093
			else {
2094
				menuNav._onVerticalMenuKeyDown(event);
2095
			}
2096
 
2097
 
2098
			if (event.keyCode === 27) {
2099
 
2100
				if (!menuNav._isRoot(oActiveMenu)) {
2101
 
2102
					if (UA.opera) {
2103
						later(0, menuNav, function () {
2104
							menuNav._hideMenu(oActiveMenu, true);
2105
						});
2106
					}
2107
					else {
2108
						menuNav._hideMenu(oActiveMenu, true);
2109
					}
2110
 
2111
					event.stopPropagation();
2112
					menuNav._blockMouseEvent = UA.gecko ? true : false;
2113
 
2114
				}
2115
				else if (oActiveItem) {
2116
 
2117
					if (isMenuLabel(oActiveItem) &&
2118
							hasVisibleSubmenu(oActiveItem)) {
2119
 
2120
						oSubmenu = oActiveItem.next();
2121
 
2122
						if (oSubmenu) {
2123
							menuNav._hideMenu(oSubmenu);
2124
						}
2125
 
2126
					}
2127
					else {
2128
 
2129
						menuNav._focusManager.blur();
2130
 
2131
						//	This is necessary for Webkit since blurring the
2132
						//	active menuitem won't result in the document
2133
						//	gaining focus, meaning the that _onDocFocus
2134
						//	listener won't clear the active menuitem.
2135
 
2136
						menuNav._clearActiveItem();
2137
 
2138
						menuNav._hasFocus = false;
2139
 
2140
					}
2141
 
2142
				}
2143
 
2144
			}
2145
 
2146
		}
2147
 
2148
	},
2149
 
2150
	/**
2151
	* @method _onDocMouseDown
2152
	* @description "mousedown" event handler for the owner document of
2153
	* the menu.
2154
	* @protected
2155
	* @param {Object} event Object representing the DOM event.
2156
	*/
2157
	_onDocMouseDown: function (event) {
2158
 
2159
		var menuNav = this,
2160
			oRoot = menuNav._rootMenu,
2161
			oTarget = event.target;
2162
 
2163
 
2164
		if (!(oRoot.compareTo(oTarget) || oRoot.contains(oTarget))) {
2165
 
2166
			menuNav._hideAllSubmenus(oRoot);
2167
 
2168
			//	Document doesn't receive focus in Webkit when the user mouses
2169
			//	down on it, so the "_hasFocus" property won't get set to the
2170
			//	correct value.  The following line corrects the problem.
2171
 
2172
			if (UA.webkit) {
2173
				menuNav._hasFocus = false;
2174
				menuNav._clearActiveItem();
2175
			}
2176
 
2177
		}
2178
 
2179
	}
2180
 
2181
});
2182
 
2183
 
2184
Y.namespace('Plugin');
2185
 
2186
Y.Plugin.NodeMenuNav = NodeMenuNav;
2187
 
2188
 
2189
}, '3.18.1', {"requires": ["node", "classnamemanager", "plugin", "node-focusmanager"], "skinnable": true});