option.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * @fileoverview A menu item class that supports selection state.
  16. *
  17. * @author attila@google.com (Attila Bodis)
  18. */
  19. goog.provide('goog.ui.Option');
  20. goog.require('goog.ui.Component');
  21. goog.require('goog.ui.MenuItem');
  22. goog.require('goog.ui.registry');
  23. /**
  24. * Class representing a menu option. This is just a convenience class that
  25. * extends {@link goog.ui.MenuItem} by making it selectable.
  26. *
  27. * @param {goog.ui.ControlContent} content Text caption or DOM structure to
  28. * display as the content of the item (use to add icons or styling to
  29. * menus).
  30. * @param {*=} opt_model Data/model associated with the menu item.
  31. * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper used for
  32. * document interactions.
  33. * @constructor
  34. * @extends {goog.ui.MenuItem}
  35. */
  36. goog.ui.Option = function(content, opt_model, opt_domHelper) {
  37. goog.ui.MenuItem.call(this, content, opt_model, opt_domHelper);
  38. this.setSelectable(true);
  39. };
  40. goog.inherits(goog.ui.Option, goog.ui.MenuItem);
  41. /**
  42. * Performs the appropriate action when the option is activated by the user.
  43. * Overrides the superclass implementation by not changing the selection state
  44. * of the option and not dispatching any SELECTED events, for backwards
  45. * compatibility with existing uses of this class.
  46. * @param {goog.events.Event} e Mouse or key event that triggered the action.
  47. * @return {boolean} True if the action was allowed to proceed, false otherwise.
  48. * @override
  49. */
  50. goog.ui.Option.prototype.performActionInternal = function(e) {
  51. return this.dispatchEvent(goog.ui.Component.EventType.ACTION);
  52. };
  53. // Register a decorator factory function for goog.ui.Options.
  54. goog.ui.registry.setDecoratorByClassName(
  55. goog.getCssName('goog-option'), function() {
  56. // Option defaults to using MenuItemRenderer.
  57. return new goog.ui.Option(null);
  58. });