DomAPI Home
DomAPI

domapi.Popupmenu

See also: Elm
See also: Component

This component is used as the dropdown menus in MenuBar. It can also be used as a stand-alone popup menu. Supports infinite cascading submenus, images, drop-shadows, checked items and radio items.

 


Popupmenu Example: system, aqua

Popupmenu Constructor

var popupmenu1 = domapi.Popupmenu({
  chevron        : "►",
  doImages       : true,
  doShadow       : true,
  mouseButton    : 1,
  doIframeShield : true 
});
Also inherits the construtor arguments of Elm and Component.

Constructor Details
Parameter Type Default Description
chevron String ►    
doImages boolean true    
doShadow boolean true    
mouseButton integer   
doIframeShield boolean true    

Events unique to domapi.Popupmenu

Also has the same events as Elm and Component.

Methods unique to domapi.Popupmenu

Properties unique to domapi.Popupmenu

Also has the same properties as Elm and Component.

Events
onbeforepopup ()

When used as a context menu, this events fires just before the menu is shown. You must return a boolean to signify whether the menu is allowed to be shown or not.

back to top
onpopup ()

Fires after the menu opens.

back to top
onselect ()

This event fires after the user has selected a menu item and just before fn is evaluated.
item is a pointer to the item that has clicked.

back to top
Methods
addChildMenu( arg ) type : Object

The "arg" parameter fed to this method is an inline Object. See below for accepted parameters.
Any parameters not listed here that you add may also be attached to any returned Object.

Creates a cascading childmenu for a specified menuitem. This method returns a reference to this new childMenu, which can then be used to add more items to.

Available "arg" Parameters:
Parameter Type Required Default Description
parent variant Y   Menuitem to add the child to. Can be either a reference or an index. 
back to top
addItem( arg ) type : Object

The "arg" parameter fed to this method is an inline Object. See below for accepted parameters.
Any parameters not listed here that you add may also be attached to any returned Object.

Adds a brand new item to the menu. text if the text that will be displayed and onclick is some optional Javascript to perform should the user select the item.
Returns a reference to the new item.

Example:
  menu1.addItem({text:"Exit", onclick:myFunc, name:"item1"});
menu1.setChecked(menu1.item1);
Available "arg" Parameters:
Parameter Type Required Default Description
text String Y   Displayed text 
img String     Path of the image to be used. This can be an Imagelist, with enabled and disabled images. 
name String   miCamelCased name  When menuitems are named, you can then refer to them directly through the Popupmenu using dot notation. Defaults to a camel-case version of the text property. 
visible boolean   true    
enabled boolean   true    
imgW integer   16    
imgH integer   16    
checked boolean   false  Determines whether a checkbox appears next to the menuitem. Cannot be used with images. 
autoCheck boolean   false  Allows an item to be toggled on and off by the user. Use the checked property to control the initial state. 
radioGroup integer   null  If numerous items are given the same radioGroup number, they function as a set of radiobuttons. You can pass checked to one of them to set the intial state. Cannot be used with images. 
back to top
addSeparator () type : HTMLElement

Adds a new separator to the menu and returns a reference to it.

Example:
  // add a separator line
menu1.addSeparator();
back to top
attach ()

Makes this menu the context menu for the specified element.

Example:
  menu1.attach(domapi.getElm("id"));
back to top
closeMenus ()

Closes all childMenus owned by any items in this menu.

back to top
getText ( i ) type : String

Returns the text of a menuitem.

Parameters:
Parameter Type Required Default Description
i variant Y   Item reference or index. 
back to top
hideItem ( i )

 

Parameters:
Parameter Type Required Default Description
i variant Y   Item reference or index. 
back to top
loadFromJson ( json )

Populates the menu via a specially structured Javascript object.

Example:
  var jsonString = {
  doImages:true,
  items:[
    {text:"Clear Text",onselect:"elm2.setText('')", img:"delete.gif", enabled:false},
    {text:"Set Text",  onselect:"getNewText()",     img:"edit.gif"},
    {type:"separator"},
    {text:"Background", onselect:pickBgColor, childMenu:{
        items:[
          {text:"Red",   radioGroup:1},
          {text:"White", radioGroup:1, checked:true},
          {text:"Blue",  radioGroup:1}
        ]
      }
    },
    {text:"Foreground", onselect:pickFgColor, childMenu:{
        items:[
          {text:"Red",   radioGroup:1},
          {text:"White", radioGroup:1},
          {text:"Blue",  radioGroup:1},
          {text:"Black", radioGroup:1, checked:true}
        ]
      }
    },
    {text:"shouldn't see me"},
    {text:"...or me", visible:false},
    {text:"disabled", enabled:false}
  ]
};
menu1.loadFromJson(jsonString);
Parameters:
Parameter Type Required Default Description
json Object Y   The JSON object. 
back to top
setChecked ( i, b )

Sets the 'checked' flag for a given item.

Parameters:
Parameter Type Required Default Description
i variant Y   Item reference or index. 
b boolean   false  true/false value 
back to top
setEnabled ( i, b )

Enables/disables an item.

Example:
  menu1.setEnabled(menu1.itemName, true);
Parameters:
Parameter Type Required Default Description
i variant Y   Item reference or index. 
b boolean   false  true/false value 
back to top
setImage ( i, src )

Changes the src of a given menuitem's image.

Example:
  menu1.setImage(menu1.item1, 'image.gif');
Parameters:
Parameter Type Required Default Description
i variant Y   Item reference or index. 
src String Y   Image src. 
back to top
setText ( i, text )

Sets the text of a menuitem.

Example:
  menu1.setText(2, "new text");
Parameters:
Parameter Type Required Default Description
i variant Y   Item reference or index. 
text String Y   New text. 
back to top
showItem ( i )

 

Parameters:
Parameter Type Required Default Description
i variant Y   Item reference or index. 
back to top
Properties
chevron type : String default value : ▶ (unicode for ▶)

This is the icon that will be displayed when a menuitem has a submenu that can be displayed.

back to top
items type : Collection

Each item that is added shows up in this collection.

back to top
DHTML by www.domapi.com