Skip to content

Commit e060184

Browse files
committed
Make copy to clipboard function generic
1 parent 949f158 commit e060184

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

resources/js/app.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import './bootstrap';
22

33
import jQuery from '$';
4-
window.$ = jQuery;
5-
64
import 'flowbite';
75

86
import '@fortawesome/fontawesome-free/scss/fontawesome.scss';
@@ -18,6 +16,8 @@ import Alpine from 'alpinejs'
1816
import FormsAlpinePlugin from '../../vendor/filament/forms/dist/module.esm'
1917
import NotificationsAlpinePlugin from '../../vendor/filament/notifications/dist/module.esm'
2018

19+
window.$ = jQuery;
20+
2121
Alpine.plugin(FormsAlpinePlugin)
2222
Alpine.plugin(NotificationsAlpinePlugin)
2323

@@ -48,3 +48,18 @@ if ($('.magnificpopup-container').length) {
4848
}
4949
});
5050
}
51+
52+
// Copy text to clipboard
53+
window.unsecuredCopyToClipboard = function (text) {
54+
const textArea = document.createElement("textarea");
55+
textArea.value = text;
56+
document.body.appendChild(textArea);
57+
textArea.focus();
58+
textArea.select();
59+
try {
60+
document.execCommand('copy');
61+
} catch (err) {
62+
console.error('Unable to copy to clipboard', err);
63+
}
64+
document.body.removeChild(textArea);
65+
}

resources/views/livewire/ticket-details.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
@push('scripts')
8484
<script>
8585
window.addEventListener('ticketUrlCopied', (event) => {
86-
navigator.clipboard.writeText(event.detail.url);
86+
window.unsecuredCopyToClipboard(event.detail.url);
8787
});
8888
</script>
8989
@endpush

resources/views/livewire/tickets.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
});
154154
155155
window.addEventListener('ticketUrlCopied', (event) => {
156-
navigator.clipboard.writeText(event.detail.url);
156+
window.unsecuredCopyToClipboard(event.detail.url);
157157
});
158158
</script>
159159
@endpush

0 commit comments

Comments
 (0)