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
|
2023-11-07 16:29:17 +00:00
|
|
|
var mobile = 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(),
|
2023-11-07 16:29:17 +00:00
|
|
|
ReferencesHtmlScraperGateway = mobile.references.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 ) {
|
2023-12-12 14:03:42 +00:00
|
|
|
var $dest = $( ev.currentTarget ),
|
2017-07-12 15:12:40 +00:00
|
|
|
href = $dest.attr( 'href' );
|
|
|
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
// If necessary strip the URL portion of the href so we are left with the
|
|
|
|
// fragment
|
2023-12-12 14:03:42 +00:00
|
|
|
var i = href.indexOf( '#' );
|
|
|
|
if ( i > 0 ) {
|
|
|
|
href = href.slice( i );
|
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.
|
2023-11-07 16:29:17 +00:00
|
|
|
$( document ).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
|
|
|
};
|