xref: /webtrees/resources/views/modules/share-url/share.phtml (revision 10e0649788c8d7d4974d81c048ca2b225df8f22e)
1853f2b8aSGreg Roach<?php
2853f2b8aSGreg Roach
3*10e06497SGreg Roachdeclare(strict_types=1);
4*10e06497SGreg Roach
5853f2b8aSGreg Roachuse Fisharebest\Webtrees\GedcomRecord;
6853f2b8aSGreg Roachuse Fisharebest\Webtrees\I18N;
7853f2b8aSGreg Roach
8853f2b8aSGreg Roach/** @var GedcomRecord $record */
9853f2b8aSGreg Roach
10853f2b8aSGreg Roach?>
11853f2b8aSGreg Roach<div class="input-group mb-3">
12853f2b8aSGreg Roach    <span class="input-group-text"><?= I18N::translate('URL') ?></span>
13853f2b8aSGreg Roach
14853f2b8aSGreg Roach    <input type="text" class="form-control" aria-label="" value="<?= e($record->url()) ?>" readonly="readonly" id="share-url-input">
15853f2b8aSGreg Roach
16315eb316SGreg Roach    <button class="btn btn-primary" type="button" id="share-url-button">
17315eb316SGreg Roach        <?= view('icons/copy') ?>
18315eb316SGreg Roach        <?= I18N::translate('Copy') ?>
19315eb316SGreg Roach    </button>
20853f2b8aSGreg Roach</div>
21853f2b8aSGreg Roach
22853f2b8aSGreg Roach<script>
23853f2b8aSGreg Roach    document.getElementById('share-url-button').addEventListener('click', function () {
245dd6eb1fSGreg Roach        const input = document.getElementById('share-url-input');
255dd6eb1fSGreg Roach        if (navigator.clipboard) {
265dd6eb1fSGreg Roach            navigator.clipboard.writeText(input.value);
275dd6eb1fSGreg Roach        } else {
285dd6eb1fSGreg Roach            input.select();
295dd6eb1fSGreg Roach            document.execCommand("copy");
305dd6eb1fSGreg Roach        }
31728c8c27SGreg Roach        alert(<?= json_encode(I18N::translate('The URL was copied to the clipboard'), JSON_THROW_ON_ERROR) ?>);
32853f2b8aSGreg Roach    });
33853f2b8aSGreg Roach</script>
34