ผู้ใช้:Hi5dn/Common.js
หมายเหตุ: หลังเผยแพร่ คุณอาจต้องล้างแคชเว็บเบราว์เซอร์ของคุณเพื่อดูการเปลี่ยนแปลง
- ไฟร์ฟอกซ์ / ซาฟารี: กด Shift ค้างขณะคลิก Reload หรือกด Ctrl-F5 หรือ Ctrl-R (⌘-R บนแมค)
- กูเกิล โครม: กด Ctrl-Shift-R (⌘-Shift-R บนแมค)
- อินเทอร์เน็ตเอกซ์พลอเรอร์ และ Edge: กด Ctrl ค้างขณะคลิก Refresh หรือกด Ctrl-F5
- โอเปร่า: กด Ctrl-F5
/* Any JavaScript here will be loaded for all users on every page load. */
//<source lang="javascript">
/** IPNG Fix Module *************************************************************
*
* Description: Includes a raw wiki page as javascript or CSS,
* Correctly handle PNG transparency in Internet Explorer 6.
* http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006. Adapted for Wikipedia by Remember_the_dot and Edokter.
*
* Maintainers: [[user:Jutiphan]]
*/
function PngFix()
{
try
{
if (!document.body.filters)
{
window.PngFixDisabled = true;
}
}
catch (e)
{
window.PngFixDisabled = true;
}
if (!window.PngFixDisabled)
{
var documentImages = document.images;
var documentCreateElement = document.createElement;
var funcEncodeURI = encodeURI;
for (var i = 0; i < documentImages.length;)
{
var img = documentImages[i];
var imgSrc = img.src;
if (imgSrc.substr(imgSrc.length - 3).toLowerCase() == "png" && !img.onclick)
{
if (img.useMap)
{
img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + encodeURI(imgSrc) + "')";
img.src = "http://upload.wikimedia.org/wikipedia/commons/c/ce/Transparent.gif";
i++;
}
else
{
var outerSpan = documentCreateElement("span");
var innerSpan = documentCreateElement("span");
var outerSpanStyle = outerSpan.style;
var innerSpanStyle = innerSpan.style;
var imgCurrentStyle = img.currentStyle;
outerSpan.id = img.id;
outerSpan.className = img.className;
outerSpanStyle.backgroundImage = imgCurrentStyle.backgroundImage;
outerSpanStyle.borderWidth = imgCurrentStyle.borderWidth;
outerSpanStyle.borderStyle = imgCurrentStyle.borderStyle;
outerSpanStyle.borderColor = imgCurrentStyle.borderColor;
outerSpanStyle.display = "inline-block";
outerSpanStyle.fontSize = "0";
outerSpanStyle.verticalAlign = "middle";
if (img.parentElement.href) outerSpanStyle.cursor = "hand";
innerSpanStyle.width = "1px";
innerSpanStyle.height = "1px";
innerSpanStyle.display = "inline-block";
innerSpanStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + funcEncodeURI(imgSrc) + "')";
outerSpan.appendChild(innerSpan);
img.parentNode.replaceChild(outerSpan, img);
}
}
else
{
i++;
}
}
}
}
if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substr(22, 1) == "6")
{
window.attachEvent("onload", PngFix);
}
/** Import module *************************************************************
*
* Description: Includes a raw wiki page as javascript or CSS,
* used for including user made modules.
* Maintainers: [[:en:User:AzaToth]]
*/
importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
function importScript(page) {
if (importedScripts[page]) {
return;
}
importedScripts[page] = true;
var url = wgScriptPath
+ '/index.php?title='
+ encodeURIComponent(page.replace(' ', '_'))
+ '&action=raw&ctype=text/javascript';
var scriptElem = document.createElement('script');
scriptElem.setAttribute('src', url);
scriptElem.setAttribute('type', 'text/javascript');
document.getElementsByTagName('head')[0].appendChild(scriptElem);
}
function importStylesheet( page ) {
var sheet = '@import "'
+ wgScriptPath
+ '/index.php?title='
+ encodeURIComponent( page.replace( / /g, '_' ) )
+ '&action=raw&ctype=text/css";'
var styleElem = document.createElement( 'style' );
styleElem.setAttribute( 'type' , 'text/css' );
styleElem.appendChild( document.createTextNode( sheet ) );
document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
}
/* Test if an element has a certain class **************************************
*
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[:en:User:Mike Dillon]], [[:en:User:R. Koot]], [[:en:User:SG]]
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
/** Preview before save changes *************************************************************
*
* Description: Force IP to preview before saving changes.
* Copyright Marc Mongenet, 2006. Modified by Jutiphan to apply only article namespace
* Maintainers: [[User:Jutiphan]]
* Source [[mediawiki:Manual:Force preview]]
*/
function forcePreview() {
if (wgUserName != null || wgAction != "edit" || wgNamespaceNumber != 0) return;
saveButton = document.getElementById("wpSave");
if (!saveButton) return;
saveButton.disabled = true;
saveButton.value = "กรุณาดูตัวอย่างก่อนบันทึก";
saveButton.style.fontWeight = "normal";
saveButton.setAttribute('type', 'button');
saveButton.setAttribute('tabIndex', '99');
document.getElementById("wpPreview").style.fontWeight = "bold";
}
$(forcePreview);
/** "Technical restrictions" title fix *****************************************
*
* Description:
* Maintainers: [[:en:User:Interiot]], [[:en:User:Mets501]]
*/
// For pages that have something like Template:Lowercase, replace the title, but only if it is cut-and-pasteable as a valid wikilink.
// (for instance [[iPod]]'s title is updated. <nowiki>But [[C#]] is not an equivalent wikilink, so [[C Sharp]] doesn't have its main title changed)</nowiki>
//
// The function looks for a banner like this: <nowiki>
// <div id="RealTitleBanner"> <!-- div that gets hidden -->
// <span id="RealTitle">title</span>
// </div>
// </nowiki>An element with id=DisableRealTitle disables the function.
var disableRealTitle = 0; // users can disable this by making this true from their monobook.js
if (wgIsArticle) { // don't display the RealTitle when editing, since it is apparently inconsistent (doesn't show when editing sections, doesn't show when not previewing)
addOnloadHook(function() {
try {
var realTitleBanner = document.getElementById("RealTitleBanner");
if (realTitleBanner && !document.getElementById("DisableRealTitle") && !disableRealTitle) {
var realTitle = document.getElementById("RealTitle");
if (realTitle) {
var realTitleHTML = realTitle.innerHTML;
realTitleText = pickUpText(realTitle);
var isPasteable = 0;
//var containsHTML = /</.test(realTitleHTML); // contains ANY HTML
var containsTooMuchHTML = /</.test(realTitleHTML.replace(/<\/?(sub|sup|small|big)>/gi, "")); // contains HTML that will be ignored when cut-n-pasted as a wikilink
// calculate whether the title is pasteable
var verifyTitle = realTitleText.replace(/^ +/, ""); // trim left spaces
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
// if the namespace prefix is there, remove it on our verification copy. If it isn't there, add it to the original realValue copy.
if (wgNamespaceNumber != 0) {
if (wgCanonicalNamespace == verifyTitle.substr(0, wgCanonicalNamespace.length).replace(/ /g, "_") && verifyTitle.charAt(wgCanonicalNamespace.length) == ":") {
verifyTitle = verifyTitle.substr(wgCanonicalNamespace.length + 1);
} else {
realTitleText = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleText;
realTitleHTML = wgCanonicalNamespace.replace(/_/g, " ") + ":" + realTitleHTML;
}
}
// verify whether wgTitle matches
verifyTitle = verifyTitle.replace(/^ +/, "").replace(/ +$/, ""); // trim left and right spaces
verifyTitle = verifyTitle.replace(/_/g, " "); // underscores to spaces
verifyTitle = verifyTitle.charAt(0).toUpperCase() + verifyTitle.substring(1, verifyTitle.length); // uppercase first character
isPasteable = (verifyTitle == wgTitle);
var h1 = document.getElementsByTagName("h1")[0];
if (h1 && isPasteable) {
h1.innerHTML = containsTooMuchHTML ? realTitleText : realTitleHTML;
if (!containsTooMuchHTML)
realTitleBanner.style.display = "none";
}
document.title = realTitleText + " - วิกิพีเดีย";
}
}
} catch (e) {
/* Something went wrong. */
}
});
}
// similar to innerHTML, but only returns the text portions of the insides, excludes HTML
function pickUpText(aParentElement) {
var str = "";
function pickUpTextInternal(aElement) {
var child = aElement.firstChild;
while (child) {
if (child.nodeType == 1) // ELEMENT_NODE
pickUpTextInternal(child);
else if (child.nodeType == 3) // TEXT_NODE
str += child.nodeValue;
child = child.nextSibling;
}
}
pickUpTextInternal(aParentElement);
return str;
}
/** Interwiki links to featured articles ***************************************
*
* Description: Highlights interwiki links to featured articles (or
* equivalents) by changing the bullet before the interwiki link
* into a star.
* Maintainers: [[:en:User:R. Koot]]
* Added by : [[User:Jutiphan]]
*/
function LinkFA()
{
if (document.getElementById("p-lang")) {
var InterwikiLinks = document.getElementById("p-lang").getElementsByTagName("li");
for (var i = 0; i < InterwikiLinks.length; i++) {
if (document.getElementById(InterwikiLinks[i].className + "-fa")) {
InterwikiLinks[i].className += " FA";
InterwikiLinks[i].title = "บทความนี้เป็นบทความคัดสรรในภาษานี้";
}
}
}
}
$(LinkFA);
/** Change Special:Search to use a drop-down menu *******************************************************
*
* Description: Change Special:Search to use a drop-down menu, with the default being
* the internal MediaWiki engine
* Created and maintained by: [[User:Gracenotes]]
* Added by : [[User:Watcharakorn]]
*/
/* Special Search */
// Improvement of the search page v4
// Auteur : Marc Mongenet & Suisui
// Source licenced GFDL & GPL
function SpecialSearchEnhanced()
{
function SearchForm(engine_name, engine_url, logo_url, search_action_url,
search_field_name, add_search_field, field_array)
{
var span = document.createElement("span");
span.style.marginRight = "1em";
var form = document.createElement("form");
form.method = "get";
form.action = search_action_url;
form.style.display = "inline";
span.appendChild(form);
var input = document.createElement("input");
input.type = "hidden";
input.name = search_field_name;
form.appendChild(input);
for (var i in field_array) {
var fld = document.createElement("input");
fld.type = "hidden";
fld.name = i;
fld.value = field_array[i];
form.appendChild(fld);
}
var submit = document.createElement("input");
submit.type = "submit";
submit.value = "ค้นหา";
form.appendChild(submit);
form.onsubmit = function() {
if (add_search_field == "") {
input.value = document.getElementById("lsearchbox").value;
} else {
input.value = document.getElementById("lsearchbox").value + add_search_field;
}
};
var a = document.createElement("a");
a.href = engine_url;
span.appendChild(a);
var img = document.createElement("img");
img.src = logo_url;
img.alt = engine_name;
img.style.borderWidth = "0";
img.style.padding = "5px";
img.style.width = "135px";
img.style.height = "35px";
a.appendChild(img);
return span;
}
if (typeof SpecialSearchEnhancedDisabled != 'undefined') return;
if (wgCanonicalNamespace != "Special" || wgCanonicalSpecialPageName != "Search") return;
if (skin == "monobook" || skin == "cologneblue" || skin == "simple") {
var mainNode = document.getElementsByTagName("form");
}
if (!mainNode) return;
mainNode = mainNode[0];
mainNode.appendChild(document.createElement("center"));
mainNode = mainNode.lastChild;
var searchValue = document.getElementById("lsearchbox").value;
var div = document.createElement("div");
div.style.width = "100%";
// ul.style.list-style-type = "none";
mainNode.appendChild(div);
var engine;
var googleo = new Object();
googleo["as_sitesearch"] = "th.wikipedia.org";
engine = SearchForm("Google", "http://www.google.co.th/", "http://www.google.co.th/logos/powered_by_google_135x35.gif",
"http://www.google.co.th/search",
"q", "", googleo);
div.appendChild(engine);
var yahoojo = new Object();
yahoojo["vs"] = "th.wikipedia.org";
yahoojo["ei"] = "UTF-8";
engine = SearchForm("Yahoo!", "http://th.yahoo.com/", "http://sg.yimg.com/i/fp/ymh_sprt_th.gif",
"http://th.search.yahoo.com/search",
"p", "", yahoojo);
div.appendChild(engine);
var msliveo = new Object();
msliveo["q1"] = "site:th.wikipedia.org";
engine = SearchForm("Live", "http://search.live.com/", "http://upload.wikimedia.org/wikipedia/th/4/49/Windows-Live-Logo-135x35.png",
"http://search.live.com/results.aspx",
"q", "", msliveo);
div.appendChild(engine);
}
$(SpecialSearchEnhanced);
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[Wikipedia:NavFrame]].
* Maintainers: [[:en:User:R. Koot]]
* Added by: [[User:Jutiphan]]
*/
var autoCollapse = 2;
var collapseCaption = "ซ่อน";
var expandCaption = "แสดง";
function collapseTable(tableIndex)
{
var Button = document.getElementById("collapseButton" + tableIndex);
var Table = document.getElementById("collapsibleTable" + tableIndex);
if (!Table || !Button) {
return false;
}
var Rows = Table.getElementsByTagName("tr");
if (Button.firstChild.data == collapseCaption) {
for (var i = 1; i < Rows.length; i++) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for (var i = 1; i < Rows.length; i++) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}
function createCollapseButtons()
{
var tableIndex = 0;
var NavigationBoxes = new Object();
var Tables = document.getElementsByTagName("table");
for (var i = 0; i < Tables.length; i++) {
if (hasClass(Tables[i], "collapsible")) {
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute("id", "collapsibleTable" + tableIndex);
var Button = document.createElement("span");
var ButtonLink = document.createElement("a");
var ButtonText = document.createTextNode(collapseCaption);
Button.style.styleFloat = "right";
Button.style.cssFloat = "right";
Button.style.fontWeight = "normal";
Button.style.textAlign = "right";
Button.style.width = "6em";
ButtonLink.setAttribute("id", "collapseButton" + tableIndex);
ButtonLink.setAttribute("href", "javascript:collapseTable(" + tableIndex + ");");
ButtonLink.appendChild(ButtonText);
Button.appendChild(document.createTextNode("["));
Button.appendChild(ButtonLink);
Button.appendChild(document.createTextNode("]"));
var Header = Tables[i].getElementsByTagName("tr")[0].getElementsByTagName("th")[0];
/* only add button and increment count if there is a header row to work with */
if (Header) {
Header.insertBefore(Button, Header.childNodes[0]);
tableIndex++;
}
}
}
for (var i = 0; i < tableIndex; i++) {
if (hasClass(NavigationBoxes[i], "collapsed") || ( tableIndex >= autoCollapse && hasClass(NavigationBoxes[i], "autocollapse") )) {
collapseTable(i);
}
}
}
$(createCollapseButtons);
/** Dynamic Navigation Bars (experimental) *************************************
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
* Added by: [[User:Jutiphan]]
*/
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
// set up max count of Navigation Bars on page,
// if there are more, all will be hidden
// NavigationBarShowDefault = 0; // all bars will be hidden
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
var NavigationBarShowDefault = autoCollapse;
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
if (!NavFrame || !NavToggle) {
return false;
}
// if shown now
if (NavToggle.firstChild.data == NavigationBarHide) {
for (
var NavChild = NavFrame.firstChild;
NavChild != null;
NavChild = NavChild.nextSibling
) {
if (hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'none';
}
if (hasClass(NavChild, 'NavContent')) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if (NavToggle.firstChild.data == NavigationBarShow) {
for (
var NavChild = NavFrame.firstChild;
NavChild != null;
NavChild = NavChild.nextSibling
) {
if (hasClass(NavChild, 'NavPic')) {
NavChild.style.display = 'block';
}
if (hasClass(NavChild, 'NavContent')) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
var indexNavigationBar = 0;
// iterate over all < div >-elements
var divs = document.getElementsByTagName("div");
for (
var i = 0;
NavFrame = divs[i];
i++
) {
// if found a navigation bar
if (hasClass(NavFrame, "NavFrame")) {
indexNavigationBar++;
var NavToggle = document.createElement("a");
NavToggle.className = 'NavToggle';
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
var NavToggleText = document.createTextNode(NavigationBarHide);
NavToggle.appendChild(NavToggleText);
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for (
var j = 0;
j < NavFrame.childNodes.length;
j++
) {
if (hasClass(NavFrame.childNodes[j], "NavHead")) {
NavFrame.childNodes[j].appendChild(NavToggle);
}
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
}
// if more Navigation Bars found than Default: hide all
if (NavigationBarShowDefault < indexNavigationBar) {
for (
var i = 1;
i <= indexNavigationBar;
i++
) {
toggleNavigationBar(i);
}
}
}
$(createNavigationBarToggleButton);
/*
Caractères spéciaux
-------------------
Ajouter un menu pour choisir des sous-ensembles de caractères spéciaux.
Ecrit par Zelda, voir sur [[Utilisateur:Zelda/Edittools.js]].
Remplace l'ancienne fonction par une variante plus rapide.
*/
/**
* Ajoute un menu déroulant permettant de choisir un jeu de caractères spéciaux
* Les caractères spéciaux sont définis dans Mediawiki:Edittools
*/
function addCharSubsetMenu() {
var specialchars = document.getElementById('specialcharsets');
if (!specialchars) return;
// Construction du menu de selection
var charSubsetSelect = document.createElement("select");
charSubsetSelect.setAttribute("style", "display:inline");
charSubsetSelect.onchange = function () {
chooseCharSubset(this.selectedIndex);
};
// Ajout des options au menu
var p = document.getElementById('specialcharsets').getElementsByTagName('p');
for (var i = 0; i < p.length; i++) {
var opt = document.createElement("option");
var txt = document.createTextNode(p[i].title);
opt.appendChild(txt);
charSubsetSelect.appendChild(opt);
}
specialchars.insertBefore(charSubsetSelect, specialchars.childNodes[0]);
/* default subset - try to use a cookie some day */
chooseCharSubset(0);
}
/**
* Affichage du jeu de caractères sélectionné
*/
function chooseCharSubset(index) {
var p = document.getElementById('specialcharsets').getElementsByTagName('p');
for (var i = 0; i < p.length; i++) {
// Initialisation du jeu de caractères sélectionné
if (i == index) {
initializeCharSubset(p[i]);
}
// Affichage du jeu sélectionné, masquage des autres
p[i].style.display = i == index ? 'inline' : 'none';
p[i].style.visibility = i == index ? 'visible' : 'hidden';
}
}
/**
* Initialisation du jeu de caractères sélectionné
* Paramètre : paragraphe contenant le jeu à initialiser. Initialise tous les
* caractères contenus dans les sous-spans du paragraphe
*/
function initializeCharSubset(p) {
// recherche des sous-elements de type span à traiter
var spans = p.getElementsByTagName("span");
if (!spans) return;
// regexp pour echapper les caractères JS spéciaux : \ et '
var re = new RegExp("(\\\\|')", "g");
// gestion du caractère d'échappement '\'
var escapeRe = new RegExp("[^\\\\](\\\\\\\\)*\\\\$", "g");
var unescapeRe = new RegExp("\\\\\\\\", "g");
// traitement des spans du paragraphe
for (var j = 0; j < spans.length; j++) {
// span deja traité
if (spans[j].childNodes.length == 0 || spans[j].childNodes[0].nodeType != 3) continue;
// On parse le contenu du span
var chars = spans[j].childNodes[0].nodeValue.split(" ");
for (var k = 0; k < chars.length; k++) {
var a = document.createElement("a");
var tags = chars[k];
// regroupement des mots se terminant par un espace protégé par un \
while (k < chars.length && chars[k].match(escapeRe)) {
k++;
tags = tags.substr(0, tags.length - 1) + " " + chars[k];
}
// création du lien insertTag(tagBegin, tagEnd, defaultValue) en protegeant les caractères JS \ et '
tags = (tags.replace(unescapeRe, "\\")).split("+");
var tagBegin = tags[0].replace(re, "\\$1");
var tagEnd = tags.length > 1 ? tags[1].replace(re, "\\$1") : "";
var defaultValue = tags.length > 2 ? tags[2].replace(re, "\\$1") : "";
a.href = "javascript:insertTags('" + tagBegin + "','" + tagEnd + "', '" + defaultValue + "')";
//a.href="#";
//eval("a.onclick = function() { insertTags('" + tagBegin + "','" + tagEnd + "', '" + defaultValue + "'); return false; }");
a.appendChild(document.createTextNode((tagBegin + tagEnd).replace(unescapeRe, "\\")));
spans[j].appendChild(a);
spans[j].appendChild(document.createTextNode(" "));
}
// suppression de l'ancien contenu
spans[j].removeChild(spans[j].firstChild);
}
}
$(addCharSubsetMenu);
/**
* Permet d'ajouter d'un jeu de caractères spéciaux dans le menu déroulant
* paramètres :
* - nom du jeu de caractères
* - contenu HTML. Les caractères spéciaux doivent être dans des spans
* exemple : "caractères : <span>â ê î ô û</span>"
*/
function addSpecialCharsetHTML(title, charsHTML) {
var specialchars = document.getElementById('specialcharsets');
if (!specialchars) return;
// Ajout d'un nouvel item au menu déroulant
var select = specialchars.getElementsByTagName("select")[0];
var opt = document.createElement("option");
opt.appendChild(document.createTextNode(title));
select.appendChild(opt);
// Ajout des caractères spéciaux. Les liens seront initialisé par initializeCharSubset()
// lors de la sélection
var specialcharsets = document.getElementById('specialcharsets');
var p = document.createElement("p");
p.style.display = "none";
p.innerHTML = charsHTML;
specialcharsets.appendChild(p);
}
/**
* Permet d'ajouter d'un jeu de caractères spéciaux dans le menu déroulant
* paramètres :
* - nom du jeu de caractères
* - caractères spéciaux
* exemple d'utilisation : addSpecialCharset("Français", "â ê î ô û");
*/
function addSpecialCharset(title, chars) {
addSpecialCharsetHTML(title, "<span>" + chars + "</span>");
}
/**
* เปลี่ยนแท็บสเปซของ 'หน้าหลัก' จาก 'บทความ' เป็น 'หน้าหลัก'
*
* ต้นฉบับจาก http://en.wikipedia.org/wiki/MediaWiki:Common.js
*/
function mainPageRenameNamespaceTab() {
try {
var Node = document.getElementById('ca-nstab-main').firstChild;
if (Node.textContent) { // Per DOM Level 3
Node.textContent = 'หน้าหลัก';
} else if (Node.innerText) { // IE doesn't handle .textContent
Node.innerText = 'หน้าหลัก';
} else { // Fallback
Node.replaceChild(Node.firstChild, document.createTextNode('หน้าหลัก'));
}
} catch(e) {
// bailing out!
}
}
if (wgTitle == 'หน้าหลัก' && ( wgNamespaceNumber == 0 || wgNamespaceNumber == 1 )) {
addOnloadHook(mainPageRenameNamespaceTab);
}
if (wgTitle == 'หน้าหลัก' && wgNamespaceNumber == 0) {
addOnloadHook(mainPageAppendCompleteListLink);
}
function mainPageAppendCompleteListLink() {
mw.util.addPortletLink('p-lang', 'http://meta.wikimedia.org/wiki/List_of_Wikipedias',
'ทุกภาษา', 'รายการอินเตอร์วิกิ', 'รายการวิกิพีเดียทั้งหมด');
}
/* เริ่มคำสั่งที่จะทำให้ แม่แบบ:Metabox ทำงาน */
/*
สร้างโดย: [[:ca:Usuari:Peleguer]]
*/
function MetaBoxInit() {
//alert("MetaBoxInit");
var i = 0;
for (i = 0; i <= 9; i++) {
var vMb = document.getElementById("mb" + i);
if (!vMb) break;
//alert("MetaBoxInit, trobada Metacaixa mb"+i);
var j = 1;
var vTabIni = 0;
for (j = 1; j <= 9; j++) {
var vBt = document.getElementById("mb" + i + "bt" + j);
if (!vBt) break;
//alert("MetaBoxInit, trobat botó mb"+i+"bt"+j);
vBt.onclick = MetaBoxShowTab;
//alert (vBt.className);
if (vBt.className == "mbButtonSel") vTabIni = j;
}
//alert ("mb="+i+", ps="+j+", psini="+vTabIni );
if (vTabIni == 0) {
vTabIni = 1 + Math.floor((j - 1) * Math.random());
//alert ("Activant Pestanya a l'atzar; _mb"+i+"bt"+vTabIni +"_");
document.getElementById("mb" + i + "ps" + vTabIni).style.display = "block";
document.getElementById("mb" + i + "ps" + vTabIni).style.visibility = "visible";
document.getElementById("mb" + i + "bt" + vTabIni).className = "mbButtonSel";
}
}
}
function MetaBoxShowTab() {
var vMbName = this.id.substr(0, 3);
var vIndex = this.id.substr(5, 1);
var i = 1;
for (i = 1; i <= 9; i++) {
//alert(vMbName+"ps"+i);
var vTabItem = document.getElementById(vMbName + "ps" + i);
if (!vTabItem) break;
if (vIndex == i) {
vTabItem.style.display = "block";
vTabItem.style.visibility = "visible";
document.getElementById(vMbName + "bt" + i).className = "mbButtonSel";
} else {
vTabItem.style.display = "none";
vTabItem.style.visibility = "hidden";
document.getElementById(vMbName + "bt" + i).className = "mbButton";
}
}
return false;
}
$(MetaBoxInit);
/* จบคำสั่งที่จะทำให้ แม่แบบ:Metabox ทำงาน */
/** WikiMiniAtlas *******************************************************
*
* Description: WikiMiniAtlas is a popup click and drag world map.
* This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
* The script itself is located on meta because it is used by many projects.
* See [[Meta:WikiMiniAtlas]] for more information.
* Created by: [[User:Dschwen]]
*/
document.write('<script type="text/javascript" src="'
+ 'http://meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js'
+ '&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400"></script>');
/** extended createElement function *************************************
*
* Description: createElement function with additional params
* Added by: [[User:Jutiphan]]
* Maintainers: [[User:Jutiphan]]
* Source: http://zh.wikipedia.org/wiki/mediawiki:common.js
*/
function createElement(tag, children, props) {
var element = document.createElement(tag);
if (!(children instanceof Array)) {
children = [children];
}
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (typeof child == 'string') {
child = document.createTextNode(child);
}
if (child) {
element.appendChild(child);
}
}
if (typeof props == 'object') {
for (var k in props) {
switch (k) {
case 'styles':
var styles = props.styles;
for (var s in styles) {
element.style[s] = styles[s];
}
break;
case 'events':
var events = props.events;
for (var e in events) {
addHandler(element, e, events[e]);
}
break;
case 'class':
element.className = props[k];break;
case 'toJSONString':
break;
default:
element.setAttribute(k, props[k]);
}
}
}
return element;
}
//</source>