Make WordPress Core

Ticket #38091: 38091.1.diff

File 38091.1.diff, 2.3 KB (added by westonruter, 8 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 56c061f..ad74ecb 100644
     
    11231123                        section.template = wp.template( 'customize-themes-details-view' );
    11241124
    11251125                        // Bind global keyboard events.
    1126                         $( 'body' ).on( 'keyup', function( event ) {
     1126                        section.container.on( 'keydown', function( event ) {
    11271127                                if ( ! section.overlay.find( '.theme-wrap' ).is( ':visible' ) ) {
    11281128                                        return;
    11291129                                }
     
    11411141                                // Pressing the escape key fires a theme:collapse event
    11421142                                if ( 27 === event.keyCode ) {
    11431143                                        section.closeDetails();
     1144                                        event.stopPropagation(); // Prevent section from being collapsed.
    11441145                                }
    11451146                        });
    11461147
     
    28642865                                });
    28652866                        }
    28662867
    2867                         this.setting.bind( function ( value ) {
     2868                        control.setting.bind( function ( value ) {
    28682869                                // bail if the update came from the control itself
    28692870                                if ( updating ) {
    28702871                                        return;
     
    28722873                                picker.val( value );
    28732874                                picker.wpColorPicker( 'color', value );
    28742875                        } );
     2876
     2877                        // Collapse color picker when hitting Esc instead of collapsing the current section.
     2878                        control.container.on( 'keydown', function( event ) {
     2879                                var pickerContainer;
     2880                                if ( 27 !== event.which ) { // Esc.
     2881                                        return;
     2882                                }
     2883                                pickerContainer = control.container.find( '.wp-picker-container' );
     2884                                if ( pickerContainer.hasClass( 'wp-picker-active' ) ) {
     2885                                        picker.wpColorPicker( 'close' );
     2886                                        control.container.find( '.wp-color-result' ).focus();
     2887                                        event.stopPropagation(); // Prevent section from being collapsed.
     2888                                }
     2889                        } );
    28752890                }
    28762891        });
    28772892
     
    52915306                                return;
    52925307                        }
    52935308
     5309                        /*
     5310                         * Abort if the event target is not the body (the default) and not inside of #customize-controls.
     5311                         * This ensures that ESC meant to collapse a modal dialog or a TinyMCE toolbar won't collapse something else.
     5312                         */
     5313                        if ( ! $( event.target ).is( 'body' ) && ! $.contains( $( '#customize-controls' )[0], event.target ) ) {
     5314                                return;
     5315                        }
     5316
    52945317                        // Check for expanded expandable controls (e.g. widgets and nav menus items), sections, and panels.
    52955318                        api.control.each( function( control ) {
    52965319                                if ( control.expanded && control.expanded() && _.isFunction( control.collapse ) ) {