Jump to content

User:Enterprisey/afch-master.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Updating AFCH: master @ 05e244
m Updating AFCH: master @ 05e244
Line 1: Line 1:
/* Uploaded from https://github.com/WPAFC/afch-rewrite, commit: 05e244d7beaf866e02e1bab828c4d8f9a6fb8578 (master) */
/* Uploaded from https://github.com/WPAFC/afch-rewrite, commit: 05e244d7beaf866e02e1bab828c4d8f9a6fb8578 (master) */
/* Uploaded from https://github.com/WPAFC/afch-rewrite, commit: cecd694a8e8a13ebd262afc1e1858905b9ccc67e (master) */
//<nowiki>
//<nowiki>
( function ( $, mw ) {
( function ( $, mw ) {
Line 33: Line 32:
return !!subscriptToLoad;
return !!subscriptToLoad;
} );
} );

// Special case: don't initialize submissions.js on
// Wikipedia:Articles for creation/Redirects, since that
// isn't a draft
if ( pageName === 'Wikipedia:Articles for creation/Redirects' ) {
subscriptToLoad = null;
}


if ( subscriptToLoad ) {
if ( subscriptToLoad ) {

Revision as of 16:58, 28 July 2018

/* Uploaded from https://github.com/WPAFC/afch-rewrite, commit: 05e244d7beaf866e02e1bab828c4d8f9a6fb8578 (master) */
//<nowiki>
( function ( $, mw ) {
	var subscriptToLoad = false,
		pageName = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ),

		// `loadMap` determines which scripts should be loaded
		// on each page. Each key is a subscript name and
		// its value is a list of page prefixes on which it
		// should be loaded.

		loadMap = {
			// `submissions.js` is for reviewing textual
			// Articles for Creation submissions.
			submissions: [
				'Wikipedia:Articles for creation/',
				'Wikipedia talk:Articles for creation/',
				'User:',
				'Draft:'
			]
		};

	$.each( loadMap, function ( script, prefixes ) {
		$.each( prefixes, function ( _, prefix ) {
			if ( pageName.indexOf( prefix ) === 0 ) {
				subscriptToLoad = script;
				return false;
			}
		} );

		// Return false and break out of the loop if already found
		return !!subscriptToLoad;
	} );

	// Special case: don't initialize submissions.js on
	// Wikipedia:Articles for creation/Redirects, since that
	// isn't a draft
	if ( pageName === 'Wikipedia:Articles for creation/Redirects' ) {
		subscriptToLoad = null;
	}

	if ( subscriptToLoad ) {
		// Initialize the AFCH object
		window.AFCH = {};

		// Set up constants
		AFCH.consts = {};

		// Master version data
		AFCH.consts.version = '0.9';
		AFCH.consts.versionName = 'Hatted Hamster';

		// FIXME: Change when moving into production
		AFCH.consts.beta = true;

		AFCH.consts.scriptpath = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' );
		AFCH.consts.baseurl = AFCH.consts.scriptpath +
			'?action=raw&ctype=text/javascript&title=User:Enterprisey/afch-master.js';

		$.getScript( AFCH.consts.baseurl + '/core.js' ).done( function () {
			var loaded = AFCH.load( subscriptToLoad );
			if ( !loaded ) {
				mw.notify( 'AFCH could not be loaded: ' + ( AFCH.error || 'unknown error' ),
					{ title: 'AFCH error' } );
			}
		} );
	}
}( jQuery, mediaWiki ) );
//</nowiki>