xref: /webtrees/resources/views/modules/statistics-chart/page.phtml (revision 89db8eda75de707a9722ac32cffa511e018d495e)
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 = window.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    window.location.hash = "tab-" + e.target.href.substring(e.target.href.indexOf('#') + 1);
47  });
48</script>
49<?php View::endpush() ?>
50