Creation.js – MediaWiki

From Bohemia Interactive Community
Categories:
m (a missed Ctrl-Z later…)
(Add Sandbox support)
Line 17: Line 17:
link = button.getElementsByTagName("a")[0];
link = button.getElementsByTagName("a")[0];
link.removeAttribute("accesskey");
link.removeAttribute("accesskey");
link.setAttribute("title", "Preload a " + type + " guide for this creation");
link.setAttribute("title", "Use Template:Preload/" + type);
link.setAttribute("href", link.getAttribute("href") + "&preload=Template:Preload/" + type);
link.setAttribute("href", link.getAttribute("href") + "&preload=Template:Preload/" + type);
link.innerHTML = "Preload " + type + " template";
link.innerHTML = "Use a preload template";
createBar.appendChild(button);
createBar.appendChild(button);
}
}
switch (mw.config.get("wgCanonicalNamespace"))
var namespace = mw.config.get("wgCanonicalNamespace");
var pageTitle = mw.config.get("wgTitle");
 
switch (namespace)
{
{
case "Template":
case "Template":
Line 30: Line 33:


case "Category":
case "Category":
if (mw.config.get("wgTitle").startsWith("Introduced with ")) {
if (pageTitle.indexOf("Introduced with ") === 0) {
offerCreationPreload("IntroductionCategory");
offerCreationPreload("IntroductionCategory");
}
}
return;
return;


default:
default:
if (mw.config.get("wgTitle").indexOf("BIS fnc ") === 0 ||
if (pageTitle.indexOf("/Sandbox") === pageTitle.length - 8) {
mw.config.get("wgTitle").indexOf("BIN fnc ") === 0) {
offerCreationPreload("Sandbox");
return;
}
if (pageTitle.indexOf("BIS fnc ") === 0 ||
pageTitle.indexOf("BIN fnc ") === 0) {
offerCreationPreload("Function");
offerCreationPreload("Function");
} else {
} else {

Revision as of 04:47, 2 January 2021

/*****************************************************************************************
 * JavaScript here will be loaded by MediaWiki:Common.js when "creation" is detected.
 *
 *****************************************************************************************/

(function() { // BEGIN WRAPPER

	/*****************************************************************************************
	 * Function adding a UI feature that if used, preloads templates
	 * helpful during certain page creations.
	 * Maintainer: Lou Montana from Fred Gandt
	 */

		function offerCreationPreload(type) {
			var createBar = document.getElementById("ca-edit"),
				button = createBar.getElementsByTagName("span")[0].cloneNode(true),
				link = button.getElementsByTagName("a")[0];
			link.removeAttribute("accesskey");
			link.setAttribute("title", "Use Template:Preload/" + type);
			link.setAttribute("href", link.getAttribute("href") + "&preload=Template:Preload/" + type);
			link.innerHTML = "Use a preload template";
			createBar.appendChild(button);
		}
		
		var namespace = mw.config.get("wgCanonicalNamespace");
		var pageTitle = mw.config.get("wgTitle");

		switch (namespace)
		{
			case "Template":
				offerCreationPreload("Template");
				return;

			case "Category":
				if (pageTitle.indexOf("Introduced with ") === 0) {
					offerCreationPreload("IntroductionCategory");
				}
				return;

			default:				
				if (pageTitle.indexOf("/Sandbox") === pageTitle.length - 8) {
					offerCreationPreload("Sandbox");
					return;
				}
				if (pageTitle.indexOf("BIS fnc ") === 0 ||
					pageTitle.indexOf("BIN fnc ") === 0) {
					offerCreationPreload("Function");
				} else {
					offerCreationPreload("Command");
				}
				return;
		}

	/*****************************************************************************************/

	}()); // END WRAPPER