Ticket #33267: 33267.patch
File 33267.patch, 3.1 KB (added by , 9 years ago) |
---|
-
src/wp-admin/js/customize-controls.js
685 685 */ 686 686 ready: function () { 687 687 var section = this; 688 section.overlay = section.container.find( '.theme-overlay' );689 688 section.template = wp.template( 'customize-themes-details-view' ); 690 689 691 690 // Bind global keyboard events. … … 733 732 */ 734 733 attachEvents: function () { 735 734 var section = this; 735 section.overlay = section.container.find( '.theme-overlay' ); 736 736 737 737 // Expand/Collapse section/panel. 738 738 section.container.find( '.change-theme, .customize-theme' ).on( 'click keydown', function( event ) { … … 806 806 } 807 807 }); 808 808 }); 809 810 // Contain tabbing within the Theme details modal. 811 section.overlay.on( 'keydown', function( event ) { 812 section.containFocus( event ); 813 }); 809 814 }, 810 815 811 816 /** … … 1025 1030 $( 'body' ).addClass( 'modal-open' ); 1026 1031 section.containFocus( section.overlay ); 1027 1032 section.updateLimits(); 1033 // Get and update the tabbable elements for each theme details modal. Keep this after updateLimits(). 1034 section.getTabbables( section.overlay ); 1028 1035 callback(); 1029 1036 }, 1030 1037 … … 1044 1051 * 1045 1052 * @since 4.2.0 1046 1053 */ 1047 containFocus: function( el ) { 1048 var tabbables; 1054 containFocus: function( event ) { 1049 1055 1050 el.on( 'keydown', function( event ) { 1056 // Return if it's not the tab key or if it's navigation with arrows. 1057 if ( 9 !== event.which || 37 === event.which || 39 === event.which ) { 1058 return; 1059 } 1051 1060 1052 // Return if it's not the tab key 1053 // When navigating with prev/next focus is already handled 1054 if ( 9 !== event.keyCode ) { 1055 return; 1056 } 1061 // Keep focus within Theme details modal. 1062 if ( this.tabbables.last()[0] === event.target && ! event.shiftKey ) { 1063 // Prevent default focusing. 1064 event.preventDefault(); 1065 this.tabbables.first().focus(); 1066 } else if ( this.tabbables.first()[0] === event.target && event.shiftKey ) { 1067 // Prevent default focusing. 1068 event.preventDefault(); 1069 this.tabbables.last().focus(); 1070 } 1071 }, 1057 1072 1058 // uses jQuery UI to get the tabbable elements 1059 tabbables = $( ':tabbable', el ); 1073 /** 1074 * Store the tabbable elements within the Theme details modal. 1075 * 1076 * Initially set to an empty jQuery object, gets updated with collection returned by getTabbables(). 1077 * 1078 * @since 4.4.0 1079 */ 1080 tabbables: $(), 1060 1081 1061 // Keep focus within the overlay1062 if ( tabbables.last()[0] === event.target && ! event.shiftKey ) {1063 tabbables.first().focus();1064 return false;1065 } else if ( tabbables.first()[0] === event.target && event.shiftKey ) {1066 tabbables.last().focus();1067 return false;1068 }1069 });1070 }1082 /** 1083 * Get the tabbable elements within the Theme details modal. 1084 * 1085 * Uses jQuery UI to get the tabbable elements. 1086 * 1087 * @since 4.4.0 1088 */ 1089 getTabbables: function( el ) { 1090 this.tabbables = $( ':tabbable', el ); 1091 } 1071 1092 }); 1072 1093 1073 1094 /**