mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-24 22:25:27 +00:00
79fd8bd799
Routine maintenance - all FIXME statements suggest these can be removed. W00t! Depends-On: Iee059a6605cf12a073954378f49ddc721a7e016a Change-Id: I645dca1fa4d9e80d506e907b0be78a5aef0e2f12
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
( function ( M, $ ) {
|
|
var TableOfContents = M.require( 'mobile.toc/TableOfContents' ),
|
|
Toggler = M.require( 'mobile.toggle/Toggler' );
|
|
|
|
/**
|
|
* 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
|
|
* @ignore
|
|
*/
|
|
function init( page ) {
|
|
var toc,
|
|
sections = page.getSections(),
|
|
$toc = $( '#toc' ),
|
|
enableToc = mw.config.get( 'wgMinervaTocEnabled' );
|
|
|
|
if ( enableToc ) {
|
|
toc = new TableOfContents( {
|
|
sections: sections
|
|
} );
|
|
|
|
// eslint-disable-next-line no-new
|
|
new Toggler( toc.$el, 'toc-', null, true );
|
|
// 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() );
|
|
}
|
|
}
|
|
}
|
|
|
|
// add a ToC only for "view" action (user is reading a page)
|
|
if ( mw.config.get( 'wgAction' ) === 'view' ) {
|
|
init( M.getCurrentPage() );
|
|
}
|
|
|
|
}( mw.mobileFrontend, jQuery ) );
|