Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
Created page with "Any JavaScript here will be loaded for all users on every page load.: ( function () { 'use strict'; function renderAutoGrid( $container ) { var category = $container.data( 'category' ); if ( !category ) { return; } $container.text( 'Loading…' ); mw.loader.using( 'mediawiki.api' ).then( function () { return new mw.Api().get( { action: 'query', list: 'categorymembers', cmtitle: 'Category:' + category, cmlimit: 500, cmsort: '..."
 
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
( function () {
( function () {
'use strict';
'use strict';
Line 10: Line 8:
}
}


$container.text( 'Loading…' );
$container.text( 'Loading...' );


mw.loader.using( 'mediawiki.api' ).then( function () {
mw.loader.using( 'mediawiki.api' ).then( function () {

Revision as of 20:49, 24 June 2026

( function () {
	'use strict';

	function renderAutoGrid( $container ) {
		var category = $container.data( 'category' );
		if ( !category ) {
			return;
		}

		$container.text( 'Loading...' );

		mw.loader.using( 'mediawiki.api' ).then( function () {
			return new mw.Api().get( {
				action: 'query',
				list: 'categorymembers',
				cmtitle: 'Category:' + category,
				cmlimit: 500,
				cmsort: 'sortkey',
				format: 'json'
			} );
		} ).then( function ( data ) {
			var members = ( data.query && data.query.categorymembers ) || [];
			$container.empty();

			if ( members.length === 0 ) {
				$container.append( $( '<p>' ).text( 'Nothing has been added here yet.' ) );
				return;
			}

			members.forEach( function ( member ) {
				var title = member.title;
				var displayName = title.split( ':' ).slice( 1 ).join( ':' ).split( '/' ).pop();
				var $link = $( '<a>' )
					.attr( 'href', mw.util.getUrl( title ) )
					.text( displayName );
				$container.append( $link );
			} );
		}, function () {
			$container.text( 'Could not load this list right now.' );
		} );
	}

	mw.hook( 'wikipage.content' ).add( function ( $content ) {
		$content.find( '.gar-auto-grid' ).each( function () {
			renderAutoGrid( $( this ) );
		} );
	} );
}() );