Only make one ajax call for multiple items. Also move jQuery extensions into their own function. props koopersmith, see #13220.

git-svn-id: https://develop.svn.wordpress.org/trunk@14468 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2010-05-05 21:23:53 +00:00
parent 13e9671554
commit 6c397f5e43
2 changed files with 119 additions and 121 deletions

View File

@ -88,6 +88,38 @@ var wpNavMenu, WPNavMenuHandler = function ($) {
menuList, targetList, api;
return api = {
// Functions that run on init.
init : function() {
menuList = $('#menu-to-edit');
targetList = menuList;
this.jQueryExtensions();
this.attachMenuEditListeners();
this.setupInputWithDefaultTitle();
this.attachAddMenuItemListeners();
this.attachQuickSearchListeners();
this.attachTabsPanelListeners();
this.attachHomeLinkListener();
if( menuList.length ) // If no menu, we're in the + tab.
this.initSortables();
this.initToggles();
this.initTabManager();
this.initAddMenuItemDraggables();
this.checkForEmptyMenu();
},
jQueryExtensions : function() {
// jQuery extensions
$.fn.extend({
menuItemDepth : function() {
@ -173,68 +205,34 @@ var wpNavMenu, WPNavMenuHandler = function ($) {
*/
addSelectedToMenu : function(processMethod) {
return this.each(function() {
var t = $(this),
checked = t.find('.tabs-panel-active .categorychecklist li input:checked'),
var t = $(this), menuItems = {},
checkboxes = t.find('.tabs-panel-active .categorychecklist li input:checked'),
re = new RegExp('menu-item\\[(\[^\\]\]*)');
processMethod = processMethod || api.addMenuItemToBottom;
// If no items are checked, bail.
if ( !checked.length )
if ( !checkboxes.length )
return false;
// Show the ajax spinner
t.find('img.waiting').show();
// Retrieve menu item data
$(checked).each(function(){
var checkbox = $(this),
item = checkbox.parent().prev();
listItemDBIDMatch = re.exec( checkbox.attr('name') );
$(checkboxes).each(function(){
var listItemDBIDMatch = re.exec( $(this).attr('name') ),
listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
listItemData = getListDataFromID(listItemDBID);
menuItem = {};
menuItem[listItemDBID] = listItemData;
api.addItemToMenu(menuItem, processMethod, function(){
item.deselectItem();
menuItems[listItemDBID] = getListDataFromID(listItemDBID);
});
});
// Remove the ajax spinner
// Add the items
api.addItemToMenu(menuItems, processMethod, function(){
// Deselect the items and hide the ajax spinner
checkboxes.parent().prev().deselectItem();
t.find('img.waiting').hide();
});
});
},
});
return api = {
// Functions that run on init.
init : function() {
menuList = $('#menu-to-edit');
targetList = menuList;
this.attachMenuEditListeners();
this.setupInputWithDefaultTitle();
this.attachAddMenuItemListeners();
this.attachQuickSearchListeners();
this.attachTabsPanelListeners();
this.attachHomeLinkListener();
if( menuList.length ) // If no menu, we're in the + tab.
this.initSortables();
this.initToggles();
this.initTabManager();
this.initAddMenuItemDraggables();
this.checkForEmptyMenu();
},
initToggles : function() {

File diff suppressed because one or more lines are too long