Jdlrobson has uploaded a new change for review. https://gerrit.wikimedia.org/r/134814
Change subject: Enable expanding of section headings via space and enter keys ...................................................................... Enable expanding of section headings via space and enter keys For accessibility purposes. See: http://www.marcozehe.de/2013/04/24/easy-aria-tip-6-making-clickables-accessible/ Change-Id: I8a8c203ae443c90b5c8948414688c7fb996bf67c --- M includes/Resources.php D javascripts/modules/toggling/accessibility.js M javascripts/modules/toggling/toggle.js 3 files changed, 18 insertions(+), 26 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/14/134814/1 diff --git a/includes/Resources.php b/includes/Resources.php index 2a0e5a3..01d316e 100644 --- a/includes/Resources.php +++ b/includes/Resources.php @@ -790,7 +790,6 @@ 'mobile.toggling', ), 'scripts' => array( - 'javascripts/modules/toggling/accessibility.js', 'javascripts/modules/mf-toggle-dynamic.js', ), ), diff --git a/javascripts/modules/toggling/accessibility.js b/javascripts/modules/toggling/accessibility.js deleted file mode 100644 index 2045b6e..0000000 --- a/javascripts/modules/toggling/accessibility.js +++ /dev/null @@ -1,24 +0,0 @@ -( function( M, $ ) { - M.assertMode( [ 'alpha', 'beta' ] ); - - var toggle = M.require( 'toggle' ); - function enableKeyboardActions( $headings ) { - $headings.on( 'keypress', function( ev ) { - if ( ev.which === 13 || ev.which === 32 ) { - // Only handle keypresses on the "Enter" or "Space" keys - toggle.toggle( $( this ) ); - } - } ); - - // Make sure certain actions from child links don't bubble up, so - // that users can still use them without toggling a section. - $headings.find( 'a' ).on( 'keypress mouseup', function( ev ) { - ev.stopPropagation(); - } ); - } - M.on( 'toggling-enabled', enableKeyboardActions ); - $( function() { - enableKeyboardActions( $( '#content .section_heading' ) ); - } ); - -}( mw.mobileFrontend, jQuery ) ); diff --git a/javascripts/modules/toggling/toggle.js b/javascripts/modules/toggling/toggle.js index 0bdf0af..0cc88b3 100644 --- a/javascripts/modules/toggling/toggle.js +++ b/javascripts/modules/toggling/toggle.js @@ -1,5 +1,6 @@ ( function( M, $ ) { + /** * Given a heading, toggle it and any of its children * emits a section-toggle event @@ -18,6 +19,22 @@ } ); M.emit( 'section-toggle', $heading ); + } + + /** + * Enables toggling via enter and space keys + * + * @param {jQuery.Object} $heading + */ + function enableKeyboardActions( $heading ) { + $heading.on( 'keypress', function( ev ) { + if ( ev.which === 13 || ev.which === 32 ) { + // Only handle keypresses on the "Enter" or "Space" keys + toggle( $( this ) ); + } + } ).find( 'a' ).on( 'keypress mouseup', function( ev ) { + ev.stopPropagation(); + } ); } /** @@ -90,6 +107,7 @@ toggle( $( this ) ); } ); + enableKeyboardActions( $elem ); if ( ( M.isWideScreen() && M.isBetaGroupMember() ) || expandSections ) { // Expand sections by default on wide screen devices (in beta and alpha), or if the expand sections setting is set (alpha only) toggle( $elem ); @@ -104,7 +122,6 @@ } checkHash(); $( '#content_wrapper a' ).on( 'click', checkHash ); - M.emit( 'toggling-enabled', $headings ); } // avoid this running on Watchlist -- To view, visit https://gerrit.wikimedia.org/r/134814 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8a8c203ae443c90b5c8948414688c7fb996bf67c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits