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