BiMenu
This class represents a menu. Menus can be filled with menu items by adding BiMenuItem objects.
The content model for the menu is very similiar to the content model for BiComponent but there are slight differences.
This class extends BiEventTarget and therefore all methods and fields available for BiEventTarget are also available for BiMenu .
Constructor
new BiMenu ( )
Parameters
No parameters.
Properties
| Name | Type | get | set | Descripton |
children | | ![]() | The menu items added to the menu | |
component | | ![]() | If the menu was opened as a context menu for a component then this will point to the component that caused the menu to be shown. This will return null if the menu is hidden or not opened by a component (by setting visible manually). This is available during the beforeshow event even though the menu is not yet visible. It is also available when the hide event fires. | |
enabled | Boolean | ![]() | ![]() | Whether the menu is enabled. |
firstChild | | ![]() | Returns the first menu item child | |
height | Number | ![]() | ![]() | The height of the menu |
hideTimeStamp | Date | ![]() | The time when the menu was hidden. This can be useful to find out whether the popup was just hidden. | |
insetBottom | Number | ![]() | Border bottom width. | |
insetLeft | Number | ![]() | Border left width. | |
insetRight | Number | ![]() | Border right width. | |
insetTop | Number | ![]() | Border top width. | |
isEnabled | Boolean | ![]() | Whether the menu is enabled. | |
isVisible | Boolean | ![]() | Whether the menu is shown on the screen | |
lastChild | | ![]() | Returns the last menu item child | |
left | Number | ![]() | ![]() | The left position of the menu relative to the browser window (used to be screen!) |
parent | | ![]() | The parent menu item in case the menu acts as a sub menu | |
parentMenu | | ![]() | The parent menu in case the menu acts as a sub menu. This is the same as the parent of the parent menu item | |
preferredHeight | Number | ![]() | The preferred height of the menu | |
preferredWidth | Number | ![]() | The preferred width of the menu | |
rightToLeft | Boolean | ![]() | ![]() | Describes whether the component should be be layed out to support locales using right-to-left fonts. If this is set to null then the rightToLeft property for the parent component is used. |
screenLeft | Number | ![]() | The left position of the menu relative to screen | |
screenTop | Number | ![]() | The top position of the menu relative to screen | |
showTimeStamp | Date | ![]() | The time when the menu was shown. | |
top | Number | ![]() | ![]() | The top position of the menu relative to the browser window (used to be screen!) |
topLevelComponent | | ![]() | Returns the top level ancestor component. This is usually the application window hosting the application. | |
width | Number | ![]() | ![]() | The width of the menu |
Methods
| Name | Description |
add | Adds a menu item to the current menu. The added menu item becomes a child of the current menu. If the menu item is a child of another menu it is first removed from that menu. The second, optional, argument can be used to insert the new menu item before an existing child. If you know the index where you want to insert the item at you might want to consider using addAt instead. |
addAt | Adds a menu item at the given index to the current menu. The added menu item becomes a child of the current menu. If the menu item is a child of another menu it is first removed from that menu. |
contains | Returns true if the menu contains another menu item or menu. This means that the current component is an ancestor of the descendant. Note that the current component contains itself so calling component.contains(component) will return true. |
hasChildren | Returns true if the menu has any child menu items |
popupAtComponent | Displays the menu near a component. |
popupAtMouse | Displays the menu at the mouse coordinates of an event. |
remove | Removes an existing menu item from the component. |
removeAll | Removes all menu items. |
removeAt | Removes the menu item at the given index from the menu. |
selectFirstItem | Selects (and focuses) the first (top) visible and enabled item on the menu. If there are no visible and enabled items, the menu itself receives the focus. |
selectLastItem | Selects (and focuses) the last (bottom) visible and enabled item on the menu. If there are no visible and enabled items, the menu itself receives the focus. |
setLocation | Sets the top, left position relative to the browser window (used to be screen!) for the menu. |
setSize | Sets the width and height of the menu. |
Events
| Name | Type | Bubbles | Descripton |
beforeshow | | Fires before the menu is shown. This is a good place to change the content of the menu to reflect the component causing the menu to be shown | |
hide | | Fires when the menu is hidden | |
show | | Fires when the menu is shown |
Static Methods
None.
Static Fields
| Name | Type | Descripton |
SCROLL_DISTANCE | Number | The distance (in pixels) to scroll the menu at each interval. A small value here (default 5) will make the scrolling smooth, but slow. |
SCROLL_INTERVAL | Number | The interval (in millliseconds) between each scroll step. A smaller interval makes for faster scrolling (defaults to 30). |
Remarks
The location of the menu is relative to the screen. A menu can only be used as a sub menu for one menu item.
Method Details
add
Adds a menu item to the current menu. The added menu item becomes a child of the current menu. If the menu item is a child of another menu it is first removed from that menu. The second, optional, argument can be used to insert the new menu item before an existing child. If you know the index where you want to insert the item at you might want to consider using addAt instead.
Syntax
object.add ( oItem [ ,oBefore ] ) Parameters
| Name | Type | Optional | Default | Descripton |
oItem | | The menu item to add | ||
oBefore | | ![]() | The existing child do add the new menu item before |
Return Type
void
addAt
Adds a menu item at the given index to the current menu. The added menu item becomes a child of the current menu. If the menu item is a child of another menu it is first removed from that menu.
Syntax
object.addAt ( oChild,nIndex ) Parameters
| Name | Type | Optional | Default | Descripton |
oChild | | The menu item to add | ||
nIndex | Number | The index to add the item at |
Return Type
void
contains
Returns true if the menu contains another menu item or menu. This means that the current component is an ancestor of the descendant. Note that the current component contains itself so calling component.contains(component) will return true.
Syntax
object.contains ( oDescendant ) Parameters
| Name | Type | Optional | Default | Descripton |
oDescendant | Object | The BiMenu or BiMenuItem to test whether the current component contains it. |
Return Type
Boolean
hasChildren
Returns true if the menu has any child menu items
Syntax
object.hasChildren ( ) Parameters
No arguments.
Return Type
Boolean
popupAtComponent
Displays the menu near a component.
Syntax
object.popupAtComponent ( oComponent,bSelectFirst ) Parameters
| Name | Type | Optional | Default | Descripton |
oComponent | | the component | ||
bSelectFirst | Boolean | Whether to make the first (top) available item selected (and focused). Setting this parameter to false (or skipping it) instead focuses the menu itself and the user may select the first available item by pressing the down arrow. |
Return Type
void
popupAtMouse
Displays the menu at the mouse coordinates of an event.
Syntax
object.popupAtMouse ( oMouseEvent,bSelectFirst ) Parameters
| Name | Type | Optional | Default | Descripton |
oMouseEvent | | the event | ||
bSelectFirst | Boolean | Whether to make the first (top) available item selected (and focused). Setting this parameter to false (or skipping it) instead focuses the menu itself and the user may select the first available item by pressing the down arrow. |
Return Type
void
remove
Removes an existing menu item from the component.
Syntax
object.remove ( oItem ) Parameters
| Name | Type | Optional | Default | Descripton |
oItem | | The menu item to remove |
Return Type
removeAll
Removes all menu items.
Syntax
object.removeAll ( ) Parameters
No arguments.
Return Type
void
removeAt
Removes the menu item at the given index from the menu.
Syntax
object.removeAt ( nIndex ) Parameters
| Name | Type | Optional | Default | Descripton |
nIndex | Number | The index of the menu item to remove |
Return Type
selectFirstItem
Selects (and focuses) the first (top) visible and enabled item on the menu. If there are no visible and enabled items, the menu itself receives the focus.
Syntax
object.selectFirstItem ( ) Parameters
No arguments.
Return Type
void
selectLastItem
Selects (and focuses) the last (bottom) visible and enabled item on the menu. If there are no visible and enabled items, the menu itself receives the focus.
Syntax
object.selectLastItem ( ) Parameters
No arguments.
Return Type
void
setLocation
Sets the top, left position relative to the browser window (used to be screen!) for the menu.
Syntax
object.setLocation ( nLeft,nTop ) Parameters
| Name | Type | Optional | Default | Descripton |
nLeft | Number | The new left location for the menu | ||
nTop | Number | The new top location for the menu |
Return Type
void
setSize
Sets the width and height of the menu.
Syntax
object.setSize ( nWidth,nHeight ) Parameters
| Name | Type | Optional | Default | Descripton |
nWidth | Number | The new width for the menu | ||
nHeight | Number | The new height for the menu |
Return Type
void
