2018-11-16 15:16:25 +00:00
|
|
|
( function ( M ) {
|
2019-01-11 00:18:45 +00:00
|
|
|
var mobile = M.require( 'mobile.startup' ),
|
|
|
|
Toggler = mobile.Toggler,
|
|
|
|
TableOfContents = mobile.toc.TableOfContents,
|
2019-07-16 21:41:37 +00:00
|
|
|
eventBus = mobile.eventBusSingleton;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create TableOfContents if the given Page has sections and is not the main page
|
|
|
|
* and wgMFTocEnabled config variable is set to true.
|
|
|
|
* @method
|
|
|
|
* @param {Page} page for which a TOC is generated
|
2019-07-16 21:41:37 +00:00
|
|
|
* @param {jQuery.Object} $toc container to replace
|
2017-07-12 15:12:40 +00:00
|
|
|
* @ignore
|
|
|
|
*/
|
2019-07-16 21:41:37 +00:00
|
|
|
function init( page, $toc ) {
|
2019-01-09 13:57:26 +00:00
|
|
|
var sections = page.getSections(),
|
|
|
|
toc = new TableOfContents( {
|
|
|
|
sections: sections
|
|
|
|
} );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2018-03-28 18:36:17 +00:00
|
|
|
// eslint-disable-next-line no-new
|
2018-12-04 22:13:38 +00:00
|
|
|
new Toggler( {
|
|
|
|
$container: toc.$el,
|
|
|
|
prefix: 'toc-',
|
2019-03-07 10:03:28 +00:00
|
|
|
page: page,
|
2018-12-04 22:13:38 +00:00
|
|
|
isClosed: true,
|
|
|
|
eventBus: eventBus
|
|
|
|
} );
|
2018-03-28 18:36:17 +00:00
|
|
|
// if there is a toc already, replace it
|
|
|
|
if ( $toc.length > 0 ) {
|
|
|
|
// don't show toc at end of page, when no sections there
|
|
|
|
$toc.replaceWith( toc.$el );
|
|
|
|
} else {
|
|
|
|
// otherwise append it to the lead section
|
|
|
|
toc.appendTo( page.getLeadSectionElement() );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-16 21:41:37 +00:00
|
|
|
module.exports = init;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2018-11-16 15:16:25 +00:00
|
|
|
}( mw.mobileFrontend ) );
|