Edit File by line
/home/barbar84/www/wp-admin/js
File: nav-menu.js
/**
[0] Fix | Delete
* WordPress Administration Navigation Menu
[1] Fix | Delete
* Interface JS functions
[2] Fix | Delete
*
[3] Fix | Delete
* @version 2.0.0
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
* @subpackage Administration
[7] Fix | Delete
* @output wp-admin/js/nav-menu.js
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
/* global menus, postboxes, columns, isRtl, ajaxurl, wpNavMenu */
[11] Fix | Delete
[12] Fix | Delete
(function($) {
[13] Fix | Delete
[14] Fix | Delete
var api;
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* Contains all the functions to handle WordPress navigation menus administration.
[18] Fix | Delete
*
[19] Fix | Delete
* @namespace wpNavMenu
[20] Fix | Delete
*/
[21] Fix | Delete
api = window.wpNavMenu = {
[22] Fix | Delete
[23] Fix | Delete
options : {
[24] Fix | Delete
menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
[25] Fix | Delete
globalMaxDepth: 11,
[26] Fix | Delete
sortableItems: '> *',
[27] Fix | Delete
targetTolerance: 0
[28] Fix | Delete
},
[29] Fix | Delete
[30] Fix | Delete
menuList : undefined, // Set in init.
[31] Fix | Delete
targetList : undefined, // Set in init.
[32] Fix | Delete
menusChanged : false,
[33] Fix | Delete
isRTL: !! ( 'undefined' != typeof isRtl && isRtl ),
[34] Fix | Delete
negateIfRTL: ( 'undefined' != typeof isRtl && isRtl ) ? -1 : 1,
[35] Fix | Delete
lastSearch: '',
[36] Fix | Delete
[37] Fix | Delete
// Functions that run on init.
[38] Fix | Delete
init : function() {
[39] Fix | Delete
api.menuList = $('#menu-to-edit');
[40] Fix | Delete
api.targetList = api.menuList;
[41] Fix | Delete
[42] Fix | Delete
this.jQueryExtensions();
[43] Fix | Delete
[44] Fix | Delete
this.attachMenuEditListeners();
[45] Fix | Delete
[46] Fix | Delete
this.attachQuickSearchListeners();
[47] Fix | Delete
this.attachThemeLocationsListeners();
[48] Fix | Delete
this.attachMenuSaveSubmitListeners();
[49] Fix | Delete
[50] Fix | Delete
this.attachTabsPanelListeners();
[51] Fix | Delete
[52] Fix | Delete
this.attachUnsavedChangesListener();
[53] Fix | Delete
[54] Fix | Delete
if ( api.menuList.length )
[55] Fix | Delete
this.initSortables();
[56] Fix | Delete
[57] Fix | Delete
if ( menus.oneThemeLocationNoMenus )
[58] Fix | Delete
$( '#posttype-page' ).addSelectedToMenu( api.addMenuItemToBottom );
[59] Fix | Delete
[60] Fix | Delete
this.initManageLocations();
[61] Fix | Delete
[62] Fix | Delete
this.initAccessibility();
[63] Fix | Delete
[64] Fix | Delete
this.initToggles();
[65] Fix | Delete
[66] Fix | Delete
this.initPreviewing();
[67] Fix | Delete
},
[68] Fix | Delete
[69] Fix | Delete
jQueryExtensions : function() {
[70] Fix | Delete
// jQuery extensions.
[71] Fix | Delete
$.fn.extend({
[72] Fix | Delete
menuItemDepth : function() {
[73] Fix | Delete
var margin = api.isRTL ? this.eq(0).css('margin-right') : this.eq(0).css('margin-left');
[74] Fix | Delete
return api.pxToDepth( margin && -1 != margin.indexOf('px') ? margin.slice(0, -2) : 0 );
[75] Fix | Delete
},
[76] Fix | Delete
updateDepthClass : function(current, prev) {
[77] Fix | Delete
return this.each(function(){
[78] Fix | Delete
var t = $(this);
[79] Fix | Delete
prev = prev || t.menuItemDepth();
[80] Fix | Delete
$(this).removeClass('menu-item-depth-'+ prev )
[81] Fix | Delete
.addClass('menu-item-depth-'+ current );
[82] Fix | Delete
});
[83] Fix | Delete
},
[84] Fix | Delete
shiftDepthClass : function(change) {
[85] Fix | Delete
return this.each(function(){
[86] Fix | Delete
var t = $(this),
[87] Fix | Delete
depth = t.menuItemDepth(),
[88] Fix | Delete
newDepth = depth + change;
[89] Fix | Delete
[90] Fix | Delete
t.removeClass( 'menu-item-depth-'+ depth )
[91] Fix | Delete
.addClass( 'menu-item-depth-'+ ( newDepth ) );
[92] Fix | Delete
[93] Fix | Delete
if ( 0 === newDepth ) {
[94] Fix | Delete
t.find( '.is-submenu' ).hide();
[95] Fix | Delete
}
[96] Fix | Delete
});
[97] Fix | Delete
},
[98] Fix | Delete
childMenuItems : function() {
[99] Fix | Delete
var result = $();
[100] Fix | Delete
this.each(function(){
[101] Fix | Delete
var t = $(this), depth = t.menuItemDepth(), next = t.next( '.menu-item' );
[102] Fix | Delete
while( next.length && next.menuItemDepth() > depth ) {
[103] Fix | Delete
result = result.add( next );
[104] Fix | Delete
next = next.next( '.menu-item' );
[105] Fix | Delete
}
[106] Fix | Delete
});
[107] Fix | Delete
return result;
[108] Fix | Delete
},
[109] Fix | Delete
shiftHorizontally : function( dir ) {
[110] Fix | Delete
return this.each(function(){
[111] Fix | Delete
var t = $(this),
[112] Fix | Delete
depth = t.menuItemDepth(),
[113] Fix | Delete
newDepth = depth + dir;
[114] Fix | Delete
[115] Fix | Delete
// Change .menu-item-depth-n class.
[116] Fix | Delete
t.moveHorizontally( newDepth, depth );
[117] Fix | Delete
});
[118] Fix | Delete
},
[119] Fix | Delete
moveHorizontally : function( newDepth, depth ) {
[120] Fix | Delete
return this.each(function(){
[121] Fix | Delete
var t = $(this),
[122] Fix | Delete
children = t.childMenuItems(),
[123] Fix | Delete
diff = newDepth - depth,
[124] Fix | Delete
subItemText = t.find('.is-submenu');
[125] Fix | Delete
[126] Fix | Delete
// Change .menu-item-depth-n class.
[127] Fix | Delete
t.updateDepthClass( newDepth, depth ).updateParentMenuItemDBId();
[128] Fix | Delete
[129] Fix | Delete
// If it has children, move those too.
[130] Fix | Delete
if ( children ) {
[131] Fix | Delete
children.each(function() {
[132] Fix | Delete
var t = $(this),
[133] Fix | Delete
thisDepth = t.menuItemDepth(),
[134] Fix | Delete
newDepth = thisDepth + diff;
[135] Fix | Delete
t.updateDepthClass(newDepth, thisDepth).updateParentMenuItemDBId();
[136] Fix | Delete
});
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
// Show "Sub item" helper text.
[140] Fix | Delete
if (0 === newDepth)
[141] Fix | Delete
subItemText.hide();
[142] Fix | Delete
else
[143] Fix | Delete
subItemText.show();
[144] Fix | Delete
});
[145] Fix | Delete
},
[146] Fix | Delete
updateParentMenuItemDBId : function() {
[147] Fix | Delete
return this.each(function(){
[148] Fix | Delete
var item = $(this),
[149] Fix | Delete
input = item.find( '.menu-item-data-parent-id' ),
[150] Fix | Delete
depth = parseInt( item.menuItemDepth(), 10 ),
[151] Fix | Delete
parentDepth = depth - 1,
[152] Fix | Delete
parent = item.prevAll( '.menu-item-depth-' + parentDepth ).first();
[153] Fix | Delete
[154] Fix | Delete
if ( 0 === depth ) { // Item is on the top level, has no parent.
[155] Fix | Delete
input.val(0);
[156] Fix | Delete
} else { // Find the parent item, and retrieve its object id.
[157] Fix | Delete
input.val( parent.find( '.menu-item-data-db-id' ).val() );
[158] Fix | Delete
}
[159] Fix | Delete
});
[160] Fix | Delete
},
[161] Fix | Delete
hideAdvancedMenuItemFields : function() {
[162] Fix | Delete
return this.each(function(){
[163] Fix | Delete
var that = $(this);
[164] Fix | Delete
$('.hide-column-tog').not(':checked').each(function(){
[165] Fix | Delete
that.find('.field-' + $(this).val() ).addClass('hidden-field');
[166] Fix | Delete
});
[167] Fix | Delete
});
[168] Fix | Delete
},
[169] Fix | Delete
/**
[170] Fix | Delete
* Adds selected menu items to the menu.
[171] Fix | Delete
*
[172] Fix | Delete
* @ignore
[173] Fix | Delete
*
[174] Fix | Delete
* @param jQuery metabox The metabox jQuery object.
[175] Fix | Delete
*/
[176] Fix | Delete
addSelectedToMenu : function(processMethod) {
[177] Fix | Delete
if ( 0 === $('#menu-to-edit').length ) {
[178] Fix | Delete
return false;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
return this.each(function() {
[182] Fix | Delete
var t = $(this), menuItems = {},
[183] Fix | Delete
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' ),
[184] Fix | Delete
re = /menu-item\[([^\]]*)/;
[185] Fix | Delete
[186] Fix | Delete
processMethod = processMethod || api.addMenuItemToBottom;
[187] Fix | Delete
[188] Fix | Delete
// If no items are checked, bail.
[189] Fix | Delete
if ( !checkboxes.length )
[190] Fix | Delete
return false;
[191] Fix | Delete
[192] Fix | Delete
// Show the Ajax spinner.
[193] Fix | Delete
t.find( '.button-controls .spinner' ).addClass( 'is-active' );
[194] Fix | Delete
[195] Fix | Delete
// Retrieve menu item data.
[196] Fix | Delete
$(checkboxes).each(function(){
[197] Fix | Delete
var t = $(this),
[198] Fix | Delete
listItemDBIDMatch = re.exec( t.attr('name') ),
[199] Fix | Delete
listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
[200] Fix | Delete
[201] Fix | Delete
if ( this.className && -1 != this.className.indexOf('add-to-top') )
[202] Fix | Delete
processMethod = api.addMenuItemToTop;
[203] Fix | Delete
menuItems[listItemDBID] = t.closest('li').getItemData( 'add-menu-item', listItemDBID );
[204] Fix | Delete
});
[205] Fix | Delete
[206] Fix | Delete
// Add the items.
[207] Fix | Delete
api.addItemToMenu(menuItems, processMethod, function(){
[208] Fix | Delete
// Deselect the items and hide the Ajax spinner.
[209] Fix | Delete
checkboxes.prop( 'checked', false );
[210] Fix | Delete
t.find( '.button-controls .select-all' ).prop( 'checked', false );
[211] Fix | Delete
t.find( '.button-controls .spinner' ).removeClass( 'is-active' );
[212] Fix | Delete
});
[213] Fix | Delete
});
[214] Fix | Delete
},
[215] Fix | Delete
getItemData : function( itemType, id ) {
[216] Fix | Delete
itemType = itemType || 'menu-item';
[217] Fix | Delete
[218] Fix | Delete
var itemData = {}, i,
[219] Fix | Delete
fields = [
[220] Fix | Delete
'menu-item-db-id',
[221] Fix | Delete
'menu-item-object-id',
[222] Fix | Delete
'menu-item-object',
[223] Fix | Delete
'menu-item-parent-id',
[224] Fix | Delete
'menu-item-position',
[225] Fix | Delete
'menu-item-type',
[226] Fix | Delete
'menu-item-title',
[227] Fix | Delete
'menu-item-url',
[228] Fix | Delete
'menu-item-description',
[229] Fix | Delete
'menu-item-attr-title',
[230] Fix | Delete
'menu-item-target',
[231] Fix | Delete
'menu-item-classes',
[232] Fix | Delete
'menu-item-xfn'
[233] Fix | Delete
];
[234] Fix | Delete
[235] Fix | Delete
if( !id && itemType == 'menu-item' ) {
[236] Fix | Delete
id = this.find('.menu-item-data-db-id').val();
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
if( !id ) return itemData;
[240] Fix | Delete
[241] Fix | Delete
this.find('input').each(function() {
[242] Fix | Delete
var field;
[243] Fix | Delete
i = fields.length;
[244] Fix | Delete
while ( i-- ) {
[245] Fix | Delete
if( itemType == 'menu-item' )
[246] Fix | Delete
field = fields[i] + '[' + id + ']';
[247] Fix | Delete
else if( itemType == 'add-menu-item' )
[248] Fix | Delete
field = 'menu-item[' + id + '][' + fields[i] + ']';
[249] Fix | Delete
[250] Fix | Delete
if (
[251] Fix | Delete
this.name &&
[252] Fix | Delete
field == this.name
[253] Fix | Delete
) {
[254] Fix | Delete
itemData[fields[i]] = this.value;
[255] Fix | Delete
}
[256] Fix | Delete
}
[257] Fix | Delete
});
[258] Fix | Delete
[259] Fix | Delete
return itemData;
[260] Fix | Delete
},
[261] Fix | Delete
setItemData : function( itemData, itemType, id ) { // Can take a type, such as 'menu-item', or an id.
[262] Fix | Delete
itemType = itemType || 'menu-item';
[263] Fix | Delete
[264] Fix | Delete
if( !id && itemType == 'menu-item' ) {
[265] Fix | Delete
id = $('.menu-item-data-db-id', this).val();
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
if( !id ) return this;
[269] Fix | Delete
[270] Fix | Delete
this.find('input').each(function() {
[271] Fix | Delete
var t = $(this), field;
[272] Fix | Delete
$.each( itemData, function( attr, val ) {
[273] Fix | Delete
if( itemType == 'menu-item' )
[274] Fix | Delete
field = attr + '[' + id + ']';
[275] Fix | Delete
else if( itemType == 'add-menu-item' )
[276] Fix | Delete
field = 'menu-item[' + id + '][' + attr + ']';
[277] Fix | Delete
[278] Fix | Delete
if ( field == t.attr('name') ) {
[279] Fix | Delete
t.val( val );
[280] Fix | Delete
}
[281] Fix | Delete
});
[282] Fix | Delete
});
[283] Fix | Delete
return this;
[284] Fix | Delete
}
[285] Fix | Delete
});
[286] Fix | Delete
},
[287] Fix | Delete
[288] Fix | Delete
countMenuItems : function( depth ) {
[289] Fix | Delete
return $( '.menu-item-depth-' + depth ).length;
[290] Fix | Delete
},
[291] Fix | Delete
[292] Fix | Delete
moveMenuItem : function( $this, dir ) {
[293] Fix | Delete
[294] Fix | Delete
var items, newItemPosition, newDepth,
[295] Fix | Delete
menuItems = $( '#menu-to-edit li' ),
[296] Fix | Delete
menuItemsCount = menuItems.length,
[297] Fix | Delete
thisItem = $this.parents( 'li.menu-item' ),
[298] Fix | Delete
thisItemChildren = thisItem.childMenuItems(),
[299] Fix | Delete
thisItemData = thisItem.getItemData(),
[300] Fix | Delete
thisItemDepth = parseInt( thisItem.menuItemDepth(), 10 ),
[301] Fix | Delete
thisItemPosition = parseInt( thisItem.index(), 10 ),
[302] Fix | Delete
nextItem = thisItem.next(),
[303] Fix | Delete
nextItemChildren = nextItem.childMenuItems(),
[304] Fix | Delete
nextItemDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1,
[305] Fix | Delete
prevItem = thisItem.prev(),
[306] Fix | Delete
prevItemDepth = parseInt( prevItem.menuItemDepth(), 10 ),
[307] Fix | Delete
prevItemId = prevItem.getItemData()['menu-item-db-id'];
[308] Fix | Delete
[309] Fix | Delete
switch ( dir ) {
[310] Fix | Delete
case 'up':
[311] Fix | Delete
newItemPosition = thisItemPosition - 1;
[312] Fix | Delete
[313] Fix | Delete
// Already at top.
[314] Fix | Delete
if ( 0 === thisItemPosition )
[315] Fix | Delete
break;
[316] Fix | Delete
[317] Fix | Delete
// If a sub item is moved to top, shift it to 0 depth.
[318] Fix | Delete
if ( 0 === newItemPosition && 0 !== thisItemDepth )
[319] Fix | Delete
thisItem.moveHorizontally( 0, thisItemDepth );
[320] Fix | Delete
[321] Fix | Delete
// If prev item is sub item, shift to match depth.
[322] Fix | Delete
if ( 0 !== prevItemDepth )
[323] Fix | Delete
thisItem.moveHorizontally( prevItemDepth, thisItemDepth );
[324] Fix | Delete
[325] Fix | Delete
// Does this item have sub items?
[326] Fix | Delete
if ( thisItemChildren ) {
[327] Fix | Delete
items = thisItem.add( thisItemChildren );
[328] Fix | Delete
// Move the entire block.
[329] Fix | Delete
items.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
[330] Fix | Delete
} else {
[331] Fix | Delete
thisItem.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
[332] Fix | Delete
}
[333] Fix | Delete
break;
[334] Fix | Delete
case 'down':
[335] Fix | Delete
// Does this item have sub items?
[336] Fix | Delete
if ( thisItemChildren ) {
[337] Fix | Delete
items = thisItem.add( thisItemChildren ),
[338] Fix | Delete
nextItem = menuItems.eq( items.length + thisItemPosition ),
[339] Fix | Delete
nextItemChildren = 0 !== nextItem.childMenuItems().length;
[340] Fix | Delete
[341] Fix | Delete
if ( nextItemChildren ) {
[342] Fix | Delete
newDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1;
[343] Fix | Delete
thisItem.moveHorizontally( newDepth, thisItemDepth );
[344] Fix | Delete
}
[345] Fix | Delete
[346] Fix | Delete
// Have we reached the bottom?
[347] Fix | Delete
if ( menuItemsCount === thisItemPosition + items.length )
[348] Fix | Delete
break;
[349] Fix | Delete
[350] Fix | Delete
items.detach().insertAfter( menuItems.eq( thisItemPosition + items.length ) ).updateParentMenuItemDBId();
[351] Fix | Delete
} else {
[352] Fix | Delete
// If next item has sub items, shift depth.
[353] Fix | Delete
if ( 0 !== nextItemChildren.length )
[354] Fix | Delete
thisItem.moveHorizontally( nextItemDepth, thisItemDepth );
[355] Fix | Delete
[356] Fix | Delete
// Have we reached the bottom?
[357] Fix | Delete
if ( menuItemsCount === thisItemPosition + 1 )
[358] Fix | Delete
break;
[359] Fix | Delete
thisItem.detach().insertAfter( menuItems.eq( thisItemPosition + 1 ) ).updateParentMenuItemDBId();
[360] Fix | Delete
}
[361] Fix | Delete
break;
[362] Fix | Delete
case 'top':
[363] Fix | Delete
// Already at top.
[364] Fix | Delete
if ( 0 === thisItemPosition )
[365] Fix | Delete
break;
[366] Fix | Delete
// Does this item have sub items?
[367] Fix | Delete
if ( thisItemChildren ) {
[368] Fix | Delete
items = thisItem.add( thisItemChildren );
[369] Fix | Delete
// Move the entire block.
[370] Fix | Delete
items.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
[371] Fix | Delete
} else {
[372] Fix | Delete
thisItem.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
[373] Fix | Delete
}
[374] Fix | Delete
break;
[375] Fix | Delete
case 'left':
[376] Fix | Delete
// As far left as possible.
[377] Fix | Delete
if ( 0 === thisItemDepth )
[378] Fix | Delete
break;
[379] Fix | Delete
thisItem.shiftHorizontally( -1 );
[380] Fix | Delete
break;
[381] Fix | Delete
case 'right':
[382] Fix | Delete
// Can't be sub item at top.
[383] Fix | Delete
if ( 0 === thisItemPosition )
[384] Fix | Delete
break;
[385] Fix | Delete
// Already sub item of prevItem.
[386] Fix | Delete
if ( thisItemData['menu-item-parent-id'] === prevItemId )
[387] Fix | Delete
break;
[388] Fix | Delete
thisItem.shiftHorizontally( 1 );
[389] Fix | Delete
break;
[390] Fix | Delete
}
[391] Fix | Delete
$this.trigger( 'focus' );
[392] Fix | Delete
api.registerChange();
[393] Fix | Delete
api.refreshKeyboardAccessibility();
[394] Fix | Delete
api.refreshAdvancedAccessibility();
[395] Fix | Delete
},
[396] Fix | Delete
[397] Fix | Delete
initAccessibility : function() {
[398] Fix | Delete
var menu = $( '#menu-to-edit' );
[399] Fix | Delete
[400] Fix | Delete
api.refreshKeyboardAccessibility();
[401] Fix | Delete
api.refreshAdvancedAccessibility();
[402] Fix | Delete
[403] Fix | Delete
// Refresh the accessibility when the user comes close to the item in any way.
[404] Fix | Delete
menu.on( 'mouseenter.refreshAccessibility focus.refreshAccessibility touchstart.refreshAccessibility' , '.menu-item' , function(){
[405] Fix | Delete
api.refreshAdvancedAccessibilityOfItem( $( this ).find( 'a.item-edit' ) );
[406] Fix | Delete
} );
[407] Fix | Delete
[408] Fix | Delete
// We have to update on click as well because we might hover first, change the item, and then click.
[409] Fix | Delete
menu.on( 'click', 'a.item-edit', function() {
[410] Fix | Delete
api.refreshAdvancedAccessibilityOfItem( $( this ) );
[411] Fix | Delete
} );
[412] Fix | Delete
[413] Fix | Delete
// Links for moving items.
[414] Fix | Delete
menu.on( 'click', '.menus-move', function () {
[415] Fix | Delete
var $this = $( this ),
[416] Fix | Delete
dir = $this.data( 'dir' );
[417] Fix | Delete
[418] Fix | Delete
if ( 'undefined' !== typeof dir ) {
[419] Fix | Delete
api.moveMenuItem( $( this ).parents( 'li.menu-item' ).find( 'a.item-edit' ), dir );
[420] Fix | Delete
}
[421] Fix | Delete
});
[422] Fix | Delete
},
[423] Fix | Delete
[424] Fix | Delete
/**
[425] Fix | Delete
* refreshAdvancedAccessibilityOfItem( [itemToRefresh] )
[426] Fix | Delete
*
[427] Fix | Delete
* Refreshes advanced accessibility buttons for one menu item.
[428] Fix | Delete
* Shows or hides buttons based on the location of the menu item.
[429] Fix | Delete
*
[430] Fix | Delete
* @param {Object} itemToRefresh The menu item that might need its advanced accessibility buttons refreshed
[431] Fix | Delete
*/
[432] Fix | Delete
refreshAdvancedAccessibilityOfItem : function( itemToRefresh ) {
[433] Fix | Delete
[434] Fix | Delete
// Only refresh accessibility when necessary.
[435] Fix | Delete
if ( true !== $( itemToRefresh ).data( 'needs_accessibility_refresh' ) ) {
[436] Fix | Delete
return;
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
var thisLink, thisLinkText, primaryItems, itemPosition, title,
[440] Fix | Delete
parentItem, parentItemId, parentItemName, subItems,
[441] Fix | Delete
$this = $( itemToRefresh ),
[442] Fix | Delete
menuItem = $this.closest( 'li.menu-item' ).first(),
[443] Fix | Delete
depth = menuItem.menuItemDepth(),
[444] Fix | Delete
isPrimaryMenuItem = ( 0 === depth ),
[445] Fix | Delete
itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(),
[446] Fix | Delete
position = parseInt( menuItem.index(), 10 ),
[447] Fix | Delete
prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1, 10 ),
[448] Fix | Delete
prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(),
[449] Fix | Delete
prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(),
[450] Fix | Delete
totalMenuItems = $('#menu-to-edit li').length,
[451] Fix | Delete
hasSameDepthSibling = menuItem.nextAll( '.menu-item-depth-' + depth ).length;
[452] Fix | Delete
[453] Fix | Delete
menuItem.find( '.field-move' ).toggle( totalMenuItems > 1 );
[454] Fix | Delete
[455] Fix | Delete
// Where can they move this menu item?
[456] Fix | Delete
if ( 0 !== position ) {
[457] Fix | Delete
thisLink = menuItem.find( '.menus-move-up' );
[458] Fix | Delete
thisLink.attr( 'aria-label', menus.moveUp ).css( 'display', 'inline' );
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
if ( 0 !== position && isPrimaryMenuItem ) {
[462] Fix | Delete
thisLink = menuItem.find( '.menus-move-top' );
[463] Fix | Delete
thisLink.attr( 'aria-label', menus.moveToTop ).css( 'display', 'inline' );
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
if ( position + 1 !== totalMenuItems && 0 !== position ) {
[467] Fix | Delete
thisLink = menuItem.find( '.menus-move-down' );
[468] Fix | Delete
thisLink.attr( 'aria-label', menus.moveDown ).css( 'display', 'inline' );
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
if ( 0 === position && 0 !== hasSameDepthSibling ) {
[472] Fix | Delete
thisLink = menuItem.find( '.menus-move-down' );
[473] Fix | Delete
thisLink.attr( 'aria-label', menus.moveDown ).css( 'display', 'inline' );
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
if ( ! isPrimaryMenuItem ) {
[477] Fix | Delete
thisLink = menuItem.find( '.menus-move-left' ),
[478] Fix | Delete
thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft );
[479] Fix | Delete
thisLink.attr( 'aria-label', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ).text( thisLinkText ).css( 'display', 'inline' );
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
if ( 0 !== position ) {
[483] Fix | Delete
if ( menuItem.find( '.menu-item-data-parent-id' ).val() !== menuItem.prev().find( '.menu-item-data-db-id' ).val() ) {
[484] Fix | Delete
thisLink = menuItem.find( '.menus-move-right' ),
[485] Fix | Delete
thisLinkText = menus.under.replace( '%s', prevItemNameRight );
[486] Fix | Delete
thisLink.attr( 'aria-label', menus.moveUnder.replace( '%s', prevItemNameRight ) ).text( thisLinkText ).css( 'display', 'inline' );
[487] Fix | Delete
}
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
if ( isPrimaryMenuItem ) {
[491] Fix | Delete
primaryItems = $( '.menu-item-depth-0' ),
[492] Fix | Delete
itemPosition = primaryItems.index( menuItem ) + 1,
[493] Fix | Delete
totalMenuItems = primaryItems.length,
[494] Fix | Delete
[495] Fix | Delete
// String together help text for primary menu items.
[496] Fix | Delete
title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$d', totalMenuItems );
[497] Fix | Delete
} else {
[498] Fix | Delete
parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(),
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function