API: menu YAHOO.widget.ContextMenu (YUI Library)

# Yahoo! UI Library

### Menu 2.8.1

Yahoo! UI Library > menu > YAHOO.widget.ContextMenu
Search:
Filters Show Private Show Protected Show Deprecated

## Class YAHOO.widget.ContextMenu - extends YAHOO.widget.Menu

Creates a list of options or commands which are made visible in response to an HTML element's "contextmenu" event ("mousedown" for Opera).

### Constructor

YAHOO.widget.ContextMenu `( p_oElement , p_oConfig )`

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

### Properties

#### _bCancelled - `private Boolean`

Boolean indicating if the display of the context menu should be cancelled.
Default Value: false

#### _oTrigger - `private String|HTMLElement|Array`

Object reference to the current value of the "trigger" configuration property.
Default Value: null

#### contextEventTarget - `HTMLElement`

Object reference for the HTML element that was the target of the "contextmenu" DOM event ("mousedown" for Opera) that triggered the display of the context menu.
Default Value: null

#### DEFAULT_CONFIG - `private final Object`

Constant representing the ContextMenu's configuration properties

#### EVENT_TYPES - `private final Object`

Constant representing the name of the ContextMenu's events

#### Properties inherited from YAHOO.widget.Overlay:

`CONTEXT_TRIGGERS, DEFAULT_CONFIG, EVENT_TYPES, YAHOO.widget.Overlay._initialized`

#### Properties inherited from YAHOO.widget.Module:

`body, browser, cfg, contructor, DEFAULT_CONFIG, element, EVENT_TYPES, footer, header, id, imageRoot, isSecure, platform`

#### Properties inherited from YAHOO.widget.Menu:

`_aGroupTitleElements, _aItemGroups, _aListElements, _bHandledMouseOutEvent, _bHandledMouseOverEvent, _bStopMouseEventHandlers, _nCurrentMouseX, _sClassName, _useHideDelay, activeItem, CSS_CLASS_NAME, GROUP_TITLE_TAG_NAME, ITEM_TYPE, itemData, lazyLoad, OFF_SCREEN_POSITION, parent, srcElement`

### Methods

#### _onTriggerClick

`private void _onTriggerClick ( p_oEvent , p_oMenu )`
"click" event handler for the HTML element(s) identified as the "trigger" for the context menu. Used to cancel default behaviors in Opera.

Parameters:
  `p_oEvent <Event>` Object representing the DOM event object passed back by the event utility (YAHOO.util.Event).
  `p_oMenu <YAHOO.widget.ContextMenu>` Object representing the context menu that is handling the event.

#### _onTriggerContextMenu

`private void _onTriggerContextMenu ( p_oEvent , p_oMenu )`
"contextmenu" event handler ("mousedown" for Opera) for the HTML element(s) that trigger the display of the context menu.

Parameters:
  `p_oEvent <Event>` Object representing the DOM event object passed back by the event utility (YAHOO.util.Event).
  `p_oMenu <YAHOO.widget.ContextMenu>` Object representing the context menu that is handling the event.

#### _removeEventHandlers

`private void _removeEventHandlers ( )`
Removes all of the DOM event handlers from the HTML element(s) whose "context menu" event ("click" for Opera) trigger the display of the context menu.

#### cancel

`void cancel ( )`
Cancels the display of the context menu.

#### configTrigger

`void configTrigger ( p_sType , p_aArgs , p_oMenu )`
Event handler for when the value of the "trigger" configuration property changes.

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.ContextMenu>` Object representing the context menu that fired the event.

#### destroy

`void destroy ( )`
Removes the context menu's `<div>` element (and accompanying child nodes) from the document.

#### init

`void init ( p_oElement , p_oConfig )`
The ContextMenu class's initialization method. This method is automatically called by the constructor, and sets up all DOM references for pre-existing markup, and creates required markup if it is not already present.

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

#### initDefaultConfig

`void initDefaultConfig ( )`
Initializes the class's configurable properties which can be changed using the context menu's Config object ("cfg").

#### initEvents

`void initEvents ( )`
Initializes the custom events for the context menu.

#### position

`private void position ( p_sType , p_aArgs , p_aPos )`
"beforeShow" event handler used to position the contextmenu.

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_aPos <Array>` Array representing the xy position for the context menu.

#### toString

`String toString ( )`
Returns a string representing the context menu.

#### Methods inherited from YAHOO.widget.Overlay:

