Debian Codegraph @

closure-library/closure/goog/demos/tabbar.html

raw
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright 2010 The Closure Library Authors. All Rights Reserved.
5
6 Use of this source code is governed by the Apache License, Version 2.0.
7 See the COPYING file for details.
8 -->
9 <head>
10 <title>goog.ui.TabBar</title>
11 <link rel="stylesheet" href="css/demo.css">
12 <link rel="stylesheet" href="../css/roundedtab.css">
13 <link rel="stylesheet" href="../css/tab.css">
14 <link rel="stylesheet" href="../css/tabbar.css">
15 <style>
16 fieldset {
17 padding: 10px;
18 border: 1px solid #369;
19 }
20
21 .goog-tab-content {
22 height: 9em;
23 margin: 0;
24 border: 1px solid #6b90da;
25 border-top: 0;
26 padding: 4px 8px;
27 background: #fff;
28 overflow: auto;
29 }
30 </style>
31 <script src="../base.js"></script>
32 <script>
33 goog.require('goog.debug.DivConsole');
34 goog.require('goog.debug.LogManager');
35 goog.require('goog.dom');
36 goog.require('goog.events');
37 goog.require('goog.events.EventType');
38 goog.require('goog.log');
39 goog.require('goog.log.Level');
40 goog.require('goog.object');
41 goog.require('goog.ui.Component.EventType');
42 goog.require('goog.ui.RoundedTabRenderer');
43 goog.require('goog.ui.Tab');
44 goog.require('goog.ui.TabBar');
45 </script>
46 </head>
47 <body>
48 <h1>goog.ui.TabBar</h1>
49 <p>
50 A <b>goog.ui.TabBar</b> is a subclass of <b>goog.ui.Container</b>,
51 designed to host one or more <b>goog.ui.Tab</b>s. The tabs in the
52 first four tab bars on this demo page were decorated using the default
53 tab renderer. Tabs in the last two tab bars were decorated using the
54 rounded tab renderer (<b>goog.ui.RoundedTabRenderer</b>).
55 </p>
56 <table border="0" cellpadding="0" cellspacing="10" width="100%">
57 <tbody>
58 <tr valign="top">
59 <td width="50%">
60 <b>Above tab content:</b><br><br>
61 <div id="top" class="goog-tab-bar goog-tab-bar-top">
62 <div class="goog-tab goog-tab-selected">Hello</div>
63 <div class="goog-tab">Settings</div>
64 <div class="goog-tab">More</div>
65 <div class="goog-tab goog-tab-disabled">Advanced</div>
66 </div>
67 <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
68 <div class="goog-tab-bar-clear"></div>
69 <div id="top_content" class="goog-tab-content">
70 Use the keyboard or the mouse to switch tabs.
71 </div>
72 <label>
73 Show/hide the first tab
74 <input type="checkbox" id="show_top" checked>
75 </label>
76 <label>
77 Enable/disable the fourth tab
78 <input type="checkbox" id="enable_top">
79 </label>
80 </td>
81 <td width="50%">
82 <b>Below tab content:</b><br><br>
83 <div id="bottom_content" class="goog-tab-content">
84 Use the keyboard or the mouse to switch tabs.
85 </div>
86 <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
87 <div class="goog-tab-bar-clear"></div>
88 <div id="bottom" class="goog-tab-bar goog-tab-bar-bottom">
89 <div class="goog-tab">Hello</div>
90 <div class="goog-tab goog-tab-selected">Settings</div>
91 <div class="goog-tab">More</div>
92 <div class="goog-tab goog-tab-disabled">Advanced</div>
93 </div>
94 <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
95 <div class="goog-tab-bar-clear"></div>
96 <label>
97 Show/hide the first tab
98 <input type="checkbox" id="show_bottom" checked>
99 </label>
100 <label>
101 Enable/disable the fourth tab
102 <input type="checkbox" id="enable_bottom">
103 </label>
104 </td>
105 </tr>
106 <tr valign="top">
107 <td width="50%">
108 <b>Before tab content:</b><br><br>
109 <div id="start" class="goog-tab-bar goog-tab-bar-start">
110 <div class="goog-tab">Hello</div>
111 <div class="goog-tab">Settings</div>
112 <div class="goog-tab goog-tab-selected">More</div>
113 <div class="goog-tab goog-tab-disabled">Advanced</div>
114 </div>
115 <div id="start_content" class="goog-tab-content">
116 Use the keyboard or the mouse to switch tabs.
117 </div>
118 <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
119 <div class="goog-tab-bar-clear"></div>
120 <label>
121 Show/hide the first tab
122 <input type="checkbox" id="show_start" checked>
123 </label>
124 <label>
125 Enable/disable the fourth tab
126 <input type="checkbox" id="enable_start">
127 </label>
128 </td>
129 <td width="50%">
130 <b>After tab content:</b><br><br>
131 <div id="end" class="goog-tab-bar goog-tab-bar-end">
132 <div class="goog-tab">Hello</div>
133 <div class="goog-tab">Settings</div>
134 <div class="goog-tab">More</div>
135 <div class="goog-tab goog-tab-disabled">Advanced</div>
136 </div>
137 <div id="end_content" class="goog-tab-content">
138 Use the keyboard or the mouse to switch tabs.
139 </div>
140 <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
141 <div class="goog-tab-bar-clear"></div>
142 <label>
143 Show/hide the first tab
144 <input type="checkbox" id="show_end" checked>
145 </label>
146 <label>
147 Enable/disable the fourth tab
148 <input type="checkbox" id="enable_end">
149 </label>
150 </td>
151 </tr>
152 <tr valign="top">
153 <td width="50%">
154 <b>Above tab content (rounded corners):</b><br><br>
155 <div id="top_round" class="goog-tab-bar goog-tab-bar-top">
156 <div class="goog-rounded-tab">Hello</div>
157 <div class="goog-rounded-tab goog-rounded-tab-selected">Settings
158 </div>
159 <div class="goog-rounded-tab">More</div>
160 <div class="goog-rounded-tab goog-rounded-tab-disabled">Advanced
161 </div>
162 </div>
163 <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
164 <div class="goog-tab-bar-clear"></div>
165 <div id="top_round_content" class="goog-tab-content"
166 style="border-width:4px">
167 Use the keyboard or the mouse to switch tabs.
168 </div>
169 <label>
170 Show/hide the first tab
171 <input type="checkbox" id="show_top_round" checked>
172 </label>
173 <label>
174 Enable/disable the fourth tab
175 <input type="checkbox" id="enable_top_round">
176 </label>
177 </td>
178 <td width="50%">
179 <b>Before tab content (rounded corners):</b><br><br>
180 <div id="start_round" class="goog-tab-bar goog-tab-bar-start">
181 <div class="goog-rounded-tab goog-rounded-tab-selected">Hello</div>
182 <div class="goog-rounded-tab">Settings</div>
183 <div class="goog-rounded-tab">More</div>
184 <div class="goog-rounded-tab goog-rounded-tab-disabled">Advanced
185 </div>
186 </div>
187 <div id="start_round_content" class="goog-tab-content"
188 style="border-width:4px">
189 Use the keyboard or the mouse to switch tabs.
190 </div>
191 <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
192 <div class="goog-tab-bar-clear"></div>
193 <label>
194 Show/hide the first tab
195 <input type="checkbox" id="show_start_round" checked>
196 </label>
197 <label>
198 Enable/disable the fourth tab
199 <input type="checkbox" id="enable_start_round">
200 </label>
201 </td>
202 </tr>
203 <tr>
204 <td colspan="2">
205 <!-- Event log. -->
206 <fieldset class="goog-debug-panel">
207 <legend>Event Log</legend>
208 <div id="log"></div>
209 </fieldset>
210 </td>
211 </tr>
212 </tbody>
213 </table>
214 <br>
215 <div id="perf"></div>
216 <script>
217 var timer = goog.now();
218
219 // Set up a logger.
220 goog.debug.LogManager.getRoot().setLevel(goog.log.Level.ALL);
221 var logger = goog.log.getLogger('demo');
222 var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
223 logconsole.setCapturing(true);
224
225 var EVENTS = goog.object.getValues(goog.ui.Component.EventType);
226 goog.log.fine(logger, 'Listening for: ' + EVENTS.join(', ') + '.');
227
228 function logEvent(e) {
229 var source =
230 typeof e.target.getCaption == 'function' && e.target.getCaption() ||
231 e.target.getId();
232 goog.log.info(logger, '"' + source + '" dispatched: ' + e.type);
233 }
234
235 var topTab = new goog.ui.TabBar();
236 topTab.decorate(goog.dom.getElement('top'));
237
238 var bottom = new goog.ui.TabBar();
239 bottom.decorate(goog.dom.getElement('bottom'));
240
241 var start = new goog.ui.TabBar();
242 start.decorate(goog.dom.getElement('start'));
243
244 var end = new goog.ui.TabBar();
245 end.decorate(goog.dom.getElement('end'));
246
247 var topRound = new goog.ui.TabBar();
248 topRound.decorate(goog.dom.getElement('top_round'));
249
250 var startRound = new goog.ui.TabBar();
251 startRound.decorate(goog.dom.getElement('start_round'));
252
253 goog.array.forEach([topTab, bottom, start, end, topRound, startRound],
254 function(tabBar) {
255 // Log all events.
256 goog.events.listen(tabBar, EVENTS, logEvent);
257
258 // Handle SELECT events dispatched by tabs.
259 goog.events.listen(tabBar, goog.ui.Component.EventType.SELECT,
260 function(e) {
261 var tabSelected = e.target;
262 var contentElement = goog.dom.getElement(tabBar.getId() +
263 '_content');
264 goog.dom.setTextContent(contentElement,
265 'You selected the "' + tabSelected.getCaption() + '" tab.');
266 });
267
268 // Hook up the "Show/hide first tab" checkbox.
269 goog.events.listen(goog.dom.getElement('show_' + tabBar.getId()),
270 goog.events.EventType.CLICK,
271 function(e) {
272 var checkbox = e.target;
273 tabBar.getChildAt(0).setVisible(checkbox.checked);
274 });
275
276 // Hook up the "Enable/disable fourth tab" checkbox.
277 goog.events.listen(goog.dom.getElement('enable_' + tabBar.getId()),
278 goog.events.EventType.CLICK,
279 function(e) {
280 var checkbox = e.target;
281 tabBar.getChildAt(3).setEnabled(checkbox.checked);
282 });
283 });
284
285 goog.dom.setTextContent(goog.dom.getElement('perf'),
286 (goog.now() - timer) + 'ms');
287 </script>
288 </body>
289 </html>