Skip to content

Commit c6aca8a

Browse files
author
Misty Stanley-Jones
authored
Improve bootstrap tabs (docker#2546)
Use data-target instead of href Move tab-syncing code into site-wide JS so everyone can use it Add example for syncing tab groups on the same page
1 parent 9902ceb commit c6aca8a

File tree

6 files changed

+57
-30
lines changed

6 files changed

+57
-30
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ references as you rename, add, and remove tabs.
251251
252252
```
253253
<ul class="nav nav-tabs">
254-
<li class="active"><a data-toggle="tab" href="#tab1">TAB 1 HEADER</a></li>
255-
<li><a data-toggle="tab" href="#tab2">TAB 2 HEADER</a></li>
254+
<li class="active"><a data-toggle="tab" data-target="#tab1">TAB 1 HEADER</a></li>
255+
<li><a data-toggle="tab" data-target="#tab2">TAB 2 HEADER</a></li>
256256
</ul>
257257
<div class="tab-content">
258258
<div id="tab1" class="tab-pane fade in active">TAB 1 CONTENT</div>

compose/compose-file/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tutorial](/engine/getstarted-voting-app/index.md).
3737

3838
<div class="panel panel-default">
3939
<div class="panel-heading" role="tab" id="headingThree">
40-
<h4 class="panel-title" id="collapsible-group-item-3"> <a class="" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="true" aria-controls="collapseThree"> Example Compose file version 3 </a> </h4>
40+
<h4 class="panel-title" id="collapsible-group-item-3"> <a class="" role="button" data-toggle="collapse" data-parent="#accordion" data-target="#collapseThree" aria-expanded="true" aria-controls="collapseThree"> Example Compose file version 3 </a> </h4>
4141
</div>
4242
<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree" aria-expanded="true">
4343
<div class="panel-body">

datacenter/dtr/2.2/guides/admin/configure/use-a-load-balancer.md

+5-19
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ balance checks. Use `/health` instead for those kinds of checks.
8989
Use the following examples to configure your load balancer for DTR.
9090

9191
<ul class="nav nav-tabs">
92-
<li class="active"><a data-toggle="tab" href="#nginx" data-group="nginx">NGINX</a></li>
93-
<li><a data-toggle="tab" href="#haproxy" data-group="haproxy">HAProxy</a></li>
94-
<li><a data-toggle="tab" href="#aws">AWS LB</a></li>
92+
<li class="active"><a data-toggle="tab" data-target="#nginx" data-group="nginx">NGINX</a></li>
93+
<li><a data-toggle="tab" data-target="#haproxy" data-group="haproxy">HAProxy</a></li>
94+
<li><a data-toggle="tab" data-target="#aws">AWS LB</a></li>
9595
</ul>
9696
<div class="tab-content">
9797
<div id="nginx" class="tab-pane fade in active">
@@ -259,8 +259,8 @@ backend dtr_upstream_servers_443
259259
You can deploy your load balancer using:
260260

261261
<ul class="nav nav-tabs">
262-
<li class="active"><a data-toggle="tab" href="#nginx-2" data-group="nginx">NGINX</a></li>
263-
<li><a data-toggle="tab" href="#haproxy-2" data-group="haproxy">HAProxy</a></li>
262+
<li class="active"><a data-toggle="tab" data-target="#nginx-2" data-group="nginx">NGINX</a></li>
263+
<li><a data-toggle="tab" data-target="#haproxy-2" data-group="haproxy">HAProxy</a></li>
264264
</ul>
265265
<div class="tab-content">
266266
<div id="nginx-2" class="tab-pane fade in active">
@@ -302,17 +302,3 @@ docker run --detach \
302302

303303
* [Backups and disaster recovery](../backups-and-disaster-recovery.md)
304304
* [DTR architecture](../../architecture.md)
305-
306-
307-
<script>
308-
// sync tabs for the same language, so you only have to click once.
309-
310-
// jquery is only loaded at the footer, so we can't rely on it for the
311-
// page load event
312-
window.onload = function() {
313-
$('.nav-tabs > li > a').click(function(e) {
314-
var group = $(this).attr('data-group');
315-
$('.nav-tabs > li > a[data-group="'+ group +'"]').tab('show');
316-
})
317-
};
318-
</script>

engine/api/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ The API can be accessed with any HTTP client, but we also provide [SDKs](sdks.md
2323
As an example, the `docker run` command can be easily implemented in various programming languages and by hitting the API directly with `curl`:
2424

2525
<ul class="nav nav-tabs">
26-
<li class="active"><a data-toggle="tab" href="#python">Python</a></li>
27-
<li><a data-toggle="tab" href="#go">Go</a></li>
28-
<li><a data-toggle="tab" href="#curl">curl</a></li>
26+
<li class="active"><a data-toggle="tab" data-target="#python">Python</a></li>
27+
<li><a data-toggle="tab" data-target="#go">Go</a></li>
28+
<li><a data-toggle="tab" data-target="#curl">curl</a></li>
2929
</ul>
3030
<div class="tab-content">
3131
<div id="python" class="tab-pane fade in active">

js/docs.js

+9
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,12 @@ if($('.nav-sidebar ul a.active').length != 0)
280280
$(this).addClass('collapse in').siblings;
281281
});
282282
}
283+
284+
// sync tabs with the same data-group
285+
286+
window.onload = function() {
287+
$('.nav-tabs > li > a').click(function(e) {
288+
var group = $(this).attr('data-group');
289+
$('.nav-tabs > li > a[data-group="'+ group +'"]').tab('show');
290+
})
291+
};

test.md

+37-5
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,22 @@ You can nest captures within each other to represent more complex logic with Liq
232232
Here are some tabs:
233233
234234
<ul class="nav nav-tabs">
235-
<li class="active"><a data-toggle="tab" href="#tab1">TAB 1 HEADER</a></li>
236-
<li><a data-toggle="tab" href="#tab2">TAB 2 HEADER</a></li>
235+
<li class="active"><a data-toggle="tab" data-target="#tab1">TAB 1 HEADER</a></li>
236+
<li><a data-toggle="tab" data-target="#tab2">TAB 2 HEADER</a></li>
237237
</ul>
238238
<div class="tab-content">
239239
<div id="tab1" class="tab-pane fade in active">TAB 1 CONTENT</div>
240240
<div id="tab2" class="tab-pane fade">TAB 2 CONTENT</div>
241241
</div>
242242
243-
You need to adjust the IDs and HREFs to match your use case.
243+
You need to adjust the `id` and `data-target` values to match your use case.
244244
245245
If you have Markdown inside the content of the `<div>`, you need to capture it, then
246246
print it and run it through the `markdownify` Liquid filter. Here's a demo:
247247

248248
<ul class="nav nav-tabs">
249-
<li class="active"><a data-toggle="tab" href="#tab3">TAB 1 HEADER</a></li>
250-
<li><a data-toggle="tab" href="#tab4">TAB 2 HEADER</a></li>
249+
<li class="active"><a data-toggle="tab" data-target="#tab3">TAB 1 HEADER</a></li>
250+
<li><a data-toggle="tab" data-target="#tab4">TAB 2 HEADER</a></li>
251251
</ul>
252252
<div class="tab-content">
253253
<div id="tab3" class="tab-pane fade in active">
@@ -270,6 +270,38 @@ print it and run it through the `markdownify` Liquid filter. Here's a demo:
270270
</div>
271271
</div>
272272

273+
#### Synchronizing multiple tab groups
274+
275+
Consider an example where you have something like one tab per language, and
276+
you have multiple tab sets like this on a page. You might want them to all
277+
toggle together. We have Javascript that loads on every page that lets you
278+
do this by setting the `data-group` attributes to be the same. Note that the
279+
`data-target` attributes still need to point to unique div IDs.
280+
281+
In this example, selecting `Go` or `Python` in one tab set will toggle the
282+
other tab set to match.
283+
284+
<ul class="nav nav-tabs">
285+
<li class="active"><a data-toggle="tab" data-target="#go" data-group="go">Go</a></li>
286+
<li><a data-toggle="tab" data-target="#python" data-group="python">Python</a></li>
287+
</ul>
288+
<div class="tab-content">
289+
<div id="go" class="tab-pane fade in active">Go content here</div>
290+
<div id="python" class="tab-pane fade in">Python content here</div>
291+
</div>
292+
293+
And some content between the two sets, just for fun...
294+
295+
<ul class="nav nav-tabs">
296+
<li class="active"><a data-toggle="tab" data-target="#go-2" data-group="go">Go</a></li>
297+
<li><a data-toggle="tab" data-target="#python-2" data-group="python">Python</a></li>
298+
</ul>
299+
<div class="tab-content">
300+
<div id="go-2" class="tab-pane fade in active">Go content here</div>
301+
<div id="python-2" class="tab-pane fade in">Python content here</div>
302+
</div>
303+
304+
273305
### Cards
274306

275307
In a Bootstrap row, your columns need to add up to 12. Here are three cards in

0 commit comments

Comments
 (0)