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-02 15:09:10 -04:00
|
|
|
var WPNavMenuHandler = function ($) {
|
|
|
|
var autoCompleteData = {},
|
2010-04-26 21:05:58 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
menuItemDepthPerLevel = 30, // Do not use directly. Use depthToPx and pxToDepth instead.
|
|
|
|
globalMaxDepth = 11,
|
2010-04-26 21:05:58 -04: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 )
|
|
|
|
autoCompleteData[data.post_title] = {ID: data.ID, object_type: data.post_type};
|
|
|
|
return data.post_title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
formatAutocompleteResult = function( resultRow, pos, total, queryTerm ) {
|
|
|
|
if ( resultRow && resultRow[0] ) {
|
|
|
|
var data = $.parseJSON(resultRow[0]);
|
|
|
|
if ( data.post_title )
|
|
|
|
return data.post_title;
|
|
|
|
}
|
|
|
|
},
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
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,
|
|
|
|
menuID = document.getElementById('nav-menu-meta-object-id').value;
|
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
2010-05-02 15:09:10 -04:00
|
|
|
|
|
|
|
recalculateMenuItemPositions = function() {
|
|
|
|
menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } );
|
2010-04-26 21:05:58 -04:00
|
|
|
},
|
2010-05-02 15:09:10 -04:00
|
|
|
|
|
|
|
depthToPx = function(depth) {
|
|
|
|
return depth * menuItemDepthPerLevel;
|
|
|
|
},
|
|
|
|
|
|
|
|
pxToDepth = function(px) {
|
|
|
|
return Math.floor(px / menuItemDepthPerLevel);
|
2010-04-26 21:05:58 -04:00
|
|
|
},
|
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
menuList;
|
|
|
|
|
|
|
|
// jQuery extensions
|
|
|
|
$.fn.extend({
|
|
|
|
menuItemDepth : function() {
|
|
|
|
return pxToDepth( this.eq(0).css('margin-left').slice(0, -2) );
|
|
|
|
},
|
|
|
|
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-object-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');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2010-04-26 21:05:58 -04:00
|
|
|
|
|
|
|
return {
|
2010-03-22 15:56:16 -04:00
|
|
|
|
|
|
|
// Functions that run on init.
|
|
|
|
init : function() {
|
2010-05-02 15:09:10 -04:00
|
|
|
menuList = $('#menu-to-edit');
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
this.attachMenuEditListeners();
|
|
|
|
|
|
|
|
this.attachMenuMetaListeners(document.getElementById('nav-menu-meta'));
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
this.attachTabsPanelListeners();
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
if( menuList.length ) // If no menu, we're in the + tab.
|
|
|
|
this.initSortables();
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-04-28 23:43:11 -04:00
|
|
|
this.initToggles();
|
|
|
|
},
|
|
|
|
|
|
|
|
initToggles : function() {
|
|
|
|
// init postboxes
|
2010-04-26 21:05:58 -04:00
|
|
|
postboxes.add_postbox_toggles('nav-menus');
|
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-02 15:09:10 -04:00
|
|
|
menuList.hideAdvancedMenuItemFields();
|
2010-04-28 23:43:11 -04:00
|
|
|
},
|
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
initSortables : function() {
|
|
|
|
var currentDepth = 0, originalDepth, minDepth, maxDepth,
|
|
|
|
menuLeft = menuList.offset().left;
|
|
|
|
|
|
|
|
menuList.sortable({
|
|
|
|
handle: ' > dl',
|
|
|
|
placeholder: 'sortable-placeholder',
|
|
|
|
start: function(e, ui) {
|
|
|
|
var next, height, width, parent, children, maxChildDepth,
|
|
|
|
transport = ui.item.children('.menu-item-transport');
|
|
|
|
|
|
|
|
// Set depths
|
|
|
|
originalDepth = ui.item.menuItemDepth();
|
|
|
|
updateCurrentDepth(ui, originalDepth);
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
|
|
|
|
// Now that the element is complete, we can update...
|
|
|
|
updateDepthRange(ui);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
height += ui.item.outerHeight();
|
|
|
|
height -= 2; // Subtract 2 for borders
|
|
|
|
ui.placeholder.height(height);
|
|
|
|
|
|
|
|
// Update the width of the placeholder to match the moving item.
|
|
|
|
maxChildDepth = originalDepth;
|
|
|
|
children.each(function(){
|
|
|
|
var depth = $(this).menuItemDepth();
|
|
|
|
maxChildDepth = (depth > maxChildDepth) ? depth : maxChildDepth;
|
|
|
|
});
|
|
|
|
width = ui.item.find('dl dt').outerWidth(); // Get original width
|
|
|
|
width += depthToPx(maxChildDepth - originalDepth); // Account for children
|
|
|
|
width -= 2; // Subtract 2 for borders
|
|
|
|
ui.placeholder.width(width);
|
|
|
|
},
|
|
|
|
stop: function(e, ui) {
|
|
|
|
var children, depthChange = currentDepth - originalDepth;
|
|
|
|
|
|
|
|
// Return child elements to the list
|
|
|
|
children = ui.item.children('.menu-item-transport').children().insertAfter(ui.item);
|
|
|
|
|
|
|
|
// Update depth classes
|
|
|
|
if( depthChange != 0 ) {
|
|
|
|
ui.item.updateDepthClass( currentDepth );
|
|
|
|
children.shiftDepthClass( depthChange );
|
|
|
|
}
|
|
|
|
// Finally, update the item/menu data.
|
|
|
|
ui.item.updateParentMenuItemDBId();
|
|
|
|
recalculateMenuItemPositions();
|
|
|
|
},
|
|
|
|
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') )
|
|
|
|
ui.placeholder.appendTo(menuList);
|
|
|
|
|
|
|
|
updateDepthRange(ui);
|
|
|
|
},
|
|
|
|
sort: function(e, ui) {
|
|
|
|
var depth = pxToDepth(ui.item.offset().left - menuLeft);
|
|
|
|
// Check and correct if depth is not within range.
|
|
|
|
if ( depth < minDepth ) depth = minDepth;
|
|
|
|
else if ( depth > maxDepth ) depth = maxDepth;
|
|
|
|
|
|
|
|
if( depth != currentDepth )
|
|
|
|
updateCurrentDepth(ui, depth);
|
|
|
|
}
|
2010-04-28 23:43:11 -04:00
|
|
|
});
|
2010-05-02 15:09:10 -04:00
|
|
|
|
|
|
|
function updateDepthRange(ui) {
|
|
|
|
var prev = ui.placeholder.prev(),
|
|
|
|
next = ui.placeholder.next(), depth;
|
|
|
|
|
|
|
|
// Make sure we don't select the moving item.
|
|
|
|
if( prev[0] == ui.item[0] ) prev = prev.prev();
|
|
|
|
if( next[0] == ui.item[0] ) next = next.next();
|
|
|
|
|
|
|
|
minDepth = (next.length) ? next.menuItemDepth() : 0;
|
|
|
|
|
|
|
|
if( prev.length )
|
|
|
|
maxDepth = ( (depth = prev.menuItemDepth() + 1) > globalMaxDepth ) ? globalMaxDepth : depth;
|
|
|
|
else
|
|
|
|
maxDepth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateCurrentDepth(ui, depth) {
|
|
|
|
ui.placeholder.updateDepthClass( depth, currentDepth );
|
|
|
|
currentDepth = depth;
|
|
|
|
}
|
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);
|
|
|
|
} 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-28 23:43:11 -04:00
|
|
|
} else if ( -1 != e.target.className.indexOf('item-close') ) {
|
|
|
|
return that.eventOnClickCloseLink(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-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-04-28 23:43: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 );
|
|
|
|
|
|
|
|
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-02 15:09:10 -04:00
|
|
|
$t.val( $t.data(name) ).addClass( name );
|
2010-04-28 23:43:11 -04:00
|
|
|
});
|
2010-05-02 15:09:10 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
attachMenuMetaListeners : function(formEL) {
|
|
|
|
if ( ! formEL )
|
|
|
|
return;
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
var that = this;
|
|
|
|
this.setupInputWithDefaultTitle();
|
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
// auto-suggest for the quick-search boxes
|
|
|
|
$('input.quick-search').each(function(i, el) {
|
|
|
|
that.setupQuickSearchEventListeners(el);
|
2010-03-22 15:56:16 -04:00
|
|
|
});
|
2010-04-26 21:05:58 -04:00
|
|
|
|
|
|
|
$(formEL).bind('submit', function(e) {
|
|
|
|
return that.eventSubmitMetaForm.call(that, this, e);
|
2010-03-22 15:56:16 -04:00
|
|
|
});
|
2010-05-02 17:05:55 -04:00
|
|
|
$(formEL).find('input:submit').click(function() {
|
|
|
|
$(this).siblings('img.waiting').show();
|
|
|
|
});
|
2010-04-26 21:05:58 -04:00
|
|
|
},
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
attachTabsPanelListeners : function() {
|
|
|
|
$('#menu-settings-column').bind('click', function(e) {
|
2010-04-28 23:43:11 -04:00
|
|
|
if ( e.target && e.target.className && -1 != e.target.className.indexOf('nav-tab-link') ) {
|
2010-04-28 14:30:32 -04:00
|
|
|
var activePanel,
|
2010-04-26 21:05:58 -04:00
|
|
|
panelIdMatch = /#(.*)$/.exec(e.target.href),
|
2010-04-28 14:30:32 -04:00
|
|
|
tabPanels,
|
2010-05-02 14:12:13 -04:00
|
|
|
wrapper = $(e.target).parents('.inside').first()[0],
|
2010-04-28 14:30:32 -04:00
|
|
|
inputs = wrapper ? wrapper.getElementsByTagName('input') : [],
|
|
|
|
i = inputs.length;
|
|
|
|
|
|
|
|
// upon changing tabs, we want to uncheck all checkboxes
|
|
|
|
while( i-- )
|
|
|
|
inputs[i].checked = false;
|
|
|
|
|
|
|
|
$('.tabs-panel', wrapper).each(function() {
|
2010-04-26 21:05:58 -04:00
|
|
|
if ( this.className )
|
|
|
|
this.className = this.className.replace('tabs-panel-active', 'tabs-panel-inactive');
|
|
|
|
});
|
|
|
|
|
2010-04-28 14:30:32 -04:00
|
|
|
$('.tabs', wrapper).each(function() {
|
2010-04-26 21:05:58 -04: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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} else if ( e.target && e.target.className && -1 != e.target.className.indexOf('select-all') ) {
|
|
|
|
var selectAreaMatch = /#(.*)$/.exec(e.target.href);
|
|
|
|
if ( selectAreaMatch && selectAreaMatch[1] ) {
|
|
|
|
$('#' + selectAreaMatch[1] + ' .tabs-panel-active input[type=checkbox]').attr('checked', 'checked');
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Set up quick-search input fields' events.
|
|
|
|
*
|
|
|
|
* @param object el The input element.
|
|
|
|
*/
|
|
|
|
setupQuickSearchEventListeners : function(el) {
|
|
|
|
var that = this;
|
|
|
|
$(el).autocomplete( ajaxurl + '?action=menu-quick-search&type=' + el.name,
|
|
|
|
{
|
|
|
|
delay: 500,
|
|
|
|
formatItem: formatAutocompleteResponse,
|
|
|
|
formatResult: formatAutocompleteResult,
|
|
|
|
minchars: 2,
|
|
|
|
multiple: false
|
|
|
|
}
|
|
|
|
).bind('blur', function(e) {
|
|
|
|
var changedData = autoCompleteData[this.value],
|
|
|
|
inputEl = this;
|
|
|
|
if ( changedData ) {
|
|
|
|
$.post(
|
|
|
|
ajaxurl + '?action=menu-quick-search&type=get-post-item&response-format=markup',
|
|
|
|
changedData,
|
|
|
|
function(r) {
|
|
|
|
that.processQuickSearchQueryResponse.call(that, r, changedData);
|
|
|
|
autoCompleteData[inputEl.value] = 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
|
|
|
eventOnClickEditLink : function(clickedEl) {
|
|
|
|
var activeEdit,
|
|
|
|
matchedSection = /#(.*)$/.exec(clickedEl.href);
|
|
|
|
if ( matchedSection && matchedSection[1] ) {
|
2010-04-28 23:43:11 -04: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-26 21:05:58 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-03-22 15:56:16 -04:00
|
|
|
},
|
|
|
|
|
2010-04-28 23:43:11 -04:00
|
|
|
eventOnClickCloseLink : function(clickedEl) {
|
|
|
|
$(clickedEl).closest('.menu-item-settings').siblings('dl').find('.item-edit').click();
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
eventOnClickMenuDelete : function(clickedEl) {
|
|
|
|
// Delete warning AYS
|
|
|
|
if ( confirm( navMenuL10n.warnDeleteMenu ) ) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2010-03-22 15:56:16 -04:00
|
|
|
}
|
2010-04-26 21:05:58 -04:00
|
|
|
},
|
2010-03-17 12:13:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04: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] ) {
|
|
|
|
itemID = parseInt(clickedEl.id.replace('delete-', ''), 10);
|
|
|
|
$.post(
|
|
|
|
ajaxurl,
|
|
|
|
{
|
|
|
|
action:'delete-menu-item',
|
|
|
|
'menu-item':itemID,
|
|
|
|
'_wpnonce':matchedSection[1]
|
|
|
|
},
|
|
|
|
function (resp) {
|
|
|
|
if ( '1' == resp )
|
|
|
|
that.removeMenuItem(document.getElementById('menu-item-' + itemID));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
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
|
|
|
* Callback for the meta form submit action listener.
|
2010-03-22 15:56:16 -04:00
|
|
|
*
|
2010-04-26 21:05:58 -04:00
|
|
|
* @param object thisForm The submitted form.
|
|
|
|
* @param object e The event object.
|
2010-03-22 15:56:16 -04:00
|
|
|
*/
|
2010-04-26 21:05:58 -04:00
|
|
|
eventSubmitMetaForm : function(thisForm, e) {
|
2010-04-28 23:43:11 -04:00
|
|
|
var inputs = thisForm.getElementsByTagName('input'),
|
2010-04-26 21:05:58 -04:00
|
|
|
i = inputs.length,
|
|
|
|
j,
|
|
|
|
listItemData,
|
|
|
|
listItemDBID,
|
|
|
|
listItemDBIDMatch,
|
|
|
|
params = {},
|
|
|
|
processMethod = function(){},
|
|
|
|
re = new RegExp('menu-item\\[(\[^\\]\]*)');
|
|
|
|
|
|
|
|
that = this;
|
|
|
|
params['action'] = '';
|
|
|
|
|
|
|
|
while ( i-- ) {
|
|
|
|
if ( // we're submitting a checked item
|
|
|
|
inputs[i].name &&
|
|
|
|
-1 != inputs[i].name.indexOf('menu-item-object-id') &&
|
|
|
|
inputs[i].checked ||
|
|
|
|
( // or we're dealing with a custom link
|
|
|
|
'undefined' != typeof inputs[i].id &&
|
|
|
|
'custom-menu-item-url' == inputs[i].id &&
|
|
|
|
'' != inputs[i].value &&
|
|
|
|
'http://' != inputs[i].value
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
params['action'] = 'add-menu-item';
|
|
|
|
processMethod = that.processAddMenuItemResponse;
|
|
|
|
|
|
|
|
listItemDBIDMatch = re.exec(inputs[i].name);
|
|
|
|
listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
|
|
|
|
listItemData = getListDataFromID(listItemDBID);
|
|
|
|
|
|
|
|
for ( j in listItemData ) {
|
|
|
|
params['menu-item[' + listItemDBID + '][' + j + ']'] = listItemData[j];
|
|
|
|
}
|
|
|
|
|
|
|
|
inputs[i].checked = false;
|
|
|
|
|
|
|
|
// we're submitting a search term
|
|
|
|
} else if (
|
|
|
|
'' == params['action'] && // give precedence to adding items
|
|
|
|
'' != inputs[i].value &&
|
|
|
|
inputs[i].className &&
|
|
|
|
-1 != inputs[i].className.search(/quick-search\b[^-]/)
|
|
|
|
) {
|
|
|
|
params['action'] = 'menu-quick-search';
|
|
|
|
params['q'] = inputs[i].value;
|
|
|
|
params['response-format'] = 'markup';
|
|
|
|
params['type'] = inputs[i].name;
|
|
|
|
processMethod = that.processQuickSearchQueryResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
params['menu'] = thisForm.elements['menu'].value;
|
|
|
|
params['menu-settings-column-nonce'] = thisForm.elements['menu-settings-column-nonce'].value;
|
|
|
|
|
|
|
|
$.post( ajaxurl, params, function(menuMarkup) {
|
|
|
|
processMethod.call(that, menuMarkup, params);
|
2010-05-02 17:05:55 -04:00
|
|
|
$(thisForm).find('img.waiting').hide();
|
2010-03-22 15:56:16 -04:00
|
|
|
});
|
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-03-22 15:56:16 -04:00
|
|
|
/**
|
2010-04-26 21:05:58 -04:00
|
|
|
* Process the add menu item request response into menu list item.
|
2010-03-22 15:56:16 -04:00
|
|
|
*
|
2010-04-26 21:05:58 -04:00
|
|
|
* @param string menuMarkup The text server response of menu item markup.
|
|
|
|
* @param object req The request arguments.
|
2010-03-22 15:56:16 -04:00
|
|
|
*/
|
2010-04-26 21:05:58 -04:00
|
|
|
processAddMenuItemResponse : function( menuMarkup, req ) {
|
2010-05-02 15:09:10 -04:00
|
|
|
$(menuMarkup).hideAdvancedMenuItemFields().appendTo( menuList );
|
2010-04-28 14:30:32 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
/* set custom link form back to defaults */
|
2010-04-28 23:43:11 -04:00
|
|
|
$('#custom-menu-item-name').val('').blur();
|
|
|
|
$('#custom-menu-item-url').val('http://');
|
2010-03-17 12:13: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
|
|
|
|
*
|
|
|
|
* @param string resp The server response to the query.
|
|
|
|
* @param object req The request arguments.
|
2010-03-22 15:56:16 -04:00
|
|
|
*/
|
2010-04-26 21:05:58 -04: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 16:44:08 -04:00
|
|
|
message,
|
2010-04-26 21:05:58 -04: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-03-22 15:56:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
items = wrap.getElementsByTagName('li');
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04: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 16:44:08 -04: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-26 21:05:58 -04:00
|
|
|
if ( resultList ) {
|
|
|
|
i = items.length;
|
2010-04-28 16:44:08 -04:00
|
|
|
if ( ! i ) {
|
|
|
|
message = document.createElement('li');
|
|
|
|
message.appendChild(document.createTextNode(navMenuL10n.noResultsFound));
|
|
|
|
resultList.appendChild(message);
|
|
|
|
}
|
2010-04-26 21:05:58 -04:00
|
|
|
while( i-- ) {
|
|
|
|
resultList.appendChild(items[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2010-03-22 15:56:16 -04:00
|
|
|
|
2010-04-26 21:05:58 -04:00
|
|
|
removeMenuItem : function(el) {
|
2010-05-02 15:09:10 -04:00
|
|
|
el = $(el)
|
|
|
|
var children = el.childMenuItems();
|
2010-04-26 21:05:58 -04:00
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
el.addClass('deleting').fadeOut( 350 , function() {
|
|
|
|
el.remove();
|
|
|
|
children.shiftDepthClass(-1).updateParentMenuItemDBId();
|
|
|
|
recalculateMenuItemPositions();
|
|
|
|
});
|
2010-03-17 12:13:16 -04:00
|
|
|
}
|
|
|
|
}
|
2010-04-26 21:05:58 -04:00
|
|
|
}
|
|
|
|
|
2010-05-02 15:09:10 -04:00
|
|
|
var wpNavMenu = new WPNavMenuHandler(jQuery);
|
2010-04-26 21:05:58 -04:00
|
|
|
|
|
|
|
jQuery(function() {
|
|
|
|
wpNavMenu.init();
|
|
|
|
});
|