aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/demos/tabbar.html
blob: 6c21f9b879388894210ec2821b8ef11d244a495b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<!DOCTYPE html>
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
  <title>goog.ui.TabBar</title>
  <link rel="stylesheet" href="css/demo.css">
  <link rel="stylesheet" href="../css/roundedtab.css">
  <link rel="stylesheet" href="../css/tab.css">
  <link rel="stylesheet" href="../css/tabbar.css">
  <style>
    fieldset {
      padding: 10px;
      border: 1px solid #369;
    }

    .goog-tab-content {
      height: 9em;
      margin: 0;
      border: 1px solid #6b90da;
      border-top: 0;
      padding: 4px 8px;
      background: #fff;
      overflow: auto;
    }
  </style>
  <script src="../base.js"></script>
  <script>
    goog.require('goog.debug.DivConsole');
    goog.require('goog.debug.Logger');
    goog.require('goog.debug.Logger.Level');
    goog.require('goog.debug.LogManager');
    goog.require('goog.dom');
    goog.require('goog.events');
    goog.require('goog.events.EventType');
    goog.require('goog.object');
    goog.require('goog.ui.Component.EventType');
    goog.require('goog.ui.RoundedTabRenderer');
    goog.require('goog.ui.Tab');
    goog.require('goog.ui.TabBar');
  </script>
