2019-07-02 21:10:10 +00:00
|
|
|
module.exports = function () {
|
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
|
|
|
|
* @ignore
|
2018-07-03 14:50:09 +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-08-08 21:09:08 +00:00
|
|
|
references.showReference( href, currentPage, $dest.text(),
|
|
|
|
currentPageHTMLParser, gateway );
|
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
|
2018-07-03 14:50:09 +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
|
|
|
};
|