Creation.js – MediaWiki
Categories:
Lou Montana (talk | contribs) m (Fix attempt (cache issue on my side?)) |
Lou Montana (talk | contribs) m (Fix 1.35 theme update) |
||
| Line 13: | Line 13: | ||
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", "Use Template:Preload/" + type); | 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 = "Use a preload template"; | link.innerHTML = "Use a preload template"; | ||
existingButton.after(newButton); | |||
} | } | ||
Revision as of 18:14, 24 August 2022
/*****************************************************************************************
* 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":
if (pageTitle.indexOf("/Sandbox") === pageTitle.length - 8) {
offerCreationPreload("Sandbox");
return;
}
if (pageTitle.indexOf("/") === -1) {
offerCreationPreload("User");
return;
}
return;
default:
return;
}
/*****************************************************************************************/
}()); // END WRAPPER