Menu enhancements. Props ptahdunbar. fixes #11817

git-svn-id: http://svn.automattic.com/wordpress/trunk@13512 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-02-28 20:00:49 +00:00
parent 45325c3d41
commit 25a2a06a9e
12 changed files with 560 additions and 711 deletions

View File

@ -1 +1 @@
#menu-management{clear:both;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{color:#f00;text-decoration:underline;font-size:11px;float:left;margin-top:5px;}.submitdelete:hover{background-color:#F00;color:#fff;}.save{float:right;}.button-controls{float:left;}.add-to-menu{float:right;}#create-menu-name{width:159px;}#available-links{margin:15px 0 0;}#available-links dt{display:block;}#add-custom-link .howto{font-size:11px;}#add-custom-link label span{display:block;float:left;margin-top:5px;padding-right:5px;}#menu-item-url,#menu-item-name{float:right;width:220px;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;}.list-container{max-height:200px;overflow-y:auto;padding:10px 10px 5px;border:1px solid #DFDFDF;-moz-border-radius:4px;}.postbox p.submit{margin-bottom:0;}.list li{margin:0;}.list dt{display:none;margin:0;overflow:hidden;margin-bottom:5px;}.list li .item-title{cursor:pointer;display:block;}.list li .item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .item-title{margin-left:14px;}.list li ul li ul li .item-title{margin-left:28px;}.list li ul li ul li ul li .item-title{margin-left:42px;}.list li ul li ul li ul li ul li .item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .item-title{margin-left:112px;}#menu-container .inside{padding-bottom:10px;}#menu ul{width:100%;}#menu li{margin:0;}#menu li dl dt{-webkit-border-bottom-left-radius:6px;-webkit-border-bottom-right-radius:6px;-webkit-border-top-left-radius:6px;-webkit-border-top-right-radius:6px;border-bottom-left-radius:6px;border-bottom-right-radius:6px;border-top-left-radius:6px;border-top-right-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-bottomright:6px;-moz-border-radius-topleft:6px;-moz-border-radius-topright:6px;border:1px solid #E6E6E6;position:relative;padding-left:10px;background-color:#f1f1f1;height:35px;line-height:35px;}#menu li dl dt:hover{cursor:move;}#menu li .item-title{background:url(../images/ico-arrow.png) no-repeat 4px 5px;background-position:center left;padding-left:15px;}#menu li ul li{margin-left:20px;opacity:.7;}#menu li ul li ul li{opacity:.9;}#menu li ul li ul li ul li{opacity:.9;}#menu li ul li ul li ul li ul li{opacity:.95;}.dropzone{height:7px;margin:3px 0 3px 0;}.ui-draggable-dragging{width:600px;}.item-type{text-transform:uppercase;font-size:11px;color:#999;padding-right:10px;}.item-controls{font-size:11px;position:absolute;right:15px;top:-1px;}.item-controls a{text-decoration:none;}.item-controls a:hover{cursor:pointer;}.item-controls .item-delete:hover{color:#f00;}#menu-item-settings{display:none;}#cancel-save{cursor:pointer;}#cancel-save:hover{color:#fff!important;}#update-menu-item{color:#fff!important;}#update-menu-item:hover,#update-menu-item:active,#update-menu-item:focus{color:#eaf2fa!important;border-color:#13455b!important;}.hide{display:none;}
#menu-management{clear:both;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{color:#f00;text-decoration:underline;font-size:11px;float:left;margin-top:5px;}.submitdelete:hover{background-color:#F00;color:#fff;}.save{float:right;}.button-controls{float:left;}.add-to-menu{float:right;}#create-menu-name{width:159px;}#available-links{margin:15px 0 0;}#available-links dt{display:block;}#add-custom-link .howto{font-size:11px;}#add-custom-link label span{display:block;float:left;margin-top:5px;padding-right:5px;}#menu-item-url,#menu-item-name{float:right;width:220px;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;}.list-container{max-height:200px;overflow-y:auto;padding:10px 10px 5px;border:1px solid #DFDFDF;-moz-border-radius:4px;}.postbox p.submit{margin-bottom:0;}.list li{display:none;margin:0;margin-bottom:5px;}.list li .item-title{cursor:pointer;display:block;}.list li .item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .item-title{margin-left:14px;}.list li ul li ul li .item-title{margin-left:28px;}.list li ul li ul li ul li .item-title{margin-left:42px;}.list li ul li ul li ul li ul li .item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .item-title{margin-left:112px;}#menu-container .inside{padding-bottom:10px;}.menu ul{width:100%;}.menu li{margin:0;}.menu li dl dt{-webkit-border-bottom-left-radius:6px;-webkit-border-bottom-right-radius:6px;-webkit-border-top-left-radius:6px;-webkit-border-top-right-radius:6px;border-bottom-left-radius:6px;border-bottom-right-radius:6px;border-top-left-radius:6px;border-top-right-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-bottomright:6px;-moz-border-radius-topleft:6px;-moz-border-radius-topright:6px;border:1px solid #E6E6E6;position:relative;padding-left:10px;background-color:#f1f1f1;height:35px;line-height:35px;}.menu li dl dt:hover{cursor:move;}.menu li .item-title{background:url(../images/ico-arrow.png) no-repeat 4px 5px;background-position:center left;padding-left:15px;}.menu li ul li{margin-left:20px;opacity:.7;}.menu li ul li ul li{opacity:.9;}.menu li ul li ul li ul li{opacity:.9;}.menu li ul li ul li ul li ul li{opacity:.95;}.dropzone{height:7px;margin:3px 0 3px 0;}.ui-draggable-dragging{width:600px;}.item-type{text-transform:uppercase;font-size:11px;color:#999;padding-right:10px;}.item-controls{font-size:11px;position:absolute;right:15px;top:-1px;}.item-controls a{text-decoration:none;}.item-controls a:hover{cursor:pointer;}.item-controls .item-delete:hover{color:#f00;}#menu-item-settings{display:none;}#cancel-save{cursor:pointer;}#cancel-save:hover{color:#fff!important;}#update-menu-item{color:#fff!important;}#update-menu-item:hover,#update-menu-item:active,#update-menu-item:focus{color:#eaf2fa!important;border-color:#13455b!important;}.hide{display:none;}

View File

