| 1 |
// Copyright 2007 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview A menu item class that supports selection state. |
| 17 |
* |
| 18 |
* @author [email protected] (Attila Bodis) |
| 19 |
*/ |
| 20 |
|
| 21 |
goog.provide('goog.ui.Option'); |
| 22 |
|
| 23 |
goog.require('goog.ui.Component'); |
| 24 |
goog.require('goog.ui.MenuItem'); |
| 25 |
goog.require('goog.ui.registry'); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* Class representing a menu option. This is just a convenience class that |
| 31 |
* extends {@link goog.ui.MenuItem} by making it selectable. |
| 32 |
* |
| 33 |
* @param {goog.ui.ControlContent} content Text caption or DOM structure to |
| 34 |
* display as the content of the item (use to add icons or styling to |
| 35 |
* menus). |
| 36 |
* @param {*=} opt_model Data/model associated with the menu item. |
| 37 |
* @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper used for |
| 38 |
* document interactions. |
| 39 |
* @constructor |
| 40 |
* @extends {goog.ui.MenuItem} |
| 41 |
*/ |
| 42 |
goog.ui.Option = function(content, opt_model, opt_domHelper) { |
| 43 |
goog.ui.MenuItem.call(this, content, opt_model, opt_domHelper); |
| 44 |
this.setSelectable(true); |
| 45 |
}; |
| 46 |
goog.inherits(goog.ui.Option, goog.ui.MenuItem); |
| 47 |
|
| 48 |
|
| 49 |
/** |
| 50 |
* Performs the appropriate action when the option is activated by the user. |
| 51 |
* Overrides the superclass implementation by not changing the selection state |
| 52 |
* of the option and not dispatching any SELECTED events, for backwards |
| 53 |
* compatibility with existing uses of this class. |
| 54 |
* @param {goog.events.Event} e Mouse or key event that triggered the action. |
| 55 |
* @return {boolean} True if the action was allowed to proceed, false otherwise. |
| 56 |
* @override |
| 57 |
*/ |
| 58 |
goog.ui.Option.prototype.performActionInternal = function(e) { |
| 59 |
return this.dispatchEvent(goog.ui.Component.EventType.ACTION); |
| 60 |
}; |
| 61 |
|
| 62 |
|
| 63 |
// Register a decorator factory function for goog.ui.Options. |
| 64 |
goog.ui.registry.setDecoratorByClassName( |
| 65 |
goog.getCssName('goog-option'), function() { |
| 66 |
// Option defaults to using MenuItemRenderer. |
| 67 |
return new goog.ui.Option(null); |
| 68 |
}); |