').html(resp).find('li'),
wrapper = panel.closest( '.accordion-section-content' ),
selectAll = wrapper.find( '.button-controls .select-all' ),
$item;
if( ! $items.length ) {
$('.categorychecklist', panel).html( '
' + wp.i18n.__( 'No results found.' ) + '
' );
$( '.spinner', panel ).removeClass( 'is-active' );
wrapper.addClass( 'has-no-menu-item' );
return;
}
$items.each(function(){
$item = $(this);
// Make a unique DB ID number.
matched = pattern.exec($item.html());
if ( matched && matched[1] ) {
newID = matched[1];
while( form.elements['menu-item[' + newID + '][menu-item-type]'] || takenIDs[ newID ] ) {
newID--;
}
takenIDs[newID] = true;
if ( newID != matched[1] ) {
$item.html( $item.html().replace(new RegExp(
'menu-item\\[' + matched[1] + '\\]', 'g'),
'menu-item[' + newID + ']'
) );
}
}
});
$('.categorychecklist', panel).html( $items );
$( '.spinner', panel ).removeClass( 'is-active' );
wrapper.removeClass( 'has-no-menu-item' );
if ( selectAll.is( ':checked' ) ) {
selectAll.prop( 'checked', false );
}
},
/**
* Remove a menu item.
*
* @param {Object} el The element to be removed as a jQuery object.
*
* @fires document#menu-removing-item Passes the element to be removed.
*/
removeMenuItem : function(el) {
var children = el.childMenuItems();
$( document ).trigger( 'menu-removing-item', [ el ] );
el.addClass('deleting').animate({
opacity : 0,
height: 0
}, 350, function() {
var ins = $('#menu-instructions');
el.remove();
children.shiftDepthClass( -1 ).updateParentMenuItemDBId();
if ( 0 === $( '#menu-to-edit li' ).length ) {
$( '.drag-instructions' ).hide();
ins.removeClass( 'menu-instructions-inactive' );
}
api.refreshAdvancedAccessibility();
wp.a11y.speak( menus.itemRemoved );
menus.updateParentDropdown();
menus.updateOrderDropdown();
});
},
depthToPx : function(depth) {
return depth * api.options.menuItemDepthPerLevel;
},
pxToDepth : function(px) {
return Math.floor(px / api.options.menuItemDepthPerLevel);
}
};
$( function() {
wpNavMenu.init();
// Prevent focused element from being hidden by the sticky footer.
$( '.menu-edit a, .menu-edit button, .menu-edit input, .menu-edit textarea, .menu-edit select' ).on('focus', function() {
if ( window.innerWidth >= 783 ) {
var navMenuHeight = $( '#nav-menu-footer' ).height() + 20;
var bottomOffset = $(this).offset().top - ( $(window).scrollTop() + $(window).height() - $(this).height() );
if ( bottomOffset > 0 ) {
bottomOffset = 0;
}
bottomOffset = bottomOffset * -1;
if( bottomOffset < navMenuHeight ) {
var scrollTop = $(document).scrollTop();
$(document).scrollTop( scrollTop + ( navMenuHeight - bottomOffset ) );
}
}
});
});
// Show bulk action.
$( document ).on( 'menu-item-added', function() {
if ( ! $( '.bulk-actions' ).is( ':visible' ) ) {
$( '.bulk-actions' ).show();
}
} );
// Hide bulk action.
$( document ).on( 'menu-removing-item', function( e, el ) {
var menuElement = $( el ).parents( '#menu-to-edit' );
if ( menuElement.find( 'li' ).length === 1 && $( '.bulk-actions' ).is( ':visible' ) ) {
$( '.bulk-actions' ).hide();
}
} );
})(jQuery);