mediawiki-extensions-Cite/modules/ext.cite.a11y.js
WMDE-Fisch 6dda36a1e7 Improve a11y support on backlinks
This changes the a11y support on the main backlinks by introducing the usage
of title and aria-labels. The support for these elements increased a lot since
the topic was first tackled and seems the appropriate way to go.

A new message was introduced for the link that will be set when directly
coming from a clicked refrence to emphasize that the can jump back to where
he came from.

Bug: T206323
Change-Id: Ifa56d41bcdb8100e19f29619796b62bb3c886d2f
2018-11-26 11:36:26 +01:00

36 lines
1.2 KiB
JavaScript

/**
* Main JavaScript for the Cite extension. The main purpose of this file
* is to add accessibility attributes to the citation links as that can
* hardly be done server side (T40141).
*
* @author Marius Hoch <hoo@online.de>
*/
( function () {
'use strict';
mw.hook( 'wikipage.content' ).add( function ( $content ) {
var accessibilityLabelOne = mw.msg( 'cite_references_link_accessibility_label' ),
accessibilityLabelMany = mw.msg( 'cite_references_link_many_accessibility_label' );
$content.find( '.mw-cite-backlink' ).each( function () {
var $links = $( this ).find( 'a' );
if ( $links.length > 1 ) {
// This citation is used multiple times. Let's only set the accessibility label on the first link, the
// following ones should then be self-explaining. This is needed to make sure this isn't getting
// too wordy.
$links.eq( 0 ).prepend(
$( '<span>' )
.addClass( 'cite-accessibility-label' )
// Also make sure we have at least one space between the accessibility label and the visual one
.text( accessibilityLabelMany + ' ' )
);
} else {
$links
.attr( 'aria-label', accessibilityLabelOne )
.attr( 'title', accessibilityLabelOne );
}
} );
} );
}() );