xref: /webtrees/resources/views/modules/share-url/share.phtml (revision 10e0649788c8d7d4974d81c048ca2b225df8f22e)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\GedcomRecord;
6use Fisharebest\Webtrees\I18N;
7
8/** @var GedcomRecord $record */
9
10?>
11<div class="input-group mb-3">
12    <span class="input-group-text"><?= I18N::translate('URL') ?></span>
13
14    <input type="text" class="form-control" aria-label="" value="<?= e($record->url()) ?>" readonly="readonly" id="share-url-input">
15
16    <button class="btn btn-primary" type="button" id="share-url-button">
17        <?= view('icons/copy') ?>
18        <?= I18N::translate('Copy') ?>
19    </button>
20</div>
21
22<script>
23    document.getElementById('share-url-button').addEventListener('click', function () {
24        const input = document.getElementById('share-url-input');
25        if (navigator.clipboard) {
26            navigator.clipboard.writeText(input.value);
27        } else {
28            input.select();
29            document.execCommand("copy");
30        }
31        alert(<?= json_encode(I18N::translate('The URL was copied to the clipboard'), JSON_THROW_ON_ERROR) ?>);
32    });
33</script>
34