mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-25 15:44:25 +00:00
6564ed9fb7
Update grunt-banana-checker to 0.4.0 Update grunt-jsonlint to 1.0.6 Update grunt-jscs to 2.5.0 Also support looking into sub folders for jshint and jscs. Also fix some js code so Replace } ) ( mw, jQuery ); with }( mediaWiki, jQuery ) ); Also remove a blank message that should not be there in gu.json Also remove two blank messages in tl.json. Change-Id: Ib8390de6fd6adfc4a9ad22c48c7872aac332d4ae
39 lines
1.4 KiB
JavaScript
39 lines
1.4 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 (bug 38141).
|
|
*
|
|
* @author Marius Hoch <hoo@online.de>
|
|
*/
|
|
( function ( mw, $ ) {
|
|
'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' ),
|
|
label;
|
|
|
|
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.
|
|
label = accessibilityLabelMany;
|
|
} else {
|
|
label = accessibilityLabelOne;
|
|
}
|
|
|
|
// We can't use aria-label over here as that's not supported consistently across all screen reader / browser
|
|
// combinations. We have to use visually hidden spans for the accessibility labels instead.
|
|
$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( label + ' ' )
|
|
);
|
|
} );
|
|
} );
|
|
}( mediaWiki, jQuery ) );
|