2010-02-20 22:57:43 +01:00
|
|
|
/**
|
|
|
|
* WordPress Administration Custom Navigation
|
|
|
|
* Interface JS functions
|
|
|
|
*
|
|
|
|
* @version 1.1.0
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
/*
|
|
|
|
* Removes menu items from current menu
|
|
|
|
* @param int o - the id of the menu li to remove.
|
|
|
|
*/
|
2010-02-21 01:03:42 +01:00
|
|
|
function removeitem(o)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
var todelete = document.getElementById('menu-' + o);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
if (todelete)
|
2010-02-21 01:03:42 +01:00
|
|
|
{
|
2010-02-20 22:57:43 +01:00
|
|
|
var parenttodelete = document.getElementById('menu-' + o).parentNode;
|
2010-02-21 01:03:42 +01:00
|
|
|
throwaway_node = parenttodelete.removeChild(todelete);
|
|
|
|
}
|
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
updatepostdata();
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loads dialog window to edit menu items from current menu
|
|
|
|
* @param int o - the id of the menu li to edit.
|
|
|
|
*/
|
2010-02-21 01:03:42 +01:00
|
|
|
function edititem(o)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-24 23:52:29 +01:00
|
|
|
itemTitle = jQuery('#title' + o).val();
|
|
|
|
itemURL = jQuery('#linkurl' + o).val();
|
|
|
|
itemAnchorTitle = jQuery('#anchortitle' + o).val();
|
|
|
|
itemNewWindow = jQuery('#newwindow' + o).val();
|
|
|
|
itemDesc = jQuery('#description' + o).val();
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery('#dialog-confirm').dialog( 'option' , 'itemID' , o )
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery('#dialog-confirm').dialog('open');
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-24 23:52:29 +01:00
|
|
|
jQuery('#edittitle').val( itemTitle );
|
|
|
|
if ( 'custom' == jQuery( '#linktype' + o ).val() ) {
|
|
|
|
jQuery( '#editlink-wrap' ).css( 'display', 'inline' );
|
|
|
|
} else {
|
|
|
|
jQuery( '#editlink-wrap' ).css( 'display', 'none' );
|
|
|
|
}
|
|
|
|
jQuery('#editlink').val( itemURL );
|
|
|
|
jQuery('#editanchortitle').val( itemAnchorTitle );
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery("#editnewwindow option[value='" + itemNewWindow + "']").attr('selected', 'selected');
|
2010-02-24 23:52:29 +01:00
|
|
|
jQuery('#editdescription').val( itemDesc );
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepares menu items for POST
|
|
|
|
*/
|
2010-02-21 01:03:42 +01:00
|
|
|
function updatepostdata()
|
|
|
|
{
|
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
var i = 0;
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery("#custom-nav").find("li").each(function(i) {
|
2010-02-20 22:57:43 +01:00
|
|
|
i = i + 1;
|
2010-02-21 00:58:00 +01:00
|
|
|
var j = jQuery(this).attr('value');
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#position' + j).attr('value', i);
|
|
|
|
jQuery(this).attr('id','menu-' + i);
|
|
|
|
jQuery(this).attr('value', i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#dbid' + j).attr('name','dbid' + i);
|
|
|
|
jQuery(this).find('#dbid' + j).attr('id','dbid' + i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#postmenu' + j).attr('name','postmenu' + i);
|
|
|
|
jQuery(this).find('#postmenu' + j).attr('id','postmenu' + i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
var p = jQuery(this).find('#parent' + j).parent().parent().parent().attr('value');
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#parent' + j).attr('name','parent' + i);
|
|
|
|
jQuery(this).find('#parent' + j).attr('id','parent' + i);
|
2010-02-20 22:57:43 +01:00
|
|
|
if (p) {
|
|
|
|
//Do nothing
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//reset p to be top level
|
|
|
|
p = 0;
|
|
|
|
}
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#parent' + j).attr('value', p);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#title' + j).attr('name','title' + i);
|
|
|
|
jQuery(this).find('#title' + j).attr('id','title' + i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#linkurl' + j).attr('name','linkurl' + i);
|
|
|
|
jQuery(this).find('#linkurl' + j).attr('id','linkurl' + i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#description' + j).attr('name','description' + i);
|
|
|
|
jQuery(this).find('#description' + j).attr('id','description' + i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#icon' + j).attr('name','icon' + i);
|
|
|
|
jQuery(this).find('#icon' + j).attr('id','icon' + i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#position' + j).attr('name','position' + i);
|
|
|
|
jQuery(this).find('#position' + j).attr('id','position' + i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#linktype' + j).attr('name','linktype' + i);
|
|
|
|
jQuery(this).find('#linktype' + j).attr('id','linktype' + i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#anchortitle' + j).attr('name','anchortitle' + i);
|
|
|
|
jQuery(this).find('#anchortitle' + j).attr('id','anchortitle' + i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('#newwindow' + j).attr('name','newwindow' + i);
|
|
|
|
jQuery(this).find('#newwindow' + j).attr('id','newwindow' + i);
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).find('dl > dt > span > #remove' + j).attr('value', i);
|
|
|
|
jQuery(this).find('dl > dt > span > #remove' + j).attr('onClick', 'removeitem(' + i + ')');
|
|
|
|
jQuery(this).find('dl > dt > span > #remove' + j).attr('id','remove' + i);
|
2010-02-20 22:57:43 +01:00
|
|
|
|
2010-02-24 19:52:54 +01:00
|
|
|
jQuery('#li-count').attr('value',i);
|
2010-02-20 22:57:43 +01:00
|
|
|
|
|
|
|
});
|
2010-02-21 01:03:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
2010-02-20 22:57:43 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Adds item from Page, Category, or Custom options menu
|
|
|
|
* @param string templatedir - directory of the add, edit, view images.
|
|
|
|
* @param string additemtype - Page, Category, or Custom.
|
|
|
|
* @param string itemtext - menu text.
|
|
|
|
* @param string itemurl - url of the menu.
|
|
|
|
* @param int itemid - menu id.
|
|
|
|
* @param int itemparentid - default 0.
|
|
|
|
* @param string itemdescription - the description of the menu item.
|
2010-02-21 01:03:42 +01:00
|
|
|
*/
|
|
|
|
function appendToList(templatedir,additemtype,itemtext,itemurl,itemid,itemparentid,itemdescription)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
var inputvaluevarname = '';
|
|
|
|
var inputvaluevarurl = '';
|
|
|
|
var inputitemid = '';
|
|
|
|
var inputparentid= '';
|
|
|
|
var inputdescription = '';
|
|
|
|
var inputicon = '';
|
|
|
|
|
2010-02-24 19:52:54 +01:00
|
|
|
if (additemtype == navMenuL10n.custom)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
2010-02-24 19:52:54 +01:00
|
|
|
inputvaluevarname = document.getElementById('custom-menu-item-name').value;
|
|
|
|
inputvaluevarurl = document.getElementById('custom-menu-item-url').value;
|
2010-02-20 22:57:43 +01:00
|
|
|
inputitemid = '';
|
|
|
|
inputparentid = '';
|
|
|
|
inputlinktype = 'custom';
|
2010-02-24 19:52:54 +01:00
|
|
|
inputdescription = '';
|
2010-02-20 22:57:43 +01:00
|
|
|
}
|
2010-02-24 19:52:54 +01:00
|
|
|
else if (additemtype == navMenuL10n.page)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
inputvaluevarname = htmlentities(itemtext.toString());
|
|
|
|
inputvaluevarurl = itemurl.toString();
|
|
|
|
inputitemid = itemid.toString();
|
|
|
|
inputparentid = '0';
|
|
|
|
inputlinktype = 'page';
|
|
|
|
inputdescription = htmlentities(itemdescription.toString());
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
}
|
2010-02-24 19:52:54 +01:00
|
|
|
else if (additemtype == navMenuL10n.category)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
inputvaluevarname = htmlentities(itemtext.toString());
|
|
|
|
inputvaluevarurl = itemurl.toString();
|
|
|
|
inputitemid = itemid.toString();
|
|
|
|
inputparentid = '0';
|
|
|
|
inputlinktype = 'category';
|
|
|
|
inputdescription = htmlentities(itemdescription.toString());
|
|
|
|
}
|
2010-02-21 01:03:42 +01:00
|
|
|
else
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
inputvaluevarname = '';
|
|
|
|
inputvaluevarname = '';
|
|
|
|
inputitemid = '';
|
|
|
|
inputparentid = '';
|
|
|
|
inputlinktype = 'custom';
|
|
|
|
inputdescription = '';
|
|
|
|
}
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-24 08:58:14 +01:00
|
|
|
var count=document.getElementById('custom-nav').getElementsByTagName('li').length + 1;
|
2010-02-20 22:57:43 +01:00
|
|
|
|
|
|
|
var randomnumber = count;
|
|
|
|
|
|
|
|
var validatetest = 0;
|
|
|
|
|
2010-02-21 01:03:42 +01:00
|
|
|
try
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
var test=document.getElementById("menu-" + randomnumber.toString()).value;
|
|
|
|
}
|
2010-02-21 01:03:42 +01:00
|
|
|
catch (err)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
validatetest = 1;
|
|
|
|
}
|
|
|
|
|
2010-02-21 01:03:42 +01:00
|
|
|
while (validatetest == 0)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
randomnumber = randomnumber + 1;
|
|
|
|
|
2010-02-21 01:03:42 +01:00
|
|
|
try
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
var test2=document.getElementById("menu-" + randomnumber.toString()).value;
|
|
|
|
}
|
2010-02-21 01:03:42 +01:00
|
|
|
catch (err)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
validatetest = 1;
|
|
|
|
}
|
|
|
|
}
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
//Notification Message
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery('.maintitle').after('<div id="message" class="updated fade below-h2"><p>Menu Item added!</p></div>');
|
|
|
|
jQuery('#message').animate({ opacity: 1.0 },2000).fadeOut(300, function(){ jQuery(this).remove();});
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
//Appends HTML to the menu
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery('#custom-nav').append('<li id="menu-' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="title">' + inputvaluevarname + '</span><span class="controls"><span class="type">' + additemtype + '</span><a id="edit' + randomnumber + '" onclick="edititem(' + randomnumber + ')" value="' + randomnumber +'"><img class="edit" alt="Edit Menu Item" title="Edit Menu Item" src="' + templatedir + '/wp-admin/images/ico-edit.png" /></a> <a id="remove' + randomnumber + '" onclick="removeitem(' + randomnumber + ')" value="' + randomnumber +'"><img class="remove" alt="Remove from Custom Menu" title="Remove from Custom Menu" src="' + templatedir + '/wp-admin/images/ico-close.png" /></a> <a href="' + inputvaluevarurl + '" target="_blank"><img alt="View Custom Link" title="View Custom Link" src="' + templatedir + '/wp-admin/images/ico-viewpage.png" /></a></span></dt></dl><a class="hide" href="' + inputvaluevarurl + '">' + inputvaluevarname + '</a><input type="hidden" name="postmenu' + randomnumber + '" id="postmenu' + randomnumber + '" value="' + inputitemid + '" /><input type="hidden" name="parent' + randomnumber + '" id="parent' + randomnumber + '" value="' + inputparentid + '" /><input type="hidden" name="title' + randomnumber + '" id="title' + randomnumber + '" value="' + inputvaluevarname + '" /><input type="hidden" name="linkurl' + randomnumber + '" id="linkurl' + randomnumber + '" value="' + inputvaluevarurl + '" /><input type="hidden" name="description' + randomnumber + '" id="description' + randomnumber + '" value="' + inputdescription + '" /><input type="hidden" name="icon' + randomnumber + '" id="icon' + randomnumber + '" value="' + inputicon + '" /><input type="hidden" name="position' + randomnumber + '" id="position' + randomnumber + '" value="' + randomnumber + '" /><input type="hidden" name="linktype' + randomnumber + '" id="linktype' + randomnumber + '" value="' + inputlinktype + '" /><input type="hidden" name="anchortitle' + randomnumber + '" id="anchortitle' + randomnumber + '" value="' + inputvaluevarname + '" /><input type="hidden" name="newwindow' + randomnumber + '" id="newwindow' + randomnumber + '" value="0" /></li>');
|
2010-02-20 22:57:43 +01:00
|
|
|
|
|
|
|
//make menu item draggable
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery('#menu-' + randomnumber + '').draggable(
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
handle: ' > dl',
|
|
|
|
opacity: .8,
|
|
|
|
addClasses: false,
|
|
|
|
helper: 'clone',
|
|
|
|
zIndex: 100
|
|
|
|
});
|
|
|
|
|
|
|
|
//make menu item droppable
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery('#menu-' + randomnumber + ' dl, #menu-' + randomnumber + ' .dropzone').droppable({
|
2010-02-20 22:57:43 +01:00
|
|
|
accept: '#' + randomnumber + ', #custom-nav li',
|
|
|
|
tolerance: 'pointer',
|
2010-02-21 01:03:42 +01:00
|
|
|
drop: function(e, ui)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
2010-02-21 00:58:00 +01:00
|
|
|
var li = jQuery(this).parent();
|
|
|
|
var child = !jQuery(this).hasClass('dropzone');
|
2010-02-20 22:57:43 +01:00
|
|
|
//Append UL to first child
|
2010-02-21 01:03:42 +01:00
|
|
|
if (child && li.children('ul').length == 0)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
li.append('<ul/>');
|
|
|
|
}
|
|
|
|
//Make it draggable
|
2010-02-21 01:03:42 +01:00
|
|
|
if (child)
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
li.children('ul').append(ui.draggable);
|
|
|
|
}
|
2010-02-21 01:03:42 +01:00
|
|
|
else
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
li.before(ui.draggable);
|
|
|
|
}
|
2010-02-21 01:03:42 +01:00
|
|
|
|
|
|
|
li.find('dl,.dropzone').css({ backgroundColor: '', borderColor: '' });
|
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
var draggablevalue = ui.draggable.attr('value');
|
|
|
|
var droppablevalue = li.attr('value');
|
2010-02-21 01:03:42 +01:00
|
|
|
li.find('#menu-' + draggablevalue).find('#parent' + draggablevalue).val(droppablevalue);
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).parent().find("dt").removeAttr('style');
|
|
|
|
jQuery(this).parent().find("div:first").removeAttr('style');
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
},
|
2010-02-21 01:03:42 +01:00
|
|
|
over: function()
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
|
|
|
//Add child
|
2010-02-21 01:03:42 +01:00
|
|
|
if (jQuery(this).attr('class') == 'dropzone ui-droppable')
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).parent().find("div:first").css('background', 'none').css('height', '50px');
|
2010-02-20 22:57:43 +01:00
|
|
|
}
|
|
|
|
//Add above
|
2010-02-21 01:03:42 +01:00
|
|
|
else if (jQuery(this).attr('class') == 'ui-droppable')
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).parent().find("dt:first").css('background', '#d8d8d8');
|
2010-02-20 22:57:43 +01:00
|
|
|
}
|
|
|
|
//do nothing
|
|
|
|
else {
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
}
|
2010-02-21 00:58:00 +01:00
|
|
|
var parentid = jQuery(this).parent().attr('id');
|
2010-02-21 01:03:42 +01:00
|
|
|
|
2010-02-20 22:57:43 +01:00
|
|
|
},
|
2010-02-21 01:03:42 +01:00
|
|
|
out: function()
|
2010-02-20 22:57:43 +01:00
|
|
|
{
|
2010-02-21 00:58:00 +01:00
|
|
|
jQuery(this).parent().find("dt").removeAttr('style');
|
|
|
|
jQuery(this).parent().find("div:first").removeAttr('style');
|
|
|
|
jQuery(this).filter('.dropzone').css({ borderColor: '' });
|
2010-02-20 22:57:43 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
updatepostdata();
|
|
|
|
};
|