Debian Codegraph @

closure-library/closure/goog/ui/tab.js

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