@ -22,7 +22,7 @@
.button-controls { float: left; }
.add-to-menu { float: right; }
/* CSS for switching the columns *//*
/* CSS for switching the main columns *//*
#menu-settings-column { clear: none; float: left; }
#menu-management #post-body { float: right; margin-left: -340px; margin-right: 0px; }
#menu-management #post-body-content { margin-left: 300px; margin-right: 0px; }
@ -48,8 +48,7 @@
.postbox p.submit { margin-bottom: 0; }
/* Listings */
.list li { margin: 0; }
.list dt { display: none; margin: 0; overflow: hidden; margin-bottom: 5px; }
.list li { display: none; margin: 0; margin-bottom: 5px; }
.list li .item-title { cursor: pointer; display: block; }
.list li .item-title input { margin-right: 3px; margin-top: -3px; }
@ -66,16 +65,16 @@
/* Menu */
#menu-container .inside { padding-bottom: 10px; }
#menu ul { width: 100%; }
#menu li { margin: 0; }
#menu li dl dt { -webkit-border-bottom-left-radius: 6px; -webkit-border-bottom-right-radius: 6px; -webkit-border-top-left-radius: 6px; -webkit-border-top-right-radius: 6px; border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; border-top-left-radius: 6px; border-top-right-radius: 6px; -moz-border-radius-bottomleft: 6px; -moz-border-radius-bottomright: 6px; -moz-border-radius-topleft: 6px; -moz-border-radius-topright: 6px; border: 1px solid #E6E6E6;position: relative; padding-left:10px; background-color: #f1f1f1; height: 35px; line-height: 35px; }
#menu li dl dt:hover { cursor: move; }
.menu ul { width: 100%; }
.menu li { margin: 0; }
.menu li dl dt { -webkit-border-bottom-left-radius: 6px; -webkit-border-bottom-right-radius: 6px; -webkit-border-top-left-radius: 6px; -webkit-border-top-right-radius: 6px; border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; border-top-left-radius: 6px; border-top-right-radius: 6px; -moz-border-radius-bottomleft: 6px; -moz-border-radius-bottomright: 6px; -moz-border-radius-topleft: 6px; -moz-border-radius-topright: 6px; border: 1px solid #E6E6E6;position: relative; padding-left:10px; background-color: #f1f1f1; height: 35px; line-height: 35px; }
.menu li dl dt:hover { cursor: move; }
#menu li .item-title { background: url(../images/ico-arrow.png) no-repeat 4px 5px; background-position: center left; padding-left: 15px; }
#menu li ul li { margin-left: 20px; opacity: .7;}
#menu li ul li ul li { opacity: .9;}
#menu li ul li ul li ul li { opacity: .9;}
#menu li ul li ul li ul li ul li { opacity: .95; }
.menu li .item-title { background: url(../images/ico-arrow.png) no-repeat 4px 5px; background-position: center left; padding-left: 15px; }
.menu li ul li { margin-left: 20px; opacity: .7;}
.menu li ul li ul li { opacity: .9;}
.menu li ul li ul li ul li { opacity: .9;}
.menu li ul li ul li ul li ul li { opacity: .95; }
/* Drag and Drop */
.dropzone { height: 7px; margin: 3px 0 3px 0; }

View File

@ -1,16 +1,72 @@
<?php
/*-----------------------------------------------------------------------------------*/
/* Custom Navigation Functions */
/* wp_custom_navigation_output() displays the menu in the back/frontend
/* wp_custom_nav_get_pages()
/* wp_custom_nav_get_categories()
/* wp_custom_navigation_default_sub_items() is a recursive sub menu item function
/*-----------------------------------------------------------------------------------*/
/**
* Displays a list of links and thier sub items.
*
* @since 3.0.0
*
* @param string $counter
* @param string $context
*/
function wp_nav_menu_get_custom_links( $counter, $context ) {
$available_links = new WP_Query( );
// Outputs All Pages and Sub Items
function wp_nav_menu_get_pages($counter, $type) {
$args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' );
$link_objects = new WP_Query( $args );
$items_counter = $counter;
if ( !$link_objects->posts ) {
_e('Not Found');
return $items_counter;
}
// Display Loop
foreach ( $link_objects->posts as $item ) {
if ( 0 == $item->parent ) {
$item = wp_setup_nav_menu_item( $item, 'item', $items_counter );
switch ( $context ) {
case 'menu':
?>
<li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>">
<?php
echo wp_get_nav_menu_item( $item, 'menu' );
$parentli = $item->ID;
$items_counter++;
$items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'menu' );
?>
</li>
<?php
break;
case 'default':
?>
<li>
<?php
echo wp_get_nav_menu_item( $item, 'default' );
$parentli = $item->ID;
$items_counter++;
$items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'default' );
?>
</li>
<?php
break;
}
}
}
return $items_counter;
}
/**
* Displays a list of pages and thier sub items.
*
* @since 3.0.0
*
* @param string $counter
* @param string $context
*/
function wp_nav_menu_get_pages( $counter, $context ) {
$pages_args = array(
'child_of' => 0,
'sort_order' => 'ASC',
@ -26,8 +82,8 @@ function wp_nav_menu_get_pages($counter, $type) {
'number' => '',
'offset' => 0 );
//GET all pages
$pages_array = get_pages($pages_args);
// Get all pages
$pages_array = get_pages( $pages_args );
$items_counter = $counter;
$parentli = $items_counter;
@ -40,43 +96,45 @@ function wp_nav_menu_get_pages($counter, $type) {
// Display Loop
foreach ( $pages_array as $post ) {
if ( $post->post_parent == 0 ) {
$post = wp_setup_nav_menu_item($post, 'page', $items_counter);
if ( $type == 'menu' ) {
$post = wp_setup_nav_menu_item( $post, 'page', $items_counter );
if ( $context == 'menu' ) {
?>
<li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>">
<?php
wp_print_nav_menu_item($post, 'menu', $items_counter);
echo wp_get_nav_menu_item( $post, 'menu', $items_counter );
$parentli = $post->ID;
$items_counter++;
$items_counter = wp_custom_navigation_default_sub_items($post->ID, $items_counter, $parentli, 'pages', 'menu');
$items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'menu' );
?>
</li>
<?php
} elseif ( $type == 'default' ) {
} elseif ( $context == 'default' ) {
// Sidebar Menu
?>
<li>
<?php
wp_print_nav_menu_item($post, 'default');
echo wp_get_nav_menu_item( $post, 'default' );
$parentli = $post->ID;
$items_counter++;
$items_counter = wp_nav_menu_sub_items($post->ID, $items_counter, $parentli, 'pages', 'default');
$items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'default' );
?>
</li>
<?php
}
}
}
return $items_counter;
}
// Outputs All Categories and Sub Items
function wp_nav_menu_get_categories($counter, $type) {
/**
* Displays a list of categories and thier sub items.
*
* @since 3.0.0
*
* @param string $counter
* @param string $context
*/
function wp_nav_menu_get_categories( $counter, $context ) {
$category_args = array(
'type' => 'post',
'child_of' => 0,
@ -93,7 +151,7 @@ function wp_nav_menu_get_categories($counter, $type) {
$items_counter = $counter;
// Get all categories
$categories_array = get_categories($category_args);
$categories_array = get_categories( $category_args );
if ( !$categories_array ) {
_e('Not Found');
@ -103,46 +161,49 @@ function wp_nav_menu_get_categories($counter, $type) {
// Display Loop
foreach ( $categories_array as $cat_item ) {
if ( $cat_item->parent == 0 ) {
$cat_item = wp_setup_nav_menu_item($cat_item, 'category', $items_counter);
$cat_item = wp_setup_nav_menu_item( $cat_item, 'category', $items_counter );
// Custom Menu
if ( $type == 'menu' ) {
if ( $context == 'menu' ) {
?>
<li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>">
<?php
wp_print_nav_menu_item($cat_item, 'menu');
echo wp_get_nav_menu_item($cat_item, 'menu');
$parentli = $cat_item->cat_ID;
$items_counter++;
$items_counter = wp_nav_menu_sub_items($cat_item->cat_ID, $items_counter, $parentli, 'categories', 'menu');
$items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'menu' );
?>
</li>
<?php
} elseif ( $type == 'default' ) {
} elseif ( $context == 'default' ) {
// Sidebar Menu
?>
<li>
<?php
wp_print_nav_menu_item($cat_item, 'default');
echo wp_get_nav_menu_item( $cat_item, 'default' );
$parentli = $cat_item->cat_ID;
$items_counter++;
$items_counter = wp_nav_menu_sub_items($cat_item->cat_ID, $items_counter, $parentli, 'categories', 'default');
$items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'default' );
?>
</li>
<?php
}
}
}
return $items_counter;
}
//RECURSIVE Sub Menu Items of default categories and pages
function wp_nav_menu_sub_items($childof, $items_counter, $parentli, $type, $output_type) {
/**
* Recursive function that gets sub menu items.
*
* @since 3.0.0
*
* @param string $childof
* @param string $items_counter
* @param string $parentli
* @param string $context
* @param string $output_type
*/
function wp_nav_menu_sub_items( $childof, $items_counter, $parentli, $context, $output_type ) {
$counter = $items_counter;
// Custom Menu
@ -159,11 +220,11 @@ function wp_nav_menu_sub_items($childof, $items_counter, $parentli, $type, $outp
'parent' => $childof);
}
if ( $type == 'categories' ) {
if ( $context == 'categories' ) {
// Get Sub Category Items
$item_type = 'category';
$sub_array = get_categories($sub_args);
} elseif ($type == 'pages') {
} elseif ($context == 'pages') {
// Get Sub Page Items
$item_type = 'page';
$sub_array = get_pages($sub_args);
@ -172,25 +233,21 @@ function wp_nav_menu_sub_items($childof, $items_counter, $parentli, $type, $outp
$sub_array = array();
}
if ( $sub_array ) {
?>
<ul id="sub-menu-<?php echo $type ?>">
<ul id="sub-menu-<?php echo $context ?>">
<?php
// Display Loop
foreach ( $sub_array as $sub_item ) {
$sub_item = wp_setup_nav_menu_item($sub_item, $item_type, $counter);
$sub_item = wp_setup_nav_menu_item( $sub_item, $item_type, $counter );
if ( $output_type == 'menu' ) {
?>
<li id="menu-<?php echo $counter; ?>" value="<?php echo $counter; ?>">
<?php
wp_print_nav_menu_item($sub_item, 'menu');
echo wp_get_nav_menu_item( $sub_item, 'menu' );
$counter++;
$counter = wp_nav_menu_sub_items($sub_item->ID, $counter, $sub_item->ID, $type, 'menu');
$counter = wp_nav_menu_sub_items( $sub_item->ID, $counter, $sub_item->ID, $context, 'menu' );
?>
</li>
<?php
} elseif ( $output_type == 'default' ) {
@ -198,9 +255,9 @@ function wp_nav_menu_sub_items($childof, $items_counter, $parentli, $type, $outp
?>
<li>
<?php
wp_print_nav_menu_item($sub_item, 'default');
echo wp_get_nav_menu_item( $sub_item, 'default' );
//$counter++;
$counter = wp_nav_menu_sub_items($sub_item->ID, $counter, $sub_item->ID, $type, 'default');
$counter = wp_nav_menu_sub_items( $sub_item->ID, $counter, $sub_item->ID, $context, 'default' );
?>
</li>
@ -208,29 +265,9 @@ function wp_nav_menu_sub_items($childof, $items_counter, $parentli, $type, $outp
}
}
?>
</ul>
<?php
}
return $counter;
}
/*
function wp_nav_menu_setup($override = false) {
// Custom Navigation Menu Setup
// Override for menu descriptions
update_option('wp_settings_nav_menu_advanced_options', 'yes');
$menus = wp_get_nav_menus();
if ( !empty( $menus ) ) {
foreach ( $menus as $menu ) {
wp_delete_nav_menu( $menu->term_id );
}
}
wp_create_nav_menu( __('Main') );
}
/**/
?>

View File

@ -13,9 +13,13 @@
*/
jQuery(document).ready(function($){
wp_drag_and_drop();
wp_update_post_data();
// Handle Save Button Clicks
$('#save_menu').click(function(){
wp_update_post_data();
return wp_update_post_data();
});
// Clear the quick search textbox
@ -30,12 +34,12 @@ jQuery(document).ready(function($){
// Edit menu item
$('#menu-container .item-edit').click(function(){
wp_edit_menu_item( $(this).attr('value') );
return wp_edit_menu_item( $(this).attr('value') );
});
// Delete menu item
$('#menu-container .item-delete').live( 'click', function(){
wp_remove_menu_item( $(this).attr('value') );
return wp_remove_menu_item( $(this).attr('value') );
});
// Update menu item settings (thickbox)
@ -50,7 +54,7 @@ jQuery(document).ready(function($){
// Close thickbox
$('#cancel-save').click(function(){
tb_remove();
return tb_remove();
});
// Show All Button
@ -58,7 +62,7 @@ jQuery(document).ready(function($){
$(this).offsetParent().find('#add-buttons-actions').attr( 'style','margin-bottom: 10px;' );
$(this).offsetParent().find('.list-wrap').css( 'display','block' );
$(this).siblings('.quick-search').attr( 'value', '' );
$(this).offsetParent().find('.list-wrap dt').css( 'display', 'block' );
$(this).offsetParent().find('.list-wrap li').css( 'display', 'block' );
$(this).hide();
$(this).siblings('.hide-all').show();
});
@ -68,31 +72,35 @@ jQuery(document).ready(function($){
$(this).offsetParent().find('#add-buttons-actions').attr( 'style','margin-bottom: 0px;' );
$(this).offsetParent().find('.list-wrap').css( 'display','none' );
$(this).siblings('.quick-search').attr( 'value', 'Search' );
$(this).offsetParent().find('.list-wrap dt').css( 'display', 'none' );
$(this).offsetParent().find('.list-wrap li').css( 'display', 'none' );
$(this).hide();
$(this).siblings('.show-all').show();
});
// Add menu item to queue
$('.list input').click(function(){
var item_type = jQuery(this).parent().siblings('.item-type').val();
var item_title = jQuery(this).parent().siblings('.item-title').val();
var item_url = jQuery(this).parent().siblings('.item-url').val();
var item_id = jQuery(this).parent().siblings('.item-id').val();
var item_parent_id = jQuery(this).parent().siblings('.item-parent-id').val();
var item_description = jQuery(this).parent().siblings('.item-description').val();
return wp_update_queue( $(this), item_type, item_title, item_url, item_id, item_parent_id, item_description );
});
// Add queued menu items into the menu
$('.enqueue a').click(function(){
wp_add_queued_items_to_menu(this);
return wp_add_queued_items_to_menu(this);
});
// Create the link, add it to the menu + available links section
$('#add-custom-link .add-to-menu a').click(function(){
var link_url = $(this).offsetParent().find('#menu-item-url').val();
var link_name = $(this).offsetParent().find('#menu-item-name').val();
var links = $(this).offsetParent().find('#available-links input:checked');
// If links are checked in the available links section, add them to the menu
if ( links ) {
for (var i = 0; i < links.length; i++) {
wp_add_item_to_menu( 'Custom', links[i].name, links[i].value, links[i].id.substring( 5, links[i].id.length ), 0, '' );
};
// Reset the checkboxes;
$(links).attr('checked', false);
};
wp_add_queued_items_to_menu( this );
// Don't save the link if it was left with it's default settings
if ( 'http://' == link_url || 'Menu Item' == link_name )
@ -119,72 +127,4 @@ jQuery(document).ready(function($){
wp_add_item_to_menu( 'Custom', params.link_name, params.link_url, params.link_id, 0, '' );
}, 'json');
});
// Add dropzones
$('#menu li').prepend('<div class="dropzone"></div>');
// Make menu items draggable
$('#menu li').draggable({
handle: ' > dl',
opacity: .8,
addClasses: false,
helper: 'clone',
zIndex: 100
});
// Make items droppable
$('#menu dl, #menu .dropzone').droppable({
accept: '#menu li',
tolerance: 'pointer',
drop: function(e, ui) {
var li = $(this).parent();
var child = !$(this).hasClass('dropzone');
// Add UL to first child
if ( child && li.children('ul').length == 0 ) {
li.append('<ul id="sub-menu" />');
}
// Make it draggable
if ( child ) {
li.children('ul').append( ui.draggable );
} else {
li.before( ui.draggable );
}
li.find('dl,.dropzone').css({ backgroundColor: '', borderColor: '' });
var draggablevalue = ui.draggable.attr('value');
var droppablevalue = li.attr('value');
li.find('#menu-' + draggablevalue).find('#parent' + draggablevalue).val(droppablevalue);
$(this).parent().find('dt').removeAttr('style');
$(this).parent().find('div:first').removeAttr('style');
},
over: function() {
if ( 'dropzone ui-droppable' == $(this).attr('class') ) {
// Add child
$(this).parent().find('dt:first').css('background', 'none').css('height', '50px');
} else if ($(this).attr('class') == 'ui-droppable') {
// Add above
$(this).parent().find('dt:first').css('background', '#d8d8d8');
} else {
// do nothing
}
var parentid = $(this).parent().attr('id');
},
out: function() {
$(this).parent().find('dt').removeAttr('style');
$(this).parent().find('div:first').removeAttr('style');
$(this).filter('.dropzone').css({ borderColor: '' });
},
deactivate: function() {
//
}
});
});

View File

@ -1 +1 @@
jQuery(document).ready(function($){$("#save_menu").click(function(){wp_update_post_data()});$(".quick-search").click(function(){$(this).attr("value","")});$(".quick-search-submit").click(function(){$(this).siblings(".quick-search").search()});$("#menu-container .item-edit").click(function(){wp_edit_menu_item($(this).attr("value"))});$("#menu-container .item-delete").live("click",function(){wp_remove_menu_item($(this).attr("value"))});$("#update-menu-item").click(function(){wp_update_menu_item();tb_remove();var id=$("#edit-item-id").val();$("#menu-"+id+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})});$("#cancel-save").click(function(){tb_remove()});$(".show-all").click(function(){$(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 10px;");$(this).offsetParent().find(".list-wrap").css("display","block");$(this).siblings(".quick-search").attr("value","");$(this).offsetParent().find(".list-wrap dt").css("display","block");$(this).hide();$(this).siblings(".hide-all").show()});$(".hide-all").click(function(){$(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 0px;");$(this).offsetParent().find(".list-wrap").css("display","none");$(this).siblings(".quick-search").attr("value","Search");$(this).offsetParent().find(".list-wrap dt").css("display","none");$(this).hide();$(this).siblings(".show-all").show()});$(".enqueue a").click(function(){wp_add_queued_items_to_menu(this)});$("#add-custom-link .add-to-menu a").click(function(){var link_url=$(this).offsetParent().find("#menu-item-url").val();var link_name=$(this).offsetParent().find("#menu-item-name").val();var links=$(this).offsetParent().find("#available-links input:checked");if(links){for(var i=0;i<links.length;i++){wp_add_item_to_menu("Custom",links[i].name,links[i].value,links[i].id.substring(5,links[i].id.length),0,"")}$(links).attr("checked",false)}if("http://"==link_url||"Menu Item"==link_name){return}params={action:"add-menu-link",link_url:link_url,link_name:link_name,};$.post(ajaxurl,params,function(response){if(null==response||"-1"==response){return false}params.link_id=response;wp_add_item_to_menu("Custom",params.link_name,params.link_url,params.link_id,0,"")},"json")});$("#menu li").prepend('<div class="dropzone"></div>');$("#menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100});$("#menu dl, #menu .dropzone").droppable({accept:"#menu li",tolerance:"pointer",drop:function(e,ui){var li=$(this).parent();var child=!$(this).hasClass("dropzone");if(child&&li.children("ul").length==0){li.append('<ul id="sub-menu" />')}if(child){li.children("ul").append(ui.draggable)}else{li.before(ui.draggable)}li.find("dl,.dropzone").css({backgroundColor:"",borderColor:""});var draggablevalue=ui.draggable.attr("value");var droppablevalue=li.attr("value");li.find("#menu-"+draggablevalue).find("#parent"+draggablevalue).val(droppablevalue);$(this).parent().find("dt").removeAttr("style");$(this).parent().find("div:first").removeAttr("style")},over:function(){if("dropzone ui-droppable"==$(this).attr("class")){$(this).parent().find("dt:first").css("background","none").css("height","50px")}else{if($(this).attr("class")=="ui-droppable"){$(this).parent().find("dt:first").css("background","#d8d8d8")}else{}}var parentid=$(this).parent().attr("id")},out:function(){$(this).parent().find("dt").removeAttr("style");$(this).parent().find("div:first").removeAttr("style");$(this).filter(".dropzone").css({borderColor:""})},deactivate:function(){}})});
jQuery(document).ready(function($){wp_drag_and_drop();wp_update_post_data();$("#save_menu").click(function(){return wp_update_post_data()});$(".quick-search").click(function(){$(this).attr("value","")});$(".quick-search-submit").click(function(){$(this).siblings(".quick-search").search()});$("#menu-container .item-edit").click(function(){return wp_edit_menu_item($(this).attr("value"))});$("#menu-container .item-delete").live("click",function(){return wp_remove_menu_item($(this).attr("value"))});$("#update-menu-item").click(function(){wp_update_menu_item();tb_remove();var id=$("#edit-item-id").val();$("#menu-"+id+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})});$("#cancel-save").click(function(){return tb_remove()});$(".show-all").click(function(){$(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 10px;");$(this).offsetParent().find(".list-wrap").css("display","block");$(this).siblings(".quick-search").attr("value","");$(this).offsetParent().find(".list-wrap li").css("display","block");$(this).hide();$(this).siblings(".hide-all").show()});$(".hide-all").click(function(){$(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 0px;");$(this).offsetParent().find(".list-wrap").css("display","none");$(this).siblings(".quick-search").attr("value","Search");$(this).offsetParent().find(".list-wrap li").css("display","none");$(this).hide();$(this).siblings(".show-all").show()});$(".list input").click(function(){var item_type=jQuery(this).parent().siblings(".item-type").val();var item_title=jQuery(this).parent().siblings(".item-title").val();var item_url=jQuery(this).parent().siblings(".item-url").val();var item_id=jQuery(this).parent().siblings(".item-id").val();var item_parent_id=jQuery(this).parent().siblings(".item-parent-id").val();var item_description=jQuery(this).parent().siblings(".item-description").val();return wp_update_queue($(this),item_type,item_title,item_url,item_id,item_parent_id,item_description)});$(".enqueue a").click(function(){return wp_add_queued_items_to_menu(this)});$("#add-custom-link .add-to-menu a").click(function(){var link_url=$(this).offsetParent().find("#menu-item-url").val();var link_name=$(this).offsetParent().find("#menu-item-name").val();wp_add_queued_items_to_menu(this);if("http://"==link_url||"Menu Item"==link_name){return}params={action:"add-menu-link",link_url:link_url,link_name:link_name,};$.post(ajaxurl,params,function(response){if(null==response||"-1"==response){return false}params.link_id=response;wp_add_item_to_menu("Custom",params.link_name,params.link_url,params.link_id,0,"")},"json")})});

View File

@ -23,44 +23,22 @@ function wp_update_links_list(e) {
jQuery('#available-links .list #link-' + e.link_id).parent().animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
}
/**
* 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();
}
};
/**
* 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 ) {
console.log('wp_edit_menu_item');
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();
console.log(id);
console.log(itemTitle);
console.log(itemURL);
console.log(itemAttrTitle);
console.log(itemTarget);
console.log(itemDesc);
// 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);
@ -83,13 +61,6 @@ function wp_update_menu_item() {
var itemTarget = jQuery('#edit-item-target').val();
var itemDesc = jQuery('#edit-item-description').val();
console.log(id);
console.log(itemTitle);
console.log(itemURL);
console.log(itemAttrTitle);
console.log(itemTarget);
console.log(itemDesc);
// update menu item settings
jQuery('#menu-' + id).find('.item-title:first').html(itemTitle);
jQuery('#item-title' + id).val(itemTitle);
@ -99,30 +70,48 @@ function wp_update_menu_item() {
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) {
jQuery('.menu li').each(function(i) {
i = i + 1;
var j = jQuery(this).attr('value');
jQuery(this).find('#position' + j).attr('value', i);
jQuery(this).find('#item-position' + j).attr('value', i);
jQuery(this).attr('id','menu-' + i);
jQuery(this).attr('value', i);
jQuery(this).find('#dbid' + j).attr('name','dbid' + i);
jQuery(this).find('#dbid' + j).attr('id','dbid' + 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('#postmenu' + j).attr('name','postmenu' + i);
jQuery(this).find('#postmenu' + j).attr('id','postmenu' + 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('#parent' + j).parent().parent().parent().attr('value');
var p = jQuery(this).find('#item-parent' + j).parent().parent().parent().attr('value');
jQuery(this).find('#parent' + j).attr('name','parent' + i);
jQuery(this).find('#parent' + j).attr('id','parent' + i);
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
@ -131,7 +120,7 @@ function wp_update_post_data() {
p = 0;
}
jQuery(this).find('#parent' + j).attr('value', p);
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);
@ -148,11 +137,11 @@ function wp_update_post_data() {
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('#position' + j).attr('name', 'position' + i);
jQuery(this).find('#position' + j).attr('id', 'position' + 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('#linktype' + j).attr('name', 'linktype' + i);
jQuery(this).find('#linktype' + j).attr('id', 'linktype' + 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 );
});
@ -169,30 +158,20 @@ function wp_update_post_data() {
* @param int itemparentid - default 0.
* @param string itemdescription - the description of the menu item.
*/
function wp_add_item_to_menu( additemtype, itemtext, itemurl, itemid, itemparentid, itemdescription ) {
var inputvaluevarname = '';
var inputvaluevarurl = '';
var inputitemid = '';
var inputparentid= '';
var inputdescription = '';
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();
inputvaluevarname = htmlentities(itemtext.toString());
inputvaluevarurl = itemurl.toString();
inputitemid = itemid;
inputparentid = itemparentid;
inputlinktype = 'custom';
inputdescription = htmlentities(itemdescription.toString());
// Adds the item in the queue
jQuery('#menu').append('<li id="menu-' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">' + inputvaluevarname + '</span><span class="item-controls"><span class="item-type">' + additemtype + '</span><a class="item-edit thickbox" id="edit' + randomnumber + '" value="' + randomnumber +'" onClick="wp_edit_menu_item('+ randomnumber +')" title="' + navMenuL10n.thickbox + '" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">' + navMenuL10n.edit + '</a> | <a class="item-delete" id="delete' + randomnumber + '" value="' + randomnumber +'">Delete</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="item-title' + randomnumber + '" id="item-title' + randomnumber + '" value="' + inputvaluevarname + '" /><input type="hidden" name="item-url' + randomnumber + '" id="item-url' + randomnumber + '" value="' + inputvaluevarurl + '" /><input type="hidden" name="item-description' + randomnumber + '" id="item-description' + randomnumber + '" value="' + inputdescription + '" /><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="item-attr-title' + randomnumber + '" id="item-attr-title' + randomnumber + '" value="' + inputvaluevarname + '" /><input type="hidden" name="item-target' + randomnumber + '" id="item-target' + randomnumber + '" value="0" /></li>');
jQuery('.menu').append('<li id="menu-' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">' + item_title + '</span><span class="item-controls"><span class="item-type">' + item_type + '</span><a class="item-edit thickbox" id="edit' + randomnumber + '" value="' + randomnumber +'" onClick="wp_edit_menu_item('+ randomnumber +')" title="' + navMenuL10n.thickbox + '" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">' + navMenuL10n.edit + '</a> | <a class="item-delete" id="delete' + randomnumber + '" value="' + randomnumber +'">Delete</a></span></dt></dl><input type="hidden" name="item-postmenu' + randomnumber + '" id="item-postmenu' + randomnumber + '" value="' + item_id + '" /><input type="hidden" name="item-parent' + randomnumber + '" id="item-parent' + randomnumber + '" value="' + item_parent_id + '" /><input type="hidden" name="item-title' + randomnumber + '" id="item-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-url' + randomnumber + '" id="item-url' + randomnumber + '" value="' + item_url + '" /><input type="hidden" name="item-description' + randomnumber + '" id="item-description' + randomnumber + '" value="' + item_description + '" /><input type="hidden" name="item-position' + randomnumber + '" id="item-position' + randomnumber + '" value="' + randomnumber + '" /><input type="hidden" name="item-type' + randomnumber + '" id="item-type' + randomnumber + '" value="' + item_type + '" /><input type="hidden" name="item-attr-title' + randomnumber + '" id="item-attr-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-target' + randomnumber + '" id="item-target' + randomnumber + '" value="0" /></li>');
// Give some feedback to the user
jQuery( '#menu #menu-' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
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');
};
@ -200,55 +179,26 @@ function wp_add_item_to_menu( additemtype, itemtext, itemurl, itemid, itemparent
/*
* Queues items in perperation for appendToList
*
* @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.
* @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( additemtype, itemtext, itemurl, itemid, itemparentid, itemdescription ) {
var inputvaluevarname = '';
var inputvaluevarurl = '';
var inputitemid = '';
var inputparentid= '';
var inputdescription = '';
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 ( additemtype == navMenuL10n.page ) {
inputvaluevarname = htmlentities(itemtext.toString());
inputvaluevarurl = itemurl.toString();
inputitemid = itemid.toString();
inputparentid = '0';
inputlinktype = 'page';
inputdescription = htmlentities(itemdescription.toString());
} else if ( additemtype == navMenuL10n.category ) {
inputvaluevarname = htmlentities(itemtext.toString());
inputvaluevarurl = itemurl.toString();
inputitemid = itemid.toString();
inputparentid = '0';
inputlinktype = 'category';
inputdescription = htmlentities(itemdescription.toString());
}
// Adds or removes the item from the queue
if ( jQuery(menu_item_id = '#menu-item-' + inputitemid).attr('checked') ) {
if ( jQuery(e).attr('checked') ) {
// Add menu item to the queue
jQuery('#queue').append('<li id="menu-' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">' + inputvaluevarname + '</span><span class="item-controls"><span class="item-type">' + additemtype + '</span><a class="item-edit thickbox" id="edit' + randomnumber + '" value="' + randomnumber +'" onClick="wp_edit_menu_item('+ randomnumber +')" title="' + navMenuL10n.thickbox + '" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">' + navMenuL10n.edit + '</a> | <a class="item-delete" id="delete' + randomnumber + '" value="' + randomnumber +'">Delete</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="item-title' + randomnumber + '" id="item-title' + randomnumber + '" value="' + inputvaluevarname + '" /><input type="hidden" name="item-url' + randomnumber + '" id="item-url' + randomnumber + '" value="' + inputvaluevarurl + '" /><input type="hidden" name="item-description' + randomnumber + '" id="item-description' + randomnumber + '" value="' + inputdescription + '" /><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="item-attr-title' + randomnumber + '" id="item-attr-title' + randomnumber + '" value="' + inputvaluevarname + '" /><input type="hidden" name="item-target' + randomnumber + '" id="item-target' + randomnumber + '" value="0" /></li>');
jQuery('#queue').append('<li id="menu-' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">' + item_title + '</span><span class="item-controls"><span class="item-type">' + item_type + '</span><a class="item-edit thickbox" id="edit' + randomnumber + '" value="' + randomnumber +'" onClick="wp_edit_menu_item('+ randomnumber +')" title="' + navMenuL10n.thickbox + '" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">' + navMenuL10n.edit + '</a> | <a class="item-delete" id="delete' + randomnumber + '" value="' + randomnumber +'">Delete</a></span></dt></dl><input type="hidden" name="item-postmenu' + randomnumber + '" id="item-postmenu' + randomnumber + '" value="' + item_id + '" /><input type="hidden" name="item-parent' + randomnumber + '" id="item-parent' + randomnumber + '" value="' + item_parent_id + '" /><input type="hidden" name="item-title' + randomnumber + '" id="item-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-url' + randomnumber + '" id="item-url' + randomnumber + '" value="' + item_url + '" /><input type="hidden" name="item-description' + randomnumber + '" id="item-description' + randomnumber + '" value="' + item_description + '" /><input type="hidden" name="item-position' + randomnumber + '" id="item-position' + randomnumber + '" value="' + randomnumber + '" /><input type="hidden" name="item-type' + randomnumber + '" id="item-type' + randomnumber + '" value="' + item_type + '" /><input type="hidden" name="item-attr-title' + randomnumber + '" id="item-attr-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-target' + randomnumber + '" id="item-target' + randomnumber + '" value="0" /><input type="hidden" name="item-id' + randomnumber + '" id="item-id' + randomnumber + '" value="'+ menu_item_id +'" /></li>');
} else {
// Get the item in the queue
for ( var i = 0; i < jQuery('#queue li input[name^="postmenu"]').length; i++ ) {
if ( itemid == jQuery('#queue li input[name^="postmenu"]')[i].value ) {
var menu_queue_id = jQuery('#queue li input[name^="postmenu"]')[i].name.substring( 8, jQuery('#queue li input[name^="postmenu"]')[i].name.length );
};
// 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()
};
// Removes the item from the queue
jQuery('#queue li#menu-' + menu_queue_id).remove();
};
};
@ -265,7 +215,7 @@ function wp_add_queued_items_to_menu( button ) {
jQuery('#queue').empty();
// Appends HTML to the menu
jQuery('#menu').append( items );
jQuery('.menu').append( items );
// Give some feedback to the user
jQuery(items).each(function(){
@ -288,18 +238,25 @@ function wp_add_queued_items_to_menu( button ) {
* 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('<div class="dropzone"></div>');
};
});
// make menu item draggable
jQuery('#menu li').draggable({
jQuery('.menu li').draggable({
handle: ' > dl',
opacity: .8,
addClasses: false,
helper: 'clone',
zIndex: 100
zIndex: 100,
});
// make menu item droppable
jQuery('#menu li dl, #menu li .dropzone').droppable({
accept: '#menu li',
jQuery('.menu li dl, .menu li .dropzone').droppable({
accept: '.menu li',
tolerance: 'pointer',
drop: function(e, ui) {
var li = jQuery(this).parent();
@ -307,7 +264,7 @@ function wp_drag_and_drop() {
// Append UL to first child
if ( child && li.children('ul').length == 0 ) {
li.append( '<ul/>' );
li.append( '<ul class="sub-menu" />' );
}
// Make it draggable
if ( child ) {
@ -322,18 +279,18 @@ function wp_drag_and_drop() {
var droppablevalue = li.attr('value');
li.find('#menu-' + draggablevalue).find('#parent' + draggablevalue).val(droppablevalue);
jQuery(this).parent().find("dt").removeAttr('style');
jQuery(this).parent().find("div:first").removeAttr('style');
jQuery(this).parent().find('dt').removeAttr('style');
jQuery(this).parent().find('div:first').removeAttr('style');
},
over: function() {
// Add child
if ( jQuery(this).attr('class') == 'dropzone ui-droppable' ) {
jQuery(this).parent().find("div:first").css('background', 'none').css('height', '50px');
jQuery(this).parent().find('div:first').css('background', 'none').css('height', '50px');
}
// Add above
else if ( jQuery(this).attr('class') == 'ui-droppable' ) {
jQuery(this).parent().find("dt:first").css('background', '#d8d8d8');
jQuery(this).parent().find('dt:first').css('background', '#d8d8d8');
} else {
// do nothing
}
@ -341,8 +298,8 @@ function wp_drag_and_drop() {
},
out: function() {
jQuery(this).parent().find("dt").removeAttr('style');
jQuery(this).parent().find("div:first").removeAttr('style');
jQuery(this).parent().find('dt').removeAttr('style');
jQuery(this).parent().find('div:first').removeAttr('style');
jQuery(this).filter('.dropzone').css({ borderColor: '' });
}
}
@ -353,7 +310,7 @@ function wp_drag_and_drop() {
* Gets a unique number based on how many items are in the menu
*/
function wp_get_unique_menu_id() {
var count = document.getElementById('menu').getElementsByTagName('li').length + 1;
var count = jQuery('.menu li').length + 1;
var randomnumber = count;
var validatetest = 0;

File diff suppressed because one or more lines are too long

View File

@ -43,9 +43,6 @@ $menu_id_in_edit = 0;
$updated = false;
$advanced_option_descriptions = 'no';
// Get all menu link items
$available_links = new WP_Query( array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_key' => 'menu_type', 'meta_value' => 'custom' ) );
// Check which menu is selected and if menu is in edit already
if ( isset( $_GET['edit-menu'] ) ) {
$menu_selected_id = (int) $_GET['edit-menu'];
@ -127,16 +124,16 @@ if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
// Loop through all POST variables
for ( $k = 1; $k <= $post_counter; $k++ ) {
$db_id = isset( $_POST['dbid'.$k] )? $_POST['dbid'.$k] : 0;
$object_id = isset( $_POST['postmenu'.$k] )? $_POST['postmenu'.$k] : 0;
$parent_id = isset( $_POST['parent'.$k] )? $_POST['parent'.$k] : 0;
$db_id = isset( $_POST['item-dbid'.$k] )? $_POST['item-dbid'.$k] : 0;
$object_id = isset( $_POST['item-postmenu'.$k] )? $_POST['item-postmenu'.$k] : 0;
$parent_id = isset( $_POST['item-parent'.$k] )? $_POST['item-parent'.$k] : 0;
$custom_title = isset( $_POST['item-title'.$k] )? $_POST['item-title'.$k] : '';
$custom_linkurl = ( isset( $_POST['item-url'.$k] ) && 'custom' == $_POST['linktype'.$k] ) ? $_POST['item-url'.$k] : '';
$custom_description = isset( $_POST['item-description'.$k] )? $_POST['item-description'.$k] : '';
// doesn't seem to be used by UI
$icon = isset( $_POST['icon'.$k] )? $_POST['icon'.$k] : 0;
$position = isset( $_POST['position'.$k] )? $_POST['position'.$k] : 0;
$linktype = isset( $_POST['linktype'.$k] )? $_POST['linktype'.$k] : 'custom';
$position = isset( $_POST['item-position'.$k] )? $_POST['item-position'.$k] : 0;
$linktype = isset( $_POST['item-type'.$k] )? $_POST['item-type'.$k] : 'custom';
$custom_anchor_title = isset( $_POST['item-attr-title'.$k] )? $_POST['item-attr-title'.$k] : $custom_title;
$new_window = isset( $_POST['item-target'.$k] )? $_POST['item-target'.$k] : 0;
@ -209,14 +206,10 @@ if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
<div class="inside">
<input type="hidden" name="li-count" id="li-count" value="0" />
<input type="hidden" name="menu-id-in-edit" id="menu-id-in-edit" value="<?php echo esc_attr( $menu_selected_id ); ?>" />
<ul id="menu">
<?php
if ( $menu_selected_id > 0 ) {
wp_print_nav_menu( array( 'type' => 'backend', 'name' => $menu_title, 'id' => $menu_selected_id ) );
}
if ( $menu_selected_id > 0 )
echo wp_get_nav_menu( array( 'type' => 'backend', 'menu' => $menu_selected_id, 'ul_class' => 'menu' ) );
?>
</ul><!-- /#menu-->
<div id="queue" class="hide">
</div><!--/#queue-->
@ -265,7 +258,6 @@ if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
</label>
</p>
<?php if ( $available_links->posts ) : ?>
<p class="button-controls">
<a class="show-all button"><?php _e('View All'); ?></a>
<a class="hide-all button"><?php _e('Hide All'); ?></a>
@ -273,24 +265,10 @@ if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
<div id="available-links" class="list-wrap">
<div class="list-container">
<ul class="list">
<?php
foreach ( $available_links->posts as $link ) :
$url = get_post_meta( $link->ID, 'menu_link' );
?>
<li>
<dl>
<dt>
<label class="item-title"><input type="checkbox" id="link-<?php echo esc_attr($link->ID); ?>" name="<?php echo esc_attr($link->post_title); ?>" value="<?php echo esc_attr($url[0]); ?>" /><?php echo esc_html($link->post_title); ?></label>
</dt>
</dl>
</li>
<?php
endforeach;
?>
<?php $items_counter = wp_nav_menu_get_custom_links( 0, 'default' ); ?>
</ul>
</div><!-- /.list-container-->
</div><!-- /#available-links-->
<?php endif; ?>
<p class="add-to-menu">
<a class="button"><?php _e('Add to Menu'); ?></a>
</p>
@ -325,7 +303,7 @@ if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
jQuery('#add-pages .quick-search').result(function(event, data, formatted) {
jQuery('#add-pages .list-wrap').css('display','block');
jQuery("#add-pages .list-wrap dt:contains('" + data + "')").css('display','block');
jQuery("#add-pages .list-wrap li:contains('" + data + "')").css('display','block');
jQuery('#add-pages .show-all').hide();
jQuery('#add-pages .hide-all').show();
});
@ -344,7 +322,7 @@ if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
<div id="existing-pages" class="list-wrap">
<div class="list-container">
<ul class="list">
<?php $items_counter = wp_nav_menu_get_pages( 0, 'default' ); ?>
<?php $items_counter = wp_nav_menu_get_pages( $items_counter, 'default' ); ?>
</ul>
</div><!-- /.list-container-->
</div><!-- /#existing-pages-->
@ -387,7 +365,7 @@ if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
jQuery('#add-categories .quick-search').autocomplete(categories);
jQuery('#add-categories .quick-search').result(function(event, data, formatted) {
jQuery('#add-categories .list-wrap').css('display','block');
jQuery("#add-categories .list-wrap dt:contains('" + data + "')").css('display','block');
jQuery("#add-categories .list-wrap li:contains('" + data + "')").css('display','block');
jQuery('#add-categories .show-all').hide();
jQuery('#add-categories .hide-all').show();
});

View File

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<title><?php
if ( is_single() ) {
<title><?php
if ( is_single() ) {
single_post_title(); echo ' | '; bloginfo('name');
} elseif ( is_home() || is_front_page() ) {
bloginfo('name'); echo ' | '; bloginfo('description'); twentyten_the_page_number();
@ -15,7 +15,7 @@
} else {
wp_title(''); echo ' | '; bloginfo('name'); twentyten_the_page_number();
}
?></title>
?></title>
<meta http-equiv="content-type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

View File

@ -1044,231 +1044,62 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
class WP_Nav_Menu_Widget extends WP_Widget {
function WP_Nav_Menu_Widget() {
$widget_ops = array('description' => __('Use this widget to add one of your navigation menus as a widget.') );
parent::WP_Widget( false, __('Navigation Menu'), $widget_ops );
$widget_ops = array( 'description' => __('Use this widget to add one of your navigation menus as a widget.') );
parent::WP_Widget( 'nav_menu', __('Navigation Menu'), $widget_ops );
}
function widget($args, $instance) {
$navmenu = $instance['navmenu'];
$navtitle = $instance['navtitle'];
$navdeveloper = strtolower($instance['navdeveloper']);
$navdiv = strtolower($instance['navdiv']);
$navul = strtolower($instance['navul']);
$navdivid = $instance['navdivid'];
$navdivclass = $instance['navdivclass'];
$navulid = $instance['navulid'];
$navulclass = $instance['navulclass'];
// Override for menu descriptions
$advanced_option_descriptions = get_option('wp_settings_nav_menu_advanced_options');
if ( $advanced_option_descriptions == 'no' ) {
$navwidgetdescription = 2;
} else {
$navwidgetdescription = $instance['navwidgetdescription'];
}
// Get menu
if ( $navmenu > 0 ) {
$custom_menu = get_term( (int) $nav_menu, 'nav_menu' );
$wp_custom_nav_menu_name = $custom_menu->name;
$menuexists = true;
} else {
$menuexists = false;
}
$nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );
if ( $navdeveloper == 'yes' ) {
// DISPLAY Custom DIV
if ( $navdiv == 'yes' ) {
?>
<div id="<?php echo $navdivid; ?>" class="<?php echo $navdivclass; ?>">
<?php
}
} else {
//DISPLAY default DIV
?>
<div class="widget">
<?php
}
?>
if ( !$nav_menu )
return;
<h3><?php echo $navtitle; ?></h3>
<?php
if ( $menuexists ) {
if ( $navdeveloper == 'yes' ) {
//DISPLAY Custom UL
if ( $navul == 'yes' ) {
?>
<ul id="<?php echo $navulid; ?>" class="<?php echo $navulclass; ?>">
<?php
}
} else {
// DISPLAY default UL
?>
<ul class="menu">
<?php
}
wp_nav_menu( array('id' => $navmenu, 'name' => $wp_custom_nav_menu_name, 'desc' => $navwidgetdescription, 'format' => 'widget') );
if ( $navdeveloper == 'yes' ) {
// DISPLAY Custom UL
if ( $navul == 'yes' ) {
?>
</ul>
<?php
}
} else {
// DISPLAY default UL
?>
</ul>
<?php
}
} else {
_e('You have not setup the custom navigation widget correctly, please check your settings in the backend.');
}
echo $args['before_widget'];
//DEVELOPER settings enabled
if ($navdeveloper == 'yes') {
// DISPLAY Custom DIV
if ( $navdiv == 'yes' ) {
?>
</div>
<?php
}
} else {
// DISPLAY default DIV
?>
</div>
<?php
}
?><!-- /#nav-container -->
<?php
if ( isset($instance['title']) )
echo $args['before_title'] . $instance['title'] . $args['after_title'];
wp_nav_menu( array( 'menu' => $nav_menu ) );
echo $args['after_widget'];
}
function update($new_instance, $old_instance) {
return $new_instance;
function update( $new_instance, $old_instance ) {
$instance['title'] = strip_tags( stripslashes($new_instance['title']) );
$instance['nav_menu'] = (int) $new_instance['nav_menu'];
return $instance;
}
function form($instance) {
$navmenu = esc_attr($instance['navmenu']);
$navtitle = esc_attr($instance['navtitle']);
$navdeveloper = esc_attr($instance['navdeveloper']);
$navdiv = esc_attr($instance['navdiv']);
$navul = esc_attr($instance['navul']);
$navdivid = esc_attr($instance['navdivid']);
$navdivclass = esc_attr($instance['navdivclass']);
$navulid = esc_attr($instance['navulid']);
$navulclass = esc_attr($instance['navulclass']);
$navwidgetdescription = esc_attr($instance['navwidgetdescription']);
global $wpdb;
function form( $instance ) {
$title = isset( $instance['title'] ) ? $instance['title'] : '';
$nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
// Get menus
$custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
$menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
if ( !$custom_menus) {
?>
<p>
<label><?php printf(__('No menus have been created yet. <a href="%s">Creat some</a>.'), admin_url('nav-menus.php')); ?></label>
</p>
<?php
// If no menus exists, direct the user to go and create some.
if ( !$menus ) {
echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Creat some</a>.'), admin_url('nav-menus.php') ) .'</p>';
return;
}
?>
<p>
<label for="<?php echo $this->get_field_id('navmenu'); ?>"><?php _e('Select Menu:'); ?></label>
<select id="<?php echo $this->get_field_id('navmenu'); ?>" name="<?php echo $this->get_field_name('navmenu'); ?>">
<?php
foreach ( $custom_menus as $menu ) {
if ( $navmenu == $menu->term_id )
$selected_option = 'selected="selected"';
else
$selected_option = '';
?>
<option value="<?php echo $menu->term_id; ?>" <?php echo $selected_option; ?>><?php echo $menu->name; ?></option>
<?php
}
?>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
<?php
foreach ( $menus as $menu ) {
$selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
}
?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('navtitle'); ?>"><?php _e('Title:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('navtitle'); ?>" value="<?php echo $navtitle; ?>" class="widefat" id="<?php echo $this->get_field_id('navtitle'); ?>" />
</p>
<?php $checked = strtolower($navdeveloper); ?>
<p>
<label for="<?php echo $this->get_field_id('navdeveloper'); ?>"><?php _e('Advanced Options:'); ?></label><br />
<span class="checkboxes">
<label>Yes</label><input type="radio" id="<?php echo $this->get_field_name('navdeveloper'); ?>" name="<?php echo $this->get_field_name('navdeveloper'); ?>" value="yes" <?php if ($checked=='yes') { echo 'checked="checked"'; } ?> />
<label>No</label><input type="radio" id="<?php echo $this->get_field_name('navdeveloper'); ?>" name="<?php echo $this->get_field_name('navdeveloper'); ?>" value="no" <?php if ($checked=='yes') { } else { echo 'checked="checked"'; } ?> />
</span><!-- /.checkboxes -->
</p>
<?php
// Advanced settings
if ( $checked == 'yes' ) :
?>
<p>
<?php $checked = strtolower($navdiv); ?>
<label for="<?php echo $this->get_field_id('navdiv'); ?>"><?php _e('Wrap in container DIV:'); ?></label><br />
<span class="checkboxes">
<label>Yes</label><input type="radio" id="<?php echo $this->get_field_name('navdiv'); ?>" name="<?php echo $this->get_field_name('navdiv'); ?>" value="yes" <?php if ($checked=='yes') { echo 'checked="checked"'; } ?> />
<label>No</label><input type="radio" id="<?php echo $this->get_field_name('navdiv'); ?>" name="<?php echo $this->get_field_name('navdiv'); ?>" value="no" <?php if ($checked=='yes') { } else { echo 'checked="checked"'; } ?> />
</span><!-- /.checkboxes -->
</p>
<?php
if ( $checked == 'yes' ) {
?>
<p>
<label for="<?php echo $this->get_field_id('navdivid'); ?>"><?php _e('DIV id:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('navdivid'); ?>" value="<?php echo $navdivid; ?>" class="widefat" id="<?php echo $this->get_field_id('navdivid'); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('navdivclass'); ?>"><?php _e('DIV class:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('navdivclass'); ?>" value="<?php echo $navdivclass; ?>" class="widefat" id="<?php echo $this->get_field_id('navdivclass'); ?>" />
</p>
<?php
}
$checked = strtolower($navul);
?>
<p>
<label for="<?php echo $this->get_field_id('navul'); ?>"><?php _e('Wrap in container UL:'); ?></label><br />
<span class="checkboxes">
<label>Yes</label><input type="radio" id="<?php echo $this->get_field_name('navul'); ?>" name="<?php echo $this->get_field_name('navul'); ?>" value="yes" <?php if ($checked=='yes') { echo 'checked="checked"'; } ?> />
<label>No</label><input type="radio" id="<?php echo $this->get_field_name('navul'); ?>" name="<?php echo $this->get_field_name('navul'); ?>" value="no" <?php if ($checked=='yes') { } else { echo 'checked="checked"'; } ?> />
</span><!-- /.checkboxes -->
</p>
<?php
if ( $checked == 'yes' ) {
?>
<p>
<label for="<?php echo $this->get_field_id('navulid'); ?>"><?php _e('UL id:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('navulid'); ?>" value="<?php echo $navulid; ?>" class="widefat" id="<?php echo $this->get_field_id('navulid'); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('navulclass'); ?>"><?php _e('UL class:'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('navulclass'); ?>" value="<?php echo $navulclass; ?>" class="widefat" id="<?php echo $this->get_field_id('navulclass'); ?>" />
</p>
<?php
}
$advanced_option_descriptions = get_option('wp_settings_nav_menu_advanced_options');
?>
<p <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?>>
<?php $checked = strtolower($navwidgetdescription); ?>
<label for="<?php echo $this->get_field_id('navwidgetdescription'); ?>"><?php _e('Show Top Level Descriptions:'); ?></label><br />
<span class="checkboxes">
<label>Yes</label><input type="radio" id="<?php echo $this->get_field_name('navwidgetdescription'); ?>" name="<?php echo $this->get_field_name('navwidgetdescription'); ?>" value="1" <?php if ($checked=='1') { echo 'checked="checked"'; } ?> />
<label>No</label><input type="radio" id="<?php echo $this->get_field_name('navwidgetdescription'); ?>" name="<?php echo $this->get_field_name('navwidgetdescription'); ?>" value="2" <?php if ($checked=='1') { } else { echo 'checked="checked"'; } ?> />
</span><!-- /.checkboxes -->
</p>
<?php
endif;
}
}

View File

@ -1,7 +1,6 @@
<?php
/**
* Outputs a navigation menu.
* Displays a navigation menu.
*
* Optional $args contents:
*
@ -10,29 +9,33 @@
* menu_class - CSS class to use for the div container of the menu list. Defaults to 'menu'.
* format - Whether to format the ul. Defaults to 'div'.
* fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'.
* before_link - Output text before the link.
* after_link - Output text after the link.
* before_title - Output text before the link text.
* before_title - Output text after the link text.
* echo - Whether to echo the menu or return it. Defaults to echo.
*
* TODO:
* show_home - If you set this argument, then it will display the link to the home page. The show_home argument really just needs to be set to the value of the text of the link.
* link_before - Text before show_home argument text.
* link_after - Text after show_home argument text.
* echo - Whether to echo the menu or return it. Defaults to echo.
*
* @since 3.0.0
*
* @param array $args Arguments
*/
function wp_nav_menu( $args = array() ) {
$defaults = array( 'id' => '', 'slug' => '', 'menu_class' => 'menu', 'format' => 'div', 'fallback_cb' => 'wp_page_menu', 'echo' => true, 'link_before' => '', 'link_after' => '' );
$defaults = array( 'menu' => '', 'menu_class' => 'menu', 'format' => 'div', 'echo' => true,
'fallback_cb' => 'wp_page_menu', 'link_before' => '', 'link_after' => '', 'before_link' => '', 'after_link' => '', );
$args = wp_parse_args( $args, $defaults );
$args = apply_filters( 'wp_nav_menu_args', $args );
$args = (object) $args;
// Get the menu
$menu = null;
if ( !empty($args->id) ) {
$menu = wp_get_nav_menu( $args->id );
} elseif ( !empty($args->slug) ) {
$menu = get_term_by( 'slug', $args->slug, 'nav_menu' );
} else {
// Get the nav menu
$menu = wp_get_nav_menu_object( $args->menu );
// If we couldn't find a menu based off the name, id or slug,
// get the first menu that has items.
if ( !$menu ) {
$menus = wp_get_nav_menus();
foreach ( $menus as $menu_maybe ) {
if ( wp_get_nav_menu_items($menu_maybe->term_id) ) {
@ -42,137 +45,157 @@ function wp_nav_menu( $args = array() ) {
}
}
// If the menu doesn't exists, call the fallback_cb
if ( !$menu || is_wp_error($menu) )
return call_user_func($args->fallback_cb, $args );
$args->menu = $menu->term_id;
$nav_menu = '';
if ( 'div' == $args->format )
echo '<div class="' . esc_attr($args->menu_class) . '"><ul>';
$nav_menu .= '<div id="menu-'. $menu->slug .'" class="' . esc_attr($args->menu_class) . '">';
$args->id = $menu->term_id;
wp_print_nav_menu($args);
$nav_menu .= wp_get_nav_menu( $args );
if ( 'div' == $args->format )
echo '</ul></div>';
$nav_menu .= '</div>';
$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu );
return $args->echo ? print $nav_menu : $nav_menu;
}
function wp_print_nav_menu( $args = array() ) {
// Defaults
$defaults = array( 'type' => 'frontend', 'name' => 'Menu 1', 'id' => 0, 'desc' => 2, 'before_title' => '', 'after_title' => '');
/**
* Returns a Navigation Menu.
*
* See wp_nav_menu() for args.
*
* @since 3.0.0
*
* @param array $args Arguments
* @return mixed $output False if menu doesn't exists, else, returns the menu.
**/
function wp_get_nav_menu( $args = array() ) {
$defaults = array( 'menu' => '', 'menu_class' => 'menu', 'ul_class' => '', 'format' => 'div', 'type' => 'frontend',
'fallback_cb' => '', 'link_before' => '', 'link_after' => '', 'before_link' => '', 'after_link' => '', );
$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
$args = wp_parse_args( $args, $defaults );
$args = apply_filters( 'wp_get_nav_menu_args', $args );
$args = (object) $args;
$menu_items = wp_get_nav_menu_items( $id );
$menu = wp_get_nav_menu_object( $args->menu );
$parent_stack = array();
$current_parent = 0;
$parent_menu_order = array();
// Setup parentage
foreach ( $menu_items as $menu_item ) {
$parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order;
// If no menu was found, call the fallback_cb
if ( !$menu || is_wp_error($menu) ) {
if ( function_exists($args->fallback_cb) )
return call_user_func( $args->fallback_cb, $args );
}
$menu_items = wp_get_nav_menu_items( $menu->term_id );
$nav_menu = '';
$parent_stack = array();
$current_parent = 0;
$parent_menu_order = array();
// Setup parentage
foreach ( $menu_items as $menu_item )
$parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order;
$ul_class = isset($args->ul_class) ? ' class="'. $args->ul_class .'"' : '';
$nav_menu .= '<ul'. $ul_class .'>';
// Display Loop
foreach ( $menu_items as $key => $menu_item ) :
// Setup the $menu_item variables
$menu_item = wp_setup_nav_menu_item( $menu_item );
$maybe_value = 'frontend' == $args->type ? '' : ' value="'. $menu_item->ID .'"';
$classes = 'frontend' == $args->type ? 'class="menu-item-'. $menu_item->type . $menu_item->li_class .'"' : '';
$nav_menu .= '<li id="menu-item-'. $menu_item->ID .'"'. $maybe_value . $classes .'>';
$nav_menu .= wp_get_nav_menu_item( $menu_item, $args->type, $args );
// Indent children
$last_item = ( count( $menu_items ) == $menu_item->menu_order );
if ( $last_item || $current_parent != $menu_items[ $key + 1 ]->post_parent ) {
if ( $last_item || in_array( $menu_items[ $key + 1 ]->post_parent, $parent_stack ) ) {
$nav_menu .= '</li>';
while ( !empty( $parent_stack ) && ($last_item || $menu_items[ $key + 1 ]->post_parent != $current_parent ) ) {
$nav_menu .= '</ul></li>';
$current_parent = array_pop( $parent_stack );
}
} else {
array_push( $parent_stack, $current_parent );
$current_parent = $menu_item->ID;
$nav_menu .= '<ul>';
}
} else {
$nav_menu .= '</li>';
}
// Display Loop
foreach ( $menu_items as $key => $menu_item ) {
$menu_item = wp_setup_nav_menu_item($menu_item);
// List Items
?><li id="menu-<?php echo $menu_item->ID; ?>" value="<?php echo $menu_item->ID; ?>" <?php echo $menu_item->li_class; ?>><?php
wp_print_nav_menu_item($menu_item, $type, $args);
// Indent children
$last_item = ( count( $menu_items ) == $menu_item->menu_order );
if ( $last_item || $current_parent != $menu_items[ $key + 1 ]->post_parent ) {
if ( $last_item || in_array( $menu_items[ $key + 1 ]->post_parent, $parent_stack ) ) { ?>
</li>
<?php while ( !empty( $parent_stack ) && ($last_item || $menu_items[ $key + 1 ]->post_parent != $current_parent ) ) { ?>
</ul>
</li>
<?php $current_parent = array_pop( $parent_stack );
} ?>
<?php } else {
array_push( $parent_stack, $current_parent );
$current_parent = $menu_item->ID; ?>
<ul>
<?php }
} else { ?>
</li>
<?php }
}
endforeach;
$nav_menu .= '</ul>';
return apply_filters( 'wp_get_nav_menu', $nav_menu );
}
function wp_print_nav_menu_item( $menu_item, $context, $args = array() ) {
/**
* Returns a menu item.
*
* @since 3.0.0
*
* @param object $menu_item The menu item
* @param string $context frontend|backend|default
* @param array $args See wp_get_nav_menu().
**/
function wp_get_nav_menu_item( $menu_item, $context, $args = array() ) {
$item = '';
switch ( $context ) {
case 'backend':
case 'menu':
?>
<dl>
<dt>
<span class="item-title"><?php echo esc_html($menu_item->title); ?></span>
<span class="item-controls">
<span class="item-type"><?php echo esc_html($menu_item->type); ?></span>
<a class="item-edit thickbox" id="edit<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->menu_order ); ?>" title="<?php _e('Edit Menu Item'); ?>" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings"><?php _e('Edit'); ?></a> |
<a class="item-delete" id="delete<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->menu_order ); ?>"><?php _e('Delete'); ?></a>
</span>
</dt>
</dl>
<?php if ( 'backend' == $context ) { ?>
<a><span class=""></span></a>
<?php } else { ?>
<a class="hide" href="<?php echo $menu_item->link; ?>"><?php echo esc_html( $menu_item->title ); ?></a>
<?php } ?>
<input type="hidden" name="dbid<?php echo esc_attr( $menu_item->menu_order ); ?>" id="dbid<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->ID ); ?>" />
<input type="hidden" name="postmenu<?php echo esc_attr( $menu_item->menu_order ); ?>" id="postmenu<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( get_post_meta( $menu_item->ID, 'object_id', true ) ); ?>" />
<input type="hidden" name="parent<?php echo esc_attr( $menu_item->menu_order ); ?>" id="parent<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->parent_item ); ?>" />
<input type="hidden" name="icon<?php echo esc_attr( $menu_item->menu_order ); ?>" id="icon<?php echo esc_attr( $menu_item->menu_order ); ?>" value="0" />
<input type="hidden" name="position<?php echo esc_attr( $menu_item->menu_order ); ?>" id="position<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->menu_order ); ?>" />
<input type="hidden" name="linktype<?php echo esc_attr( $menu_item->menu_order ); ?>" id="linktype<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( get_post_meta( $menu_item->ID, 'menu_type', true ) ); ?>" />
<input type="hidden" name="item-title<?php echo esc_attr( $menu_item->menu_order ); ?>" id="item-title<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->title ); ?>" />
<input type="hidden" name="item-url<?php echo esc_attr( $menu_item->menu_order ); ?>" id="item-url<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->link ); ?>" />
<input type="hidden" name="item-description<?php echo esc_attr( $menu_item->menu_order ); ?>" id="item-description<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->description ); ?>" />
<input type="hidden" name="item-attr-title<?php echo esc_attr( $menu_item->menu_order ); ?>" id="item-attr-title<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo esc_attr( $menu_item->post_excerpt ); ?>" />
<input type="hidden" name="item-target<?php echo esc_attr( $menu_item->menu_order ); ?>" id="item-target<?php echo esc_attr( $menu_item->menu_order ); ?>" value="<?php echo ( get_post_meta( $menu_item->ID, 'menu_new_window', true ) ? '1' : '0' ); ?>" />
<?php
break;
case 'frontend':
// Override for menu descriptions
$advanced_option_descriptions = get_option('wp_settings_nav_menu_advanced_options');
if ( $advanced_option_descriptions == 'no' )
$args['desc'] = 2;
?>
<a title="<?php echo esc_attr( $menu_item->anchor_title ); ?>" href="<?php echo esc_url( $menu_item->link ); ?>" <?php echo $menu_item->target; ?>><?php echo $args['before_title'] . esc_html( $menu_item->title ) . $args['after_title']; ?><?php
$attr_title = ( isset($menu_item->anchor_title) && '' != $menu_item->anchor_title ) ? ' title="'. esc_attr($menu_item->anchor_title) .'"' : '';
$href = isset($menu_item->link) ? ' href="'. esc_url($menu_item->link) .'"' : '';
if ( $advanced_option_descriptions == 'no' ) {
// 2 widget override do NOT display descriptions
// 1 widget override display descriptions
// 0 widget override not set
if ( ($args['desc'] == 1) || ($args['desc'] == 0) ) {
?><span class="nav-description"><?php echo $menu_item->description; ?></span><?php
}
} else {
// 2 widget override do NOT display descriptions
// 1 widget override display descriptions
// 0 widget override not set
if ( $args['desc'] == 1 ) {
?><span class="nav-description"><?php echo $menu_item->description; ?></span><?php
}
}
?></a>
<?php
break;
$item .= '<a'. $attr_title . $href . $menu_item->target .'>';
$item .= $args->before_link . esc_html( $menu_item->title ) . $args->after_link;
$item .= '</a>';
break;
case 'backend':
$item .= '<dl><dt>';
$item .= '<span class="item-title">'. esc_html($menu_item->title) .'</span>';
$item .= '<span class="item-controls">';
$item .= '<span class="item-type">'. esc_html($menu_item->type) .'</span>';
// Actions
$item .= '<a class="item-edit thickbox" id="edit'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" title="'. __('Edit Menu Item') .'" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">'. __('Edit') .'</a> | ';
$item .= '<a class="item-delete" id="delete'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'">'. __('Delete') .'</a>';
$item .= '</dt></dl>';
// Menu Item Settings
$item .= '<input type="hidden" id="item-dbid'. esc_attr( $menu_item->menu_order ) .'" name="item-dbid'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->ID ) .'" />';
$item .= '<input type="hidden" id="item-postmenu'. esc_attr( $menu_item->menu_order ) .'" name="item-postmenu'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( get_post_meta( $menu_item->ID, 'object_id', true ) ) .'" />';
$item .= '<input type="hidden" id="item-parent'. esc_attr( $menu_item->menu_order ) .'" name="item-parent'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->parent_item ) .'" />';
$item .= '<input type="hidden" id="item-position'. esc_attr( $menu_item->menu_order ) .'" name="item-position'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" />';
$item .= '<input type="hidden" id="item-type'. esc_attr( $menu_item->menu_order ) .'" name="item-type'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( get_post_meta( $menu_item->ID, 'menu_type', true ) ) .'" />';
$item .= '<input type="hidden" id="item-title'. esc_attr( $menu_item->menu_order ) .'" name="item-title'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->title ) .'" />';
$item .= '<input type="hidden" id="item-url'. esc_attr( $menu_item->menu_order ) .'" name="item-url'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->link ) .'" />';
$item .= '<input type="hidden" id="item-description'. esc_attr( $menu_item->menu_order ) .'" name="item-description'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->description ) .'" />';
$item .= '<input type="hidden" id="item-attr-title'. esc_attr( $menu_item->menu_order ) .'" name="item-attr-title'. esc_attr( $menu_item->menu_order ) .'" value="'.esc_attr( $menu_item->post_excerpt ) .'" />';
$item .= '<input type="hidden" id="item-target'. esc_attr( $menu_item->menu_order ) .'" name="item-target'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( get_post_meta( $menu_item->ID, 'menu_new_window', true ) ? '1' : '0' ) .'" />';
break;
case 'default':
$menu_id = 'menu-item-' . $menu_item->ID;
?>
<dl>
<dt>
<label class="item-title"><input type="checkbox" id="<?php echo esc_attr($menu_id); ?>" onclick="wp_update_queue('<?php echo esc_js( $menu_item->append ); ?>','<?php echo esc_js( $menu_item->title ); ?>','<?php echo esc_js( $menu_item->link ); ?>','<?php echo esc_js( $menu_item->ID ); ?>','<?php echo esc_js( $menu_item->parent_item ); ?>','<?php echo esc_js( $menu_item->description ); ?>')" name="<?php echo esc_attr( $menu_item->title ); ?>" value="<?php echo esc_attr( $menu_item->link ); ?>" /><?php echo $menu_item->title; ?></label>
</dt>
</dl>
<?php
break;
}
}
$item .= '<label class="item-title"><input type="checkbox" id="'. esc_attr($menu_id) .'" name="'. esc_attr( $menu_item->title ) .'" value="'. esc_attr( $menu_item->link ) .'" />'. $menu_item->title .'</label>';
// Menu Item Settings
$item .= '<input type="hidden" class="item-type" value="'. esc_attr( $menu_item->append ) .'" />';
$item .= '<input type="hidden" class="item-title" value="'. esc_attr( $menu_item->title ) .'" />';
$item .= '<input type="hidden" class="item-url" value="'. esc_attr( $menu_item->link ) .'" />';
$item .= '<input type="hidden" class="item-dbid" value="'. esc_attr( $menu_item->ID ) .'" />';
$item .= '<input type="hidden" class="item-parent" value="'. esc_attr( $menu_item->parent_item ) .'" />';
$item .= '<input type="hidden" class="item-description" value="'. esc_attr( $menu_item->description ) .'" />';
break;
}
return apply_filters( 'wp_get_nav_menu_item', $item );
}
?>

View File

@ -7,22 +7,65 @@
* @since 3.0.0
*/
// Deletes a nav menu
function wp_delete_nav_menu( $menu_id ) {
$menu_id = (int) $menu_id;
if ( !$menu_id )
return false;
$menu_objects = get_objects_in_term( $menu_id, 'nav_menu' );
if ( !empty( $menu_objects ) ) {
foreach ( $menu_objects as $item ) {
wp_delete_post( $item );
}
}
wp_delete_term( $menu_id, 'nav_menu' );
/**
* Returns a Navigation Menu object
*
* @since 3.0.0
*
* @param string $menu Menu id
* @return mixed $menu|false
*/
function wp_get_nav_menu_object( $menu ) {
return is_nav_menu( $menu );
}
// Creates a new nav menu
/**
* Check if Menu exists.
*
* Returns the menu object, or false if the term doesn't exist.
*
* @since 3.0.0
*
* @param int|string $menu The menu to check
* @return mixed Menu Object, if exists.
*/
function is_nav_menu( $menu ) {
if ( $menu ) {
$menu = get_term( $menu, 'nav_menu' );
} elseif ( !$menu ) {
$menu = get_term_by( 'slug', $menu, 'nav_menu' );
} elseif( !$menu ) {
$menu = get_term_by( 'name', $menu, 'nav_menu' );
} else {
$menu = false;
}
return $menu;
}
/**
* Returns all Navigation Menu objects.
*
* @since 3.0.0
*
* @return array menu objects
*/
function wp_get_nav_menus() {
return get_terms( 'nav_menu', array( 'hide_empty' => false, 'orderby' => 'id' ) );
}
/**
* Creates a navigation menu.
*
* Optional args:
* slug - the url friendly version of the nav menu.
*
* @since 3.0.0
*
* @param string $menu_name Menu Name
* @param string $args Optional.
* @return mixed Menu object|WP_Error
*/
function wp_create_nav_menu( $menu_name, $args = array() ) {
$menu_exists = get_term_by( 'name', $menu_name, 'nav_menu' );
@ -39,10 +82,39 @@ function wp_create_nav_menu( $menu_name, $args = array() ) {
if ( is_wp_error($menu) )
return $menu;
return get_term( $menu['term_id'], 'nav_menu');
return get_term( $menu['term_id'], 'nav_menu') ;
}
// Creates a default menu if none exists
/**
* Deletes a navigation menu.
*
* @since 3.0.0
*
* @param string $menu name|id|slug
* @return bool true on success, else false.
*/
function wp_delete_nav_menu( $menu ) {
$menu = wp_get_nav_menu_object( $menu );
if ( !$menu )
return false;
$menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' );
if ( !empty( $menu_objects ) ) {
foreach ( $menu_objects as $item ) {
wp_delete_post( $item );
}
}
wp_delete_term( $menu_id, 'nav_menu' );
}
/**
* Creates a nav menu named 'Menu 1'.
*
* This function is called if the user doesn't have any nav menus.
* It grabs the first 14 pages, and creates a new default menu.
*
* @since 3.0.0
*/
function wp_create_default_nav_menu() {
$menu = wp_create_nav_menu( __('Menu 1'), array('slug' => 'menu-1') );
@ -61,23 +133,26 @@ function wp_create_default_nav_menu() {
}
}
// Get nav menu by id
function wp_get_nav_menu( $menu ) {
return get_term( (int) $menu, 'nav_menu' );
}
// Get all nav menus
function wp_get_nav_menus() {
return get_terms( 'nav_menu', array( 'hide_empty' => false, 'orderby' => 'id' ) );
}
// Get the nav menu items
/**
* Returns the menu items of a navigation menu.
*
* @since 3.0.0
*
* @param string $menu menu name, id, or slug
* @param string $args
* @return mixed $items array of menu items, else false.
*/
function wp_get_nav_menu_items( $menu, $args = array() ) {
$items = get_objects_in_term( (int) $menu, 'nav_menu' );
$menu = wp_get_nav_menu_object( $menu );
if ( !$menu )
return false;
$items = get_objects_in_term( $menu->term_id, 'nav_menu' );
if ( ! empty( $items ) ) {
$defaults = array( 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order' );
$args = wp_parse_args($args, $defaults);
$args = wp_parse_args( $args, $defaults );
if ( count( $items ) > 1 )
$args['include'] = implode( ',', $items );
else
@ -90,21 +165,30 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
foreach ( $items as $item ) {
$output[$item->$args['output_key']] = $item;
}
unset($items);
ksort($output);
unset( $items );
ksort( $output );
return $output;
}
}
return $items;
}
// wp_setup_nav_menu_item()
function wp_setup_nav_menu_item($menu_item, $type = 'item', $position = 0) {
/**
* Returns a menu item with all it's nessecary data populated.
*
* @since 3.0.0
*
* @param string $menu_item Menu item.
* @param string $type item|category|page.
* @param string $position position of the menu item.
* @return $menu_item
*/
function wp_setup_nav_menu_item( $menu_item, $type = 'item', $position = 0 ) {
global $parent_menu_order;
if ( 'item' == $type ) {
$menu_item->type = get_post_meta($menu_item->ID, 'menu_type', true);
$menu_item->object_id = get_post_meta($menu_item->ID, 'object_id', true);
$menu_item->type = get_post_meta( $menu_item->ID, 'menu_type', true );
$menu_item->object_id = get_post_meta( $menu_item->ID, 'object_id', true );
$menu_item->target = ( get_post_meta( $menu_item->ID, 'menu_new_window', true ) ) ? 'target="_blank"' : '';
if ( isset( $parent_menu_order[ $menu_item->post_parent ] ) )
$menu_item->parent_item = $parent_menu_order[ $menu_item->post_parent ];
@ -165,8 +249,9 @@ function wp_setup_nav_menu_item($menu_item, $type = 'item', $position = 0) {
$menu_item->li_class = '';
global $wp_query;
if ( $menu_item->ID == $wp_query->get_queried_object_id() )
$menu_item->li_class = 'class="current_page_item"';
if ( $menu_item->object_id == $wp_query->get_queried_object_id() )
$menu_item->li_class = ' current_page_item';
$menu_item->anchor_title = '';
/* @todo: update to use tax/post data
@ -195,5 +280,4 @@ function wp_setup_nav_menu_item($menu_item, $type = 'item', $position = 0) {
return $menu_item;
}
?>