From 90d242939d030a057c6a0719af415ec336d379e2 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 7 Oct 2024 02:47:18 +0000 Subject: [PATCH] Media: Hide "copied" tooltip once another URL is copied to the clipboard. 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 --- src/js/_enqueues/admin/media.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/js/_enqueues/admin/media.js b/src/js/_enqueues/admin/media.js index ddc8a6c9337e6..db61220b50e5f 100644 --- a/src/js/_enqueues/admin/media.js +++ b/src/js/_enqueues/admin/media.js @@ -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 ) { @@ -224,6 +225,11 @@ // 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' ); @@ -231,8 +237,12 @@ // 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' ) ); } );