Developers › Dev.Opera

MenuItem.disabled

August 24, 2012 · by Opera Software

This functionality has not landed in a stable Opera version yet, but you can use it already in Opera Next.

Description:

The disabled attribute represents whether a menu item is visible in a context menu. If the value is false (default), the menu item will be displayed and is clickable, whereas if the value is true the item will not be displayed in the context menu.

Syntax:

Boolean false

Example:

In the following example, a menu item is created for translating the web page into English. The menu item is disabled (not visible) if the user's browser language is not set to English.

<!-- 
  The configuration file ('config.xml').
-->
<?xml version='1.0' encoding='utf-8'?>
<widget xmlns="http://www.w3.org/ns/widgets">
    ...
    <feature name="opera:contextmenus"/>
    ...
</widget>
//
// The background process (e.g. index.html)
//

if (opera.contexts.menu) {
  var menu = opera.contexts.menu;
  // Create a menu item properties object
  var itemProps = {
    title: 'Translate page into English',
    onclick: function(event) {
      doTranslate(event.pageURL);
    }
  }
  
  if (window.navigator.browserLanguage.indexOf('en') != 0) {
    itemProps.disabled = true;
  }

  // Create a menu item with the specified properties
  var item = menu.createItem(itemProps);
  // Add the menu item to the context menu
  menu.addItem(item);
}

About this article

Published inDev.Opera
DateAugust 24, 2012
AuthorOpera Software
Tagscontext menu, extensions API
OriginalInternet Archive