diff --git a/src/js/_enqueues/admin/privacy-tools.js b/src/js/_enqueues/admin/privacy-tools.js index d00d5d1573..7d91e50044 100644 --- a/src/js/_enqueues/admin/privacy-tools.js +++ b/src/js/_enqueues/admin/privacy-tools.js @@ -259,10 +259,14 @@ jQuery( document ).ready( function( $ ) { doNextErasure( 1, 1 ); }); - // Privacy policy page, copy button. + // Privacy Policy page, copy action. $( document ).on( 'click', function( event ) { - var $target = $( event.target ); - var $parent, $container, range; + var $parent, + $container, + range, + __ = wp.i18n.__, + $target = $( event.target ), + copiedNotice = $target.siblings( '.success' ); if ( $target.is( 'button.privacy-text-copy' ) ) { $parent = $target.parent().parent(); @@ -277,22 +281,35 @@ jQuery( document ).ready( function( $ ) { var documentPosition = document.documentElement.scrollTop, bodyPosition = document.body.scrollTop; + // Setup copy. window.getSelection().removeAllRanges(); + + // Hide tutorial content to remove from copied content. range = document.createRange(); $container.addClass( 'hide-privacy-policy-tutorial' ); + // Copy action. range.selectNodeContents( $container[0] ); window.getSelection().addRange( range ); document.execCommand( 'copy' ); + // Reset section. $container.removeClass( 'hide-privacy-policy-tutorial' ); window.getSelection().removeAllRanges(); + // Return scroll position - see #49540. if ( documentPosition > 0 && documentPosition !== document.documentElement.scrollTop ) { document.documentElement.scrollTop = documentPosition; } else if ( bodyPosition > 0 && bodyPosition !== document.body.scrollTop ) { document.body.scrollTop = bodyPosition; } + + // Display and speak notice to indicate action complete. + copiedNotice.addClass( 'visible' ); + wp.a11y.speak( __( 'The section has been copied to your clipboard.' ) ); + + // Delay notice dismissal. + setTimeout( function(){ copiedNotice.removeClass( 'visible' ); }, 3000 ); } catch ( er ) {} } } diff --git a/src/wp-admin/css/edit.css b/src/wp-admin/css/edit.css index 7e0beb356a..1c2b3336ca 100644 --- a/src/wp-admin/css/edit.css +++ b/src/wp-admin/css/edit.css @@ -728,6 +728,18 @@ form#tags-filter { padding-bottom: 6px; } +.privacy-text-actions .success { + display: none; + color: #40860a; + float: right; + padding-right: 1em; +} + +.privacy-text-actions .success.visible { + display: inline-block; + height: 32px; +} + .wp-privacy-policy-guide .policy-text h2 { margin: 1.2em 0 1em; padding: 0; diff --git a/src/wp-admin/includes/class-wp-privacy-policy-content.php b/src/wp-admin/includes/class-wp-privacy-policy-content.php index c252bdebb6..3dd728cb52 100644 --- a/src/wp-admin/includes/class-wp-privacy-policy-content.php +++ b/src/wp-admin/includes/class-wp-privacy-policy-content.php @@ -372,12 +372,9 @@ final class WP_Privacy_Policy_Content { public static function privacy_policy_guide() { $content_array = self::get_suggested_policy_text(); - $content = ''; $toc = array( '
' . sprintf( $removed, $date ) . '