mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-17 19:21:39 +00:00
76be18c788
The TableOfContents component is now inside mobile.startup so is readily available. Thus skins.minerva.tablet.scripts is removed and its code moved inside skins.minerva.scripts The check to whether the user is in tablet mode now happens inside toc.js The resize handler is dropped on the basis that this is an edge case that is not worth supporting at the cost of an eventBus. Depends-On: I353d6d7a6884dae03b55364150c6bb95cd4cc57f Change-Id: Id16a64573e020b4606fc9b11456163a4cd290e0b
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
( function ( M ) {
|
|
var mobile = M.require( 'mobile.startup' ),
|
|
Toggler = mobile.Toggler,
|
|
TableOfContents = mobile.toc.TableOfContents,
|
|
eventBus = mobile.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 ) );
|