mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-03 02:06:43 +00:00
5bfd949f9a
This patch removes the remaining usages of M.on/M.off/M.emit (functionality derived from moduleLoader.js in MobileFrontend) in Minerva and continues the work of Id990b0e1a53221d5c1cb3e3012aed0e27d801fc2 (patch for MobileFrontend). This patch and the patch for MobileFrontend should be merged together as they both depend on eachother. Depends-On: Id990b0e1a53221d5c1cb3e3012aed0e27d801fc2 Bug: T156186 Change-Id: I005d2fcdbf91c2f1ac98178dfa388aa8174e7530
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
( function ( M ) {
|
|
var TableOfContents = M.require( 'mobile.toc/TableOfContents' ),
|
|
Toggler = M.require( 'mobile.toggle/Toggler' ),
|
|
eventBus = M.require( 'mobile.startup/eventBusSingleton' );
|
|
|
|
/**
|
|
* 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' );
|
|
|
|
toc = new TableOfContents( {
|
|
sections: sections
|
|
} );
|
|
|
|
// eslint-disable-next-line no-new
|
|
new Toggler( {
|
|
$container: toc.$el,
|
|
prefix: 'toc-',
|
|
page: null,
|
|
isClosed: true,
|
|
eventBus: eventBus
|
|
} );
|
|
// 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)
|
|
// provided a table of contents placeholder has been rendered
|
|
if ( mw.config.get( 'wgAction' ) === 'view' && $( '#toc' ).length > 0 ) {
|
|
init( M.getCurrentPage() );
|
|
}
|
|
|
|
}( mw.mobileFrontend ) );
|