Creation.js – MediaWiki
Categories:
Lou Montana (talk | contribs) m (Fix attempt) |
Lou Montana (talk | contribs) m (Fix User creation bug, finally!) |
||
| (10 intermediate revisions by the same user not shown) | |||
| Line 8: | Line 8: | ||
/***************************************************************************************** | /***************************************************************************************** | ||
* Function adding a UI feature that if used, preloads templates | * Function adding a UI feature that if used, preloads templates | ||
* | * helpful during certain page creations. | ||
* Maintainer: Lou Montana from Fred Gandt | * Maintainer: Lou Montana from Fred Gandt | ||
*/ | */ | ||
function offerCreationPreload(type) { | function offerCreationPreload(type) { | ||
var | var existingButton = document.getElementById("ca-edit"), | ||
newButton = existingButton.cloneNode(true), | |||
link = | link = newButton.getElementsByTagName("a")[0]; | ||
link.removeAttribute("accesskey"); | link.removeAttribute("accesskey"); | ||
link.setAttribute("title", "Preload | link.setAttribute("title", "Use Template:Preload/" + type); | ||
link.setAttribute("href", link.getAttribute("href") + "&preload=Template:" + type | link.setAttribute("href", link.getAttribute("href") + "&preload=Template:Preload/" + type); | ||
link.innerHTML = " | 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; | |||
} | } | ||
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