wp/wp-admin/js/privacy-tools.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 21 48c4eec2b7e6
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
     3  *
     3  *
     4  * @output wp-admin/js/privacy-tools.js
     4  * @output wp-admin/js/privacy-tools.js
     5  */
     5  */
     6 
     6 
     7 // Privacy request action handling.
     7 // Privacy request action handling.
     8 jQuery( document ).ready( function( $ ) {
     8 jQuery( function( $ ) {
     9 	var __ = wp.i18n.__,
     9 	var __ = wp.i18n.__,
    10 		copiedNoticeTimeout;
    10 		copiedNoticeTimeout;
    11 
    11 
    12 	function setActionState( $action, state ) {
    12 	function setActionState( $action, state ) {
    13 		$action.children().addClass( 'hidden' );
    13 		$action.children().addClass( 'hidden' );
    54 				'</td>' +
    54 				'</td>' +
    55 				'</tr>';
    55 				'</tr>';
    56 		});
    56 		});
    57 	}
    57 	}
    58 
    58 
    59 	$( '.export-personal-data-handle' ).click( function( event ) {
    59 	$( '.export-personal-data-handle' ).on( 'click', function( event ) {
    60 		var $this          = $( this ),
    60 		var $this          = $( this ),
    61 			$action        = $this.parents( '.export-personal-data' ),
    61 			$action        = $this.parents( '.export-personal-data' ),
    62 			$requestRow    = $this.parents( 'tr' ),
    62 			$requestRow    = $this.parents( 'tr' ),
    63 			$progress      = $requestRow.find( '.export-progress' ),
    63 			$progress      = $requestRow.find( '.export-progress' ),
    64 			$rowActions    = $this.parents( '.row-actions' ),
    64 			$rowActions    = $this.parents( '.row-actions' ),
    70 		event.preventDefault();
    70 		event.preventDefault();
    71 		event.stopPropagation();
    71 		event.stopPropagation();
    72 
    72 
    73 		$rowActions.addClass( 'processing' );
    73 		$rowActions.addClass( 'processing' );
    74 
    74 
    75 		$action.blur();
    75 		$action.trigger( 'blur' );
    76 		clearResultsAfterRow( $requestRow );
    76 		clearResultsAfterRow( $requestRow );
    77 		setExportProgress( 0 );
    77 		setExportProgress( 0 );
    78 
    78 
    79 		function onExportDoneSuccess( zipUrl ) {
    79 		function onExportDoneSuccess( zipUrl ) {
    80 			var summaryMessage = __( 'The personal data export link for this user was sent.' );
    80 			var summaryMessage = __( 'This user&#8217;s personal data export link was sent.' );
       
    81 
       
    82 			if ( 'undefined' !== typeof zipUrl ) {
       
    83 				summaryMessage = __( 'This user&#8217;s personal data export file was downloaded.' );
       
    84 			}
    81 
    85 
    82 			setActionState( $action, 'export-personal-data-success' );
    86 			setActionState( $action, 'export-personal-data-success' );
    83 
    87 
    84 			appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
    88 			appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
    85 
    89 
   153 		// And now, let's begin.
   157 		// And now, let's begin.
   154 		setActionState( $action, 'export-personal-data-processing' );
   158 		setActionState( $action, 'export-personal-data-processing' );
   155 		doNextExport( 1, 1 );
   159 		doNextExport( 1, 1 );
   156 	});
   160 	});
   157 
   161 
   158 	$( '.remove-personal-data-handle' ).click( function( event ) {
   162 	$( '.remove-personal-data-handle' ).on( 'click', function( event ) {
   159 		var $this         = $( this ),
   163 		var $this         = $( this ),
   160 			$action       = $this.parents( '.remove-personal-data' ),
   164 			$action       = $this.parents( '.remove-personal-data' ),
   161 			$requestRow   = $this.parents( 'tr' ),
   165 			$requestRow   = $this.parents( 'tr' ),
   162 			$progress     = $requestRow.find( '.erasure-progress' ),
   166 			$progress     = $requestRow.find( '.erasure-progress' ),
   163 			$rowActions   = $this.parents( '.row-actions' ),
   167 			$rowActions   = $this.parents( '.row-actions' ),
   171 		event.preventDefault();
   175 		event.preventDefault();
   172 		event.stopPropagation();
   176 		event.stopPropagation();
   173 
   177 
   174 		$rowActions.addClass( 'processing' );
   178 		$rowActions.addClass( 'processing' );
   175 
   179 
   176 		$action.blur();
   180 		$action.trigger( 'blur' );
   177 		clearResultsAfterRow( $requestRow );
   181 		clearResultsAfterRow( $requestRow );
   178 		setErasureProgress( 0 );
   182 		setErasureProgress( 0 );
   179 
   183 
   180 		function onErasureDoneSuccess() {
   184 		function onErasureDoneSuccess() {
   181 			var summaryMessage = __( 'No personal data was found for this user.' ),
   185 			var summaryMessage = __( 'No personal data was found for this user.' ),
   269 	});
   273 	});
   270 
   274 
   271 	// Privacy Policy page, copy action.
   275 	// Privacy Policy page, copy action.
   272 	$( document ).on( 'click', function( event ) {
   276 	$( document ).on( 'click', function( event ) {
   273 		var $parent,
   277 		var $parent,
   274 			$container,
       
   275 			range,
   278 			range,
   276 			$target = $( event.target ),
   279 			$target = $( event.target ),
   277 			copiedNotice = $target.siblings( '.success' );
   280 			copiedNotice = $target.siblings( '.success' );
   278 
   281 
   279 		clearTimeout( copiedNoticeTimeout );
   282 		clearTimeout( copiedNoticeTimeout );
   280 
   283 
   281 		if ( $target.is( 'button.privacy-text-copy' ) ) {
   284 		if ( $target.is( 'button.privacy-text-copy' ) ) {
   282 			$parent = $target.parent().parent();
   285 			$parent = $target.closest( '.privacy-settings-accordion-panel' );
   283 			$container = $parent.find( 'div.wp-suggested-text' );
   286 
   284 
   287 			if ( $parent.length ) {
   285 			if ( ! $container.length ) {
       
   286 				$container = $parent.find( 'div.policy-text' );
       
   287 			}
       
   288 
       
   289 			if ( $container.length ) {
       
   290 				try {
   288 				try {
   291 					var documentPosition = document.documentElement.scrollTop,
   289 					var documentPosition = document.documentElement.scrollTop,
   292 						bodyPosition     = document.body.scrollTop;
   290 						bodyPosition     = document.body.scrollTop;
   293 
   291 
   294 					// Setup copy.
   292 					// Setup copy.
   295 					window.getSelection().removeAllRanges();
   293 					window.getSelection().removeAllRanges();
   296 
   294 
   297 					// Hide tutorial content to remove from copied content.
   295 					// Hide tutorial content to remove from copied content.
   298 					range = document.createRange();
   296 					range = document.createRange();
   299 					$container.addClass( 'hide-privacy-policy-tutorial' );
   297 					$parent.addClass( 'hide-privacy-policy-tutorial' );
   300 
   298 
   301 					// Copy action.
   299 					// Copy action.
   302 					range.selectNodeContents( $container[0] );
   300 					range.selectNodeContents( $parent[0] );
   303 					window.getSelection().addRange( range );
   301 					window.getSelection().addRange( range );
   304 					document.execCommand( 'copy' );
   302 					document.execCommand( 'copy' );
   305 
   303 
   306 					// Reset section.
   304 					// Reset section.
   307 					$container.removeClass( 'hide-privacy-policy-tutorial' );
   305 					$parent.removeClass( 'hide-privacy-policy-tutorial' );
   308 					window.getSelection().removeAllRanges();
   306 					window.getSelection().removeAllRanges();
   309 
   307 
   310 					// Return scroll position - see #49540.
   308 					// Return scroll position - see #49540.
   311 					if ( documentPosition > 0 && documentPosition !== document.documentElement.scrollTop ) {
   309 					if ( documentPosition > 0 && documentPosition !== document.documentElement.scrollTop ) {
   312 						document.documentElement.scrollTop = documentPosition;
   310 						document.documentElement.scrollTop = documentPosition;
   314 						document.body.scrollTop = bodyPosition;
   312 						document.body.scrollTop = bodyPosition;
   315 					}
   313 					}
   316 
   314 
   317 					// Display and speak notice to indicate action complete.
   315 					// Display and speak notice to indicate action complete.
   318 					copiedNotice.addClass( 'visible' );
   316 					copiedNotice.addClass( 'visible' );
   319 					wp.a11y.speak( __( 'The section has been copied to your clipboard.' ) );
   317 					wp.a11y.speak( __( 'The suggested policy text has been copied to your clipboard.' ) );
   320 
   318 
   321 					// Delay notice dismissal.
   319 					// Delay notice dismissal.
   322 					copiedNoticeTimeout = setTimeout( function() {
   320 					copiedNoticeTimeout = setTimeout( function() {
   323 						copiedNotice.removeClass( 'visible' );
   321 						copiedNotice.removeClass( 'visible' );
   324 					}, 3000 );
   322 					}, 3000 );
   325 				} catch ( er ) {}
   323 				} catch ( er ) {}
   326 			}
   324 			}
   327 		}
   325 		}
   328 	});
   326 	});
       
   327 
       
   328 	// Label handling to focus the create page button on Privacy settings page.
       
   329 	$( 'body.options-privacy-php label[for=create-page]' ).on( 'click', function( e ) {
       
   330 		e.preventDefault();
       
   331 		$( 'input#create-page' ).trigger( 'focus' );
       
   332 	} );
       
   333 
       
   334 	// Accordion handling in various new Privacy settings pages.
       
   335 	$( '.privacy-settings-accordion' ).on( 'click', '.privacy-settings-accordion-trigger', function() {
       
   336 		var isExpanded = ( 'true' === $( this ).attr( 'aria-expanded' ) );
       
   337 
       
   338 		if ( isExpanded ) {
       
   339 			$( this ).attr( 'aria-expanded', 'false' );
       
   340 			$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', true );
       
   341 		} else {
       
   342 			$( this ).attr( 'aria-expanded', 'true' );
       
   343 			$( '#' + $( this ).attr( 'aria-controls' ) ).attr( 'hidden', false );
       
   344 		}
       
   345 	} );
   329 });
   346 });