2019-12-16 23:47:54 +00:00
|
|
|
var drawers = require( './drawers.js' );
|
|
|
|
|
2019-07-02 21:10:10 +00:00
|
|
|
module.exports = function () {
|
2019-09-27 18:53:01 +00:00
|
|
|
// eslint-disable-next-line no-restricted-properties
|
2019-08-08 21:09:08 +00:00
|
|
|
var M = mw.mobileFrontend,
|
2018-11-08 21:34:50 +00:00
|
|
|
mobile = M.require( 'mobile.startup' ),
|
2019-08-08 21:09:08 +00:00
|
|
|
references = mobile.references,
|
2019-07-11 00:56:04 +00:00
|
|
|
currentPage = mobile.currentPage(),
|
|
|
|
currentPageHTMLParser = mobile.currentPageHTMLParser(),
|
2018-11-08 21:34:50 +00:00
|
|
|
ReferencesHtmlScraperGateway = mobile.ReferencesHtmlScraperGateway,
|
2019-08-08 21:09:08 +00:00
|
|
|
gateway = new ReferencesHtmlScraperGateway( new mw.Api() );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler to show reference when a reference link is clicked
|
2020-06-02 21:21:44 +00:00
|
|
|
*
|
2017-07-12 15:12:40 +00:00
|
|
|
* @ignore
|
2020-06-02 21:21:44 +00:00
|
|
|
* @param {jQuery.Event} ev Click event of the reference element
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
2019-08-08 21:09:08 +00:00
|
|
|
function showReference( ev ) {
|
|
|
|
var urlComponents,
|
2017-07-12 15:12:40 +00:00
|
|
|
$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 ) {
|
2018-11-27 12:29:39 +00:00
|
|
|
href = '#' + urlComponents[ 1 ];
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
2019-11-26 19:04:02 +00:00
|
|
|
|
2019-08-08 21:09:08 +00:00
|
|
|
references.showReference( href, currentPage, $dest.text(),
|
2019-11-26 19:04:02 +00:00
|
|
|
currentPageHTMLParser, gateway, {
|
|
|
|
onShow: function () {
|
2019-12-16 23:47:54 +00:00
|
|
|
drawers.lockScroll();
|
2019-11-26 19:04:02 +00:00
|
|
|
},
|
2020-07-21 20:17:05 +00:00
|
|
|
onShowNestedReference: true,
|
2019-12-16 23:47:54 +00:00
|
|
|
onBeforeHide: drawers.discardDrawer
|
2020-07-21 20:17:05 +00:00
|
|
|
},
|
|
|
|
function ( oldDrawer, newDrawer ) {
|
|
|
|
oldDrawer.hide();
|
|
|
|
drawers.displayDrawer( newDrawer, {} );
|
2019-11-26 19:04:02 +00:00
|
|
|
}
|
|
|
|
).then( function ( drawer ) {
|
2019-12-16 23:47:54 +00:00
|
|
|
drawers.displayDrawer( drawer, {} );
|
2019-11-26 19:04:02 +00:00
|
|
|
} );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler to show reference when a reference link is clicked.
|
|
|
|
* Delegates to `showReference` once the references drawer is ready.
|
|
|
|
*
|
|
|
|
* @ignore
|
2020-06-02 21:21:44 +00:00
|
|
|
* @param {jQuery.Event} ev Click event of the reference element
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
function onClickReference( ev ) {
|
2019-08-08 21:09:08 +00:00
|
|
|
showReference( ev );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 00:56:04 +00:00
|
|
|
function init() {
|
|
|
|
// Make references clickable and show a drawer when clicked on.
|
|
|
|
mobile.util.getDocument().on( 'click', 'sup.reference a', onClickReference );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 00:56:04 +00:00
|
|
|
init();
|
2019-07-02 21:10:10 +00:00
|
|
|
};
|