mirror of
git://develop.git.wordpress.org/
synced 2025-03-21 12:29:53 +01:00
Media: Add a "Copy URL to clipboard" function to the list table view.
Previously, a button was added to the modal view for a single media item in the "grid" view to copy the file URL to the user's clipboard. This change adds a similar function to the "list" view for each media item. Follow-up to [48232]. Props pbiron, ravipatel, alexstine, afercia. Fixes #54426. git-svn-id: https://develop.svn.wordpress.org/trunk@52842 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e4955f67c2
commit
d238f31fab
@ -141,7 +141,10 @@
|
||||
* @return {void}
|
||||
*/
|
||||
$( function() {
|
||||
var settings, $mediaGridWrap = $( '#wp-media-grid' );
|
||||
var settings,
|
||||
$mediaGridWrap = $( '#wp-media-grid' ),
|
||||
copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.media-library' ),
|
||||
copyAttachmentURLSuccessTimeout;
|
||||
|
||||
// Opens a manage media frame into the grid.
|
||||
if ( $mediaGridWrap.length && window.wp && window.wp.media ) {
|
||||
@ -205,5 +208,35 @@
|
||||
$( '.find-box-inside' ).on( 'click', 'tr', function() {
|
||||
$( this ).find( '.found-radio input' ).prop( 'checked', true );
|
||||
});
|
||||
|
||||
/**
|
||||
* Handles media list copy media URL button.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @param {MouseEvent} event A click event.
|
||||
* @return {void}
|
||||
*/
|
||||
copyAttachmentURLClipboard.on( 'success', function( event ) {
|
||||
var triggerElement = $( event.trigger ),
|
||||
successElement = $( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) );
|
||||
|
||||
// Clear the selection and move focus back to the trigger.
|
||||
event.clearSelection();
|
||||
// Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680.
|
||||
triggerElement.trigger( 'focus' );
|
||||
|
||||
// Show success visual feedback.
|
||||
clearTimeout( copyAttachmentURLSuccessTimeout );
|
||||
successElement.removeClass( 'hidden' );
|
||||
|
||||
// Hide success visual feedback after 3 seconds since last success and unfocus the trigger.
|
||||
copyAttachmentURLSuccessTimeout = setTimeout( function() {
|
||||
successElement.addClass( 'hidden' );
|
||||
}, 3000 );
|
||||
|
||||
// Handle success audible feedback.
|
||||
wp.a11y.speak( wp.i18n.__( 'The file URL has been copied to your clipboard' ) );
|
||||
} );
|
||||
});
|
||||
})( jQuery );
|
||||
|
@ -384,6 +384,23 @@ table.media .column-title .filename {
|
||||
margin-bottom: 0.2em;
|
||||
}
|
||||
|
||||
/* Media Copy to clipboard row action */
|
||||
.media .row-actions .copy-to-clipboard-container {
|
||||
display: inline;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.media .row-actions .copy-to-clipboard-container .success {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -100%);
|
||||
background: #000;
|
||||
color: #fff;
|
||||
border-radius: 5px;
|
||||
margin: 0;
|
||||
padding: 2px 5px;
|
||||
}
|
||||
|
||||
/* @todo: pick a consistent list table selector */
|
||||
.wp-list-table a {
|
||||
transition: none;
|
||||
|
@ -806,6 +806,15 @@ class WP_Media_List_Table extends WP_List_Table {
|
||||
esc_attr( sprintf( __( 'View “%s”' ), $att_title ) ),
|
||||
__( 'View' )
|
||||
);
|
||||
|
||||
$actions['copy'] = sprintf(
|
||||
'<span class="copy-to-clipboard-container"><button type="button" class="button-link copy-attachment-url media-library" data-clipboard-text="%s" aria-label="%s">%s</button><span class="success hidden" aria-hidden="true">%s</span></span>',
|
||||
esc_url( wp_get_attachment_url( $post->ID ) ),
|
||||
/* translators: %s: Attachment title. */
|
||||
esc_attr( sprintf( __( 'Copy “%s” URL to clipboard' ), $att_title ) ),
|
||||
__( 'Copy URL to clipboard' ),
|
||||
__( 'Copied!' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1351,7 +1351,7 @@ function wp_default_scripts( $scripts ) {
|
||||
$scripts->add( 'list-revisions', "/wp-includes/js/wp-list-revisions$suffix.js" );
|
||||
|
||||
$scripts->add( 'media-grid', "/wp-includes/js/media-grid$suffix.js", array( 'media-editor' ), false, 1 );
|
||||
$scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery' ), false, 1 );
|
||||
$scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery', 'clipboard', 'wp-i18n', 'wp-a11y' ), false, 1 );
|
||||
$scripts->set_translations( 'media' );
|
||||
|
||||
$scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array( 'jquery', 'jquery-ui-core', 'json2', 'imgareaselect', 'wp-a11y' ), false, 1 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user