API Docs for:
Show:

gallery-contextmenu-view Module

This module includes a Y.View class extension that attaches to an existing "trigger" Node and uses event delegation to listen for "contextmenu" requests (i.e. right-click). When the context menu is invoked, a Y.Overlay object is rendered and displayed as a popup that includes user-defined menu items that are related to the context where the menu was invoked.

This view utilizes several attributes and fires several events that users can listen to in order to take specific actions based on the "trigger target" node.

Please refer to the trigger ATTRIBUTE for more description of the target.node and target.trigger.

Usage

To configure a bare-bones basic contextmenu, you need to provide the trigger and menuItems attributes as;

var cmenu = new Y.ContextMenuView({
   trigger: {
       node:   Y.one(".myExistingContainer"),
       target:  'li'
   },
   menuItems: [ "Add", "Edit", "Delete" ]

});

The menuItems can be simple entries or Objects, if they are Objects the "label" property will be used to fill the visible Menu (See menuItems).

Attributes / Events

An implementer is typically interested in listening to the following ATTRIBUTE "change" events;

  • selectedMenuChange : which fires when a contextmenu choice is clicked (see selectedMenu)
  • contextTargetChange: which fires when the user "right-clicks" on the target.node (see contextTarget)

Additionally please refer to the Events section for more information on available events.