tab.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2008 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 tab control, designed to be used in {@link goog.ui.TabBar}s.
  16. *
  17. * @author attila@google.com (Attila Bodis)
  18. * @see ../demos/tabbar.html
  19. */
  20. goog.provide('goog.ui.Tab');
  21. goog.require('goog.ui.Component');
  22. goog.require('goog.ui.Control');
  23. goog.require('goog.ui.TabRenderer');
  24. goog.require('goog.ui.registry');
  25. /**
  26. * Tab control, designed to be hosted in a {@link goog.ui.TabBar}. The tab's
  27. * DOM may be different based on the configuration of the containing tab bar,
  28. * so tabs should only be rendered or decorated as children of a tab bar.
  29. * @param {goog.ui.ControlContent} content Text caption or DOM structure to
  30. * display as the tab's caption (if any).
  31. * @param {goog.ui.TabRenderer=} opt_renderer Optional renderer used to render
  32. * or decorate the tab.
  33. * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper, used for
  34. * document interaction.
  35. * @constructor
  36. * @extends {goog.ui.Control}
  37. */
  38. goog.ui.Tab = function(content, opt_renderer, opt_domHelper) {
  39. goog.ui.Control.call(
  40. this, content, opt_renderer || goog.ui.TabRenderer.getInstance(),
  41. opt_domHelper);
  42. // Tabs support the SELECTED state.
  43. this.setSupportedState(goog.ui.Component.State.SELECTED, true);
  44. // Tabs must dispatch state transition events for the DISABLED and SELECTED
  45. // states in order for the tab bar to function properly.
  46. this.setDispatchTransitionEvents(
  47. goog.ui.Component.State.DISABLED | goog.ui.Component.State.SELECTED,
  48. true);
  49. };
  50. goog.inherits(goog.ui.Tab, goog.ui.Control);
  51. goog.tagUnsealableClass(goog.ui.Tab);
  52. /**
  53. * Tooltip text for the tab, displayed on hover (if any).
  54. * @type {string|undefined}
  55. * @private
  56. */
  57. goog.ui.Tab.prototype.tooltip_;
  58. /**
  59. * @return {string|undefined} Tab tooltip text (if any).
  60. */
  61. goog.ui.Tab.prototype.getTooltip = function() {
  62. return this.tooltip_;
  63. };
  64. /**
  65. * Sets the tab tooltip text. If the tab has already been rendered, updates
  66. * its tooltip.
  67. * @param {string} tooltip New tooltip text.
  68. */
  69. goog.ui.Tab.prototype.setTooltip = function(tooltip) {
  70. this.getRenderer().setTooltip(this.getElement(), tooltip);
  71. this.setTooltipInternal(tooltip);
  72. };
  73. /**
  74. * Sets the tab tooltip text. Considered protected; to be called only by the
  75. * renderer during element decoration.
  76. * @param {string} tooltip New tooltip text.
  77. * @protected
  78. */
  79. goog.ui.Tab.prototype.setTooltipInternal = function(tooltip) {
  80. this.tooltip_ = tooltip;
  81. };
  82. // Register a decorator factory function for goog.ui.Tabs.
  83. goog.ui.registry.setDecoratorByClassName(
  84. goog.ui.TabRenderer.CSS_CLASS,
  85. function() { return new goog.ui.Tab(null); });