2018-11-15 17:32:38 +00:00
|
|
|
/**
|
|
|
|
* @author Thiemo Kreuz
|
|
|
|
*/
|
|
|
|
( function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
mw.hook( 'wikipage.content' ).add( function ( $content ) {
|
|
|
|
// We are going to use the ID in the code below, so better be sure one is there.
|
|
|
|
$content.find( '.reference[id] > a' ).click( function () {
|
2018-11-19 09:25:21 +00:00
|
|
|
var $backlink, $backlinkWrapper, $upArrowLink, textNode, upArrow,
|
|
|
|
id = $( this ).parent().attr( 'id' ),
|
2018-11-20 16:42:53 +00:00
|
|
|
className = 'mw-cite-targeted-backlink',
|
|
|
|
accessibilityLabel;
|
2018-11-15 17:32:38 +00:00
|
|
|
|
|
|
|
$content.find( '.' + className ).removeClass( className );
|
|
|
|
// The additional "*" avoids the "↑" (when there is only one backlink) becoming bold.
|
2018-11-19 09:25:21 +00:00
|
|
|
$backlink = $content.find( '.mw-cite-backlink * a[href="#' + id + '"]' )
|
|
|
|
.addClass( className );
|
|
|
|
|
|
|
|
if ( !$backlink.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$backlinkWrapper = $backlink.closest( '.mw-cite-backlink' );
|
|
|
|
$upArrowLink = $backlinkWrapper.find( '.mw-cite-up-arrow-backlink' );
|
|
|
|
|
|
|
|
if ( !$upArrowLink.length ) {
|
|
|
|
textNode = $backlinkWrapper[ 0 ].firstChild;
|
|
|
|
|
|
|
|
if ( textNode &&
|
|
|
|
textNode.nodeType === Node.TEXT_NODE &&
|
|
|
|
textNode.data.trim() !== ''
|
|
|
|
) {
|
2018-11-20 16:42:53 +00:00
|
|
|
accessibilityLabel = mw.msg( 'cite_references_link_accessibility_back_label' );
|
2018-11-19 09:25:21 +00:00
|
|
|
upArrow = textNode.data.trim();
|
|
|
|
// The text node typically contains "↑ ", and we need to keep the space.
|
|
|
|
textNode.data = textNode.data.replace( upArrow, '' );
|
|
|
|
|
|
|
|
// Create a plain text and a clickable "↑". CSS :target selectors make sure only
|
|
|
|
// one is visible at a time.
|
|
|
|
$upArrowLink = $( '<a>' )
|
|
|
|
.addClass( 'mw-cite-up-arrow-backlink' )
|
2018-11-20 16:42:53 +00:00
|
|
|
.attr( 'aria-label', accessibilityLabel )
|
|
|
|
.attr( 'title', accessibilityLabel )
|
2018-11-19 09:25:21 +00:00
|
|
|
.text( upArrow );
|
|
|
|
$backlinkWrapper.prepend(
|
|
|
|
$( '<span>' )
|
|
|
|
.addClass( 'mw-cite-up-arrow' )
|
|
|
|
.text( upArrow ),
|
|
|
|
$upArrowLink
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$upArrowLink.attr( 'href', $backlink.attr( 'href' ) );
|
2018-11-15 17:32:38 +00:00
|
|
|
} );
|
|
|
|
} );
|
|
|
|
}() );
|