xref: /webtrees/resources/views/modules/random_media/slide-show.phtml (revision 24931b29a0237a5f5f1b8620af661ea530451af0)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Family;
6use Fisharebest\Webtrees\I18N;
7use Fisharebest\Webtrees\Individual;
8use Fisharebest\Webtrees\Media;
9use Fisharebest\Webtrees\MediaFile;
10use Fisharebest\Webtrees\Source;
11use Fisharebest\Webtrees\Tree;
12use Illuminate\Support\Collection;
13
14/**
15 * @var int                        $block_id
16 * @var int                        $delay
17 * @var Collection<int,Family>     $linked_families
18 * @var Collection<int,Individual> $linked_individuals
19 * @var Collection<int,Source>     $linked_sources
20 * @var Media                      $media
21 * @var MediaFile                  $media_file
22 * @var bool                       $show_controls
23 * @var bool                       $start_automatically
24 * @var Tree                       $tree
25 */
26
27?>
28
29<div class="wt-slide-show-container">
30    <?php if ($show_controls) : ?>
31        <div class="wt-slide-show-controls text-center">
32            <a href="#" title="<?= I18N::translate('Play') ?>" <?= $start_automatically ? 'hidden' : '' ?>>
33                <?= view('icons/media-play') ?>
34                <span class="visually-hidden"><?= I18N::translate('Play') ?></span>
35            </a>
36            <a href="#" title="<?= I18N::translate('Stop') ?>" <?= $start_automatically ? '' : 'hidden' ?>>
37                <?= view('icons/media-stop') ?>
38                <span class="visually-hidden"><?= I18N::translate('Stop') ?></span>
39            </a>
40            <a href="#" title="<?= I18N::translate('Next image') ?>">
41                <?= view('icons/media-next') ?>
42                <span class="visually-hidden"><?= I18N::translate('Next image') ?></span>
43            </a>
44        </div>
45    <?php endif ?>
46
47    <figure class="wt-slide-show-figure text-center">
48        <?= $media_file->displayImage(200, 200, 'contain', ['class' => 'slide-show-image img-fluid']) ?>
49        <figcaption class="wt-slide-show-figcaption">
50            <a href="<?= e($media->url()) ?>">
51                <b><?= $media->fullName() ?></b>
52            </a>
53        </figcaption>
54    </figure>
55
56    <p class="wt-slide-show-notes text-center">
57        <?php foreach ($media->facts(['NOTE']) as $fact) : ?>
58            <?= view('fact-gedcom-fields', ['gedcom' => $fact->gedcom(), 'parent' => $media->tag(), 'tree' => $tree]) ?>
59        <?php endforeach ?>
60    </p>
61
62    <ul class="fa-ul wt-slide-show-links">
63        <?php foreach ($linked_individuals as $individual) : ?>
64            <li>
65                <span class="fa-li" title="<?= I18N::translate('Individual') ?>"><?= view('icons/individual') ?></span>
66                <a href="<?= e($individual->url()) ?>" class="wt-slide-show-link">
67                    <?= $individual->fullName() ?>
68                </a>
69            </li>
70        <?php endforeach ?>
71
72        <?php foreach ($linked_families as $family) : ?>
73            <li>
74                <span class="fa-li" title="<?= I18N::translate('Family') ?>"><?= view('icons/family') ?></span>
75                <a href="<?= e($family->url()) ?>" class="wt-slide-show-link">
76                    <?= $family->fullName() ?>
77                </a>
78            </li>
79        <?php endforeach ?>
80
81        <?php foreach ($linked_sources as $source) : ?>
82            <li>
83                <span class="fa-li" title="<?= I18N::translate('Source') ?>"><?= view('icons/source') ?></span>
84                <a href="<?= e($source->url()) ?>" class="wt-slide-show-link">
85                    <?= $source->fullName() ?>
86                </a>
87            </li>
88        <?php endforeach ?>
89    </ul>
90</div>
91
92<script>
93  (function () {
94    let block = document.getElementById('block-<?= $block_id ?>');
95
96    let play = <?= json_encode($start_automatically, JSON_THROW_ON_ERROR) ?>;
97
98    function slideShowReload () {
99      clearTimeout(timeout);
100
101      if (document.hidden) {
102        // No point loading images when nobody is looking.
103        timeout = setTimeout(slideShowReload, 1000);
104      } else {
105        $(block.parentNode).load($(block).parent().data('wtAjaxUrl') + '&start=' + (play ? '1' : '0'));
106      }
107    }
108
109    let timeout = null;
110
111    if (play) {
112      timeout = setTimeout(slideShowReload, <?= json_encode($delay * 1000, JSON_THROW_ON_ERROR) ?>);
113    }
114
115    block.querySelector('.wt-icon-media-play').addEventListener('click', (event) => {
116      event.preventDefault();
117      block.querySelector('.wt-icon-media-play').parentNode.hidden = true;
118      block.querySelector('.wt-icon-media-stop').parentNode.hidden = false;
119      play = true;
120      slideShowReload();
121    });
122
123    block.querySelector('.wt-icon-media-stop').addEventListener('click', (event) => {
124      event.preventDefault();
125      block.querySelector('.wt-icon-media-stop').parentNode.hidden = true;
126      block.querySelector('.wt-icon-media-play').parentNode.hidden = false;
127      play = false;
128      clearTimeout(timeout);
129    });
130
131    block.querySelector('.wt-icon-media-next').addEventListener('click', (event) => {
132      event.preventDefault();
133      slideShowReload();
134    });
135  })();
136</script>
137