Debian Codegraph @

extensions/Cite/modules/ext.cite.a11y.js

raw symbols SCIP
1 'use strict';
2
3 /**
4 * Adds accessibility attributes to citation links.
5 *
6 * @see https://phabricator.wikimedia.org/T40141
7 * @author Marius Hoch <[email protected]>
8 */
9 mw.hook( 'wikipage.content' ).add( ( $content ) => {
10 const accessibilityLabelOne = mw.msg( 'cite_references_link_accessibility_label' );
11 const accessibilityLabelMany = mw.msg( 'cite_references_link_many_accessibility_label' );
12
13 $content.find( '.mw-cite-backlink' ).each( ( i, el ) => {
14 const $links = $( el ).find( 'a' );
15
16 if ( $links.length > 1 ) {
17 // This citation is used multiple times. Let's only set the accessibility
18 // label on the first link, the following ones should then be
19 // self-explaining. This is needed to make sure this isn't getting too
20 // wordy.
21 $links.eq( 0 ).prepend(
22 $( '<span>' )
23 .addClass( 'cite-accessibility-label' )
24 // Also make sure we have at least one space between the accessibility
25 // label and the visual one
26 .text( accessibilityLabelMany + ' ' )
27 );
28 } else {
29 $links
30 .attr( 'aria-label', accessibilityLabelOne )
31 .attr( 'title', accessibilityLabelOne );
32 }
33 } );
34 } );