Accessibility: Media: Add a "Copy URL" button to the attachment File URL fields.

For a number of years, various screens in the WordPress admin provided users with a readonly input field to copy the attachment file URL. Manually copying from a readonly field is an annoying task at best even for mouser users. It's a usability and accessibility issue at the same time. 
These fields now have a new "Copy URL" button that is easy to use and accessible to everyone.

Props theolg, markdubois, vabrashev, sajjad67, xkon, nrqsnchz, melchoyce, audrasjb, afercia.
See #41612, #50322, #50335.
Fixes #48463.

Built from https://develop.svn.wordpress.org/trunk@48232


git-svn-id: http://core.svn.wordpress.org/trunk@48001 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrea Fercia
2020-06-30 13:16:04 +00:00
parent 91a38c62ea
commit eebf187963
20 changed files with 219 additions and 23 deletions

View File

@@ -798,6 +798,16 @@ border color while dragging a file over the uploader drop area */
text-decoration: none;
}
.copy-to-clipboard-container {
display: flex;
align-items: center;
margin-top: 8px;
clear: both;
}
.copy-to-clipboard-container .success {
margin-right: 8px;
}
/*------------------------------------------------------------------------------
14.2 - Image Editor
@@ -1216,6 +1226,10 @@ audio, video {
width: auto;
max-width: none;
}
.copy-to-clipboard-container .success {
font-size: 14px;
}
}
/**

File diff suppressed because one or more lines are too long

View File

@@ -797,6 +797,16 @@ border color while dragging a file over the uploader drop area */
text-decoration: none;
}
.copy-to-clipboard-container {
display: flex;
align-items: center;
margin-top: 8px;
clear: both;
}
.copy-to-clipboard-container .success {
margin-left: 8px;
}
/*------------------------------------------------------------------------------
14.2 - Image Editor
@@ -1215,6 +1225,10 @@ audio, video {
width: auto;
max-width: none;
}
.copy-to-clipboard-container .success {
font-size: 14px;
}
}
/**

File diff suppressed because one or more lines are too long

View File

@@ -3268,6 +3268,10 @@ function attachment_submitbox_metadata() {
<div class="misc-pub-section misc-pub-attachment">
<label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" />
<span class="copy-to-clipboard-container">
<button type="button" class="button copy-attachment-url edit-media" data-clipboard-target="#attachment_url"><?php _e( 'Copy URL' ); ?></button>
<span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span>
</span>
</div>
<div class="misc-pub-section misc-pub-filename">
<?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong>

View File

@@ -4,7 +4,7 @@
* @output wp-admin/js/post.js
*/
/* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */
/* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting, ClipboardJS */
/* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */
/* global WPSetThumbnailHTML, wptitlehint */
@@ -297,7 +297,10 @@ jQuery(document).ready( function($) {
$postVisibilitySelect = $('#post-visibility-select'),
$timestampdiv = $('#timestampdiv'),
$postStatusSelect = $('#post-status-select'),
isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false;
isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false,
copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.edit-media' ),
copyAttachmentURLSuccessTimeout,
__ = wp.i18n.__;
postboxes.add_postbox_toggles(pagenow);
@@ -1217,7 +1220,38 @@ jQuery(document).ready( function($) {
window.history.replaceState( null, null, location );
});
}
});
/**
* Copies the attachment URL in the Edit Media page to the clipboard.
*
* @since 5.5.0
*
* @param {MouseEvent} event A click event.
*
* @returns {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.focus();
// Show success visual feedback.
clearTimeout( copyAttachmentURLSuccessTimeout );
successElement.removeClass( 'hidden' );
// Hide success visual feedback after 3 seconds since last success.
copyAttachmentURLSuccessTimeout = setTimeout( function() {
successElement.addClass( 'hidden' );
}, 3000 );
// Handle success audible feedback.
wp.a11y.speak( __( 'The file URL has been copied to your clipboard' ) );
} );
} );
/**
* TinyMCE word count display

File diff suppressed because one or more lines are too long