mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-25 06:36:32 +00:00
b0970a4a7e
This is redundant. page.getLeadSectionElement() will return null if the main page is special casing and sections have not been wrapped. Removing this check also allows toggling to work on pages where users want to treat main pages like any other page. Bug: T177337 Change-Id: Ic52fd1c9f6cc4f727ca52c871f29c76997e47f1d
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
( function ( M, $ ) {
|
|
var page = M.getCurrentPage(),
|
|
$contentContainer = $( '#mw-content-text > .mw-parser-output' ),
|
|
Toggler = M.require( 'mobile.toggle/Toggler' );
|
|
|
|
if ( !page.getLeadSectionElement() ) {
|
|
// Operating in desktop Minerva mode. Stop execution. (T172948)
|
|
return;
|
|
}
|
|
// If there was no mw-parser-output wrapper, just use the parent
|
|
if ( $contentContainer.length === 0 ) {
|
|
$contentContainer = $( '#mw-content-text' );
|
|
}
|
|
|
|
/**
|
|
* Initialises toggling code.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Object} $container to enable toggling on
|
|
* @param {string} prefix a prefix to use for the id.
|
|
* @param {Page} page The current page
|
|
* @ignore
|
|
*/
|
|
function init( $container, prefix, page ) {
|
|
// distinguish headings in content from other headings
|
|
$container.find( '> h1,> h2,> h3,> h4,> h5,> h6' ).addClass( 'section-heading' )
|
|
.removeAttr( 'onclick' );
|
|
// cleanup global as it is no longer needed. We check if it's undefined because
|
|
// there is no guarantee this won't be run on other skins e.g. Vector or cached HTML
|
|
if ( window.mfTempOpenSection !== undefined ) {
|
|
delete window.mfTempOpenSection;
|
|
}
|
|
// eslint-disable-next-line no-new
|
|
new Toggler( $container, prefix, page );
|
|
}
|
|
|
|
// avoid this running on Watchlist
|
|
if (
|
|
!page.inNamespace( 'special' ) &&
|
|
mw.config.get( 'wgAction' ) === 'view'
|
|
) {
|
|
init( $contentContainer, 'content-', page );
|
|
}
|
|
}( mw.mobileFrontend, jQuery ) );
|