MediaWiki:Gadget-WikiEditor-Tools-loader.js

/** This script contains the code required for loading. * All other code is located at that page. * * This is intended to reduce the code bloat on pages that do not need this functionality, * and also make it easier to switch in debug versions. */

( function {

/* Not editing, no Wikieditor to care about */ if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) === -1 ) { return; }

if ( !window.wsutils ) { window.wsutils = {}; }

/**	 * This is the boilerplate wikieditor configurator function * (without the "is editing" check, as we do that above) *	 * Any code can use this boilerplate (including user JS) as long as this script * is loaded first. *	 * @param {Function} callback function to call (called with the wikieditor) */	window.wsutils.wikiEditorConfigIncantation = function ( callback ) { mw.loader.using( 'user.options' ).then( function {			// This can be the string '0' if the user disabled the preference			// (T54542)			if ( mw.user.options.get( 'usebetatoolbar' ) === 1 ) {				$.when( mw.loader.using( 'ext.wikiEditor' ), $.ready ).then( function { /* eslint-disable-next-line no-jquery/no-global-selector */ var $tb = $( '#wpTextbox1' ); callback( $tb.wikiEditor.bind( $tb ) ); } );			}		} );	};

var cm = mw.config.get( 'wgPageContentModel' ); var ns = mw.config.get( 'wgCanonicalNamespace' ); var isSandbox = mw.config.get( 'wgTitle' ).search( /\bSandbox/ ) !== -1;

var scripts = [];

if ( cm === 'wikitext' ) { if ( ns === 'Template' || isSandbox ) { scripts.push( 'WikiEditor-TemplateTools' ); } else if ( ns === 'Module_talk' ) { scripts.push( 'WikiEditor-ModuleTools' ); }	} else if ( [ 'css', 'sanitized-css' ].indexOf( cm ) !== -1 ) { scripts.push( 'WikiEditor-CssTools' ); } else if ( cm === 'Scribunto' ) { scripts.push( 'WikiEditor-ModuleTools' ); }

if ( scripts.length ) { // Preload these common deps while the main scripts load mw.loader.load( [ 'user.options', 'ext.wikiEditor' ] );

var loc = function ( s ) { return 'ext.gadget.' + s;		};

// load all the scripts scripts .map( loc ) .forEach( function ( s ) {				mw.loader.load( s );			} ); } } );