wp/wp-admin/js/common.js
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   417 	 *
   417 	 *
   418 	 * @return {void}
   418 	 * @return {void}
   419 	 */
   419 	 */
   420 	saveManageColumnsState : function() {
   420 	saveManageColumnsState : function() {
   421 		var hidden = this.hidden();
   421 		var hidden = this.hidden();
   422 		$.post(ajaxurl, {
   422 		$.post(
   423 			action: 'hidden-columns',
   423 			ajaxurl,
   424 			hidden: hidden,
   424 			{
   425 			screenoptionnonce: $('#screenoptionnonce').val(),
   425 				action: 'hidden-columns',
   426 			page: pagenow
   426 				hidden: hidden,
   427 		});
   427 				screenoptionnonce: $('#screenoptionnonce').val(),
       
   428 				page: pagenow
       
   429 			},
       
   430 			function() {
       
   431 				wp.a11y.speak( __( 'Screen Options updated.' ) );
       
   432 			}
       
   433 		);
   428 	},
   434 	},
   429 
   435 
   430 	/**
   436 	/**
   431 	 * Makes a column visible and adjusts the column span for the table.
   437 	 * Makes a column visible and adjusts the column span for the table.
   432 	 *
   438 	 *
  1112 
  1118 
  1113 			$el.append( $button );
  1119 			$el.append( $button );
  1114 		});
  1120 		});
  1115 	}
  1121 	}
  1116 
  1122 
  1117 	$document.on( 'wp-updates-notice-added wp-plugin-install-error wp-plugin-update-error wp-plugin-delete-error wp-theme-install-error wp-theme-delete-error', makeNoticesDismissible );
  1123 	$document.on( 'wp-updates-notice-added wp-plugin-install-error wp-plugin-update-error wp-plugin-delete-error wp-theme-install-error wp-theme-delete-error wp-notice-added', makeNoticesDismissible );
  1118 
  1124 
  1119 	// Init screen meta.
  1125 	// Init screen meta.
  1120 	screenMeta.init();
  1126 	screenMeta.init();
  1121 
  1127 
  1122 	/**
  1128 	/**
  1273 	// Marry the secondary "Bulk actions" controls to the primary controls:
  1279 	// Marry the secondary "Bulk actions" controls to the primary controls:
  1274 	marryControls( $('#bulk-action-selector-top'), $('#doaction'), $('#bulk-action-selector-bottom'), $('#doaction2') );
  1280 	marryControls( $('#bulk-action-selector-top'), $('#doaction'), $('#bulk-action-selector-bottom'), $('#doaction2') );
  1275 
  1281 
  1276 	// Marry the secondary "Change role to" controls to the primary controls:
  1282 	// Marry the secondary "Change role to" controls to the primary controls:
  1277 	marryControls( $('#new_role'), $('#changeit'), $('#new_role2'), $('#changeit2') );
  1283 	marryControls( $('#new_role'), $('#changeit'), $('#new_role2'), $('#changeit2') );
       
  1284 
       
  1285 	var addAdminNotice = function( data ) {
       
  1286 		var $notice = $( data.selector ),
       
  1287 			$headerEnd = $( '.wp-header-end' ),
       
  1288 			type,
       
  1289 			dismissible,
       
  1290 			$adminNotice;
       
  1291 
       
  1292 		delete data.selector;
       
  1293 
       
  1294 		dismissible = ( data.dismissible && data.dismissible === true ) ? ' is-dismissible' : '';
       
  1295 		type        = ( data.type ) ? data.type : 'info';
       
  1296 
       
  1297 		$adminNotice = '<div id="' + data.id + '" class="notice notice-' + data.type + dismissible + '"><p>' + data.message + '</p></div>';
       
  1298 
       
  1299 		// Check if this admin notice already exists.
       
  1300 		if ( ! $notice.length ) {
       
  1301 			$notice = $( '#' + data.id );
       
  1302 		}
       
  1303 
       
  1304 		if ( $notice.length ) {
       
  1305 			$notice.replaceWith( $adminNotice );
       
  1306 		} else if ( $headerEnd.length ) {
       
  1307 			$headerEnd.after( $adminNotice );
       
  1308 		} else {
       
  1309 			if ( 'customize' === pagenow ) {
       
  1310 				$( '.customize-themes-notifications' ).append( $adminNotice );
       
  1311 			} else {
       
  1312 				$( '.wrap' ).find( '> h1' ).after( $adminNotice );
       
  1313 			}
       
  1314 		}
       
  1315 
       
  1316 		$document.trigger( 'wp-notice-added' );
       
  1317 	};
       
  1318 
       
  1319 	$( '.bulkactions' ).parents( 'form' ).on( 'submit', function( event ) {
       
  1320 		var form = this,
       
  1321 			submitterName = event.originalEvent && event.originalEvent.submitter ? event.originalEvent.submitter.name : false,
       
  1322 			currentPageSelector = form.querySelector( '#current-page-selector' );
       
  1323 
       
  1324 		if ( currentPageSelector && currentPageSelector.defaultValue !== currentPageSelector.value ) {
       
  1325 			return; // Pagination form submission.
       
  1326 		}
       
  1327 
       
  1328 		// Observe submissions from posts lists for 'bulk_action' or users lists for 'new_role'.
       
  1329 		var bulkFieldRelations = {
       
  1330 			'bulk_action' : window.bulkActionObserverIds.bulk_action,
       
  1331 			'changeit' : window.bulkActionObserverIds.changeit
       
  1332 		};
       
  1333 		if ( ! Object.keys( bulkFieldRelations ).includes( submitterName ) ) {
       
  1334 			return;
       
  1335 		}
       
  1336 
       
  1337 		var values = new FormData(form);
       
  1338 		var value = values.get( bulkFieldRelations[ submitterName ] ) || '-1';
       
  1339 
       
  1340 		// Check that the action is not the default one.
       
  1341 		if ( value !== '-1' ) {
       
  1342 			// Check that at least one item is selected.
       
  1343 			var itemsSelected = form.querySelectorAll( '.wp-list-table tbody .check-column input[type="checkbox"]:checked' );
       
  1344 
       
  1345 			if ( itemsSelected.length > 0 ) {
       
  1346 				return;
       
  1347 			}
       
  1348 		}
       
  1349 		event.preventDefault();
       
  1350 		event.stopPropagation();
       
  1351 		$( 'html, body' ).animate( { scrollTop: 0 } );
       
  1352 
       
  1353 		var errorMessage = __( 'Please select at least one item to perform this action on.' );
       
  1354 		addAdminNotice( {
       
  1355 			id: 'no-items-selected',
       
  1356 			type: 'error',
       
  1357 			message: errorMessage,
       
  1358 			dismissible: true,
       
  1359 		} );
       
  1360 
       
  1361 		wp.a11y.speak( errorMessage );
       
  1362 	});
  1278 
  1363 
  1279 	/**
  1364 	/**
  1280 	 * Shows row actions on focus of its parent container element or any other elements contained within.
  1365 	 * Shows row actions on focus of its parent container element or any other elements contained within.
  1281 	 *
  1366 	 *
  1282 	 * @return {void}
  1367 	 * @return {void}