From f635d99754fc6636d16b65586cbb2b81870c966b Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 15 Mar 2010 16:26:46 +0000 Subject: [PATCH] Menus rework. Props ptahdunbar. see #11817 git-svn-id: http://svn.automattic.com/wordpress/trunk@13704 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/css/nav-menu.css | 2 +- wp-admin/css/nav-menu.dev.css | 49 +- wp-admin/includes/nav-menu.php | 602 +++++++++++------- wp-admin/js/nav-menu-default-items.dev.js | 88 ++- wp-admin/js/nav-menu-default-items.js | 2 +- wp-admin/js/nav-menu-dynamic-functions.dev.js | 358 ++++++----- wp-admin/js/nav-menu-dynamic-functions.js | 2 +- wp-admin/nav-menus.php | 591 +++++++---------- wp-content/themes/twentyten/header.php | 2 +- wp-content/themes/twentyten/style.css | 8 +- wp-includes/nav-menu-template.php | 216 ++++--- wp-includes/nav-menu.php | 211 +++--- wp-includes/script-loader.php | 5 +- wp-includes/taxonomy.php | 2 +- 14 files changed, 1065 insertions(+), 1073 deletions(-) diff --git a/wp-admin/css/nav-menu.css b/wp-admin/css/nav-menu.css index aad36daf4a..07c8034ac4 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{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;} \ 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;}.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 diff --git a/wp-admin/css/nav-menu.dev.css b/wp-admin/css/nav-menu.dev.css index bbe65082f2..923857d9f3 100644 --- a/wp-admin/css/nav-menu.dev.css +++ b/wp-admin/css/nav-menu.dev.css @@ -14,19 +14,16 @@ /* Button Primary Actions */ #menu-container .submit { margin: 0px 0px 10px; padding: 0px; } -.submitdelete { color: #ff0000; text-decoration: underline; font-size: 11px; float: left; margin-top: 5px; } -.submitdelete:hover { background-color: #FF0000; color: #fff; } -.save { float: right; } + +.submitdelete { font-size: 11px; } +#cancel-save { color: #ff0000; text-decoration: underline; font-size: 11px; margin-left: 20px; margin-top: 5px; } +#cancel-save:hover { background-color: #FF0000; color: #fff; } /* Button Secondary Actions */ .button-controls { float: left; } .add-to-menu { float: right; } -/* 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; } -*/ +#manage-menu .inside { padding: 0px 0px; } /* Create Menu */ #create-menu-name { width: 159px; } @@ -36,7 +33,8 @@ #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; } +.menu-item-textbox { float: right; width: 220px; } +.howto span { margin-top: 4px; display: block; float: left; } /* Pages/Categories */ .show-all, .hide-all { cursor: pointer; } @@ -50,17 +48,17 @@ /* Listings */ .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 .menu-item-title { cursor: pointer; display: block; } +.list li .menu-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; } +.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 */ #menu-container .inside { padding-bottom: 10px; } @@ -71,9 +69,9 @@ .menu li dl dt:hover { cursor: move; } .menu li .item-title { } -.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 { 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 */ @@ -85,7 +83,7 @@ .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: #ff0000; } +.item-controls .menu-item-delete:hover { color: #ff0000; } /* Thickbox */ #menu-item-settings { display: none; } @@ -94,7 +92,4 @@ #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; } - -/* Misc */ -.hide { display: none; } \ No newline at end of file +#update-menu-item:focus { color: #eaf2fa !important; border-color: #13455b !important; } \ No newline at end of file diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php index bacb534318..da5cf18e18 100644 --- a/wp-admin/includes/nav-menu.php +++ b/wp-admin/includes/nav-menu.php @@ -1,273 +1,383 @@ true ), 'object' ); - $args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' ); - $link_objects = new WP_Query( $args ); + if ( !$post_types ) + return false; - $items_counter = $counter; - - if ( !$link_objects->posts ) { - _e('Not Found'); - return $items_counter; + foreach ( $post_types as $post_type ) { + $id = sanitize_title_with_dashes( $post_type->label ); + + // delete_transient( "nav_menu_items_{$post_type->name}" ); + // delete_transient( "nav_menu_sub_items_{$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 ); } - - // 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': - ?> - - -
  • - ID; - $items_counter++; - $items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'default' ); - ?> -
  • - 0, - 'sort_order' => 'ASC', - 'sort_column' => 'post_title', - 'hierarchical' => 1, - 'exclude' => '', - 'include' => '', - 'meta_key' => '', - 'meta_value' => '', - 'authors' => '', - 'parent' => -1, - 'exclude_tree' => '', - 'number' => '', - 'offset' => 0 ); - - // Get all pages - $pages_array = get_pages( $pages_args ); - - $items_counter = $counter; - $parentli = $items_counter; - - if ( !$pages_array ) { - echo __('Not Found'); - return $items_counter; +function wp_nav_menu_taxonomy_metaboxes() { + $taxonomies = get_taxonomies( array( 'show_ui' => true ), 'object' ); + + if ( !$taxonomies ) + return false; + + foreach ( $taxonomies as $tax ) { + $id = sanitize_title_with_dashes( $tax->label ); + + // delete_transient( "nav_menu_items_{$tax->name}" ); + // delete_transient( "nav_menu_sub_items_{$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 ); } - - // Display Loop - foreach ( $pages_array as $post ) { - if ( $post->post_parent == 0 ) { - $post = wp_setup_nav_menu_item( $post, 'page', $items_counter ); - if ( $context == 'menu' ) { - ?> - - -
  • - ID; - $items_counter++; - $items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'default' ); - ?> -
  • - 'post', - 'child_of' => 0, - 'orderby' => 'name', - 'order' => 'ASC', - 'hide_empty' => false, - 'include_last_update_time' => false, - 'hierarchical' => 1, - 'exclude' => '', - 'include' => '', - 'number' => '', - 'pad_counts' => false ); +function wp_nav_menu_manage_menu_metabox( $object, $menu ) { ?> +
    +
    +
    + +
    +
    +
    +
    +
    + +
    - $items_counter = $counter; - - // Get all categories - $categories_array = get_categories( $category_args ); - - if ( !$categories_array ) { - _e('Not Found'); - return $items_counter; - } - - // 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 ); - // Custom Menu - if ( $context == 'menu' ) { - ?> - - -
  • - cat_ID; - $items_counter++; - $items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'default' ); - ?> -
  • - $childof, - 'hide_empty' => false, - 'parent' => $childof); - } elseif ( $output_type == 'default' ) { - // Sidebar Menu - $sub_args = array( - 'child_of' => $childof, - 'hide_empty' => false, - 'parent' => $childof); - } - - if ( $context == 'categories' ) { - // Get Sub Category Items - $item_type = 'category'; - $sub_array = get_categories($sub_args); - } elseif ($context == 'pages') { - // Get Sub Page Items - $item_type = 'page'; - $sub_array = get_pages($sub_args); - } else { - $item_type = 'custom'; - $sub_array = array(); - } - - if ( $sub_array ) { - ?> - +
    + +
    +
    +
    +
    +

    + + +

    + 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' ); + + // Cache the query for a day. @todo: Make sure to flush transient when links are updated. + $query = get_transient( 'menu_item_query_custom_links' ); + if ( false == $query ) { + $query = new WP_Query( $args ); + set_transient( 'menu_item_query_custom_links', $query, 86400 ); } - return $counter; + + ?> + +
    + + +

    + + +

    + +

    + +

    +
    + $post_type['args']->name, ); + + if ( 'attachment' == $post_type['args']->name ) + $args['post_status'] = 'any'; + + // Cache the query for a day. @todo: Make sure to flush transient when objects are updated. + $query = get_transient( "nav_menu_items_{$post_type['args']->name}" ); + if ( false == $query ) { + $query = new WP_Query( $args ); + set_transient( "nav_menu_items_{$post_type['args']->name}", $query, 86400 ); + } + + if ( !$query->posts ) + $error = '
  • '. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'
  • '; + + $pt_names = ''; + if ( is_array($query->posts) ) { + foreach ( $query->posts as $post ) { + if ( $post->post_title ) { + $pt_names .= htmlentities( $post->post_title ) .'|'; + } else { + $pt_names = sprintf( __('No %s exists'), $post_type['args']->label ); + } + } + } + + $id = sanitize_title_with_dashes( $post_type['args']->label ); + ?> +

    + + +

    + +

    + + +

    + +
    +
    +
      + posts, 'post_type', $post_type['args']->name ); ?> +
    +
    +
    +

    + +

    + +
    + + 0, 'orderby' => 'name', 'order' => 'ASC', + 'hide_empty' => false, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '', + 'include' => '', 'number' => '', 'pad_counts' => false + ); + + // Cache the query for a day. @todo: Make sure to flush transient when terms are updated. + $terms = get_transient( "nav_menu_items_{$taxonomy['args']->name}" ); + if ( false == $terms ) { + $terms = get_terms( $taxonomy['args']->name, $args ); + set_transient( "nav_menu_items_{$taxonomy['args']->name}", $terms, 86400 ); + } + + if ( !$terms ) + $error = '
  • '. sprintf( __( 'No %s exists' ), $taxonomy['args']->label ) .'
  • '; + + $term_names = ''; + if ( is_array($terms) ) { + foreach ( $terms as $term ) { + if ( $term->name ) { + $term_names .= htmlentities( $term->name ) .'|'; + } else { + $term_names = sprintf( __('No %s exists'), $taxonomy['args']->label ); + } + } + } + + $id = sanitize_title_with_dashes( $taxonomy['args']->label ); + ?> +

    + + +

    + +

    + + +

    + +
    +
    +
      + name ); ?> +
    +
    +
    +

    + +

    + +
    + + post_parent) ) + $menu_item->post_parent = $menu_item->parent; + + // Cleanest way to get all attachements + if ( 'attachment' == $object ) + $menu_item->post_parent = 0; + + if ( 0 == $menu_item->post_parent ) { + // Setup the menu item + $menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object ); + $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 ); + $output .= ''; + + ++$i; + } + } + + return $output; +} + +/** + * Recursive function to retrieve sub menu items. + * + * @since 3.0.0 + * + * @param string $childof The Parent ID. + * @param string $object_type The object type. + * @param string $object The object name. + * @return string $output sub menu items. + */ +function wp_get_nav_menu_sub_items( $childof, $object_type, $object = null, $context = 'frontend' ) { + $args = array( 'child_of' => $childof, 'parent' => $childof, 'hide_empty' => false, ); + + switch ( $object_type ) { + case 'post_type': + $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); + if ( in_array( $object, $hierarchical_post_types ) ) { + $args['post_type'] = $object; + $sub_menu_items = get_pages( $args ); + } else { + $sub_menu_items = array(); + } + break; + + case 'taxonomy': + if ( is_taxonomy_hierarchical( $object ) ) { + $sub_menu_items = get_terms( $object, $args ); + } else { + $sub_menu_items = array(); + } + break; + + default: + $sub_menu_items = array(); + break; + } + + $output = ''; + $i = 1; + if ( !empty($sub_menu_items) && !is_wp_error($sub_menu_items) ) { + $output .= ''; + } + return $output; } ?> \ No newline at end of file diff --git a/wp-admin/js/nav-menu-default-items.dev.js b/wp-admin/js/nav-menu-default-items.dev.js index 0eb6b8a5c0..4112aa54d6 100644 --- a/wp-admin/js/nav-menu-default-items.dev.js +++ b/wp-admin/js/nav-menu-default-items.dev.js @@ -15,13 +15,26 @@ jQuery(document).ready(function($){ wp_drag_and_drop(); - wp_update_post_data(); + // Delete AYS + $('#update-nav-menu .deletion').click(function(){ + if ( confirm( navMenuL10n.warnDelete ) ) { + return true; + } else { + return false; + }; + }); // Handle Save Button Clicks $('#save_menu').click(function(){ return wp_update_post_data(); }); - + + // 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', '' ); @@ -38,18 +51,14 @@ jQuery(document).ready(function($){ }); // Delete menu item - $('#menu-container .item-delete').live( 'click', function(){ + $('#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(); - tb_remove(); - - // Give feedback to the user - var id = $('#edit-item-id').val(); - $('#menu-' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); + return tb_remove(); }); // Close thickbox @@ -58,55 +67,32 @@ jQuery(document).ready(function($){ }); // Show All Button - $('.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(); + $('.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(){ - $(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(); + $('.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 item to queue - $('.list input').click(function(){ + // Add menu items into the menu + $('.add-to-menu').click(function(e){ + return wp_add_checked_items_to_menu(e.currentTarget); + }); - 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-dbid').val(); - var item_parent_id = jQuery(this).parent().siblings('.item-parent').val(); - var item_description = jQuery(this).parent().siblings('.item-description').val(); + // Create a new link then add it to the menu + $('#add-custom-links .add-to-menu a').click(function(e){ + var link_url = jQuery(e.currentTarget).parent().parent().find('#custom-menu-item-url').val(); + var link_name = jQuery(e.currentTarget).parent().parent().find('#custom-menu-item-name').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(){ - 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(); - - 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 ) - return; - - // and update the Menu with the new link - wp_add_item_to_menu( 'custom', link_name, link_url, 0, 0, '' ); + // Add link to menu + wp_add_item_to_menu( 0, '', 'custom', navMenuL10n.custom, 0, link_name, link_url, '', '', '_none', '', '' ); }); }); \ No newline at end of file diff --git a/wp-admin/js/nav-menu-default-items.js b/wp-admin/js/nav-menu-default-items.js index 32a2324fe6..329e6b8c88 100644 --- a/wp-admin/js/nav-menu-default-items.js +++ b/wp-admin/js/nav-menu-default-items.js @@ -1 +1 @@ -jQuery(document).ready(function(a){wp_drag_and_drop();wp_update_post_data();a("#save_menu").click(function(){return wp_update_post_data()});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(){return wp_remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wp_update_menu_item();tb_remove();var b=a("#edit-item-id").val();a("#menu-"+b+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})});a("#cancel-save").click(function(){return tb_remove()});a(".show-all").click(function(){a(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 10px;");a(this).offsetParent().find(".list-wrap").css("display","block");a(this).siblings(".quick-search").attr("value","");a(this).offsetParent().find(".list-wrap li").css("display","block");a(this).hide();a(this).siblings(".hide-all").show()});a(".hide-all").click(function(){a(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 0px;");a(this).offsetParent().find(".list-wrap").css("display","none");a(this).siblings(".quick-search").attr("value","Search");a(this).offsetParent().find(".list-wrap li").css("display","none");a(this).hide();a(this).siblings(".show-all").show()});a(".list input").click(function(){var d=jQuery(this).parent().siblings(".item-type").val();var g=jQuery(this).parent().siblings(".item-title").val();var c=jQuery(this).parent().siblings(".item-url").val();var e=jQuery(this).parent().siblings(".item-dbid").val();var b=jQuery(this).parent().siblings(".item-parent").val();var f=jQuery(this).parent().siblings(".item-description").val();return wp_update_queue(a(this),d,g,c,e,b,f)});a(".enqueue a").click(function(){return wp_add_queued_items_to_menu(this)});a("#add-custom-link .add-to-menu a").click(function(){var b=a(this).offsetParent().find("#menu-item-url").val();var c=a(this).offsetParent().find("#menu-item-name").val();wp_add_queued_items_to_menu(this);if("http://"==b||"Menu Item"==c){return}wp_add_item_to_menu("custom",c,b,0,0,"")})}); \ No newline at end of file +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(".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(d){var b=jQuery(d.currentTarget).parent().parent().find("#custom-menu-item-url").val();var c=jQuery(d.currentTarget).parent().parent().find("#custom-menu-item-name").val();wp_add_item_to_menu(0,"","custom",navMenuL10n.custom,0,c,b,"","","_none","","")})}); \ No newline at end of file diff --git a/wp-admin/js/nav-menu-dynamic-functions.dev.js b/wp-admin/js/nav-menu-dynamic-functions.dev.js index 7098ada94b..34a8c466aa 100644 --- a/wp-admin/js/nav-menu-dynamic-functions.dev.js +++ b/wp-admin/js/nav-menu-dynamic-functions.dev.js @@ -8,66 +8,75 @@ * @subpackage Administration */ -/** - * Adds a link to the available links section - * - * @param object e - An object recieved via ajax - */ -function wp_update_links_list(e) { - var link = '
  • '; - - // Prepend the link to the available links section - jQuery('#available-links .list').prepend( link ); - - // Give feedback to the user - jQuery('#available-links .list #link-' + e.link_id).parent().animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); +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 o - the id of the menu li to edit. + * @param int id - the id of the menu li to edit. */ function wp_edit_menu_item( id ) { - var itemType = jQuery('#item-type' + id).val(); - var itemTitle = jQuery('#item-title' + id).val(); - var itemURL = jQuery('#item-url' + id).val(); - var itemAttrTitle = jQuery('#item-attr-title' + id).val(); - var itemTarget = jQuery('#item-target' + id).val(); - var itemDesc = jQuery('#item-description' + id).val(); + 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(); - // Disable the ability to edit the url for page and category items - if ( 'page' == itemType || 'category' == itemType ) - jQuery( '#edit-item-url' ).attr('disabled', 'disabled' ); + // 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-item-id' ).val(id); - jQuery( '#edit-item-title' ).val(itemTitle); - jQuery( '#edit-item-url' ).val(itemURL); - jQuery( '#edit-item-attr-title' ).val(itemAttrTitle); - jQuery( '#edit-item-target' ).val(itemTarget); - jQuery( "#edit-item-target option[value='" + itemTarget + "']" ).attr('selected', 'selected'); - jQuery( '#edit-item-description' ).val(itemDesc); + 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-item-id').val(); - var itemTitle = jQuery('#edit-item-title').val(); - var itemURL = jQuery('#edit-item-url').val(); - var itemAttrTitle = jQuery('#edit-item-attr-title').val(); - var itemTarget = jQuery('#edit-item-target').val(); - var itemDesc = jQuery('#edit-item-description').val(); + 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-' + id).find('.item-title:first').html(itemTitle); - jQuery('#item-title' + id).val(itemTitle); - jQuery('#item-url' + id).val(itemURL); - jQuery('#item-attr-title' + id).val(itemAttrTitle); - jQuery('#item-target' + id).val(itemTarget); - jQuery('#item-description' + id).val(itemDesc); + // 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', '' ); }}); } /** @@ -76,166 +85,100 @@ function wp_update_menu_item() { * @param int o - the id of the menu li to remove. */ function wp_remove_menu_item( o ) { - var todelete = document.getElementById('menu-' + 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() } } ); }); - - wp_update_post_data(); } }; -/** - * Prepares menu items for POST - */ -function wp_update_post_data() { - var i = 0; - - jQuery('.menu li').each(function(i) { - i = i + 1; - var j = jQuery(this).attr('value'); - - jQuery(this).find('#item-position' + j).attr('value', i); - jQuery(this).attr('id','menu-' + i); - jQuery(this).attr('value', i); - - jQuery(this).find('#item-dbid' + j).attr('name','item-dbid' + i); - jQuery(this).find('#item-dbid' + j).attr('id','item-dbid' + i); - - jQuery(this).find('#item-postmenu' + j).attr('name','item-postmenu' + i); - jQuery(this).find('#item-postmenu' + j).attr('id','item-postmenu' + i); - - var p = jQuery(this).find('#item-parent' + j).parent().parent().parent().attr('value'); - - jQuery(this).find('#item-parent' + j).attr('name','item-parent' + i); - jQuery(this).find('#item-parent' + j).attr('id','item-parent' + i); - - if (p) { - // Do nothing - } else { - // reset p to be top level - p = 0; - } - - jQuery(this).find('#item-parent' + j).attr('value', p); - - jQuery(this).find('#item-title' + j).attr('name','item-title' + i); - jQuery(this).find('#item-title' + j).attr('id','item-title' + i); - - jQuery(this).find('#item-url' + j).attr('name','item-url' + i); - jQuery(this).find('#item-url' + j).attr('id','item-url' + i); - - jQuery(this).find('#item-description' + j).attr('name','item-description' + i); - jQuery(this).find('#item-description' + j).attr('id','item-description' + i); - - jQuery(this).find('#item-attr-title' + j).attr('name','item-attr-title' + i); - jQuery(this).find('#item-attr-title' + j).attr('id','item-attr-title' + i); - - jQuery(this).find('#item-target' + j).attr('name','item-target' + i); - jQuery(this).find('#item-target' + j).attr('id','item-target' + i); - - jQuery(this).find('#item-position' + j).attr('name', 'item-position' + i); - jQuery(this).find('#item-position' + j).attr('id', 'item-position' + i); - - jQuery(this).find('#item-type' + j).attr('name', 'item-type' + i); - jQuery(this).find('#item-type' + j).attr('id', 'item-type' + i); - - jQuery('#li-count').attr( 'value', i ); - }); -}; - /** * Adds the item to the menu * - * @param string id - The menu item's id - * @param string additemtype - Page, Category, or Custom. - * @param string itemtext - menu text. - * @param string itemurl - url of the menu. - * @param int itemid - menu id. - * @param int itemparentid - default 0. - * @param string itemdescription - the description of the menu item. + * @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_type, item_title, item_url, item_id, item_parent_id, item_description ) { +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(''); + jQuery('.menu').append(''); // Give some feedback to the user - jQuery( '.menu #menu-' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); + 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(); - wp_update_post_data(); - // Reload thickbox tb_init('a.thickbox, area.thickbox, input.thickbox'); }; -/* - * Queues items in perperation for appendToList - * - * @param string type - Page, Category, or Custom. - * @param string link - menu text. - * @param string url - url of the menu. - * @param int id - menu id. - * @param int parent_id - default 0. - * @param string description - the description of the menu item. -*/ -function wp_update_queue( e, item_type, item_title, item_url, item_id, item_parent_id, item_description ) { - var randomnumber = wp_get_unique_menu_id(); - var menu_item_id = jQuery(e).attr('id'); - - if ( jQuery(e).attr('checked') ) { - // Add menu item to the queue - jQuery('#queue').append(''); - - } else { - // Remove the item from the queue - if ( menu_item_id == jQuery('#queue li input[name^="item-id"]' ).val() ) { - jQuery('#queue li input[name^="item-id"]' ).parent().remove() - }; - }; -}; - /** * Grabs items from the queue and adds them to the menu. * - * @param string button - a reference of the button that was clicked + * @param string button - a reference to the button that was clicked */ -function wp_add_queued_items_to_menu( button ) { - // Grab items in queue - var items = jQuery('#queue').children(); +function wp_add_checked_items_to_menu( button ) { + // Grab checked items + var items = jQuery(button).siblings('.list-wrap').find(':checked'); - // Empty Queue - jQuery('#queue').empty(); - - // Appends HTML to the menu - jQuery('.menu').append( items ); - - // Give some feedback to the user + // 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(){ - jQuery(this).find('dt').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }}); + 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 = '_none'; + 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 ); }); - - // Uncheck the checkboxes in the list - jQuery(button).offsetParent().find('.list-container input').attr('checked', false); - - wp_update_post_data(); - - // Enable drag-n-drop - wp_drag_and_drop(); - - // Reload thickbox - tb_init('a.thickbox, area.thickbox, input.thickbox'); }; /** - * Allow the items in the Menu to be dragged and dropped. + * Makes the menu items drag and droppable. */ function wp_drag_and_drop() { // Make sure all li's have dropzones @@ -251,7 +194,7 @@ function wp_drag_and_drop() { opacity: .8, addClasses: false, helper: 'clone', - zIndex: 100, + zIndex: 100 }); // make menu item droppable @@ -306,6 +249,49 @@ function wp_drag_and_drop() { ); } +/** + * 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 */ @@ -331,4 +317,40 @@ function wp_get_unique_menu_id() { } } 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; } \ No newline at end of file diff --git a/wp-admin/js/nav-menu-dynamic-functions.js b/wp-admin/js/nav-menu-dynamic-functions.js index 45a420a8c1..fd6a4168b4 100644 --- a/wp-admin/js/nav-menu-dynamic-functions.js +++ b/wp-admin/js/nav-menu-dynamic-functions.js @@ -1 +1 @@ -function wp_update_links_list(e){var link='
  • ";jQuery("#available-links .list").prepend(link);jQuery("#available-links .list #link-"+e.link_id).parent().animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})}function wp_edit_menu_item(id){var itemType=jQuery("#item-type"+id).val();var itemTitle=jQuery("#item-title"+id).val();var itemURL=jQuery("#item-url"+id).val();var itemAttrTitle=jQuery("#item-attr-title"+id).val();var itemTarget=jQuery("#item-target"+id).val();var itemDesc=jQuery("#item-description"+id).val();if("page"==itemType||"category"==itemType){jQuery("#edit-item-url").attr("disabled","disabled")}jQuery("#edit-item-id").val(id);jQuery("#edit-item-title").val(itemTitle);jQuery("#edit-item-url").val(itemURL);jQuery("#edit-item-attr-title").val(itemAttrTitle);jQuery("#edit-item-target").val(itemTarget);jQuery("#edit-item-target option[value='"+itemTarget+"']").attr("selected","selected");jQuery("#edit-item-description").val(itemDesc)}function wp_update_menu_item(){var id=jQuery("#edit-item-id").val();var itemTitle=jQuery("#edit-item-title").val();var itemURL=jQuery("#edit-item-url").val();var itemAttrTitle=jQuery("#edit-item-attr-title").val();var itemTarget=jQuery("#edit-item-target").val();var itemDesc=jQuery("#edit-item-description").val();jQuery("#menu-"+id).find(".item-title:first").html(itemTitle);jQuery("#item-title"+id).val(itemTitle);jQuery("#item-url"+id).val(itemURL);jQuery("#item-attr-title"+id).val(itemAttrTitle);jQuery("#item-target"+id).val(itemTarget);jQuery("#item-description"+id).val(itemDesc)}function wp_remove_menu_item(o){var todelete=document.getElementById("menu-"+o);if(todelete){jQuery(todelete).find("dt").each(function(){jQuery(this).animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){jQuery(this).parent().parent().remove()}})});wp_update_post_data()}}function wp_update_post_data(){var i=0;jQuery(".menu li").each(function(i){i=i+1;var j=jQuery(this).attr("value");jQuery(this).find("#item-position"+j).attr("value",i);jQuery(this).attr("id","menu-"+i);jQuery(this).attr("value",i);jQuery(this).find("#item-dbid"+j).attr("name","item-dbid"+i);jQuery(this).find("#item-dbid"+j).attr("id","item-dbid"+i);jQuery(this).find("#item-postmenu"+j).attr("name","item-postmenu"+i);jQuery(this).find("#item-postmenu"+j).attr("id","item-postmenu"+i);var p=jQuery(this).find("#item-parent"+j).parent().parent().parent().attr("value");jQuery(this).find("#item-parent"+j).attr("name","item-parent"+i);jQuery(this).find("#item-parent"+j).attr("id","item-parent"+i);if(p){}else{p=0}jQuery(this).find("#item-parent"+j).attr("value",p);jQuery(this).find("#item-title"+j).attr("name","item-title"+i);jQuery(this).find("#item-title"+j).attr("id","item-title"+i);jQuery(this).find("#item-url"+j).attr("name","item-url"+i);jQuery(this).find("#item-url"+j).attr("id","item-url"+i);jQuery(this).find("#item-description"+j).attr("name","item-description"+i);jQuery(this).find("#item-description"+j).attr("id","item-description"+i);jQuery(this).find("#item-attr-title"+j).attr("name","item-attr-title"+i);jQuery(this).find("#item-attr-title"+j).attr("id","item-attr-title"+i);jQuery(this).find("#item-target"+j).attr("name","item-target"+i);jQuery(this).find("#item-target"+j).attr("id","item-target"+i);jQuery(this).find("#item-position"+j).attr("name","item-position"+i);jQuery(this).find("#item-position"+j).attr("id","item-position"+i);jQuery(this).find("#item-type"+j).attr("name","item-type"+i);jQuery(this).find("#item-type"+j).attr("id","item-type"+i);jQuery("#li-count").attr("value",i)})}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();jQuery(".menu").append('');jQuery(".menu #menu-"+randomnumber+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}});wp_drag_and_drop();wp_update_post_data();tb_init("a.thickbox, area.thickbox, input.thickbox")}function wp_update_queue(e,item_type,item_title,item_url,item_id,item_parent_id,item_description){var randomnumber=wp_get_unique_menu_id();var menu_item_id=jQuery(e).attr("id");if(jQuery(e).attr("checked")){jQuery("#queue").append('')}else{if(menu_item_id==jQuery('#queue li input[name^="item-id"]').val()){jQuery('#queue li input[name^="item-id"]').parent().remove()}}}function wp_add_queued_items_to_menu(button){var items=jQuery("#queue").children();jQuery("#queue").empty();jQuery(".menu").append(items);jQuery(items).each(function(){jQuery(this).find("dt").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})});jQuery(button).offsetParent().find(".list-container input").attr("checked",false);wp_update_post_data();wp_drag_and_drop();tb_init("a.thickbox, area.thickbox, input.thickbox")}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(e,ui){var li=jQuery(this).parent();var child=!jQuery(this).hasClass("dropzone");if(child&&li.children("ul").length==0){li.append(''; $current_parent = array_pop( $parent_stack ); } } else { array_push( $parent_stack, $current_parent ); $current_parent = $menu_item->ID; - $nav_menu .= '