2023-08-21 08:08:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
2013-08-17 18:21:00 +00:00
|
|
|
/**
|
2024-03-12 08:37:44 +00:00
|
|
|
* @file Adds accessibility attributes to citation links.
|
|
|
|
* @see https://phabricator.wikimedia.org/T40141
|
2013-08-17 18:21:00 +00:00
|
|
|
* @author Marius Hoch <hoo@online.de>
|
|
|
|
*/
|
2023-10-10 09:00:00 +00:00
|
|
|
mw.hook( 'wikipage.content' ).add( function ( $content ) {
|
|
|
|
const accessibilityLabelOne = mw.msg( 'cite_references_link_accessibility_label' );
|
|
|
|
const accessibilityLabelMany = mw.msg( 'cite_references_link_many_accessibility_label' );
|
2013-08-17 18:21:00 +00:00
|
|
|
|
2023-10-10 09:00:00 +00:00
|
|
|
$content.find( '.mw-cite-backlink' ).each( function () {
|
|
|
|
const $links = $( this ).find( 'a' );
|
2013-08-17 18:21:00 +00:00
|
|
|
|
2023-10-10 09:00:00 +00:00
|
|
|
if ( $links.length > 1 ) {
|
2024-01-30 11:18:52 +00:00
|
|
|
// 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.
|
2023-10-10 09:00:00 +00:00
|
|
|
$links.eq( 0 ).prepend(
|
|
|
|
$( '<span>' )
|
|
|
|
.addClass( 'cite-accessibility-label' )
|
2024-01-30 11:18:52 +00:00
|
|
|
// Also make sure we have at least one space between the accessibility
|
|
|
|
// label and the visual one
|
2023-10-10 09:00:00 +00:00
|
|
|
.text( accessibilityLabelMany + ' ' )
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$links
|
|
|
|
.attr( 'aria-label', accessibilityLabelOne )
|
|
|
|
.attr( 'title', accessibilityLabelOne );
|
|
|
|
}
|
2013-08-17 18:21:00 +00:00
|
|
|
} );
|
2023-10-10 09:00:00 +00:00
|
|
|
} );
|