Path: blob/trunk/third_party/closure/goog/ui/option.js
4062 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview A menu item class that supports selection state.8*/910goog.provide('goog.ui.Option');1112goog.require('goog.ui.Component');13goog.require('goog.ui.MenuItem');14goog.require('goog.ui.registry');15goog.requireType('goog.dom.DomHelper');16goog.requireType('goog.events.Event');17goog.requireType('goog.ui.ControlContent');18192021/**22* Class representing a menu option. This is just a convenience class that23* extends {@link goog.ui.MenuItem} by making it selectable.24*25* @param {goog.ui.ControlContent} content Text caption or DOM structure to26* display as the content of the item (use to add icons or styling to27* menus).28* @param {*=} opt_model Data/model associated with the menu item.29* @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper used for30* document interactions.31* @constructor32* @extends {goog.ui.MenuItem}33*/34goog.ui.Option = function(content, opt_model, opt_domHelper) {35'use strict';36goog.ui.MenuItem.call(this, content, opt_model, opt_domHelper);37this.setSelectable(true);38};39goog.inherits(goog.ui.Option, goog.ui.MenuItem);404142/**43* Performs the appropriate action when the option is activated by the user.44* Overrides the superclass implementation by not changing the selection state45* of the option and not dispatching any SELECTED events, for backwards46* compatibility with existing uses of this class.47* @param {goog.events.Event} e Mouse or key event that triggered the action.48* @return {boolean} True if the action was allowed to proceed, false otherwise.49* @override50*/51goog.ui.Option.prototype.performActionInternal = function(e) {52'use strict';53return this.dispatchEvent(goog.ui.Component.EventType.ACTION);54};555657// Register a decorator factory function for goog.ui.Options.58goog.ui.registry.setDecoratorByClassName(59goog.getCssName('goog-option'), function() {60'use strict';61// Option defaults to using MenuItemRenderer.62return new goog.ui.Option(null);63});646566