wp/wp-admin/js/nav-menu.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
   447 			if ( true !== $( itemToRefresh ).data( 'needs_accessibility_refresh' ) ) {
   447 			if ( true !== $( itemToRefresh ).data( 'needs_accessibility_refresh' ) ) {
   448 				return;
   448 				return;
   449 			}
   449 			}
   450 
   450 
   451 			var thisLink, thisLinkText, primaryItems, itemPosition, title,
   451 			var thisLink, thisLinkText, primaryItems, itemPosition, title,
   452 				parentItem, parentItemId, parentItemName, subItems,
   452 				parentItem, parentItemId, parentItemName, subItems, totalSubItems,
   453 				$this = $( itemToRefresh ),
   453 				$this = $( itemToRefresh ),
   454 				menuItem = $this.closest( 'li.menu-item' ).first(),
   454 				menuItem = $this.closest( 'li.menu-item' ).first(),
   455 				depth = menuItem.menuItemDepth(),
   455 				depth = menuItem.menuItemDepth(),
   456 				isPrimaryMenuItem = ( 0 === depth ),
   456 				isPrimaryMenuItem = ( 0 === depth ),
   457 				itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(),
   457 				itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(),
       
   458 				menuItemType = $this.closest( '.menu-item-handle' ).find( '.item-controls' ).find( '.item-type' ).text(),
   458 				position = parseInt( menuItem.index(), 10 ),
   459 				position = parseInt( menuItem.index(), 10 ),
   459 				prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1, 10 ),
   460 				prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1, 10 ),
   460 				prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(),
   461 				prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(),
   461 				prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(),
   462 				prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(),
   462 				totalMenuItems = $('#menu-to-edit li').length,
   463 				totalMenuItems = $('#menu-to-edit li').length,
   501 
   502 
   502 			if ( isPrimaryMenuItem ) {
   503 			if ( isPrimaryMenuItem ) {
   503 				primaryItems = $( '.menu-item-depth-0' ),
   504 				primaryItems = $( '.menu-item-depth-0' ),
   504 				itemPosition = primaryItems.index( menuItem ) + 1,
   505 				itemPosition = primaryItems.index( menuItem ) + 1,
   505 				totalMenuItems = primaryItems.length,
   506 				totalMenuItems = primaryItems.length,
   506 
       
   507 				// String together help text for primary menu items.
   507 				// String together help text for primary menu items.
   508 				title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$d', totalMenuItems );
   508 				title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$s', menuItemType ).replace( '%3$d', itemPosition ).replace( '%4$d', totalMenuItems );
   509 			} else {
   509 			} else {
   510 				parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(),
   510 				parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(),
   511 				parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(),
   511 				parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(),
   512 				parentItemName = parentItem.find( '.menu-item-title' ).text(),
   512 				parentItemName = parentItem.find( '.menu-item-title' ).text(),
   513 				subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ),
   513 				subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ),
       
   514 				totalSubItems = subItems.length,
   514 				itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1;
   515 				itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1;
   515 
   516 
   516 				// String together help text for sub menu items.
   517 				// String together help text for sub menu items.
   517 				title = menus.subMenuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$s', parentItemName );
   518 				if ( depth < 2 ) {
       
   519 					title = menus.subMenuFocus.replace( '%1$s', itemName ).replace( '%2$s', menuItemType ).replace( '%3$d', itemPosition ).replace( '%4$d', totalSubItems ).replace( '%5$s', parentItemName );
       
   520 				} else {
       
   521 					title = menus.subMenuMoreDepthFocus.replace( '%1$s', itemName ).replace( '%2$s', menuItemType ).replace( '%3$d', itemPosition ).replace( '%4$d', totalSubItems ).replace( '%5$s', parentItemName ).replace( '%6$d', depth );
       
   522 				}
   518 			}
   523 			}
   519 
   524 
   520 			$this.attr( 'aria-label', title );
   525 			$this.attr( 'aria-label', title );
   521 
   526 
   522 			// Mark this item's accessibility as refreshed.
   527 			// Mark this item's accessibility as refreshed.
   730 						ui.item[0].style.right = 0;
   735 						ui.item[0].style.right = 0;
   731 					}
   736 					}
   732 
   737 
   733 					api.refreshKeyboardAccessibility();
   738 					api.refreshKeyboardAccessibility();
   734 					api.refreshAdvancedAccessibility();
   739 					api.refreshAdvancedAccessibility();
       
   740 					api.refreshAdvancedAccessibilityOfItem( ui.item.find( 'a.item-edit' ) );
   735 				},
   741 				},
   736 				change: function(e, ui) {
   742 				change: function(e, ui) {
   737 					// Make sure the placeholder is inside the menu.
   743 					// Make sure the placeholder is inside the menu.
   738 					// Otherwise fix it, or we're in trouble.
   744 					// Otherwise fix it, or we're in trouble.
   739 					if( ! ui.placeholder.parent().hasClass('menu') )
   745 					if( ! ui.placeholder.parent().hasClass('menu') )
  1555 				}
  1561 				}
  1556 			}
  1562 			}
  1557 		});
  1563 		});
  1558 	});
  1564 	});
  1559 
  1565 
       
  1566 	// Show bulk action.
       
  1567 	$( document ).on( 'menu-item-added', function() {
       
  1568 		if ( ! $( '.bulk-actions' ).is( ':visible' ) ) {
       
  1569 			$( '.bulk-actions' ).show();
       
  1570 		}
       
  1571 	} );
       
  1572 
       
  1573 	// Hide bulk action.
       
  1574 	$( document ).on( 'menu-removing-item', function( e, el ) {
       
  1575 		var menuElement = $( el ).parents( '#menu-to-edit' );
       
  1576 		if ( menuElement.find( 'li' ).length === 1 && $( '.bulk-actions' ).is( ':visible' ) ) {
       
  1577 			$( '.bulk-actions' ).hide();
       
  1578 		}
       
  1579 	} );
       
  1580 
  1560 })(jQuery);
  1581 })(jQuery);