mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-24 22:25:27 +00:00
874d9c9e3b
From TypeScript's do's and don'ts:[0] Don’t ever use the types Number, String, Boolean, or Object. These types refer to non-primitive boxed objects that are almost never used appropriately in JavaScript code. Although Minerva only uses JSDocs at this time which seemingly doesn't care about casing[1], we should endeavor to use the proper return types. This patch lowercases typing to indicate primitive / boxed type as appropriate.[2] As a special case, function types are uppercased for compatibility with TypeScript type checking. Also, JQuery types are of type "JQuery". The global JQuery object's identifier is "jQuery". This patch uppercases J's where appropriate. Lastly, replace unsupported type "Integer" with "number" and a comment. [0] https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#general-types [1] https://github.com/jsdoc3/jsdoc/issues/1046#issuecomment-126477791 [2] find resources tests -iname \*.js| xargs -rd\\n sed -ri ' s%\{\s*(number|string|boolean|object|null|undefined)%{\L\1%gi; s%\{\s*function%{Function%g; s%\{\s*jquery%{JQuery%gi; s%\{\s*integer\s*\}%{number} An integer.%gi ' Change-Id: I6cbac15940e4501aee7ede8f421b77ffd027170d
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 ) );
|