xref: /webtrees/resources/views/modules/statistics-chart/page.phtml (revision df27497a949ee94233b78915e33f253447a14e62)
1<?php
2declare(strict_types=1);
3
4use Fisharebest\Webtrees\View;
5?>
6
7<h2 class="wt-page-title">
8    <?= $title ?>
9</h2>
10
11<div class="wt-page-content wt-chart wt-statistics-chart" id="statistics-tabs">
12    <ul class="nav nav-tabs" role="tablist">
13        <?php foreach ($tabs as $label => $url) : ?>
14            <li class="nav-item">
15                <a class="nav-link" href="#tab-<?= e(md5($url)) ?>" data-toggle="tab" data-href="<?= e($url) ?>" role="tab">
16                    <?= $label ?>
17                </a>
18            </li>
19        <?php endforeach ?>
20    </ul>
21
22    <div class="tab-content">
23        <?php foreach ($tabs as $label => $url) : ?>
24            <div class="tab-pane fade wt-ajax-load" role="tabpanel" id="tab-<?= e(md5($url)) ?>"></div>
25        <?php endforeach ?>
26    </div>
27</div>
28
29<?php View::push('javascript') ?>
30<script>
31  "use strict";
32
33  // Bootstrap tabs - load content dynamically using AJAX
34  $('a[data-toggle="tab"][data-href]').on('show.bs.tab', function () {
35    $(this.getAttribute('href') + ':empty').load($(this).data('href'));
36  });
37
38  // If the URL contains a fragment, then activate the corresponding tab.
39  // Use a prefix on the fragment, to prevent scrolling to the element.
40  var target = window.location.hash.replace("tab-", "");
41  var tab    = $("#statistics-tabs .nav-link[href='" + target + "']");
42  // If not, then activate the first tab.
43  if (tab.length === 0) {
44    tab = $("#statistics-tabs .nav-link:first");
45  }
46  tab.tab("show");
47
48  // If the user selects a tab, update the URL to reflect this
49  $('#statistics-tabs a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
50    window.location.hash = "tab-" + e.target.href.substring(e.target.href.indexOf('#') + 1);
51  });
52</script>
53<?php View::endpush() ?>
54