Creation.js – MediaWiki

From Bohemia Interactive Community
Categories:
(Created for conditional import by MediaWiki:Common.js)
 
m (Fix User creation bug, finally!)
 
(14 intermediate revisions by the same user not shown)
Line 3: Line 3:
  *
  *
  *****************************************************************************************/
  *****************************************************************************************/
 
(function() { // BEGIN WRAPPER
(function() { // BEGIN WRAPPER
/*****************************************************************************************
* Function adding a UI feature that if used, preloads templates
*  helpful during certain page creations.
* Maintainer: BIKI User:Fred Gandt
*/


function offerCreationPreload(pl) {
/*****************************************************************************************
var cb = document.getElementById("ca-edit"),
* Function adding a UI feature that if used, preloads templates
cbc = cb.getElementsByTagName("span")[0].cloneNode(true),
* helpful during certain page creations.
cbca = cbc.getElementsByTagName("a")[0];
* Maintainer: Lou Montana from Fred Gandt
cbca.removeAttribute("accesskey");
*/
cbca.setAttribute("title", "Preload a " + pl + " guide for this creation");
 
cbca.setAttribute("href", cbca.getAttribute("href") + "&preload=Template:" + pl + "/preload");
function offerCreationPreload(type) {
cbca.innerHTML = "Preload (<i style='color:green'>experimental</i>)";
var existingButton = document.getElementById("ca-edit"),
cb.appendChild(cbc);
newButton = existingButton.cloneNode(true),
}
link = newButton.getElementsByTagName("a")[0];
if (mw.config.get("wgCanonicalNamespace") === "Template") {
link.removeAttribute("accesskey");
offerCreationPreload("Template");
link.setAttribute("title", "Use Template:Preload/" + type);
} else if (mw.config.get("wgCanonicalNamespace") === "") {
link.setAttribute("href", link.getAttribute("href") + "&preload=Template:Preload/" + type);
if (mw.config.get("wgTitle").indexOf("BIS fnc ") === 0) {
link.innerHTML = "Use a preload template";
offerCreationPreload("Function");
existingButton.after(newButton);
} else {
offerCreationPreload("Command");
}
}
}
var namespace = mw.config.get("wgCanonicalNamespace");
/*****************************************************************************************/
var pageTitle = mw.config.get("wgTitle");
 
/*****************************************************************************************
switch (namespace)
* Next ***
{
*/
case "":
if (pageTitle.indexOf("BIS fnc ") === 0 ||
// code code code
pageTitle.indexOf("BIN fnc ") === 0) {
offerCreationPreload("Function");
/*****************************************************************************************/
} else {
offerCreationPreload("Command");
}
return;
 
case "Category":
if (pageTitle.indexOf("Introduced with ") === 0) {
offerCreationPreload("IntroductionCategory");
}
return;
 
case "Template":
offerCreationPreload("Template");
return;
 
case "User":
var index = pageTitle.indexOf("/Sandbox");
if (index > -1 && index === pageTitle.length - 8) {
offerCreationPreload("Sandbox");
return;
}
if (pageTitle.indexOf("/") === -1) {
offerCreationPreload("User");
return;
}
return;
 
default:
return;
}
 
/*****************************************************************************************/


}()); // END WRAPPER
}()); // END WRAPPER

Latest revision as of 13:02, 21 February 2024

/*****************************************************************************************
 * 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 existingButton = document.getElementById("ca-edit"),
				newButton = existingButton.cloneNode(true),
				link = newButton.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";
			existingButton.after(newButton);
		}
		
		var namespace = mw.config.get("wgCanonicalNamespace");
		var pageTitle = mw.config.get("wgTitle");

		switch (namespace)
		{
			case "":
				if (pageTitle.indexOf("BIS fnc ") === 0 ||
					pageTitle.indexOf("BIN fnc ") === 0) {
					offerCreationPreload("Function");
				} else {
					offerCreationPreload("Command");
				}
				return;

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

			case "Template":
				offerCreationPreload("Template");
				return;

			case "User":
				var index = pageTitle.indexOf("/Sandbox");
				if (index > -1 && index === pageTitle.length - 8) {
					offerCreationPreload("Sandbox");
					return;
				}
				if (pageTitle.indexOf("/") === -1) {
					offerCreationPreload("User");
					return;
				}
				return;

			default:
				return;
		}

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

	}()); // END WRAPPER