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