From 7efd04280717b344dce315c9340b42ba68b4dc29 Mon Sep 17 00:00:00 2001 From: David Sn Date: Thu, 7 Dec 2017 12:55:10 +0000 Subject: [PATCH] Add tabindex to Special:Upload in mw-editTools Bug: T25238 Change-Id: I2b581667aaf0f95c9c0f189f5bf5e852c12fd3cd --- .../mediawiki.special.upload.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/resources/src/mediawiki.special/mediawiki.special.upload.js b/resources/src/mediawiki.special/mediawiki.special.upload.js index 0ddf7fe3f1..aa003591f3 100644 --- a/resources/src/mediawiki.special/mediawiki.special.upload.js +++ b/resources/src/mediawiki.special/mediawiki.special.upload.js @@ -612,4 +612,43 @@ allowCloseWindow.release(); } ); } ); + + // Add tabindex to mw-editTools + $( function () { + // Function to change tabindex for all links within mw-editTools + function setEditTabindex( $val ) { + $( '.mw-editTools' ).find( 'a' ).each( function () { + $( this ).attr( 'tabindex', $val ); + } ); + } + + // Change tabindex to 0 if user pressed spaced or enter while focused + $( '.mw-editTools' ).on( 'keypress', function ( e ) { + // Don't continue if pressed key was not enter or spacebar + if ( e.which !== 13 && e.which !== 32 ) { + return; + } + + // Change tabindex only when main div has focus + if ( $( this ).is( ':focus' ) ) { + $( this ).find( 'a' ).first().focus(); + setEditTabindex( '0' ); + } + } ); + + // Reset tabindex for elements when user focused out mw-editTools + $( '.mw-editTools' ).on( 'focusout', function ( e ) { + // Don't continue if relatedTarget is within mw-editTools + if ( e.relatedTarget !== null && $( e.relatedTarget ).closest( '.mw-editTools' ).length > 0 ) { + return; + } + + // Reset tabindex back to -1 + setEditTabindex( '-1' ); + } ); + + // Set initial tabindex for mw-editTools to 0 and to -1 for all links + $( '.mw-editTools' ).attr( 'tabindex', '0' ); + setEditTabindex( '-1' ); + } ); }( mediaWiki, jQuery ) ); -- 2.20.1