wp/wp-admin/js/nav-menu.js
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     6  *
     6  *
     7  * @package WordPress
     7  * @package WordPress
     8  * @subpackage Administration
     8  * @subpackage Administration
     9  */
     9  */
    10 
    10 
       
    11 /* global menus, postboxes, columns, isRtl, navMenuL10n, ajaxurl */
       
    12 
    11 var wpNavMenu;
    13 var wpNavMenu;
    12 
    14 
    13 (function($) {
    15 (function($) {
    14 
    16 
    15 	var api = wpNavMenu = {
    17 	var api;
       
    18 
       
    19 	api = wpNavMenu = {
    16 
    20 
    17 		options : {
    21 		options : {
    18 			menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
    22 			menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
    19 			globalMaxDepth : 11
    23 			globalMaxDepth : 11
    20 		},
    24 		},
    51 			this.initManageLocations();
    55 			this.initManageLocations();
    52 
    56 
    53 			this.initAccessibility();
    57 			this.initAccessibility();
    54 
    58 
    55 			this.initToggles();
    59 			this.initToggles();
       
    60 
       
    61 			this.initPreviewing();
    56 		},
    62 		},
    57 
    63 
    58 		jQueryExtensions : function() {
    64 		jQueryExtensions : function() {
    59 			// jQuery extensions
    65 			// jQuery extensions
    60 			$.fn.extend({
    66 			$.fn.extend({
   109 						// Change .menu-item-depth-n class
   115 						// Change .menu-item-depth-n class
   110 						t.updateDepthClass( newDepth, depth ).updateParentMenuItemDBId();
   116 						t.updateDepthClass( newDepth, depth ).updateParentMenuItemDBId();
   111 
   117 
   112 						// If it has children, move those too
   118 						// If it has children, move those too
   113 						if ( children ) {
   119 						if ( children ) {
   114 							children.each(function( index ) {
   120 							children.each(function() {
   115 								var t = $(this),
   121 								var t = $(this),
   116 									thisDepth = t.menuItemDepth(),
   122 									thisDepth = t.menuItemDepth(),
   117 									newDepth = thisDepth + diff;
   123 									newDepth = thisDepth + diff;
   118 								t.updateDepthClass(newDepth, thisDepth).updateParentMenuItemDBId();
   124 								t.updateDepthClass(newDepth, thisDepth).updateParentMenuItemDBId();
   119 							});
   125 							});
   128 				},
   134 				},
   129 				updateParentMenuItemDBId : function() {
   135 				updateParentMenuItemDBId : function() {
   130 					return this.each(function(){
   136 					return this.each(function(){
   131 						var item = $(this),
   137 						var item = $(this),
   132 							input = item.find( '.menu-item-data-parent-id' ),
   138 							input = item.find( '.menu-item-data-parent-id' ),
   133 							depth = parseInt( item.menuItemDepth() ),
   139 							depth = parseInt( item.menuItemDepth(), 10 ),
   134 							parentDepth = depth - 1,
   140 							parentDepth = depth - 1,
   135 							parent = item.prevAll( '.menu-item-depth-' + parentDepth ).first();
   141 							parent = item.prevAll( '.menu-item-depth-' + parentDepth ).first();
   136 
   142 
   137 						if ( 0 == depth ) { // Item is on the top level, has no parent
   143 						if ( 0 === depth ) { // Item is on the top level, has no parent
   138 							input.val(0);
   144 							input.val(0);
   139 						} else { // Find the parent item, and retrieve its object id.
   145 						} else { // Find the parent item, and retrieve its object id.
   140 							input.val( parent.find( '.menu-item-data-db-id' ).val() );
   146 							input.val( parent.find( '.menu-item-data-db-id' ).val() );
   141 						}
   147 						}
   142 					});
   148 					});
   153 				 * Adds selected menu items to the menu.
   159 				 * Adds selected menu items to the menu.
   154 				 *
   160 				 *
   155 				 * @param jQuery metabox The metabox jQuery object.
   161 				 * @param jQuery metabox The metabox jQuery object.
   156 				 */
   162 				 */
   157 				addSelectedToMenu : function(processMethod) {
   163 				addSelectedToMenu : function(processMethod) {
   158 					if ( 0 == $('#menu-to-edit').length ) {
   164 					if ( 0 === $('#menu-to-edit').length ) {
   159 						return false;
   165 						return false;
   160 					}
   166 					}
   161 
   167 
   162 					return this.each(function() {
   168 					return this.each(function() {
   163 						var t = $(this), menuItems = {},
   169 						var t = $(this), menuItems = {},
   164 							checkboxes = ( menus.oneThemeLocationNoMenus && 0 == t.find('.tabs-panel-active .categorychecklist li input:checked').length ) ? t.find('#page-all li input[type="checkbox"]') : t.find('.tabs-panel-active .categorychecklist li input:checked'),
   170 							checkboxes = ( menus.oneThemeLocationNoMenus && 0 === t.find( '.tabs-panel-active .categorychecklist li input:checked' ).length ) ? t.find( '#page-all li input[type="checkbox"]' ) : t.find( '.tabs-panel-active .categorychecklist li input:checked' ),
   165 							re = new RegExp('menu-item\\[(\[^\\]\]*)');
   171 							re = /menu-item\[([^\]]*)/;
   166 
   172 
   167 						processMethod = processMethod || api.addMenuItemToBottom;
   173 						processMethod = processMethod || api.addMenuItemToBottom;
   168 
   174 
   169 						// If no items are checked, bail.
   175 						// If no items are checked, bail.
   170 						if ( !checkboxes.length )
   176 						if ( !checkboxes.length )
   171 							return false;
   177 							return false;
   172 
   178 
   173 						// Show the ajax spinner
   179 						// Show the ajax spinner
   174 						t.find('.spinner').show();
   180 						t.find( '.spinner' ).addClass( 'is-active' );
   175 
   181 
   176 						// Retrieve menu item data
   182 						// Retrieve menu item data
   177 						$(checkboxes).each(function(){
   183 						$(checkboxes).each(function(){
   178 							var t = $(this),
   184 							var t = $(this),
   179 								listItemDBIDMatch = re.exec( t.attr('name') ),
   185 								listItemDBIDMatch = re.exec( t.attr('name') ),
   186 
   192 
   187 						// Add the items
   193 						// Add the items
   188 						api.addItemToMenu(menuItems, processMethod, function(){
   194 						api.addItemToMenu(menuItems, processMethod, function(){
   189 							// Deselect the items and hide the ajax spinner
   195 							// Deselect the items and hide the ajax spinner
   190 							checkboxes.removeAttr('checked');
   196 							checkboxes.removeAttr('checked');
   191 							t.find('.spinner').hide();
   197 							t.find( '.spinner' ).removeClass( 'is-active' );
   192 						});
   198 						});
   193 					});
   199 					});
   194 				},
   200 				},
   195 				getItemData : function( itemType, id ) {
   201 				getItemData : function( itemType, id ) {
   196 					itemType = itemType || 'menu-item';
   202 					itemType = itemType || 'menu-item';
   269 			return $( '.menu-item-depth-' + depth ).length;
   275 			return $( '.menu-item-depth-' + depth ).length;
   270 		},
   276 		},
   271 
   277 
   272 		moveMenuItem : function( $this, dir ) {
   278 		moveMenuItem : function( $this, dir ) {
   273 
   279 
   274 			var menuItems = $('#menu-to-edit li');
   280 			var items, newItemPosition, newDepth,
       
   281 				menuItems = $( '#menu-to-edit li' ),
   275 				menuItemsCount = menuItems.length,
   282 				menuItemsCount = menuItems.length,
   276 				thisItem = $this.parents( 'li.menu-item' ),
   283 				thisItem = $this.parents( 'li.menu-item' ),
   277 				thisItemChildren = thisItem.childMenuItems(),
   284 				thisItemChildren = thisItem.childMenuItems(),
   278 				thisItemData = thisItem.getItemData(),
   285 				thisItemData = thisItem.getItemData(),
   279 				thisItemDepth = parseInt( thisItem.menuItemDepth() ),
   286 				thisItemDepth = parseInt( thisItem.menuItemDepth(), 10 ),
   280 				thisItemPosition = parseInt( thisItem.index() ),
   287 				thisItemPosition = parseInt( thisItem.index(), 10 ),
   281 				nextItem = thisItem.next(),
   288 				nextItem = thisItem.next(),
   282 				nextItemChildren = nextItem.childMenuItems(),
   289 				nextItemChildren = nextItem.childMenuItems(),
   283 				nextItemDepth = parseInt( nextItem.menuItemDepth() ) + 1,
   290 				nextItemDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1,
   284 				prevItem = thisItem.prev(),
   291 				prevItem = thisItem.prev(),
   285 				prevItemDepth = parseInt( prevItem.menuItemDepth() ),
   292 				prevItemDepth = parseInt( prevItem.menuItemDepth(), 10 ),
   286 				prevItemId = prevItem.getItemData()['menu-item-db-id'];
   293 				prevItemId = prevItem.getItemData()['menu-item-db-id'];
   287 
   294 
   288 			switch ( dir ) {
   295 			switch ( dir ) {
   289 			case 'up':
   296 			case 'up':
   290 				var newItemPosition = thisItemPosition - 1;
   297 				newItemPosition = thisItemPosition - 1;
   291 
   298 
   292 				// Already at top
   299 				// Already at top
   293 				if ( 0 === thisItemPosition )
   300 				if ( 0 === thisItemPosition )
   294 					break;
   301 					break;
   295 
   302 
   301 				if ( 0 !== prevItemDepth )
   308 				if ( 0 !== prevItemDepth )
   302 					thisItem.moveHorizontally( prevItemDepth, thisItemDepth );
   309 					thisItem.moveHorizontally( prevItemDepth, thisItemDepth );
   303 
   310 
   304 				// Does this item have sub items?
   311 				// Does this item have sub items?
   305 				if ( thisItemChildren ) {
   312 				if ( thisItemChildren ) {
   306 					var items = thisItem.add( thisItemChildren );
   313 					items = thisItem.add( thisItemChildren );
   307 					// Move the entire block
   314 					// Move the entire block
   308 					items.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
   315 					items.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
   309 				} else {
   316 				} else {
   310 					thisItem.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
   317 					thisItem.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
   311 				}
   318 				}
   312 				break;
   319 				break;
   313 			case 'down':
   320 			case 'down':
   314 				// Does this item have sub items?
   321 				// Does this item have sub items?
   315 				if ( thisItemChildren ) {
   322 				if ( thisItemChildren ) {
   316 					var items = thisItem.add( thisItemChildren ),
   323 					items = thisItem.add( thisItemChildren ),
   317 						nextItem = menuItems.eq( items.length + thisItemPosition ),
   324 						nextItem = menuItems.eq( items.length + thisItemPosition ),
   318 						nextItemChildren = 0 !== nextItem.childMenuItems().length;
   325 						nextItemChildren = 0 !== nextItem.childMenuItems().length;
   319 
   326 
   320 					if ( nextItemChildren ) {
   327 					if ( nextItemChildren ) {
   321 						var newDepth = parseInt( nextItem.menuItemDepth() ) + 1;
   328 						newDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1;
   322 						thisItem.moveHorizontally( newDepth, thisItemDepth );
   329 						thisItem.moveHorizontally( newDepth, thisItemDepth );
   323 					}
   330 					}
   324 
   331 
   325 					// Have we reached the bottom?
   332 					// Have we reached the bottom?
   326 					if ( menuItemsCount === thisItemPosition + items.length )
   333 					if ( menuItemsCount === thisItemPosition + items.length )
   342 				// Already at top
   349 				// Already at top
   343 				if ( 0 === thisItemPosition )
   350 				if ( 0 === thisItemPosition )
   344 					break;
   351 					break;
   345 				// Does this item have sub items?
   352 				// Does this item have sub items?
   346 				if ( thisItemChildren ) {
   353 				if ( thisItemChildren ) {
   347 					var items = thisItem.add( thisItemChildren );
   354 					items = thisItem.add( thisItemChildren );
   348 					// Move the entire block
   355 					// Move the entire block
   349 					items.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
   356 					items.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
   350 				} else {
   357 				} else {
   351 					thisItem.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
   358 					thisItem.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
   352 				}
   359 				}
   372 			api.refreshKeyboardAccessibility();
   379 			api.refreshKeyboardAccessibility();
   373 			api.refreshAdvancedAccessibility();
   380 			api.refreshAdvancedAccessibility();
   374 		},
   381 		},
   375 
   382 
   376 		initAccessibility : function() {
   383 		initAccessibility : function() {
       
   384 			var menu = $( '#menu-to-edit' );
       
   385 
   377 			api.refreshKeyboardAccessibility();
   386 			api.refreshKeyboardAccessibility();
   378 			api.refreshAdvancedAccessibility();
   387 			api.refreshAdvancedAccessibility();
   379 
   388 
   380 			// Events
   389 			// Refresh the accessibility when the user comes close to the item in any way
   381 			$( '.menus-move-up' ).on( 'click', function ( e ) {
   390 			menu.on( 'mouseenter.refreshAccessibility focus.refreshAccessibility touchstart.refreshAccessibility' , '.menu-item' , function(){
   382 				api.moveMenuItem( $( this ).parents( 'li.menu-item' ).find( 'a.item-edit' ), 'up' );
   391 				api.refreshAdvancedAccessibilityOfItem( $( this ).find( '.item-edit' ) );
       
   392 			} );
       
   393 
       
   394 			// We have to update on click as well because we might hover first, change the item, and then click.
       
   395 			menu.on( 'click', '.item-edit', function() {
       
   396 				api.refreshAdvancedAccessibilityOfItem( $( this ) );
       
   397 			} );
       
   398 
       
   399 			// Links for moving items
       
   400 			menu.on( 'click', '.menus-move', function ( e ) {
       
   401 				var $this = $( this ),
       
   402 					dir = $this.data( 'dir' );
       
   403 
       
   404 				if ( 'undefined' !== typeof dir ) {
       
   405 					api.moveMenuItem( $( this ).parents( 'li.menu-item' ).find( 'a.item-edit' ), dir );
       
   406 				}
   383 				e.preventDefault();
   407 				e.preventDefault();
   384 			});
   408 			});
   385 			$( '.menus-move-down' ).on( 'click', function ( e ) {
   409 		},
   386 				api.moveMenuItem( $( this ).parents( 'li.menu-item' ).find( 'a.item-edit' ), 'down' );
   410 
   387 				e.preventDefault();
   411 		/**
   388 			});
   412 		 * refreshAdvancedAccessibilityOfItem( [itemToRefresh] )
   389 			$( '.menus-move-top' ).on( 'click', function ( e ) {
   413 		 *
   390 				api.moveMenuItem( $( this ).parents( 'li.menu-item' ).find( 'a.item-edit' ), 'top' );
   414 		 * Refreshes advanced accessibility buttons for one menu item.
   391 				e.preventDefault();
   415 		 * Shows or hides buttons based on the location of the menu item.
   392 			});
   416 		 *
   393 			$( '.menus-move-left' ).on( 'click', function ( e ) {
   417 		 * @param  {object} itemToRefresh The menu item that might need its advanced accessibility buttons refreshed
   394 				api.moveMenuItem( $( this ).parents( 'li.menu-item' ).find( 'a.item-edit' ), 'left' );
   418 		 */
   395 				e.preventDefault();
   419 		refreshAdvancedAccessibilityOfItem : function( itemToRefresh ) {
   396 			});
   420 
   397 			$( '.menus-move-right' ).on( 'click', function ( e ) {
   421 			// Only refresh accessibility when necessary
   398 				api.moveMenuItem( $( this ).parents( 'li.menu-item' ).find( 'a.item-edit' ), 'right' );
   422 			if ( true !== $( itemToRefresh ).data( 'needs_accessibility_refresh' ) ) {
   399 				e.preventDefault();
   423 				return;
   400 			});
   424 			}
   401 		},
   425 
   402 
   426 			var thisLink, thisLinkText, primaryItems, itemPosition, title,
       
   427 				parentItem, parentItemId, parentItemName, subItems,
       
   428 				$this = $( itemToRefresh ),
       
   429 				menuItem = $this.closest( 'li.menu-item' ).first(),
       
   430 				depth = menuItem.menuItemDepth(),
       
   431 				isPrimaryMenuItem = ( 0 === depth ),
       
   432 				itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(),
       
   433 				position = parseInt( menuItem.index(), 10 ),
       
   434 				prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1, 10 ),
       
   435 				prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(),
       
   436 				prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(),
       
   437 				totalMenuItems = $('#menu-to-edit li').length,
       
   438 				hasSameDepthSibling = menuItem.nextAll( '.menu-item-depth-' + depth ).length;
       
   439 
       
   440 				menuItem.find( '.field-move' ).toggle( totalMenuItems > 1 ); 
       
   441 
       
   442 			// Where can they move this menu item?
       
   443 			if ( 0 !== position ) {
       
   444 				thisLink = menuItem.find( '.menus-move-up' );
       
   445 				thisLink.prop( 'title', menus.moveUp ).css( 'display', 'inline' );
       
   446 			}
       
   447 
       
   448 			if ( 0 !== position && isPrimaryMenuItem ) {
       
   449 				thisLink = menuItem.find( '.menus-move-top' );
       
   450 				thisLink.prop( 'title', menus.moveToTop ).css( 'display', 'inline' );
       
   451 			}
       
   452 
       
   453 			if ( position + 1 !== totalMenuItems && 0 !== position ) {
       
   454 				thisLink = menuItem.find( '.menus-move-down' );
       
   455 				thisLink.prop( 'title', menus.moveDown ).css( 'display', 'inline' );
       
   456 			}
       
   457 
       
   458 			if ( 0 === position && 0 !== hasSameDepthSibling ) {
       
   459 				thisLink = menuItem.find( '.menus-move-down' );
       
   460 				thisLink.prop( 'title', menus.moveDown ).css( 'display', 'inline' );
       
   461 			}
       
   462 
       
   463 			if ( ! isPrimaryMenuItem ) {
       
   464 				thisLink = menuItem.find( '.menus-move-left' ),
       
   465 				thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft );
       
   466 				thisLink.prop( 'title', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ).text( thisLinkText ).css( 'display', 'inline' );
       
   467 			}
       
   468 
       
   469 			if ( 0 !== position ) {
       
   470 				if ( menuItem.find( '.menu-item-data-parent-id' ).val() !== menuItem.prev().find( '.menu-item-data-db-id' ).val() ) {
       
   471 					thisLink = menuItem.find( '.menus-move-right' ),
       
   472 					thisLinkText = menus.under.replace( '%s', prevItemNameRight );
       
   473 					thisLink.prop( 'title', menus.moveUnder.replace( '%s', prevItemNameRight ) ).text( thisLinkText ).css( 'display', 'inline' );
       
   474 				}
       
   475 			}
       
   476 
       
   477 			if ( isPrimaryMenuItem ) {
       
   478 				primaryItems = $( '.menu-item-depth-0' ),
       
   479 				itemPosition = primaryItems.index( menuItem ) + 1,
       
   480 				totalMenuItems = primaryItems.length,
       
   481 
       
   482 				// String together help text for primary menu items
       
   483 				title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$d', totalMenuItems );
       
   484 			} else {
       
   485 				parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(),
       
   486 				parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(),
       
   487 				parentItemName = parentItem.find( '.menu-item-title' ).text(),
       
   488 				subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ),
       
   489 				itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1;
       
   490 
       
   491 				// String together help text for sub menu items
       
   492 				title = menus.subMenuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$s', parentItemName );
       
   493 			}
       
   494 
       
   495 			$this.prop('title', title).html( title );
       
   496 
       
   497 			// Mark this item's accessibility as refreshed
       
   498 			$this.data( 'needs_accessibility_refresh', false );
       
   499 		},
       
   500 
       
   501 		/**
       
   502 		 * refreshAdvancedAccessibility
       
   503 		 *
       
   504 		 * Hides all advanced accessibility buttons and marks them for refreshing.
       
   505 		 */
   403 		refreshAdvancedAccessibility : function() {
   506 		refreshAdvancedAccessibility : function() {
   404 
   507 
   405 			// Hide all links by default
   508 			// Hide all links by default
   406 			$( '.menu-item-settings .field-move a' ).css( 'display', 'none' );
   509 			$( '.menu-item-settings .field-move a' ).hide();
   407 
   510 
   408 			$( '.item-edit' ).each( function() {
   511 			// Mark all menu items as unprocessed
   409 				var $this = $(this),
   512 			$( '.item-edit' ).data( 'needs_accessibility_refresh', true );
   410 					movement = [],
   513 
   411 					availableMovement = '',
   514 			// All open items have to be refreshed or they will show no links
   412 					menuItem = $this.closest( 'li.menu-item' ).first(),
   515 			$( '.menu-item-edit-active .item-edit' ).each( function() {
   413 					depth = menuItem.menuItemDepth(),
   516 				api.refreshAdvancedAccessibilityOfItem( this );
   414 					isPrimaryMenuItem = ( 0 === depth ),
   517 			} );
   415 					itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(),
       
   416 					position = parseInt( menuItem.index() ),
       
   417 					prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1 ),
       
   418 					prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(),
       
   419 					prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(),
       
   420 					totalMenuItems = $('#menu-to-edit li').length,
       
   421 					hasSameDepthSibling = menuItem.nextAll( '.menu-item-depth-' + depth ).length;
       
   422 
       
   423 				// Where can they move this menu item?
       
   424 				if ( 0 !== position ) {
       
   425 					var thisLink = menuItem.find( '.menus-move-up' );
       
   426 					thisLink.prop( 'title', menus.moveUp ).css( 'display', 'inline' );
       
   427 				}
       
   428 
       
   429 				if ( 0 !== position && isPrimaryMenuItem ) {
       
   430 					var thisLink = menuItem.find( '.menus-move-top' );
       
   431 					thisLink.prop( 'title', menus.moveToTop ).css( 'display', 'inline' );
       
   432 				}
       
   433 
       
   434 				if ( position + 1 !== totalMenuItems && 0 !== position ) {
       
   435 					var thisLink = menuItem.find( '.menus-move-down' );
       
   436 					thisLink.prop( 'title', menus.moveDown ).css( 'display', 'inline' );
       
   437 				}
       
   438 
       
   439 				if ( 0 === position && 0 !== hasSameDepthSibling ) {
       
   440 					var thisLink = menuItem.find( '.menus-move-down' );
       
   441 					thisLink.prop( 'title', menus.moveDown ).css( 'display', 'inline' );
       
   442 				}
       
   443 
       
   444 				if ( ! isPrimaryMenuItem ) {
       
   445 					var thisLink = menuItem.find( '.menus-move-left' ),
       
   446 						thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft );
       
   447 					thisLink.prop( 'title', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ).html( thisLinkText ).css( 'display', 'inline' );
       
   448 				}
       
   449 
       
   450 				if ( 0 !== position ) {
       
   451 					if ( menuItem.find( '.menu-item-data-parent-id' ).val() !== menuItem.prev().find( '.menu-item-data-db-id' ).val() ) {
       
   452 						var thisLink = menuItem.find( '.menus-move-right' ),
       
   453 							thisLinkText = menus.under.replace( '%s', prevItemNameRight );
       
   454 						thisLink.prop( 'title', menus.moveUnder.replace( '%s', prevItemNameRight ) ).html( thisLinkText ).css( 'display', 'inline' );
       
   455 					}
       
   456 				}
       
   457 
       
   458 				if ( isPrimaryMenuItem ) {
       
   459 					var primaryItems = $( '.menu-item-depth-0' ),
       
   460 						itemPosition = primaryItems.index( menuItem ) + 1,
       
   461 						totalMenuItems = primaryItems.length,
       
   462 
       
   463 						// String together help text for primary menu items
       
   464 						title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$d', totalMenuItems );
       
   465 				} else {
       
   466 					var parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1 ) ).first(),
       
   467 						parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(),
       
   468 						parentItemName = parentItem.find( '.menu-item-title' ).text(),
       
   469 						subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ),
       
   470 						itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1;
       
   471 
       
   472 						// String together help text for sub menu items
       
   473 						title = menus.subMenuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$s', parentItemName );
       
   474 				}
       
   475 
       
   476 				$this.prop('title', title).html( title );
       
   477 			});
       
   478 		},
   518 		},
   479 
   519 
   480 		refreshKeyboardAccessibility : function() {
   520 		refreshKeyboardAccessibility : function() {
   481 			$( '.item-edit' ).off( 'focus' ).on( 'focus', function(){
   521 			$( '.item-edit' ).off( 'focus' ).on( 'focus', function(){
   482 				$(this).off( 'keydown' ).on( 'keydown', function(e){
   522 				$(this).off( 'keydown' ).on( 'keydown', function(e){
   483 
   523 
   484 					var $this = $(this);
   524 					var arrows,
       
   525 						$this = $( this ),
       
   526 						thisItem = $this.parents( 'li.menu-item' ),
       
   527 						thisItemData = thisItem.getItemData();
   485 
   528 
   486 					// Bail if it's not an arrow key
   529 					// Bail if it's not an arrow key
   487 					if ( 37 != e.which && 38 != e.which && 39 != e.which && 40 != e.which )
   530 					if ( 37 != e.which && 38 != e.which && 39 != e.which && 40 != e.which )
   488 						return;
   531 						return;
   489 
   532 
   493 					// Bail if there is only one menu item
   536 					// Bail if there is only one menu item
   494 					if ( 1 === $('#menu-to-edit li').length )
   537 					if ( 1 === $('#menu-to-edit li').length )
   495 						return;
   538 						return;
   496 
   539 
   497 					// If RTL, swap left/right arrows
   540 					// If RTL, swap left/right arrows
   498 					var arrows = { '38' : 'up', '40' : 'down', '37' : 'left', '39' : 'right' };
   541 					arrows = { '38': 'up', '40': 'down', '37': 'left', '39': 'right' };
   499 					if ( $('body').hasClass('rtl') )
   542 					if ( $('body').hasClass('rtl') )
   500 						arrows = { '38' : 'up', '40' : 'down', '39' : 'left', '37' : 'right' };
   543 						arrows = { '38' : 'up', '40' : 'down', '39' : 'left', '37' : 'right' };
   501 
   544 
   502 					switch ( arrows[e.which] ) {
   545 					switch ( arrows[e.which] ) {
   503 					case 'up':
   546 					case 'up':
   518 					return false;
   561 					return false;
   519 				});
   562 				});
   520 			});
   563 			});
   521 		},
   564 		},
   522 
   565 
       
   566 		initPreviewing : function() {
       
   567 			// Update the item handle title when the navigation label is changed.
       
   568 			$( '#menu-to-edit' ).on( 'change input', '.edit-menu-item-title', function(e) {
       
   569 				var input = $( e.currentTarget ), title, titleEl;
       
   570 				title = input.val();
       
   571 				titleEl = input.closest( '.menu-item' ).find( '.menu-item-title' );
       
   572 				// Don't update to empty title.
       
   573 				if ( title ) {
       
   574 					titleEl.text( title ).removeClass( 'no-title' );
       
   575 				} else {
       
   576 					titleEl.text( navMenuL10n.untitled ).addClass( 'no-title' );
       
   577 				}
       
   578 			} );
       
   579 		},
       
   580 
   523 		initToggles : function() {
   581 		initToggles : function() {
   524 			// init postboxes
   582 			// init postboxes
   525 			postboxes.add_postbox_toggles('nav-menus');
   583 			postboxes.add_postbox_toggles('nav-menus');
   526 
   584 
   527 			// adjust columns functions for menus UI
   585 			// adjust columns functions for menus UI
   528 			columns.useCheckboxesForHidden();
   586 			columns.useCheckboxesForHidden();
   529 			columns.checked = function(field) {
   587 			columns.checked = function(field) {
   530 				$('.field-' + field).removeClass('hidden-field');
   588 				$('.field-' + field).removeClass('hidden-field');
   531 			}
   589 			};
   532 			columns.unchecked = function(field) {
   590 			columns.unchecked = function(field) {
   533 				$('.field-' + field).addClass('hidden-field');
   591 				$('.field-' + field).addClass('hidden-field');
   534 			}
   592 			};
   535 			// hide fields
   593 			// hide fields
   536 			api.menuList.hideAdvancedMenuItemFields();
   594 			api.menuList.hideAdvancedMenuItemFields();
   537 
   595 
   538 			$('.hide-postbox-tog').click(function () {
   596 			$('.hide-postbox-tog').click(function () {
   539 				var hidden = $( '.accordion-container li.accordion-section' ).filter(':hidden').map(function() { return this.id; }).get().join(',');
   597 				var hidden = $( '.accordion-container li.accordion-section' ).filter(':hidden').map(function() { return this.id; }).get().join(',');
   551 				prev, next, prevBottom, nextThreshold, helperHeight, transport,
   609 				prev, next, prevBottom, nextThreshold, helperHeight, transport,
   552 				menuEdge = api.menuList.offset().left,
   610 				menuEdge = api.menuList.offset().left,
   553 				body = $('body'), maxChildDepth,
   611 				body = $('body'), maxChildDepth,
   554 				menuMaxDepth = initialMenuMaxDepth();
   612 				menuMaxDepth = initialMenuMaxDepth();
   555 
   613 
   556 			if( 0 != $( '#menu-to-edit li' ).length )
   614 			if( 0 !== $( '#menu-to-edit li' ).length )
   557 				$( '.drag-instructions' ).show();
   615 				$( '.drag-instructions' ).show();
   558 
   616 
   559 			// Use the right edge if RTL.
   617 			// Use the right edge if RTL.
   560 			menuEdge += api.isRTL ? api.menuList.width() : 0;
   618 			menuEdge += api.isRTL ? api.menuList.width() : 0;
   561 
   619 
   603 
   661 
   604 					// Update the list of menu items.
   662 					// Update the list of menu items.
   605 					tempHolder = ui.placeholder.next();
   663 					tempHolder = ui.placeholder.next();
   606 					tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder
   664 					tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder
   607 					ui.placeholder.detach(); // detach or jQuery UI will think the placeholder is a menu item
   665 					ui.placeholder.detach(); // detach or jQuery UI will think the placeholder is a menu item
   608 					$(this).sortable( "refresh" ); // The children aren't sortable. We should let jQ UI know.
   666 					$(this).sortable( 'refresh' ); // The children aren't sortable. We should let jQ UI know.
   609 					ui.item.after( ui.placeholder ); // reattach the placeholder.
   667 					ui.item.after( ui.placeholder ); // reattach the placeholder.
   610 					tempHolder.css('margin-top', 0); // reset the margin
   668 					tempHolder.css('margin-top', 0); // reset the margin
   611 
   669 
   612 					// Now that the element is complete, we can update...
   670 					// Now that the element is complete, we can update...
   613 					updateSharedVars(ui);
   671 					updateSharedVars(ui);
   614 				},
   672 				},
   615 				stop: function(e, ui) {
   673 				stop: function(e, ui) {
   616 					var children, depthChange = currentDepth - originalDepth;
   674 					var children, subMenuTitle,
       
   675 						depthChange = currentDepth - originalDepth;
   617 
   676 
   618 					// Return child elements to the list
   677 					// Return child elements to the list
   619 					children = transport.children().insertAfter(ui.item);
   678 					children = transport.children().insertAfter(ui.item);
   620 
   679 
   621 					// Add "sub menu" description
   680 					// Add "sub menu" description
   622 					var subMenuTitle = ui.item.find( '.item-title .is-submenu' );
   681 					subMenuTitle = ui.item.find( '.item-title .is-submenu' );
   623 					if ( 0 < currentDepth )
   682 					if ( 0 < currentDepth )
   624 						subMenuTitle.show();
   683 						subMenuTitle.show();
   625 					else
   684 					else
   626 						subMenuTitle.hide();
   685 						subMenuTitle.hide();
   627 
   686 
   628 					// Update depth classes
   687 					// Update depth classes
   629 					if( depthChange != 0 ) {
   688 					if ( 0 !== depthChange ) {
   630 						ui.item.updateDepthClass( currentDepth );
   689 						ui.item.updateDepthClass( currentDepth );
   631 						children.shiftDepthClass( depthChange );
   690 						children.shiftDepthClass( depthChange );
   632 						updateMenuMaxDepth( depthChange );
   691 						updateMenuMaxDepth( depthChange );
   633 					}
   692 					}
   634 					// Register a change
   693 					// Register a change
   671 
   730 
   672 					// If we overlap the next element, manually shift downwards
   731 					// If we overlap the next element, manually shift downwards
   673 					if( nextThreshold && offset.top + helperHeight > nextThreshold ) {
   732 					if( nextThreshold && offset.top + helperHeight > nextThreshold ) {
   674 						next.after( ui.placeholder );
   733 						next.after( ui.placeholder );
   675 						updateSharedVars( ui );
   734 						updateSharedVars( ui );
   676 						$(this).sortable( "refreshPositions" );
   735 						$( this ).sortable( 'refreshPositions' );
   677 					}
   736 					}
   678 				}
   737 				}
   679 			});
   738 			});
   680 
   739 
   681 			function updateSharedVars(ui) {
   740 			function updateSharedVars(ui) {
   704 			}
   763 			}
   705 
   764 
   706 			function initialMenuMaxDepth() {
   765 			function initialMenuMaxDepth() {
   707 				if( ! body[0].className ) return 0;
   766 				if( ! body[0].className ) return 0;
   708 				var match = body[0].className.match(/menu-max-depth-(\d+)/);
   767 				var match = body[0].className.match(/menu-max-depth-(\d+)/);
   709 				return match && match[1] ? parseInt(match[1]) : 0;
   768 				return match && match[1] ? parseInt( match[1], 10 ) : 0;
   710 			}
   769 			}
   711 
   770 
   712 			function updateMenuMaxDepth( depthChange ) {
   771 			function updateMenuMaxDepth( depthChange ) {
   713 				var depth, newDepth = menuMaxDepth;
   772 				var depth, newDepth = menuMaxDepth;
   714 				if ( depthChange === 0 ) {
   773 				if ( depthChange === 0 ) {
   758 				}
   817 				}
   759 			});
   818 			});
   760 			$('#add-custom-links input[type="text"]').keypress(function(e){
   819 			$('#add-custom-links input[type="text"]').keypress(function(e){
   761 				if ( e.keyCode === 13 ) {
   820 				if ( e.keyCode === 13 ) {
   762 					e.preventDefault();
   821 					e.preventDefault();
   763 					$("#submit-customlinkdiv").click();
   822 					$( '#submit-customlinkdiv' ).click();
   764 				}
   823 				}
   765 			});
   824 			});
   766 		},
   825 		},
   767 
   826 
   768 		/**
   827 		/**
   777 
   836 
   778 			$('.' + name).each( function(){
   837 			$('.' + name).each( function(){
   779 				var $t = $(this), title = $t.attr('title'), val = $t.val();
   838 				var $t = $(this), title = $t.attr('title'), val = $t.val();
   780 				$t.data( name, title );
   839 				$t.data( name, title );
   781 
   840 
   782 				if( '' == val ) $t.val( title );
   841 				if( '' === val ) $t.val( title );
   783 				else if ( title == val ) return;
   842 				else if ( title == val ) return;
   784 				else $t.removeClass( name );
   843 				else $t.removeClass( name );
   785 			}).focus( function(){
   844 			}).focus( function(){
   786 				var $t = $(this);
   845 				var $t = $(this);
   787 				if( $t.val() == $t.data(name) )
   846 				if( $t.val() == $t.data(name) )
   788 					$t.val('').removeClass( name );
   847 					$t.val('').removeClass( name );
   789 			}).blur( function(){
   848 			}).blur( function(){
   790 				var $t = $(this);
   849 				var $t = $(this);
   791 				if( '' == $t.val() )
   850 				if( '' === $t.val() )
   792 					$t.addClass( name ).val( $t.data(name) );
   851 					$t.addClass( name ).val( $t.data(name) );
   793 			});
   852 			});
   794 
   853 
   795 			$( '.blank-slate .input-with-default-title' ).focus();
   854 			$( '.blank-slate .input-with-default-title' ).focus();
   796 		},
   855 		},
   797 
   856 
   798 		attachThemeLocationsListeners : function() {
   857 		attachThemeLocationsListeners : function() {
   799 			var loc = $('#nav-menu-theme-locations'), params = {};
   858 			var loc = $('#nav-menu-theme-locations'), params = {};
   800 			params['action'] = 'menu-locations-save';
   859 			params.action = 'menu-locations-save';
   801 			params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val();
   860 			params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val();
   802 			loc.find('input[type="submit"]').click(function() {
   861 			loc.find('input[type="submit"]').click(function() {
   803 				loc.find('select').each(function() {
   862 				loc.find('select').each(function() {
   804 					params[this.name] = $(this).val();
   863 					params[this.name] = $(this).val();
   805 				});
   864 				});
   806 				loc.find('.spinner').show();
   865 				loc.find( '.spinner' ).addClass( 'is-active' );
   807 				$.post( ajaxurl, params, function(r) {
   866 				$.post( ajaxurl, params, function() {
   808 					loc.find('.spinner').hide();
   867 					loc.find( '.spinner' ).removeClass( 'is-active' );
   809 				});
   868 				});
   810 				return false;
   869 				return false;
   811 			});
   870 			});
   812 		},
   871 		},
   813 
   872 
   845 				'menu-settings-column-nonce': $('#menu-settings-column-nonce').val(),
   904 				'menu-settings-column-nonce': $('#menu-settings-column-nonce').val(),
   846 				'q': q,
   905 				'q': q,
   847 				'type': input.attr('name')
   906 				'type': input.attr('name')
   848 			};
   907 			};
   849 
   908 
   850 			$('.spinner', panel).show();
   909 			$( '.spinner', panel ).addClass( 'is-active' );
   851 
   910 
   852 			$.post( ajaxurl, params, function(menuMarkup) {
   911 			$.post( ajaxurl, params, function(menuMarkup) {
   853 				api.processQuickSearchQueryResponse(menuMarkup, params, panel);
   912 				api.processQuickSearchQueryResponse(menuMarkup, params, panel);
   854 			});
   913 			});
   855 		},
   914 		},
   858 			var url = $('#custom-menu-item-url').val(),
   917 			var url = $('#custom-menu-item-url').val(),
   859 				label = $('#custom-menu-item-name').val();
   918 				label = $('#custom-menu-item-name').val();
   860 
   919 
   861 			processMethod = processMethod || api.addMenuItemToBottom;
   920 			processMethod = processMethod || api.addMenuItemToBottom;
   862 
   921 
   863 			if ( '' == url || 'http://' == url )
   922 			if ( '' === url || 'http://' == url )
   864 				return false;
   923 				return false;
   865 
   924 
   866 			// Show the ajax spinner
   925 			// Show the ajax spinner
   867 			$('.customlinkdiv .spinner').show();
   926 			$( '.customlinkdiv .spinner' ).addClass( 'is-active' );
   868 			this.addLinkToMenu( url, label, processMethod, function() {
   927 			this.addLinkToMenu( url, label, processMethod, function() {
   869 				// Remove the ajax spinner
   928 				// Remove the ajax spinner
   870 				$('.customlinkdiv .spinner').hide();
   929 				$( '.customlinkdiv .spinner' ).removeClass( 'is-active' );
   871 				// Set custom link form back to defaults
   930 				// Set custom link form back to defaults
   872 				$('#custom-menu-item-name').val('').blur();
   931 				$('#custom-menu-item-name').val('').blur();
   873 				$('#custom-menu-item-url').val('http://');
   932 				$('#custom-menu-item-url').val('http://');
   874 			});
   933 			});
   875 		},
   934 		},
   887 			}, processMethod, callback);
   946 			}, processMethod, callback);
   888 		},
   947 		},
   889 
   948 
   890 		addItemToMenu : function(menuItem, processMethod, callback) {
   949 		addItemToMenu : function(menuItem, processMethod, callback) {
   891 			var menu = $('#menu').val(),
   950 			var menu = $('#menu').val(),
   892 				nonce = $('#menu-settings-column-nonce').val();
   951 				nonce = $('#menu-settings-column-nonce').val(),
       
   952 				params;
   893 
   953 
   894 			processMethod = processMethod || function(){};
   954 			processMethod = processMethod || function(){};
   895 			callback = callback || function(){};
   955 			callback = callback || function(){};
   896 
   956 
   897 			params = {
   957 			params = {
   921 		 * Process the add menu item request response into menu list item.
   981 		 * Process the add menu item request response into menu list item.
   922 		 *
   982 		 *
   923 		 * @param string menuMarkup The text server response of menu item markup.
   983 		 * @param string menuMarkup The text server response of menu item markup.
   924 		 * @param object req The request arguments.
   984 		 * @param object req The request arguments.
   925 		 */
   985 		 */
   926 		addMenuItemToBottom : function( menuMarkup, req ) {
   986 		addMenuItemToBottom : function( menuMarkup ) {
   927 			$(menuMarkup).hideAdvancedMenuItemFields().appendTo( api.targetList );
   987 			$(menuMarkup).hideAdvancedMenuItemFields().appendTo( api.targetList );
   928 			api.refreshKeyboardAccessibility();
   988 			api.refreshKeyboardAccessibility();
   929 			api.refreshAdvancedAccessibility();
   989 			api.refreshAdvancedAccessibility();
   930 		},
   990 		},
   931 
   991 
   932 		addMenuItemToTop : function( menuMarkup, req ) {
   992 		addMenuItemToTop : function( menuMarkup ) {
   933 			$(menuMarkup).hideAdvancedMenuItemFields().prependTo( api.targetList );
   993 			$(menuMarkup).hideAdvancedMenuItemFields().prependTo( api.targetList );
   934 			api.refreshKeyboardAccessibility();
   994 			api.refreshKeyboardAccessibility();
   935 			api.refreshAdvancedAccessibility();
   995 			api.refreshAdvancedAccessibility();
   936 		},
   996 		},
   937 
   997 
   938 		attachUnsavedChangesListener : function() {
   998 		attachUnsavedChangesListener : function() {
   939 			$('#menu-management input, #menu-management select, #menu-management, #menu-management textarea, .menu-location-menus select').change(function(){
   999 			$('#menu-management input, #menu-management select, #menu-management, #menu-management textarea, .menu-location-menus select').change(function(){
   940 				api.registerChange();
  1000 				api.registerChange();
   941 			});
  1001 			});
   942 
  1002 
   943 			if ( 0 != $('#menu-to-edit').length || 0 != $('.menu-location-menus select').length ) {
  1003 			if ( 0 !== $('#menu-to-edit').length || 0 !== $('.menu-location-menus select').length ) {
   944 				window.onbeforeunload = function(){
  1004 				window.onbeforeunload = function(){
   945 					if ( api.menusChanged )
  1005 					if ( api.menusChanged )
   946 						return navMenuL10n.saveAlert;
  1006 						return navMenuL10n.saveAlert;
   947 				};
  1007 				};
   948 			} else {
  1008 			} else {
  1006 							var metaBoxData = $.parseJSON(resp),
  1066 							var metaBoxData = $.parseJSON(resp),
  1007 							toReplace = document.getElementById(metaBoxData['replace-id']),
  1067 							toReplace = document.getElementById(metaBoxData['replace-id']),
  1008 							placeholder = document.createElement('div'),
  1068 							placeholder = document.createElement('div'),
  1009 							wrap = document.createElement('div');
  1069 							wrap = document.createElement('div');
  1010 
  1070 
  1011 							if ( ! metaBoxData['markup'] || ! toReplace )
  1071 							if ( ! metaBoxData.markup || ! toReplace )
  1012 								return;
  1072 								return;
  1013 
  1073 
  1014 							wrap.innerHTML = metaBoxData['markup'] ? metaBoxData['markup'] : '';
  1074 							wrap.innerHTML = metaBoxData.markup ? metaBoxData.markup : '';
  1015 
  1075 
  1016 							toReplace.parentNode.insertBefore( placeholder, toReplace );
  1076 							toReplace.parentNode.insertBefore( placeholder, toReplace );
  1017 							placeholder.parentNode.removeChild( toReplace );
  1077 							placeholder.parentNode.removeChild( toReplace );
  1018 
  1078 
  1019 							placeholder.parentNode.insertBefore( wrap, placeholder );
  1079 							placeholder.parentNode.insertBefore( wrap, placeholder );
  1032 			var settings, item,
  1092 			var settings, item,
  1033 			matchedSection = /#(.*)$/.exec(clickedEl.href);
  1093 			matchedSection = /#(.*)$/.exec(clickedEl.href);
  1034 			if ( matchedSection && matchedSection[1] ) {
  1094 			if ( matchedSection && matchedSection[1] ) {
  1035 				settings = $('#'+matchedSection[1]);
  1095 				settings = $('#'+matchedSection[1]);
  1036 				item = settings.parent();
  1096 				item = settings.parent();
  1037 				if( 0 != item.length ) {
  1097 				if( 0 !== item.length ) {
  1038 					if( item.hasClass('menu-item-edit-inactive') ) {
  1098 					if( item.hasClass('menu-item-edit-inactive') ) {
  1039 						if( ! settings.data('menu-item-data') ) {
  1099 						if( ! settings.data('menu-item-data') ) {
  1040 							settings.data( 'menu-item-data', settings.getItemData() );
  1100 							settings.data( 'menu-item-data', settings.getItemData() );
  1041 						}
  1101 						}
  1042 						settings.slideDown('fast');
  1102 						settings.slideDown('fast');
  1058 			thisMenuItem.removeClass('menu-item-edit-active').addClass('menu-item-edit-inactive');
  1118 			thisMenuItem.removeClass('menu-item-edit-active').addClass('menu-item-edit-inactive');
  1059 			settings.setItemData( settings.data('menu-item-data') ).hide();
  1119 			settings.setItemData( settings.data('menu-item-data') ).hide();
  1060 			return false;
  1120 			return false;
  1061 		},
  1121 		},
  1062 
  1122 
  1063 		eventOnClickMenuSave : function(clickedEl) {
  1123 		eventOnClickMenuSave : function() {
  1064 			var locs = '',
  1124 			var locs = '',
  1065 			menuName = $('#menu-name'),
  1125 			menuName = $('#menu-name'),
  1066 			menuNameVal = menuName.val();
  1126 			menuNameVal = menuName.val();
  1067 			// Cancel and warn if invalid menu name
  1127 			// Cancel and warn if invalid menu name
  1068 			if( !menuNameVal || menuNameVal == menuName.attr('title') || !menuNameVal.replace(/\s+/, '') ) {
  1128 			if( !menuNameVal || menuNameVal == menuName.attr('title') || !menuNameVal.replace(/\s+/, '') ) {
  1079 			window.onbeforeunload = null;
  1139 			window.onbeforeunload = null;
  1080 
  1140 
  1081 			return true;
  1141 			return true;
  1082 		},
  1142 		},
  1083 
  1143 
  1084 		eventOnClickMenuDelete : function(clickedEl) {
  1144 		eventOnClickMenuDelete : function() {
  1085 			// Delete warning AYS
  1145 			// Delete warning AYS
  1086 			if ( confirm( navMenuL10n.warnDeleteMenu ) ) {
  1146 			if ( window.confirm( navMenuL10n.warnDeleteMenu ) ) {
  1087 				window.onbeforeunload = null;
  1147 				window.onbeforeunload = null;
  1088 				return true;
  1148 				return true;
  1089 			}
  1149 			}
  1090 			return false;
  1150 			return false;
  1091 		},
  1151 		},
  1106 		 */
  1166 		 */
  1107 		processQuickSearchQueryResponse : function(resp, req, panel) {
  1167 		processQuickSearchQueryResponse : function(resp, req, panel) {
  1108 			var matched, newID,
  1168 			var matched, newID,
  1109 			takenIDs = {},
  1169 			takenIDs = {},
  1110 			form = document.getElementById('nav-menu-meta'),
  1170 			form = document.getElementById('nav-menu-meta'),
  1111 			pattern = new RegExp('menu-item\\[(\[^\\]\]*)', 'g'),
  1171 			pattern = /menu-item[(\[^]\]*/,
  1112 			$items = $('<div>').html(resp).find('li'),
  1172 			$items = $('<div>').html(resp).find('li'),
  1113 			$item;
  1173 			$item;
  1114 
  1174 
  1115 			if( ! $items.length ) {
  1175 			if( ! $items.length ) {
  1116 				$('.categorychecklist', panel).html( '<li><p>' + navMenuL10n.noResultsFound + '</p></li>' );
  1176 				$('.categorychecklist', panel).html( '<li><p>' + navMenuL10n.noResultsFound + '</p></li>' );
  1117 				$('.spinner', panel).hide();
  1177 				$( '.spinner', panel ).removeClass( 'is-active' );
  1118 				return;
  1178 				return;
  1119 			}
  1179 			}
  1120 
  1180 
  1121 			$items.each(function(){
  1181 			$items.each(function(){
  1122 				$item = $(this);
  1182 				$item = $(this);
  1139 					}
  1199 					}
  1140 				}
  1200 				}
  1141 			});
  1201 			});
  1142 
  1202 
  1143 			$('.categorychecklist', panel).html( $items );
  1203 			$('.categorychecklist', panel).html( $items );
  1144 			$('.spinner', panel).hide();
  1204 			$( '.spinner', panel ).removeClass( 'is-active' );
  1145 		},
  1205 		},
  1146 
  1206 
  1147 		removeMenuItem : function(el) {
  1207 		removeMenuItem : function(el) {
  1148 			var children = el.childMenuItems();
  1208 			var children = el.childMenuItems();
  1149 
  1209 
  1152 					height: 0
  1212 					height: 0
  1153 				}, 350, function() {
  1213 				}, 350, function() {
  1154 					var ins = $('#menu-instructions');
  1214 					var ins = $('#menu-instructions');
  1155 					el.remove();
  1215 					el.remove();
  1156 					children.shiftDepthClass( -1 ).updateParentMenuItemDBId();
  1216 					children.shiftDepthClass( -1 ).updateParentMenuItemDBId();
  1157 					if( 0 == $( '#menu-to-edit li' ).length ) {
  1217 					if ( 0 === $( '#menu-to-edit li' ).length ) {
  1158 						$( '.drag-instructions' ).hide();
  1218 						$( '.drag-instructions' ).hide();
  1159 						ins.removeClass( 'menu-instructions-inactive' );
  1219 						ins.removeClass( 'menu-instructions-inactive' );
  1160 					}
  1220 					}
       
  1221 					api.refreshAdvancedAccessibility();
  1161 				});
  1222 				});
  1162 		},
  1223 		},
  1163 
  1224 
  1164 		depthToPx : function(depth) {
  1225 		depthToPx : function(depth) {
  1165 			return depth * api.options.menuItemDepthPerLevel;
  1226 			return depth * api.options.menuItemDepthPerLevel;