Yahoo! UI Library

Menu Library 

Yahoo! UI Library > menu > YAHOO.widget.Menu

Class YAHOO.widget.Menu - extends YAHOO.widget.Overlay

Known Subclasses:
YAHOO.widget.ContextMenu YAHOO.widget.Menubar
The Menu class creates a container that holds a vertical list representing a set of options or commands. Menu is the base class for all menu containers.

Constructor

YAHOO.widget.Menu ( p_oElement , p_oConfig )
Parameters:
p_oElement <String> String specifying the id attribute of the <div> element of the menu.
p_oElement <String> String specifying the id attribute of the <select> element to be used as the data source for the menu.
p_oElement <HTMLDivElement> Object specifying the <div> element of the menu.
p_oElement <HTMLSelectElement> Object specifying the <select> element to be used as the data source for the menu.
p_oConfig <Object> Optional. Object literal specifying the configuration for the menu. See configuration class documentation for more details.

Properties

_aGroupTitleElements - private Array

Array of HTML element used to title groups of menu items.
Default Value: []

_aItemGroups - private Array

Array of menu items.
Default Value: []

_aListElements - private Array

Array of <ul> elements, each of which is the parent node for each item's <li> element.
Default Value: []

_bHandledMouseOutEvent - private Boolean

Boolean indicating the current state of the menu's "mouseout" event.
Default Value: false

_bHandledMouseOverEvent - private Boolean

Boolean indicating the current state of the menu's "mouseover" event.
Default Value: false

_hideDelayEventHandlersAssigned - private Boolean

Boolean indicating if the "mouseover" and "mouseout" event handlers used for hiding the menu via a call to "window.setTimeout" have already been assigned.
Default Value: false

_nHideDelayId - private Number

Number representing the time-out setting used to cancel the hiding of a menu.
Default Value: null

_nShowDelayId - private Number

Number representing the time-out setting used to cancel the showing of a menu.
Default Value: null

activeItem - YAHOO.widget.MenuItem

Object reference to the item in the menu that has focus.
Default Value: null

CSS_CLASS_NAME - final String

String representing the CSS class(es) to be applied to the menu's <div> element.
Default Value: "yuimenu"

GROUP_TITLE_TAG_NAME - final String

String representing the tagname of the HTML element used to title the menu's item groups.
Default Value: H6

ITEM_TYPE - final YAHOO.widget.MenuItem

Object representing the type of menu item to instantiate and add when parsing the child nodes (either <li> element, <optgroup> element or <option>) of the menu's source HTML element.
Default Value: YAHOO.widget.MenuItem

itemData - Array

Array of items to be added to the menu. The array can contain strings representing the text for each item to be created, object literals representing the menu item configuration properties, or MenuItem instances. This property should be set via the constructor using the configuration object literal.
Default Value: null

lazyLoad - Boolean

Boolean indicating if the menu's "lazy load" feature is enabled. If set to "true," initialization and rendering of the menu's items will be deferred until the first time it is made visible. This property should be set via the constructor using the configuration object literal.
Default Value: false

parent - YAHOO.widget.MenuItem

Object reference to the menu's parent menu or menu item. This property can be set via the constructor using the configuration object literal.
Default Value: null

srcElement - HTMLSelectElement|HTMLDivElement

Object reference to the HTML element (either <select> or <div>) used to create the menu.
Default Value: null

Methods

_addItemToGroup

private YAHOO.widget.MenuItem _addItemToGroup ( p_nGroupIndex , p_oItem , p_nItemIndex )
Adds a menu item to a group.
Parameters:
p_nGroupIndex <Number> Number indicating the group to which the item belongs.
p_oItem <YAHOO.widget.MenuItem> Object reference for the MenuItem instance to be added to the menu.
p_oItem <String> String specifying the text of the item to be added to the menu.
p_oItem <Object> Object literal containing a set of menu item configuration properties.
p_nItemIndex <Number> Optional. Number indicating the index at which the menu item should be added.
Returns: YAHOO.widget.MenuItem

_cancelHideDelay

private void _cancelHideDelay ( )
Cancels the call to "hideMenu."
Returns: void

