PopMenuItem Class
Constructor
PopMenuItem(options)
A PopMenuItem object represents a menu item on a context menu.
-
options: Object
Menu item options. See Options section for the
list of available options.
// EXAMPLE //
var menuItem = new PopMenuItem({
id: 'new',
label: 'New',
icon: 'new'
});
Options
action: function
since 1.0
A callback to be executed when a menu item is selected. Assigning this option
will override any existing 'action' callbacks. To add multiple callbacks,
please use on() method instead.
disabled: boolean = false
since 1.0
Disable menu item.
href: string
since 1.0
URL to open when the item is selected.
icon: string
since 1.0
Icon common name or icon path to use. When specifying relative path, the path
is relative to the directory of the HTML page.
id: string
since 1.0
ID of the menu item.
label: string
since 1.0
Label of the menu item. If not specified, the menu item will act as a
separator.
submenu: PopMenu
since 1.0
An item can have a submenu. In this case, a collection of PopMenuItems or an
instance of PopMenu can be assigned to this option.
// Example usage of inline submenu creation
var item = new PopMenuItem({
id: 'view',
label: 'View Mode',
submenu: {
viewThumb: {label: 'Thumbnails'},
viewIcon: {label: 'Icons'},
viewList: {label: 'List'},
viewTree: {label: 'Tree'}
}
});
// Example usage of a submenu created beforehand
var submenu = new PopMenu({
viewThumb: {label: 'Thumbnails'},
viewIcon: {label: 'Icons'},
viewList: {label: 'List'},
viewTree: {label: 'Tree'}
});
var item = new PopMenuItem({
id: 'view',
label: 'View Mode',
submenu: submenu
});
target: string
since 1.0
Open the URL specified in href on the specified target window.
Specify _blank to open in a new window.
type: string = "item"
since 1.0
item|separator
Specify the type of the menu.
visible: boolean = true
since 1.0
Toggle visibility.
Properties
$: jQuery
since 1.0
Reference to DOM (jQuery) representation of the menu item.
$icon: jQuery
since 1.0
Reference to DOM (jQuery) representation of the menu item's icon (PopMenu-Icon).
$link: jQuery
since 1.0
Reference to DOM (jQuery) representation of the menu item's label (PopMenu-Link).
data: Object
since 1.0
Internally stores the menu item options. Please use options() method
to get/set menu item options.
callbacks: Object
since 1.0
Stores event callbacks internally. Please use on() or off() to
bind or unbind callbacks instead.
submenu: PopMenu
since 1.0
Access to the submenu object.
Events
action
since 1.0
Triggered when a menu item is selected.
$(elm).popmenu().find('item_id').on('action', callback);
Methods
disable: boolean
since 1.0
disable([disabled])
Enable/disable menu item, or check current disable state.
-
disable: boolean
Assign true/false to enable/disable menu item. Leave blank to get current state.
// To disable an item
$(elm).popmenu().find('item_id').disable(true);
// To get current state
var state = $(elm).popmenu().find('item_id').disable();
hide: void
since 1.0
hide()
Set menu item visibility to hidden. Use show() to show.
// To hide an item
$(elm).popmenu().find('item_id').hide();
href: string
since 1.0
href([url])
Get/set href property, a URL to open when the item is selected.
-
url: string
URL to open when the item is selected.
// To assign a link
$(elm).popmenu().find('item_id').href("http://www.doublejar.com");
// To get currently assigned link
var link = $(elm).popmenu().find('item_id').href();
icon: string
since 1.0
icon([icon])
Get/set icon for the menu item.
-
icon: string
Icon name or path.
// To set common icon (icons defined in CSS file, such as jquery.popmenu.icons.css)
$(elm).popmenu().find('item_id').icon('add');
// To set a specific icon file
$(elm).popmenu().find('item_id').icon('img/home.png');
// To get current icon name/path
var icon = $(elm).popmenu().find('item_id').icon();
label: string
since 1.0
label([label])
Get/set label for the menu item.
-
label: string
Label for the menu item.
// To set item label
$(elm).popmenu().find('item_id').icon('Open...');
// To get current label
var label = $(elm).popmenu().find('item_id').label();
off: void
since 1.0
off(event)
Unbind event callbacks.
-
event: string
Event name.
// To remove events
$(elm).popmenu().find('item_id').off('action');
on: void
since 1.0
on(event, callback)
Bind a callback to an event.
-
event: string
Event name.
-
callback: function
Callback to be executed when the event is triggered.
// To assign 'action' event callback
$(elm).popmenu().find('helloItem').on('action', function() {
alert("Hello");
});
options: object
since 1.0
options([options])
Get/set menu item options. The options set or returned from this methods are
from data property, which contains options bound to the
PopMenu object.
-
options: object
Options to be set, please refer to Options section for list of available options.
If none is specified, the method will act as getter.
// To retrieve options
var options = $(elm).popmenu().find('new').options();
// To set the item label via options() method
$(elm).popmenu().find('new').options({label: 'New File'});
show: void
since 1.0
show()
Set menu item visibility to visible. Use hide() to hide.
// To show an item
$(elm).popmenu().find('item_id').show();
updateLabel: void
since 1.0
updateLabel([force])
Update menu label. Particularly used when a function is assigned to the item
label instead of string. To assign a new label, please use label()
instead.
-
force: boolean = false
If set to false, only item with dynamic label (ie. function) will be updated.
// To update current label
$(elm).popmenu().find('item_id').updateLabel();
visible: boolean
since 1.0
visible([value])
Toggle visibility of the menu item, or check current disable state.
-
visible: boolean
Assign true/false to show/hide menu item. Leave blank to get current state.
// To hide an item
$(elm).popmenu().find('item_id').visible(false);
// To get current state
var state = $(elm).popmenu().find('item_id').visible();