Make WordPress Core

Changeset 24680


Ignore:
Timestamp:
07/12/2013 06:16:29 PM (13 years ago)
Author:
helen
Message:

Tweaks to the accordion:

  • Enqueues JS in do_accordion_sections().
  • Top and bottom rounded corners for the nav menu accordion.
  • Better RTL and no-JS.

props lessbloat, DrewAPicture, aaroncampbell, helen. fixes #23449.

Location:
trunk/wp-admin
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/css/wp-admin-rtl.css

    r24633 r24680  
    27092709}
    27102710
    2711 .accordion-section-title:after {
     2711.js .accordion-section-title:after {
    27122712        right: auto;
    27132713        left: 20px;
  • trunk/wp-admin/css/wp-admin.css

    r24677 r24680  
    75017501}
    75027502
    7503 .accordion-container .accordion-section:first-child {
     7503#nav-menu-meta .accordion-container .top {
     7504        border-top: 1px solid #dfdfdf;
     7505}
     7506
     7507#nav-menu-meta .accordion-container .accordion-section:first-child,
     7508#nav-menu-meta .accordion-container .accordion-section:first-child h3,
     7509#nav-menu-meta .accordion-container .top,
     7510#nav-menu-meta .accordion-container .top h3 {
    75047511        -webkit-border-top-right-radius: 3px;
    75057512        -webkit-border-top-left-radius: 3px;
     
    75087515}
    75097516
    7510 .accordion-container .accordion-section:last-child {
     7517#nav-menu-meta .accordion-container .accordion-section:last-child,
     7518#nav-menu-meta .accordion-container .accordion-section:last-child .accordion-section-content,
     7519#nav-menu-meta .accordion-container .bottom,
     7520#nav-menu-meta .accordion-container .bottom:not(.open) h3 {
    75117521        -webkit-border-bottom-right-radius: 3px;
    75127522        -webkit-border-bottom-left-radius: 3px;
     
    89698979        border-right: 1px solid #dfdfdf;
    89708980
    8971         cursor: pointer;
    8972 
    89738981        -webkit-user-select: none;
    89748982        -moz-user-select: none;
     
    89768984}
    89778985
    8978 .accordion-section-title:after {
     8986.js .accordion-section-title {
     8987        cursor: pointer;
     8988}
     8989
     8990.js .accordion-section-title:after {
    89798991        content: '';
    89808992        width: 0;
     
    90299041}
    90309042
    9031 .control-section:hover .accordion-section-title,
    9032 .control-section .accordion-section-title:hover,
    9033 .control-section.open .accordion-section-title,
    9034 .control-section .accordion-section-title:focus {
     9043.js .control-section:hover .accordion-section-title,
     9044.js .control-section .accordion-section-title:hover,
     9045.js .control-section.open .accordion-section-title,
     9046.js .control-section .accordion-section-title:focus {
    90359047        color: #fff;
    90369048        text-shadow: 0 -1px 0 #333;
     
    90459057}
    90469058
    9047 .control-section.accordion-section:hover,
     9059.js .control-section.accordion-section:hover,
    90489060.control-section.accordion-section.open {
    90499061        border-top-color: #808080;
  • trunk/wp-admin/includes/template.php

    r24674 r24680  
    986986        global $wp_meta_boxes;
    987987
     988        wp_enqueue_script( 'accordion' );
     989
    988990        if ( empty( $screen ) )
    989991                $screen = get_current_screen();
  • trunk/wp-admin/js/accordion.js

    r24644 r24680  
    1 jQuery(document).ready( function($) {
    2         // Expand/Collapse
    3         $('.accordion-container').on( 'click keydown', '.accordion-section-title', function(e) {
    4                 if ( e.type === 'keydown' && 13 !== e.which ) // "return" key
    5                                 return;
    6                 e.preventDefault(); // Keep this AFTER the key filter above
     1( function( $ ){
    72
    8                 var section = $( this ).closest( '.accordion-section' ),
    9                     siblings = section.siblings( '.open' ),
    10                     content = section.find( '.accordion-section-content' );
     3        $( document ).ready( function () {
    114
    12                 if ( section.hasClass('cannot-expand') )
     5                // Expand/Collapse on click
     6                $( '.accordion-container' ).on( 'click keydown', '.accordion-section-title', function( e ) {
     7                        if ( e.type === 'keydown' && 13 !== e.which ) // "return" key
     8                                        return;
     9                        e.preventDefault(); // Keep this AFTER the key filter above
     10
     11                        accordionSwitch( $( this ) );
     12                        accordionCorners();
     13                });
     14
     15                // Refresh selected accordion option when screen options are toggled
     16                $( '.hide-postbox-tog' ).click( function () {
     17                        accordionInit();
     18                });
     19
     20        });
     21
     22        var accordionOptions = $( '.accordion-container li.accordion-section' ),
     23                sectionContent   = $( '.accordion-section-content' );
     24
     25        // Rounded corners
     26        function accordionCorners () {
     27                accordionOptions.removeClass( 'top bottom' );
     28                accordionOptions.filter( ':visible' ).first().addClass( 'top' );
     29                accordionOptions.filter( ':visible' ).last().addClass( 'bottom' ).find( sectionContent ).addClass('bottom');
     30        };
     31
     32        function accordionInit () {
     33                accordionSwitch( accordionOptions.filter( ':visible' ).first() );
     34                accordionCorners();
     35        }
     36
     37        function accordionSwitch ( el ) {
     38                var section = el.closest( '.accordion-section' ),
     39                    siblings = section.parent().find( '.open' ),
     40                    content = section.find( sectionContent );
     41
     42                if ( section.hasClass( 'cannot-expand' ) )
    1343                        return;
    1444
    1545                siblings.removeClass( 'open' );
    16                 siblings.find( '.accordion-section-content' ).show().slideUp( 150 );
     46                siblings.find( sectionContent ).show().slideUp( 150 );
    1747                content.toggle( section.hasClass( 'open' ) ).slideToggle( 150 );
    1848                section.toggleClass( 'open' );
    19         });
    20 });
     49        }
     50
     51        // Show the first accordion option by default
     52        accordionInit();
     53
     54})(jQuery);
  • trunk/wp-admin/js/nav-menu.js

    r23810 r24680  
    5454
    5555                        this.initToggles();
    56 
    57                         // Open first accordion option
    58                         this.initAccordion();
    5956                },
    6057
     
    266263                                }
    267264                        });
    268                 },
    269 
    270                 initAccordion : function() {
    271                         var accordionOptions = $( '.accordion-container li.accordion-section' );
    272                         accordionOptions.removeClass('open');
    273                         accordionOptions.filter(':visible').first().addClass( 'open' );
    274265                },
    275266
     
    545536
    546537                        $('.hide-postbox-tog').click(function () {
    547                                 api.initAccordion();
    548 
    549538                                var hidden = $( '.accordion-container li.accordion-section' ).filter(':hidden').map(function() { return this.id; }).get().join(',');
    550539                                $.post(ajaxurl, {
  • trunk/wp-admin/nav-menus.php

    r24567 r24680  
    2424
    2525wp_enqueue_script( 'nav-menu' );
    26 wp_enqueue_script( 'accordion' );
    2726
    2827if ( wp_is_mobile() )
Note: See TracChangeset for help on using the changeset viewer.