tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

menu-item.js (2735B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /**
      8 * A partial implementation of the MenuItem API provided by electron:
      9 * https://github.com/electron/electron/blob/master/docs/api/menu-item.md.
     10 *
     11 * Missing features:
     12 *   - id String - Unique within a single menu. If defined then it can be used
     13 *                 as a reference to this item by the position attribute.
     14 *   - role String - Define the action of the menu item; when specified the
     15 *                   click property will be ignored
     16 *   - sublabel String
     17 *   - accelerator Accelerator
     18 *   - position String - This field allows fine-grained definition of the
     19 *                       specific location within a given menu.
     20 *
     21 * Implemented features:
     22 *
     23 *  @param Object options
     24 *    String accelerator
     25 *      Text that appears beside the menu label to indicate the shortcut key
     26 *      (accelerator key) to use to invoke the command.
     27 *      Unlike the Electron API, this is a label only and does not actually
     28 *      register a handler for the key.
     29 *    String accesskey [non-standard]
     30 *      A single character used as the shortcut key. This should be one of the
     31 *      characters that appears in the label.
     32 *    Function click
     33 *      Will be called with click(menuItem, browserWindow) when the menu item
     34 *       is clicked
     35 *    String type
     36 *      Can be normal, separator, submenu, checkbox or radio
     37 *    String label
     38 *    String image
     39 *    Boolean enabled
     40 *      If false, the menu item will be greyed out and unclickable.
     41 *    Boolean checked
     42 *      Should only be specified for checkbox or radio type menu items.
     43 *    Menu submenu
     44 *      Should be specified for submenu type menu items. If submenu is specified,
     45 *      the type: 'submenu' can be omitted. If the value is not a Menu then it
     46 *      will be automatically converted to one using Menu.buildFromTemplate.
     47 *    Boolean visible
     48 *      If false, the menu item will be entirely hidden.
     49 */
     50 function MenuItem({
     51  accelerator = null,
     52  accesskey = null,
     53  l10nID = null,
     54  checked = false,
     55  click = () => {},
     56  disabled = false,
     57  hover = () => {},
     58  id = null,
     59  label = "",
     60  image = null,
     61  submenu = null,
     62  type = "normal",
     63  visible = true,
     64 } = {}) {
     65  this.accelerator = accelerator;
     66  this.accesskey = accesskey;
     67  this.l10nID = l10nID;
     68  this.checked = checked;
     69  this.click = click;
     70  this.disabled = disabled;
     71  this.hover = hover;
     72  this.id = id;
     73  this.label = label;
     74  this.image = image;
     75  this.submenu = submenu;
     76  this.type = type;
     77  this.visible = visible;
     78 }
     79 
     80 module.exports = MenuItem;