[AMOS commit] MDL-61460 core: Create a copy to clipboard JS module Committed into Git: 2021-06-23 09:27 UTC

[AMOS commit] MDL-61460 core: Create a copy to clipboard JS module Committed into Git: 2021-06-23 09:27 UTC

by AMOS bot -
Number of replies: 0
Author: Jun Pataleta
MDL-61460 core: Create a copy to clipboard JS module
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>


http://git.moodle.org/gw?p=moodle.git;a=commit;h=341578bfde777f2cb547e2711eb16169c0d35fb0
http://github.com/moodle/moodle/commit/341578bfde777f2cb547e2711eb16169c0d35fb0

+ 4.0 en [textcopiedtoclipboard,core]
+ 4.0 en [unabletocopytoclipboard,core]