Ticket #13525: 13525.diff
File 13525.diff, 14.4 KB (added by , 14 years ago) |
---|
-
wp-admin/admin-ajax.php
399 399 else 400 400 die('0'); 401 401 break; 402 case 'delete-menu-item' :403 $menu_item_id = (int) $_POST['menu-item'];404 check_ajax_referer( 'delete-menu_item_' . $menu_item_id );405 if ( ! current_user_can( 'edit_theme_options' ) )406 die('-1');407 408 if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) )409 die('1');410 else411 die('0');412 break;413 402 case 'delete-meta' : 414 403 check_ajax_referer( "delete-meta_$id" ); 415 404 if ( !$meta = get_post_meta_by_id( $id ) ) -
wp-admin/includes/nav-menu.php
59 59 $original_title = $original_object->post_title; 60 60 } 61 61 ?> 62 <li id="menu-item-<?php echo $item_id; ?>" class="menu-item menu-item-depth-<?php echo $depth; ?> menu-item-<?php echo esc_attr( $item->object ); ?> ">63 <dl class="menu-item-bar <?php64 if ( isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] )65 echo 'menu-item-edit-active menu-item-bar-active';66 e lse67 echo 'menu-item-edit-inactive menu-item-bar-inactive';68 ?>">62 <li id="menu-item-<?php echo $item_id; ?>" class="menu-item menu-item-depth-<?php echo $depth; ?> menu-item-<?php echo esc_attr( $item->object ); ?> menu-item-edit-<?php 63 if ( isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] ) 64 echo 'active'; 65 else 66 echo 'inactive'; 67 ?>"> 68 <dl class="menu-item-bar"> 69 69 <dt class="menu-item-handle"> 70 70 <span class="item-title"><?php echo esc_html( $item->title ); ?></span> 71 71 <span class="item-controls"> … … 104 104 </dt> 105 105 </dl> 106 106 107 <div class="menu-item-settings <?php 108 if ( isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] ) 109 echo 'menu-item-edit-active menu-item-settings-active'; 110 else 111 echo 'menu-item-edit-inactive menu-item-settings-inactive'; 112 ?>" id="menu-item-settings-<?php echo $item_id; ?>"> 107 <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?>"> 113 108 <?php if( 'custom' == $item->type ) : ?> 114 109 <p class="field-url description description-wide"> 115 110 <label for="edit-menu-item-url-<?php echo $item_id; ?>"> … … 178 173 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) ) 179 174 ), 180 175 'delete-menu_item_' . $item_id 181 ); ?>"><?php _e('Remove'); ?></a> <span class="meta-sep"> | </span> <a class="item-close submitclose" id="close-<?php echo $item_id; ?>" href="<?php echo admin_url( 'nav-menus.php' ); ?>"><?php _e('Close'); ?></a> 182 <input class="button-primary save-menu-item" name="save_menu_item" type="submit" value="<?php esc_attr_e('Save Menu Item'); ?>" /> 176 ); ?>"><?php _e('Remove'); ?></a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php echo $item_id; ?>" href="<?php echo admin_url( 'nav-menus.php' ); ?>"><?php _e('Cancel'); ?></a> 183 177 </div> 184 178 185 179 <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" /> -
wp-admin/js/nav-menu.dev.js
132 132 133 133 // Retrieve menu item data 134 134 $(checkboxes).each(function(){ 135 var listItemDBIDMatch = re.exec( $(this).attr('name') ), 135 var t = $(this), 136 listItemDBIDMatch = re.exec( t.attr('name') ), 136 137 listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10); 137 menuItems[listItemDBID] = api.getListDataFromID(listItemDBID);138 menuItems[listItemDBID] = t.closest('li').getItemData( 'add-menu-item', listItemDBID ); 138 139 }); 139 140 // Add the items 140 141 api.addItemToMenu(menuItems, processMethod, function(){ … … 143 144 t.find('img.waiting').hide(); 144 145 }); 145 146 }); 147 }, 148 getItemData : function( itemType, id ) { 149 itemType = itemType || 'menu-item'; 150 151 var itemData = {}, i, objId, 152 fields = [ 153 'menu-item-db-id', 154 'menu-item-object-id', 155 'menu-item-object', 156 'menu-item-parent-id', 157 'menu-item-position', 158 'menu-item-type', 159 'menu-item-title', 160 'menu-item-url', 161 'menu-item-description', 162 'menu-item-attr-title', 163 'menu-item-target', 164 'menu-item-classes', 165 'menu-item-xfn' 166 ]; 167 168 if( !id && itemType == 'menu-item' ) { 169 id = this.find('.menu-item-data-db-id').val(); 170 } 171 172 if( !id ) return itemData; 173 174 this.find('input').each(function() { 175 var field; 176 i = fields.length; 177 while ( i-- ) { 178 if( itemType == 'menu-item' ) 179 field = fields[i] + '[' + id + ']'; 180 else if( itemType == 'add-menu-item' ) 181 field = 'menu-item[' + id + '][' + fields[i] + ']'; 182 183 if ( 184 this.name && 185 field == this.name 186 ) { 187 itemData[fields[i]] = this.value; 188 } 189 } 190 }); 191 192 return itemData; 193 }, 194 setItemData : function( itemData, itemType, id ) { // Can take a type, such as 'menu-item', or an id. 195 itemType = itemType || 'menu-item'; 196 197 if( !id && itemType == 'menu-item' ) { 198 id = $('.menu-item-data-db-id', this).val(); 199 } 200 201 if( !id ) return this; 202 203 this.find('input').each(function() { 204 var t = $(this), field; 205 $.each( itemData, function( attr, val ) { 206 if( itemType == 'menu-item' ) 207 field = attr + '[' + id + ']'; 208 else if( itemType == 'add-menu-item' ) 209 field = 'menu-item[' + id + '][' + attr + ']'; 210 211 if ( field == t.attr('name') ) { 212 t.val( val ); 213 } 214 }); 215 }); 216 return this; 146 217 } 147 218 }); 148 219 }, … … 306 377 return that.eventOnClickMenuDelete(e.target); 307 378 } else if ( -1 != e.target.className.indexOf('item-delete') ) { 308 379 return that.eventOnClickMenuItemDelete(e.target); 309 } else if ( -1 != e.target.className.indexOf('item-c lose') ) {310 return that.eventOnClickC loseLink(e.target);380 } else if ( -1 != e.target.className.indexOf('item-cancel') ) { 381 return that.eventOnClickCancelLink(e.target); 311 382 } 312 383 } 313 384 }); … … 498 569 if ( api.menusChanged ) 499 570 return navMenuL10n.saveAlert; 500 571 }; 501 $('input.menu-save , input.save-menu-item').click(function(){572 $('input.menu-save').click(function(){ 502 573 window.onbeforeunload = null; 503 574 }); 504 575 }, … … 652 723 }, 653 724 654 725 eventOnClickEditLink : function(clickedEl) { 655 var activeEdit,726 var settings, item, 656 727 matchedSection = /#(.*)$/.exec(clickedEl.href); 657 728 if ( matchedSection && matchedSection[1] ) { 658 activeEdit = $('#'+matchedSection[1]); 659 if( 0 != activeEdit.length ) { 660 if( activeEdit.hasClass('menu-item-edit-inactive') ) { 661 activeEdit.slideDown('fast') 662 .siblings('dl').andSelf() 663 .removeClass('menu-item-edit-inactive') 729 settings = $('#'+matchedSection[1]); 730 item = settings.parent(); 731 if( 0 != item.length ) { 732 if( item.hasClass('menu-item-edit-inactive') ) { 733 if( ! settings.data('menu-item-data') ) { 734 settings.data( 'menu-item-data', settings.getItemData() ); 735 } 736 settings.slideDown('fast'); 737 item.removeClass('menu-item-edit-inactive') 664 738 .addClass('menu-item-edit-active'); 665 739 } else { 666 activeEdit.slideUp('fast') 667 .siblings('dl').andSelf() 668 .removeClass('menu-item-edit-active') 740 settings.slideUp('fast'); 741 item.removeClass('menu-item-edit-active') 669 742 .addClass('menu-item-edit-inactive'); 670 743 } 671 744 return false; … … 673 746 } 674 747 }, 675 748 676 eventOnClickCloseLink : function(clickedEl) { 677 $(clickedEl).closest('.menu-item-settings').siblings('dl').find('.item-edit').click(); 749 eventOnClickCancelLink : function(clickedEl) { 750 var settings = $(clickedEl).closest('.menu-item-settings'); 751 settings.setItemData( settings.data('menu-item-data') ); 678 752 return false; 679 753 }, 680 754 … … 699 773 }, 700 774 701 775 eventOnClickMenuItemDelete : function(clickedEl) { 702 var itemID, 703 matchedSection, 704 that = this; 705 706 matchedSection = /_wpnonce=([a-zA-Z0-9]*)$/.exec(clickedEl.href); 707 if ( matchedSection && matchedSection[1] ) { 708 itemID = parseInt(clickedEl.id.replace('delete-', ''), 10); 709 $.post( 710 ajaxurl, 711 { 712 action:'delete-menu-item', 713 'menu-item':itemID, 714 '_wpnonce':matchedSection[1] 715 }, 716 function (resp) { 717 if ( '1' == resp ) 718 that.removeMenuItem(document.getElementById('menu-item-' + itemID)); 719 } 720 ); 721 return false; 722 } 723 return true; 776 var itemID = parseInt(clickedEl.id.replace('delete-', ''), 10); 777 api.removeMenuItem( $('#menu-item-' + itemID) ); 778 return false; 724 779 }, 725 780 726 781 /** … … 765 820 }, 766 821 767 822 removeMenuItem : function(el) { 768 el = $(el);769 823 var children = el.childMenuItems(); 770 824 771 el.addClass('deleting').fadeOut( 350 , function() { 772 el.remove(); 773 children.shiftDepthClass(-1).updateParentMenuItemDBId(); 774 }); 825 el.addClass('deleting').animate({ 826 opacity : 0, 827 height: 0 828 }, 350, function() { 829 el.remove(); 830 children.shiftDepthClass(-1).updateParentMenuItemDBId(); 831 }); 775 832 }, 776 833 777 getListDataFromID : function(menuItemID, parentEl) {778 if ( ! menuItemID )779 return false;780 parentEl = parentEl || document;781 var fields = [782 'menu-item-db-id',783 'menu-item-object-id',784 'menu-item-object',785 'menu-item-parent-id',786 'menu-item-position',787 'menu-item-type',788 'menu-item-title',789 'menu-item-url',790 'menu-item-description',791 'menu-item-attr-title',792 'menu-item-target',793 'menu-item-classes',794 'menu-item-xfn'795 ],796 itemData = {},797 inputs = parentEl.getElementsByTagName('input'),798 i = inputs.length,799 j;800 801 while ( i-- ) {802 j = fields.length;803 while ( j-- ) {804 if (805 inputs[i] &&806 inputs[i].name &&807 'menu-item[' + menuItemID + '][' + fields[j] + ']' == inputs[i].name808 ) {809 itemData[fields[j]] = inputs[i].value;810 }811 }812 }813 814 return itemData;815 },816 817 834 depthToPx : function(depth) { 818 835 return depth * api.options.menuItemDepthPerLevel; 819 836 }, -
wp-admin/nav-menus.php
318 318 // Update menu items 319 319 320 320 if ( ! is_wp_error( $_menu_object ) ) { 321 $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') ); 321 $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') ); 322 $menu_items = array(); 323 // Index menu items by db ID 324 foreach( $unsorted_menu_items as $_item ) 325 $menu_items[$_item->db_id] = $_item; 326 322 327 $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' ); 323 328 wp_defer_term_counting(true); 324 329 // Loop through all the menu items' POST variables … … 356 361 do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); 357 362 358 363 $messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been updated.'), $nav_menu_selected_title ) . '</p></div>'; 359 unset( $menu_items );364 unset( $menu_items, $unsorted_menu_items ); 360 365 } 361 366 } 362 367 break; … … 410 415 // Set up nav menu 411 416 wp_nav_menu_setup(); 412 417 $messages[] = '<div id="message" class="error"><p>' . __('The current theme does not natively support menus, but you can use the “Navigation Menu” widget to add any menus you create here to the theme’s sidebar.') . '</p></div>'; 413 414 // The theme supports neither menus nor widgets.415 } else {416 remove_meta_box( 'create-menu', 'nav-menus', 'side' );417 $messages[] = '<div id="message" class="error"><p>' . __('The current theme does not support menus.') . '</p></div>';418 418 } 419 419 420 420 wp_initial_nav_menu_meta_boxes(); … … 512 512 <?php endif; ?> 513 513 </div><!--END .major-publishing-actions--> 514 514 </div><!--END #submitpost .submitbox--> 515 <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> 516 <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> 517 <?php wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' ); ?> 515 <?php 516 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); 517 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); 518 wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' ); 519 ?> 518 520 <input type="hidden" name="action" value="update" /> 519 521 <input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> 520 522 </div><!--END #nav-menu-header--> -
wp-admin/css/nav-menu.dev.css
214 214 215 215 .meta-sep, 216 216 .submitdelete, 217 .submitc lose{217 .submitcancel { 218 218 display:block; 219 219 float:left; 220 220 font-size: 11px; … … 416 416 -khtml-border-bottom-right-radius: 6px; 417 417 -khtml-border-bottom-left-radius: 6px; 418 418 } 419 .menu-item- settings-active{419 .menu-item-edit-active .menu-item-settings { 420 420 display:block; 421 421 } 422 422 423 .menu-item- settings-inactive{423 .menu-item-edit-inactive .menu-item-settings { 424 424 display:none; 425 425 } 426 426 … … 468 468 padding-top: 15px; 469 469 line-height: 25px; 470 470 } 471 .save-menu-item {472 float: right;473 padding-left: 10px;474 }475 471 476 472 #cancel-save { cursor: pointer; } 477 473 #cancel-save:hover { color: #fff !important; } … … 502 498 font-size: 11px; 503 499 font-style: normal; 504 500 } 505 .submitbox .submitc lose{501 .submitbox .submitcancel { 506 502 color: #21759B; 507 503 border-bottom: 1px solid #21759B; 508 504 padding: 1px 2px; 509 505 text-decoration: none; 510 506 } 511 .submitbox .submitc lose:hover {507 .submitbox .submitcancel:hover { 512 508 background: #21759B; 513 509 color: #fff; 514 510 }