mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-01 01:06:31 +00:00
38178c608a
The `page` parameter for the table of contents widget was null, causing an exception to be thrown when the Toggler checks for page.title. Bug: T217820 Change-Id: Ifb78496c8b42f9500ab03655a496e9aae6d1c04b
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
( function ( M ) {
|
|
var mobile = M.require( 'mobile.startup' ),
|
|
Toggler = mobile.Toggler,
|
|
TableOfContents = mobile.toc.TableOfContents,
|
|
eventBus = mobile.eventBusSingleton,
|
|
// eslint-disable-next-line jquery/no-global-selector
|
|
$toc = $( '#toc' );
|
|
|
|
/**
|
|
* 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 sections = page.getSections(),
|
|
toc = new TableOfContents( {
|
|
sections: sections
|
|
} );
|
|
|
|
// eslint-disable-next-line no-new
|
|
new Toggler( {
|
|
$container: toc.$el,
|
|
prefix: 'toc-',
|
|
page: page,
|
|
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 ) );
|