2010-03-17 12:13:16 -04:00
|
|
|
/**
|
2010-03-22 15:56:16 -04:00
|
|
|
* WordPress Administration Navigation Menu
|
2010-03-17 12:13:16 -04:00
|
|
|
* Interface JS functions
|
|
|
|
*
|
2010-03-22 15:56:16 -04:00
|
|
|
* @version 2.0.0
|
2010-03-17 12:13:16 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
2010-05-06 13:11:52 -04:00
|
|
|
var wpNavMenu;
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-06 13:11:52 -04:00
|
|
|
(function($) {
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-06 13:11:52 -04:00
|
|
|
var api = wpNavMenu = {
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-06 13:11:52 -04:00
|
|
|
options : {
|
|
|
|
menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
|
|
|
|
globalMaxDepth : 11
|
|
|
|
},
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-06 13:11:52 -04:00
|
|
|
menuList : undefined, // Set in init.
|
|
|
|
targetList : undefined, // Set in init.
|
2010-05-19 05:56:02 -04:00
|
|
|
menusChanged : false,
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-03-22 15:56:16 -04:00
|
|
|
// Functions that run on init.
|
|
|
|
init : function() {
|
2010-05-06 13:11:52 -04:00
|
|
|
api.menuList = $('#menu-to-edit');
|
|
|
|
api.targetList = api.menuList;
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-05 17:23:53 -04:00
|
|
|
this.jQueryExtensions();
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
this.attachMenuEditListeners();
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-05 16:29:50 -04:00
|
|
|
this.setupInputWithDefaultTitle();
|
|
|
|
this.attachAddMenuItemListeners();
|
|
|
|
this.attachQuickSearchListeners();
|
2010-05-18 11:16:58 -04:00
|
|
|
this.attachThemeLocationsListeners();
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
this.attachTabsPanelListeners();
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-04 06:01:15 -04:00
|
|
|
this.attachHomeLinkListener();
|
|
|
|
|
2010-05-19 05:56:02 -04:00
|
|
|
this.attachUnsavedChangesListener();
|
|
|
|
|
2010-05-06 13:11:52 -04:00
|
|
|
if( api.menuList.length ) // If no menu, we're in the + tab.
|
2010-05-02 15:09:10 -04:00
|
|
|
this.initSortables();
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-04-28 23:43:11 -04:00
|
|
|
this.initToggles();
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-03 06:28:35 -04:00
|
|
|
this.initTabManager();
|
2010-04-28 23:43:11 -04:00
|
|
|
},
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-05 17:23:53 -04:00
|
|
|
jQueryExtensions : function() {
|
|
|
|
// jQuery extensions
|
|
|
|
$.fn.extend({
|
|
|
|
menuItemDepth : function() {
|
2010-05-21 19:35:37 -04:00
|
|
|
var margin = this.eq(0).css('margin-left');
|
|
|
|
return api.pxToDepth( margin && -1 != margin.indexOf('px') ? margin.slice(0, -2) : 0 );
|
2010-05-05 17:23:53 -04: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(){
|
2010-05-24 15:50:20 -04:00
|
|
|
var t = $(this),
|
|
|
|
listItemDBIDMatch = re.exec( t.attr('name') ),
|
2010-05-05 17:23:53 -04:00
|
|
|
listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
|
2010-05-24 15:50:20 -04:00
|
|
|
menuItems[listItemDBID] = t.closest('li').getItemData( 'add-menu-item', listItemDBID );
|
2010-05-05 17:23:53 -04:00
|
|
|
});
|
|
|
|
// Add the items
|
|
|
|
api.addItemToMenu(menuItems, processMethod, function(){
|
|
|
|
// Deselect the items and hide the ajax spinner
|
2010-05-06 10:09:10 -04:00
|
|
|
checkboxes.removeAttr('checked');
|
2010-05-05 17:23:53 -04:00
|
|
|
t.find('img.waiting').hide();
|
|
|
|
});
|
|
|
|
});
|
2010-05-24 15:50:20 -04:00
|
|
|
},
|
|
|
|
getItemData : function( itemType, id ) {
|
|
|
|
itemType = itemType || 'menu-item';
|
|
|
|
|
|
|
|
var itemData = {}, i,
|
|
|
|
fields = [
|
|
|
|
'menu-item-db-id',
|
|
|
|
'menu-item-object-id',
|
|
|
|
'menu-item-object',
|
|
|
|
'menu-item-parent-id',
|
|
|
|
'menu-item-position',
|
|
|
|
'menu-item-type',
|
|
|
|
'menu-item-title',
|
|
|
|
'menu-item-url',
|
|
|
|
'menu-item-description',
|
|
|
|
'menu-item-attr-title',
|
|
|
|
'menu-item-target',
|
|
|
|
'menu-item-classes',
|
|
|
|
'menu-item-xfn'
|
|
|
|
];
|
|
|
|
|
|
|
|
if( !id && itemType == 'menu-item' ) {
|
|
|
|
id = this.find('.menu-item-data-db-id').val();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !id ) return itemData;
|
|
|
|
|
|
|
|
this.find('input').each(function() {
|
|
|
|
var field;
|
|
|
|
i = fields.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
if( itemType == 'menu-item' )
|
|
|
|
field = fields[i] + '[' + id + ']';
|
|
|
|
else if( itemType == 'add-menu-item' )
|
|
|
|
field = 'menu-item[' + id + '][' + fields[i] + ']';
|
|
|
|
|
|
|
|
if (
|
|
|
|
this.name &&
|
|
|
|
field == this.name
|
|
|
|
) {
|
|
|
|
itemData[fields[i]] = this.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return itemData;
|
|
|
|
},
|
|
|
|
setItemData : function( itemData, itemType, id ) { // Can take a type, such as 'menu-item', or an id.
|
|
|
|
itemType = itemType || 'menu-item';
|
|
|
|
|
|
|
|
if( !id && itemType == 'menu-item' ) {
|
|
|
|
id = $('.menu-item-data-db-id', this).val();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !id ) return this;
|
|
|
|
|
|
|
|
this.find('input').each(function() {
|
|
|
|
var t = $(this), field;
|
|
|
|
$.each( itemData, function( attr, val ) {
|
|
|
|
if( itemType == 'menu-item' )
|
|
|
|
field = attr + '[' + id + ']';
|
|
|
|
else if( itemType == 'add-menu-item' )
|
|
|
|
field = 'menu-item[' + id + '][' + attr + ']';
|
|
|
|
|
|
|
|
if ( field == t.attr('name') ) {
|
|
|
|
t.val( val );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return this;
|
2010-05-06 11:40:29 -04:00
|
|
|
}
|
2010-05-05 17:23:53 -04:00
|
|
|
});
|
|
|
|
},
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-04-28 23:43:11 -04:00
|
|
|
initToggles : function() {
|
|
|
|
// init postboxes
|
2010-04-26 21:05:58 -04:00
|
|
|
postboxes.add_postbox_toggles('nav-menus');
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-04-28 23:43:11 -04: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 13:11:52 -04:00
|
|
|
api.menuList.hideAdvancedMenuItemFields();
|
2010-04-28 23:43:11 -04:00
|
|
|
},
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
initSortables : function() {
|
2010-05-10 00:51:57 -04:00
|
|
|
var currentDepth = 0, originalDepth, minDepth, maxDepth,
|
|
|
|
prev, next, prevBottom, nextThreshold, helperHeight, transport,
|
|
|
|
menuLeft = api.menuList.offset().left;
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-06 13:11:52 -04:00
|
|
|
api.menuList.sortable({
|
2010-05-04 03:24:49 -04:00
|
|
|
handle: '.menu-item-handle',
|
2010-05-02 15:09:10 -04:00
|
|
|
placeholder: 'sortable-placeholder',
|
|
|
|
start: function(e, ui) {
|
2010-05-10 00:51:57 -04:00
|
|
|
var height, width, parent, children, maxChildDepth, tempHolder;
|
2010-05-04 03:24:49 -04:00
|
|
|
|
|
|
|
transport = ui.item.children('.menu-item-transport');
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-04 03:24:49 -04:00
|
|
|
// Set depths. currentDepth must be set before children are located.
|
2010-05-10 00:51:57 -04:00
|
|
|
originalDepth = ui.item.menuItemDepth();
|
2010-05-02 15:09:10 -04:00
|
|
|
updateCurrentDepth(ui, originalDepth);
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-06 10:09:10 -04: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 15:09:10 -04: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 03:24:49 -04:00
|
|
|
height += ui.helper.outerHeight();
|
2010-05-10 00:51:57 -04:00
|
|
|
helperHeight = height;
|
2010-05-02 15:09:10 -04:00
|
|
|
height -= 2; // Subtract 2 for borders
|
|
|
|
ui.placeholder.height(height);
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
// Update the width of the placeholder to match the moving item.
|
|
|
|
maxChildDepth = originalDepth;
|
2010-05-06 10:09:10 -04:00
|
|
|
children.each(function(){
|
|
|
|
var depth = $(this).menuItemDepth();
|
|
|
|
maxChildDepth = (depth > maxChildDepth) ? depth : maxChildDepth;
|
|
|
|
});
|
2010-05-04 03:24:49 -04:00
|
|
|
width = ui.helper.find('.menu-item-handle').outerWidth(); // Get original width
|
2010-05-06 13:11:52 -04:00
|
|
|
width += api.depthToPx(maxChildDepth - originalDepth); // Account for children
|
2010-05-02 15:09:10 -04:00
|
|
|
width -= 2; // Subtract 2 for borders
|
|
|
|
ui.placeholder.width(width);
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-10 00:51:57 -04:00
|
|
|
// Update the list of menu items.
|
|
|
|
tempHolder = ui.placeholder.next();
|
|
|
|
tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder
|
|
|
|
ui.placeholder.detach(); // detach or jQuery UI will think the placeholder is a menu item
|
|
|
|
$(this).sortable( "refresh" ); // The children aren't sortable. We should let jQ UI know.
|
|
|
|
ui.item.after( ui.placeholder ); // reattach the placeholder.
|
|
|
|
tempHolder.css('margin-top', 0); // reset the margin
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-10 00:51:57 -04:00
|
|
|
// Now that the element is complete, we can update...
|
|
|
|
updateSharedVars(ui);
|
2010-05-02 15:09:10 -04:00
|
|
|
},
|
|
|
|
stop: function(e, ui) {
|
|
|
|
var children, depthChange = currentDepth - originalDepth;
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
// Return child elements to the list
|
2010-05-04 03:24:49 -04:00
|
|
|
children = transport.children().insertAfter(ui.item);
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-06 10:09:10 -04:00
|
|
|
// Update depth classes
|
|
|
|
if( depthChange != 0 ) {
|
|
|
|
ui.item.updateDepthClass( currentDepth );
|
|
|
|
children.shiftDepthClass( depthChange );
|
2010-05-19 05:56:02 -04:00
|
|
|
api.registerChange();
|
2010-05-02 15:09:10 -04:00
|
|
|
}
|
2010-05-06 10:09:10 -04:00
|
|
|
// Update the item data.
|
|
|
|
ui.item.updateParentMenuItemDBId();
|
2010-05-20 15:33:57 -04:00
|
|
|
|
|
|
|
// address sortable's incorrectly-calculated top in opera
|
|
|
|
ui.item[0].style.top = 0;
|
|
|
|
|
2010-05-02 15:09:10 -04: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-10 00:51:57 -04:00
|
|
|
(prev.length) ? prev.after( ui.placeholder ) : api.menuList.prepend( ui.placeholder );
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-10 00:51:57 -04:00
|
|
|
updateSharedVars(ui);
|
2010-05-02 15:09:10 -04:00
|
|
|
},
|
|
|
|
sort: function(e, ui) {
|
2010-05-08 17:56:53 -04:00
|
|
|
var offset = ui.helper.offset(),
|
|
|
|
depth = api.pxToDepth( offset.left - menuLeft );
|
2010-05-02 15:09:10 -04:00
|
|
|
// Check and correct if depth is not within range.
|
2010-05-08 17:56:53 -04:00
|
|
|
// Also, if the dragged element is dragged upwards over
|
|
|
|
// an item, shift the placeholder to a child position.
|
|
|
|
if ( depth > maxDepth || offset.top < prevBottom ) depth = maxDepth;
|
|
|
|
else if ( depth < minDepth ) depth = minDepth;
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
if( depth != currentDepth )
|
|
|
|
updateCurrentDepth(ui, depth);
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-10 00:51:57 -04:00
|
|
|
// If we overlap the next element, manually shift downwards
|
|
|
|
if( nextThreshold && offset.top + helperHeight > nextThreshold ) {
|
|
|
|
next.after( ui.placeholder );
|
|
|
|
updateSharedVars( ui );
|
|
|
|
$(this).sortable( "refreshPositions" );
|
|
|
|
}
|
2010-05-19 05:56:02 -04:00
|
|
|
},
|
|
|
|
update: function(e, ui) {
|
|
|
|
api.registerChange();
|
2010-05-06 13:11:52 -04:00
|
|
|
}
|
2010-04-28 23:43:11 -04:00
|
|
|
});
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-10 00:51:57 -04:00
|
|
|
function updateSharedVars(ui) {
|
|
|
|
var depth;
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-10 00:51:57 -04:00
|
|
|
prev = ui.placeholder.prev();
|
|
|
|
next = ui.placeholder.next();
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
// Make sure we don't select the moving item.
|
2010-05-03 16:26:11 -04:00
|
|
|
if( prev[0] == ui.item[0] ) prev = prev.prev();
|
2010-05-02 15:09:10 -04:00
|
|
|
if( next[0] == ui.item[0] ) next = next.next();
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-08 17:56:53 -04:00
|
|
|
prevBottom = (prev.length) ? prev.offset().top + prev.height() : 0;
|
2010-05-10 00:51:57 -04:00
|
|
|
nextThreshold = (next.length) ? next.offset().top + next.height() / 3 : 0;
|
2010-05-02 15:09:10 -04:00
|
|
|
minDepth = (next.length) ? next.menuItemDepth() : 0;
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
if( prev.length )
|
2010-05-06 13:11:52 -04:00
|
|
|
maxDepth = ( (depth = prev.menuItemDepth() + 1) > api.options.globalMaxDepth ) ? api.options.globalMaxDepth : depth;
|
2010-05-02 15:09:10 -04:00
|
|
|
else
|
|
|
|
maxDepth = 0;
|
|
|
|
}
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
function updateCurrentDepth(ui, depth) {
|
|
|
|
ui.placeholder.updateDepthClass( depth, currentDepth );
|
|
|
|
currentDepth = depth;
|
|
|
|
}
|
2010-04-26 21:05:58 -04:00
|
|
|
},
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-04-26 21:05:58 -04: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);
|
2010-05-13 21:32:48 -04:00
|
|
|
} else if ( -1 != e.target.className.indexOf('menu-save') ) {
|
|
|
|
return that.eventOnClickMenuSave(e.target);
|
2010-04-26 21:05:58 -04:00
|
|
|
} 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-05-24 15:50:20 -04:00
|
|
|
} else if ( -1 != e.target.className.indexOf('item-cancel') ) {
|
|
|
|
return that.eventOnClickCancelLink(e.target);
|
2010-04-26 21:05:58 -04:00
|
|
|
}
|
2010-03-22 15:56:16 -04:00
|
|
|
}
|
|
|
|
});
|
2010-04-26 21:05:58 -04:00
|
|
|
},
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-02 15:09:10 -04: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 16:26:11 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
$('.' + name).each( function(){
|
2010-04-28 23:43:11 -04:00
|
|
|
var $t = $(this), title = $t.attr('title'), val = $t.val();
|
2010-05-02 15:09:10 -04:00
|
|
|
$t.data( name, title );
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
if( '' == val ) $t.val( title );
|
2010-04-28 23:43:11 -04:00
|
|
|
else if ( title == val ) return;
|
2010-05-02 15:09:10 -04:00
|
|
|
else $t.removeClass( name );
|
|
|
|
}).focus( function(){
|
2010-04-28 23:43:11 -04:00
|
|
|
var $t = $(this);
|
2010-05-02 15:09:10 -04:00
|
|
|
if( $t.val() == $t.data(name) )
|
|
|
|
$t.val('').removeClass( name );
|
|
|
|
}).blur( function(){
|
2010-04-28 23:43:11 -04:00
|
|
|
var $t = $(this);
|
|
|
|
if( '' == $t.val() )
|
2010-05-05 16:29:50 -04:00
|
|
|
$t.addClass( name ).val( $t.data(name) );
|
2010-04-28 23:43:11 -04:00
|
|
|
});
|
2010-05-02 15:09:10 -04:00
|
|
|
},
|
|
|
|
|
2010-05-05 16:29:50 -04:00
|
|
|
attachAddMenuItemListeners : function() {
|
2010-05-18 11:16:58 -04:00
|
|
|
var form = $('#nav-menu-meta');
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-05 16:29:50 -04:00
|
|
|
form.find('.add-to-menu input').click(function(){
|
2010-05-19 05:56:02 -04:00
|
|
|
api.registerChange();
|
2010-05-05 16:29:50 -04:00
|
|
|
$(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 16:37:32 -04:00
|
|
|
});
|
2010-05-18 11:16:58 -04:00
|
|
|
},
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-18 11:16:58 -04:00
|
|
|
attachThemeLocationsListeners : function() {
|
2010-05-20 18:43:14 -04:00
|
|
|
var loc = $('#nav-menu-theme-locations'), params = {};
|
|
|
|
params['action'] = 'menu-locations-save';
|
|
|
|
params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val();
|
2010-05-17 19:58:56 -04:00
|
|
|
loc.find('input[type=submit]').click(function() {
|
2010-05-20 18:43:14 -04:00
|
|
|
loc.find('select').each(function() {
|
|
|
|
params[this.name] = $(this).val();
|
|
|
|
});
|
2010-05-17 19:58:56 -04:00
|
|
|
loc.find('.waiting').show();
|
2010-05-18 11:16:58 -04:00
|
|
|
$.post( ajaxurl, params, function(r) {
|
2010-05-17 19:58:56 -04:00
|
|
|
loc.find('.waiting').hide();
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2010-05-05 16:29:50 -04:00
|
|
|
},
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-05 16:29:50 -04:00
|
|
|
attachQuickSearchListeners : function() {
|
2010-05-16 01:39:53 -04:00
|
|
|
var searchTimer;
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
$('.quick-search').keypress(function(e){
|
|
|
|
var t = $(this);
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
if( 13 == e.which ) {
|
|
|
|
api.updateQuickSearchResults( t );
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
if( searchTimer ) clearTimeout(searchTimer);
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
searchTimer = setTimeout(function(){
|
|
|
|
api.updateQuickSearchResults( t );
|
|
|
|
}, 400);
|
|
|
|
}).attr('autocomplete','off');
|
2010-05-04 04:31:40 -04:00
|
|
|
},
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
updateQuickSearchResults : function(input) {
|
|
|
|
var panel, params,
|
|
|
|
minSearchLength = 2,
|
|
|
|
q = input.val();
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
if( q.length < minSearchLength ) return;
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
panel = input.parents('.tabs-panel');
|
2010-05-04 04:31:40 -04:00
|
|
|
params = {
|
|
|
|
'action': 'menu-quick-search',
|
|
|
|
'response-format': 'markup',
|
2010-05-16 01:39:53 -04:00
|
|
|
'menu': $('#menu').val(),
|
|
|
|
'menu-settings-column-nonce': $('#menu-settings-column-nonce').val(),
|
2010-05-04 04:31:40 -04:00
|
|
|
'q': q,
|
2010-05-16 01:39:53 -04:00
|
|
|
'type': input.attr('name')
|
2010-05-04 04:31:40 -04:00
|
|
|
};
|
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
$('img.waiting', panel).show();
|
|
|
|
|
2010-05-04 04:31:40 -04:00
|
|
|
$.post( ajaxurl, params, function(menuMarkup) {
|
2010-05-16 01:39:53 -04:00
|
|
|
api.processQuickSearchQueryResponse(menuMarkup, params, panel);
|
2010-05-04 04:31:40 -04:00
|
|
|
});
|
|
|
|
},
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-05 16:29:50 -04:00
|
|
|
addCustomLink : function( processMethod ) {
|
|
|
|
var url = $('#custom-menu-item-url').val(),
|
|
|
|
label = $('#custom-menu-item-name').val();
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-05 16:37:32 -04:00
|
|
|
processMethod = processMethod || api.addMenuItemToBottom;
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-04 04:31:40 -04:00
|
|
|
if ( '' == url || 'http://' == url )
|
|
|
|
return false;
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-04 04:31:40 -04:00
|
|
|
// Show the ajax spinner
|
|
|
|
$('.customlinkdiv img.waiting').show();
|
2010-05-05 16:29:50 -04: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-19 04:44:28 -04:00
|
|
|
|
2010-05-05 16:29:50 -04:00
|
|
|
addLinkToMenu : function(url, label, processMethod, callback) {
|
|
|
|
processMethod = processMethod || api.addMenuItemToBottom;
|
|
|
|
callback = callback || function(){};
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-05 16:29:50 -04:00
|
|
|
api.addItemToMenu({
|
|
|
|
'-1': {
|
|
|
|
'menu-item-type': 'custom',
|
|
|
|
'menu-item-url': url,
|
|
|
|
'menu-item-title': label
|
|
|
|
}
|
|
|
|
}, processMethod, callback);
|
|
|
|
},
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-05 16:29:50 -04:00
|
|
|
addItemToMenu : function(menuItem, processMethod, callback) {
|
|
|
|
var menu = $('#menu').val(),
|
|
|
|
nonce = $('#menu-settings-column-nonce').val();
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-05 16:29:50 -04:00
|
|
|
processMethod = processMethod || function(){};
|
|
|
|
callback = callback || function(){};
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-04 04:31:40 -04:00
|
|
|
params = {
|
|
|
|
'action': 'add-menu-item',
|
|
|
|
'menu': menu,
|
|
|
|
'menu-settings-column-nonce': nonce,
|
2010-05-06 11:40:29 -04:00
|
|
|
'menu-item': menuItem
|
2010-05-04 04:31:40 -04:00
|
|
|
};
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-04 04:31:40 -04:00
|
|
|
$.post( ajaxurl, params, function(menuMarkup) {
|
2010-05-05 16:29:50 -04:00
|
|
|
processMethod(menuMarkup, params);
|
|
|
|
callback();
|
2010-05-04 06:01:15 -04:00
|
|
|
});
|
|
|
|
},
|
2010-05-05 16:29:50 -04: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 13:11:52 -04:00
|
|
|
$(menuMarkup).hideAdvancedMenuItemFields().appendTo( api.targetList );
|
2010-05-05 16:29:50 -04:00
|
|
|
},
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-05 16:29:50 -04:00
|
|
|
addMenuItemToTop : function( menuMarkup, req ) {
|
2010-05-06 13:11:52 -04:00
|
|
|
$(menuMarkup).hideAdvancedMenuItemFields().prependTo( api.targetList );
|
2010-05-04 06:01:15 -04:00
|
|
|
},
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-04 06:01:15 -04:00
|
|
|
attachHomeLinkListener : function() {
|
|
|
|
$('.add-home-link', '.customlinkdiv').click(function(e) {
|
2010-05-13 21:32:48 -04:00
|
|
|
api.addLinkToMenu( navMenuL10n.homeurl, navMenuL10n.home, api.addMenuItemToTop );
|
2010-05-04 06:01:15 -04:00
|
|
|
return false;
|
2010-05-02 17:05:55 -04:00
|
|
|
});
|
2010-04-26 21:05:58 -04:00
|
|
|
},
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-05-19 05:56:02 -04:00
|
|
|
attachUnsavedChangesListener : function() {
|
|
|
|
$('#menu-management input, #menu-management select, #menu-management, #menu-management textarea').change(function(){
|
|
|
|
api.registerChange();
|
|
|
|
});
|
|
|
|
window.onbeforeunload = function(){
|
|
|
|
if ( api.menusChanged )
|
|
|
|
return navMenuL10n.saveAlert;
|
|
|
|
};
|
2010-05-24 15:50:20 -04:00
|
|
|
$('input.menu-save').click(function(){
|
2010-05-19 05:56:02 -04:00
|
|
|
window.onbeforeunload = null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
registerChange : function() {
|
|
|
|
api.menusChanged = true;
|
|
|
|
},
|
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
attachTabsPanelListeners : function() {
|
|
|
|
$('#menu-settings-column').bind('click', function(e) {
|
2010-05-24 05:23:56 -04:00
|
|
|
var selectAreaMatch, panelId, wrapper, items,
|
2010-05-16 01:39:53 -04:00
|
|
|
target = $(e.target);
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
if ( target.hasClass('nav-tab-link') ) {
|
|
|
|
panelId = /#(.*)$/.exec(e.target.href);
|
|
|
|
if ( panelId && panelId[1] )
|
|
|
|
panelId = panelId[1]
|
|
|
|
else
|
|
|
|
return false;
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
wrapper = target.parents('.inside').first();
|
2010-04-28 14:30:32 -04:00
|
|
|
|
|
|
|
// upon changing tabs, we want to uncheck all checkboxes
|
2010-05-16 01:39:53 -04:00
|
|
|
$('input', wrapper).removeAttr('checked');
|
2010-05-19 04:44:28 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
$('.tabs-panel-active', wrapper).removeClass('tabs-panel-active').addClass('tabs-panel-inactive');
|
|
|
|
$('#' + panelId, wrapper).removeClass('tabs-panel-inactive').addClass('tabs-panel-active');
|
2010-04-26 21:05:58 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
$('.tabs', wrapper).removeClass('tabs');
|
|
|
|
target.parent().addClass('tabs');
|
2010-04-26 21:05:58 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
// select the search bar
|
|
|
|
$('.quick-search', wrapper).focus();
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
return false;
|
2010-05-16 01:39:53 -04:00
|
|
|
} else if ( target.hasClass('select-all') ) {
|
2010-05-06 10:09:10 -04:00
|
|
|
selectAreaMatch = /#(.*)$/.exec(e.target.href);
|
2010-04-26 21:05:58 -04:00
|
|
|
if ( selectAreaMatch && selectAreaMatch[1] ) {
|
2010-05-06 10:09:10 -04:00
|
|
|
items = $('#' + selectAreaMatch[1] + ' .tabs-panel-active .menu-item-title input');
|
|
|
|
if( items.length === items.filter(':checked').length )
|
|
|
|
items.removeAttr('checked');
|
2010-05-04 04:54:35 -04:00
|
|
|
else
|
2010-05-06 10:09:10 -04:00
|
|
|
items.attr('checked', 'checked');
|
2010-04-26 21:05:58 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-03-22 15:56:16 -04:00
|
|
|
});
|
2010-04-26 21:05:58 -04:00
|
|
|
},
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-03 06:28:35 -04: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 11:40:29 -04:00
|
|
|
arrowLeft, arrowRight,
|
2010-05-03 06:28:35 -04:00
|
|
|
resizing = false;
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-03 06:28:35 -04:00
|
|
|
function resetMenuTabs() {
|
|
|
|
fixedLeft = fixed.offset().left;
|
|
|
|
fixedRight = fixedLeft + fixed.width();
|
|
|
|
active.makeTabVisible();
|
|
|
|
}
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-03 06:28:35 -04:00
|
|
|
$.fn.extend({
|
|
|
|
makeTabVisible : function() {
|
2010-05-03 15:35:54 -04:00
|
|
|
var t = this.eq(0), left, right;
|
|
|
|
if( ! t.length ) return;
|
|
|
|
left = t.offset().left;
|
|
|
|
right = left + t.outerWidth();
|
2010-05-03 06:28:35 -04:00
|
|
|
if( right > fixedRight )
|
2010-05-06 11:40:29 -04:00
|
|
|
fluid.animate({ 'margin-left' : "+=" + (fixedRight - right) + 'px' }, 'fast');
|
2010-05-03 06:28:35 -04:00
|
|
|
else if ( left < fixedLeft )
|
2010-05-06 11:40:29 -04:00
|
|
|
fluid.animate({ 'margin-left' : "-=" + (left - fixedLeft) + 'px' }, 'fast');
|
2010-05-03 06:28:35 -04: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 16:26:11 -04:00
|
|
|
|
2010-05-03 12:59:51 -04:00
|
|
|
// Find the width of all tabs
|
|
|
|
tabs.each(function(){
|
|
|
|
tabsWidth += $(this).outerWidth(true);
|
|
|
|
});
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-03 12:59:51 -04: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 16:26:11 -04:00
|
|
|
|
2010-05-03 12:59:51 -04:00
|
|
|
// Set up right margin for overflow, unset padding
|
|
|
|
fluid.css({
|
|
|
|
'margin-right' : (-1 * tabsWidth) + 'px',
|
2010-05-06 11:40:29 -04:00
|
|
|
'padding' : 0
|
2010-05-03 12:59:51 -04:00
|
|
|
});
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-03 06:28:35 -04: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 16:26:11 -04:00
|
|
|
|
2010-05-03 06:28:35 -04:00
|
|
|
// Set the menu tabs
|
|
|
|
resetMenuTabs();
|
|
|
|
// Make sure the tabs reset on resize
|
|
|
|
$(window).resize(function() {
|
|
|
|
if( resizing ) return;
|
|
|
|
resizing = true;
|
2010-05-03 16:26:11 -04:00
|
|
|
setTimeout(function(){
|
2010-05-03 06:28:35 -04:00
|
|
|
resetMenuTabs();
|
|
|
|
resizing = false;
|
|
|
|
}, 1000);
|
|
|
|
});
|
2010-05-03 16:26:11 -04:00
|
|
|
|
|
|
|
// Build arrow functions
|
2010-05-03 06:28:35 -04:00
|
|
|
$.each([{
|
|
|
|
arrow : arrowLeft,
|
|
|
|
next : "next",
|
|
|
|
last : "first",
|
2010-05-06 11:40:29 -04:00
|
|
|
operator : "+="
|
2010-05-03 06:28:35 -04:00
|
|
|
},{
|
|
|
|
arrow : arrowRight,
|
|
|
|
next : "prev",
|
|
|
|
last : "last",
|
2010-05-06 11:40:29 -04:00
|
|
|
operator : "-="
|
2010-05-03 06:28:35 -04:00
|
|
|
}], function(){
|
|
|
|
var that = this;
|
|
|
|
this.arrow.mousedown(function(){
|
|
|
|
var last = tabs[that.last](),
|
|
|
|
fn = function() {
|
|
|
|
if( ! last.isTabVisible() )
|
2010-05-06 11:40:29 -04:00
|
|
|
fluid.animate({ 'margin-left' : that.operator + '90px' }, 300, "linear", fn);
|
2010-05-03 06:28:35 -04: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 15:56:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
eventOnClickEditLink : function(clickedEl) {
|
2010-05-24 15:50:20 -04:00
|
|
|
var settings, item,
|
2010-04-26 21:05:58 -04:00
|
|
|
matchedSection = /#(.*)$/.exec(clickedEl.href);
|
|
|
|
if ( matchedSection && matchedSection[1] ) {
|
2010-05-24 15:50:20 -04:00
|
|
|
settings = $('#'+matchedSection[1]);
|
|
|
|
item = settings.parent();
|
|
|
|
if( 0 != item.length ) {
|
|
|
|
if( item.hasClass('menu-item-edit-inactive') ) {
|
|
|
|
if( ! settings.data('menu-item-data') ) {
|
|
|
|
settings.data( 'menu-item-data', settings.getItemData() );
|
|
|
|
}
|
|
|
|
settings.slideDown('fast');
|
|
|
|
item.removeClass('menu-item-edit-inactive')
|
2010-04-28 23:43:11 -04:00
|
|
|
.addClass('menu-item-edit-active');
|
|
|
|
} else {
|
2010-05-24 15:50:20 -04:00
|
|
|
settings.slideUp('fast');
|
|
|
|
item.removeClass('menu-item-edit-active')
|
2010-04-28 23:43:11 -04:00
|
|
|
.addClass('menu-item-edit-inactive');
|
2010-04-26 21:05:58 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-03-22 15:56:16 -04:00
|
|
|
},
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-24 15:50:20 -04:00
|
|
|
eventOnClickCancelLink : function(clickedEl) {
|
|
|
|
var settings = $(clickedEl).closest('.menu-item-settings');
|
|
|
|
settings.setItemData( settings.data('menu-item-data') );
|
2010-04-28 23:43:11 -04:00
|
|
|
return false;
|
|
|
|
},
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-13 21:32:48 -04:00
|
|
|
eventOnClickMenuSave : function(clickedEl) {
|
2010-05-24 05:23:56 -04:00
|
|
|
var locs = '';
|
|
|
|
// Copy menu theme locations
|
|
|
|
$('#nav-menu-theme-locations select').each(function() {
|
|
|
|
locs += '<input type="hidden" name="' + this.name + '" value="' + $(this).val() + '" />';
|
|
|
|
});
|
|
|
|
$('#update-nav-menu').append( locs );
|
2010-05-13 21:32:48 -04:00
|
|
|
// Update menu item position data
|
|
|
|
api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } );
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
eventOnClickMenuDelete : function(clickedEl) {
|
|
|
|
// Delete warning AYS
|
2010-05-04 06:01:15 -04:00
|
|
|
if ( confirm( navMenuL10n.warnDeleteMenu ) )
|
2010-04-26 21:05:58 -04:00
|
|
|
return true;
|
2010-05-04 06:01:15 -04:00
|
|
|
else
|
2010-04-26 21:05:58 -04:00
|
|
|
return false;
|
|
|
|
},
|
2010-03-17 12:13:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
eventOnClickMenuItemDelete : function(clickedEl) {
|
2010-05-24 15:50:20 -04:00
|
|
|
var itemID = parseInt(clickedEl.id.replace('delete-', ''), 10);
|
|
|
|
api.removeMenuItem( $('#menu-item-' + itemID) );
|
|
|
|
return false;
|
2010-03-22 15:56:16 -04:00
|
|
|
},
|
2010-04-26 21:05:58 -04:00
|
|
|
|
2010-03-22 15:56:16 -04:00
|
|
|
/**
|
2010-04-26 21:05:58 -04:00
|
|
|
* Process the quick search response into a search result
|
2010-05-03 16:26:11 -04:00
|
|
|
*
|
2010-04-26 21:05:58 -04:00
|
|
|
* @param string resp The server response to the query.
|
|
|
|
* @param object req The request arguments.
|
2010-05-16 01:39:53 -04:00
|
|
|
* @param jQuery panel The tabs panel we're searching in.
|
2010-03-22 15:56:16 -04:00
|
|
|
*/
|
2010-05-16 01:39:53 -04:00
|
|
|
processQuickSearchQueryResponse : function(resp, req, panel) {
|
|
|
|
var i, matched, newID,
|
|
|
|
takenIDs = {},
|
2010-04-26 21:05:58 -04:00
|
|
|
form = document.getElementById('nav-menu-meta'),
|
2010-05-16 01:39:53 -04:00
|
|
|
pattern = new RegExp('menu-item\\[(\[^\\]\]*)', 'g'),
|
|
|
|
items = resp.match(/<li>.*<\/li>/g);
|
2010-04-26 21:05:58 -04:00
|
|
|
|
2010-05-19 04:44:28 -04:00
|
|
|
if( ! items ) {
|
2010-05-16 01:39:53 -04:00
|
|
|
$('.categorychecklist', panel).html( '<li><p>' + navMenuL10n.noResultsFound + '</p></li>' );
|
|
|
|
$('img.waiting', panel).hide();
|
|
|
|
return;
|
2010-04-26 21:05:58 -04:00
|
|
|
}
|
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
i = items.length;
|
|
|
|
while( i-- ) {
|
|
|
|
// make a unique DB ID number
|
|
|
|
matched = pattern.exec(items[i]);
|
|
|
|
if ( matched && matched[1] ) {
|
|
|
|
newID = matched[1];
|
|
|
|
while( form.elements['menu-item[' + newID + '][menu-item-type]'] || takenIDs[ newID ] ) {
|
|
|
|
newID--;
|
|
|
|
}
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-05-16 01:39:53 -04:00
|
|
|
takenIDs[newID] = true;
|
|
|
|
if ( newID != matched[1] ) {
|
|
|
|
items[i] = items[i].replace(new RegExp('menu-item\\[' + matched[1] + '\\]', 'g'), 'menu-item[' + newID + ']');
|
2010-04-26 21:05:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-16 01:39:53 -04:00
|
|
|
|
|
|
|
$('.categorychecklist', panel).html( items.join('') );
|
|
|
|
$('img.waiting', panel).hide();
|
2010-04-26 21:05:58 -04:00
|
|
|
},
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
removeMenuItem : function(el) {
|
2010-05-24 05:23:56 -04:00
|
|
|
var children = el.childMenuItems();
|
2010-05-03 16:26:11 -04:00
|
|
|
|
2010-05-24 15:50:20 -04:00
|
|
|
el.addClass('deleting').animate({
|
|
|
|
opacity : 0,
|
|
|
|
height: 0
|
|
|
|
}, 350, function() {
|
|
|
|
el.remove();
|
|
|
|
children.shiftDepthClass(-1).updateParentMenuItemDBId();
|
|
|
|
});
|
2010-05-06 13:11:52 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
depthToPx : function(depth) {
|
|
|
|
return depth * api.options.menuItemDepthPerLevel;
|
|
|
|
},
|
|
|
|
|
|
|
|
pxToDepth : function(px) {
|
|
|
|
return Math.floor(px / api.options.menuItemDepthPerLevel);
|
2010-03-17 12:13:16 -04:00
|
|
|
}
|
2010-04-26 21:05:58 -04:00
|
|
|
|
2010-05-06 13:11:52 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function(){ wpNavMenu.init(); });
|
2010-04-26 21:05:58 -04:00
|
|
|
|
2010-05-06 13:11:52 -04:00
|
|
|
})(jQuery);
|