1/** 2 * Follows the wordpress.org keyboard accessibility rules. 3 */ 4jQuery(document).ready(function($) { 5 6 "use strict"; 7 var KEYCODE_TAB = 9; 8 9 /** 10 * On click modal content toggler. 11 */ 12 $( ".azure-news-modal-toggler" ).on( "click", function() { 13 var _this = $(this), 14 popupContent = _this.data("popup-content"), 15 focusToTrapIn = document.querySelector( ".azure-news-modal-popup-content.isActive" ); 16 if( !focusToTrapIn ) return; 17 if( focusToTrapIn.length != 0 ) { 18 var focusable = focusElements( focusToTrapIn ), 19 initialFocusable = focusable[0], 20 finalFocusable = focusable[focusable.length - 1]; 21 $( initialFocusable ).focus(); 22 $(document).on('keydown', function(e) { 23 azure_news_accessibility_focus_trap( initialFocusable, finalFocusable, e ); 24 }); 25 } 26 }); 27 28 /** 29 * On click modal close button 30 * stay focus on popup toggler 31 */ 32 $( ".azure-news-modal-close" ).on( "click", function() { 33 var toFocus = $(this).data( "focus" ); 34 $( toFocus ).focus(); 35 }); 36 37 /** 38 * Focus trap inside the popup content. 39 */ 40 function azure_news_accessibility_focus_trap( initialFocusable, finalFocusable, e ) { 41 if ( e.key === 'Tab' || e.keyCode === KEYCODE_TAB ) { 42 if ( e.shiftKey ) /* shift + tab */ { 43 if (document.activeElement === initialFocusable) { 44 finalFocusable.focus(); 45 e.preventDefault(); 46 } 47 } else /* tab */ { 48 if ( document.activeElement === finalFocusable ) { 49 initialFocusable.focus(); 50 e.preventDefault(); 51 } 52 } 53 } 54 } 55 56 /** 57 * Get all focusable elements inside the element 58 */ 59 function focusElements( focusToTrapIn ) { 60 return focusToTrapIn.querySelectorAll( 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'); 61 } 62 63});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.