diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php
index 98e15cf889..e43cf06717 100644
--- a/wp-admin/admin-ajax.php
+++ b/wp-admin/admin-ajax.php
@@ -1004,7 +1004,7 @@ case 'closed-postboxes' :
update_user_option($user->ID, "closedpostboxes_$page", $closed);
if ( is_array($hidden) ) {
- $hidden = array_diff( $hidden, array('submitdiv', 'linksubmitdiv') ); // postboxes that are always shown
+ $hidden = array_diff( $hidden, array('submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu') ); // postboxes that are always shown
update_user_option($user->ID, "meta-box-hidden_$page", $hidden);
}
@@ -1395,6 +1395,33 @@ case 'set-post-thumbnail':
}
}
die( '0' );
+case 'save-custom-link':
+ if ( ! current_user_can('manage_links') )
+ die('-1');
+
+ $link_name = isset( $_POST['link_name'] ) ? esc_html($_POST['link_name']) : null;
+ $link_url = isset( $_POST['link_url'] ) ? esc_url_raw($_POST['link_url']) : null;
+
+ if ( !$link_name || !$link_url )
+ die('-1');
+
+ $post = array(
+ 'post_status' => 'draft', 'post_type' => 'nav_menu_item', 'ping_status' => 0,
+ 'post_author' => $user_ID, 'post_title' => $link_name, 'post_excerpt' => '',
+ 'post_parent' => 0, 'menu_order' => 0, 'post_content' => '',
+ );
+
+ $link_id = wp_insert_post( $post );
+
+ update_post_meta( $link_id, '_menu_item_type', 'custom' );
+ update_post_meta( $link_id, '_menu_item_object_id', (int) $link_id );
+ update_post_meta( $link_id, '_menu_item_object', 'custom' );
+ update_post_meta( $link_id, '_menu_item_target', '_self' );
+ update_post_meta( $link_id, '_menu_item_classes', '' );
+ update_post_meta( $link_id, '_menu_item_xfn', '' );
+ update_post_meta( $link_id, '_menu_item_url', $link_url );
+
+ die( json_encode($link_id) );
default :
do_action( 'wp_ajax_' . $_POST['action'] );
die('0');
diff --git a/wp-admin/css/nav-menu.css b/wp-admin/css/nav-menu.css
index 07c8034ac4..d108856736 100644
--- a/wp-admin/css/nav-menu.css
+++ b/wp-admin/css/nav-menu.css
@@ -1 +1 @@
-#menu-management{clear:both;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{font-size:11px;}#cancel-save{color:#f00;text-decoration:underline;font-size:11px;margin-left:20px;margin-top:5px;}#cancel-save:hover{background-color:#F00;color:#fff;}.button-controls{float:left;}.add-to-menu{float:right;}#manage-menu .inside{padding:0;}#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-textbox{float:right;width:220px;}.howto span{margin-top:4px;display:block;float:left;}.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 .menu-item-title{cursor:pointer;display:block;}.list li .menu-item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .menu-item-title{margin-left:14px;}.list li ul li ul li .menu-item-title{margin-left:28px;}.list li ul li ul li ul li .menu-item-title{margin-left:42px;}.list li ul li ul li ul li ul li .menu-item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .menu-item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .menu-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 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 .menu-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;}
\ No newline at end of file
+#menu-management{clear:both;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{font-size:11px;}#cancel-save{color:#f00;text-decoration:underline;font-size:11px;margin-left:20px;margin-top:5px;}#cancel-save:hover{background-color:#F00;color:#fff;}.list-controls{float:left;}.add-to-menu{float:right;}.button-controls{margin:10px 0;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}#create-menu-name{width:159px;}#manage-menu .inside{padding: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-textbox{float:right;width:220px;}.howto span{margin-top:4px;display:block;float:left;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;margin-bottom:10px;}.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 .menu-item-title{cursor:pointer;display:block;}.list li .menu-item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .menu-item-title{margin-left:14px;}.list li ul li ul li .menu-item-title{margin-left:28px;}.list li ul li ul li ul li .menu-item-title{margin-left:42px;}.list li ul li ul li ul li ul li .menu-item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .menu-item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .menu-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-radius:6px;border-radius:6px;-moz-border-radius: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 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 .menu-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;}.button-controls:after,#menu-item-url-wrap:after,#menu-item-name-wrap:after{content:".";display:block;height:0;clear:both;visibility:hidden;}.button-controls,#menu-item-url-wrap,#menu-item-name-wrap{display:block;}
\ No newline at end of file
diff --git a/wp-admin/css/nav-menu.dev.css b/wp-admin/css/nav-menu.dev.css
index 923857d9f3..01333b359c 100644
--- a/wp-admin/css/nav-menu.dev.css
+++ b/wp-admin/css/nav-menu.dev.css
@@ -20,28 +20,26 @@
#cancel-save:hover { background-color: #FF0000; color: #fff; }
/* Button Secondary Actions */
-.button-controls { float: left; }
+.list-controls { float: left; }
.add-to-menu { float: right; }
-
-#manage-menu .inside { padding: 0px 0px; }
+.button-controls { margin: 10px 0; }
+.show-all, .hide-all { cursor: pointer; }
+.hide-all { display: none; }
/* Create Menu */
#create-menu-name { width: 159px; }
+#manage-menu .inside { padding: 0px 0px; }
/* Custom Links */
-#available-links { margin: 15px 0px 0px; }
#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-textbox { float: right; width: 220px; }
.howto span { margin-top: 4px; display: block; float: left; }
-/* Pages/Categories */
-.show-all, .hide-all { cursor: pointer; }
-.hide-all { display: none; }
-
+/* Menu item types */
.quick-search { width: 190px; }
-.list-wrap { display: none; clear: both; }
+.list-wrap { display: none; clear: both; margin-bottom: 10px; }
.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; }
@@ -60,12 +58,12 @@
.list li ul li ul li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 98px; }
.list li ul li ul li ul li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 112px; }
-/* Menu */
+/* Nav 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 { -webkit-border-radius: 6px; border-radius: 6px; -moz-border-radius: 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 { }
@@ -78,7 +76,7 @@
.dropzone { height: 7px; margin: 3px 0 3px 0; }
.ui-draggable-dragging { width: 600px; }
-/* Menu Controls */
+/* Menu item controls */
.item-type { text-transform: uppercase; font-size: 11px; color: #999999; padding-right: 10px; }
.item-controls { font-size: 11px; position: absolute; right: 15px; top: -1px; }
.item-controls a { text-decoration: none; }
@@ -92,4 +90,8 @@
#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; }
\ No newline at end of file
+#update-menu-item:focus { color: #eaf2fa !important; border-color: #13455b !important; }
+
+/* Clearfix */
+.button-controls:after, #menu-item-url-wrap:after, #menu-item-name-wrap:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
+.button-controls, #menu-item-url-wrap, #menu-item-name-wrap { display: block; }
\ No newline at end of file
diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php
index 73e1443fbd..0af3626df4 100644
--- a/wp-admin/includes/nav-menu.php
+++ b/wp-admin/includes/nav-menu.php
@@ -1,10 +1,46 @@
ID, 'meta-box-hidden_nav-menus', $hidden_meta_boxes );
+
+ // returns all the hidden metaboxes to the js function: wpNavMenu.initial_meta_boxes()
+ return join( ',', $hidden_meta_boxes );
+ }
+}
/**
* Creates metaboxes for any post type menu item.
@@ -15,15 +51,11 @@ function wp_nav_menu_post_type_metaboxes() {
$post_types = get_post_types( array( 'public' => true ), 'object' );
if ( !$post_types )
- return false;
+ return;
- $allowed_types = apply_filters('post_types_allowed_in_menus', array('page'));
foreach ( $post_types as $post_type ) {
- if ( !in_array($post_type->name, $allowed_types) )
- continue;
$id = $post_type->name;
-
- add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'menus', 'side', 'default', $post_type );
+ add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'nav-menus', 'side', 'default', $post_type );
}
}
@@ -36,15 +68,12 @@ function wp_nav_menu_taxonomy_metaboxes() {
$taxonomies = get_taxonomies( array( 'show_ui' => true ), 'object' );
if ( !$taxonomies )
- return false;
+ return;
- $allowed_types = apply_filters('taxonomies_allowed_in_menus', array('category'));
foreach ( $taxonomies as $tax ) {
- if ( !in_array($tax->name, $allowed_types) )
- continue;
$id = $tax->name;
- add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', 'menus', 'side', 'default', $tax );
+ add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', 'nav-menus', 'side', 'default', $tax );
}
}
@@ -98,11 +127,11 @@ function wp_nav_menu_create_metabox() { ?>
* @since 3.0.0
*/
function wp_nav_menu_item_link_metabox() {
- $args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom', 'showposts' => -1 );
+ // @note: hacky query, see #12660
+ $args = array( 'post_type' => 'nav_menu_item', 'post_status' => 'any', 'meta_key' => '_menu_item_type', 'numberposts' => -1, 'orderby' => 'title', );
// @todo transient caching of these results with proper invalidation on updating links
- $query = new WP_Query( $args );
-
+ $links = get_posts( $args );
?>
-
-
-
+
+
+
+
+
+
- posts, 'custom' ); ?>
+
-
$post_type['args']->name, 'post_status' => 'publish', 'showposts' => -1 );
-
- if ( 'attachment' == $post_type['args']->name )
- $args['post_status'] = 'any';
+ $args = array( 'post_type' => $post_type['args']->name, 'numberposts' => -1, 'orderby' => 'title', );
// @todo transient caching of these results with proper invalidation on updating of a post of this type
- $query = new WP_Query( $args );
+ $posts = get_posts( $args );
- if ( !$query->posts )
+ if ( !$posts )
$error = ''. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .' ';
$pt_names = '';
- if ( is_array($query->posts) ) {
- foreach ( $query->posts as $post ) {
+ if ( is_array($posts) ) {
+ foreach ( $posts as $post ) {
if ( $post->post_title ) {
$pt_names .= htmlentities( $post->post_title ) .'|';
- } else {
- $pt_names = sprintf( __('No %s exists'), $post_type['args']->label );
}
}
}
@@ -175,26 +201,29 @@ function wp_nav_menu_item_post_type_metabox( $object, $post_type ) {
-
-
+
+
+
+
+
+
- posts, 'post_type', $id ); ?>
+
-
@@ -227,8 +256,6 @@ function wp_nav_menu_item_taxonomy_metabox( $object, $taxonomy ) {
foreach ( $terms as $term ) {
if ( $term->name ) {
$term_names .= htmlentities( $term->name ) .'|';
- } else {
- $term_names = sprintf( __('No %s exists'), $taxonomy['args']->label );
}
}
}
@@ -241,8 +268,14 @@ function wp_nav_menu_item_taxonomy_metabox( $object, $taxonomy ) {
-
-
+
+
+
+
+
+
@@ -252,15 +285,12 @@ function wp_nav_menu_item_taxonomy_metabox( $object, $taxonomy ) {
-
@@ -290,15 +320,20 @@ function wp_nav_menu_get_items( $menu_items, $object_type, $object = null, $cont
if ( !isset($menu_item->post_parent) )
$menu_item->post_parent = $menu_item->parent;
- // Cleanest way to get all attachements
- if ( 'attachment' == $object )
+ // Get all attachements and links
+ if ( in_array($object, array( 'attachment', 'custom' )) )
$menu_item->post_parent = 0;
if ( 0 == $menu_item->post_parent ) {
// Set up the menu item
$menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object );
+
+ // No blank titles
+ if ( empty($menu_item->title) )
+ continue;
+
$attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : '';
-
+
$output .= '';
$output .= wp_get_nav_menu_item( $menu_item, $object_type, $object );
$output .= wp_get_nav_menu_sub_items( $menu_item->ID, $object_type, $object, $context );
diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php
index b3008ef197..fc7aba9714 100644
--- a/wp-admin/includes/upgrade.php
+++ b/wp-admin/includes/upgrade.php
@@ -1105,13 +1105,26 @@ function upgrade_290() {
* @since 3.0.0
*/
function upgrade_300() {
- global $wp_current_db_version;
+ global $wp_current_db_version, $wpdb;
if ( $wp_current_db_version < 12751 ) {
populate_roles_300();
if ( is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false )
add_site_option( 'siteurl', '' );
}
+
+ // 3.0-alpha nav menu postmeta changes. can be removed before release
+ if ( $wp_current_db_version >= 13226 && $wp_current_db_version < 13802 ) {
+ // remove old nav menu post meta keys
+ $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key IN( 'menu_type', 'object_id', 'menu_new_window', 'menu_link', '_menu_item_append', 'menu_item_append' )" );
+ // update nav menu post meta keys to underscore prefixes
+ $wpdb->update( $wpdb->postmeta, array( 'meta_key' => '_menu_item_type' ), array( 'meta_key' => 'menu_item_type' ) );
+ $wpdb->update( $wpdb->postmeta, array( 'meta_key' => '_menu_item_object_id' ), array( 'meta_key' => 'menu_item_object_id' ) );
+ $wpdb->update( $wpdb->postmeta, array( 'meta_key' => '_menu_item_target' ), array( 'meta_key' => 'menu_item_target' ) );
+ $wpdb->update( $wpdb->postmeta, array( 'meta_key' => '_menu_item_classes' ), array( 'meta_key' => 'menu_item_classes' ) );
+ $wpdb->update( $wpdb->postmeta, array( 'meta_key' => '_menu_item_xfn' ), array( 'meta_key' => 'menu_item_xfn' ) );
+ $wpdb->update( $wpdb->postmeta, array( 'meta_key' => '_menu_item_url' ), array( 'meta_key' => 'menu_item_url' ) );
+ }
}
/**
diff --git a/wp-admin/js/nav-menu.dev.js b/wp-admin/js/nav-menu.dev.js
index 59bb36b3c8..f418962c82 100644
--- a/wp-admin/js/nav-menu.dev.js
+++ b/wp-admin/js/nav-menu.dev.js
@@ -1,489 +1,491 @@
/**
- * WordPress Administration Custom Navigation
+ * WordPress Administration Navigation Menu
* Interface JS functions
*
- * @version 1.1.0
- *
- * @package WordPress
- * @subpackage Administration
- */
-
-function wp_nav_menu_autocomplete( id ) {
- jQuery('#add-'+ id +' .quick-search').autocomplete(jQuery( '#add-'+ id +' .autocomplete' ).val().split('|'));
-
- jQuery('#add-'+ id +' .quick-search').result(function(event, data, formatted) {
- jQuery('#add-'+ id +' .list-wrap').css( 'display', 'block' );
- jQuery("#add-"+ id +" .list-wrap li:contains('" + data + "')").css( 'display', 'block' );
- jQuery('#add-'+ id +' .show-all').hide();
- jQuery('#add-'+ id +' .hide-all').show();
- });
-}
-
-/**
- * Populate the thickbox window with the selected menu items
- *
- * @param int id - the id of the menu li to edit.
- */
-function wp_edit_menu_item( id ) {
- var item_type = jQuery('#menu-item-type' + id).val();
- var item_title = jQuery('#menu-item-title' + id).val();
- var item_link = jQuery('#menu-item-url' + id).val();
- var item_attr_title = jQuery('#menu-item-attr-title' + id).val();
- var item_target = jQuery('#menu-item-target' + id).val();
- var item_description = jQuery('#menu-item-description' + id).val();
- var item_classes = jQuery('#menu-item-classes' + id).val();
- var item_xfn = jQuery('#menu-item-xfn' + id).val();
-
- // Only allow custom links to be editable.
- if ( 'custom' != item_type )
- jQuery( '#edit-menu-item-url' ).attr('disabled', 'disabled' );
-
- // Populate the fields for thickbox
- jQuery( '#edit-menu-item-id' ).val(id);
- jQuery( '#edit-menu-item-title' ).val(item_title);
- jQuery( '#edit-menu-item-url' ).val(item_link);
- jQuery( '#edit-menu-item-attr-title' ).val(item_attr_title);
- jQuery( '#edit-menu-item-target' ).val(item_target);
- jQuery( "#edit-menu-item-target option[value='" + item_target + "']" ).attr('selected', 'selected');
- jQuery( '#edit-menu-item-description' ).val(item_description);
- jQuery( '#edit-menu-item-classes' ).val(item_classes);
- jQuery( '#edit-menu-item-xfn' ).val(item_xfn);
-
- // focus
- jQuery( '#edit-menu-item-title' ).focus();
-};
-
-/**
- * Update the values for the menu item being editing
- */
-function wp_update_menu_item() {
- var id = jQuery('#edit-menu-item-id').val();
- var item_title = jQuery('#edit-menu-item-title').val();
- var item_link = jQuery('#edit-menu-item-url').val();
- var item_attr_title = jQuery('#edit-menu-item-attr-title').val();
- var item_target = jQuery('#edit-menu-item-target').val();
- var item_description = jQuery('#edit-menu-item-description').val();
- var item_classes = jQuery('#edit-menu-item-classes').val();
- var item_xfn = jQuery('#edit-menu-item-xfn').val();
-
- // update menu item settings
- jQuery('.menu #menu-item' + id).find('span.item-title').html(item_title);
- jQuery('.menu #menu-item-title' + id).val(item_title);
- jQuery('.menu #menu-item-url' + id).val(item_link);
- jQuery('.menu #menu-item-attr-title' + id).val(item_attr_title);
- jQuery('.menu #menu-item-target' + id).val(item_target);
- jQuery('.menu #menu-item-description' + id).val(item_description);
- jQuery('.menu #menu-item-classes' + id).val(item_classes);
- jQuery('.menu #menu-item-xfn' + id).val(item_xfn);
-
- jQuery('.menu #menu-item' + id + ' dt:first').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-item' + 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() } } );
- });
- }
-};
-
-/**
- * Adds the item to the menu
- *
- * @param string item_db_id - The menu item's db id.
- * @param string item_object_id - The menu item's object id.
- * @param string item_type - The menu item's object type.
- * @param string item_append - The menu item's nice name.
- * @param string item_parent_id - The menu item's parent id.
- * @param string item_title - The menu item title.
- * @param string item_url - The menu item url
- * @param string item_description - The menu item description.
- * @param string item_attr_title - The title attribute.
- * @param string item_target - The target attribute.
- * @param string item_classes - Optional. Additional CSS classes for the menu item
- * @param string item_xfn - Optional. The rel attribute.
- */
-function wp_add_item_to_menu( item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) {
- var randomnumber = wp_get_unique_menu_id();
- var hidden = wp_get_hidden_inputs( randomnumber, item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn );
-
- // Adds the item in the queue
- jQuery('.menu').append('
' + item_title + ' ' + item_append + ' ' + navMenuL10n.edit + ' | Delete ' + hidden + ' ');
-
- // Give some feedback to the user
- jQuery( '.menu #menu-item' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
-
- // Enable drag-n-drop
- wp_drag_and_drop();
-
- // Reload thickbox
- tb_init('a.thickbox, area.thickbox, input.thickbox');
-};
-
-/**
- * Grabs items from the queue and adds them to the menu.
- *
- * @param string button - a reference to the button that was clicked
- */
-function wp_add_checked_items_to_menu( button ) {
- // Grab checked items
- var items = jQuery(button).siblings('.list-wrap').find(':checked');
-
- // If nothing was checked, cancel
- if ( 0 == items.length )
- return false;
-
- // Loop through each item, grab it's hidden data and add it to the menu.
- jQuery(items).each(function(){
- var item_type = jQuery(this).parent().siblings('.menu-item-type').val();
-
- if ( 'custom' == item_type ) {
- var item_attr_title = jQuery(this).parent().siblings('.menu-item-attr-title').val();
- var item_target = jQuery(this).parent().siblings('.menu-item-target').val();
- var item_classes = jQuery(this).parent().siblings('.menu-item-classes').val();
- var item_xfn = jQuery(this).parent().siblings('.menu-item-xfn').val();
- } else {
- var item_attr_title = '';
- var item_target = '_self';
- var item_classes = '';
- var item_xfn = '';
- };
-
- var item_db_id = jQuery(this).parent().siblings('.menu-item-db-id').val();
- var item_object_id = jQuery(this).parent().siblings('.menu-item-object-id').val();
- var item_append = jQuery(this).parent().siblings('.menu-item-append').val();
- var item_parent_id = jQuery(this).parent().siblings('.menu-item-parent-id').val();
- var item_title = jQuery(this).parent().siblings('.menu-item-title').val();
- var item_url = jQuery(this).parent().siblings('.menu-item-url').val();
- var item_description = jQuery(this).parent().siblings('.menu-item-description').val();
-
- if ( undefined == item_description ) {
- item_description = '';
- };
-
- // Add the menu item to the menu
- wp_add_item_to_menu( item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn );
-
- // uncheck the menu item in the list
- jQuery(this).attr( 'checked', false );
- });
-};
-
-/**
- * Makes the menu items drag and droppable.
- */
-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( '' );
- }
- // 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);
- 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');
- }
- // Add above
- else if ( jQuery(this).attr('class') == 'ui-droppable' ) {
- jQuery(this).parent().find('dt:first').css('background', '#d8d8d8');
- } else {
- // do nothing
- }
- var parentid = jQuery(this).parent().attr('id');
-
- },
- out: function() {
- jQuery(this).parent().find('dt').removeAttr('style');
- jQuery(this).parent().find('div:first').removeAttr('style');
- jQuery(this).filter('.dropzone').css({ borderColor: '' });
- }
- }
- );
-}
-
-/**
- * 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('#menu-item-position' + j).attr('value', i);
- jQuery(this).attr('id','menu-item' + i);
- jQuery(this).attr('value', i);
-
- jQuery(this).find('#menu-item-db-id' + j).attr('id','menu-item-db-id' + i);
- jQuery(this).find('#menu-item-object-id' + j).attr('id','menu-item-object-id' + i);
- jQuery(this).find('#menu-item-append' + j).attr('id', 'menu-item-append' + i);
- jQuery(this).find('#menu-item-type' + j).attr('id', 'menu-item-type' + i);
- jQuery(this).find('#menu-item-position' + j).attr('id', 'menu-item-position' + i);
-
- var p = jQuery(this).find('#menu-item-parent-id' + j).parent().parent().parent().attr('value');
- jQuery(this).find('#menu-item-parent-id' + j).attr('id','menu-item-parent-id' + i);
- if (p) {
- // Do nothing
- } else {
- // reset p to be top level
- p = 0;
- }
- jQuery(this).find('#menu-item-parent-id' + j).attr('value', p);
-
- jQuery(this).find('#menu-item-title' + j).attr('id','menu-item-title' + i);
- jQuery(this).find('#menu-item-url' + j).attr('id','menu-item-url' + i);
- jQuery(this).find('#menu-item-description' + j).attr('id','menu-item-description' + i);
- jQuery(this).find('#menu-item-classes' + j).attr('id','menu-item-classes' + i);
- jQuery(this).find('#menu-item-xfn' + j).attr('id','menu-item-xfn' + i);
- jQuery(this).find('#menu-item-description' + j).attr('id','menu-item-description' + i);
- jQuery(this).find('#menu-item-attr-title' + j).attr('id','menu-item-attr-title' + i);
- jQuery(this).find('#menu-item-target' + j).attr('id','menu-item-target' + i);
-
- jQuery('#li-count').attr( 'value', i );
- });
-};
-
-/**
- * Gets a unique number based on how many items are in the menu
- */
-function wp_get_unique_menu_id() {
- var count = jQuery('.menu li').length + 1;
- var randomnumber = count;
- var validatetest = 0;
-
- try {
- var test = document.getElementById( 'menu-' + randomnumber.toString() ).value;
- }
- catch ( err ) {
- validatetest = 1;
- }
-
- while ( validatetest == 0 ) {
- randomnumber = randomnumber + 1;
- try {
- var test2 = document.getElementById( 'menu-' + randomnumber.toString() ).value;
- }
- catch ( err ) {
- validatetest = 1;
- }
- }
- return randomnumber;
-}
-
-/**
- * Returns all the nessecary hidden inputs for each menu item.
- *
- * @param string item_db_id - The menu item's db id.
- * @param string item_object_id - The menu item's object id.
- * @param string item_type - The menu item's object type.
- * @param string item_append - The menu item's nice name.
- * @param string item_parent_id - The menu item's parent id.
- * @param string item_title - The menu item title.
- * @param string item_url - The menu item url
- * @param string item_description - The menu item description.
- * @param string item_attr_title - The title attribute.
- * @param string item_target - The target attribute.
- * @param string item_classes - Optional. Additional CSS classes for the menu item
- * @param string item_xfn - Optional. The rel attribute.
- */
-function wp_get_hidden_inputs( randomnumber, item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) {
- var hidden = '';
-
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
- hidden += ' ';
-
- return hidden;
-}
-
-/**
- * WordPress Administration Custom Navigation
- * Interface $ functions
- *
* @version 2.0.0
*
* @package WordPress
* @subpackage Administration
*/
-/**
- * Init Functions
- */
-jQuery(document).ready(function($){
+var wpNavMenu;
- wp_drag_and_drop();
+(function($) {
+
+ wpNavMenu = {
+
+ // Functions that run on init.
+ init : function() {
+
+ wpNavMenu.initial_meta_boxes();
+
+ wpNavMenu.drag_and_drop();
+
+ // Delete AYS
+ $('#update-nav-menu .deletion').click(function(){
+ if ( confirm( navMenuL10n.warnDelete ) ) {
+ return true;
+ } else {
+ return false;
+ };
+ });
- // Delete AYS
- $('#update-nav-menu .deletion').click(function(){
- if ( confirm( navMenuL10n.warnDelete ) ) {
- return true;
- } else {
- return false;
- };
- });
+ // Handle Save Button Clicks
+ $('#update-nav-menu').submit(function(){
+ wpNavMenu.update_post_data();
+ });
- // Handle Save Button Clicks
- $('#save_menu').click(function(){
- return wp_update_post_data();
- });
+ // Handle some return keypresses
+ $('#create-menu-name').keypress(function(e){
+ if ( 13 == e.keyCode ) {
+ $('#create-menu-button').click();
+ return false;
+ }
+ });
- // Handle some return keypresses
- $('#create-menu-name').keypress(function(e){
- if ( 13 == e.keyCode ) {
- $('#create-menu-button').click();
- return false;
+ $('#custom-menu-item-url, #custom-menu-item-name').keypress(function(e){
+ if ( 13 == e.keyCode ) {
+ $('#add-custom-links a.button').click();
+ return false;
+ }
+ }).focus(function(){
+ if ( $(this).val() == $(this).attr('defaultValue') && $(this).attr('id') != 'custom-menu-item-url' ) {
+ $(this).val('');
+ }
+ }).blur(function(){
+ if ( $(this).val() == '' ) {
+ $(this).val($(this).attr('defaultValue'));
+ }
+ });
+
+ $('#create-menu-name').focus(function(){
+ if ( $(this).val() == $(this).attr('defaultValue') ) {
+ $(this).val('');
+ }
+ }).blur(function(){
+ if ( $(this).val() == '' ) {
+ $(this).val($(this).attr('defaultValue'));
+ }
+ });
+
+ // close postboxes that should be closed
+ $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
+
+ // postboxes setup
+ postboxes.add_postbox_toggles('nav-menus');
+
+ // Clear the quick search textbox
+ $('.quick-search').click(function(){
+ $(this).attr( 'value', '' );
+ });
+
+ // Quick Search submit
+ $('.quick-search-submit').click(function(){
+ $(this).siblings('.quick-search').search();
+ });
+
+ // Edit menu item
+ $('#menu-container .item-edit').click(function(){
+ wpNavMenu.edit_menu_item( $(this).attr('value') );
+ });
+
+ // Delete menu item
+ $('#menu-container .item-delete').click(function(){
+ wpNavMenu.remove_menu_item( $(this).attr('value') );
+ });
+
+ // Update menu item settings (thickbox)
+ $('#update-menu-item').click(function(){
+ wpNavMenu.update_menu_item();
+ tb_remove();
+ });
+
+ // Close thickbox
+ $('#cancel-save').click(function(){
+ tb_remove();
+ });
+
+ // Show All Button
+ $('.show-all').click(function(e){
+ $(e.currentTarget).parent().parent().siblings('.list-wrap').css( 'display', 'block' );
+ $(e.currentTarget).parent().parent().siblings('.list-wrap').find('li').css( 'display', 'block' );
+ $(e.currentTarget).hide();
+ $(e.currentTarget).siblings('.hide-all').show();
+ });
+
+ // Hide All Button
+ $('.hide-all').click(function(e){
+ $(e.currentTarget).parent().parent().siblings('.list-wrap').css( 'display', 'none' );
+ $(e.currentTarget).parent().parent().siblings('.list-wrap').find('li').css( 'display', 'none' );
+ $(e.currentTarget).hide();
+ $(e.currentTarget).siblings('.show-all').show();
+ });
+
+ // Add menu items into the menu
+ $('.add-to-menu').click(function(e){
+ wpNavMenu.add_checked_items_to_menu(e.currentTarget);
+ });
+
+ // Create a new link then add it to the menu
+ $('#add-custom-links .add-to-menu a').click(function(e){
+ // Add link to menu
+ if ( $('#custom-menu-item-url').val() == $('#custom-menu-item-url').attr('defaultValue') )
+ return; // Do not allow "http://" submissions to go through
+
+ wpNavMenu.add_custom_link( $('#custom-menu-item-name').val(), $('#custom-menu-item-url').val() );
+
+ // Reset the fields back to their defaults
+ $('#custom-menu-item-name').val($('#custom-menu-item-name').attr('defaultValue'));
+ $('#custom-menu-item-url' ).val($('#custom-menu-item-url' ).attr('defaultValue')).focus();
+ });
+ },
+
+ add_custom_link : function( link_name, link_url ) {
+ var params = {
+ action: 'save-custom-link',
+ link_name: link_name,
+ link_url: link_url
+ }
+
+ $.post( ajaxurl, params, function(link_id) {
+ if ( '-1' == link_id )
+ return;
+
+ wpNavMenu.add_to_menu( link_id, link_id, 'custom', 'custom', navMenuL10n.custom, 0, link_name, link_url, '', '', '_self', '', '' );
+ }, 'json');
+ },
+
+ /**
+ * In combination with the php function wp_initial_nav_menu_meta_boxes(),
+ * this function limits the metaboxes for first time users to just links, pages and cats.
+ */
+ initial_meta_boxes : function() {
+ var hidden = $('#hidden-metaboxes').val().split( ',' );
+
+ if ( '' != hidden ) {
+ for ( var i = 0; i < hidden.length; i++ ) {
+ $( '#' + hidden[i] ).attr( 'style', 'display: none;' );
+ $( '#' + hidden[i] + '-hide' ).attr( 'checked', false );
+ };
+ };
+ },
+
+ // Makes the menu items drag and droppable.
+ drag_and_drop : function() {
+ // Make sure all li's have dropzones
+ $('.menu li').each(function(){
+ if ( !$(this).children('.dropzone').attr('class') ) {
+ $(this).prepend('
');
+ };
+ });
+
+ // make menu item draggable
+ $('.menu li').draggable({
+ handle: ' > dl',
+ opacity: .8,
+ addClasses: false,
+ helper: 'clone',
+ zIndex: 100
+ });
+
+ // make menu item droppable
+ $('.menu li dl, .menu li .dropzone').droppable({
+ accept: '.menu li',
+ tolerance: 'pointer',
+ drop: function(e, ui) {
+ var li = $(this).parent();
+ var child = !$(this).hasClass('dropzone');
+
+ // Append UL to first child
+ if ( child && li.children('ul').length == 0 ) {
+ li.append( '' );
+ }
+ // 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(e) {
+ // Add child
+ if ( $(this).attr('class') == 'dropzone ui-droppable' ) {
+ $(this).parent().find('div:first').css({ background: '#f5f5f5', border: '1px dashed #bbb', margin: '10px 0px', height: '40px' });
+ }
+ // Add above
+ else if ( $(this).attr('class') == 'ui-droppable' ) {
+ $(this).parent().find('dt:first').css('background', '#d8d8d8');
+ } else {
+ // Do nothing
+ }
+ },
+ out: function() {
+ $(this).parent().find('dt').removeAttr('style');
+ $(this).parent().find('div:first').removeAttr('style');
+ $(this).filter('.dropzone').css({ borderColor: '' });
+ }
+ });
+ },
+
+ // Prepares menu items for POST.
+ update_post_data : function() {
+ var i = 0; // counter
+
+ $('.menu li').each(function(){
+ i = i + 1; // the menu order for each item
+
+ var j = $(this).attr('value'); // reference to the current menu item (e.g. li#menu-item + j)
+
+ // Grab the menu item id
+ var id = $(this).children('input[name=menu-item-db-id[]]').val();
+
+ // Update the li value to equal the menu order
+ $(this).attr('value', i);
+
+ // Update the position
+ $(this).children('input[name=menu-item-position[]]').attr( 'value', i );
+
+ // Update the parent id
+ var pid = $(this).parent('.sub-menu').siblings('input[name=menu-item-object-id[]]').val();
+
+ if ( undefined == pid ) {
+ pid = 0;
+ };
+
+ $(this).children('input[name=menu-item-parent-id[]]').attr( 'value', pid );
+
+ // Update the menu item count
+ $('#li-count').attr( 'value', i );
+ });
+ },
+
+ /**
+ * Enables autocomplete for nav menu types.
+ *
+ * @param int id - the id of the menu item type.
+ */
+ autocomplete : function( id ) {
+ $('#add-'+ id +' .quick-search').autocomplete( $( '#add-'+ id +' .autocomplete' ).val().split('|') );
+
+ $('#add-'+ id +' .quick-search').result(function( event, data, formatted ) {
+ $('#add-'+ id +' .list-wrap').css( 'display', 'block' );
+ $("#add-"+ id +" .list-wrap li:contains('" + data + "')").css( 'display', 'block' );
+ $('#add-'+ id +' .show-all').hide();
+ $('#add-'+ id +' .hide-all').show();
+ });
+ },
+
+ /**
+ * Populate the thickbox window with the selected menu items
+ *
+ * @param int id - the id of the menu item to edit.
+ */
+ edit_menu_item : function( id ) {
+ var item_type = $('#menu-item-' + id).children('input[name=menu-item-type[]]').val();
+ var item_title = $('#menu-item-' + id).children('input[name=menu-item-title[]]').val();
+ var item_link = $('#menu-item-' + id).children('input[name=menu-item-url[]]').val();
+ var item_attr_title = $('#menu-item-' + id).children('input[name=menu-item-attr-title[]]').val();
+ var item_target = $('#menu-item-' + id).children('input[name=menu-item-target[]]').val();
+ var item_description = $('#menu-item-' + id).children('input[name=menu-item-description[]]').val();
+ var item_classes = $('#menu-item-' + id).children('input[name=menu-item-classes[]]').val();
+ var item_xfn = $('#menu-item-' + id).children('input[name=menu-item-xfn[]]').val();
+
+ // Only allow custom links to be editable.
+ if ( 'custom' != item_type )
+ $( '#edit-menu-item-url' ).attr('disabled', 'disabled' );
+
+ // Populate the fields for thickbox
+ $( '#edit-menu-item-id' ).val(id);
+ $( '#edit-menu-item-title' ).val(item_title);
+ $( '#edit-menu-item-url' ).val(item_link);
+ $( '#edit-menu-item-attr-title' ).val(item_attr_title);
+ $( '#edit-menu-item-target' ).val(item_target);
+ $( "#edit-menu-item-target option[value='" + item_target + "']" ).attr('selected', 'selected');
+ $( '#edit-menu-item-description' ).val(item_description);
+ $( '#edit-menu-item-classes' ).val(item_classes);
+ $( '#edit-menu-item-xfn' ).val(item_xfn);
+
+ // @todo: focus on #edit-menu-item-title
+ },
+
+ /**
+ * Update the values for the menu item being editing
+ */
+ update_menu_item : function() {
+ var id = $('#edit-menu-item-id').val();
+ var item_title = $('#edit-menu-item-title').val();
+ var item_link = $('#edit-menu-item-url').val();
+ var item_attr_title = $('#edit-menu-item-attr-title').val();
+ var item_target = $('#edit-menu-item-target').val();
+ var item_description = $('#edit-menu-item-description').val();
+ var item_classes = $('#edit-menu-item-classes').val();
+ var item_xfn = $('#edit-menu-item-xfn').val();
+
+ // update menu item settings
+ $('.menu #menu-item-' + id).find('span.item-title:first').html(item_title);
+
+ $('#menu-item-' + id).children('input[name=menu-item-title[]]').val(item_title);
+ $('#menu-item-' + id).children('input[name=menu-item-url[]]').val(item_link);
+ $('#menu-item-' + id).children('input[name=menu-item-attr-title[]]').val(item_attr_title);
+ $('#menu-item-' + id).children('input[name=menu-item-target[]]').val(item_target);
+ $('#menu-item-' + id).children('input[name=menu-item-description[]]').val(item_description);
+ $('#menu-item-' + id).children('input[name=menu-item-classes[]]').val(item_classes);
+ $('#menu-item-' + id).children('input[name=menu-item-xfn[]]').val(item_xfn);
+
+ $('.menu #menu-item-' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { $(this).css( 'backgroundColor', '' ); }});
+ },
+
+ /**
+ * Removes a menu item from current menu
+ *
+ * @param int id - the id of the menu item to remove.
+ */
+ remove_menu_item : function( id ) {
+ var todelete = $('#menu-item-' + id);
+
+ if ( todelete ) {
+ // Give some feedback to the user
+ $( todelete ).find('dt').each(function(){
+ $(this).animate( { backgroundColor: '#FF3333' }, { duration: 'normal', complete: function() { $(this).parent().parent().remove() } } );
+ });
+ }
+ },
+
+ /**
+ * Adds the item to the menu
+ *
+ * @param string item_db_id - The menu item's db id.
+ * @param string item_object_id - The menu item's object id.
+ * @param string item_object - The menu item's object name.
+ * @param string item_type - The menu item's object type.
+ * @param string item_append - The menu item's nice name.
+ * @param string item_parent_id - The menu item's parent id.
+ * @param string item_title - The menu item title.
+ * @param string item_url - The menu item url
+ * @param string item_description - The menu item description.
+ * @param string item_attr_title - The title attribute.
+ * @param string item_target - The target attribute.
+ * @param string item_classes - Optional. Additional CSS classes for the menu item
+ * @param string item_xfn - Optional. The rel attribute.
+ */
+ add_to_menu : function( item_db_id, item_object_id, item_object, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) {
+ var randomnumber = $('.menu li').length + 1;
+ var hidden = wpNavMenu.get_hidden_inputs( randomnumber, item_db_id, item_object_id, item_object, item_type, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn );
+
+ // Adds the item to the menu
+ $('.menu').append('
' + item_title + ' ' + item_append + ' ' + navMenuL10n.edit + ' | Delete ' + hidden + ' ');
+
+ // Give some feedback to the user
+ $( '.menu #menu-item-' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { $(this).css( 'backgroundColor', '' ); }});
+
+ // Enable drag-n-drop
+ wpNavMenu.drag_and_drop();
+
+ // Reload thickbox
+ tb_init('a.thickbox, area.thickbox, input.thickbox');
+ },
+
+ /**
+ * Grabs items from the queue and adds them to the menu.
+ *
+ * @param string button - a reference to the button that was clicked
+ */
+ add_checked_items_to_menu : function( button ) {
+ // Grab checked items
+ var items = $(button).parent().siblings('.list-wrap').find(':checked');
+
+ // If nothing was checked, cancel
+ if ( 0 == items.length )
+ return false;
+
+ // Loop through each item, grab it's hidden data and add it to the menu.
+ $(items).each(function(){
+ var item_type = $(this).parent().siblings('.menu-item-type').val();
+
+ if ( 'custom' == item_type ) {
+ var item_attr_title = $(this).parent().siblings('.menu-item-attr-title').val();
+ var item_target = $(this).parent().siblings('.menu-item-target').val();
+ var item_classes = $(this).parent().siblings('.menu-item-classes').val();
+ var item_xfn = $(this).parent().siblings('.menu-item-xfn').val();
+ } else {
+ var item_attr_title = '';
+ var item_target = '_self';
+ var item_classes = '';
+ var item_xfn = '';
+ };
+
+ var item_db_id = $(this).parent().siblings('.menu-item-db-id').val();
+ var item_object_id = $(this).parent().siblings('.menu-item-object-id').val();
+ var item_object = $(this).parent().siblings('.menu-item-object').val();
+ var item_append = $(this).parent().siblings('.menu-item-append').val();
+ var item_parent_id = $(this).parent().siblings('.menu-item-parent-id').val();
+ var item_title = $(this).parent().siblings('.menu-item-title').val();
+ var item_url = $(this).parent().siblings('.menu-item-url').val();
+ var item_description = $(this).parent().siblings('.menu-item-description').val();
+
+ if ( undefined == item_description ) {
+ item_description = '';
+ };
+
+ if ( undefined == item_attr_title ) {
+ item_attr_title = '';
+ };
+
+ // Add the menu item to the menu
+ wpNavMenu.add_to_menu( item_db_id, item_object_id, item_object, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn );
+
+ // uncheck the menu item in the list
+ $(this).attr( 'checked', false );
+ });
+ },
+
+ /**
+ * Returns all the nessecary hidden inputs for each menu item.
+ *
+ * @param string item_db_id - The menu item's db id.
+ * @param string item_object_id - The menu item's object id.
+ * @param string item_object - The menu item's object name.
+ * @param string item_type - The menu item's object type.
+ * @param string item_append - The menu item's nice name.
+ * @param string item_parent_id - The menu item's parent id.
+ * @param string item_title - The menu item title.
+ * @param string item_url - The menu item url
+ * @param string item_description - The menu item description.
+ * @param string item_attr_title - The title attribute.
+ * @param string item_target - The target attribute.
+ * @param string item_classes - Optional. Additional CSS classes for the menu item
+ * @param string item_xfn - Optional. The rel attribute.
+ */
+ get_hidden_inputs : function( randomnumber, item_db_id, item_object_id, item_object, item_type, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) {
+ var hidden = '';
+
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+
+ return hidden;
}
- });
-
- $('#custom-menu-item-url, #custom-menu-item-name').keypress(function(e){
- if ( 13 == e.keyCode ) {
- $('#add-custom-links a.button').click();
- return false;
- }
- }).focus(function(){
- if ( $(this).val() == $(this).attr('defaultValue') && $(this).attr('id') != 'custom-menu-item-url' ) {
- $(this).val('');
- }
- }).blur(function(){
- if ( $(this).val() == '' ) {
- $(this).val($(this).attr('defaultValue'));
- }
- });
-
- $('#create-menu-name').focus(function(){
- if ( $(this).val() == $(this).attr('defaultValue') ) {
- $(this).val('');
- }
- }).blur(function(){
- if ( $(this).val() == '' ) {
- $(this).val($(this).attr('defaultValue'));
- }
- });
-
- // close postboxes that should be closed
- $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
-
- // postboxes setup
- postboxes.add_postbox_toggles('menus');
-
- // Clear the quick search textbox
- $('.quick-search').click(function(){
- $(this).attr( 'value', '' );
- });
-
- // Quick Search submit
- $('.quick-search-submit').click(function(){
- $(this).siblings('.quick-search').search();
- });
-
- // Edit menu item
- $('#menu-container .item-edit').click(function(){
- return wp_edit_menu_item( $(this).attr('value') );
- });
-
- // Delete menu item
- $('#menu-container .item-delete').live( 'click', function(e){
- return wp_remove_menu_item( $(this).attr('value') );
- });
-
- // Update menu item settings (thickbox)
- $('#update-menu-item').click(function(){
- wp_update_menu_item();
- return tb_remove();
- });
-
- // Close thickbox
- $('#cancel-save').click(function(){
- return tb_remove();
- });
-
- // Show All Button
- $('.show-all').click(function(e){
- jQuery(e.currentTarget).parent().siblings('.list-wrap').css( 'display', 'block' );
- jQuery(e.currentTarget).parent().siblings('.list-wrap').find('li').css( 'display', 'block' );
- jQuery(e.currentTarget).hide();
- jQuery(e.currentTarget).siblings('.hide-all').show();
- });
-
- // Hide All Button
- $('.hide-all').click(function(e){
- jQuery(e.currentTarget).parent().siblings('.list-wrap').css( 'display', 'none' );
- jQuery(e.currentTarget).parent().siblings('.list-wrap').find('li').css( 'display', 'none' );
- jQuery(e.currentTarget).hide();
- jQuery(e.currentTarget).siblings('.show-all').show();
- });
-
- // Add menu items into the menu
- $('.add-to-menu').click(function(e){
- return wp_add_checked_items_to_menu(e.currentTarget);
- });
-
- // Create a new link then add it to the menu
- $('#add-custom-links .add-to-menu a').click(function(e){
- // Add link to menu
- if ( $('#custom-menu-item-url').val() == $('#custom-menu-item-url').attr('defaultValue') )
- return; // Do not allow "http://" submissions to go through
- wp_add_item_to_menu( 0, '', 'custom', navMenuL10n.custom, 0, $('#custom-menu-item-name').val(), $('#custom-menu-item-url').val(), '', '', '_self', '', '' );
- $('#custom-menu-item-name').val($('#custom-menu-item-name').attr('defaultValue'));
- $('#custom-menu-item-url' ).val($('#custom-menu-item-url' ).attr('defaultValue')).focus();
- });
-});
\ No newline at end of file
+ }
+
+ $(document).ready(function($){ wpNavMenu.init(); });
+})(jQuery);
\ No newline at end of file
diff --git a/wp-admin/js/nav-menu.js b/wp-admin/js/nav-menu.js
index c76a2339ec..098f212f51 100644
--- a/wp-admin/js/nav-menu.js
+++ b/wp-admin/js/nav-menu.js
@@ -1 +1 @@
-function wp_nav_menu_autocomplete(a){jQuery("#add-"+a+" .quick-search").autocomplete(jQuery("#add-"+a+" .autocomplete").val().split("|"));jQuery("#add-"+a+" .quick-search").result(function(b,d,c){jQuery("#add-"+a+" .list-wrap").css("display","block");jQuery("#add-"+a+" .list-wrap li:contains('"+d+"')").css("display","block");jQuery("#add-"+a+" .show-all").hide();jQuery("#add-"+a+" .hide-all").show()})}function wp_edit_menu_item(a){var f=jQuery("#menu-item-type"+a).val();var b=jQuery("#menu-item-title"+a).val();var g=jQuery("#menu-item-url"+a).val();var c=jQuery("#menu-item-attr-title"+a).val();var d=jQuery("#menu-item-target"+a).val();var h=jQuery("#menu-item-description"+a).val();var e=jQuery("#menu-item-classes"+a).val();var i=jQuery("#menu-item-xfn"+a).val();if("custom"!=f){jQuery("#edit-menu-item-url").attr("disabled","disabled")}jQuery("#edit-menu-item-id").val(a);jQuery("#edit-menu-item-title").val(b);jQuery("#edit-menu-item-url").val(g);jQuery("#edit-menu-item-attr-title").val(c);jQuery("#edit-menu-item-target").val(d);jQuery("#edit-menu-item-target option[value='"+d+"']").attr("selected","selected");jQuery("#edit-menu-item-description").val(h);jQuery("#edit-menu-item-classes").val(e);jQuery("#edit-menu-item-xfn").val(i);jQuery("#edit-menu-item-title").focus()}function wp_update_menu_item(){var h=jQuery("#edit-menu-item-id").val();var f=jQuery("#edit-menu-item-title").val();var b=jQuery("#edit-menu-item-url").val();var g=jQuery("#edit-menu-item-attr-title").val();var d=jQuery("#edit-menu-item-target").val();var c=jQuery("#edit-menu-item-description").val();var a=jQuery("#edit-menu-item-classes").val();var e=jQuery("#edit-menu-item-xfn").val();jQuery(".menu #menu-item"+h).find("span.item-title").html(f);jQuery(".menu #menu-item-title"+h).val(f);jQuery(".menu #menu-item-url"+h).val(b);jQuery(".menu #menu-item-attr-title"+h).val(g);jQuery(".menu #menu-item-target"+h).val(d);jQuery(".menu #menu-item-description"+h).val(c);jQuery(".menu #menu-item-classes"+h).val(a);jQuery(".menu #menu-item-xfn"+h).val(e);jQuery(".menu #menu-item"+h+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})}function wp_remove_menu_item(b){var a=document.getElementById("menu-item"+b);if(a){jQuery(a).find("dt").each(function(){jQuery(this).animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){jQuery(this).parent().parent().remove()}})})}}function wp_add_item_to_menu(a,k,f,n,l,b,m,h,e,d,c,i){var j=wp_get_unique_menu_id();var g=wp_get_hidden_inputs(j,a,k,f,n,l,b,m,h,e,d,c,i);jQuery(".menu").append('");jQuery(".menu #menu-item"+j+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}});wp_drag_and_drop();tb_init("a.thickbox, area.thickbox, input.thickbox")}function wp_add_checked_items_to_menu(b){var a=jQuery(b).siblings(".list-wrap").find(":checked");if(0==a.length){return false}jQuery(a).each(function(){var h=jQuery(this).parent().siblings(".menu-item-type").val();if("custom"==h){var e=jQuery(this).parent().siblings(".menu-item-attr-title").val();var f=jQuery(this).parent().siblings(".menu-item-target").val();var g=jQuery(this).parent().siblings(".menu-item-classes").val();var j=jQuery(this).parent().siblings(".menu-item-xfn").val()}else{var e="";var f="_self";var g="";var j=""}var c=jQuery(this).parent().siblings(".menu-item-db-id").val();var k=jQuery(this).parent().siblings(".menu-item-object-id").val();var n=jQuery(this).parent().siblings(".menu-item-append").val();var l=jQuery(this).parent().siblings(".menu-item-parent-id").val();var d=jQuery(this).parent().siblings(".menu-item-title").val();var m=jQuery(this).parent().siblings(".menu-item-url").val();var i=jQuery(this).parent().siblings(".menu-item-description").val();if(undefined==i){i=""}wp_add_item_to_menu(c,k,h,n,l,d,m,i,e,f,g,j);jQuery(this).attr("checked",false)})}function wp_drag_and_drop(){jQuery(".menu li").each(function(){if(!jQuery(this).children(".dropzone").attr("class")){jQuery(this).prepend('
')}});jQuery(".menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100});jQuery(".menu li dl, .menu li .dropzone").droppable({accept:".menu li",tolerance:"pointer",drop:function(f,d){var a=jQuery(this).parent();var g=!jQuery(this).hasClass("dropzone");if(g&&a.children("ul").length==0){a.append('')}if(g){a.children("ul").append(d.draggable)}else{a.before(d.draggable)}a.find("dl,.dropzone").css({backgroundColor:"",borderColor:""});var c=d.draggable.attr("value");var b=a.attr("value");a.find("#menu-"+c).find("#parent"+c).val(b);jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style")},over:function(){if(jQuery(this).attr("class")=="dropzone ui-droppable"){jQuery(this).parent().find("div:first").css("background","none").css("height","50px")}else{if(jQuery(this).attr("class")=="ui-droppable"){jQuery(this).parent().find("dt:first").css("background","#d8d8d8")}else{}}var a=jQuery(this).parent().attr("id")},out:function(){jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style");jQuery(this).filter(".dropzone").css({borderColor:""})}})}function wp_update_post_data(){var a=0;jQuery(".menu li").each(function(c){c=c+1;var b=jQuery(this).attr("value");jQuery(this).find("#menu-item-position"+b).attr("value",c);jQuery(this).attr("id","menu-item"+c);jQuery(this).attr("value",c);jQuery(this).find("#menu-item-db-id"+b).attr("id","menu-item-db-id"+c);jQuery(this).find("#menu-item-object-id"+b).attr("id","menu-item-object-id"+c);jQuery(this).find("#menu-item-append"+b).attr("id","menu-item-append"+c);jQuery(this).find("#menu-item-type"+b).attr("id","menu-item-type"+c);jQuery(this).find("#menu-item-position"+b).attr("id","menu-item-position"+c);var d=jQuery(this).find("#menu-item-parent-id"+b).parent().parent().parent().attr("value");jQuery(this).find("#menu-item-parent-id"+b).attr("id","menu-item-parent-id"+c);if(d){}else{d=0}jQuery(this).find("#menu-item-parent-id"+b).attr("value",d);jQuery(this).find("#menu-item-title"+b).attr("id","menu-item-title"+c);jQuery(this).find("#menu-item-url"+b).attr("id","menu-item-url"+c);jQuery(this).find("#menu-item-description"+b).attr("id","menu-item-description"+c);jQuery(this).find("#menu-item-classes"+b).attr("id","menu-item-classes"+c);jQuery(this).find("#menu-item-xfn"+b).attr("id","menu-item-xfn"+c);jQuery(this).find("#menu-item-description"+b).attr("id","menu-item-description"+c);jQuery(this).find("#menu-item-attr-title"+b).attr("id","menu-item-attr-title"+c);jQuery(this).find("#menu-item-target"+b).attr("id","menu-item-target"+c);jQuery("#li-count").attr("value",c)})}function wp_get_unique_menu_id(){var d=jQuery(".menu li").length+1;var e=d;var a=0;try{var f=document.getElementById("menu-"+e.toString()).value}catch(c){a=1}while(a==0){e=e+1;try{var b=document.getElementById("menu-"+e.toString()).value}catch(c){a=1}}return e}function wp_get_hidden_inputs(j,a,k,f,n,l,b,m,h,e,d,c,i){var g="";g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';return g}jQuery(document).ready(function(a){wp_drag_and_drop();a("#update-nav-menu .deletion").click(function(){if(confirm(navMenuL10n.warnDelete)){return true}else{return false}});a("#save_menu").click(function(){return wp_update_post_data()});a("#create-menu-name").keypress(function(b){if(13==b.keyCode){a("#create-menu-button").click();return false}});a("#custom-menu-item-url, #custom-menu-item-name").keypress(function(b){if(13==b.keyCode){a("#add-custom-links a.button").click();return false}}).focus(function(){if(a(this).val()==a(this).attr("defaultValue")&&a(this).attr("id")!="custom-menu-item-url"){a(this).val("")}}).blur(function(){if(a(this).val()==""){a(this).val(a(this).attr("defaultValue"))}});a("#create-menu-name").focus(function(){if(a(this).val()==a(this).attr("defaultValue")){a(this).val("")}}).blur(function(){if(a(this).val()==""){a(this).val(a(this).attr("defaultValue"))}});a(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles("menus");a(".quick-search").click(function(){a(this).attr("value","")});a(".quick-search-submit").click(function(){a(this).siblings(".quick-search").search()});a("#menu-container .item-edit").click(function(){return wp_edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").live("click",function(b){return wp_remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wp_update_menu_item();return tb_remove()});a("#cancel-save").click(function(){return tb_remove()});a(".show-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","block");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","block");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".hide-all").show()});a(".hide-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","none");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","none");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".show-all").show()});a(".add-to-menu").click(function(b){return wp_add_checked_items_to_menu(b.currentTarget)});a("#add-custom-links .add-to-menu a").click(function(b){if(a("#custom-menu-item-url").val()==a("#custom-menu-item-url").attr("defaultValue")){return}wp_add_item_to_menu(0,"","custom",navMenuL10n.custom,0,a("#custom-menu-item-name").val(),a("#custom-menu-item-url").val(),"","","_self","","");a("#custom-menu-item-name").val(a("#custom-menu-item-name").attr("defaultValue"));a("#custom-menu-item-url").val(a("#custom-menu-item-url").attr("defaultValue")).focus()})});
\ No newline at end of file
+var wpNavMenu;(function(a){wpNavMenu={init:function(){wpNavMenu.initial_meta_boxes();wpNavMenu.drag_and_drop();a("#update-nav-menu .deletion").click(function(){if(confirm(navMenuL10n.warnDelete)){return true}else{return false}});a("#update-nav-menu").submit(function(){wpNavMenu.update_post_data()});a("#create-menu-name").keypress(function(b){if(13==b.keyCode){a("#create-menu-button").click();return false}});a("#custom-menu-item-url, #custom-menu-item-name").keypress(function(b){if(13==b.keyCode){a("#add-custom-links a.button").click();return false}}).focus(function(){if(a(this).val()==a(this).attr("defaultValue")&&a(this).attr("id")!="custom-menu-item-url"){a(this).val("")}}).blur(function(){if(a(this).val()==""){a(this).val(a(this).attr("defaultValue"))}});a("#create-menu-name").focus(function(){if(a(this).val()==a(this).attr("defaultValue")){a(this).val("")}}).blur(function(){if(a(this).val()==""){a(this).val(a(this).attr("defaultValue"))}});a(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles("nav-menus");a(".quick-search").click(function(){a(this).attr("value","")});a(".quick-search-submit").click(function(){a(this).siblings(".quick-search").search()});a("#menu-container .item-edit").click(function(){wpNavMenu.edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").click(function(){wpNavMenu.remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wpNavMenu.update_menu_item();tb_remove()});a("#cancel-save").click(function(){tb_remove()});a(".show-all").click(function(b){a(b.currentTarget).parent().parent().siblings(".list-wrap").css("display","block");a(b.currentTarget).parent().parent().siblings(".list-wrap").find("li").css("display","block");a(b.currentTarget).hide();a(b.currentTarget).siblings(".hide-all").show()});a(".hide-all").click(function(b){a(b.currentTarget).parent().parent().siblings(".list-wrap").css("display","none");a(b.currentTarget).parent().parent().siblings(".list-wrap").find("li").css("display","none");a(b.currentTarget).hide();a(b.currentTarget).siblings(".show-all").show()});a(".add-to-menu").click(function(b){wpNavMenu.add_checked_items_to_menu(b.currentTarget)});a("#add-custom-links .add-to-menu a").click(function(b){if(a("#custom-menu-item-url").val()==a("#custom-menu-item-url").attr("defaultValue")){return}wpNavMenu.add_custom_link(a("#custom-menu-item-name").val(),a("#custom-menu-item-url").val());a("#custom-menu-item-name").val(a("#custom-menu-item-name").attr("defaultValue"));a("#custom-menu-item-url").val(a("#custom-menu-item-url").attr("defaultValue")).focus()})},add_custom_link:function(c,b){var d={action:"save-custom-link",link_name:c,link_url:b};a.post(ajaxurl,d,function(e){if("-1"==e){return}wpNavMenu.add_to_menu(e,e,"custom","custom",navMenuL10n.custom,0,c,b,"","","_self","","")},"json")},initial_meta_boxes:function(){var c=a("#hidden-metaboxes").val().split(",");if(""!=c){for(var b=0;b')}});a(".menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100});a(".menu li dl, .menu li .dropzone").droppable({accept:".menu li",tolerance:"pointer",drop:function(g,f){var b=a(this).parent();var h=!a(this).hasClass("dropzone");if(h&&b.children("ul").length==0){b.append('')}if(h){b.children("ul").append(f.draggable)}else{b.before(f.draggable)}b.find("dl,.dropzone").css({backgroundColor:"",borderColor:""});var d=f.draggable.attr("value");var c=b.attr("value");b.find("#menu-"+d).find("#parent"+d).val(c);a(this).parent().find("dt").removeAttr("style");a(this).parent().find("div:first").removeAttr("style")},over:function(b){if(a(this).attr("class")=="dropzone ui-droppable"){a(this).parent().find("div:first").css({background:"#f5f5f5",border:"1px dashed #bbb",margin:"10px 0px",height:"40px"})}else{if(a(this).attr("class")=="ui-droppable"){a(this).parent().find("dt:first").css("background","#d8d8d8")}else{}}},out:function(){a(this).parent().find("dt").removeAttr("style");a(this).parent().find("div:first").removeAttr("style");a(this).filter(".dropzone").css({borderColor:""})}})},update_post_data:function(){var b=0;a(".menu li").each(function(){b=b+1;var d=a(this).attr("value");var e=a(this).children("input[name=menu-item-db-id[]]").val();a(this).attr("value",b);a(this).children("input[name=menu-item-position[]]").attr("value",b);var c=a(this).parent(".sub-menu").siblings("input[name=menu-item-object-id[]]").val();if(undefined==c){c=0}a(this).children("input[name=menu-item-parent-id[]]").attr("value",c);a("#li-count").attr("value",b)})},autocomplete:function(b){a("#add-"+b+" .quick-search").autocomplete(a("#add-"+b+" .autocomplete").val().split("|"));a("#add-"+b+" .quick-search").result(function(c,e,d){a("#add-"+b+" .list-wrap").css("display","block");a("#add-"+b+" .list-wrap li:contains('"+e+"')").css("display","block");a("#add-"+b+" .show-all").hide();a("#add-"+b+" .hide-all").show()})},edit_menu_item:function(b){var g=a("#menu-item-"+b).children("input[name=menu-item-type[]]").val();var c=a("#menu-item-"+b).children("input[name=menu-item-title[]]").val();var h=a("#menu-item-"+b).children("input[name=menu-item-url[]]").val();var d=a("#menu-item-"+b).children("input[name=menu-item-attr-title[]]").val();var e=a("#menu-item-"+b).children("input[name=menu-item-target[]]").val();var i=a("#menu-item-"+b).children("input[name=menu-item-description[]]").val();var f=a("#menu-item-"+b).children("input[name=menu-item-classes[]]").val();var j=a("#menu-item-"+b).children("input[name=menu-item-xfn[]]").val();if("custom"!=g){a("#edit-menu-item-url").attr("disabled","disabled")}a("#edit-menu-item-id").val(b);a("#edit-menu-item-title").val(c);a("#edit-menu-item-url").val(h);a("#edit-menu-item-attr-title").val(d);a("#edit-menu-item-target").val(e);a("#edit-menu-item-target option[value='"+e+"']").attr("selected","selected");a("#edit-menu-item-description").val(i);a("#edit-menu-item-classes").val(f);a("#edit-menu-item-xfn").val(j)},update_menu_item:function(){var i=a("#edit-menu-item-id").val();var g=a("#edit-menu-item-title").val();var c=a("#edit-menu-item-url").val();var h=a("#edit-menu-item-attr-title").val();var e=a("#edit-menu-item-target").val();var d=a("#edit-menu-item-description").val();var b=a("#edit-menu-item-classes").val();var f=a("#edit-menu-item-xfn").val();a(".menu #menu-item-"+i).find("span.item-title:first").html(g);a("#menu-item-"+i).children("input[name=menu-item-title[]]").val(g);a("#menu-item-"+i).children("input[name=menu-item-url[]]").val(c);a("#menu-item-"+i).children("input[name=menu-item-attr-title[]]").val(h);a("#menu-item-"+i).children("input[name=menu-item-target[]]").val(e);a("#menu-item-"+i).children("input[name=menu-item-description[]]").val(d);a("#menu-item-"+i).children("input[name=menu-item-classes[]]").val(b);a("#menu-item-"+i).children("input[name=menu-item-xfn[]]").val(f);a(".menu #menu-item-"+i+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){a(this).css("backgroundColor","")}})},remove_menu_item:function(c){var b=a("#menu-item-"+c);if(b){a(b).find("dt").each(function(){a(this).animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){a(this).parent().parent().remove()}})})}},add_to_menu:function(b,m,c,h,p,n,d,o,j,g,f,e,k){var l=a(".menu li").length+1;var i=wpNavMenu.get_hidden_inputs(l,b,m,c,h,n,d,o,j,g,f,e,k);a(".menu").append('");a(".menu #menu-item-"+l+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){a(this).css("backgroundColor","")}});wpNavMenu.drag_and_drop();tb_init("a.thickbox, area.thickbox, input.thickbox")},add_checked_items_to_menu:function(c){var b=a(c).parent().siblings(".list-wrap").find(":checked");if(0==b.length){return false}a(b).each(function(){var j=a(this).parent().siblings(".menu-item-type").val();if("custom"==j){var g=a(this).parent().siblings(".menu-item-attr-title").val();var h=a(this).parent().siblings(".menu-item-target").val();var i=a(this).parent().siblings(".menu-item-classes").val();var l=a(this).parent().siblings(".menu-item-xfn").val()}else{var g="";var h="_self";var i="";var l=""}var d=a(this).parent().siblings(".menu-item-db-id").val();var m=a(this).parent().siblings(".menu-item-object-id").val();var e=a(this).parent().siblings(".menu-item-object").val();var p=a(this).parent().siblings(".menu-item-append").val();var n=a(this).parent().siblings(".menu-item-parent-id").val();var f=a(this).parent().siblings(".menu-item-title").val();var o=a(this).parent().siblings(".menu-item-url").val();var k=a(this).parent().siblings(".menu-item-description").val();if(undefined==k){k=""}if(undefined==g){g=""}wpNavMenu.add_to_menu(d,m,e,j,p,n,f,o,k,g,h,i,l);a(this).attr("checked",false)})},get_hidden_inputs:function(l,b,m,c,h,n,d,o,j,g,f,e,k){var i="";i+=' ';i+=' ';i+=' ';i+=' ';i+=' ';i+=' ';i+=' ';i+=' ';i+=' ';i+=' ';i+=' ';i+=' ';i+=' ';return i}};a(document).ready(function(b){wpNavMenu.init()})})(jQuery);
\ No newline at end of file
diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php
index 5ebca58d53..d02364f035 100644
--- a/wp-admin/nav-menus.php
+++ b/wp-admin/nav-menus.php
@@ -12,6 +12,9 @@
/** Load WordPress Administration Bootstrap */
require_once( 'admin.php' );
+// Load all the nav menu interface functions
+require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
+
// Permissions Check
if ( ! current_user_can('switch_themes') )
wp_die( __( 'Cheatin’ uh?' ));
@@ -37,9 +40,6 @@ wp_enqueue_script( 'postbox' );
// Thickbox
add_thickbox();
-// Load all the nav menu interface functions
-require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
-
// Container for any messages displayed to the user
$messages_div = '';
@@ -57,9 +57,15 @@ switch ( $action ) {
check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
if ( is_nav_menu($nav_menu_selected_id) ) {
- wp_delete_nav_menu( $nav_menu_selected_id );
- $messages_div = '' . __('Menu successfully deleted.') . '
';
- $nav_menu_selected_id = 0;
+ $delete_nav_menu = wp_delete_nav_menu( $nav_menu_selected_id );
+
+ if ( is_wp_error($delete_nav_menu) ) {
+ $messages_div = '' . $delete_nav_menu->get_error_message() . '
';
+ } else {
+ $messages_div = '' . __('The menu has been successfully deleted.') . '
';
+ $nav_menu_selected_id = 0; // Reset the selected menu
+ }
+ unset( $delete_nav_menu );
}
break;
@@ -75,36 +81,45 @@ switch ( $action ) {
$add_nav_menu = wp_create_nav_menu( $add_nav_menu );
if ( is_wp_error( $add_nav_menu ) ) {
- $messages_div = '' . $add_nav_menu->get_error_message() . '
';
+ $messages_div = '' . $add_nav_menu->get_error_message() . '
';
} else {
$nav_menu_selected_id = $add_nav_menu->term_id;
$nav_menu_selected_title = $add_nav_menu->name;
- $messages_div = '' . sprintf( __('The %s menu has been successfully created.'), esc_html( $add_nav_menu->name ) ) . '
';
+ $messages_div = '' . sprintf( __('The %s menu has been successfully created.'), $add_nav_menu->name ) . '
';
}
} else {
- $messages_div = '' . __('Please enter a valid menu name.') . '
';
+ $messages_div = '' . __('Please enter a valid menu name.') . '
';
}
- unset($add_nav_menu);
+ unset( $add_nav_menu );
}
} else {
+
+ // @todo wrap this into wp_update_nav_menu_object();
if ( isset($_POST['menu-name']) ) {
$old_nav_menu = get_term( $nav_menu_selected_id, 'nav_menu', ARRAY_A );
$args = array( 'name' => $_POST['menu-name'], 'slug' => null, 'description' => $old_nav_menu['description'], 'parent' => $old_nav_menu['parent'], );
$new_nav_menu = wp_update_term( $nav_menu_selected_id, 'nav_menu', $args );
}
-
+
// Update menu items
- $update_nav_items = isset( $_POST['li-count'] ) ? (int) $_POST['li-count'] : 0;
+
+ // @todo: wrap update logic into wp_update_nav_menu();
+ $update_count = isset( $_POST['li-count'] ) ? (int) $_POST['li-count'] : 0;
$update_nav_menu = is_nav_menu( $nav_menu_selected_id );
if ( !is_wp_error($update_nav_menu) ) {
$menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
- $parent_menu_ids = array();
-
+
// Loop through all POST variables
- for ( $k = 0; $k < $update_nav_items; $k++ ) {
+ for ( $k = 0; $k < $update_count; $k++ ) {
+
+ // Menu item title can't be blank
+ if ( '' == $_POST['menu-item-title'][$k] )
+ continue;
+
$menu_item_db_id = isset( $_POST['menu-item-db-id'][$k] ) ? $_POST['menu-item-db-id'][$k] : 0;
$menu_item_object_id = isset( $_POST['menu-item-object-id'][$k] ) ? $_POST['menu-item-object-id'][$k] : 0;
+ $menu_item_object = isset( $_POST['menu-item-object'][$k] ) ? $_POST['menu-item-object'][$k] : '';
$menu_item_parent_id = isset( $_POST['menu-item-parent-id'][$k] ) ? $_POST['menu-item-parent-id'][$k] : 0;
$menu_item_position = isset( $_POST['menu-item-position'][$k] ) ? $_POST['menu-item-position'][$k] : 0;
$menu_item_type = isset( $_POST['menu-item-type'][$k] ) ? $_POST['menu-item-type'][$k] : 'custom';
@@ -113,41 +128,40 @@ switch ( $action ) {
$menu_item_url = isset( $_POST['menu-item-url'][$k] ) ? $_POST['menu-item-url'][$k] : '';
$menu_item_description = isset( $_POST['menu-item-description'][$k] ) ? $_POST['menu-item-description'][$k] : '';
$menu_item_attr_title = isset( $_POST['menu-item-attr-title'][$k] ) ? $_POST['menu-item-attr-title'][$k] : '';
- $menu_item_target = isset( $_POST['menu-item-target'][$k] ) ? $_POST['menu-item-target'][$k] : 0;
+ $menu_item_target = isset( $_POST['menu-item-target'][$k] ) ? $_POST['menu-item-target'][$k] : '_self';
$menu_item_classes = isset( $_POST['menu-item-classes'][$k] ) ? $_POST['menu-item-classes'][$k] : '';
$menu_item_xfn = isset( $_POST['menu-item-xfn'][$k] ) ? $_POST['menu-item-xfn'][$k] : '';
- // Menu item title can't be blank
- if ( '' == $menu_item_title )
- continue;
-
- // Populate the menu item
- $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID,
- 'ping_status' => 0, 'post_parent' => $menu_item_parent_id, 'menu_order' => $menu_item_position,
- 'post_excerpt' => $menu_item_attr_title, 'tax_input' => array( 'nav_menu' => $update_nav_menu->name ),
- 'post_content' => $menu_item_description, 'post_title' => $menu_item_title );
-
+ // Populate the menu item object
+ $post = array(
+ 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'ping_status' => 0,
+ 'post_author' => $user_ID, 'tax_input' => array( 'nav_menu' => $update_nav_menu->name ),
+ 'post_title' => $menu_item_title, 'post_excerpt' => $menu_item_attr_title,
+ 'post_parent' => $menu_item_parent_id, 'menu_order' => $menu_item_position,
+ 'post_content' => $menu_item_description,
+ );
+
// New menu item
if ( $menu_item_db_id == 0 ) {
$menu_item_db_id = wp_insert_post( $post );
- } elseif ( isset( $menu_items[$menu_item_db_id] ) ) {
+
+ // Update existing menu item
+ } elseif ( isset($menu_items[$menu_item_db_id]) || ( 'custom' == $menu_item_type && 0 != $menu_item_db_id ) ) {
$post['ID'] = $menu_item_db_id;
wp_update_post( $post );
unset( $menu_items[$menu_item_db_id] );
}
- $parent_menu_ids[$k] = $menu_item_db_id;
- // @todo sanitize type append and ID.
- update_post_meta( $menu_item_db_id, 'menu_item_type', $menu_item_type );
- update_post_meta( $menu_item_db_id, 'menu_item_append', $menu_item_append );
- update_post_meta( $menu_item_db_id, 'menu_item_object_id', $menu_item_object_id );
- update_post_meta( $menu_item_db_id, 'menu_item_target', sanitize_key($menu_item_target) );
+ update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($menu_item_type) );
+ update_post_meta( $menu_item_db_id, '_menu_item_object_id', (int) $menu_item_object_id );
+ update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($menu_item_object) );
+ update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($menu_item_target) );
// @todo handle sanitizing multiple classes separated by whitespace.
- update_post_meta( $menu_item_db_id, 'menu_item_classes', sanitize_html_class($menu_item_classes) );
- update_post_meta( $menu_item_db_id, 'menu_item_xfn', sanitize_html_class($menu_item_xfn) );
+ update_post_meta( $menu_item_db_id, '_menu_item_classes', sanitize_html_class($menu_item_classes) );
+ update_post_meta( $menu_item_db_id, '_menu_item_xfn', sanitize_html_class($menu_item_xfn) );
// @todo: only save custom link urls.
- update_post_meta( $menu_item_db_id, 'menu_item_url', esc_url_raw( $menu_item_url ) );
+ update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($menu_item_url) );
}
// Remove menu items from the menu that weren't in $_POST
@@ -156,7 +170,11 @@ switch ( $action ) {
wp_delete_post( $menu_item_id );
}
}
- $messages_div = '' . __('The menu has been updated.') . '
';
+
+ do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
+
+ $messages_div = '' . sprintf( __('The %s menu has been updated.'), $update_nav_menu->name ) . '
';
+ unset( $update_nav_menu, $update_count, $menu_items );
}
}
break;
@@ -190,15 +208,24 @@ if ( !$nav_menu_selected_title && $nav_menu_selected_title = is_nav_menu( $nav_m
$nav_menu_selected_title = $nav_menu_selected_title->name;
}
+// Create Menu Metabox
+add_meta_box( 'create-menu', __('Create Menu'), 'wp_nav_menu_create_metabox', 'nav-menus', 'side', 'core' );
+
// The user has no menus.
if ( !is_nav_menu( $nav_menu_selected_id ) ) {
- if ( current_theme_supports('nav-menus') ) {
- $messages_div = '' . __('You do not have any menus. Create a new menu.') . '
';
- } else {
- $messages_div = '' . __('The current theme does not support menus.') . '
';
- }
+ $messages_div = '' . __('You do not have any menus. Create a new menu.') . '
';
+
+// The theme supports menus
+} elseif ( current_theme_supports('nav-menus') ) {
+
+ // Register nav menu metaboxes
+ add_meta_box( 'manage-menu', __( 'Menu Settings' ), 'wp_nav_menu_manage_menu_metabox', 'nav-menus', 'side', 'high', array( $nav_menu_selected_id, $nav_menu_selected_title ) );
+ wp_nav_menu_metaboxes_setup();
+
+// The theme does not support menus
} else {
- add_meta_box( 'manage-menu', __( 'Menu Settings' ), 'wp_nav_menu_manage_menu_metabox', 'menus', 'side', 'high', array( $nav_menu_selected_id, $nav_menu_selected_title ) );
+ remove_meta_box( 'create-menu', 'nav-menus', 'side' );
+ $messages_div = '' . __('The current theme does not support menus.') . '
';
}
// Get the admin header
@@ -210,7 +237,7 @@ require_once( 'admin-header.php' );
- 1 ) : ?>
+ 1 && current_theme_supports('nav-menus') ) : ?>