mirror of
https://github.com/moodle/moodle.git
synced 2025-03-24 01:20:27 +01:00
This works by adding event listeners for elements that contain the 'copytoclipboard' "data-action" attribute through event delegation. These trigger elements must also define a "data-clipboard-target" attribute which contains the query selector for the target element where text will be copied. On success, a toast message is shown to the user that the text has been copied to the clipboard. This success message can be customised by passing a message string to the "data-clipboard-success-message" attribute in the trigger element. When the element's value or innerText cannot be found, a toast message indicating that the text cannot be copied to the clipboard is shown. The copy to clipboard functionality is primarily using the Clipboard API but in the event that this is not available, e.g. the site is not running on HTTPS, this falls back to the document.execCommand('copy') approach of copying the text in the target container. Special thanks to Andrew for improving this module with the event delegation approach and improved fallback handling. Co-authored-by: Andrew Lyons <andrew@nicols.co.uk>