_cancelShowDelay

private void _cancelShowDelay ( )
Cancels the call to the "showMenu."
Returns: void

_checkPosition

private Boolean _checkPosition ( p_sPosition )
Checks to make sure that the value of the "position" property is one of the supported strings. Returns true if the position is supported.
Parameters:
p_sPosition <Object> String specifying the position of the menu.
Returns: Boolean

_configureSubmenu

private void _configureSubmenu ( p_oItem )
Subscribes the menu item's submenu to its parent menu's events.
Parameters:
p_oItem <YAHOO.widget.MenuItem> Object reference for the MenuItem instance with the submenu to be configured.
Returns: void

_createItemGroup

private Array _createItemGroup ( p_nIndex )
Creates a new menu item group (array) and its associated <ul> element. Returns an aray of menu item groups.
Parameters:
p_nIndex <Number> Number indicating the group to create.
Returns: Array

_execHideDelay

private void _execHideDelay ( )
Hides the menu after the number of milliseconds specified by the "hidedelay" configuration property.
Returns: void

_execShowDelay

private void _execShowDelay ( p_oMenu )
Shows the menu after the number of milliseconds specified by the "showdelay" configuration property have ellapsed.
Parameters:
p_oMenu <YAHOO.widget.Menu> Object specifying the menu that should be made visible.
Returns: void

_getFirstEnabledItem

private YAHOO.widget.MenuItem _getFirstEnabledItem ( )
Returns the first enabled item in the menu.
Returns: YAHOO.widget.MenuItem

_getItemGroup

private Array _getItemGroup ( p_nIndex )
Returns the menu item group at the specified index.
Parameters:
p_nIndex <Number> Number indicating the index of the menu item group to be retrieved.
Returns: Array

_getOffsetWidth

private void _getOffsetWidth ( )
Returns the offset width of the menu's <div> element.
Returns: void

_initSubTree

private void _initSubTree ( )
Iterates the childNodes of the source element to find nodes used to instantiate menu and menu items.
Returns: void

_onBeforeHide

private void _onBeforeHide ( p_sType , p_aArgs , p_oMenu )
"beforehide" event handler for the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_onBeforeRender

private void _onBeforeRender ( p_sType , p_aArgs , p_oMenu )
"beforerender" event handler for the menu. Appends all of the <ul>, <li> and their accompanying title elements to the body element of the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_onBeforeShow

private void _onBeforeShow ( p_sType , p_aArgs , p_oMenu )
"beforeshow" event handler for the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_onClick

protected void _onClick ( p_sType , p_aArgs , p_oMenu )
"click" event handler for the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_onInit

private void _onInit ( p_sType , p_aArgs , p_oMenu )
"init" event handler for the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_onKeyDown

protected void _onKeyDown ( p_sType , p_aArgs , p_oMenu )
"keydown" event handler for the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_onMenuItemBlur

private void _onMenuItemBlur ( p_sType , p_aArgs )
"blur" event handler for the menu's items.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
Returns: void

_onMenuItemConfigChange

private void _onMenuItemConfigChange ( p_sType , p_aArgs , p_oItem )
"configchange" event handler for the menu's items.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oItem <YAHOO.widget.MenuItem> Object representing the menu item that fired the event.
Returns: void

_onMenuItemFocus

private void _onMenuItemFocus ( p_sType , p_aArgs , p_oItem )
"focus" event handler for the menu's items.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oItem <YAHOO.widget.MenuItem> Object representing the menu item that fired the event.
Returns: void

_onMouseOut

protected void _onMouseOut ( p_sType , p_aArgs , p_oMenu )
"mouseout" event handler for the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_onMouseOver

protected void _onMouseOver ( p_sType , p_aArgs , p_oMenu )
"mouseover" event handler for the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_onParentMenuConfigChange

private void _onParentMenuConfigChange ( p_sType , p_aArgs , p_oSubmenu )
"configchange" event handler for a submenu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oSubmenu <YAHOO.widget.Menu> Object representing the submenu that subscribed to the event.
Returns: void

_onParentMenuRender

