/** * WordPress Administration Custom Navigation * Interface JS functions * * @author Jeffikus * @version 1.1.0 * * @package WordPress * @subpackage Administration */ /* * Removes menu items from current menu * @param int o - the id of the menu li to remove. */ function removeitem(o) { var todelete = document.getElementById('menu-' + o); if (todelete) { var parenttodelete = document.getElementById('menu-' + o).parentNode; throwaway_node = parenttodelete.removeChild(todelete); } updatepostdata(); }; /* * Loads dialog window to edit menu items from current menu * @param int o - the id of the menu li to edit. */ function edititem(o) { itemTitle = $('#title' + o).attr('value'); itemURL = $('#linkurl' + o).attr('value'); itemAnchorTitle = $('#anchortitle' + o).attr('value'); itemNewWindow = $('#newwindow' + o).attr('value'); itemDesc = $('#description' + o).attr('value'); $('#dialog-confirm').dialog( 'option' , 'itemID' , o ) $('#dialog-confirm').dialog('open'); $('#edittitle').attr('value', itemTitle); $('#editlink').attr('value', itemURL); $('#editanchortitle').attr('value', itemAnchorTitle); $("#editnewwindow option[value='" + itemNewWindow + "']").attr('selected', 'selected'); $('#editdescription').attr('value', itemDesc); }; /* * Prepares menu items for POST */ function updatepostdata() { var i = 0; $("#custom-nav").find("li").each(function(i) { i = i + 1; var j = $(this).attr('value'); $(this).find('#position' + j).attr('value', i); $(this).attr('id','menu-' + i); $(this).attr('value', i); $(this).find('#dbid' + j).attr('name','dbid' + i); $(this).find('#dbid' + j).attr('id','dbid' + i); $(this).find('#postmenu' + j).attr('name','postmenu' + i); $(this).find('#postmenu' + j).attr('id','postmenu' + i); var p = $(this).find('#parent' + j).parent().parent().parent().attr('value'); $(this).find('#parent' + j).attr('name','parent' + i); $(this).find('#parent' + j).attr('id','parent' + i); if (p) { //Do nothing } else { //reset p to be top level p = 0; } $(this).find('#parent' + j).attr('value', p); $(this).find('#title' + j).attr('name','title' + i); $(this).find('#title' + j).attr('id','title' + i); $(this).find('#linkurl' + j).attr('name','linkurl' + i); $(this).find('#linkurl' + j).attr('id','linkurl' + i); $(this).find('#description' + j).attr('name','description' + i); $(this).find('#description' + j).attr('id','description' + i); $(this).find('#icon' + j).attr('name','icon' + i); $(this).find('#icon' + j).attr('id','icon' + i); $(this).find('#position' + j).attr('name','position' + i); $(this).find('#position' + j).attr('id','position' + i); $(this).find('#linktype' + j).attr('name','linktype' + i); $(this).find('#linktype' + j).attr('id','linktype' + i); $(this).find('#anchortitle' + j).attr('name','anchortitle' + i); $(this).find('#anchortitle' + j).attr('id','anchortitle' + i); $(this).find('#newwindow' + j).attr('name','newwindow' + i); $(this).find('#newwindow' + j).attr('id','newwindow' + i); $(this).find('dl > dt > span > #remove' + j).attr('value', i); $(this).find('dl > dt > span > #remove' + j).attr('onClick', 'removeitem(' + i + ')'); $(this).find('dl > dt > span > #remove' + j).attr('id','remove' + i); $('#licount').attr('value',i); }); }; /* * 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. */ function appendToList(templatedir,additemtype,itemtext,itemurl,itemid,itemparentid,itemdescription) { var inputvaluevarname = ''; var inputvaluevarurl = ''; var inputitemid = ''; var inputparentid= ''; var inputdescription = ''; var inputicon = ''; if (additemtype == 'Custom') { inputvaluevarname = document.getElementById('custom_menu_item_name').value; inputvaluevarurl = document.getElementById('custom_menu_item_url').value; inputitemid = ''; inputparentid = ''; inputlinktype = 'custom'; inputdescription = document.getElementById('custom_menu_item_description').value; } else if (additemtype == 'Page') { inputvaluevarname = htmlentities(itemtext.toString()); inputvaluevarurl = itemurl.toString(); inputitemid = itemid.toString(); inputparentid = '0'; inputlinktype = 'page'; inputdescription = htmlentities(itemdescription.toString()); } else if (additemtype == 'Category') { inputvaluevarname = htmlentities(itemtext.toString()); inputvaluevarurl = itemurl.toString(); inputitemid = itemid.toString(); inputparentid = '0'; inputlinktype = 'category'; inputdescription = htmlentities(itemdescription.toString()); } else { inputvaluevarname = ''; inputvaluevarname = ''; inputitemid = ''; inputparentid = ''; inputlinktype = 'custom'; inputdescription = ''; } var count=document.getElementById('custom-nav').getElementsByTagName('li').length; var randomnumber = count; var validatetest = 0; try { var test=document.getElementById("menu-" + randomnumber.toString()).value; } catch (err) { validatetest = 1; } while (validatetest == 0) { randomnumber = randomnumber + 1; try { var test2=document.getElementById("menu-" + randomnumber.toString()).value; } catch (err) { validatetest = 1; } } //Notification Message $('.maintitle').after('

Menu Item added!

'); $('#message').animate({ opacity: 1.0 },2000).fadeOut(300, function(){ $(this).remove();}); //Appends HTML to the menu $('#custom-nav').append(''); //make menu item draggable $('#menu-' + randomnumber + '').draggable( { handle: ' > dl', opacity: .8, addClasses: false, helper: 'clone', zIndex: 100 }); //make menu item droppable $('#menu-' + randomnumber + ' dl, #menu-' + randomnumber + ' .dropzone').droppable({ accept: '#' + randomnumber + ', #custom-nav li', tolerance: 'pointer', drop: function(e, ui) { var li = $(this).parent(); var child = !$(this).hasClass('dropzone'); //Append UL to first child if (child && li.children('ul').length == 0) { li.append('