diff --git a/src/js/media/views/attachment/details.js b/src/js/media/views/attachment/details.js
index 0afa28a4b4..babb518565 100644
a
|
b
|
Details = Attachment.extend(/** @lends wp.media.view.Attachment.Details.prototyp |
23 | 23 | 'click .trash-attachment': 'trashAttachment', |
24 | 24 | 'click .untrash-attachment': 'untrashAttachment', |
25 | 25 | 'click .edit-attachment': 'editAttachment', |
| 26 | 'click .copy-attachment-button': 'copyAttachmentLink', |
26 | 27 | 'keydown': 'toggleSelectionHandler' |
27 | 28 | }, |
28 | 29 | |
… |
… |
Details = Attachment.extend(/** @lends wp.media.view.Attachment.Details.prototyp |
217 | 218 | this.controller.trigger( 'attachment:details:shift-tab', event ); |
218 | 219 | return false; |
219 | 220 | } |
| 221 | }, |
| 222 | |
| 223 | /** |
| 224 | * Copies the attachment link to clipboard. |
| 225 | * |
| 226 | * @since 5.2.0 |
| 227 | * |
| 228 | * @param {MouseEvent} event A click event. |
| 229 | * |
| 230 | * @returns {void} |
| 231 | */ |
| 232 | copyAttachmentLink: function( event ) { |
| 233 | var linkInput = document.querySelector( '#attachment-details-two-column-copy-link' ); |
| 234 | var textArea = document.createElement( 'textarea' ); |
| 235 | textArea.value = linkInput.value; |
| 236 | textArea.style.position = 'fixed'; |
| 237 | |
| 238 | document.body.appendChild( textArea ); |
| 239 | textArea.focus(); |
| 240 | textArea.select(); |
| 241 | |
| 242 | try { |
| 243 | var successful = document.execCommand( 'copy' ); |
| 244 | } catch ( err ) { |
| 245 | alert( 'Sorry, unable to copy', err ); |
| 246 | } |
| 247 | |
| 248 | document.body.removeChild( textArea ); |
220 | 249 | } |
221 | 250 | }); |
222 | 251 | |
diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php
index 978772d732..24e1ceb035 100644
a
|
b
|
function wp_print_media_templates() { |
501 | 501 | </span> |
502 | 502 | <# } #> |
503 | 503 | <span class="setting" data-setting="url"> |
504 | | <label for="attachment-details-two-column-copy-link" class="name"><?php _e( 'Copy Link' ); ?></label> |
| 504 | <label for="attachment-details-two-column-copy-link" class="name copy-attachment-button"><?php _e( 'Copy Link' ); ?></label> |
505 | 505 | <input type="text" id="attachment-details-two-column-copy-link" value="{{ data.url }}" readonly /> |
506 | 506 | </span> |
507 | 507 | <div class="attachment-compat"></div> |