Make WordPress Core

Ticket #33220: 33220.8.diff

File 33220.8.diff, 5.6 KB (added by valendesigns, 10 years ago)
  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index 739b962..0e8d27b 100644
     
    6868                params = params || {};
    6969                focus = function () {
    7070                        var focusContainer;
    71                         if ( construct.extended( api.Panel ) && construct.expanded() ) {
    72                                 focusContainer = construct.container.find( '.control-panel-content:first' );
     71                        if ( construct.expanded && construct.expanded() ) {
     72                                focusContainer = construct.container.find( 'ul:first' );
    7373                        } else {
    7474                                focusContainer = construct.container;
    7575                        }
    76                         focusContainer.find( ':focusable:first' ).focus();
    77                         focusContainer[0].scrollIntoView( true );
     76
     77                        // Note that we can't use :focusable due to a jQuery UI issue. See: https://github.com/jquery/jquery-ui/pull/1583
     78                        focusContainer.find( 'input, select, textarea, button, object, a[href], [tabindex]' ).filter( ':visible' ).first().focus();
    7879                };
    7980                if ( params.completeCallback ) {
    8081                        completeCallback = params.completeCallback;
     
    580581                 * @param {Object}  args
    581582                 */
    582583                onChangeExpanded: function ( expanded, args ) {
    583                         var position, scroll, section = this,
     584                        var section = this,
    584585                                container = section.container.closest( '.wp-full-overlay-sidebar-content' ),
    585586                                content = section.container.find( '.accordion-section-content' ),
    586587                                overlay = section.container.closest( '.wp-full-overlay' ),
    587588                                backBtn = section.container.find( '.customize-section-back' ),
    588589                                sectionTitle = section.container.find( '.accordion-section-title' ).first(),
    589                                 expand;
     590                                actions = $( '#customize-header-actions' ).height(),
     591                                sizing, expand, position, scroll;
    590592
    591593                        if ( expanded && ! section.container.hasClass( 'open' ) ) {
    592594
     
    594596                                        expand = args.completeCallback;
    595597                                } else {
    596598                                        container.scrollTop( 0 );
    597                                         expand = function () {
     599                                        sizing = function() {
    598600                                                var matchMedia, offset;
    599601                                                matchMedia = window.matchMedia || window.msMatchMedia;
    600602                                                offset = 90; // 45px for customize header actions + 45px for footer actions.
     
    603605                                                if ( matchMedia && matchMedia( '(max-width: 640px)' ).matches ) {
    604606                                                        offset = 45;
    605607                                                }
    606 
     608                                                content.css( 'height', ( window.innerHeight - offset ) );
     609                                        };
     610                                        expand = function() {
    607611                                                section.container.addClass( 'open' );
    608612                                                overlay.addClass( 'section-open' );
    609613                                                position = content.offset().top;
    610614                                                scroll = container.scrollTop();
    611                                                 content.css( 'margin-top', ( 45 - position - scroll ) );
    612                                                 content.css( 'height', ( window.innerHeight - offset ) );
     615                                                content.css( 'margin-top', ( actions - position - scroll ) );
     616                                                sizing();
    613617                                                sectionTitle.attr( 'tabindex', '-1' );
    614618                                                backBtn.attr( 'tabindex', '0' );
    615619                                                backBtn.focus();
    616620                                                if ( args.completeCallback ) {
    617621                                                        args.completeCallback();
    618622                                                }
     623
     624                                                // Fix the height after browser resize.
     625                                                $( window ).on( 'resize.customizer-section', _.debounce( sizing, 100 ) );
     626
     627                                                // Fix the top margin after reflow.
     628                                                api.bind( 'pane-contents-reflowed', _.debounce( function() {
     629                                                        var offset = ( content.offset().top - actions );
     630                                                        if ( 0 < offset ) {
     631                                                                content.css( 'margin-top', ( parseInt( content.css( 'margin-top' ), 10 ) - offset ) );
     632                                                        }
     633                                                }, 100 ) );
    619634                                        };
    620635                                }
    621636
     
    639654                        } else if ( ! expanded && section.container.hasClass( 'open' ) ) {
    640655                                section.container.removeClass( 'open' );
    641656                                overlay.removeClass( 'section-open' );
    642                                 content.css( 'margin-top', 'inherit' );
     657                                content.css( 'margin-top', '' );
    643658                                container.scrollTop( 0 );
    644659                                backBtn.attr( 'tabindex', '-1' );
    645660                                sectionTitle.attr( 'tabindex', '0' );
     
    647662                                if ( args.completeCallback ) {
    648663                                        args.completeCallback();
    649664                                }
     665                                $( window ).off( 'resize.customizer-section' );
    650666                        } else {
    651667                                if ( args.completeCallback ) {
    652668                                        args.completeCallback();
     
    12341250                                topPanel = overlay.find( '#customize-theme-controls > ul > .accordion-section > .accordion-section-title' ),
    12351251                                backBtn = section.find( '.customize-panel-back' ),
    12361252                                panelTitle = section.find( '.accordion-section-title' ).first(),
    1237                                 content = section.find( '.control-panel-content' );
     1253                                content = section.find( '.control-panel-content' ),
     1254                                actions = $( '#customize-header-actions' ).height();
    12381255
    12391256                        if ( expanded ) {
    12401257
     
    12541271                                        content.parent().show();
    12551272                                        position = content.offset().top;
    12561273                                        scroll = container.scrollTop();
    1257                                         content.css( 'margin-top', ( $( '#customize-header-actions' ).height() - position - scroll ) );
     1274                                        content.css( 'margin-top', ( actions - position - scroll ) );
    12581275                                        section.addClass( 'current-panel' );
    12591276                                        overlay.addClass( 'in-sub-panel' );
    12601277                                        container.scrollTop( 0 );
     
    12651282                                topPanel.attr( 'tabindex', '-1' );
    12661283                                backBtn.attr( 'tabindex', '0' );
    12671284                                backBtn.focus();
     1285
     1286                                // Fix the top margin after reflow.
     1287                                api.bind( 'pane-contents-reflowed', _.debounce( function() {
     1288                                        content.css( 'margin-top', ( parseInt( content.css( 'margin-top' ), 10 ) - ( content.offset().top - actions ) ) );
     1289                                }, 100 ) );
    12681290                        } else {
    12691291                                siblings.removeClass( 'open' );
    12701292                                section.removeClass( 'current-panel' );
     
    26022624                                _( constructs ).each( function ( activeConstructs, type ) {
    26032625                                        api[ type ].each( function ( construct, id ) {
    26042626                                                var active = !! ( activeConstructs && activeConstructs[ id ] );
    2605                                                 construct.active( active );
     2627                                                if ( active ) {
     2628                                                        construct.activate();
     2629                                                } else {
     2630                                                        construct.deactivate();
     2631                                                }
    26062632                                        } );
    26072633                                } );
    26082634                        } );