From 1445d02e6eaf931c1681fb599a34d8d16aef9025 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Wed, 3 Jul 2013 17:29:44 +0530 Subject: [PATCH] Accessibility attributes for ULS trigger Bug: 50575 Change-Id: I07a6fa740e6dcdcb0fd4ae8832ba0ad6fd875170 --- resources/js/ext.uls.interface.js | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/resources/js/ext.uls.interface.js b/resources/js/ext.uls.interface.js index 02aca379..30aa4f5c 100644 --- a/resources/js/ext.uls.interface.js +++ b/resources/js/ext.uls.interface.js @@ -112,6 +112,44 @@ } ); } + /** + * Helper function to make the uls triggers accessible with the keyboard. + * @param {jQuery} $target One or more jQuery elements. + * @since 2013.07 + */ + function addAccessibilityFeatures( $target ) { + // tabindex=0 makes it appear when tabbing targets. + // See also http://www.w3.org/TR/wai-aria/roles#button + $target.attr( { + tabIndex: 0, + role: 'button', + 'aria-haspopup': true + } ); + // TODO: + // * aria-pressed true/false when popup is open + // * aria-controls to reference to the popup + + // Remove outline when clicking + $target.click( function () { + $( this ).css( 'outline', 'none' ); + } ); + // Allow outline to appear again if keyboard activated + $target.blur( function () { + $( this ).css( 'outline', '' ); + } ); + + // Make Enter act the same as clicking. This has the unfortunate side + // effect of removing the outline. + $target.keydown( function ( event ) { + // Enter + if ( event.keyCode === 13 ) { + $( this ).click(); + event.preventDefault(); + event.stopPropagation(); + } + } ); + } + /** * The tooltip to be shown when language changed using ULS * It also allows to undo the language selection. @@ -226,6 +264,7 @@ $( document ).ready( function () { mw.uls.init( function () { var $ulsSettingsTrigger, + $triggers, $pLang, ulsOptions, $ulsTrigger = $( '.uls-trigger' ), @@ -320,6 +359,10 @@ $ulsTrigger.uls( ulsOptions ); } + // At this point we don't care which kind of trigger it is + $triggers = $( '.uls-settings-trigger, .uls-trigger' ); + addAccessibilityFeatures( $triggers ); + // Bind language settings to preferences page link $( '#uls-preferences-link' ) .text( $.i18n( 'ext-uls-language-settings-preferences-link' ) )