Skip to content

Commit 90d2429

Browse files
committed
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
1 parent 023d3c4 commit 90d2429

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/js/_enqueues/admin/media.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144
var settings,
145145
$mediaGridWrap = $( '#wp-media-grid' ),
146146
copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.media-library' ),
147-
copyAttachmentURLSuccessTimeout;
147+
copyAttachmentURLSuccessTimeout,
148+
previousSuccessElement = null;
148149

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

228+
// Checking if the previousSuccessElement is present, adding the hidden class to it.
229+
if ( previousSuccessElement ) {
230+
previousSuccessElement.addClass( 'hidden' );
231+
}
232+
227233
// Show success visual feedback.
228234
clearTimeout( copyAttachmentURLSuccessTimeout );
229235
successElement.removeClass( 'hidden' );
230236

231237
// Hide success visual feedback after 3 seconds since last success and unfocus the trigger.
232238
copyAttachmentURLSuccessTimeout = setTimeout( function() {
233239
successElement.addClass( 'hidden' );
240+
// No need to store the previous success element further.
241+
previousSuccessElement = null;
234242
}, 3000 );
235243

244+
previousSuccessElement = successElement;
245+
236246
// Handle success audible feedback.
237247
wp.a11y.speak( wp.i18n.__( 'The file URL has been copied to your clipboard' ) );
238248
} );

0 commit comments

Comments
 (0)