xref: /webtrees/resources/views/modules/random_media/slide-show.phtml (revision d0648f1410989e1dbd09dbfb58264040e9dc59b2)
11c7f202cSGreg Roach<?php
2dd6b2bfcSGreg Roach
310e06497SGreg Roachdeclare(strict_types=1);
410e06497SGreg Roach
54991f205SGreg Roachuse Fisharebest\Webtrees\Family;
61c7f202cSGreg Roachuse Fisharebest\Webtrees\I18N;
74991f205SGreg Roachuse Fisharebest\Webtrees\Individual;
81c7f202cSGreg Roachuse Fisharebest\Webtrees\Media;
91c7f202cSGreg Roachuse Fisharebest\Webtrees\MediaFile;
104991f205SGreg Roachuse Fisharebest\Webtrees\Source;
117c2c99faSGreg Roachuse Fisharebest\Webtrees\Tree;
124991f205SGreg Roachuse Illuminate\Support\Collection;
131c7f202cSGreg Roach
141c7f202cSGreg Roach/**
151c7f202cSGreg Roach * @var int                        $block_id
167c2c99faSGreg Roach * @var int                        $delay
17c5402244SGreg Roach * @var Collection<int,Family>     $linked_families
18c5402244SGreg Roach * @var Collection<int,Individual> $linked_individuals
19c5402244SGreg Roach * @var Collection<int,Source>     $linked_sources
201c7f202cSGreg Roach * @var Media                      $media
211c7f202cSGreg Roach * @var MediaFile                  $media_file
224991f205SGreg Roach * @var bool                       $show_controls
234991f205SGreg Roach * @var bool                       $start_automatically
247c2c99faSGreg Roach * @var Tree                       $tree
251c7f202cSGreg Roach */
261c7f202cSGreg Roach
271c7f202cSGreg Roach?>
281c7f202cSGreg Roach
291c7f202cSGreg Roach<div class="wt-slide-show-container">
30dd6b2bfcSGreg Roach    <?php if ($show_controls) : ?>
311c7f202cSGreg Roach        <div class="wt-slide-show-controls text-center">
3239b853a7SGreg Roach            <a href="#" title="<?= I18N::translate('Play') ?>" <?= $start_automatically ? 'hidden' : '' ?>>
3339b853a7SGreg Roach                <?= view('icons/media-play') ?>
34315eb316SGreg Roach                <span class="visually-hidden"><?= I18N::translate('Play') ?></span>
3539b853a7SGreg Roach            </a>
3639b853a7SGreg Roach            <a href="#" title="<?= I18N::translate('Stop') ?>" <?= $start_automatically ? '' : 'hidden' ?>>
3739b853a7SGreg Roach                <?= view('icons/media-stop') ?>
38315eb316SGreg Roach                <span class="visually-hidden"><?= I18N::translate('Stop') ?></span>
3939b853a7SGreg Roach            </a>
4039b853a7SGreg Roach            <a href="#" title="<?= I18N::translate('Next image') ?>">
4139b853a7SGreg Roach                <?= view('icons/media-next') ?>
42315eb316SGreg Roach                <span class="visually-hidden"><?= I18N::translate('Next image') ?></span>
4339b853a7SGreg Roach            </a>
44dd6b2bfcSGreg Roach        </div>
45dd6b2bfcSGreg Roach    <?php endif ?>
46dd6b2bfcSGreg Roach
471c7f202cSGreg Roach    <figure class="wt-slide-show-figure text-center">
481558ebe9SGreg Roach        <?= $media_file->displayImage(200, 200, 'contain', ['class' => 'slide-show-image img-fluid']) ?>
49a21d61aeSGreg Roach        <figcaption class="wt-slide-show-figcaption">
50dd6b2bfcSGreg Roach            <a href="<?= e($media->url()) ?>">
5139ca88baSGreg Roach                <b><?= $media->fullName() ?></b>
52dd6b2bfcSGreg Roach            </a>
53dd6b2bfcSGreg Roach        </figcaption>
54dd6b2bfcSGreg Roach    </figure>
55dd6b2bfcSGreg Roach
561c7f202cSGreg Roach    <p class="wt-slide-show-notes text-center">
57b315f3e1SGreg Roach        <?php foreach ($media->facts(['NOTE']) as $fact) : ?>
58b315f3e1SGreg Roach            <?= view('fact-gedcom-fields', ['gedcom' => $fact->gedcom(), 'parent' => $media->tag(), 'tree' => $tree]) ?>
59b315f3e1SGreg Roach        <?php endforeach ?>
60dd6b2bfcSGreg Roach    </p>
61dd6b2bfcSGreg Roach
62*d0648f14SGreg Roach    <ul class="fa-ul mx-0 wt-slide-show-links">
634991f205SGreg Roach        <?php foreach ($linked_individuals as $individual) : ?>
649db3b894Skiwi3685            <li class="wt-slide-show-link">
651c7f202cSGreg Roach                <span class="fa-li" title="<?= I18N::translate('Individual') ?>"><?= view('icons/individual') ?></span>
669db3b894Skiwi3685                <a href="<?= e($individual->url()) ?>">
6739ca88baSGreg Roach                    <?= $individual->fullName() ?>
689db3b894Skiwi3685                    <span class="wt-slide-show-link-lifespan"><?= $individual->lifespan() ?></span>
69dd6b2bfcSGreg Roach                </a>
701c7f202cSGreg Roach            </li>
71dd6b2bfcSGreg Roach        <?php endforeach ?>
72dd6b2bfcSGreg Roach
734991f205SGreg Roach        <?php foreach ($linked_families as $family) : ?>
749db3b894Skiwi3685            <li class="wt-slide-show-link">
751c7f202cSGreg Roach                <span class="fa-li" title="<?= I18N::translate('Family') ?>"><?= view('icons/family') ?></span>
761c7f202cSGreg Roach                <a href="<?= e($family->url()) ?>" class="wt-slide-show-link">
7739ca88baSGreg Roach                    <?= $family->fullName() ?>
78dd6b2bfcSGreg Roach                </a>
791c7f202cSGreg Roach            </li>
80dd6b2bfcSGreg Roach        <?php endforeach ?>
81dd6b2bfcSGreg Roach
824991f205SGreg Roach        <?php foreach ($linked_sources as $source) : ?>
839db3b894Skiwi3685            <li class="wt-slide-show-link">
841c7f202cSGreg Roach                <span class="fa-li" title="<?= I18N::translate('Source') ?>"><?= view('icons/source') ?></span>
851c7f202cSGreg Roach                <a href="<?= e($source->url()) ?>" class="wt-slide-show-link">
8639ca88baSGreg Roach                    <?= $source->fullName() ?>
87dd6b2bfcSGreg Roach                </a>
881c7f202cSGreg Roach            </li>
89dd6b2bfcSGreg Roach        <?php endforeach ?>
90dd6b2bfcSGreg Roach    </ul>
91dd6b2bfcSGreg Roach</div>
92dd6b2bfcSGreg Roach
93dd6b2bfcSGreg Roach<script>
9431aa728cSGreg Roach  (function () {
9531aa728cSGreg Roach    let block = document.getElementById('block-<?= $block_id ?>');
96dd6b2bfcSGreg Roach
9731aa728cSGreg Roach    let play = <?= json_encode($start_automatically, JSON_THROW_ON_ERROR) ?>;
98375cf3adSGreg Roach
99375cf3adSGreg Roach    function slideShowReload () {
100dd6b2bfcSGreg Roach      clearTimeout(timeout);
101dd6b2bfcSGreg Roach
10231aa728cSGreg Roach      if (document.hidden) {
10331aa728cSGreg Roach        // No point loading images when nobody is looking.
10431aa728cSGreg Roach        timeout = setTimeout(slideShowReload, 1000);
10531aa728cSGreg Roach      } else {
10631aa728cSGreg Roach        $(block.parentNode).load($(block).parent().data('wtAjaxUrl') + '&start=' + (play ? '1' : '0'));
10731aa728cSGreg Roach      }
108dd6b2bfcSGreg Roach    }
109dd6b2bfcSGreg Roach
11031aa728cSGreg Roach    let timeout = null;
11131aa728cSGreg Roach
11231aa728cSGreg Roach    if (play) {
11331aa728cSGreg Roach      timeout = setTimeout(slideShowReload, <?= json_encode($delay * 1000, JSON_THROW_ON_ERROR) ?>);
11431aa728cSGreg Roach    }
11531aa728cSGreg Roach
11631aa728cSGreg Roach    block.querySelector('.wt-icon-media-play').addEventListener('click', (event) => {
11731aa728cSGreg Roach      event.preventDefault();
11831aa728cSGreg Roach      block.querySelector('.wt-icon-media-play').parentNode.hidden = true;
11931aa728cSGreg Roach      block.querySelector('.wt-icon-media-stop').parentNode.hidden = false;
120dd6b2bfcSGreg Roach      play = true;
12131aa728cSGreg Roach      slideShowReload();
122dd6b2bfcSGreg Roach    });
123dd6b2bfcSGreg Roach
12431aa728cSGreg Roach    block.querySelector('.wt-icon-media-stop').addEventListener('click', (event) => {
12531aa728cSGreg Roach      event.preventDefault();
12631aa728cSGreg Roach      block.querySelector('.wt-icon-media-stop').parentNode.hidden = true;
12731aa728cSGreg Roach      block.querySelector('.wt-icon-media-play').parentNode.hidden = false;
128dd6b2bfcSGreg Roach      play = false;
129375cf3adSGreg Roach      clearTimeout(timeout);
130dd6b2bfcSGreg Roach    });
131dd6b2bfcSGreg Roach
13231aa728cSGreg Roach    block.querySelector('.wt-icon-media-next').addEventListener('click', (event) => {
13331aa728cSGreg Roach      event.preventDefault();
13431aa728cSGreg Roach      slideShowReload();
135dd6b2bfcSGreg Roach    });
13631aa728cSGreg Roach  })();
137dd6b2bfcSGreg Roach</script>
138