| 3098 | $( 'body' ).on( 'keydown', function( event ) { |
| 3099 | |
| 3100 | if ( 27 !== event.which ) { |
| 3101 | return; |
| 3102 | } |
| 3103 | |
| 3104 | var foundExpandedContainer = false; |
| 3105 | |
| 3106 | // Check for expanded sections, return when/if found. |
| 3107 | api.section.each( function ( section ) { |
| 3108 | if ( section.expanded() ) { |
| 3109 | section.collapse(); |
| 3110 | foundExpandedContainer = true; |
| 3111 | return; |
| 3112 | } |
| 3113 | }); |
| 3114 | |
| 3115 | if ( foundExpandedContainer ) { |
| 3116 | return; |
| 3117 | } |
| 3118 | |
| 3119 | // Check for expanded panels, return when/if found. |
| 3120 | api.panel.each( function ( panel ) { |
| 3121 | if ( panel.expanded() ) { |
| 3122 | panel.collapse(); |
| 3123 | foundExpandedContainer = true; |
| 3124 | return; |
| 3125 | } |
| 3126 | }); |
| 3127 | |
| 3128 | if ( foundExpandedContainer ) { |
| 3129 | return; |
| 3130 | } |
| 3131 | |
| 3132 | // Otherwise, collapse the customizer. |
| 3133 | if ( overlay.hasClass( 'expanded' ) ) { |
| 3134 | overlay.removeClass( 'expanded' ).addClass( 'collapsed' ); |
| 3135 | } |
| 3136 | |
| 3137 | event.preventDefault(); |
| 3138 | }); |
| 3139 | |