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

git-svn-id: http://svn.automattic.com/wordpress/trunk@14468 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-05-05 21:23:53 +00:00
parent 2d7f62489d
commit 8b27606b04
2 changed files with 119 additions and 121 deletions

View File

@ -88,6 +88,38 @@ var wpNavMenu, WPNavMenuHandler = function ($) {
menuList, targetList, api; 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 // jQuery extensions
$.fn.extend({ $.fn.extend({
menuItemDepth : function() { menuItemDepth : function() {
@ -173,68 +205,34 @@ var wpNavMenu, WPNavMenuHandler = function ($) {
*/ */
addSelectedToMenu : function(processMethod) { addSelectedToMenu : function(processMethod) {
return this.each(function() { return this.each(function() {
var t = $(this), var t = $(this), menuItems = {},
checked = t.find('.tabs-panel-active .categorychecklist li input:checked'), checkboxes = t.find('.tabs-panel-active .categorychecklist li input:checked'),
re = new RegExp('menu-item\\[(\[^\\]\]*)'); re = new RegExp('menu-item\\[(\[^\\]\]*)');
processMethod = processMethod || api.addMenuItemToBottom; processMethod = processMethod || api.addMenuItemToBottom;
// If no items are checked, bail. // If no items are checked, bail.
if ( !checked.length ) if ( !checkboxes.length )
return false; return false;
// Show the ajax spinner // Show the ajax spinner
t.find('img.waiting').show(); t.find('img.waiting').show();
// Retrieve menu item data // Retrieve menu item data
$(checked).each(function(){ $(checkboxes).each(function(){
var checkbox = $(this), var listItemDBIDMatch = re.exec( $(this).attr('name') ),
item = checkbox.parent().prev();
listItemDBIDMatch = re.exec( checkbox.attr('name') );
listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10); listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
listItemData = getListDataFromID(listItemDBID); menuItems[listItemDBID] = getListDataFromID(listItemDBID);
menuItem = {};
menuItem[listItemDBID] = listItemData;
api.addItemToMenu(menuItem, processMethod, function(){
item.deselectItem();
}); });
}); // Add the items
api.addItemToMenu(menuItems, processMethod, function(){
// Remove the ajax spinner // Deselect the items and hide the ajax spinner
checkboxes.parent().prev().deselectItem();
t.find('img.waiting').hide(); 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() { initToggles : function() {

File diff suppressed because one or more lines are too long