Creation.js – MediaWiki
Categories:
Lou Montana (talk | contribs) m (Fix detection imprecision) |
Lou Montana (talk | contribs) m (Fix attempt (cache issue on my side?)) |
||
| Line 28: | Line 28: | ||
switch (namespace) | switch (namespace) | ||
{ | { | ||
case " | case "": | ||
offerCreationPreload(" | if (pageTitle.indexOf("BIS fnc ") === 0 || | ||
pageTitle.indexOf("BIN fnc ") === 0) { | |||
offerCreationPreload("Function"); | |||
} else { | |||
offerCreationPreload("Command"); | |||
} | |||
return; | return; | ||
| Line 36: | Line 41: | ||
offerCreationPreload("IntroductionCategory"); | offerCreationPreload("IntroductionCategory"); | ||
} | } | ||
return; | |||
case "Template": | |||
offerCreationPreload("Template"); | |||
return; | return; | ||
| Line 48: | Line 57: | ||
} | } | ||
return; | return; | ||
default: | |||
return; | return; | ||
} | } | ||
Revision as of 05:36, 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 "":
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