mediawiki-skins-MinervaNeue/resources/skins.minerva.scripts/references.js
jdlrobson 46f28730e1 Do not add the navigation-enabled class to body tag for drawers
This class is used for the main menu exclusively. Applying it
will reveal 2 transparent shields on top of each other when is
not desired

Bug: T214049
Change-Id: I8ddcc7082c3c602a78084157c2d613366a8016c7
2020-01-14 01:20:40 +00:00

62 lines
1.7 KiB
JavaScript

var drawers = require( './drawers.js' );
module.exports = function () {
// eslint-disable-next-line no-restricted-properties
var M = mw.mobileFrontend,
mobile = M.require( 'mobile.startup' ),
references = mobile.references,
currentPage = mobile.currentPage(),
currentPageHTMLParser = mobile.currentPageHTMLParser(),
ReferencesHtmlScraperGateway = mobile.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 urlComponents,
$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
urlComponents = href.split( '#' );
if ( urlComponents.length > 1 ) {
href = '#' + urlComponents[ 1 ];
}
references.showReference( href, currentPage, $dest.text(),
currentPageHTMLParser, gateway, {
onShow: function () {
drawers.lockScroll();
},
onBeforeHide: drawers.discardDrawer
}
).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.
mobile.util.getDocument().on( 'click', 'sup.reference a', onClickReference );
}
init();
};