Skip to content

Commit

Permalink
Media: Hide "copied" tooltip once another URL is copied to the clipbo…
Browse files Browse the repository at this point in the history
…ard.

On the media grid view, hide the copied tooltip when a subsequent URL is copied to the clipboard. This prevents tooltips from remaining displayed if a user copies multiple URLs within a three second period.

Props antpb, debarghyabanerjee, jayadevankbh, sabernhardt.
Fixes #60082.



git-svn-id: https://develop.svn.wordpress.org/trunk@59187 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
peterwilsoncc committed Oct 7, 2024
1 parent 023d3c4 commit 90d2429
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/js/_enqueues/admin/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@
var settings,
$mediaGridWrap = $( '#wp-media-grid' ),
copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.media-library' ),
copyAttachmentURLSuccessTimeout;
copyAttachmentURLSuccessTimeout,
previousSuccessElement = null;

// Opens a manage media frame into the grid.
if ( $mediaGridWrap.length && window.wp && window.wp.media ) {
Expand Down Expand Up @@ -224,15 +225,24 @@
// Clear the selection and move focus back to the trigger.
event.clearSelection();

// Checking if the previousSuccessElement is present, adding the hidden class to it.
if ( previousSuccessElement ) {
previousSuccessElement.addClass( 'hidden' );
}

// 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' );
// No need to store the previous success element further.
previousSuccessElement = null;
}, 3000 );

previousSuccessElement = successElement;

// Handle success audible feedback.
wp.a11y.speak( wp.i18n.__( 'The file URL has been copied to your clipboard' ) );
} );
Expand Down

0 comments on commit 90d2429

Please sign in to comment.