| 3631 | // Keyboard shortcuts - esc to exit section/panel. |
| 3632 | $( 'body' ).on( 'keydown', function( event ) { |
| 3633 | |
| 3634 | if ( 27 !== event.which ) { // esc |
| 3635 | return; |
| 3636 | } |
| 3637 | |
| 3638 | var foundExpandedContainer = false; |
| 3639 | |
| 3640 | // Check for expanded sections, return when/if found. |
| 3641 | api.section.each( function ( section ) { |
| 3642 | if ( section.expanded() ) { |
| 3643 | section.collapse(); |
| 3644 | event.preventDefault(); |
| 3645 | foundExpandedContainer = true; |
| 3646 | } |
| 3647 | }); |
| 3648 | |
| 3649 | if ( foundExpandedContainer ) { |
| 3650 | return; |
| 3651 | } |
| 3652 | |
| 3653 | // Check for expanded panels, return when/if found. |
| 3654 | api.panel.each( function ( panel ) { |
| 3655 | if ( panel.expanded() ) { |
| 3656 | panel.collapse(); |
| 3657 | event.preventDefault(); |
| 3658 | foundExpandedContainer = true; |
| 3659 | } |
| 3660 | }); |
| 3661 | |
| 3662 | if ( foundExpandedContainer ) { |
| 3663 | return; |
| 3664 | } |
| 3665 | |
| 3666 | // Otherwise, we're at the root level, so do nothing. |
| 3667 | }); |
| 3668 | |