private void _onParentMenuRender ( p_sType , p_aArgs , p_oSubmenu )
"render" event handler for a submenu. Renders a submenu in response to the firing of its parent's "render" event.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oSubmenu <YAHOO.widget.Menu> Object representing the submenu that subscribed to the event.
Returns: void

_onRender

private void _onRender ( p_sType , p_aArgs , p_oMenu )
"render" event handler for the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_onShow

private void _onShow ( p_sType , p_aArgs , p_oMenu )
"show" event handler for the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_onSubmenuBeforeShow

private void _onSubmenuBeforeShow ( p_sType , p_aArgs , p_oSubmenu )
"beforeshow" event handler for a submenu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oSubmenu <YAHOO.widget.Menu> Object representing the submenu that subscribed to the event.
Returns: void

_onSubmenuHide

private void _onSubmenuHide ( p_sType , p_aArgs , p_oSubmenu )
"hide" Custom Event handler for a submenu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oSubmenu <YAHOO.widget.Menu> Object representing the submenu that subscribed to the event.
Returns: void

_onSubmenuShow

private void _onSubmenuShow ( p_sType , p_aArgs , p_oSubmenu )
"show" event handler for a submenu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oSubmenu <YAHOO.widget.Menu> Object representing the submenu that subscribed to the event.
Returns: void

_onTextResize

protected void _onTextResize ( p_sType , p_aArgs , p_oMenu )
"textresize" event handler for the menu.
Parameters:
p_sType <String> String representing the name of the event that was fired.
p_aArgs <Array> Array of arguments sent when the event was fired.
p_oMenu <YAHOO.widget.Menu> Object representing the menu that fired the event.
Returns: void

_removeItemFromGroupByIndex

private YAHOO.widget.MenuItem _removeItemFromGroupByIndex ( p_nGroupIndex , p_nItemIndex )
Removes a menu item from a group by index. Returns the menu item that was removed.
Parameters:
p_nGroupIndex <Number> Number indicating the group to which the menu item belongs.
p_nItemIndex <Number> Number indicating the index of the menu item to be removed.
Returns: YAHOO.widget.MenuItem

_removeItemFromGroupByValue

private YAHOO.widget.MenuItem _removeItemFromGroupByValue ( p_nGroupIndex , p_oItem )
Removes a menu item from a group by reference. Returns the menu item that was removed.
Parameters:
p_nGroupIndex <Number> Number indicating the group to which the menu item belongs.
p_oItem <YAHOO.widget.MenuItem> Object reference for the MenuItem instance to be removed.
Returns: YAHOO.widget.MenuItem

_subscribeToItemEvents

private void _subscribeToItemEvents ( p_oItem )
Subscribes a menu to a menu item's event.
Parameters:
p_oItem <YAHOO.widget.MenuItem> Object reference for the MenuItem instance whose events should be subscribed to.
Returns: void

_updateItemProperties

private void _updateItemProperties ( p_nGroupIndex )
Updates the "index," "groupindex," and "className" properties of the menu items in the specified group.
Parameters:
p_nGroupIndex <Number> Number indicating the group of items to update.
Returns: void

addItem

YAHOO.widget.MenuItem addItem ( p_oItem , p_nGroupIndex )
Appends an item to the menu.
Parameters:
p_oItem <YAHOO.widget.MenuItem> Object reference for the MenuItem instance to be added to the menu.
p_oItem <String> String specifying the text of the item to be added to the menu.
p_oItem <Object> Object literal containing a set of menu item configuration properties.
p_nGroupIndex <Number> Optional. Number indicating the group to which the item belongs.
Returns: YAHOO.widget.MenuItem

addItems

Array addItems ( p_aItems , p_nGroupIndex )
Adds an array of items to the menu.
Parameters:
p_aItems <Array> Array of items to be added to the menu. The array can contain strings specifying the text for each item to be created, object literals specifying each of the menu item configuration properties, or MenuItem instances.
p_nGroupIndex <Number> Optional. Number specifying the group to which the items belongs.
Returns: Array

clearActiveItem

void clearActiveItem ( p_bBlur )
Sets the "selected" configuration property of the menu's active item to "false" and hides the item's submenu.