Make WordPress Core

Ticket #23450: 23450.9.diff

File 23450.9.diff, 14.2 KB (added by DrewAPicture, 10 years ago)

New approach w/ do_menu_accordion_sections()

  • wp-admin/css/wp-admin.css

     
    60376037        overflow: auto;
    60386038}
    60396039
     6040.wp-full-overlay-sidebar-content .accordion-section:first-child {
     6041        border-top: 1px solid #fff;
     6042}
     6043
    60406044/* Close Link */
    60416045.wp-full-overlay .close-full-overlay {
    60426046        text-decoration: none;
     
    72027206        display: block;
    72037207}
    72047208
     7209#nav-menu-meta ul.outer-border {
     7210        -webkit-border-radius: 3px;
     7211        border-radius: 3px;
     7212}
     7213
     7214.accordion-section ul.category-tabs,
     7215.accordion-section ul.add-menu-item-tabs,
     7216.accordion-section ul.wp-tab-bar {
     7217        margin: 0;
     7218}
     7219
     7220.accordion-section .categorychecklist {
     7221        margin: 13px 0;
     7222}
     7223
     7224#nav-menu-meta .accordion-section-content {
     7225        padding: 18px 13px;
     7226}
     7227
     7228#nav-menu-meta .button-controls {
     7229        margin-bottom: 0;
     7230}
     7231
    72057232#nav-menus-frame {
    72067233        margin-left: 300px;
    72077234        margin-top: 28px;
     
    73317358}
    73327359
    73337360.nav-menus-php #post-body {
    7334         padding: 0 10px;
     7361        padding: 0 10px 10px;
    73357362        border-width: 1px 0;
    73367363        border-style: solid;
    73377364}
     
    74017428}
    74027429
    74037430/* Add Menu Item Boxes */
    7404 .postbox .howto input {
     7431.postbox .howto input,
     7432.accordion-container .howto input {
    74057433        width: 180px;
    74067434        float: right;
    74077435}
    74087436
     7437.accordion-container .outer-border {
     7438        margin-top: 0;
     7439}
     7440
     7441.accordion-container .accordion-section:first-child {
     7442        -webkit-border-top-right-radius: 3px;
     7443        -webkit-border-top-left-radius: 3px;
     7444        border-top-right-radius: 3px;
     7445        border-top-left-radius: 3px;
     7446}
     7447
     7448.accordion-container .accordion-section:last-child {
     7449        -webkit-border-bottom-right-radius: 3px;
     7450        -webkit-border-bottom-left-radius: 3px;
     7451        border-bottom-right-radius: 3px;
     7452        border-bottom-left-radius: 3px;
     7453}
     7454
    74097455.customlinkdiv .howto input {
    7410         width: 200px;
     7456        width: 180px;
    74117457}
    74127458
     7459.customlinkdiv p {
     7460        margin-top: 0
     7461}
     7462
    74137463#nav-menu-theme-locations .howto select {
    74147464        width: 100%;
    74157465}
     
    88188868        margin: 0;
    88198869}
    88208870
     8871.accordion-section:first-child {
     8872        border-top: 1px solid #dfdfdf;
     8873}
     8874
    88218875.accordion-section:last-child {
    88228876        box-shadow: 0 1px 0 0px #fff;
    88238877}
     
    88258879.accordion-section.open .accordion-section-content {
    88268880        display: block;
    88278881        background: #fdfdfd;
     8882        border-left: 1px solid #dfdfdf;
     8883        border-right: 1px solid #dfdfdf;
    88288884}
    88298885
    88308886.accordion-section.open:hover {
     
    88418897        margin: 0;
    88428898        padding: 15px 20px;
    88438899        position: relative;
     8900        border-left: 1px solid #dfdfdf;
     8901        border-right: 1px solid #dfdfdf;
    88448902
    88458903        cursor: pointer;
    88468904
     
    89148972        background-image:    -moz-linear-gradient(bottom, #6d6d6d, #808080);
    89158973        background-image:      -o-linear-gradient(bottom, #6d6d6d, #808080);
    89168974        background-image: linear-gradient(to top, #6d6d6d, #808080);
     8975        border-left: 1px solid #808080;
     8976        border-right: 1px solid #808080;
    89178977}
    89188978
    89198979.control-section.accordion-section:hover,
  • wp-admin/includes/nav-menu.php

     
    387387function wp_nav_menu_setup() {
    388388        // Register meta boxes
    389389        wp_nav_menu_post_type_meta_boxes();
    390         add_meta_box( 'add-custom-links', __( 'Add Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );
     390        add_menu_accordion_section( 'add-custom-links', __( 'Links' ), 'wp_nav_menu_item_link_meta_box', 'side', 'default' );
    391391        wp_nav_menu_taxonomy_meta_boxes();
    392392
    393393        // Register advanced menu items (columns)
    394         add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns');
     394        add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' );
    395395
    396396        // If first time editing, disable advanced items by default.
    397397        if( false === get_user_option( 'managenav-menuscolumnshidden' ) ) {
     
    440440function wp_nav_menu_post_type_meta_boxes() {
    441441        $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
    442442
     443        // Reverse array to show pages as first item
     444        $post_types = array_merge( array_reverse( array_slice( $post_types, 0, 2 ) ), $post_types );
     445
    443446        if ( ! $post_types )
    444447                return;
    445448
     
    447450                $post_type = apply_filters( 'nav_menu_meta_box_object', $post_type );
    448451                if ( $post_type ) {
    449452                        $id = $post_type->name;
    450                         add_meta_box( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'nav-menus', 'side', 'default', $post_type );
     453                        add_menu_accordion_section( "add-{$id}", $post_type->labels->name, 'wp_nav_menu_item_post_type_meta_box', 'side', 'default', $post_type );
    451454                }
    452455        }
    453456}
     
    467470                $tax = apply_filters( 'nav_menu_meta_box_object', $tax );
    468471                if ( $tax ) {
    469472                        $id = $tax->name;
    470                         add_meta_box( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'nav-menus', 'side', 'default', $tax );
     473                        add_menu_accordion_section( "add-{$id}", $tax->labels->name, 'wp_nav_menu_item_taxonomy_meta_box', 'side', 'default', $tax );
    471474                }
    472475        }
    473476}
     
    565568
    566569        ?>
    567570        <div class="customlinkdiv" id="customlinkdiv">
     571                <input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
     572                <p id="menu-item-url-wrap">
     573                        <label class="howto" for="custom-menu-item-url">
     574                                <span><?php _e('URL'); ?></span>
     575                                <input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" />
     576                        </label>
     577                </p>
    568578
    569                         <input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
    570                         <p id="menu-item-url-wrap">
    571                                 <label class="howto" for="custom-menu-item-url">
    572                                         <span><?php _e('URL'); ?></span>
    573                                         <input id="custom-menu-item-url" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-url]" type="text" class="code menu-item-textbox" value="http://" />
    574                                 </label>
    575                         </p>
     579                <p id="menu-item-name-wrap">
     580                        <label class="howto" for="custom-menu-item-name">
     581                                <span><?php _e( 'Link Text' ); ?></span>
     582                                <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Menu Item'); ?>" />
     583                        </label>
     584                </p>
    576585
    577                         <p id="menu-item-name-wrap">
    578                                 <label class="howto" for="custom-menu-item-name">
    579                                         <span><?php _e( 'Link Text' ); ?></span>
    580                                         <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Menu Item'); ?>" />
    581                                 </label>
    582                         </p>
    583 
    584586                <p class="button-controls">
    585587                        <span class="add-to-menu">
    586588                                <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" />
  • wp-admin/includes/template.php

     
    887887                $screen = get_current_screen();
    888888        elseif ( is_string( $screen ) )
    889889                $screen = convert_to_screen( $screen );
    890 
     890               
    891891        $page = $screen->id;
    892892
    893893        $hidden = get_hidden_meta_boxes( $screen );
     
    968968}
    969969
    970970/**
     971 * Add Menu Accordion Section
     972 *
     973 * Used as a wrapper for add_meta_box() to both add new menu accordion
     974 * sections and reinforce the idea that we're no longer working with
     975 * "meta boxes" in the Menus UI but rather accordion sections.
     976 *
     977 * @since 3.6.0
     978 *
     979 * @uses add_meta_box() to add a new accordion section via do_menu_accordion_sections().
     980 *
     981 * @param string $id String for use in the 'id' attribute of tags.
     982 * @param string $title Title of the menu accordion section.
     983 * @param string $callback Function that fills the section with the desired content. The function should echo its output.
     984 * @param string $context Optional. The context within the accordion where the section should show ('normal', 'advanced').
     985 * @param string $priority Optional. The priority within the context where the section should show ('high', 'low').
     986 * @param array $callback_args Optional. Data that should be set as the "args" property of the section array (which is the second parameter passed to your callback).
     987 */
     988function add_menu_accordion_section( $id, $title, $callback, $context = 'advanced', $priority = 'default', $callback_args = null ) {
     989        add_meta_box( $id, $title, $callback, 'nav-menus', $context, $priority, $callback_args );
     990}
     991
     992/**
     993 * Menu Accordion Template Function
     994 *
     995 * Largely abstracted away from code in do_meta_boxes(), this function
     996 * serves to build the list items contained in the Menus UI accordion.
     997 * The naming also serves to reinforce the idea that we're no longer
     998 * working with "meta boxes" in the Menus UI, but rather an accordion.
     999 *
     1000 * @since 3.6.0
     1001 *
     1002 * @uses global $wp_meta_boxes to retrieve registered sections.
     1003 *
     1004 * @param string|object $screen Screen identifier.
     1005 * @param string $context accordion section context.
     1006 * @param mixed $object gets passed to the section callback function as first parameter.
     1007 * @return int number of accordion sections.
     1008 */
     1009function do_menu_accordion_sections( $screen, $context, $object ) {
     1010        global $wp_meta_boxes;
     1011
     1012        if ( empty( $screen ) )
     1013                $screen = get_current_screen();
     1014        elseif ( is_string( $screen ) )
     1015                $screen = convert_to_screen( $screen );
     1016               
     1017        $page = $screen->id;
     1018
     1019        $hidden = get_hidden_meta_boxes( $screen );
     1020       
     1021        $i = 0;
     1022        do {
     1023                if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[$page] ) || ! isset( $wp_meta_boxes[$page][$context] ) )
     1024                        break;
     1025
     1026                foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
     1027                        if ( isset( $wp_meta_boxes[$page][$context][$priority] ) ) {
     1028                                foreach ( $wp_meta_boxes[$page][$context][$priority] as $box ) {
     1029                                        if ( false == $box || ! $box['title'] )
     1030                                                continue;
     1031                                        $i++;
     1032                                        $style = '';
     1033                                        $hidden_class = in_array( $box['id'], $hidden ) ? ' hide-if-js' : '';
     1034                                        ?>
     1035                                        <li class="control-section accordion-section <?php echo $hidden; ?>" id="accordion-section-title_tagline">
     1036                                                <h3 class="accordion-section-title hndle" tabindex="0" title="<?php echo esc_attr( $box['title'] ); ?>"><?php echo esc_html( $box['title'] ); ?></h3>
     1037                                                <div id="<?php echo $box['id']; ?>" class="accordion-section-content <php postbox_classes( $box['id'], $page ); ?>">
     1038                                                        <div class="inside">
     1039                                                                <?php call_user_func( $box['callback'], $object, $box ); ?>
     1040                                                        </div><!-- .inside -->
     1041                                                </div><!-- .accordion-section-content -->
     1042                                        </li><!-- .control-section -->
     1043                                        <?php
     1044                                }                       
     1045                        }
     1046                }
     1047        } while(0);
     1048
     1049        return $i;     
     1050}
     1051
     1052/**
     1053 * Remove Menu Accordion Section
     1054 *
     1055 * Used as a wrapper for remove_meta_box() to both remove menu accordion
     1056 * sections and reinforce the idea that we're no longer working with
     1057 * "meta boxes" in the Menus UI but rather accordion sections.
     1058 *
     1059 * @since 3.6.0
     1060 *
     1061 * @uses remove_meta_box() to remove an accordion section.
     1062 *
     1063 * @param string $id String for use in the 'id' attribute of tags.
     1064 * @param string $context The context within the accordion where the section shows ('normal', 'advanced').
     1065 */
     1066function remove_menu_accordion_section( $id, $context ) {
     1067        remove_meta_box( $id, 'nav-menus', $context );
     1068}
     1069
     1070/**
    9711071 * Add a new section to a settings page.
    9721072 *
    9731073 * Part of the Settings API. Use this to define new settings sections for an admin page.
  • wp-admin/js/nav-menu.js

     
    4242
    4343                        this.attachUnsavedChangesListener();
    4444
    45                         if( api.menuList.length ) // If no menu, we're in the + tab.
     45                        if( api.menuList.length )
    4646                                this.initSortables();
    4747
    4848                        if( oneThemeLocationNoMenus )
     
    5151                        this.initAccessibility();
    5252
    5353                        this.initToggles();
     54
     55                        // Open first accordion option
     56                        $( '.accordion-container li' ).first().addClass( 'open' );
    5457                },
    5558
    5659                jQueryExtensions : function() {
     
    380383                initToggles : function() {
    381384                        // init postboxes
    382385                        postboxes.add_postbox_toggles('nav-menus');
    383 
     386                       
    384387                        // adjust columns functions for menus UI
    385388                        columns.useCheckboxesForHidden();
    386389                        columns.checked = function(field) {
     
    786789                                        target = $(e.target);
    787790
    788791                                if ( target.hasClass('nav-tab-link') ) {
    789                                         panelId = /#(.*)$/.exec(e.target.href);
    790                                         if ( panelId && panelId[1] )
    791                                                 panelId = panelId[1]
    792                                         else
    793                                                 return false;
    794792
    795                                         wrapper = target.parents('.inside').first();
     793                                        panelId = target.data( 'type' );
    796794
     795                                        wrapper = target.parents('.accordion-section-content').first();
     796
    797797                                        // upon changing tabs, we want to uncheck all checkboxes
    798798                                        $('input', wrapper).removeAttr('checked');
    799799
     
    806806                                        // select the search bar
    807807                                        $('.quick-search', wrapper).focus();
    808808
    809                                         return false;
     809                                        e.preventDefault();
    810810                                } else if ( target.hasClass('select-all') ) {
    811811                                        selectAreaMatch = /#(.*)$/.exec(e.target.href);
    812812                                        if ( selectAreaMatch && selectAreaMatch[1] ) {
  • wp-admin/nav-menus.php

     
    2323        wp_die( __( 'Cheatin&#8217; uh?' ) );
    2424
    2525wp_enqueue_script( 'nav-menu' );
     26wp_enqueue_script( 'accordion' );
    2627
    2728if ( wp_is_mobile() )
    2829        wp_enqueue_script( 'jquery-touch-punch' );
     
    422423add_filter('admin_body_class', 'wp_nav_menu_max_depth');
    423424
    424425wp_nav_menu_setup();
     426
    425427wp_initial_nav_menu_meta_boxes();
    426428
    427429if ( ! current_theme_supports( 'menus' ) && ! wp_get_nav_menus() )
     
    510512                        <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
    511513                        <input type="hidden" name="action" value="add-menu-item" />
    512514                        <?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?>
    513                         <?php do_meta_boxes( 'nav-menus', 'side', null ); ?>
     515                        <div id="side-sortables" class="accordion-container">
     516                                <ul class="outer-border">
     517                                        <?php do_menu_accordion_sections( 'nav-menus', 'side', null ); ?>
     518                                </ul>
     519                        </div>
    514520                </form>
    515521
    516522        </div><!-- /#menu-settings-column -->