mozilla

Revision 439461 of update

  • Revision slug: Extensions/Mobile/API/NativeWindow/menu/update
  • Revision title: update
  • Revision id: 439461
  • Created:
  • Creator: MarkFinkle
  • Is current revision? No
  • Comment

Revision Content

The NativeWindow object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.

Summary

NativeWindow.menu.add() adds an item to the main menu in Firefox for Android, returning an ID for the item. To update the item, use NativeWindow.menu.update(), passing in the item's ID and a set of attributes to update.

Syntax

window.NativeWindow.menu.update(menuID, options);

menuID
The ID of the item to update.
options
The Javascript object specifying the set of attributes to update. The current set of supported options are:
  • checkable - Boolean specifying whether the item should be checkable.
  • checked - Boolean specifying whether the item should be checked.
  • enabled - Boolean specifying whether the item should be enabled.
  • visible - Boolean specifying whether the item should be checkable.

Example

The following example adds a menu item with the label "Desktop Mode" which can be toggled.

var menuID;  
var isChecked = false;  
 
function addMenuItem(window) {  
  menuID = window.NativeWindow.menu.add({  
    name: "Desktop Mode",  
    icon: null,  
    checkable: true,   // specifies the toggling behavior of the item.  
    callback: function(){  
      toggleWindow(window);   
  });  
}  
 
function toggleDesktopMode(window) {  
  isChecked = !isChecked;
  window.NativeWindow.menu.update(menuID, {
   checked: isChecked   // updates the checked state of the item.  
  });  
}  

See Also

Revision Source

<div class="note">
  The <a href="/en/Extensions/Mobile/API/NativeWindow" title="https://developer.mozilla.org/en/DOM/window.NativeWindow">NativeWindow</a> object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p><code><a href="/en/Extensions/Mobile/API/NativeWindow/menu" title="https://developer.mozilla.org/en/DOM/window.NativeWindow.menu">NativeWindow.menu</a>.add() </code>adds an item to the main menu in <a href="/en/Mozilla/Firefox_for_Android" title="https://developer.mozilla.org/en/Mozilla/Firefox_for_Android">Firefox for Android</a>, returning an ID for the item. To update the item, use <code>NativeWindow.menu.update()</code>, passing in the item's ID and a set of attributes to update.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<p><code><em>window.NativeWindow.menu.update</em><em>(menuID, options);</em></code></p>
<dl>
  <dt>
    <code>menuID</code></dt>
  <dd>
    The ID of the item to update.</dd>
  <dt>
    <code>options</code></dt>
  <dd>
    The Javascript object specifying the set of attributes to update. The current set of supported options are:
    <ul>
      <li><code>checkable</code> - Boolean specifying whether the item should be checkable.</li>
      <li><code>checked</code> - Boolean specifying whether the item should be checked.</li>
      <li><code>enabled</code> - Boolean specifying whether the item should be enabled.</li>
      <li><code>visible</code> - Boolean specifying whether the item should be checkable.</li>
    </ul>
  </dd>
</dl>
<h2 id="Example" name="Example">Example</h2>
<p>The following example adds a menu item with the label "Desktop Mode" which can be toggled.</p>
<pre class="brush: js">
var menuID; &nbsp;
var isChecked = false; &nbsp;
&nbsp;
function addMenuItem(window) { &nbsp;
&nbsp; menuID = window.NativeWindow.menu.add({ &nbsp;
&nbsp;&nbsp;&nbsp; name: "Desktop Mode", &nbsp;
&nbsp;&nbsp;&nbsp; icon: null, &nbsp;
&nbsp;&nbsp;&nbsp; checkable: true, &nbsp; // specifies the toggling behavior of the item. &nbsp;
&nbsp;&nbsp;&nbsp; callback: function(){ &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; toggleWindow(window);&nbsp; &nbsp;
&nbsp; }); &nbsp;
} &nbsp;
&nbsp;
function toggleDesktopMode(window) { &nbsp;
&nbsp; isChecked = !isChecked;
&nbsp; window.NativeWindow.menu.update(menuID, {
&nbsp;&nbsp; checked: isChecked &nbsp; // updates the checked state of the item. &nbsp;
&nbsp; }); &nbsp;
} &nbsp;
</pre>
<h2 id="Specification" name="Specification">See Also</h2>
Revert to this revision