10f5fd22fSGreg Roach<?php 20f5fd22fSGreg Roach 30f5fd22fSGreg Roachuse Fisharebest\Webtrees\Individual; 40f5fd22fSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface; 50f5fd22fSGreg Roachuse Fisharebest\Webtrees\View; 60f5fd22fSGreg Roachuse Illuminate\Support\Collection; 70f5fd22fSGreg Roach 80f5fd22fSGreg Roach/** 90f5fd22fSGreg Roach * @var Individual $record 10*36779af1SGreg Roach * @var Collection<int,ModuleTabInterface> $tabs 110f5fd22fSGreg Roach */ 120f5fd22fSGreg Roach?> 130f5fd22fSGreg Roach 140f5fd22fSGreg Roach<div class="wt-tabs-individual" id="individual-tabs"> 150f5fd22fSGreg Roach <ul class="nav nav-tabs flex-wrap" role="tablist"> 160f5fd22fSGreg Roach <?php foreach ($tabs as $tab) : ?> 170f5fd22fSGreg Roach <li class="nav-item" role="presentation"> 18d4786c66SGreg Roach <a class="nav-link<?= $tab->isGrayedOut($record) ? ' text-muted' : '' ?>" data-bs-toggle="tab" role="tab" data-wt-href="<?= e(route('module', ['module' => $tab->name(), 'action' => 'Tab', 'tree' => $record->tree()->name(), 'xref' => $record->xref()])) ?>" href="#<?= $tab->name() ?>"> 190f5fd22fSGreg Roach <?= $tab->tabTitle() ?> 200f5fd22fSGreg Roach </a> 210f5fd22fSGreg Roach </li> 220f5fd22fSGreg Roach <?php endforeach ?> 230f5fd22fSGreg Roach </ul> 240f5fd22fSGreg Roach 250f5fd22fSGreg Roach <div class="tab-content"> 260f5fd22fSGreg Roach <?php foreach ($tabs as $tab) : ?> 270f5fd22fSGreg Roach <div id="<?= $tab->name() ?>" class="tab-pane fade wt-ajax-load" role="tabpanel"><?php if (!$tab->canLoadAjax()) : 280f5fd22fSGreg Roach ?><?= $tab->getTabContent($record) ?><?php 290f5fd22fSGreg Roach endif ?></div> 300f5fd22fSGreg Roach <?php endforeach ?> 310f5fd22fSGreg Roach </div> 320f5fd22fSGreg Roach</div> 330f5fd22fSGreg Roach 340f5fd22fSGreg Roach<?php View::push('javascript') ?> 350f5fd22fSGreg Roach<script> 36ffb44950SGreg Roach 'use strict'; 370f5fd22fSGreg Roach 380f5fd22fSGreg Roach // Bootstrap tabs - load content dynamically using AJAX 39d4786c66SGreg Roach $('a[data-bs-toggle="tab"][data-wt-href]').on('show.bs.tab', function () { 400f5fd22fSGreg Roach let target = $(this.hash + ':empty'); 410f5fd22fSGreg Roach if (target.length > 0) { 420f5fd22fSGreg Roach // Start the download immediately... 435a56d720SGreg Roach let download = fetch(this.dataset.wtHref, { 445a56d720SGreg Roach headers: new Headers({ 'X-Requested-with': 'XMLHttpRequest' }), 455a56d720SGreg Roach }); 460f5fd22fSGreg Roach 470f5fd22fSGreg Roach // ...but don't insert it until the tab is ready. 480f5fd22fSGreg Roach $(this).one('shown.bs.tab', () => { 490f5fd22fSGreg Roach download 500f5fd22fSGreg Roach .then(data => data.text()) 510f5fd22fSGreg Roach .then(data => target.html(data)); 520f5fd22fSGreg Roach }); 530f5fd22fSGreg Roach } 540f5fd22fSGreg Roach }); 550f5fd22fSGreg Roach 560f5fd22fSGreg Roach // If the URL contains a fragment, then activate the corresponding tab. 570f5fd22fSGreg Roach // Use a prefix on the fragment, to prevent scrolling to the element. 580f5fd22fSGreg Roach let target = window.location.hash.replace("tab-", ""); 59315eb316SGreg Roach let tab = document.querySelector("#individual-tabs .nav-link[href='" + target + "']"); 600f5fd22fSGreg Roach // If not, then activate the first tab. 61315eb316SGreg Roach tab = tab ?? document.querySelector("#individual-tabs .nav-link"); 62315eb316SGreg Roach tab.click(); 630f5fd22fSGreg Roach 640f5fd22fSGreg Roach // If the user selects a tab, update the URL to reflect this 65315eb316SGreg Roach $('#individual-tabs a[data-bs-toggle="tab"]').on('shown.bs.tab', function (e) { 660f5fd22fSGreg Roach window.location.hash = "tab-" + e.target.href.substring(e.target.href.indexOf('#') + 1); 670f5fd22fSGreg Roach }); 680f5fd22fSGreg Roach</script> 690f5fd22fSGreg Roach<?php View::endpush() ?> 70