</head>
<body>
  <h1>goog.ui.TabBar</h1>
  <p>
    A <b>goog.ui.TabBar</b> is a subclass of <b>goog.ui.Container</b>,
    designed to host one or more <b>goog.ui.Tab</b>s.  The tabs in the
    first four tab bars on this demo page were decorated using the default
    tab renderer.  Tabs in the last two tab bars were decorated using the
    rounded tab renderer (<b>goog.ui.RoundedTabRenderer</b>).
  </p>
  <table border="0" cellpadding="0" cellspacing="10" width="100%">
    <tbody>
      <tr valign="top">
        <td width="50%">
          <b>Above tab content:</b><br><br>
          <div id="top" class="goog-tab-bar goog-tab-bar-top">
            <div class="goog-tab goog-tab-selected">Hello</div>
            <div class="goog-tab">Settings</div>
            <div class="goog-tab">More</div>
            <div class="goog-tab goog-tab-disabled">Advanced</div>
          </div>
          <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
          <div class="goog-tab-bar-clear"></div>
          <div id="top_content" class="goog-tab-content">
            Use the keyboard or the mouse to switch tabs.
          </div>
          <label>
            Show/hide the first tab
            <input type="checkbox" id="show_top" checked>
          </label>
          <label>
            Enable/disable the fourth tab
            <input type="checkbox" id="enable_top">
          </label>
        </td>
        <td width="50%">
          <b>Below tab content:</b><br><br>
          <div id="bottom_content" class="goog-tab-content">
            Use the keyboard or the mouse to switch tabs.
          </div>
          <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
          <div class="goog-tab-bar-clear"></div>
          <div id="bottom" class="goog-tab-bar goog-tab-bar-bottom">
            <div class="goog-tab">Hello</div>
            <div class="goog-tab goog-tab-selected">Settings</div>
            <div class="goog-tab">More</div>
            <div class="goog-tab goog-tab-disabled">Advanced</div>
          </div>
          <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
          <div class="goog-tab-bar-clear"></div>
          <label>
            Show/hide the first tab
            <input type="checkbox" id="show_bottom" checked>
          </label>
          <label>
            Enable/disable the fourth tab
            <input type="checkbox" id="enable_bottom">
          </label>
        </td>
      </tr>
      <tr valign="top">
        <td width="50%">
          <b>Before tab content:</b><br><br>
          <div id="start" class="goog-tab-bar goog-tab-bar-start">
            <div class="goog-tab">Hello</div>
            <div class="goog-tab">Settings</div>
            <div class="goog-tab goog-tab-selected">More</div>
            <div class="goog-tab goog-tab-disabled">Advanced</div>
          </div>
          <div id="start_content" class="goog-tab-content">
            Use the keyboard or the mouse to switch tabs.
          </div>
          <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
          <div class="goog-tab-bar-clear"></div>
          <label>
            Show/hide the first tab
            <input type="checkbox" id="show_start" checked>
          </label>
          <label>
            Enable/disable the fourth tab
            <input type="checkbox" id="enable_start">
          </label>
        </td>
        <td width="50%">
          <b>After tab content:</b><br><br>
          <div id="end" class="goog-tab-bar goog-tab-bar-end">
            <div class="goog-tab">Hello</div>
            <div class="goog-tab">Settings</div>
            <div class="goog-tab">More</div>
            <div class="goog-tab goog-tab-disabled">Advanced</div>
          </div>
          <div id="end_content" class="goog-tab-content">
            Use the keyboard or the mouse to switch tabs.
          </div>
          <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
          <div class="goog-tab-bar-clear"></div>
          <label>
            Show/hide the first tab
            <input type="checkbox" id="show_end" checked>
          </label>
          <label>
            Enable/disable the fourth tab
            <input type="checkbox" id="enable_end">
          </label>
        </td>
      </tr>
      <tr valign="top">
        <td width="50%">
          <b>Above tab content (rounded corners):</b><br><br>
          <div id="top_round" class="goog-tab-bar goog-tab-bar-top">
            <div class="goog-rounded-tab">Hello</div>
            <div class="goog-rounded-tab goog-rounded-tab-selected">Settings
            </div>
            <div class="goog-rounded-tab">More</div>
            <div class="goog-rounded-tab goog-rounded-tab-disabled">Advanced
            </div>
          </div>
          <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
          <div class="goog-tab-bar-clear"></div>
          <div id="top_round_content" class="goog-tab-content"
              style="border-width:4px">
            Use the keyboard or the mouse to switch tabs.
          </div>
          <label>
            Show/hide the first tab
            <input type="checkbox" id="show_top_round" checked>
          </label>
          <label>
            Enable/disable the fourth tab
            <input type="checkbox" id="enable_top_round">
          </label>
        </td>
        <td width="50%">
          <b>Before tab content (rounded corners):</b><br><br>
          <div id="start_round" class="goog-tab-bar goog-tab-bar-start">
            <div class="goog-rounded-tab goog-rounded-tab-selected">Hello</div>
            <div class="goog-rounded-tab">Settings</div>
            <div class="goog-rounded-tab">More</div>
            <div class="goog-rounded-tab goog-rounded-tab-disabled">Advanced
            </div>
          </div>
          <div id="start_round_content" class="goog-tab-content"
            style="border-width:4px">
            Use the keyboard or the mouse to switch tabs.
          </div>
          <!-- Use goog-tab-bar-clear to separate the tabs from the content. -->
          <div class="goog-tab-bar-clear"></div>
          <label>
            Show/hide the first tab
            <input type="checkbox" id="show_start_round" checked>
          </label>
          <label>
            Enable/disable the fourth tab
            <input type="checkbox" id="enable_start_round">
          </label>
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <!-- Event log. -->
          <fieldset class="goog-debug-panel">
            <legend>Event Log</legend>
            <div id="log"></div>
          </fieldset>
        </td>
      </tr>
    </tbody>
  </table>
  <br>
  <div id="perf"></div>
  <script>
    var timer = goog.now();

    // Set up a logger.
    goog.debug.LogManager.getRoot().setLevel(goog.debug.Logger.Level.ALL);
    var logger = goog.debug.Logger.getLogger('demo');
    var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));
    logconsole.setCapturing(true);

    var EVENTS = goog.object.getValues(goog.ui.Component.EventType);
    logger.fine('Listening for: ' + EVENTS.join(', ') + '.');

    function logEvent(e) {
      var source =
          typeof e.target.getCaption == 'function' && e.target.getCaption() ||
          e.target.getId();
      logger.info('"' + source + '" dispatched: ' + e.type);
    }

    var topTab = new goog.ui.TabBar();
    topTab.decorate(goog.dom.getElement('top'));

    var bottom = new goog.ui.TabBar();
    bottom.decorate(goog.dom.getElement('bottom'));

    var start = new goog.ui.TabBar();
    start.decorate(goog.dom.getElement('start'));

    var end = new goog.ui.TabBar();
    end.decorate(goog.dom.getElement('end'));

    var topRound = new goog.ui.TabBar();
    topRound.decorate(goog.dom.getElement('top_round'));

    var startRound = new goog.ui.TabBar();
    startRound.decorate(goog.dom.getElement('start_round'));

    goog.array.forEach([topTab, bottom, start, end, topRound, startRound],
        function(tabBar) {
        // Log all events.
        goog.events.listen(tabBar, EVENTS, logEvent);

        // Handle SELECT events dispatched by tabs.
        goog.events.listen(tabBar, goog.ui.Component.EventType.SELECT,
            function(e) {
              var tabSelected = e.target;
              var contentElement = goog.dom.getElement(tabBar.getId() +
                  '_content');
              goog.dom.setTextContent(contentElement,
                  'You selected the "' + tabSelected.getCaption() + '" tab.');
            });

        // Hook up the "Show/hide first tab" checkbox.
        goog.events.listen(goog.dom.getElement('show_' + tabBar.getId()),
            goog.events.EventType.CLICK,
            function(e) {
              var checkbox = e.target;
              tabBar.getChildAt(0).setVisible(checkbox.checked);
            });

        // Hook up the "Enable/disable fourth tab" checkbox.
        goog.events.listen(goog.dom.getElement('enable_' + tabBar.getId()),
            goog.events.EventType.CLICK,
            function(e) {
              var checkbox = e.target;
              tabBar.getChildAt(3).setEnabled(checkbox.checked);
            });
      });

    goog.dom.setTextContent(goog.dom.getElement('perf'),
        (goog.now() - timer) + 'ms');
  </script>
</body>
</html>