Ticket #23119: 23119-F.diff
| File 23119-F.diff, 17.7 KB (added by lessbloat, 5 months ago) |
|---|
-
wp-admin/includes/nav-menu.php
382 382 **/ 383 383 function wp_nav_menu_setup() { 384 384 // Register meta boxes 385 if ( wp_get_nav_menus() )386 add_meta_box( 'nav-menu-theme-locations', __( 'Theme Locations' ), 'wp_nav_menu_locations_meta_box' , 'nav-menus', 'side', 'default' );387 385 add_meta_box( 'add-custom-links', __('Custom Links'), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); 388 386 wp_nav_menu_post_type_meta_boxes(); 389 387 wp_nav_menu_taxonomy_meta_boxes(); … … 471 469 } 472 470 473 471 /** 474 * Displays a metabox for the nav menu theme locations.475 *476 * @since 3.0.0477 */478 function wp_nav_menu_locations_meta_box() {479 global $nav_menu_selected_id;480 481 if ( ! current_theme_supports( 'menus' ) ) {482 // We must only support widgets. Leave a message and bail.483 echo '<p class="howto">' . __('The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.') . '</p>';484 return;485 }486 487 $locations = get_registered_nav_menus();488 $menus = wp_get_nav_menus();489 $menu_locations = get_nav_menu_locations();490 $num_locations = count( array_keys($locations) );491 492 echo '<p class="howto">' . sprintf( _n('Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n($num_locations) ) . '</p>';493 494 foreach ( $locations as $location => $description ) {495 ?>496 <p>497 <label class="howto" for="locations-<?php echo $location; ?>">498 <span><?php echo $description; ?></span>499 <select name="menu-locations[<?php echo $location; ?>]" id="locations-<?php echo $location; ?>">500 <option value="0"></option>501 <?php foreach ( $menus as $menu ) : ?>502 <option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?>503 value="<?php echo $menu->term_id; ?>"><?php504 $truncated_name = wp_html_excerpt( $menu->name, 40 );505 echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '…';506 ?></option>507 <?php endforeach; ?>508 </select>509 </label>510 </p>511 <?php512 }513 ?>514 <p class="button-controls">515 <?php submit_button( __( 'Save' ), 'primary right', 'nav-menu-locations', false, disabled( $nav_menu_selected_id, 0, false ) ); ?>516 <span class="spinner"></span>517 </p>518 <?php519 }520 521 /**522 472 * Displays a metabox for the custom links menu item. 523 473 * 524 474 * @since 3.0.0 -
wp-admin/js/nav-menu.js
47 47 48 48 this.initToggles(); 49 49 50 this.init TabManager();50 this.initSelectMenuDropdown(); 51 51 }, 52 52 53 53 jQueryExtensions : function() { … … 222 222 } 223 223 }); 224 224 }, 225 226 initSelectMenuDropdown : function () { 227 var menuSelector = $('.menu-selector select'); 228 229 menuSelector.on('change', function () { 230 var url = $(this).val(); 231 232 if (url && '--' !== url) { 233 $('.menu-selector .spinner').show(); 234 window.location = url; 235 } 236 }); 237 }, 238 239 hideAllMetaBoxes : function(el) { 240 el.addClass('closed'); 241 }, 242 243 showMetaBox : function(el) { 244 el.removeClass('closed'); 245 }, 225 246 226 247 initToggles : function() { 227 248 // init postboxes 228 249 postboxes.add_postbox_toggles('nav-menus'); 250 251 // Hide all visible .postbox 252 var pboxes = $('.postbox'); 253 this.hideAllMetaBoxes(pboxes); 254 255 // Show first .postbox 256 this.showMetaBox(pboxes.first()); 257 258 // Show on click and hide all others 259 pboxes.on('click', function () { 260 api.hideAllMetaBoxes(pboxes); 261 api.showMetaBox($(this)); 262 }); 263 264 // Show when adding from screen options 265 $('.hide-postbox-tog').on('click', function () { 266 api.hideAllMetaBoxes(pboxes); 267 api.showMetaBox($('#' + $(this).val())); 268 }); 229 269 230 270 // adjust columns functions for menus UI 231 271 columns.useCheckboxesForHidden(); … … 461 501 if( '' == $t.val() ) 462 502 $t.addClass( name ).val( $t.data(name) ); 463 503 }); 504 505 $('.blank-slate .input-with-default-title').focus(); 464 506 }, 465 507 466 508 attachThemeLocationsListeners : function() { … … 688 730 }); 689 731 }, 690 732 691 initTabManager : function() {692 var fixed = $('.nav-tabs-wrapper'),693 fluid = fixed.children('.nav-tabs'),694 active = fluid.children('.nav-tab-active'),695 tabs = fluid.children('.nav-tab'),696 tabsWidth = 0,697 fixedRight, fixedLeft,698 arrowLeft, arrowRight, resizeTimer, css = {},699 marginFluid = api.isRTL ? 'margin-right' : 'margin-left',700 marginFixed = api.isRTL ? 'margin-left' : 'margin-right',701 msPerPx = 2;702 703 /**704 * Refreshes the menu tabs.705 * Will show and hide arrows where necessary.706 * Scrolls to the active tab by default.707 *708 * @param savePosition {boolean} Optional. Prevents scrolling so709 * that the current position is maintained. Default false.710 **/711 api.refreshMenuTabs = function( savePosition ) {712 var fixedWidth = fixed.width(),713 margin = 0, css = {};714 fixedLeft = fixed.offset().left;715 fixedRight = fixedLeft + fixedWidth;716 717 if( !savePosition )718 active.makeTabVisible();719 720 // Prevent space from building up next to the last tab if there's more to show721 if( tabs.last().isTabVisible() ) {722 margin = fixed.width() - tabsWidth;723 margin = margin > 0 ? 0 : margin;724 css[marginFluid] = margin + 'px';725 fluid.animate( css, 100, "linear" );726 }727 728 // Show the arrows only when necessary729 if( fixedWidth > tabsWidth )730 arrowLeft.add( arrowRight ).hide();731 else732 arrowLeft.add( arrowRight ).show();733 }734 735 $.fn.extend({736 makeTabVisible : function() {737 var t = this.eq(0), left, right, css = {}, shift = 0;738 739 if( ! t.length ) return this;740 741 left = t.offset().left;742 right = left + t.outerWidth();743 744 if( right > fixedRight )745 shift = fixedRight - right;746 else if ( left < fixedLeft )747 shift = fixedLeft - left;748 749 if( ! shift ) return this;750 751 css[marginFluid] = "+=" + api.negateIfRTL * shift + 'px';752 fluid.animate( css, Math.abs( shift ) * msPerPx, "linear" );753 return this;754 },755 isTabVisible : function() {756 var t = this.eq(0),757 left = t.offset().left,758 right = left + t.outerWidth();759 return ( right <= fixedRight && left >= fixedLeft ) ? true : false;760 }761 });762 763 // Find the width of all tabs764 tabs.each(function(){765 tabsWidth += $(this).outerWidth(true);766 });767 768 // Set up fixed margin for overflow, unset padding769 css['padding'] = 0;770 css[marginFixed] = (-1 * tabsWidth) + 'px';771 fluid.css( css );772 773 // Build tab navigation774 arrowLeft = $('<div class="nav-tabs-arrow nav-tabs-arrow-left"><a>«</a></div>');775 arrowRight = $('<div class="nav-tabs-arrow nav-tabs-arrow-right"><a>»</a></div>');776 // Attach to the document777 fixed.wrap('<div class="nav-tabs-nav"/>').parent().prepend( arrowLeft ).append( arrowRight );778 779 // Set the menu tabs780 api.refreshMenuTabs();781 // Make sure the tabs reset on resize782 $(window).resize(function() {783 if( resizeTimer ) clearTimeout(resizeTimer);784 resizeTimer = setTimeout( api.refreshMenuTabs, 200);785 });786 787 // Build arrow functions788 $.each([{789 arrow : arrowLeft,790 next : "next",791 last : "first",792 operator : "+="793 },{794 arrow : arrowRight,795 next : "prev",796 last : "last",797 operator : "-="798 }], function(){799 var that = this;800 this.arrow.mousedown(function(){801 var marginFluidVal = Math.abs( parseInt( fluid.css(marginFluid) ) ),802 shift = marginFluidVal,803 css = {};804 805 if( "-=" == that.operator )806 shift = Math.abs( tabsWidth - fixed.width() ) - marginFluidVal;807 808 if( ! shift ) return;809 810 css[marginFluid] = that.operator + shift + 'px';811 fluid.animate( css, shift * msPerPx, "linear" );812 }).mouseup(function(){813 var tab, next;814 fluid.stop(true);815 tab = tabs[that.last]();816 while( (next = tab[that.next]()) && next.length && ! next.isTabVisible() ) {817 tab = next;818 }819 tab.makeTabVisible();820 });821 });822 },823 824 733 eventOnClickEditLink : function(clickedEl) { 825 734 var settings, item, 826 735 matchedSection = /#(.*)$/.exec(clickedEl.href); -
wp-admin/nav-menus.php
42 42 switch ( $action ) { 43 43 case 'add-menu-item': 44 44 check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' ); 45 if ( isset( $_REQUEST['nav-menu-locations'] ) ) 45 if ( isset( $_REQUEST['nav-menu-locations'] ) ) { 46 46 set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) ); 47 elseif ( isset( $_REQUEST['menu-item'] ) ) 47 $messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The menus within your theme have been updated. <a href="%s">Visit your site</a> to preview these changes.'), get_site_url() ) . '</p></div>'; 48 } elseif ( isset( $_REQUEST['menu-item'] ) ) { 48 49 wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] ); 50 } 49 51 break; 50 52 case 'move-down-menu-item' : 51 53 // moving down a menu item is the same as moving up the next in order … … 460 462 ?> 461 463 <div class="wrap"> 462 464 <?php screen_icon(); ?> 463 <h2><?php esc_html_e('Menus'); ?></h2> 465 <h2><?php esc_html_e('Menus'); ?> <a href="<?php 466 echo esc_url(add_query_arg( 467 array( 468 'action' => 'edit', 469 'menu' => 0, 470 ), 471 admin_url( 'nav-menus.php' ) 472 )); 473 ?>" class="add-new-h2">Add New</a></h2> 464 474 <?php 465 475 foreach( $messages as $message ) : 466 476 echo $message . "\n"; 467 477 endforeach; 468 478 ?> 479 <?php if ( 1 < count( $nav_menus ) ) : ?> 480 <p class="menu-selector"> 481 <span class="spinner"></span> 482 <select> 483 <option value="" selected="selected">Select a menu</option> 484 <?php 485 foreach( (array) $nav_menus as $_nav_menu ) : ?> 486 <option value="<?php 487 echo esc_url(add_query_arg( 488 array( 489 'action' => 'edit', 490 'menu' => $_nav_menu->term_id, 491 ), 492 admin_url( 'nav-menus.php' ) 493 )); 494 ?>"> 495 <?php echo esc_html( $_nav_menu->truncated_name ); ?> 496 </option> 497 <?php endforeach; ?> 498 </select> 499 </p> 500 <p class="menus-intro">Menus can be used <?php if ( current_theme_supports( 'menus' ) ) { ?> to replace your themes default navigation, or <?php } ?> <a href="<?php echo admin_url( 'widgets.php' ); ?>">within a widget</a>.</p> 501 <?php endif; ?> 469 502 <div id="nav-menus-frame"> 470 503 <div id="menu-settings-column" class="metabox-holder<?php if ( !$nav_menu_selected_id ) { echo ' metabox-holder-disabled'; } ?>"> 471 504 … … 494 527 <?php submit_button( __( 'Select' ), 'secondary', 'select_menu', false ); ?> 495 528 </form> 496 529 </div> 497 <div class="nav-tabs-wrapper">498 <div class="nav-tabs">499 <?php500 foreach( (array) $nav_menus as $_nav_menu ) :501 if ( $nav_menu_selected_id == $_nav_menu->term_id ) : ?><span class="nav-tab nav-tab-active">502 <?php echo esc_html( $_nav_menu->truncated_name ); ?>503 </span><?php else : ?><a href="<?php504 echo esc_url(add_query_arg(505 array(506 'action' => 'edit',507 'menu' => $_nav_menu->term_id,508 ),509 admin_url( 'nav-menus.php' )510 ));511 ?>" class="nav-tab hide-if-no-js">512 <?php echo esc_html( $_nav_menu->truncated_name ); ?>513 </a><?php endif;514 endforeach;515 if ( 0 == $nav_menu_selected_id ) : ?><span class="nav-tab menu-add-new nav-tab-active">516 <?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add menu' ) ); ?>517 </span><?php else : ?><a href="<?php518 echo esc_url(add_query_arg(519 array(520 'action' => 'edit',521 'menu' => 0,522 ),523 admin_url( 'nav-menus.php' )524 ));525 ?>" class="nav-tab menu-add-new">526 <?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add menu' ) ); ?>527 </a><?php endif; ?>528 </div>529 </div>530 530 <div class="menu-edit"> 531 531 <form id="update-nav-menu" action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data"> 532 532 <div id="nav-menu-header"> 533 533 <div id="submitpost" class="submitbox"> 534 <div class="major-publishing-actions ">534 <div class="major-publishing-actions <?php if ( isset( $_GET['menu'] ) && 0 == $_GET['menu'] ) echo 'blank-slate'; ?>"> 535 535 <label class="menu-name-label howto open-label" for="menu-name"> 536 536 <span><?php _e('Menu Name'); ?></span> 537 537 <input name="menu-name" id="menu-name" type="text" class="menu-name regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Enter menu name here'); ?>" value="<?php echo esc_attr( $nav_menu_selected_title ); ?>" /> … … 602 602 </div><!-- /#menu-management --> 603 603 </div><!-- /#menu-management-liquid --> 604 604 </div><!-- /#nav-menus-frame --> 605 <div class="menu-locations"> 606 <h3>Select menus for your theme</h3> 607 <?php 608 if ( ! current_theme_supports( 'menus' ) ) { 609 // We must only support widgets. Leave a message and bail. 610 echo '<p class="howto">' . __('The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar.') . '</p>'; 611 } 612 613 if ( wp_get_nav_menus() ) : 614 615 $locations = get_registered_nav_menus(); 616 $menus = wp_get_nav_menus(); 617 $menu_locations = get_nav_menu_locations(); 618 $num_locations = count( array_keys($locations) ); 619 620 echo '<p>' . sprintf( _n('Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n($num_locations) ) . '</p>'; 621 ?> 622 <form enctype="multipart/form-data" method="post" class="nav-menu-meta" action="<?php echo admin_url( 'nav-menus.php' ); ?>"> 623 <input type="hidden" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" id="nav-menu-meta-object-id" name="menu"> 624 <input type="hidden" value="add-menu-item" name="action"> 625 <?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?> 626 <?php 627 628 foreach ( $locations as $location => $description ) { 629 ?> 630 <p> 631 <label class="desc" for="locations-<?php echo $location; ?>"><?php echo $description; ?></label> 632 <select name="menu-locations[<?php echo $location; ?>]" id="locations-<?php echo $location; ?>"> 633 <option value="0"></option> 634 <?php foreach ( $menus as $menu ) : ?> 635 <option<?php selected( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $menu->term_id ); ?> 636 value="<?php echo $menu->term_id; ?>"><?php 637 $truncated_name = wp_html_excerpt( $menu->name, 40 ); 638 echo $truncated_name == $menu->name ? $menu->name : trim( $truncated_name ) . '…'; 639 ?></option> 640 <?php endforeach; ?> 641 </select> 642 </p> 643 <?php } ?> 644 <?php submit_button( __( 'Save' ), 'primary', 'nav-menu-locations', false ); ?> 645 <span class="spinner"></span> 646 <?php endif; ?> 647 </form> 648 </div> 605 649 </div><!-- /.wrap--> 606 650 607 651 <?php include( './admin-footer.php' ); ?> -
wp-admin/css/wp-admin.css
6760 6760 margin-left: -300px; 6761 6761 clear: both; 6762 6762 float: left; 6763 padding-top: 24px; 6763 padding-top: 0; 6764 border-top: 1px solid #DFDFDF; 6765 -webkit-border-radius: 3px; 6766 border-radius: 3px; 6767 margin-bottom: 20px; 6764 6768 } 6765 6769 6766 6770 .no-js #wpbody-content #menu-settings-column { … … 6772 6776 margin: 10px 0 0; 6773 6777 } 6774 6778 6779 #menu-settings-column .postbox { 6780 border-top: 0; 6781 margin-bottom: 0; 6782 -webkit-border-radius: 0; 6783 border-radius: 0; 6784 } 6785 6775 6786 .metabox-holder-disabled .postbox { 6776 6787 opacity: 0.5; 6777 6788 filter: alpha(opacity=50); … … 6785 6796 position: relative; 6786 6797 } 6787 6798 6799 .menu-selector { 6800 float: right; 6801 margin-top: 0; 6802 } 6803 6804 .menu-selector .spinner { 6805 float: left; 6806 } 6807 6808 .blank-slate br { 6809 display: none; 6810 } 6811 6812 .blank-slate .menu-name { 6813 height: 2em; 6814 } 6815 6816 .menu-locations { 6817 border-top: 1px solid #ddd; 6818 } 6819 6820 .menu-locations .desc { 6821 width: 200px; 6822 } 6823 6824 .menu-locations .spinner { 6825 float: none; 6826 } 6827 6828 .menus-intro { 6829 float: left; 6830 margin-top: 4px; 6831 } 6832 6788 6833 /* Menu Container */ 6789 6834 #menu-management-liquid { 6790 6835 float: left; 6791 6836 min-width: 100%; 6837 margin-top: 3px; 6792 6838 } 6793 6839 6794 6840 #menu-management { … … 6835 6881 font-weight:bold; 6836 6882 } 6837 6883 6838 /* Menu Tabs */6839 6840 #menu-management .nav-tabs-nav {6841 margin: 0 20px;6842 }6843 6844 #menu-management .nav-tabs-arrow {6845 width: 10px;6846 padding: 0 5px 4px;6847 cursor: pointer;6848 position: absolute;6849 top: 0;6850 line-height: 22px;6851 font-size: 18px;6852 text-shadow: 0 1px 0 #fff;6853 }6854 6855 #menu-management .nav-tabs-arrow-left {6856 left: 0;6857 }6858 6859 #menu-management .nav-tabs-arrow-right {6860 right: 0;6861 text-align: right;6862 }6863 6864 #menu-management .nav-tabs-wrapper {6865 width: 100%;6866 height: 28px;6867 margin-bottom: -1px;6868 overflow: hidden;6869 }6870 6871 #menu-management .nav-tabs {6872 padding-left: 20px;6873 padding-right: 10px;6874 }6875 6876 .js #menu-management .nav-tabs {6877 float: left;6878 margin-left: 0px;6879 margin-right: -400px;6880 }6881 6882 #menu-management .nav-tab {6883 margin-bottom: 0;6884 font-size: 14px;6885 }6886 6887 6884 #select-nav-menu-container { 6888 6885 text-align: right; 6889 6886 padding: 0 10px 3px 10px; … … 7326 7323 margin: 5px 0 1px; 7327 7324 } 7328 7325 7326 .nav-menus-php .blank-slate .publishing-action { 7327 float: left; 7328 margin: 1px 0 0; 7329 } 7330 7329 7331 .nav-menus-php .major-publishing-actions .delete-action { 7330 7332 vertical-align: middle; 7331 7333 text-align: left;
