SafariExtensionMenuItem Class Reference

Inherits from
Technology area
Safari Extensions
Availability
Available in Safari 5.1 and later.

Overview

The SafariExtensionMenuItem class represents items in a menu.

Tasks

Identifying Menu Items

Working with Menu Items

Working with Menu Item State

Properties

checkedState

The state of the menu item.

attribute short checkedState
Discussion

For possible values, see “Menu Item States.” Any other value you set is ignored.

This property is ignored for separator items.

This property is optional; the default state is unchecked.

Availability

command

The command identifier that the menu item sends when activated.

attribute DOMString command
Discussion

If the submenu property is null, setting the value of this property to null, undefined, or the empty string has no effect.

If the submenu property is defined, validate events are sent using the value of this property; if this property is blank, events are sent using the menu item’s identifier.

Changes made to the command property take effect immediately, regardless of visibility.

Availability

disabled

A Boolean value that indicates whether a menu item is disabled.

attribute boolean disabled
Discussion

This property is optional; the default value is false.

Availability

identifier

The unique identifier of the menu item.

readonly attribute DOMString identifier
Availability

image

The URL of the image shown next to the menu item.

attribute DOMString image
Discussion

This attribute can be changed to the URL of an image in the extension bundle. Images larger than 16 x 16 pixels are scaled down to fit. Supported URL schemes are safari-extension, http, and https.

On Windows, if the menu item is checked, the icon is not displayed.

To support HiDPI, provide an image of the appropriate resolution at the same location, with the suffix @2x after its name. For example some/path/image-name@2x.png and some/path/image-name.png provide the same image at high resolution and standard resolution, respectively.

Availability

separator

A Boolean value that indicates whether the menu item is a separator.

readonly attribute boolean separator
Discussion

This attribute is optional; the default value is false.

Availability

submenu

The submenu displayed by this menu item.

attribute SafariExtensionMenu submenu
Discussion

If the separator property is true, the value of this property is ignored.

If the value of this property is null or undefined, no submenu is displayed.

If the value is a menu that is already being displayed, no submenu is displayed and this menu item’s command is dispatched. This prevents recursive menus.

If the menu item is visible, changes to this property are not reflected until the next time the menu item is displayed.

The behavior if the submenu is removed using the SafariExtension removeMenu method while the menu item is visible is undefined.

Availability

title

The title displayed in the menu.

attribute DOMString title
Discussion

If the separator property is true, the value of this property is ignored.

Setting this property to the empty string, null, or undefined has no effect.

Availability

visible

A Boolean value that indicates whether the menu item is visible.

readonly attribute boolean visible
Discussion

Changes made to the menu item while it is visible are not reflected until the next time it presented, except for changes made to the command property, which take effect immediately.

Availability

Constants

Menu Item States

The state of a menu item, indicated by a small icon displayed next to the title.

Constants
CHECKED

Checked state.

Available in Safari 5.1 and later.

MIXED

Mixed state.

On Windows, this is treated as CHECKED.

Available in Safari 5.1 and later.

UNCHECKED

Unchecked state.

Available in Safari 5.1 and later.