/** * WordPress Administration Custom Navigation * Interface JS functions * * @version 1.1.0 * * @package WordPress * @subpackage Administration */ /** * Adds a link to the available links section * * @param object e - An object recieved via ajax */ function wp_update_links_list(e) { var link = '
  • '; // Prepend the link to the available links section jQuery('#available-links .list').prepend( link ); // Give feedback to the user jQuery('#available-links .list #link-' + e.link_id).parent().animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); } /** * Populate the thickbox window with the selected menu items * * @param int o - the id of the menu li to edit. */ function wp_edit_menu_item( id ) { var itemType = jQuery('#item-type' + id).val(); var itemTitle = jQuery('#item-title' + id).val(); var itemURL = jQuery('#item-url' + id).val(); var itemAttrTitle = jQuery('#item-attr-title' + id).val(); var itemTarget = jQuery('#item-target' + id).val(); var itemDesc = jQuery('#item-description' + id).val(); // Disable the ability to edit the url for page and category items if ( 'page' == itemType || 'category' == itemType ) jQuery( '#edit-item-url' ).attr('disabled', 'disabled' ); // Populate the fields for thickbox jQuery( '#edit-item-id' ).val(id); jQuery( '#edit-item-title' ).val(itemTitle); jQuery( '#edit-item-url' ).val(itemURL); jQuery( '#edit-item-attr-title' ).val(itemAttrTitle); jQuery( '#edit-item-target' ).val(itemTarget); jQuery( "#edit-item-target option[value='" + itemTarget + "']" ).attr('selected', 'selected'); jQuery( '#edit-item-description' ).val(itemDesc); }; /** * Update the values for the menu item being editing */ function wp_update_menu_item() { var id = jQuery('#edit-item-id').val(); var itemTitle = jQuery('#edit-item-title').val(); var itemURL = jQuery('#edit-item-url').val(); var itemAttrTitle = jQuery('#edit-item-attr-title').val(); var itemTarget = jQuery('#edit-item-target').val(); var itemDesc = jQuery('#edit-item-description').val(); // update menu item settings jQuery('#menu-' + id).find('.item-title:first').html(itemTitle); jQuery('#item-title' + id).val(itemTitle); jQuery('#item-url' + id).val(itemURL); jQuery('#item-attr-title' + id).val(itemAttrTitle); jQuery('#item-target' + id).val(itemTarget); jQuery('#item-description' + id).val(itemDesc); } /** * Removes a menu item from current menu * * @param int o - the id of the menu li to remove. */ function wp_remove_menu_item( o ) { var todelete = document.getElementById('menu-' + o); if ( todelete ) { // Give some feedback to the user jQuery( todelete ).find('dt').each(function(){ jQuery(this).animate( { backgroundColor: '#FF3333' }, { duration: 'normal', complete: function() { jQuery(this).parent().parent().remove() } } ); }); wp_update_post_data(); } }; /** * Prepares menu items for POST */ function wp_update_post_data() { var i = 0; jQuery('.menu li').each(function(i) { i = i + 1; var j = jQuery(this).attr('value'); jQuery(this).find('#item-position' + j).attr('value', i); jQuery(this).attr('id','menu-' + i); jQuery(this).attr('value', i); jQuery(this).find('#item-dbid' + j).attr('name','item-dbid' + i); jQuery(this).find('#item-dbid' + j).attr('id','item-dbid' + i); jQuery(this).find('#item-postmenu' + j).attr('name','item-postmenu' + i); jQuery(this).find('#item-postmenu' + j).attr('id','item-postmenu' + i); var p = jQuery(this).find('#item-parent' + j).parent().parent().parent().attr('value'); jQuery(this).find('#item-parent' + j).attr('name','item-parent' + i); jQuery(this).find('#item-parent' + j).attr('id','item-parent' + i); if (p) { // Do nothing } else { // reset p to be top level p = 0; } jQuery(this).find('#item-parent' + j).attr('value', p); jQuery(this).find('#item-title' + j).attr('name','item-title' + i); jQuery(this).find('#item-title' + j).attr('id','item-title' + i); jQuery(this).find('#item-url' + j).attr('name','item-url' + i); jQuery(this).find('#item-url' + j).attr('id','item-url' + i); jQuery(this).find('#item-description' + j).attr('name','item-description' + i); jQuery(this).find('#item-description' + j).attr('id','item-description' + i); jQuery(this).find('#item-attr-title' + j).attr('name','item-attr-title' + i); jQuery(this).find('#item-attr-title' + j).attr('id','item-attr-title' + i); jQuery(this).find('#item-target' + j).attr('name','item-target' + i); jQuery(this).find('#item-target' + j).attr('id','item-target' + i); jQuery(this).find('#item-position' + j).attr('name', 'item-position' + i); jQuery(this).find('#item-position' + j).attr('id', 'item-position' + i); jQuery(this).find('#item-type' + j).attr('name', 'item-type' + i); jQuery(this).find('#item-type' + j).attr('id', 'item-type' + i); jQuery('#li-count').attr( 'value', i ); }); }; /** * Adds the item to the menu * * @param string id - The menu item's id * @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 wp_add_item_to_menu( item_type, item_title, item_url, item_id, item_parent_id, item_description ) { var randomnumber = wp_get_unique_menu_id(); // Adds the item in the queue jQuery('.menu').append(''); // Give some feedback to the user jQuery( '.menu #menu-' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); // Enable drag-n-drop wp_drag_and_drop(); wp_update_post_data(); // Reload thickbox tb_init('a.thickbox, area.thickbox, input.thickbox'); }; /* * Queues items in perperation for appendToList * * @param string type - Page, Category, or Custom. * @param string link - menu text. * @param string url - url of the menu. * @param int id - menu id. * @param int parent_id - default 0. * @param string description - the description of the menu item. */ function wp_update_queue( e, item_type, item_title, item_url, item_id, item_parent_id, item_description ) { var randomnumber = wp_get_unique_menu_id(); var menu_item_id = jQuery(e).attr('id'); if ( jQuery(e).attr('checked') ) { // Add menu item to the queue jQuery('#queue').append(''); } else { // Remove the item from the queue if ( menu_item_id == jQuery('#queue li input[name^="item-id"]' ).val() ) { jQuery('#queue li input[name^="item-id"]' ).parent().remove() }; }; }; /** * Grabs items from the queue and adds them to the menu. * * @param string button - a reference of the button that was clicked */ function wp_add_queued_items_to_menu( button ) { // Grab items in queue var items = jQuery('#queue').children(); // Empty Queue jQuery('#queue').empty(); // Appends HTML to the menu jQuery('.menu').append( items ); // Give some feedback to the user jQuery(items).each(function(){ jQuery(this).find('dt').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); }); // Uncheck the checkboxes in the list jQuery(button).offsetParent().find('.list-container input').attr('checked', false); wp_update_post_data(); // Enable drag-n-drop wp_drag_and_drop(); // Reload thickbox tb_init('a.thickbox, area.thickbox, input.thickbox'); }; /** * Allow the items in the Menu to be dragged and dropped. */ function wp_drag_and_drop() { // Make sure all li's have dropzones jQuery('.menu li').each(function(){ if ( !jQuery(this).children('.dropzone').attr('class') ) { jQuery(this).prepend('
    '); }; }); // make menu item draggable jQuery('.menu li').draggable({ handle: ' > dl', opacity: .8, addClasses: false, helper: 'clone', zIndex: 100, }); // make menu item droppable jQuery('.menu li dl, .menu li .dropzone').droppable({ accept: '.menu li', tolerance: 'pointer', drop: function(e, ui) { var li = jQuery(this).parent(); var child = !jQuery(this).hasClass('dropzone'); // Append UL to first child if ( child && li.children('ul').length == 0 ) { li.append( '