summaryrefslogtreecommitdiff
path: root/resources/views/modules/random_media/slide-show.phtml
blob: d5e3698290809cca5de2e8d37307b4161af9b442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Media;
use Fisharebest\Webtrees\MediaFile;
use Fisharebest\Webtrees\Source;
use Fisharebest\Webtrees\Tree;
use Illuminate\Support\Collection;

/**
 * @var int                    $block_id
 * @var int                    $delay
 * @var Collection<Family>     $linked_families
 * @var Collection<Individual> $linked_individuals
 * @var Collection<Source>     $linked_sources
 * @var Media                  $media
 * @var MediaFile              $media_file
 * @var bool                   $show_controls
 * @var bool                   $start_automatically
 * @var Tree                   $tree
 */

?>

<div class="wt-slide-show-container">
    <?php if ($show_controls) : ?>
        <div class="wt-slide-show-controls text-center">
            <a href="#" title="<?= I18N::translate('Play') ?>" <?= $start_automatically ? 'hidden' : '' ?>>
                <?= view('icons/media-play') ?>
                <span class="visually-hidden"><?= I18N::translate('Play') ?></span>
            </a>
            <a href="#" title="<?= I18N::translate('Stop') ?>" <?= $start_automatically ? '' : 'hidden' ?>>
                <?= view('icons/media-stop') ?>
                <span class="visually-hidden"><?= I18N::translate('Stop') ?></span>
            </a>
            <a href="#" title="<?= I18N::translate('Next image') ?>">
                <?= view('icons/media-next') ?>
                <span class="visually-hidden"><?= I18N::translate('Next image') ?></span>
            </a>
        </div>
    <?php endif ?>

    <figure class="wt-slide-show-figure text-center">
        <?= $media_file->displayImage(200, 200, 'contain', ['class' => 'slide-show-image img-fluid']) ?>
        <figcaption class="wt-slide-show-figcaption">
            <a href="<?= e($media->url()) ?>">
                <b><?= $media->fullName() ?></b>
            </a>
        </figcaption>
    </figure>

    <p class="wt-slide-show-notes text-center">
        <?php foreach ($media->facts(['NOTE']) as $fact) : ?>
            <?= view('fact-gedcom-fields', ['gedcom' => $fact->gedcom(), 'parent' => $media->tag(), 'tree' => $tree]) ?>
        <?php endforeach ?>
    </p>

    <ul class="fa-ul wt-slide-show-links">
        <?php foreach ($linked_individuals as $individual) : ?>
            <li>
                <span class="fa-li" title="<?= I18N::translate('Individual') ?>"><?= view('icons/individual') ?></span>
                <a href="<?= e($individual->url()) ?>" class="wt-slide-show-link">
                    <?= $individual->fullName() ?>
                </a>
            </li>
        <?php endforeach ?>

        <?php foreach ($linked_families as $family) : ?>
            <li>
                <span class="fa-li" title="<?= I18N::translate('Family') ?>"><?= view('icons/family') ?></span>
                <a href="<?= e($family->url()) ?>" class="wt-slide-show-link">
                    <?= $family->fullName() ?>
                </a>
            </li>
        <?php endforeach ?>

        <?php foreach ($linked_sources as $source) : ?>
            <li>
                <span class="fa-li" title="<?= I18N::translate('Source') ?>"><?= view('icons/source') ?></span>
                <a href="<?= e($source->url()) ?>" class="wt-slide-show-link">
                    <?= $source->fullName() ?>
                </a>
            </li>
        <?php endforeach ?>
    </ul>
</div>

<script>
    var play = <?= json_encode($start_automatically, JSON_THROW_ON_ERROR) ?>;

    if (play) {
        var timeout = setTimeout(slideShowReload, <?= json_encode($delay * 1000, JSON_THROW_ON_ERROR) ?>);
    }

    function slideShowReload() {
        var block = $("#block-<?= $block_id ?>").parent();
        clearTimeout(timeout);
        block.load(block.data("wtAjaxUrl") + "&start=" + (play ? "1" : "0"));

        return false;
    }

    $(".wt-icon-media-play").on("click", function () {
        $(".wt-icon-media-play").parent().attr("hidden", true);
        $(".wt-icon-media-stop").parent().attr("hidden", false);
        play = true;
        return slideShowReload();
    });

    $(".wt-icon-media-stop").on("click", function () {
        $(".wt-icon-media-stop").parent().attr("hidden", true);
        $(".wt-icon-media-play").parent().attr("hidden", false);
        play = false;
        clearTimeout(timeout);
        return false;
    });

    $(".wt-icon-media-next").on("click", function () {
        return slideShowReload();
    });
</script>