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($) {
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-06 19:11:52 +02:00
|
|
|
var api = wpNavMenu = {
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-06 19:11:52 +02:00
|
|
|
options : {
|
|
|
|
menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
|
|
|
|
globalMaxDepth : 11
|
|
|
|
},
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-06 19:11:52 +02:00
|
|
|
menuList : undefined, // Set in init.
|
|
|
|
targetList : undefined, // Set in init.
|
2010-05-19 11:56:02 +02:00
|
|
|
menusChanged : false,
|
2010-05-28 18:57:47 +02:00
|
|
|
isRTL: !! ( 'undefined' != typeof isRtl && isRtl ),
|
2010-05-31 22:22:49 +02:00
|
|
|
negateIfRTL: ( 'undefined' != typeof isRtl && isRtl ) ? -1 : 1,
|
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-05-19 10:44:28 +02:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
this.attachMenuEditListeners();
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
this.setupInputWithDefaultTitle();
|
|
|
|
this.attachQuickSearchListeners();
|
2010-05-18 17:16:58 +02:00
|
|
|
this.attachThemeLocationsListeners();
|
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-19 11:56:02 +02:00
|
|
|
this.attachUnsavedChangesListener();
|
|
|
|
|
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-04-29 05:43:11 +02:00
|
|
|
},
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-05 23:23:53 +02:00
|
|
|
jQueryExtensions : function() {
|
|
|
|
// jQuery extensions
|
|
|
|
$.fn.extend({
|
|
|
|
menuItemDepth : function() {
|
2010-05-28 18:57:47 +02:00
|
|
|
var margin = api.isRTL ? this.eq(0).css('margin-right') : this.eq(0).css('margin-left');
|
2010-05-22 01:35:37 +02:00
|
|
|
return api.pxToDepth( margin && -1 != margin.indexOf('px') ? margin.slice(0, -2) : 0 );
|
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.
|
2010-05-29 01:04:00 +02:00
|
|
|
while( ! parent[0] || ! parent[0].className || -1 == parent[0].className.indexOf('menu-item') || ( parent.menuItemDepth() != depth - 1 ) )
|
2010-05-05 23:23:53 +02:00
|
|
|
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) {
|
2010-05-29 21:39:40 +02:00
|
|
|
if ( 0 == $('#menu-to-edit').length ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-05 23:23:53 +02:00
|
|
|
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 21:50:20 +02:00
|
|
|
var t = $(this),
|
|
|
|
listItemDBIDMatch = re.exec( t.attr('name') ),
|
2010-05-05 23:23:53 +02:00
|
|
|
listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
|
2010-05-27 04:24:33 +02:00
|
|
|
if ( this.className && -1 != this.className.indexOf('add-to-top') )
|
2010-06-02 22:04:07 +02:00
|
|
|
processMethod = api.addMenuItemToTop;
|
2010-05-24 21:50:20 +02:00
|
|
|
menuItems[listItemDBID] = t.closest('li').getItemData( 'add-menu-item', listItemDBID );
|
2010-05-05 23:23:53 +02:00
|
|
|
});
|
2010-06-02 22:04:07 +02:00
|
|
|
|
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-24 21:50:20 +02:00
|
|
|
},
|
|
|
|
getItemData : function( itemType, id ) {
|
|
|
|
itemType = itemType || 'menu-item';
|
2010-05-26 04:42:15 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
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'
|
|
|
|
];
|
2010-05-26 04:42:15 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
if( !id && itemType == 'menu-item' ) {
|
|
|
|
id = this.find('.menu-item-data-db-id').val();
|
|
|
|
}
|
2010-05-26 04:42:15 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
if( !id ) return itemData;
|
2010-05-26 04:42:15 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
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] + ']';
|
2010-05-26 04:42:15 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
if (
|
|
|
|
this.name &&
|
|
|
|
field == this.name
|
|
|
|
) {
|
|
|
|
itemData[fields[i]] = this.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2010-05-26 04:42:15 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
return itemData;
|
|
|
|
},
|
|
|
|
setItemData : function( itemData, itemType, id ) { // Can take a type, such as 'menu-item', or an id.
|
|
|
|
itemType = itemType || 'menu-item';
|
2010-05-26 04:42:15 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
if( !id && itemType == 'menu-item' ) {
|
|
|
|
id = $('.menu-item-data-db-id', this).val();
|
|
|
|
}
|
2010-05-26 04:42:15 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
if( !id ) return this;
|
2010-05-26 04:42:15 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
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 + ']';
|
2010-05-26 04:42:15 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
if ( field == t.attr('name') ) {
|
|
|
|
t.val( val );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return this;
|
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() {
|
2010-05-10 06:51:57 +02:00
|
|
|
var currentDepth = 0, originalDepth, minDepth, maxDepth,
|
|
|
|
prev, next, prevBottom, nextThreshold, helperHeight, transport,
|
2010-06-11 07:19:36 +02:00
|
|
|
menuEdge = api.menuList.offset().left,
|
|
|
|
body = $('body'), maxChildDepth,
|
|
|
|
menuMaxDepth = initialMenuMaxDepth();
|
|
|
|
|
|
|
|
// Use the right edge if RTL.
|
|
|
|
menuEdge += api.isRTL ? api.menuList.width() : 0;
|
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-06-11 07:19:36 +02:00
|
|
|
var height, width, parent, children, tempHolder;
|
2010-06-02 22:04:07 +02:00
|
|
|
|
2010-05-28 18:57:47 +02:00
|
|
|
// handle placement for rtl orientation
|
|
|
|
if ( api.isRTL )
|
|
|
|
ui.item[0].style.right = 'auto';
|
2010-05-04 09:24:49 +02:00
|
|
|
|
|
|
|
transport = ui.item.children('.menu-item-transport');
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-04 09:24:49 +02:00
|
|
|
// Set depths. currentDepth must be set before children are located.
|
2010-05-10 06:51:57 +02:00
|
|
|
originalDepth = ui.item.menuItemDepth();
|
2010-05-02 21:09:10 +02:00
|
|
|
updateCurrentDepth(ui, originalDepth);
|
2010-05-19 10:44:28 +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
|
|
|
|
|
|
|
// 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-10 06:51:57 +02:00
|
|
|
helperHeight = height;
|
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);
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-10 06:51:57 +02: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 10:44:28 +02:00
|
|
|
|
2010-05-10 06:51:57 +02:00
|
|
|
// Now that the element is complete, we can update...
|
|
|
|
updateSharedVars(ui);
|
2010-05-02 21:09:10 +02:00
|
|
|
},
|
|
|
|
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-19 10:44:28 +02:00
|
|
|
|
2010-05-06 16:09:10 +02:00
|
|
|
// Update depth classes
|
|
|
|
if( depthChange != 0 ) {
|
|
|
|
ui.item.updateDepthClass( currentDepth );
|
|
|
|
children.shiftDepthClass( depthChange );
|
2010-06-11 07:19:36 +02:00
|
|
|
updateMenuMaxDepth( depthChange );
|
2010-05-02 21:09:10 +02:00
|
|
|
}
|
2010-06-11 07:19:36 +02:00
|
|
|
// Register a change
|
|
|
|
api.registerChange();
|
2010-05-06 16:09:10 +02:00
|
|
|
// Update the item data.
|
|
|
|
ui.item.updateParentMenuItemDBId();
|
2010-05-20 21:33:57 +02:00
|
|
|
|
|
|
|
// address sortable's incorrectly-calculated top in opera
|
|
|
|
ui.item[0].style.top = 0;
|
|
|
|
|
2010-05-28 18:57:47 +02:00
|
|
|
// handle drop placement for rtl orientation
|
|
|
|
if ( api.isRTL ) {
|
|
|
|
ui.item[0].style.left = 'auto';
|
|
|
|
ui.item[0].style.right = 0;
|
|
|
|
}
|
|
|
|
|
2010-06-11 07:19:36 +02:00
|
|
|
// The width of the tab bar might have changed. Just in case.
|
|
|
|
api.refreshMenuTabs( true );
|
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-10 06:51:57 +02:00
|
|
|
(prev.length) ? prev.after( ui.placeholder ) : api.menuList.prepend( ui.placeholder );
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-10 06:51:57 +02:00
|
|
|
updateSharedVars(ui);
|
2010-05-02 21:09:10 +02:00
|
|
|
},
|
|
|
|
sort: function(e, ui) {
|
2010-05-08 23:56:53 +02:00
|
|
|
var offset = ui.helper.offset(),
|
2010-06-11 07:19:36 +02:00
|
|
|
edge = api.isRTL ? offset.left + ui.helper.width() : offset.left,
|
|
|
|
depth = api.negateIfRTL * api.pxToDepth( edge - menuEdge );
|
2010-05-02 21:09:10 +02:00
|
|
|
// Check and correct if depth is not within range.
|
2010-05-08 23:56:53 +02: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 22:26:11 +02:00
|
|
|
|
2010-05-02 21:09:10 +02:00
|
|
|
if( depth != currentDepth )
|
|
|
|
updateCurrentDepth(ui, depth);
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-10 06:51:57 +02: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-06 19:11:52 +02:00
|
|
|
}
|
2010-04-29 05:43:11 +02:00
|
|
|
});
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-10 06:51:57 +02:00
|
|
|
function updateSharedVars(ui) {
|
|
|
|
var depth;
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-10 06:51:57 +02:00
|
|
|
prev = ui.placeholder.prev();
|
|
|
|
next = ui.placeholder.next();
|
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-08 23:56:53 +02:00
|
|
|
prevBottom = (prev.length) ? prev.offset().top + prev.height() : 0;
|
2010-05-10 06:51:57 +02:00
|
|
|
nextThreshold = (next.length) ? next.offset().top + next.height() / 3 : 0;
|
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-06-11 07:19:36 +02:00
|
|
|
|
|
|
|
function initialMenuMaxDepth() {
|
|
|
|
if( ! body[0].className ) return 0;
|
|
|
|
var match = body[0].className.match(/menu-max-depth-(\d+)/);
|
|
|
|
return match && match[1] ? parseInt(match[1]) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateMenuMaxDepth( depthChange ) {
|
|
|
|
var depth, newDepth = menuMaxDepth;
|
|
|
|
if ( depthChange === 0 ) {
|
|
|
|
return;
|
|
|
|
} else if ( depthChange > 0 ) {
|
|
|
|
depth = maxChildDepth + depthChange;
|
|
|
|
if( depth > menuMaxDepth )
|
|
|
|
newDepth = depth;
|
|
|
|
} else if ( depthChange < 0 && maxChildDepth == menuMaxDepth ) {
|
|
|
|
while( ! $('.menu-item-depth-' + newDepth, api.menuList).length && newDepth > 0 )
|
|
|
|
newDepth--;
|
|
|
|
}
|
|
|
|
// Update the depth class.
|
|
|
|
body.removeClass( 'menu-max-depth-' + menuMaxDepth ).addClass( 'menu-max-depth-' + newDepth );
|
|
|
|
menuMaxDepth = newDepth;
|
|
|
|
}
|
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);
|
2010-05-14 03:32:48 +02:00
|
|
|
} else if ( -1 != e.target.className.indexOf('menu-save') ) {
|
|
|
|
return that.eventOnClickMenuSave(e.target);
|
2010-04-27 03:05:58 +02: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 21:50:20 +02:00
|
|
|
} else if ( -1 != e.target.className.indexOf('item-cancel') ) {
|
|
|
|
return that.eventOnClickCancelLink(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-18 17:16:58 +02:00
|
|
|
attachThemeLocationsListeners : function() {
|
2010-05-21 00:43:14 +02: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-18 01:58:56 +02:00
|
|
|
loc.find('input[type=submit]').click(function() {
|
2010-05-21 00:43:14 +02:00
|
|
|
loc.find('select').each(function() {
|
|
|
|
params[this.name] = $(this).val();
|
|
|
|
});
|
2010-05-18 01:58:56 +02:00
|
|
|
loc.find('.waiting').show();
|
2010-05-18 17:16:58 +02:00
|
|
|
$.post( ajaxurl, params, function(r) {
|
2010-05-18 01:58:56 +02:00
|
|
|
loc.find('.waiting').hide();
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2010-05-05 22:29:50 +02:00
|
|
|
},
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
attachQuickSearchListeners : function() {
|
2010-05-16 07:39:53 +02:00
|
|
|
var searchTimer;
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
$('.quick-search').keypress(function(e){
|
|
|
|
var t = $(this);
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
if( 13 == e.which ) {
|
|
|
|
api.updateQuickSearchResults( t );
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
if( searchTimer ) clearTimeout(searchTimer);
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
searchTimer = setTimeout(function(){
|
|
|
|
api.updateQuickSearchResults( t );
|
|
|
|
}, 400);
|
|
|
|
}).attr('autocomplete','off');
|
2010-05-04 10:31:40 +02:00
|
|
|
},
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
updateQuickSearchResults : function(input) {
|
|
|
|
var panel, params,
|
|
|
|
minSearchLength = 2,
|
|
|
|
q = input.val();
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
if( q.length < minSearchLength ) return;
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
panel = input.parents('.tabs-panel');
|
2010-05-04 10:31:40 +02:00
|
|
|
params = {
|
|
|
|
'action': 'menu-quick-search',
|
|
|
|
'response-format': 'markup',
|
2010-05-16 07:39:53 +02:00
|
|
|
'menu': $('#menu').val(),
|
|
|
|
'menu-settings-column-nonce': $('#menu-settings-column-nonce').val(),
|
2010-05-04 10:31:40 +02:00
|
|
|
'q': q,
|
2010-05-16 07:39:53 +02:00
|
|
|
'type': input.attr('name')
|
2010-05-04 10:31:40 +02:00
|
|
|
};
|
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
$('img.waiting', panel).show();
|
|
|
|
|
2010-05-04 10:31:40 +02:00
|
|
|
$.post( ajaxurl, params, function(menuMarkup) {
|
2010-05-16 07:39:53 +02:00
|
|
|
api.processQuickSearchQueryResponse(menuMarkup, params, panel);
|
2010-05-04 10:31:40 +02:00
|
|
|
});
|
|
|
|
},
|
2010-05-19 10:44:28 +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-19 10:44:28 +02:00
|
|
|
|
2010-05-05 22:37:32 +02:00
|
|
|
processMethod = processMethod || api.addMenuItemToBottom;
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-04 10:31:40 +02:00
|
|
|
if ( '' == url || 'http://' == url )
|
|
|
|
return false;
|
2010-05-19 10:44:28 +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-19 10:44:28 +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-19 10:44:28 +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-19 10:44:28 +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-19 10:44:28 +02:00
|
|
|
|
2010-05-05 22:29:50 +02:00
|
|
|
processMethod = processMethod || function(){};
|
|
|
|
callback = callback || function(){};
|
2010-05-19 10:44:28 +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-19 10:44:28 +02:00
|
|
|
|
2010-05-04 10:31:40 +02:00
|
|
|
$.post( ajaxurl, params, function(menuMarkup) {
|
2010-05-26 02:41:18 +02:00
|
|
|
var ins = $('#menu-instructions');
|
2010-05-05 22:29:50 +02:00
|
|
|
processMethod(menuMarkup, params);
|
2010-05-26 02:41:18 +02:00
|
|
|
if( ! ins.hasClass('menu-instructions-inactive') && ins.siblings().length )
|
|
|
|
ins.addClass('menu-instructions-inactive');
|
2010-05-05 22:29:50 +02:00
|
|
|
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-19 10:44:28 +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-19 10:44:28 +02:00
|
|
|
|
2010-05-19 11:56:02 +02:00
|
|
|
attachUnsavedChangesListener : function() {
|
|
|
|
$('#menu-management input, #menu-management select, #menu-management, #menu-management textarea').change(function(){
|
|
|
|
api.registerChange();
|
|
|
|
});
|
2010-05-29 21:39:40 +02:00
|
|
|
|
|
|
|
if ( 0 != $('#menu-to-edit').length ) {
|
|
|
|
window.onbeforeunload = function(){
|
|
|
|
if ( api.menusChanged )
|
|
|
|
return navMenuL10n.saveAlert;
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Make the post boxes read-only, as they can't be used yet
|
|
|
|
$('#menu-settings-column').find('input,select').attr('disabled', 'disabled').end().find('a').attr('href', '#').unbind('click');
|
|
|
|
}
|
2010-05-19 11:56:02 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
registerChange : function() {
|
|
|
|
api.menusChanged = true;
|
|
|
|
},
|
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
attachTabsPanelListeners : function() {
|
|
|
|
$('#menu-settings-column').bind('click', function(e) {
|
2010-05-24 11:23:56 +02:00
|
|
|
var selectAreaMatch, panelId, wrapper, items,
|
2010-05-16 07:39:53 +02:00
|
|
|
target = $(e.target);
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-16 07:39:53 +02: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 10:44:28 +02:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
wrapper = target.parents('.inside').first();
|
2010-04-28 20:30:32 +02:00
|
|
|
|
|
|
|
// upon changing tabs, we want to uncheck all checkboxes
|
2010-05-16 07:39:53 +02:00
|
|
|
$('input', wrapper).removeAttr('checked');
|
2010-05-19 10:44:28 +02:00
|
|
|
|
2010-05-16 07:39:53 +02: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-27 03:05:58 +02:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
$('.tabs', wrapper).removeClass('tabs');
|
|
|
|
target.parent().addClass('tabs');
|
2010-04-27 03:05:58 +02:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
// select the search bar
|
|
|
|
$('.quick-search', wrapper).focus();
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
return false;
|
2010-05-16 07:39:53 +02:00
|
|
|
} else if ( target.hasClass('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-05-26 16:49:43 +02:00
|
|
|
} else if ( target.hasClass('submit-add-to-menu') ) {
|
|
|
|
api.registerChange();
|
|
|
|
|
|
|
|
if ( e.target.id && 'submit-customlinkdiv' == e.target.id )
|
|
|
|
api.addCustomLink( api.addMenuItemToBottom );
|
|
|
|
else if ( e.target.id && -1 != e.target.id.indexOf('submit-') )
|
|
|
|
$('#' + e.target.id.replace(/submit-/, '')).addSelectedToMenu( api.addMenuItemToBottom );
|
|
|
|
return false;
|
|
|
|
} else if ( target.hasClass('page-numbers') ) {
|
2010-06-02 22:04:07 +02:00
|
|
|
$.post( ajaxurl, e.target.href.replace(/.*\?/, '').replace(/action=([^&]*)/, '') + '&action=menu-get-metabox',
|
2010-05-26 16:49:43 +02:00
|
|
|
function( resp ) {
|
|
|
|
if ( -1 == resp.indexOf('replace-id') )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var metaBoxData = $.parseJSON(resp),
|
|
|
|
toReplace = document.getElementById(metaBoxData['replace-id']),
|
|
|
|
placeholder = document.createElement('div'),
|
|
|
|
wrap = document.createElement('div');
|
|
|
|
|
|
|
|
if ( ! metaBoxData['markup'] || ! toReplace )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wrap.innerHTML = metaBoxData['markup'] ? metaBoxData['markup'] : '';
|
|
|
|
|
|
|
|
toReplace.parentNode.insertBefore( placeholder, toReplace );
|
|
|
|
placeholder.parentNode.removeChild( toReplace );
|
|
|
|
|
|
|
|
placeholder.parentNode.insertBefore( wrap, placeholder );
|
|
|
|
|
|
|
|
placeholder.parentNode.removeChild( placeholder );
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
2010-06-02 22:04:07 +02:00
|
|
|
|
2010-05-26 16:49:43 +02:00
|
|
|
return 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-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-31 22:22:49 +02:00
|
|
|
arrowLeft, arrowRight, resizeTimer, css = {},
|
|
|
|
marginFluid = api.isRTL ? 'margin-right' : 'margin-left',
|
|
|
|
marginFixed = api.isRTL ? 'margin-left' : 'margin-right',
|
|
|
|
msPerPx = 2;
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-06-11 07:19:36 +02:00
|
|
|
/**
|
|
|
|
* Refreshes the menu tabs.
|
|
|
|
* Will show and hide arrows where necessary.
|
|
|
|
* Scrolls to the active tab by default.
|
2010-06-11 22:19:35 +02:00
|
|
|
*
|
2010-06-11 07:19:36 +02:00
|
|
|
* @param savePosition {boolean} Optional. Prevents scrolling so
|
2010-06-11 22:19:35 +02:00
|
|
|
* that the current position is maintained. Default false.
|
2010-06-11 07:19:36 +02:00
|
|
|
**/
|
|
|
|
api.refreshMenuTabs = function( savePosition ) {
|
2010-05-31 22:22:49 +02:00
|
|
|
var fixedWidth = fixed.width(),
|
|
|
|
margin = 0, css = {};
|
2010-05-03 12:28:35 +02:00
|
|
|
fixedLeft = fixed.offset().left;
|
2010-05-31 22:22:49 +02:00
|
|
|
fixedRight = fixedLeft + fixedWidth;
|
2010-06-11 07:19:36 +02:00
|
|
|
|
|
|
|
if( !savePosition )
|
|
|
|
active.makeTabVisible();
|
2010-06-02 22:04:07 +02:00
|
|
|
|
2010-05-31 22:22:49 +02:00
|
|
|
// Prevent space from building up next to the last tab if there's more to show
|
|
|
|
if( tabs.last().isTabVisible() ) {
|
|
|
|
margin = fixed.width() - tabsWidth;
|
|
|
|
margin = margin > 0 ? 0 : margin;
|
|
|
|
css[marginFluid] = margin + 'px';
|
|
|
|
fluid.animate( css, 100, "linear" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show the arrows only when necessary
|
|
|
|
if( fixedWidth > tabsWidth )
|
|
|
|
arrowLeft.add( arrowRight ).hide();
|
|
|
|
else
|
|
|
|
arrowLeft.add( arrowRight ).show();
|
2010-05-03 12:28:35 +02:00
|
|
|
}
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-03 12:28:35 +02:00
|
|
|
$.fn.extend({
|
|
|
|
makeTabVisible : function() {
|
2010-05-31 22:22:49 +02:00
|
|
|
var t = this.eq(0), left, right, css = {}, shift = 0;
|
|
|
|
|
|
|
|
if( ! t.length ) return this;
|
|
|
|
|
2010-05-03 21:35:54 +02:00
|
|
|
left = t.offset().left;
|
|
|
|
right = left + t.outerWidth();
|
2010-05-31 22:22:49 +02:00
|
|
|
|
2010-05-03 12:28:35 +02:00
|
|
|
if( right > fixedRight )
|
2010-05-31 22:22:49 +02:00
|
|
|
shift = fixedRight - right;
|
2010-05-03 12:28:35 +02:00
|
|
|
else if ( left < fixedLeft )
|
2010-05-31 22:22:49 +02:00
|
|
|
shift = fixedLeft - left;
|
|
|
|
|
|
|
|
if( ! shift ) return this;
|
|
|
|
|
|
|
|
css[marginFluid] = "+=" + api.negateIfRTL * shift + 'px';
|
|
|
|
fluid.animate( css, Math.abs( shift ) * msPerPx, "linear" );
|
|
|
|
return this;
|
2010-05-03 12:28:35 +02:00
|
|
|
},
|
|
|
|
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-31 22:22:49 +02:00
|
|
|
// Set up fixed margin for overflow, unset padding
|
|
|
|
css['padding'] = 0;
|
|
|
|
css[marginFixed] = (-1 * tabsWidth) + 'px';
|
|
|
|
fluid.css( css );
|
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
|
2010-06-11 07:19:36 +02:00
|
|
|
api.refreshMenuTabs();
|
2010-05-03 12:28:35 +02:00
|
|
|
// Make sure the tabs reset on resize
|
|
|
|
$(window).resize(function() {
|
2010-05-31 22:22:49 +02:00
|
|
|
if( resizeTimer ) clearTimeout(resizeTimer);
|
2010-06-11 07:19:36 +02:00
|
|
|
resizeTimer = setTimeout( api.refreshMenuTabs, 200);
|
2010-05-03 12:28:35 +02:00
|
|
|
});
|
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(){
|
2010-05-31 22:22:49 +02:00
|
|
|
var marginFluidVal = Math.abs( parseInt( fluid.css(marginFluid) ) ),
|
|
|
|
shift = marginFluidVal,
|
|
|
|
css = {};
|
|
|
|
|
|
|
|
if( "-=" == that.operator )
|
|
|
|
shift = Math.abs( tabsWidth - fixed.width() ) - marginFluidVal;
|
|
|
|
|
|
|
|
if( ! shift ) return;
|
|
|
|
|
|
|
|
css[marginFluid] = that.operator + shift + 'px';
|
|
|
|
fluid.animate( css, shift * msPerPx, "linear" );
|
2010-05-03 12:28:35 +02:00
|
|
|
}).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
|
|
|
eventOnClickEditLink : function(clickedEl) {
|
2010-05-24 21:50:20 +02:00
|
|
|
var settings, item,
|
2010-04-27 03:05:58 +02:00
|
|
|
matchedSection = /#(.*)$/.exec(clickedEl.href);
|
|
|
|
if ( matchedSection && matchedSection[1] ) {
|
2010-05-24 21:50:20 +02: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-29 05:43:11 +02:00
|
|
|
.addClass('menu-item-edit-active');
|
|
|
|
} else {
|
2010-05-24 21:50:20 +02:00
|
|
|
settings.slideUp('fast');
|
|
|
|
item.removeClass('menu-item-edit-active')
|
2010-04-29 05:43:11 +02:00
|
|
|
.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-05-24 21:50:20 +02:00
|
|
|
eventOnClickCancelLink : function(clickedEl) {
|
|
|
|
var settings = $(clickedEl).closest('.menu-item-settings');
|
|
|
|
settings.setItemData( settings.data('menu-item-data') );
|
2010-04-29 05:43:11 +02:00
|
|
|
return false;
|
|
|
|
},
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-14 03:32:48 +02:00
|
|
|
eventOnClickMenuSave : function(clickedEl) {
|
2010-06-03 05:33:54 +02:00
|
|
|
var locs = '',
|
|
|
|
menuName = $('#menu-name'),
|
|
|
|
menuNameVal = menuName.val();
|
|
|
|
// Cancel and warn if invalid menu name
|
|
|
|
if( !menuNameVal || menuNameVal == menuName.attr('title') || !menuNameVal.replace(/\s+/, '') ) {
|
|
|
|
menuName.parent().addClass('form-invalid');
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-24 11:23:56 +02:00
|
|
|
// 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-14 03:32:48 +02:00
|
|
|
// Update menu item position data
|
|
|
|
api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } );
|
2010-05-28 22:38:19 +02:00
|
|
|
window.onbeforeunload = null;
|
|
|
|
|
2010-05-14 03:32:48 +02:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
eventOnClickMenuDelete : function(clickedEl) {
|
|
|
|
// Delete warning AYS
|
2010-05-28 22:38:19 +02:00
|
|
|
if ( confirm( navMenuL10n.warnDeleteMenu ) ) {
|
|
|
|
window.onbeforeunload = null;
|
2010-04-27 03:05:58 +02:00
|
|
|
return true;
|
2010-05-28 22:38:19 +02:00
|
|
|
}
|
|
|
|
return false;
|
2010-04-27 03:05:58 +02:00
|
|
|
},
|
2010-03-17 17:13:16 +01:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
eventOnClickMenuItemDelete : function(clickedEl) {
|
2010-05-24 21:50:20 +02:00
|
|
|
var itemID = parseInt(clickedEl.id.replace('delete-', ''), 10);
|
|
|
|
api.removeMenuItem( $('#menu-item-' + itemID) );
|
2010-05-27 04:31:23 +02:00
|
|
|
api.registerChange();
|
2010-05-24 21:50:20 +02:00
|
|
|
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-05-16 07:39:53 +02:00
|
|
|
* @param jQuery panel The tabs panel we're searching in.
|
2010-03-22 20:56:16 +01:00
|
|
|
*/
|
2010-05-16 07:39:53 +02:00
|
|
|
processQuickSearchQueryResponse : function(resp, req, panel) {
|
2010-10-04 16:17:34 +02:00
|
|
|
var matched, newID,
|
2010-05-16 07:39:53 +02:00
|
|
|
takenIDs = {},
|
2010-04-27 03:05:58 +02:00
|
|
|
form = document.getElementById('nav-menu-meta'),
|
2010-05-16 07:39:53 +02:00
|
|
|
pattern = new RegExp('menu-item\\[(\[^\\]\]*)', 'g'),
|
2010-10-04 16:17:34 +02:00
|
|
|
$items = $('<div>').html(resp).find('li'),
|
|
|
|
$item;
|
2010-04-27 03:05:58 +02:00
|
|
|
|
2010-10-04 16:17:34 +02:00
|
|
|
if( ! $items.length ) {
|
2010-05-16 07:39:53 +02:00
|
|
|
$('.categorychecklist', panel).html( '<li><p>' + navMenuL10n.noResultsFound + '</p></li>' );
|
|
|
|
$('img.waiting', panel).hide();
|
|
|
|
return;
|
2010-04-27 03:05:58 +02:00
|
|
|
}
|
|
|
|
|
2010-10-04 16:17:34 +02:00
|
|
|
$items.each(function(){
|
|
|
|
$item = $(this);
|
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
// make a unique DB ID number
|
2010-10-04 16:17:34 +02:00
|
|
|
matched = pattern.exec($item.html());
|
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
if ( matched && matched[1] ) {
|
|
|
|
newID = matched[1];
|
|
|
|
while( form.elements['menu-item[' + newID + '][menu-item-type]'] || takenIDs[ newID ] ) {
|
|
|
|
newID--;
|
|
|
|
}
|
2010-03-22 20:56:16 +01:00
|
|
|
|
2010-05-16 07:39:53 +02:00
|
|
|
takenIDs[newID] = true;
|
|
|
|
if ( newID != matched[1] ) {
|
2010-10-04 16:17:34 +02:00
|
|
|
$item.html( $item.html().replace(new RegExp(
|
|
|
|
'menu-item\\[' + matched[1] + '\\]', 'g'),
|
|
|
|
'menu-item[' + newID + ']'
|
|
|
|
) );
|
2010-04-27 03:05:58 +02:00
|
|
|
}
|
|
|
|
}
|
2010-10-04 16:17:34 +02:00
|
|
|
});
|
2010-05-16 07:39:53 +02:00
|
|
|
|
2010-10-04 16:17:34 +02:00
|
|
|
$('.categorychecklist', panel).html( $items );
|
2010-05-16 07:39:53 +02:00
|
|
|
$('img.waiting', panel).hide();
|
2010-04-27 03:05:58 +02:00
|
|
|
},
|
2010-03-22 20:56:16 +01:00
|
|
|
|
2010-04-27 03:05:58 +02:00
|
|
|
removeMenuItem : function(el) {
|
2010-05-24 11:23:56 +02:00
|
|
|
var children = el.childMenuItems();
|
2010-05-03 22:26:11 +02:00
|
|
|
|
2010-05-24 21:50:20 +02:00
|
|
|
el.addClass('deleting').animate({
|
|
|
|
opacity : 0,
|
|
|
|
height: 0
|
|
|
|
}, 350, function() {
|
2010-05-26 02:41:18 +02:00
|
|
|
var ins = $('#menu-instructions');
|
2010-05-24 21:50:20 +02:00
|
|
|
el.remove();
|
|
|
|
children.shiftDepthClass(-1).updateParentMenuItemDBId();
|
2010-05-26 02:41:18 +02:00
|
|
|
if( ! ins.siblings().length )
|
|
|
|
ins.removeClass('menu-instructions-inactive');
|
2010-05-24 21:50:20 +02:00
|
|
|
});
|
2010-05-06 19:11:52 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
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);
|