mediawiki-skins-MinervaNeue/resources/skins.minerva.tablet.scripts/toc.js
jdlrobson 2cc9516cde Minerva is its own skin
This is programmatic output from python3 scripts/migrate.py

This will result in a Minerva skin dependent on MobileFrontend.

Post merge we will rename message keys to have minerva- prefix

Bug: T166748
Change-Id: Iff1f7e63e796cc5d4a6d2ab0370e0c33248d2fce
2017-07-12 08:12:40 -07:00

44 lines
1.2 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 ||
// Fallback for old cached HTML, added 26 June, 2014
( enableToc === null && sections.length > 0 && !page.isMainPage() ) ) {
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 ) );