Menu class

From PhiWiki
Jump to: navigation, search
Pagesettingsmenu.png

Describes the menu of a document. You can react on menu items which are selected by the user. This is a special Phi class. The Menu class is a sub class of the PhiBase class and only available in the Application mode of Phi. Menus can be disabled, checked and you can even define icons for each entry.

See also: Page settings menu.

Usage

The Menu class provides many additional functions in the Phi environment which are not available in XHTML so they will be completely ignored outside Phi. The document must run in application mode since normal operating browsers have their own menu entries which can not be changed by scripting. Each menu entry has its own ID.

You reference the menu thru the PhiBase class:

var m=phi.menu;

Reimplement the following function to react on menu entry actions:

phi.menu.activated=function( id, checked ) {
  phi.alert( 'Menu entry with id '+id+' was activated.' );
}

Properties

There are currently no properties defined.

Functions

Void addCheckableMenuItem()

Adds a menu item with id and text to the menu with IDparent_id and optional a shortcut. The item will be checked if 'isChecked' is true.

phi.menu.addCheckableMenuItem( parent_id, id, text, isChecked=false, shortcut=String() );
phi.menu.addCheckableMenuItem( 'edit_id', 'mirror_id', 'Mirror', true, 'Ctrl-M' );
phi.menu.addCheckableMenuItem( 'edit_id', 'rotate_id', 'Rotate' ); // without a shortcut

See also: phi.menu.setShortcut().

Void addMenu()

Adds a menu with id and text to the menu bar or creates a submenu if parent_id is not empty.

phi.menu.addMenu( id, text, parent_id=String() );
phi.menu.addMenu( 'edit_id', 'Edit' );

Void addMenuItem()

Adds a menu item with id and text to the menu with ID parent_id and an optional shortcut.

phi.menu.addMenuItem( parent_id, id, text, shortcut=String() );
phi.menu.addMenuItem( 'edit_id', 'cut_id', 'Cut', 'Ctrl-C' );
phi.menu.addMenuItem( 'edit_id', 'paste_id', 'Paste' ); // without a shortcut

See also: phi.menu.setShortcut().

Boolean isCheckable()

Returns true if the menu item with id is checkable.

var chkable=phi.menu.isCheckable( 'id' );

If the id does not exist this function will return false.

Boolean isChecked()

Returns true if the menu item menu_id is checked.

var chk=phi.menu.isChecked( 'menu_id' );

Note: uncheckable menu items always return false.

Boolean isEnabled()

Returns true if the menu item is enabled. Disabled menu items can not be selected and are grayed out.

var chk=phi.menu.isEnabled( 'menu_id' );

Void removeMenuItem()

Removes the a menu or menu item with the ID menu_id.

phi.menu.removeMenuItem( 'menu_id' );

String shortcut()

Returns the shortcut string for the menu item with ID menu_id.

var sc=phi.menu.shortcut( 'menu_id' );

Void setChecked()

Checks or unchecks a checkable menu item with ID menu_id by setting true or false.

phi.menu.setChecked( 'menu_id', true );

Void setEnabled()

Enables or disables the menu or menu item with ID menu_id by setting true or false.

phi.menu.setEnabled( 'menu_id', false );

Void setShortcut()

Sets the shortcut sc for menu item with ID menu_id.

phi.menu.setShortcut( 'menu_id', 'Ctrl-C' );

Void setText()

Sets the text menu_text for the menu or menu item with ID menu_id.

phi.menu.setText( 'menu_id', 'menu_text' );

String text()

Returns the text for the menu or menu item with ID menu_id.

var mtext=phi.menu.text( 'menu_id' );

Additional notes

The menu feature is mostly usefull in intranet appliations where you want to provide special menus. You should define it in a Master template page, so the menu structure will be copied to the current page as long as the current page does not provide its own menu.

Menus make hardly sense in the Internet environment since a user must have the PhiPlugin installed to be able to use menus.