UNPKG

@qooxdoo/framework

Version:

The JS Framework for Coders

104 lines (83 loc) 2.53 kB
/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de License: MIT: https://opensource.org/licenses/MIT See the LICENSE file in the project's top-level directory for details. Authors: * Sebastian Werner (wpbasti) * Fabian Jakobs (fjakobs) ************************************************************************ */ /** * The real menu button class which supports a command and an icon. All * other features are inherited from the {@link qx.ui.menu.AbstractButton} * class. */ qx.Class.define("qx.ui.menu.Button", { extend: qx.ui.menu.AbstractButton, /* ***************************************************************************** CONSTRUCTOR ***************************************************************************** */ /** * @param label {String} Initial label * @param icon {String} Initial icon * @param command {qx.ui.command.Command} Initial command (shortcut) * @param menu {qx.ui.menu.Menu} Initial sub menu */ construct(label, icon, command, menu) { super(); // ARIA attrs this.getContentElement().setAttribute("role", "button"); // Initialize with incoming arguments if (label != null) { this.setLabel(label); } if (icon != null) { this.setIcon(icon); } if (command != null) { this.setCommand(command); } if (menu != null) { this.setMenu(menu); } }, /* ***************************************************************************** PROPERTIES ***************************************************************************** */ properties: { // overridden appearance: { refine: true, init: "menu-button" } }, /* ***************************************************************************** MEMBERS ***************************************************************************** */ members: { /* --------------------------------------------------------------------------- EVENT HANDLER --------------------------------------------------------------------------- */ // overridden _onTap(e) { if (e.isLeftPressed() && this.getMenu()) { this.execute(); // don't close menus if the button is a sub menu button this.getMenu().open(); return; } super._onTap(e); } } });