2010-03-17 17:13:16 +01:00
|
|
|
/**
|
2010-03-22 20:56:16 +01:00
|
|
|
* WordPress Administration Navigation Menu
|
2010-03-17 17:13:16 +01:00
|
|
|
* Interface JS functions
|
|
|
|
*
|
2010-03-22 20:56:16 +01:00
|
|
|
* @version 2.0.0
|
2010-03-17 17:13:16 +01:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
2010-05-06 19:11:52 +02:00
|
|
|
var wpNavMenu;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-06 19:11:52 +02:00
|
|
|
(function($) {
|
|
|
|
|
|
|
|
var api = wpNavMenu = {
|
|
|
|
|
|
|
|
options : {
|
|
|
|
menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
|
|
|
|
globalMaxDepth : 11
|
|
|
|
},
|
|
|
|
|
|
|
|
menuList : undefined, // Set in init.
|
|
|
|
targetList : undefined, // Set in init.
|
|
|
|
|
|
|
|
autoCompleteData : {},
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-03-22 20:56:16 +01:00
|
|
|
// Functions that run on init.
|
|
|
|
init : function() {
|
2010-05-06 19:11:52 +02:00
|
|
|
api.menuList = $('#menu-to-edit');
|
|
|
|
api.targetList = api.menuList;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-05 23:23:53 +02:00
|
|
|
this.jQueryExtensions();
|
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
this.attachMenuEditListeners();
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
this.setupInputWithDefaultTitle();
|
|
|
|
this.attachAddMenuItemListeners();
|
|
|
|
this.attachQuickSearchListeners();
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
this.attachTabsPanelListeners();
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-04 12:01:15 +02:00
|
|
|
this.attachHomeLinkListener();
|
|
|
|
|
2010-05-06 19:11:52 +02:00
|
|
|
if( api.menuList.length ) // If no menu, we're in the + tab.
|
2010-05-02 21:09:10 +02:00
|
|
|
this.initSortables();
|
2010-03-22 20:56:16 +01:00
|
|
|
|
2010-04-29 05:43:11 +02:00
|
|
|
this.initToggles();
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-03 12:28:35 +02:00
|
|
|
this.initTabManager();
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-04 12:01:15 +02:00
|
|
|
this.checkForEmptyMenu();
|
2010-04-29 05:43:11 +02:00
|
|
|
},
|
2010-05-05 23:23:53 +02:00
|
|
|
|
|
|
|
jQueryExtensions : function() {
|
|
|
|
// jQuery extensions
|
|
|
|
$.fn.extend({
|
|
|
|
menuItemDepth : function() {
|
2010-05-06 19:11:52 +02:00
|
|
|
return api.pxToDepth( this.eq(0).css('margin-left').slice(0, -2) );
|
2010-05-05 23:23:53 +02:00
|
|
|
},
|
|
|
|
updateDepthClass : function(current, prev) {
|
|
|
|
return this.each(function(){
|
|
|
|
var t = $(this);
|
|
|
|
prev = prev || t.menuItemDepth();
|
|
|
|
$(this).removeClass('menu-item-depth-'+ prev )
|
|
|
|
.addClass('menu-item-depth-'+ current );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
shiftDepthClass : function(change) {
|
|
|
|
return this.each(function(){
|
|
|
|
var t = $(this),
|
|
|
|
depth = t.menuItemDepth();
|
|
|
|
$(this).removeClass('menu-item-depth-'+ depth )
|
|
|
|
.addClass('menu-item-depth-'+ (depth + change) );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
childMenuItems : function() {
|
|
|
|
var result = $();
|
|
|
|
this.each(function(){
|
|
|
|
var t = $(this), depth = t.menuItemDepth(), next = t.next();
|
|
|
|
while( next.length && next.menuItemDepth() > depth ) {
|
|
|
|
result = result.add( next );
|
|
|
|
next = next.next();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
updateParentMenuItemDBId : function() {
|
|
|
|
return this.each(function(){
|
|
|
|
var item = $(this),
|
|
|
|
input = item.find('.menu-item-data-parent-id'),
|
|
|
|
depth = item.menuItemDepth(),
|
|
|
|
parent = item.prev();
|
|
|
|
|
|
|
|
if( depth == 0 ) { // Item is on the top level, has no parent
|
|
|
|
input.val(0);
|
|
|
|
} else { // Find the parent item, and retrieve its object id.
|
|
|
|
while( parent.menuItemDepth() != depth - 1 ) {
|
|
|
|
parent = parent.prev();
|
|
|
|
}
|
|
|
|
input.val( parent.find('.menu-item-data-db-id').val() );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
hideAdvancedMenuItemFields : function() {
|
|
|
|
return this.each(function(){
|
|
|
|
var that = $(this);
|
|
|
|
$('.hide-column-tog').not(':checked').each(function(){
|
|
|
|
that.find('.field-' + $(this).val() ).addClass('hidden-field');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Adds selected menu items to the menu.
|
|
|
|
*
|
|
|
|
* @param jQuery metabox The metabox jQuery object.
|
|
|
|
*/
|
|
|
|
addSelectedToMenu : function(processMethod) {
|
|
|
|
return this.each(function() {
|
|
|
|
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 ( !checkboxes.length )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Show the ajax spinner
|
|
|
|
t.find('img.waiting').show();
|
|
|
|
|
|
|
|
// Retrieve menu item data
|
|
|
|
$(checkboxes).each(function(){
|
|
|
|
var listItemDBIDMatch = re.exec( $(this).attr('name') ),
|
|
|
|
listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
|
2010-05-06 19:11:52 +02:00
|
|
|
menuItems[listItemDBID] = api.getListDataFromID(listItemDBID);
|
2010-05-05 23:23:53 +02:00
|
|
|
});
|
|
|
|
// Add the items
|
|
|
|
api.addItemToMenu(menuItems, processMethod, function(){
|
|
|
|
// Deselect the items and hide the ajax spinner
|
2010-05-06 16:09:10 +02:00
|
|
|
checkboxes.removeAttr('checked');
|
2010-05-05 23:23:53 +02:00
|
|
|
t.find('img.waiting').hide();
|
|
|
|
});
|
|
|
|
});
|
2010-05-06 17:40:29 +02:00
|
|
|
}
|
2010-05-05 23:23:53 +02:00
|
|
|
});
|
|
|
|
},
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-04-29 05:43:11 +02:00
|
|
|
initToggles : function() {
|
|
|
|
// init postboxes
|
2010-04-27 03:05:58 +02:00
|
|
|
postboxes.add_postbox_toggles('nav-menus');
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-04-29 05:43:11 +02:00
|
|
|
// adjust columns functions for menus UI
|
|
|
|
columns.useCheckboxesForHidden();
|
|
|
|
columns.checked = function(field) {
|
|
|
|
$('.field-' + field).removeClass('hidden-field');
|
|
|
|
}
|
|
|
|
columns.unchecked = function(field) {
|
|
|
|
$('.field-' + field).addClass('hidden-field');
|
|
|
|
}
|
|
|
|
// hide fields
|
2010-05-06 19:11:52 +02:00
|
|
|
api.menuList.hideAdvancedMenuItemFields();
|
2010-04-29 05:43:11 +02:00
|
|
|
},
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
initSortables : function() {
|
|
|
|
var currentDepth = 0, originalDepth, minDepth, maxDepth,
|
2010-05-06 19:11:52 +02:00
|
|
|
menuLeft = api.menuList.offset().left,
|
2010-05-04 09:24:49 +02:00
|
|
|
newItem, transport;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-06 19:11:52 +02:00
|
|
|
api.menuList.sortable({
|
2010-05-04 09:24:49 +02:00
|
|
|
handle: '.menu-item-handle',
|
2010-05-02 21:09:10 +02:00
|
|
|
placeholder: 'sortable-placeholder',
|
|
|
|
start: function(e, ui) {
|
2010-05-05 23:06:43 +02:00
|
|
|
var height, width, parent, children, maxChildDepth;
|
2010-05-04 09:24:49 +02:00
|
|
|
|
|
|
|
transport = ui.item.children('.menu-item-transport');
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-04 09:24:49 +02:00
|
|
|
// Set depths. currentDepth must be set before children are located.
|
|
|
|
originalDepth = ( newItem ) ? 0 : ui.item.menuItemDepth();
|
2010-05-02 21:09:10 +02:00
|
|
|
updateCurrentDepth(ui, originalDepth);
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-06 16:09:10 +02:00
|
|
|
// Attach child elements to parent
|
|
|
|
// Skip the placeholder
|
|
|
|
parent = ( ui.item.next()[0] == ui.placeholder[0] ) ? ui.item.next() : ui.item;
|
|
|
|
children = parent.childMenuItems();
|
|
|
|
transport.append( children );
|
2010-05-02 21:09:10 +02:00
|
|
|
|
|
|
|
// Now that the element is complete, we can update...
|
|
|
|
updateDepthRange(ui);
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
// Update the height of the placeholder to match the moving item.
|
|
|
|
height = transport.outerHeight();
|
|
|
|
// If there are children, account for distance between top of children and parent
|
|
|
|
height += ( height > 0 ) ? (ui.placeholder.css('margin-top').slice(0, -2) * 1) : 0;
|
2010-05-04 09:24:49 +02:00
|
|
|
height += ui.helper.outerHeight();
|
2010-05-02 21:09:10 +02:00
|
|
|
height -= 2; // Subtract 2 for borders
|
|
|
|
ui.placeholder.height(height);
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
// Update the width of the placeholder to match the moving item.
|
|
|
|
maxChildDepth = originalDepth;
|
2010-05-06 16:09:10 +02:00
|
|
|
children.each(function(){
|
|
|
|
var depth = $(this).menuItemDepth();
|
|
|
|
maxChildDepth = (depth > maxChildDepth) ? depth : maxChildDepth;
|
|
|
|
});
|
2010-05-04 09:24:49 +02:00
|
|
|
width = ui.helper.find('.menu-item-handle').outerWidth(); // Get original width
|
2010-05-06 19:11:52 +02:00
|
|
|
width += api.depthToPx(maxChildDepth - originalDepth); // Account for children
|
2010-05-02 21:09:10 +02:00
|
|
|
width -= 2; // Subtract 2 for borders
|
|
|
|
ui.placeholder.width(width);
|
|
|
|
},
|
|
|
|
stop: function(e, ui) {
|
|
|
|
var children, depthChange = currentDepth - originalDepth;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
// Return child elements to the list
|
2010-05-04 09:24:49 +02:00
|
|
|
children = transport.children().insertAfter(ui.item);
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-06 16:09:10 +02:00
|
|
|
// Update depth classes
|
|
|
|
if( depthChange != 0 ) {
|
|
|
|
ui.item.updateDepthClass( currentDepth );
|
|
|
|
children.shiftDepthClass( depthChange );
|
2010-05-02 21:09:10 +02:00
|
|
|
}
|
2010-05-06 16:09:10 +02:00
|
|
|
// Update the item data.
|
|
|
|
ui.item.updateParentMenuItemDBId();
|
2010-05-04 09:24:49 +02:00
|
|
|
// Update positions
|
2010-05-06 19:11:52 +02:00
|
|
|
api.recalculateMenuItemPositions();
|
2010-05-02 21:09:10 +02:00
|
|
|
},
|
|
|
|
change: function(e, ui) {
|
|
|
|
// Make sure the placeholder is inside the menu.
|
|
|
|
// Otherwise fix it, or we're in trouble.
|
|
|
|
if( ! ui.placeholder.parent().hasClass('menu') )
|
2010-05-06 19:11:52 +02:00
|
|
|
ui.placeholder.appendTo(api.menuList);
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
updateDepthRange(ui);
|
|
|
|
},
|
|
|
|
sort: function(e, ui) {
|
2010-05-06 19:11:52 +02:00
|
|
|
var depth = api.pxToDepth(ui.helper.offset().left - menuLeft);
|
2010-05-02 21:09:10 +02:00
|
|
|
// Check and correct if depth is not within range.
|
|
|
|
if ( depth < minDepth ) depth = minDepth;
|
|
|
|
else if ( depth > maxDepth ) depth = maxDepth;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
if( depth != currentDepth )
|
|
|
|
updateCurrentDepth(ui, depth);
|
2010-05-06 19:11:52 +02:00
|
|
|
}
|
2010-04-29 05:43:11 +02:00
|
|
|
});
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
function updateDepthRange(ui) {
|
|
|
|
var prev = ui.placeholder.prev(),
|
|
|
|
next = ui.placeholder.next(), depth;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
// Make sure we don't select the moving item.
|
2010-05-03 22:26:11 +02:00
|
|
|
if( prev[0] == ui.item[0] ) prev = prev.prev();
|
2010-05-02 21:09:10 +02:00
|
|
|
if( next[0] == ui.item[0] ) next = next.next();
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
minDepth = (next.length) ? next.menuItemDepth() : 0;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
if( prev.length )
|
2010-05-06 19:11:52 +02:00
|
|
|
maxDepth = ( (depth = prev.menuItemDepth() + 1) > api.options.globalMaxDepth ) ? api.options.globalMaxDepth : depth;
|
2010-05-02 21:09:10 +02:00
|
|
|
else
|
|
|
|
maxDepth = 0;
|
|
|
|
}
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
function updateCurrentDepth(ui, depth) {
|
|
|
|
ui.placeholder.updateDepthClass( depth, currentDepth );
|
|
|
|
currentDepth = depth;
|
|
|
|
}
|
2010-04-27 03:05:58 +02:00
|
|
|
},
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
attachMenuEditListeners : function() {
|
|
|
|
var that = this;
|
|
|
|
$('#update-nav-menu').bind('click', function(e) {
|
|
|
|
if ( e.target && e.target.className ) {
|
|
|
|
if ( -1 != e.target.className.indexOf('item-edit') ) {
|
|
|
|
return that.eventOnClickEditLink(e.target);
|
|
|
|
} else if ( -1 != e.target.className.indexOf('menu-delete') ) {
|
|
|
|
return that.eventOnClickMenuDelete(e.target);
|
|
|
|
} else if ( -1 != e.target.className.indexOf('item-delete') ) {
|
|
|
|
return that.eventOnClickMenuItemDelete(e.target);
|
2010-04-29 05:43:11 +02:00
|
|
|
} else if ( -1 != e.target.className.indexOf('item-close') ) {
|
|
|
|
return that.eventOnClickCloseLink(e.target);
|
2010-04-27 03:05:58 +02:00
|
|
|
}
|
2010-03-22 20:56:16 +01:00
|
|
|
}
|
|
|
|
});
|
2010-04-27 03:05:58 +02:00
|
|
|
},
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
/**
|
|
|
|
* An interface for managing default values for input elements
|
|
|
|
* that is both JS and accessibility-friendly.
|
|
|
|
*
|
|
|
|
* Input elements that add the class 'input-with-default-title'
|
|
|
|
* will have their values set to the provided HTML title when empty.
|
|
|
|
*/
|
|
|
|
setupInputWithDefaultTitle : function() {
|
|
|
|
var name = 'input-with-default-title';
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
$('.' + name).each( function(){
|
2010-04-29 05:43:11 +02:00
|
|
|
var $t = $(this), title = $t.attr('title'), val = $t.val();
|
2010-05-02 21:09:10 +02:00
|
|
|
$t.data( name, title );
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
if( '' == val ) $t.val( title );
|
2010-04-29 05:43:11 +02:00
|
|
|
else if ( title == val ) return;
|
2010-05-02 21:09:10 +02:00
|
|
|
else $t.removeClass( name );
|
|
|
|
}).focus( function(){
|
2010-04-29 05:43:11 +02:00
|
|
|
var $t = $(this);
|
2010-05-02 21:09:10 +02:00
|
|
|
if( $t.val() == $t.data(name) )
|
|
|
|
$t.val('').removeClass( name );
|
|
|
|
}).blur( function(){
|
2010-04-29 05:43:11 +02:00
|
|
|
var $t = $(this);
|
|
|
|
if( '' == $t.val() )
|
2010-05-05 22:29:50 +02:00
|
|
|
$t.addClass( name ).val( $t.data(name) );
|
2010-04-29 05:43:11 +02:00
|
|
|
});
|
2010-05-02 21:09:10 +02:00
|
|
|
},
|
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
attachAddMenuItemListeners : function() {
|
|
|
|
var form = $('#nav-menu-meta');
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
form.find('.add-to-menu input').click(function(){
|
|
|
|
$(this).trigger('wp-add-menu-item', [api.addMenuItemToBottom]);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
form.find('.customlinkdiv').bind('wp-add-menu-item', function(e, processMethod) {
|
|
|
|
api.addCustomLink( processMethod );
|
|
|
|
});
|
|
|
|
form.find('.posttypediv, .taxonomydiv').bind('wp-add-menu-item', function(e, processMethod) {
|
|
|
|
$(this).addSelectedToMenu( processMethod );
|
2010-05-05 22:37:32 +02:00
|
|
|
});
|
2010-05-05 22:29:50 +02:00
|
|
|
},
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
attachQuickSearchListeners : function() {
|
|
|
|
var that = this,
|
|
|
|
form = $('#nav-menu-meta');
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
// auto-suggest for the quick-search boxes
|
|
|
|
$('input.quick-search').each(function(i, el) {
|
2010-05-03 22:26:11 +02:00
|
|
|
that.setupQuickSearchEventListeners(el);
|
2010-03-22 20:56:16 +01:00
|
|
|
});
|
2010-05-05 22:29:50 +02:00
|
|
|
form.find('.quick-search-submit').click(function() {
|
|
|
|
$(this).trigger('wp-quick-search');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
form.find('.inside').children().bind('wp-quick-search', function() {
|
|
|
|
that.quickSearch( $(this).attr('id') );
|
2010-03-22 20:56:16 +01:00
|
|
|
});
|
2010-05-04 10:31:40 +02:00
|
|
|
},
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-04 10:31:40 +02:00
|
|
|
quickSearch : function(id) {
|
|
|
|
var type = $('#' + id + ' .quick-search').attr('name'),
|
|
|
|
q = $('#' + id + ' .quick-search').val(),
|
|
|
|
menu = $('#menu').val(),
|
|
|
|
nonce = $('#menu-settings-column-nonce').val(),
|
|
|
|
params = {},
|
|
|
|
that = this,
|
|
|
|
processMethod = function(){};
|
|
|
|
|
|
|
|
processMethod = that.processQuickSearchQueryResponse;
|
|
|
|
|
|
|
|
params = {
|
|
|
|
'action': 'menu-quick-search',
|
|
|
|
'response-format': 'markup',
|
|
|
|
'menu': menu,
|
|
|
|
'menu-settings-column-nonce': nonce,
|
|
|
|
'q': q,
|
|
|
|
'type': type
|
|
|
|
};
|
|
|
|
|
|
|
|
$.post( ajaxurl, params, function(menuMarkup) {
|
|
|
|
processMethod.call(that, menuMarkup, params);
|
|
|
|
});
|
|
|
|
},
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
addCustomLink : function( processMethod ) {
|
|
|
|
var url = $('#custom-menu-item-url').val(),
|
|
|
|
label = $('#custom-menu-item-name').val();
|
2010-05-04 10:31:40 +02:00
|
|
|
|
2010-05-05 22:37:32 +02:00
|
|
|
processMethod = processMethod || api.addMenuItemToBottom;
|
|
|
|
|
2010-05-04 10:31:40 +02:00
|
|
|
if ( '' == url || 'http://' == url )
|
|
|
|
return false;
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-04 10:31:40 +02:00
|
|
|
// Show the ajax spinner
|
|
|
|
$('.customlinkdiv img.waiting').show();
|
2010-05-05 22:29:50 +02:00
|
|
|
this.addLinkToMenu( url, label, processMethod, function() {
|
|
|
|
// Remove the ajax spinner
|
|
|
|
$('.customlinkdiv img.waiting').hide();
|
|
|
|
// Set custom link form back to defaults
|
|
|
|
$('#custom-menu-item-name').val('').blur();
|
|
|
|
$('#custom-menu-item-url').val('http://');
|
|
|
|
});
|
|
|
|
},
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
addLinkToMenu : function(url, label, processMethod, callback) {
|
|
|
|
processMethod = processMethod || api.addMenuItemToBottom;
|
|
|
|
callback = callback || function(){};
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
api.addItemToMenu({
|
|
|
|
'-1': {
|
|
|
|
'menu-item-type': 'custom',
|
|
|
|
'menu-item-url': url,
|
|
|
|
'menu-item-title': label
|
|
|
|
}
|
|
|
|
}, processMethod, callback);
|
|
|
|
},
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
addItemToMenu : function(menuItem, processMethod, callback) {
|
|
|
|
var menu = $('#menu').val(),
|
|
|
|
nonce = $('#menu-settings-column-nonce').val();
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
processMethod = processMethod || function(){};
|
|
|
|
callback = callback || function(){};
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-04 10:31:40 +02:00
|
|
|
params = {
|
|
|
|
'action': 'add-menu-item',
|
|
|
|
'menu': menu,
|
|
|
|
'menu-settings-column-nonce': nonce,
|
2010-05-06 17:40:29 +02:00
|
|
|
'menu-item': menuItem
|
2010-05-04 10:31:40 +02:00
|
|
|
};
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-04 10:31:40 +02:00
|
|
|
$.post( ajaxurl, params, function(menuMarkup) {
|
2010-05-05 22:29:50 +02:00
|
|
|
processMethod(menuMarkup, params);
|
|
|
|
callback();
|
2010-05-04 12:01:15 +02:00
|
|
|
});
|
|
|
|
},
|
2010-05-05 22:29:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the add menu item request response into menu list item.
|
|
|
|
*
|
|
|
|
* @param string menuMarkup The text server response of menu item markup.
|
|
|
|
* @param object req The request arguments.
|
|
|
|
*/
|
|
|
|
addMenuItemToBottom : function( menuMarkup, req ) {
|
2010-05-06 19:11:52 +02:00
|
|
|
$(menuMarkup).hideAdvancedMenuItemFields().appendTo( api.targetList );
|
2010-05-05 22:29:50 +02:00
|
|
|
},
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
addMenuItemToTop : function( menuMarkup, req ) {
|
2010-05-06 19:11:52 +02:00
|
|
|
$(menuMarkup).hideAdvancedMenuItemFields().prependTo( api.targetList );
|
2010-05-04 12:01:15 +02:00
|
|
|
},
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-04 12:01:15 +02:00
|
|
|
attachHomeLinkListener : function() {
|
|
|
|
$('.add-home-link', '.customlinkdiv').click(function(e) {
|
2010-05-06 19:11:52 +02:00
|
|
|
api.addLinkToMenu( navMenuL10n.homeurl, navMenuL10n.home, api.addMenuItemToTop, api.recalculateMenuItemPositions );
|
2010-05-04 12:01:15 +02:00
|
|
|
return false;
|
2010-05-02 23:05:55 +02:00
|
|
|
});
|
2010-04-27 03:05:58 +02:00
|
|
|
},
|
2010-03-22 20:56:16 +01:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
attachTabsPanelListeners : function() {
|
|
|
|
$('#menu-settings-column').bind('click', function(e) {
|
2010-05-06 16:09:10 +02:00
|
|
|
var selectAreaMatch, activePanel, panelIdMatch, wrapper, inputs, i, items;
|
2010-05-05 23:06:43 +02:00
|
|
|
|
2010-04-29 05:43:11 +02:00
|
|
|
if ( e.target && e.target.className && -1 != e.target.className.indexOf('nav-tab-link') ) {
|
2010-05-05 23:06:43 +02:00
|
|
|
panelIdMatch = /#(.*)$/.exec(e.target.href);
|
|
|
|
wrapper = $(e.target).parents('.inside').first()[0];
|
|
|
|
inputs = wrapper ? wrapper.getElementsByTagName('input') : [];
|
2010-04-28 20:30:32 +02:00
|
|
|
i = inputs.length;
|
|
|
|
|
|
|
|
// upon changing tabs, we want to uncheck all checkboxes
|
2010-05-03 22:26:11 +02:00
|
|
|
while( i-- )
|
2010-04-28 20:30:32 +02:00
|
|
|
inputs[i].checked = false;
|
|
|
|
|
|
|
|
$('.tabs-panel', wrapper).each(function() {
|
2010-04-27 03:05:58 +02:00
|
|
|
if ( this.className )
|
|
|
|
this.className = this.className.replace('tabs-panel-active', 'tabs-panel-inactive');
|
|
|
|
});
|
|
|
|
|
2010-04-28 20:30:32 +02:00
|
|
|
$('.tabs', wrapper).each(function() {
|
2010-04-27 03:05:58 +02:00
|
|
|
this.className = this.className.replace('tabs', '');
|
|
|
|
});
|
|
|
|
|
|
|
|
e.target.parentNode.className += ' tabs';
|
|
|
|
|
|
|
|
if ( panelIdMatch && panelIdMatch[1] ) {
|
|
|
|
activePanel = document.getElementById(panelIdMatch[1]);
|
|
|
|
if ( activePanel ) {
|
|
|
|
activePanel.className = activePanel.className.replace('tabs-panel-inactive', 'tabs-panel-active');
|
|
|
|
}
|
|
|
|
}
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
return false;
|
|
|
|
} else if ( e.target && e.target.className && -1 != e.target.className.indexOf('select-all') ) {
|
2010-05-06 16:09:10 +02:00
|
|
|
selectAreaMatch = /#(.*)$/.exec(e.target.href);
|
2010-04-27 03:05:58 +02:00
|
|
|
if ( selectAreaMatch && selectAreaMatch[1] ) {
|
2010-05-06 16:09:10 +02:00
|
|
|
items = $('#' + selectAreaMatch[1] + ' .tabs-panel-active .menu-item-title input');
|
|
|
|
if( items.length === items.filter(':checked').length )
|
|
|
|
items.removeAttr('checked');
|
2010-05-04 10:54:35 +02:00
|
|
|
else
|
2010-05-06 16:09:10 +02:00
|
|
|
items.attr('checked', 'checked');
|
2010-04-27 03:05:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-03-22 20:56:16 +01:00
|
|
|
});
|
2010-04-27 03:05:58 +02:00
|
|
|
},
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-03 12:28:35 +02:00
|
|
|
initTabManager : function() {
|
|
|
|
var fixed = $('.nav-tabs-wrapper'),
|
|
|
|
fluid = fixed.children('.nav-tabs'),
|
|
|
|
active = fluid.children('.nav-tab-active'),
|
|
|
|
tabs = fluid.children('.nav-tab'),
|
|
|
|
tabsWidth = 0,
|
|
|
|
fixedRight, fixedLeft,
|
2010-05-06 17:40:29 +02:00
|
|
|
arrowLeft, arrowRight,
|
2010-05-03 12:28:35 +02:00
|
|
|
resizing = false;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-03 12:28:35 +02:00
|
|
|
function resetMenuTabs() {
|
|
|
|
fixedLeft = fixed.offset().left;
|
|
|
|
fixedRight = fixedLeft + fixed.width();
|
|
|
|
active.makeTabVisible();
|
|
|
|
}
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-03 12:28:35 +02:00
|
|
|
$.fn.extend({
|
|
|
|
makeTabVisible : function() {
|
2010-05-03 21:35:54 +02:00
|
|
|
var t = this.eq(0), left, right;
|
|
|
|
if( ! t.length ) return;
|
|
|
|
left = t.offset().left;
|
|
|
|
right = left + t.outerWidth();
|
2010-05-03 12:28:35 +02:00
|
|
|
if( right > fixedRight )
|
2010-05-06 17:40:29 +02:00
|
|
|
fluid.animate({ 'margin-left' : "+=" + (fixedRight - right) + 'px' }, 'fast');
|
2010-05-03 12:28:35 +02:00
|
|
|
else if ( left < fixedLeft )
|
2010-05-06 17:40:29 +02:00
|
|
|
fluid.animate({ 'margin-left' : "-=" + (left - fixedLeft) + 'px' }, 'fast');
|
2010-05-03 12:28:35 +02:00
|
|
|
return t;
|
|
|
|
},
|
|
|
|
isTabVisible : function() {
|
|
|
|
var t = this.eq(0),
|
|
|
|
left = t.offset().left,
|
|
|
|
right = left + t.outerWidth();
|
|
|
|
return ( right <= fixedRight && left >= fixedLeft ) ? true : false;
|
|
|
|
}
|
|
|
|
});
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-03 18:59:51 +02:00
|
|
|
// Find the width of all tabs
|
|
|
|
tabs.each(function(){
|
|
|
|
tabsWidth += $(this).outerWidth(true);
|
|
|
|
});
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-03 18:59:51 +02:00
|
|
|
// Check if we need the tab manager
|
|
|
|
if( tabsWidth <= fixed.width()
|
|
|
|
- fluid.css('padding-left').slice(0,-2)
|
|
|
|
- fluid.css('padding-right').slice(0,-2) )
|
|
|
|
return;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-03 18:59:51 +02:00
|
|
|
// Set up right margin for overflow, unset padding
|
|
|
|
fluid.css({
|
|
|
|
'margin-right' : (-1 * tabsWidth) + 'px',
|
2010-05-06 17:40:29 +02:00
|
|
|
'padding' : 0
|
2010-05-03 18:59:51 +02:00
|
|
|
});
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-03 12:28:35 +02:00
|
|
|
// Build tab navigation
|
|
|
|
arrowLeft = $('<div class="nav-tabs-arrow nav-tabs-arrow-left"><a>«</a></div>');
|
|
|
|
arrowRight = $('<div class="nav-tabs-arrow nav-tabs-arrow-right"><a>»</a></div>');
|
|
|
|
// Attach to the document
|
|
|
|
fixed.wrap('<div class="nav-tabs-nav"/>').parent().prepend( arrowLeft ).append( arrowRight );
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-03 12:28:35 +02:00
|
|
|
// Set the menu tabs
|
|
|
|
resetMenuTabs();
|
|
|
|
// Make sure the tabs reset on resize
|
|
|
|
$(window).resize(function() {
|
|
|
|
if( resizing ) return;
|
|
|
|
resizing = true;
|
2010-05-03 22:26:11 +02:00
|
|
|
setTimeout(function(){
|
2010-05-03 12:28:35 +02:00
|
|
|
resetMenuTabs();
|
|
|
|
resizing = false;
|
|
|
|
}, 1000);
|
|
|
|
});
|
2010-05-03 22:26:11 +02:00
|
|
|
|
|
|
|
// Build arrow functions
|
2010-05-03 12:28:35 +02:00
|
|
|
$.each([{
|
|
|
|
arrow : arrowLeft,
|
|
|
|
next : "next",
|
|
|
|
last : "first",
|
2010-05-06 17:40:29 +02:00
|
|
|
operator : "+="
|
2010-05-03 12:28:35 +02:00
|
|
|
},{
|
|
|
|
arrow : arrowRight,
|
|
|
|
next : "prev",
|
|
|
|
last : "last",
|
2010-05-06 17:40:29 +02:00
|
|
|
operator : "-="
|
2010-05-03 12:28:35 +02:00
|
|
|
}], function(){
|
|
|
|
var that = this;
|
|
|
|
this.arrow.mousedown(function(){
|
|
|
|
var last = tabs[that.last](),
|
|
|
|
fn = function() {
|
|
|
|
if( ! last.isTabVisible() )
|
2010-05-06 17:40:29 +02:00
|
|
|
fluid.animate({ 'margin-left' : that.operator + '90px' }, 300, "linear", fn);
|
2010-05-03 12:28:35 +02:00
|
|
|
};
|
|
|
|
fn();
|
|
|
|
}).mouseup(function(){
|
|
|
|
var tab, next;
|
|
|
|
fluid.stop(true);
|
|
|
|
tab = tabs[that.last]();
|
|
|
|
while( (next = tab[that.next]()) && next.length && ! next.isTabVisible() ) {
|
|
|
|
tab = next;
|
|
|
|
}
|
|
|
|
tab.makeTabVisible();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2010-03-22 20:56:16 +01:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
/**
|
|
|
|
* Set up quick-search input fields' events.
|
|
|
|
*
|
|
|
|
* @param object el The input element.
|
|
|
|
*/
|
|
|
|
setupQuickSearchEventListeners : function(el) {
|
|
|
|
var that = this;
|
2010-05-03 22:26:11 +02:00
|
|
|
$(el).autocomplete( ajaxurl + '?action=menu-quick-search&type=' + el.name,
|
|
|
|
{
|
|
|
|
delay: 500,
|
2010-05-06 19:11:52 +02:00
|
|
|
formatItem: api.formatAutocompleteResponse,
|
|
|
|
formatResult: api.formatAutocompleteResult,
|
2010-05-03 22:26:11 +02:00
|
|
|
minchars: 2,
|
|
|
|
multiple: false
|
2010-04-27 03:05:58 +02:00
|
|
|
}
|
|
|
|
).bind('blur', function(e) {
|
2010-05-06 19:11:52 +02:00
|
|
|
var changedData = api.autoCompleteData[this.value],
|
2010-04-27 03:05:58 +02:00
|
|
|
inputEl = this;
|
|
|
|
if ( changedData ) {
|
2010-05-03 22:26:11 +02:00
|
|
|
$.post(
|
2010-04-27 03:05:58 +02:00
|
|
|
ajaxurl + '?action=menu-quick-search&type=get-post-item&response-format=markup',
|
|
|
|
changedData,
|
|
|
|
function(r) {
|
2010-05-03 22:26:11 +02:00
|
|
|
that.processQuickSearchQueryResponse.call(that, r, changedData);
|
2010-05-06 19:11:52 +02:00
|
|
|
api.autoCompleteData[inputEl.value] = false;
|
2010-04-27 03:05:58 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2010-03-22 20:56:16 +01:00
|
|
|
});
|
2010-04-27 03:05:58 +02:00
|
|
|
},
|
2010-03-22 20:56:16 +01:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
eventOnClickEditLink : function(clickedEl) {
|
|
|
|
var activeEdit,
|
|
|
|
matchedSection = /#(.*)$/.exec(clickedEl.href);
|
|
|
|
if ( matchedSection && matchedSection[1] ) {
|
2010-04-29 05:43:11 +02:00
|
|
|
activeEdit = $('#'+matchedSection[1]);
|
|
|
|
if( 0 != activeEdit.length ) {
|
|
|
|
if( activeEdit.hasClass('menu-item-edit-inactive') ) {
|
|
|
|
activeEdit.slideDown('fast')
|
|
|
|
.siblings('dl').andSelf()
|
|
|
|
.removeClass('menu-item-edit-inactive')
|
|
|
|
.addClass('menu-item-edit-active');
|
|
|
|
} else {
|
|
|
|
activeEdit.slideUp('fast')
|
|
|
|
.siblings('dl').andSelf()
|
|
|
|
.removeClass('menu-item-edit-active')
|
|
|
|
.addClass('menu-item-edit-inactive');
|
2010-04-27 03:05:58 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-03-22 20:56:16 +01:00
|
|
|
},
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-04-29 05:43:11 +02:00
|
|
|
eventOnClickCloseLink : function(clickedEl) {
|
|
|
|
$(clickedEl).closest('.menu-item-settings').siblings('dl').find('.item-edit').click();
|
|
|
|
return false;
|
|
|
|
},
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
eventOnClickMenuDelete : function(clickedEl) {
|
|
|
|
// Delete warning AYS
|
2010-05-04 12:01:15 +02:00
|
|
|
if ( confirm( navMenuL10n.warnDeleteMenu ) )
|
2010-04-27 03:05:58 +02:00
|
|
|
return true;
|
2010-05-04 12:01:15 +02:00
|
|
|
else
|
2010-04-27 03:05:58 +02:00
|
|
|
return false;
|
|
|
|
},
|
2010-03-17 17:13:16 +01:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
eventOnClickMenuItemDelete : function(clickedEl) {
|
|
|
|
var itemID,
|
|
|
|
matchedSection,
|
|
|
|
that = this;
|
|
|
|
|
|
|
|
// Delete warning AYS
|
|
|
|
if ( confirm( navMenuL10n.warnDeleteMenuItem ) ) {
|
|
|
|
matchedSection = /_wpnonce=([a-zA-Z0-9]*)$/.exec(clickedEl.href);
|
|
|
|
if ( matchedSection && matchedSection[1] ) {
|
2010-05-03 22:26:11 +02:00
|
|
|
itemID = parseInt(clickedEl.id.replace('delete-', ''), 10);
|
2010-04-27 03:05:58 +02:00
|
|
|
$.post(
|
|
|
|
ajaxurl,
|
|
|
|
{
|
|
|
|
action:'delete-menu-item',
|
|
|
|
'menu-item':itemID,
|
|
|
|
'_wpnonce':matchedSection[1]
|
|
|
|
},
|
|
|
|
function (resp) {
|
|
|
|
if ( '1' == resp )
|
|
|
|
that.removeMenuItem(document.getElementById('menu-item-' + itemID));
|
|
|
|
}
|
|
|
|
);
|
2010-05-03 22:26:11 +02:00
|
|
|
return false;
|
2010-04-27 03:05:58 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-22 20:56:16 +01:00
|
|
|
},
|
2010-04-27 03:05:58 +02:00
|
|
|
|
2010-03-22 20:56:16 +01:00
|
|
|
/**
|
2010-04-27 03:05:58 +02:00
|
|
|
* Process the quick search response into a search result
|
2010-05-03 22:26:11 +02:00
|
|
|
*
|
2010-04-27 03:05:58 +02:00
|
|
|
* @param string resp The server response to the query.
|
|
|
|
* @param object req The request arguments.
|
2010-03-22 20:56:16 +01:00
|
|
|
*/
|
2010-04-27 03:05:58 +02:00
|
|
|
processQuickSearchQueryResponse : function(resp, req) {
|
|
|
|
if ( ! req )
|
|
|
|
req = {};
|
|
|
|
var wrap = document.createElement('ul'),
|
|
|
|
form = document.getElementById('nav-menu-meta'),
|
|
|
|
i,
|
|
|
|
items,
|
|
|
|
matched,
|
2010-04-28 22:44:08 +02:00
|
|
|
message,
|
2010-04-27 03:05:58 +02:00
|
|
|
newID,
|
|
|
|
pattern = new RegExp('menu-item\\[(\[^\\]\]*)'),
|
|
|
|
resultList;
|
|
|
|
|
|
|
|
// make a unique DB ID number
|
|
|
|
matched = pattern.exec(resp);
|
|
|
|
if ( matched && matched[1] ) {
|
|
|
|
newID = matched[1];
|
|
|
|
while( form.elements['menu-item[' + newID + '][menu-item-type]'] ) {
|
|
|
|
newID--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newID != matched[1] ) {
|
|
|
|
resp = resp.replace(new RegExp('menu-item\\[' + matched[1] + '\\]', 'g'), 'menu-item[' + newID + ']');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wrap.innerHTML = resp;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
items = wrap.getElementsByTagName('li');
|
2010-03-22 20:56:16 +01:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
if ( items[0] && req.object_type ) {
|
|
|
|
resultList = document.getElementById(req.object_type + '-search-checklist');
|
|
|
|
if ( resultList ) {
|
|
|
|
resultList.appendChild(items[0]);
|
|
|
|
}
|
|
|
|
} else if ( req.type ) {
|
2010-04-28 22:44:08 +02:00
|
|
|
matched = /quick-search-(posttype|taxonomy)-([a-zA-Z_-]*)/.exec(req.type);
|
|
|
|
if ( matched && matched[2] ) {
|
|
|
|
resultList = document.getElementById(matched[2] + '-search-checklist');
|
2010-04-27 03:05:58 +02:00
|
|
|
if ( resultList ) {
|
|
|
|
i = items.length;
|
2010-04-28 22:44:08 +02:00
|
|
|
if ( ! i ) {
|
|
|
|
message = document.createElement('li');
|
|
|
|
message.appendChild(document.createTextNode(navMenuL10n.noResultsFound));
|
|
|
|
resultList.appendChild(message);
|
|
|
|
}
|
2010-04-27 03:05:58 +02:00
|
|
|
while( i-- ) {
|
|
|
|
resultList.appendChild(items[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2010-03-22 20:56:16 +01:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
removeMenuItem : function(el) {
|
2010-05-02 21:09:10 +02:00
|
|
|
el = $(el)
|
2010-05-05 23:06:43 +02:00
|
|
|
var children = el.childMenuItems(),
|
|
|
|
that = this;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
el.addClass('deleting').fadeOut( 350 , function() {
|
|
|
|
el.remove();
|
|
|
|
children.shiftDepthClass(-1).updateParentMenuItemDBId();
|
2010-05-06 19:11:52 +02:00
|
|
|
api.recalculateMenuItemPositions();
|
2010-05-04 12:01:15 +02:00
|
|
|
that.checkForEmptyMenu();
|
|
|
|
});
|
|
|
|
},
|
2010-05-05 22:37:32 +02:00
|
|
|
|
2010-05-04 12:01:15 +02:00
|
|
|
checkForEmptyMenu : function() {
|
2010-05-06 19:11:52 +02:00
|
|
|
if( api.menuList.children().length ) return;
|
|
|
|
api.menuList.height(80).one('sortstop', function(){
|
2010-05-04 12:01:15 +02:00
|
|
|
$(this).height('auto');
|
2010-05-02 21:09:10 +02:00
|
|
|
});
|
2010-05-06 19:11:52 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
formatAutocompleteResponse : function( resultRow, pos, total, queryTerm ) {
|
|
|
|
if ( resultRow && resultRow[0] ) {
|
|
|
|
var data = $.parseJSON(resultRow[0]);
|
|
|
|
if ( data.post_title ) {
|
|
|
|
if ( data.ID && data.post_type )
|
|
|
|
api.autoCompleteData[data.post_title] = {ID: data.ID, object_type: data.post_type};
|
|
|
|
return data.post_title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
formatAutocompleteResult : function( resultRow, pos, total, queryTerm ) {
|
|
|
|
if ( resultRow && resultRow[0] ) {
|
|
|
|
var data = $.parseJSON(resultRow[0]);
|
|
|
|
if ( data.post_title )
|
|
|
|
return data.post_title;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getListDataFromID : function(menuItemID, parentEl) {
|
|
|
|
if ( ! menuItemID )
|
|
|
|
return false;
|
|
|
|
parentEl = parentEl || document;
|
|
|
|
var fields = [
|
|
|
|
'menu-item-db-id',
|
|
|
|
'menu-item-object-id',
|
|
|
|
'menu-item-object',
|
|
|
|
'menu-item-parent-id',
|
|
|
|
'menu-item-position',
|
|
|
|
'menu-item-type',
|
|
|
|
'menu-item-append',
|
|
|
|
'menu-item-title',
|
|
|
|
'menu-item-url',
|
|
|
|
'menu-item-description',
|
|
|
|
'menu-item-attr-title',
|
|
|
|
'menu-item-target',
|
|
|
|
'menu-item-classes',
|
|
|
|
'menu-item-xfn'
|
|
|
|
],
|
|
|
|
itemData = {},
|
|
|
|
inputs = parentEl.getElementsByTagName('input'),
|
|
|
|
i = inputs.length,
|
|
|
|
j;
|
|
|
|
|
|
|
|
while ( i-- ) {
|
|
|
|
j = fields.length;
|
|
|
|
while ( j-- ) {
|
|
|
|
if (
|
|
|
|
inputs[i] &&
|
|
|
|
inputs[i].name &&
|
|
|
|
'menu-item[' + menuItemID + '][' + fields[j] + ']' == inputs[i].name
|
|
|
|
) {
|
|
|
|
itemData[fields[j]] = inputs[i].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemData;
|
|
|
|
},
|
|
|
|
|
|
|
|
recalculateMenuItemPositions : function() {
|
|
|
|
api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } );
|
|
|
|
},
|
|
|
|
|
|
|
|
depthToPx : function(depth) {
|
|
|
|
return depth * api.options.menuItemDepthPerLevel;
|
|
|
|
},
|
|
|
|
|
|
|
|
pxToDepth : function(px) {
|
|
|
|
return Math.floor(px / api.options.menuItemDepthPerLevel);
|
2010-03-17 17:13:16 +01:00
|
|
|
}
|
2010-04-27 03:05:58 +02:00
|
|
|
|
2010-05-06 19:11:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function(){ wpNavMenu.init(); });
|
2010-04-27 03:05:58 +02:00
|
|
|
|
2010-05-06 19:11:52 +02:00
|
|
|
})(jQuery);
|