`_alignOnTrigger, _autoFillOnHeightChange, _findTriggerCE, _getComputedHeight, _getConstrainedPos, _getPreciseHeight, _preventOverlap, _primeXYFromDOM, _processTriggers, _setDomVisibility, _validateAutoFillHeight, align, bringToTop, center, configAutoFillHeight, configConstrainToViewport, configContext, configFixedCenter, configHeight, configIframe, configVisible, configWidth, configX, configXY, configY, configzIndex, destroy, doCenterOnDOMEvent, enforceConstraints, fillHeight, fitsInViewport, forceContainerRedraw, getConstrainedX, getConstrainedXY, getConstrainedY, hideIframe, hideMacGeckoScrollbars, init, initDefaultConfig, initEvents, moveTo, onDomResize, showIframe, showMacGeckoScrollbars, stackIframe, syncIframe, syncPosition, toString`

#### Methods inherited from YAHOO.widget.Module:

`_addToParent, _initResizeMonitor, _renderBody, _renderFooter, _renderHeader, _supportsCWResize, appendToBody, appendToFooter, appendToHeader, configMonitorResize, configVisible, destroy, hide, init, initDefaultConfig, initEvents, initResizeMonitor, onDomResize, render, setBody, setFooter, setHeader, show, toString`

#### Methods inherited from YAHOO.widget.Menu:

`_addItemToGroup, _cancelHideDelay, _cancelShowDelay, _clearSetWidthFlag, _configureSubmenu, _createItemGroup, _disableScrollFooter, _disableScrollHeader, _enableScrollFooter, _enableScrollHeader, _execHideDelay, _execSubmenuHideDelay, _getFirstEnabledItem, _getItemGroup, _initSubTree, _onBeforeHide, _onBeforeRender, _onBeforeShow, _onBlur, _onClick, _onHide, _onInit, _onItemAdded, _onKeyDown, _onKeyPress, _onMenuItemConfigChange, _onMenuItemDestroy, _onMouseMove, _onMouseOut, _onMouseOver, _onParentMenuConfigChange, _onParentMenuRender, _onRender, _onScrollTargetMouseOut, _onScrollTargetMouseOver, _onShow, _onVisibleChange, _onYChange, _removeItemFromGroupByIndex, _removeItemFromGroupByValue, _setMaxHeight, _setScrollHeight, _subscribeToItemEvents, _updateItemProperties, addItem, addItems, blur, checkPosition, clearActiveItem, clearContent, configClassName, configContainer, configDisabled, configHideDelay, configIframe, configMaxHeight, configPosition, configShadow, configVisible, destroy, focus, getItem, getItemGroups, getItems, getRoot, getSubmenus, hasFocus, init, initDefaultConfig, initEvents, insertItem, positionOffScreen, removeItem, setInitialFocus, setInitialSelection, setItemGroupTitle, subscribe, toString`

### Events

#### triggerContextMenuEvent

`triggerContextMenuEvent ( )`
Custom Event wrapper for the "contextmenu" DOM event ("mousedown" for Opera) fired by the element(s) that trigger the display of the context menu.

#### Events inherited from YAHOO.widget.Overlay:

`beforeMoveEvent, moveEvent, YAHOO.widget.Overlay.windowResizeEvent, YAHOO.widget.Overlay.windowScrollEvent,`

#### Events inherited from YAHOO.widget.Module:

`appendEvent, beforeHideEvent, beforeInitEvent, beforeRenderEvent, beforeShowEvent, changeBodyEvent, changeContentEvent, changeFooterEvent, changeHeaderEvent, destroyEvent, hideEvent, initEvent renderEvent showEvent YAHOO.widget.Module.textResizeEvent`

#### Events inherited from YAHOO.widget.Menu:

`clickEvent, itemAddedEvent, itemRemovedEvent, keyDownEvent, keyPressEvent, keyUpEvent, mouseDownEvent, mouseOutEvent, mouseOverEvent, mouseUpEvent,`

### Configuration Attributes

#### trigger `- String|HTMLElement|Array`

The HTML element(s) whose "contextmenu" event ("mousedown" for Opera) trigger the display of the context menu. Can be a string representing the id attribute of the HTML element, an object reference for the HTML element, or an array of strings or HTML element references.
Default Value: null

#### Configuration attributes inherited from YAHOO.widget.Overlay:

`autofillheight, constraintoviewport, context, fixedcenter, height, iframe preventcontextoverlap width x xy y zIndex`

#### Configuration attributes inherited from YAHOO.widget.Module:

`appendtodocumentbody, effect monitorresize visible`

#### Configuration attributes inherited from YAHOO.widget.Menu:

`autosubmenudisplay, classname, clicktohide, constraintoviewport, container, context, disabled, effect, fixedcenter, hidedelay, iframe, keepopen, maxheight minscrollheight position preventcontextoverlap scrollincrement shadow showdelay submenualignment submenuhidedelay visible x xy y`

Copyright © 2010 Yahoo! Inc. All rights reserved.