xref: /webtrees/resources/views/modules/random_media/slide-show.phtml (revision ac71572d8462e396ed5a307f05b29381e49f9e6e)
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<Family>     $linked_families
18 * @var Collection<Individual> $linked_individuals
19 * @var Collection<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    var play = <?= json_encode($start_automatically, JSON_THROW_ON_ERROR) ?>;
94
95    if (play) {
96        var timeout = setTimeout(slideShowReload, <?= json_encode($delay * 1000, JSON_THROW_ON_ERROR) ?>);
97    }
98
99    function slideShowReload() {
100        var block = $("#block-<?= $block_id ?>").parent();
101        clearTimeout(timeout);
102        block.load(block.data("wtAjaxUrl") + "&start=" + (play ? "1" : "0"));
103
104        return false;
105    }
106
107    $(".wt-icon-media-play").on("click", function () {
108        $(".wt-icon-media-play").parent().attr("hidden", true);
109        $(".wt-icon-media-stop").parent().attr("hidden", false);
110        play = true;
111        return slideShowReload();
112    });
113
114    $(".wt-icon-media-stop").on("click", function () {
115        $(".wt-icon-media-stop").parent().attr("hidden", true);
116        $(".wt-icon-media-play").parent().attr("hidden", false);
117        play = false;
118        clearTimeout(timeout);
119        return false;
120    });
121
122    $(".wt-icon-media-next").on("click", function () {
123        return slideShowReload();
124    });
125</script>
126