mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-16 10:50:52 +00:00
e0d893c0f5
The fragment in a URL like http://example.com/foo#bar#baz doesn't end when there is another # somewhere. That # is part of the fragment. I'm not sure since when this issue exists. It's already in the first version of this codebase from 2017, see Iff1f7e6. Bug: T332007 Change-Id: I3b0726380d2f385475f5ba53aeab16932d7ccaa7
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
var drawers = require( './drawers.js' );
|
|
|
|
module.exports = function () {
|
|
// eslint-disable-next-line no-restricted-properties
|
|
var mobile = require( 'mobile.startup' ),
|
|
references = mobile.references,
|
|
currentPage = mobile.currentPage(),
|
|
currentPageHTMLParser = mobile.currentPageHTMLParser(),
|
|
ReferencesHtmlScraperGateway = mobile.references.ReferencesHtmlScraperGateway,
|
|
gateway = new ReferencesHtmlScraperGateway( new mw.Api() );
|
|
|
|
/**
|
|
* Event handler to show reference when a reference link is clicked
|
|
*
|
|
* @ignore
|
|
* @param {jQuery.Event} ev Click event of the reference element
|
|
*/
|
|
function showReference( ev ) {
|
|
var $dest = $( ev.currentTarget ),
|
|
href = $dest.attr( 'href' );
|
|
|
|
ev.preventDefault();
|
|
|
|
// If necessary strip the URL portion of the href so we are left with the
|
|
// fragment
|
|
var i = href.indexOf( '#' );
|
|
if ( i > 0 ) {
|
|
href = href.slice( i );
|
|
}
|
|
|
|
references.showReference( href, currentPage, $dest.text(),
|
|
currentPageHTMLParser, gateway, {
|
|
onShow: function () {
|
|
drawers.lockScroll();
|
|
},
|
|
onShowNestedReference: true,
|
|
onBeforeHide: drawers.discardDrawer
|
|
},
|
|
function ( oldDrawer, newDrawer ) {
|
|
oldDrawer.hide();
|
|
drawers.displayDrawer( newDrawer, {} );
|
|
}
|
|
).then( function ( drawer ) {
|
|
drawers.displayDrawer( drawer, {} );
|
|
} );
|
|
}
|
|
|
|
/**
|
|
* Event handler to show reference when a reference link is clicked.
|
|
* Delegates to `showReference` once the references drawer is ready.
|
|
*
|
|
* @ignore
|
|
* @param {jQuery.Event} ev Click event of the reference element
|
|
*/
|
|
function onClickReference( ev ) {
|
|
showReference( ev );
|
|
}
|
|
|
|
function init() {
|
|
// Make references clickable and show a drawer when clicked on.
|
|
$( document ).on( 'click', 'sup.reference a', onClickReference );
|
|
}
|
|
|
|
init();
|
|
};
|