This is an archive copy of wikilivres.ca as of 18 February 2017 (from the WikiTeam dump). The original site is closed.
MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
imported>LaosLos test3: I'm going to revert this test immediately, don't worry ;) |
imported>LaosLos |
||
| Line 4: | Line 4: | ||
<pre>*/ | <pre>*/ | ||
function ongletCopyright() | |||
{ | |||
var a = document.getElementById("p-cactions"); | |||
if (a) | |||
{ | |||
b = a.getElementsByTagName("ul"); | |||
if(b.length > 0) | |||
{ | |||
if(document.getElementById("Creative Commons by-nc-sa")) | |||
{ b[0].innerHTML = b[0].innerHTML | |||
+ '<li id="ca-nstab-user">' | |||
+ '<a href="/wiki/Wikilivres:Creative Commons by-nc-sa">' | |||
+ 'License</a></li>'; | |||
} | |||
else if(document.getElementById("Copyright-ONU")) | |||
{ b[0].innerHTML = b[0].innerHTML | |||
+ '<li id="ca-nstab-user">' | |||
+ '<a href="/wiki/Wikilivres:Copyright-ONU">' | |||
+ 'License</a></li>'; | |||
} | |||
else if(document.getElementById("Copyright-UNESCO")) | |||
{ b[0].innerHTML = b[0].innerHTML | |||
+ '<li id="ca-nstab-user">' | |||
+ '<a href="/wiki/Wikilivres:Copyright-UNESCO">' | |||
+ 'License</a></li>'; | |||
} | |||
else if(document.getElementById("GFDL")) | |||
{ b[0].innerHTML = b[0].innerHTML | |||
+ '<li id="ca-nstab-user">' | |||
+ '<a href="/wiki/Wikilivres:Licence GFDL">' | |||
+ 'License</a></li>'; | |||
} | |||
} | |||
} | |||
} | |||
addOnloadHook(ongletCopyright); | |||
/* </pre> | /*</pre> | ||
=== | ===interwikiextra=== | ||
Auteur:ThomasV | |||
<pre>*/ | |||
function interwikiExtra() | |||
{ | |||
// iterate over all <span>-elements | |||
for(var i=0; a = document.getElementsByTagName("span")[i]; i++) { | |||
// if found a linkInfo span | |||
if(a.className == "interwiki-info") { | |||
// iterate over all <li>-elements | |||
var count=0; | |||
for(var j=0; b = document.getElementsByTagName("li")[j]; j++) { | |||
if(b.className == "interwiki-" + a.id) { | |||
b.innerHTML = b.innerHTML + " "+a.title; | |||
if(a.title == "(vo)") { b.title = "Texte original"; } | |||
} | |||
else if(b.className == "interwiki-" + a.id.substr(0,a.id.length-1)) { | |||
count = count+1; | |||
if(a.id.charAt(a.id.length-1) == count) { | |||
b.innerHTML = b.innerHTML + " "+a.title; | |||
} | |||
} | |||
} | |||
} | |||
if(a.className == "AutreVersion") { | |||
p = a.title.indexOf("|"); | |||
pvers = document.getElementById("p-version"); | |||
if (pvers == null) { | |||
c = document.getElementById("column-one"); | |||
c.innerHTML = c.innerHTML | |||
+ "<div class=\"portlet\" id=\"p-version\">" | |||
+ "<h5>Autres versions</h5>" | |||
+ "<div class=\"pBody\">" | |||
+ "<ul>" | |||
+ "</ul>" | |||
+ "</div>"; | |||
pvers = document.getElementById("p-version"); | |||
} | |||
e = pvers.getElementsByTagName("ul")[0]; | |||
e.innerHTML = e.innerHTML | |||
+ "<li class=\"\"><a href='" | |||
+ a.title.substr(0,p) | |||
+ "'>" + a.title.substr(p+1,a.title.length-1)+ "</a> " +"</li>"; | |||
} | |||
} | |||
} | |||
addOnloadHook(interwikiExtra); | |||
/*</pre> | |||
===Liens bilingues=== | |||
Fonctionne avec l'extension DoubleWiki. Auteur: ThomasV | |||
<pre>*/ | |||
function BilingualLink() | |||
{ | |||
if( wgNamespaceNumber != 0) return; | |||
var doc_url = document.URL; | |||
var url = ''; | |||
// iterate over all <li>-elements | |||
for(var j=0; b = document.getElementsByTagName("li")[j]; j++) { | |||
if(b.className.substring(0,10) == "interwiki-" ) { | |||
var lang = b.className.substring(10,b.className.length); | |||
if( doc_url.indexOf('?title=') != -1 ) { | |||
var qm = doc_url.indexOf('&match='); | |||
if( qm != -1 ) url = doc_url.substring(0,qm)+"&match="+lang; | |||
else url = doc_url+"&match="+lang; | |||
} else { | |||
var qm = doc_url.indexOf('?'); | |||
if( qm != -1 ) url = doc_url.substring(0,qm)+"?match="+lang; | |||
else url = doc_url+"?match="+lang; | |||
} | |||
b.innerHTML = b.innerHTML+"<a href='"+url+"'> ⇔</a>"; | |||
} | |||
} | |||
} | |||
addOnloadHook(BilingualLink); | |||
/*</pre> | |||
===Edittools=== | |||
<pre>*/ | |||
/* add menu for selecting subsets of secial characters */ | |||
/***** must match MediaWiki:Edittools *****/ | |||
function addCharSubsetMenu() { | |||
var specialchars = document.getElementById('specialchars'); | |||
if (specialchars) { | |||
var menu = "<select style=\"display:inline\" onChange=\"chooseCharSubset(selectedIndex)\">"; | |||
menu += "<option>Wiki</option>"; | |||
menu += "<option>Latin/Romain</option>"; | |||
menu += "<option>Grec</option>"; | |||
menu += "<option>Cyrillique</option>"; | |||
menu += "<option>AHD</option>"; | |||
menu += "<option>Allemand</option>"; | |||
menu += "<option>Catalan</option>"; | |||
menu += "<option>Croate</option>"; | |||
menu += "<option>Espagnol</option>"; | |||
menu += "<option>Espéranto</option>"; | |||
menu += "<option>Estonien</option>"; | |||
menu += "<option>Gallois</option>"; | |||
menu += "<option>Hawaien</option>"; | |||
menu += "<option>Hiéroglyphe</option>"; | |||
menu += "<option>Islandais</option>"; | |||
menu += "<option>Italien</option>"; | |||
menu += "<option>Maltais</option>"; | |||
menu += "<option>Pinyin</option>"; | |||
menu += "<option>Polonais</option>"; | |||
menu += "<option>Portugais</option>"; | |||
menu += "<option>Rōmaji</option>"; | |||
menu += "<option>Roumain</option>"; | |||
menu += "<option>Scandinave</option>"; | |||
menu += "<option>Serbe</option>"; | |||
menu += "<option>Tchèque</option>"; | |||
menu += "<option>Vieil anglais</option>"; | |||
menu += "<option>Vietnamien</option>"; | |||
menu += "</select>"; | |||
specialchars.innerHTML = menu + specialchars.innerHTML; | |||
/* default subset - try to use a cookie some day */ | |||
chooseCharSubset(0); | |||
} | |||
} | |||
/* select subsection of special characters */ | |||
function chooseCharSubset(s) { | |||
var l = document.getElementById('specialchars').getElementsByTagName('p'); | |||
for (var i = 0; i < l.length ; i++) { | |||
l[i].style.display = i == s ? 'inline' : 'none'; | |||
l[i].style.visibility = i == s ? 'visible' : 'hidden'; | |||
} | |||
} | |||
addOnloadHook(addCharSubsetMenu); | |||
/****************************************/ | |||
function mwInsertEditButton(parent, item) { | |||
var image = document.createElement("img"); | |||
image.width = 23; | |||
image.height = 22; | |||
image.src = item.imageFile; | |||
image.border = 0; | |||
image.style.cursor = "pointer"; | |||
var ref = document.createElement("a") | |||
ref.setAttribute("href", "javascript:insertTags(\"" + item.tagOpen + "\",\"" + item.tagClose + "\",\"" + item.sampleText + "\");") | |||
ref.setAttribute("title", item.speedTip); | |||
ref.appendChild(image); | |||
parent.appendChild(ref); | |||
} | |||
/*</pre> | |||
===Générateur de tableaux=== | |||
<pre>*/ | |||
/** | |||
* | |||
* English: Generate an array using Mediawiki syntax | |||
* | |||
* @author: fr:user:dake | |||
* @version: 0.1 | |||
*/ | |||
function generateTableau(nbCol, nbRow, border, styleHeader, styleLine) | |||
{ | |||
var code = "\n"; | |||
if (styleHeader==1) { | |||
code += '{{entête tableau charte}}\n'; | |||
} else { | |||
code += '{| border="' + border + '"\n'; | |||
code += '|+ Titre du tableau\n'; | |||
} | |||
for (var i=0;i<nbCol;i++) code += '! en-tête ' + i + '\n' | |||
for (var j=0;j<nbRow;j++) { | |||
if ((j+1)%2==0 && styleLine==1) { | |||
code += '|-{'+'{ligne grise}'+'}\n' | |||
} else { | |||
code += '|-----\n' | |||
} | |||
for (var i=0;i<nbCol;i++) code += '| élément\n'; | |||
} | |||
code += '|}'; | |||
insertTags('','', code); | |||
} | |||
/** | |||
* | |||
* English: Open a popup with parameters to generate an array. | |||
* The number of rows/columns can be modified. Some additional | |||
* parameters are related to templates available on :fr | |||
* | |||
* @author: fr:user:dake | |||
* @version: 0.1 | |||
*/ | |||
function popupTableau() | |||
{ | |||
var popup = window.open('','name','height=400,width=500'); | |||
javaCode = '<script type="text\/javascript">function insertCode(){'; | |||
javaCode += 'var row = parseInt(document.paramForm.inputRow.value); ' | |||
javaCode += 'var col = parseInt(document.paramForm.inputCol.value); ' | |||
javaCode += 'var bord = parseInt(document.paramForm.inputBorder.value); ' | |||
javaCode += 'var styleHeader = document.paramForm.inputHeader.checked; ' | |||
javaCode += 'var styleLine = document.paramForm.inputLine.checked; ' | |||
javaCode += 'window.opener.generateTableau(col,row,bord,styleHeader,styleLine); ' | |||
javaCode += '}<\/script>'; | |||
popup.document.write('<html><head><title>Paramètres du tableau</title>'); | |||
popup.document.write('<script type="text\/javascript" src="\/skins-1.5\/common\/wikibits.js"><!-- wikibits js --><\/script>'); | |||
popup.document.write('<style type="text\/css" media="screen,projection">/*<![CDATA[*/ @import "\/skins-1.5\/monobook\/main.css?5"; /*]]>*/<\/style>'); | |||
popup.document.write(javaCode); | |||
popup.document.write('</head><body>'); | |||
popup.document.write('<p>Veuillez entrer les paramètres du tableau : </p>'); | |||
popup.document.write('<form name="paramForm">'); | |||
popup.document.write('Nombre de lignes : <input type="text" name="inputRow" value="3" ><p>'); | |||
popup.document.write('Nombre de colonnes : <input type="text" name="inputCol" value="3" ><p>'); | |||
popup.document.write('Largeur de la bordure : <input type="text" name="inputBorder" value="1" ><p>'); | |||
popup.document.write('En-tête en gris (style « charte graphique ») : <input type="checkbox" name="inputHeader" checked="1" ><p>'); | |||
popup.document.write('Lignes grises alternées (style « charte graphique ») : <input type="checkbox" name="inputLine" checked="1" ><p>'); | |||
popup.document.write('</form">'); | |||
popup.document.write('<p><a href="javascript:insertCode()"> Insérer le code dans la fenêtre d\'édition</a></p>'); | |||
popup.document.write('<p><a href="javascript:self.close()"> Fermer</a></p>'); | |||
popup.document.write('</body></html>'); | |||
popup.document.close(); | |||
} | |||
/*</pre> | |||
===Insertion de nouveaux boutons dans la barre d'outil=== | |||
<pre>*/ | |||
// Début du code pour le modèle interprojet (codice adattato da de:wikt:Mediawiki:monobook.js) | |||
document.write('<style type="text/css">#interProject {display: none; speak: none;} #p-tb .pBody {padding-right: 0;}<\/style>'); | |||
function iProject() { | |||
if (document.getElementById("interProject")) { | |||
var iProject = document.getElementById("interProject").innerHTML; | |||
var interProject = document.createElement("div"); | |||
interProject.style.marginTop = "0.7em"; | |||
interProject.innerHTML = '<h5>compléments<\/h5><div class="pBody">'+iProject+'<\/div>'; | |||
document.getElementById("p-tb").appendChild(interProject); | |||
} | |||
} | |||
hookEvent("load", iProject); | |||
// fin du code pour l'interprojet | |||
//============================================================ | |||
// Insertion de nouveaux boutons dans la barre d'outil | |||
//============================================================ | |||
//Remplit la variable mwCustomEditButtons (voir /skins-1.5/commons/wikibits.js) pour ajouter des boutons à la barre d'outils | |||
function addCustomButton(imageFile, speedTip, tagOpen, tagClose, sampleText) | |||
{ | |||
mwCustomEditButtons[mwCustomEditButtons.length] = | |||
{"imageFile": imageFile, | |||
"speedTip": speedTip, | |||
"tagOpen": tagOpen, | |||
"tagClose": tagClose, | |||
"sampleText": sampleText}; | |||
} | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/3/30/Btn_toolbar_rayer.png','Rayer','<s>','</s>',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/8/88/Btn_toolbar_enum.png','Énumération','\\n# élément 1\\n# élément 2\\n# élément 3','',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/1/11/Btn_toolbar_liste.png','Liste','\\n* élément A\\n* élément B\\n* élément C','',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/8/8f/Button_poeme.png','Poésie','<poem>\\n\\n','\\n</poem>',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/9/9e/Btn_toolbar_gallery.png','Galerie Photo','<gallery>\\n','\\n</gallery>',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/3/37/Btn_toolbar_commentaire.png','Commentaire','<!--','-->','Insérer votre commentaire'); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/c/c8/Button_redirect.png','Redirection','#REDIRECT \[\[','\]\]','nom de la destination'); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/b/b4/Button_category03.png','Catégorie','\[\[Catégorie:','\]\]','nom de la catégorie'); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/en/5/5f/Button_center.png','Texte centré','<div style="text-align: center;">','</div>',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/en/e/e9/Button_headline2.png','paragraphe niveau 3','===','===',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/en/8/8e/Button_shifting.png', 'Insérer un retrait',':','',':' ); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/en/5/58/Button_small.png','Texte plus petit','<small>','</small>',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png','Exposant','<sup>','</sup>',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/4/4b/Button_nbsp.png','Espace insécable',' \;','',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/en/9/93/Button_sub_link.png','Lien vers sous-titre','\[\[Page\#','\]\]','Sub_page' ); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png','Block quote','<blockquote style="border: 1px solid blue; padding: 2em;">\\n','\\n</blockquote>','Block quote'); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png','Aller à la ligne','<br />','',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/4/4b/Button_class_text.png', 'Paragraphe texte','<div class=text>\\n\\n','\\n</div>',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/7/78/Button_titre.png','Titre de page','\{\{Titre\|','\|\|\}\}',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/0/03/Button_chapitre.png','Titre de Chapitre','\{\{chapitre\|livre=','\|auteur=\|nrpartie=\|nrchapitre=\|TitreChapitre=\|commentaires=\}\}',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/a/a0/Button_references_alt.png','Ajoute une référence','<ref>','</ref>',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/9/9a/Button_references.png','Liste des références','<references />','',''); | |||
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/c/c3/Button_travaux.png','Relecture','\{\{subst:Infoédit\|1=','\|2= \|3= \|4= \|5= \|6= \}\}',''); | |||
//Ressemble à la fonction de /skins-1.5/commons/wikibits.js pour insérer un autre lien que insertTags | |||
function marque_tab() | |||
{ | |||
var toolbar = document.getElementById('toolbar'); | |||
if (!toolbar) return false; | |||
var textbox = document.getElementById('wpTextbox1'); | |||
if (!textbox) return false; | |||
if (!document.selection && textbox.selectionStart == null) | |||
return false; | |||
var image = document.createElement("img"); | |||
image.width = 23; | |||
image.height = 22; | |||
image.src = 'http://upload.wikimedia.org/wikipedia/fr/0/04/Button_array.png'; | |||
image.border = 0; | |||
image.alt = 'Tableau'; | |||
image.title = 'Tableau'; | |||
image.style.cursor = "pointer"; | |||
image.onclick = function() { | |||
popupTableau(); | |||
return false; | |||
} | |||
toolbar.appendChild(image); | |||
} | |||
addOnloadHook(marque_tab); | |||
/*</pre> | |||
</div> | |||
===Options d'affichage=== | |||
Voir [[:Modèle:Option]]. Auteur:ThomasV | |||
<pre>*/ | |||
//Cookies | |||
function SetCookie(name,value) { | |||
document.cookie = name + "=" + escape(value); | |||
} | |||
function GetCookie(name) { | |||
var i =0; | |||
while (i < document.cookie.length) { | |||
if (document.cookie.substr(i,name.length) == name) { | |||
var valend = document.cookie.indexOf(";",i+name.length+1); | |||
if (valend == -1) { | |||
valend = document.cookie.length; | |||
} | |||
return unescape(document.cookie.substring(i+name.length+1,valend)); | |||
} | |||
i = document.cookie.indexOf(" ", i) + 1; | |||
if (i == 0) break; | |||
} | |||
} | |||
function OptionText() { | |||
var indexNavigationBar = 0; | |||
// iterate over all < span >-elements until class "OptionText" is found | |||
for( | |||
var i=0; | |||
SpanElem = document.getElementsByTagName("span")[i]; | |||
i++ | |||
) { | |||
// if found an option span | |||
if (SpanElem.className == "OptionText") { | |||
//SpanElem.style.display = 'none'; | |||
OptionTitle = SpanElem.title; | |||
OptionStyle = SpanElem.firstChild.getAttribute('style'); | |||
//check if option was already encountered... | |||
if(!document.getElementById(OptionTitle)){ | |||
//read cookie | |||
var DisplayOptionDefault = true; | |||
CookieDisplayOption = GetCookie ("Display"+OptionTitle) | |||
if (CookieDisplayOption ) { | |||
if (CookieDisplayOption == "false") DisplayOptionDefault = false; } | |||
var PageDisplay = document.createElement("li"); | |||
PageDisplay.setAttribute('id', OptionTitle); | |||
var PageDisplayLink = document.createElement("a"); | |||
OptionText = document.createTextNode("Désactiver "+OptionTitle); | |||
PageDisplayLink.appendChild(OptionText); | |||
PageDisplayLink.setAttribute('href','javascript:displayOptionText("'+OptionTitle+'","' + OptionStyle +'", '+DisplayOptionDefault+');'); | |||
PageDisplay.appendChild(PageDisplayLink); | |||
var optlist = document.getElementById("optlist"); | |||
if(!optlist) { | |||
var displayOptions = document.createElement("div"); | |||
displayOptions.style.marginTop = "0.7em"; | |||
displayOptions.innerHTML = '<h5>options d’affichage<\/h5><div class="pBody"><ul id="optlist"></ul><\/div>'; | |||
document.getElementById("p-tb").appendChild(displayOptions); | |||
optlist = document.getElementById("optlist"); | |||
} | |||
optlist.appendChild(PageDisplay); | |||
displayOptionText(OptionTitle,OptionStyle,DisplayOptionDefault); | |||
} | |||
} | |||
} | |||
} | |||
function displayOptionText(optiontitle, optionstyle, bool) { | |||
SetCookie ("Display"+optiontitle,bool); | |||
var PageDisplayLink = document.getElementById(optiontitle).firstChild;; | |||
// iterate over all < span >-elements | |||
for( | |||
var i=0; | |||
SpanElem = document.getElementsByTagName("span")[i]; | |||
i++ | |||
) { | |||
// if found an option text | |||
if ((SpanElem.className == "OptionText") && (SpanElem.title == optiontitle)) { | |||
if(bool==true ) { | |||
SpanElem.setAttribute('style',optionstyle); | |||
PageDisplayLink.firstChild.data = (optiontitle); | |||
PageDisplayLink.setAttribute('href', 'javascript:displayOptionText("'+optiontitle+'","'+optionstyle+'", false);'); | |||
} | |||
if(bool==false) { | |||
SpanElem.setAttribute('style','null'); | |||
PageDisplayLink.firstChild.data = (optiontitle); | |||
PageDisplayLink.setAttribute('href', 'javascript:displayOptionText("'+optiontitle+'","'+optionstyle+'", true);'); | |||
} | |||
} | |||
} | |||
} | |||
addOnloadHook(OptionText); | |||
function loadImage(ImageSrc,id){ | |||
var d = document.getElementById(id); | |||
//if(d.firstChild){d.removeChild(d.firstChild);} | |||
d.firstChild.setAttribute('href', 'javascript:hideImage("'+ImageSrc+'", "'+id+'");'); | |||
d.firstChild.setAttribute('title', 'cacher'); | |||
d.firstChild.innerHTML='[-]'; | |||
var newimg = document.createElement("img"); | |||
//newimg.setAttribute("src", "/wiki/index.php/Special:Filepath/"+ImageSrc.substring(6)); | |||
newimg.setAttribute("src", "/w/thumb.php?f="+ImageSrc.substring(6)+"&w=650"); | |||
newimg.setAttribute("alt", "image not found : "+ImageSrc.substring(6)); | |||
newimg.setAttribute("id", "img2"); | |||
d.appendChild(newimg); | |||
} | |||
function hideImage(ImageSrc,id){ | |||
var d = document.getElementById(id); | |||
d.firstChild.setAttribute('href', 'javascript:loadImage("'+ImageSrc+'", "'+id+'");'); | |||
d.firstChild.setAttribute('title', 'montrer'); | |||
d.firstChild.innerHTML='[+]'; | |||
d.removeChild(d.lastChild); | |||
} | |||
function onclickImages() { | |||
// iterate over all < span >-elements | |||
for( | |||
var i=0; | |||
spanElem = document.getElementsByTagName("span")[i]; | |||
i++ | |||
) { | |||
if (spanElem.className == "onclickImage") { | |||
spanElem.setAttribute('id', 'onclick'+i); | |||
title = spanElem.firstChild.getAttribute('title'); | |||
spanElem.firstChild.setAttribute('href', 'javascript:loadImage("'+title+'", "onclick'+i+'");'); | |||
spanElem.firstChild.innerHTML='[+]'; | |||
spanElem.firstChild.setAttribute('title', 'montrer'); | |||
} | |||
} | |||
} | |||
addOnloadHook(onclickImages); | |||
/********************** | /********************** | ||
| Line 19: | Line 533: | ||
var src=''; | var src=''; | ||
switch(t){ | switch(t){ | ||
case "0%": src='http://wikilivres.info/wiki/ | case "0%": src='http://wikilivres.info/wiki/index.php/Special:Filepath/00%25.png'; break; | ||
case "25%": src='http://wikilivres.info/wiki/ | case "25%": src='http://wikilivres.info/wiki/index.php/Special:Filepath/25%25.png'; break; | ||
case "50%": src='http://wikilivres.info/wiki/ | case "50%": src='http://wikilivres.info/wiki/index.php/Special:Filepath/50%25.png'; break; | ||
case "75%": src='http://wikilivres.info/wiki/ | case "75%": src='http://wikilivres.info/wiki/index.php/Special:Filepath/75%25.png'; break; | ||
case "100%": src='http://wikilivres.info/wiki/ | case "100%": src='http://wikilivres.info/wiki/index.php/Special:Filepath/100%25.png'; break; | ||
} | } | ||
return src; | return src; | ||
} | } | ||
function | function pageQuality() { | ||
var a = document.getElementById("ca-nstab-main"); | var a = document.getElementById("ca-nstab-main"); | ||
if(!a) return; | if(!a) return; | ||
var q = document.getElementById("textquality") | |||
if(q) { | |||
var new_img = document.createElement("img"); | |||
new_img.setAttribute("src", icon_src(q.className)); | |||
a.firstChild.appendChild(new_img); | |||
} | |||
for(var i=0; spanElem = document.getElementsByTagName("span")[i]; i++) { | |||
if (spanElem.className == "pagequality") { | |||
var new_img = document.createElement("img"); | |||
new_img.setAttribute("src", icon_src(spanElem.title)); | |||
if(wgCanonicalNamespace == "Page") { | |||
a.firstChild.appendChild(new_img); | |||
} | |||
else { | |||
s1 = spanElem.parentNode.previousSibling; | |||
opttext = s1.firstChild.firstChild; | |||
img = opttext.firstChild.nextSibling.nextSibling.nextSibling; | |||
next = img.nextSibling; | |||
opttext.removeChild(img); | |||
opttext.insertBefore(new_img,next); | |||
} | |||
} | |||
} | |||
} | |||
addOnloadHook(pageQuality); | |||
var q = document.getElementById("textquality") | /* Script from fr.ws replaced by script from en.ws */ | ||
if(q) { | /* | ||
function textQuality() { | |||
if(wgAction!='view' && wgAction!='submit' && wgAction!='purge') return; | |||
if(wgCanonicalNamespace != "") return; | |||
if( document.getElementById("Author") ) { a.firstChild.innerHTML = "Auteur"; return;} | |||
if(wgPageName.substring(0,8) == "Portail:") return; | |||
var a = document.getElementById("ca-nstab-main"); if(!a) return; | |||
var q = document.getElementById("textquality") | |||
if( q ) { | |||
var t = q.className; | |||
var new_img = document.createElement("img"); | var new_img = document.createElement("img"); | ||
new_img.setAttribute("src", | if(t == 'Textes validés') new_img.setAttribute("src", "http://www.wikilivres.info/wiki/images/b/b7/Etoile.png"); | ||
else new_img.setAttribute("src", "/wiki/index.php/Special:Filepath/"+t.substring(0,t.length-1)+'%25.png'); | |||
new_img.setAttribute("title", "état d'avancement: "+t.substring(0,t.length-1)+'%'); | |||
a.firstChild.appendChild(new_img); | a.firstChild.appendChild(new_img); | ||
} | |||
var q = document.getElementById("pr_index") | |||
if( q ) { | |||
href = q.firstChild; if(!href) return; | |||
q.removeChild(href); | |||
href.innerHTML = "<img src='http://www.wikilivres.info/wiki/images/d/df/Livre.png' />"; | |||
href.setAttribute("title", "Voir la liste des pages et participer à la correction de ce livre"); | |||
var new_li = document.createElement("li"); | |||
new_li.appendChild(href); | |||
a.parentNode.insertBefore(new_li,a.nextSibling); | |||
} | |||
else { | |||
if( ! document.getElementById("pr_page")) { | |||
var c = document.getElementById("contentSub"); | |||
c.innerHTML = c.innerHTML + "<span></span>"; | |||
} | |||
} | } | ||
} | } | ||
addOnloadHook(textQuality); | addOnloadHook(textQuality); | ||
*/ | |||
/********************** | /********************** | ||
| Line 49: | Line 623: | ||
**********************/ | **********************/ | ||
if( | function addQuality(form,value){ | ||
var text=""; | |||
switch(value){ | |||
//these should be the same as in template:textquality, etc. | |||
case "25%": text = "Incomplete text"; break; | |||
case "50%": text = "Complete text"; break; | |||
case "75%": text = "Correct typography and layout"; break; | |||
case "100%": text = "Proofread"; break; | |||
} | |||
form.elements["wpSummary"].value="/* "+text+" */"; | |||
if(wgCanonicalNamespace == "Page") { | |||
s = form.elements["headerTextbox"].value; | |||
s = s.replace(/\{\{PageQuality\|(.*?)\}\}/gi,"") | |||
form.elements["headerTextbox"].value="{"+"{PageQuality|"+value+"}"+"}"+s; | |||
} | |||
else { | |||
s = form.elements["wpTextbox1"].value; | |||
s = s.replace(/\{\{TextQuality\|(.*?)\}\}/gi,"") | |||
form.elements["wpTextbox1"].value="{"+"{TextQuality|"+value+"}"+"}"+s; | |||
} | |||
} | |||
function addQualityButtons(){ | |||
if( wgNamespaceNumber != 0) { | |||
return; | |||
} | |||
var ig = document.getElementById("wpWatchthis"); | |||
if(ig) { | |||
var f = document.createElement("span"); | |||
f.innerHTML = ' <input type="radio" name="quality" value="25%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/index.php/Special:Filepath/25%25.png">'+'<input type="radio" name="quality" value="50%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/index.php/Special:Filepath/50%25.png">'+'<input type="radio" name="quality" value="75%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/index.php/Special:Filepath/75%25.png">'+'<input type="radio" name="quality" value="100%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/index.php/Special:Filepath/100%25.png"><a href="http://www.wikilivres.info/wiki/index.php/Help:Contents#Quality_notation">Text advancement</a>'; | |||
ig.parentNode.insertBefore(f,ig.nextSibling.nextSibling.nextSibling) | |||
} | |||
} | |||
addOnloadHook(addQualityButtons); | |||
/* </pre> */ | |||
==Chinese converter == | |||
/* | |||
所有用戶在加載任何頁面時,這裡的JavaScript都會加載 | |||
=== 辅助处理 === | |||
<pre> | |||
*/ | |||
//功能設定 | |||
if(!window.JSConfig){var JSConfig={};} | |||
JSConfig.collapseText=wgULS('隐藏▲','隱藏▲');//指示折叠收缩的默认文字 | |||
JSConfig.expandText=wgULS('显示▼','顯示▼');//指示折叠展开的默认文字 | |||
JSConfig.autoCollapse=2; //文章少于 autoCollapse 个折叠块时,不自动折叠 | |||
JSConfig.SpecialSearchEnhancedDisabled=false; //是否禁止增加其它搜索引擎 | |||
function forEach(callback,array){ | |||
var i=0,j=array.length; | |||
while(i<j){callback(array[i++]);} | |||
} | |||
// 移動元素 | |||
function elementMoveto(node, refNode, pos){//默认位置为refNode前 | |||
if(node && refNode){ | |||
var parent=refNode.parentNode; | |||
if (pos && pos=='after') {refNode=refNode.nextSibling;} | |||
try { | |||
if(refNode){ | |||
parent.insertBefore(node, refNode); | |||
}else{ | |||
parent.appendChild(node); | |||
} | |||
} catch (DOMException) {}; | |||
} | |||
} | |||
//创建元素 | |||
function createElement(tag,children,props){ | |||
var element = document.createElement(tag); | |||
if(!(children instanceof Array)){children=[children];} | |||
forEach(function(child){ | |||
if(typeof child=='string'){child=document.createTextNode(child);} | |||
if(child){element.appendChild(child);} | |||
},children); | |||
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; | |||
default: | |||
element.setAttribute(k,props[k]); | |||
} | |||
} | |||
} | |||
return element; | |||
} | |||
//wiki URL | |||
var wgProjectURL={ | |||
en:'http://en.wikipedia.org',de:'http://de.wikipedia.org',fr:'http://fr.wikipedia.org', | |||
pl:'http://pl.wikipedia.org',ja:'http://ja.wikipedia.org',it:'http://it.wikipedia.org', | |||
nl:'http://nl.wikipedia.org',pt:'http://pt.wikipedia.org',es:'http://es.wikipedia.org', | |||
sv:'http://sv.wikipedia.org',//僅列前十名其它語言百科 | |||
m:'http://meta.wikimedia.org',b:'http://zh.wikibooks.org',q:'http://zh.wikiquote.org', | |||
n:'http://zh.wikinews.org',wikt:'http://zh.wiktionary.org',mw:'http://www.mediawiki.org', | |||
commons:'http://commons.wikimedia.org' | |||
} | |||
/** | |||
* 将页面名称转换为URL | |||
* | |||
* @param page 页面名称 | |||
* @param paras 附加后缀对象,用空对象{}做参数可以取得源码 | |||
*/ | |||
function getWikiPath(page,paras){ | |||
var reg=/^[a-z]+:/; | |||
var pre=page.match(reg); | |||
pre = pre && wgProjectURL[pre[0].replace(/:$/,'').toLowerCase()]; | |||
if (pre) {page=page.replace(reg,'');} else {pre=wgServer;} //保障没有相对路径,以照顾在线代理。 | |||
var url = pre + wgScript + '?title=' + encodeURI( page.replace( ' ', '_' ) ); | |||
if(typeof paras=='object'){ | |||
paras.ctype=paras.ctype||'text'; | |||
paras.dontcountme=paras.dontcountme||'s'; | |||
paras.action=paras.action||'raw'; | |||
for(var k in paras){url += '&' + k + '=' + paras[k]; } | |||
} | |||
return url; | |||
} | |||
function | //JS、CSS导入模块 | ||
importedURLs = {}; //用以保證腳本和樣式只载入一次 | |||
function importScript( page ) { | |||
var src= /^https?:\/\//.test(page) ? page : getWikiPath(page,{'ctype':'text/javascript'}); | |||
if( importedURLs[src] ) { return; } | |||
importedURLs[src] = true; | |||
var scriptElem = createElement( 'script',null,{'src':src,'type':'text/javascript'} ); | |||
document.getElementsByTagName( 'head' )[0].appendChild( scriptElem ); | |||
} | |||
function importStylesheet( page ) {//注,目前在IE下还有错,避免调用此函数 | |||
var sheet= /^https?:\/\//.test(page) ? page : getWikiPath(page,{'ctype':'text/css'}); | |||
if( importedURLs[sheet] ) { return; } | |||
importedURLs[sheet] = true; | |||
var styleElem = createElement( 'style', ['@import "'+sheet+'";'], {'type':'text/css'} ); | |||
document.getElementsByTagName( 'head' )[0].appendChild( styleElem ); | |||
} | |||
//引入[[Special:Gadgets]]要求的腳本和樣式 | |||
if(window.requireScripts instanceof Array){ | |||
forEach(importScript,requireScripts); | |||
} | |||
if(window.requireStylesheets instanceof Array){ | |||
forEach(importStylesheet,requireStylesheets); | |||
} | |||
/* 测试元素中是否含有指定的样式 ************************************** | |||
* Description: 使用正则式与缓存来提高性能 | |||
* Maintainers: User:fdcn @zh.wikipedia | |||
* [[en:User:Mike Dillon]], [[en:User:R. Koot]], [[en:User:SG]] @en.wikipedia | |||
*/ | |||
var hasClass = (function () { | |||
var reCache = {}; | |||
return function (element, className) { | |||
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className); | |||
}; | |||
})(); | |||
/* | |||
</pre> | |||
=== 中文處理 === | |||
<pre> | |||
*/ | |||
//设置中文语言页 | |||
var htmlE=document.documentElement; | |||
htmlE.setAttribute("lang",wgUserLanguage); | |||
htmlE.setAttribute("xml:lang",wgUserLanguage); | |||
//返回繁簡字串 | |||
function wgULS(hans,hant,cn,tw,hk,sg,zh){ | |||
return {//保證每一語言有值 | |||
'zh-hans':hans||cn||sg, | |||
'zh-hant':hant||tw||hk, | |||
'zh-cn':cn||hans||sg, | |||
'zh-sg':sg||hans||cn, | |||
'zh-tw':tw||hant||hk, | |||
'zh-hk':hk||hant||tw, | |||
'zh':zh||hant||hans||cn||tw||hk||sg | |||
}[wgUserLanguage]; | |||
} | |||
/* | |||
</pre> | |||
=== IE兼容性修正 === | |||
<pre> | |||
*/ | |||
function fixIE(){ | |||
var oldWidth; | |||
var docEl = document.documentElement; | |||
function fixIEScroll(){ | |||
if (!oldWidth || docEl.clientWidth > oldWidth){ | |||
doFixIEScroll(); | |||
}else{ | |||
setTimeout(doFixIEScroll, 1); | |||
} | |||
oldWidth = docEl.clientWidth; | |||
} | |||
function doFixIEScroll() { | |||
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : ""; | |||
} | |||
document.attachEvent("onreadystatechange", fixIEScroll); | |||
attachEvent("onresize", fixIEScroll); | |||
} | |||
if (navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat"){ | |||
fixIE(); | |||
} | |||
/* | |||
</pre> | |||
=== 工具提示與快捷鍵 === | |||
<pre> | |||
*/ | |||
ta = { | |||
'ca-article' : ['a',wgULS('浏览条目正文','瀏覽條目正文')], | |||
'ca-nomove' : ['',wgULS('你不能移动这个页面','你不能移動這個頁面')], | |||
'n-Featured_content' : ['',wgULS('查看中文维基百科的特色内容','查看中文維基百科的特色內容')], | |||
'n-indexpage' : ['',wgULS('以分类索引搜寻中文维基百科','以分類索引搜尋中文維基百科')], | |||
'n-commonsupload' : ['',wgULS('把自由版权图片上传到维基共享资源','把自由版權圖片上傳到維基共享資源')], | |||
'n-contact' : ['',wgULS('如何联络维基百科','如何聯絡維基百科')], | |||
'n-villagepump' : ['',wgULS('参与维基百科社群的讨论','參與維基百科社群的討論')], | |||
'n-Information_desk' : ['',wgULS('解答任何与维基百科无关的问题的地方','解答任何與維基百科無關的問題的地方')], | |||
'n-conversion' : ['',wgULS('提出字词转换请求','提出字詞轉換請求')], | |||
'n-allpages' : ['',wgULS('浏览所有页面的清单','瀏覽所有頁面的清單')], | |||
'ca-nstab-project' : ['a',wgULS('查看维基计划页面','查看維基計畫頁面','查看維基計劃頁面')], | |||
'n-policy' : ['',wgULS('查看维基百科的方针和指引','查看維基百科的方針和指引')], | |||
'n-about' : ['',wgULS('查看维基百科的简介','查看維基百科的簡介')] | |||
} | |||
/* | |||
</pre> | |||
=== 特色條目優良與條目鏈接顯示 === | |||
<pre> | |||
*/ | |||
addOnloadHook( function(){ | |||
var InterwikiLinks = document.getElementById( "p-lang" ); | |||
if ( !InterwikiLinks ) { return; } | |||
forEach( function(link){ | |||
if ( document.getElementById( link.className + "-fa" ) ) { | |||
link.className += " FA" | |||
link.title = wgULS("此条目为特色条目。","此條目為特色條目。"); | |||
} | |||
if ( document.getElementById( link.className + "-ga" ) ) { | |||
link.className += " GA" | |||
link.title = wgULS("此条目为优良条目。","此條目為優良條目。"); | |||
} | |||
},InterwikiLinks.getElementsByTagName("li") ); | |||
}); | |||
/* | |||
</pre> | |||
=== 編輯工具欄 === | |||
<pre> | |||
*/ | |||
/** | |||
* tip for custom edittools | |||
* | |||
* Maintainers: fdcn@zh.wikipedia | |||
*/ | |||
hookEvent("load",function(){ | |||
var wpEditToolbar=document.getElementById("toolbar"); | |||
if(!wpEditToolbar){return;} | |||
// 增加对未注册用户的提示 | |||
if(!mwCustomEditButtons.length){ | |||
wpEditToolbar.appendChild( createElement("a","扩展编辑按钮?",{ | |||
'href':getWikiPath('Wikipedia:維基百科工具/編輯工具'), | |||
'title':wgULS('注册一个用户,即可以定制自己的编辑按钮','註冊一個賬號,即可以定制自己的編輯按鈕'), | |||
'styles':{'fontSize':'smaller','marginLeft':'1em'} | |||
})); | |||
} | |||
// 有重複按鈕的提示 | |||
if(mwCustomEditButtons.state=='rID'){ | |||
wpEditToolbar.appendChild( createElement("span"," ! ",{ | |||
'title':wgULS('你选择的编辑按钮扩展可能有重复的按钮','你選擇的編輯按鈕擴展可能有重複的按鈕'), | |||
'styles':{'color':'red','cursor':'pointer'} | |||
})); | |||
} | |||
//增加編輯摘要的下拉選單 | |||
var wpSummaryLabel=document.getElementById("wpSummaryLabel"); | |||
if(!wpSummaryLabel){return;} | |||
var form = document.getElementById('editform'); | |||
var summarys={}; | |||
var i=0; | |||
function add(label,summary){ | |||
var val='summary'+(i++); | |||
summarys[val]=summary; | |||
var option=new Option(label,val); | |||
return menu.options[menu.options.length]=option; | |||
} | |||
var menu=createElement( | |||
"select", | |||
[new Option(wgULS("摘要类型","摘要類型"))], | |||
{id:"summaryMenu",size:1,events:{'change':function(){ | |||
var key=menu.options[menu.selectedIndex].value; | |||
var s=summarys[key]; | |||
if(s){form.wpSummary.value += ' '+s;} | |||
menu.selectedIndex=0; | |||
}}} | |||
); | |||
add( wgULS('新条目','新條目'), wgULS('新条目','新條目') ); | |||
add( wgULS('修饰语句','修飾語句'), wgULS('修饰语句','修飾語句') ); | |||
add( wgULS('修正笔误','修正筆誤'), wgULS('修正笔误','修正筆誤') ); | |||
add( wgULS('内容扩充','內容擴充'), wgULS('内容扩充','內容擴充') ); | |||
add( '排版', wgULS('调整格式、排版','調整格式、排版') ); | |||
add( wgULS('段落章节','段落章節'), wgULS('移动或调整段落章节','移動或調整段落章節') ); | |||
add( wgULS('内部链接','內部連結'), wgULS('增加或调整内部链接','增加或調整內部連結') ); | |||
add( wgULS('跨语言链接','跨語言連結'), wgULS('增加或调整跨语言链接','增加或調整跨語言連結') ); | |||
add( wgULS('分类','分類'), wgULS('增加或调整分类','增加或調整分類') ); | |||
add( wgULS('小作品标签','小作品標籤'), wgULS('增加或调整小作品标签','增加或調整小作品標籤') ); | |||
add( wgULS('字词转换','字詞轉換'), wgULS('增加或调整字词转换代码','增加或調整字詞轉換代碼') ); | |||
add( wgULS('消歧义','消歧義'), wgULS('消歧义','消歧義') ); | |||
add( wgULS('维基化','維基化'), wgULS('维基化','維基化') ); | |||
add( wgULS('标识删除','標識刪除'), wgULS('提交删除讨论或速删','提交刪除討論或速刪') ); | |||
add( wgULS('侵权','侵權'), wgULS('提交侵权删除','提交侵權刪除') ); | |||
add( wgULS('欢迎','歡迎'), wgULS('欢迎用户','歡迎用戶') ); | |||
add( '警告', wgULS('警告用户','警告用戶') ); | |||
wpSummaryLabel.appendChild(menu); | |||
//加入對摘要框的限制,以適應中文UTF-8的字節數 | |||
var summaryinput=document.getElementById("wpSummary"); | |||
if(summaryinput && summaryinput.maxLength)summaryinput.maxLength=83; | |||
}); | |||
/* | |||
</pre> | |||
=== 强制预览 === | |||
<pre> | |||
*/ | |||
if ( (wgUserGroups+" ").indexOf("autoconfirmed") == -1 && wgAction == "edit" ) { | |||
addOnloadHook (function(){ | |||
var saveButton = document.getElementById("wpSave"); | |||
if (!saveButton) return; | |||
saveButton.disabled = true; | |||
saveButton.value += wgULS(" (预览后可用)"," (預覽後可用)"); | |||
saveButton.style.fontWeight = "normal"; | |||
document.getElementById("wpPreview").style.fontWeight = "bold"; | |||
}); | |||
} | |||
/* | |||
</pre> | |||
=== 增加摺疊功能 === | |||
<pre> | |||
*/ | |||
/** 摺疊 div table ***************************** | |||
* Description: 实现div.NavFrame和table.collapsible的可折叠性。 | |||
* JSConfig的collapseText、expandText、autoCollapse属性定义默认文字和默认最少自动折叠块 | |||
* Maintainers: User:fdcn | |||
*/ | |||
function cancelBubble(e){ | |||
e=e||window.event; | |||
if(e.stopPropagation){e.stopPropagation();}else{e.cancelBubble=true;} | |||
} | |||
function createToggleButton(head){ | |||
var parent=head; | |||
if( head.tagName.toLowerCase()=='tr' ){//对表格特别处理 | |||
if(head.getElementsByTagName("th").length){ | |||
parent=head.cells[parent.cells.length-1]; | |||
} else {return;} | |||
} | |||
var textS,textH,button=getElementsByClassName(head,"span","NavToggle")[0]; | |||
if(button){parent=button.parentNode;} else{ | |||
textS=createElement("span",[JSConfig.expandText],{'class':'toggleShow'}); | |||
textH=createElement("span",[JSConfig.collapseText],{'class':'toggleHide'}); | |||
button=createElement("span",[textS,textH],{'class':'NavToggle',styles:{'width':"3.8em"}}); | |||
} | |||
button.style.display="inline"; | |||
head.className+=" uncollapse toggleHotspot"; | |||
parent.insertBefore( button, parent.childNodes[0] ); | |||
} | |||
function wgCollapse(head,container,defaultCollapse){ | |||
if(head){ createToggleButton(head); } | |||
var self=this; | |||
this.state=0; | |||
this.container=container; | |||
forEach( function(h){ | |||
if ( h.nodeType==1 | |||
&& !hasClass(h,"uncollapse") | |||
&& !hasClass(h,"toggleShow") | |||
&& !hasClass(h,"toggleHide") | |||
) { h.className+=" toggleHide"; } | |||
}, defaultCollapse );//预设的隐藏元素 | |||
function getArray(clsname){ | |||
var r=[],i=0,e,ea=getElementsByClassName(container,"*",clsname); | |||
while(e=ea[i++]){ | |||
var parent=e.parentNode; | |||
while(!hasClass(parent,'NavFrame')&&!hasClass(parent,'collapsible')){parent=parent.parentNode;} | |||
if(parent==container){r.push(e);} | |||
} | |||
return r; | |||
} | |||
var toggleA=getArray("toggleShow"); | |||
var toggleB=getArray("toggleHide"); | |||
var hotspots=getArray("toggleHotspot"); | |||
function _toggle(list,state){ | |||
var i=0,e; | |||
while(e=list[i++]){e.style.display=state?e.showStyle||'':'none';} | |||
} | |||
this.toggle=function(state){ | |||
self.state=(typeof state=='undefined')?1-self.state:state; | |||
_toggle(toggleA,self.state); | |||
_toggle(toggleB,1-self.state); | |||
} | |||
var i=0,h; | |||
while(h=hotspots[i++]){ | |||
forEach(function(link){ | |||
addClickHandler(link,cancelBubble); | |||
},h.getElementsByTagName("A")); | |||
h.style.cursor = "pointer"; | |||
addClickHandler(h,function(){self.toggle();}); | |||
} | |||
} | |||
addOnloadHook(function(){ | |||
//init | |||
var items=[]; | |||
forEach( function(NavFrame){ | |||
var i=0, | |||
child=NavFrame.childNodes, | |||
head; | |||
while (head=child[i++]) { | |||
if( head.className&&hasClass(head,"NavHead") ){break;} | |||
} | |||
items.push(new wgCollapse(head,NavFrame,NavFrame.childNodes)); | |||
},getElementsByClassName(document,"div","NavFrame") ); | |||
forEach ( function(table){ | |||
var rows = table.rows; | |||
items.push(new wgCollapse(rows[0],table,rows)); | |||
},getElementsByClassName(document,"table","collapsible") ); | |||
var item,i=0,count=items.length; | |||
while ( item=items[i++] ) { | |||
item.toggle ( | |||
hasClass(item.container,"collapsed") | |||
|| ( count>=JSConfig.autoCollapse&&hasClass(item.container,"autocollapse") ) | |||
); | |||
} | |||
}); | |||
//修正摺疊後定位變化 | |||
hookEvent("load",function(){if(location.hash){location.href=location.hash;}}); | |||
/* | |||
</pre> | |||
=== 首頁輸出修正 === | |||
<pre> | |||
*/ | |||
/** 首页输出修正 ******************************************************* | |||
描述: | |||
维护者: [[User:Fdcn]] | |||
*/ | |||
// "首頁" == wgTitle 代表重定向頁 | |||
if ( wgTitle == '首页' && ( wgNamespaceNumber == 0 || wgNamespaceNumber == 1 ) ) { | |||
addOnloadHook( function () { | |||
try { | |||
var Node = document.getElementById( 'ca-nstab-main' ).firstChild; | |||
var label = wgULS('首页','首頁'); | |||
if ( Node.textContent ) { // Per DOM Level 3 | |||
Node.textContent = label; | |||
} else if ( Node.innerText ) { // IE doesn't handle .textContent | |||
Node.innerText = label; | |||
} else { // Fallback | |||
Node.replaceChild( Node.firstChild, document.createTextNode( label ) ); | |||
} | |||
} catch(e) {}// bailing out! | |||
} ); | |||
if(wgNamespaceNumber == 0){ | |||
addOnloadHook( function () { | |||
addPortletLink('p-lang', getWikiPath('Wikipedia:维基百科语言列表'), | |||
wgULS('维基百科语言列表','維基百科語言列表'), 'interwiki-completelist',wgULS('维基百科的完整各语言列表', '維基百科的完整各語言列表')); | |||
}); | |||
} | |||
} | |||
/* | |||
</pre> | |||
=== 取消修訂編輯摘要修正 === | |||
<pre> | |||
*/ | |||
/** | |||
fix edit summary prompt for undo | |||
this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the edit summary unchanged | |||
this was added by [[:en:User:Deskana]], code by [[:en:User:Tra]] | |||
*/ | |||
addOnloadHook(function () { | |||
var autoSummary=document.getElementsByName('wpAutoSummary')[0]; | |||
if (document.location.search.indexOf("undo=") != -1 && autoSummary) | |||
{ autoSummary.value=''; } | |||
}) | |||
/* | |||
</pre> | |||
=== 取消討論頁的[+]按鈕 === | |||
<pre> | |||
*/ | |||
addOnloadHook(function () { | |||
if(document.getElementById('no-newsection') && document.getElementById('ca-addsection')) { | |||
document.getElementById('ca-addsection').style.display="none"; | |||
} | |||
}); | |||
/* | |||
</pre> | |||
=== [[Special:Search]]其他搜尋引擎連結表單 === | |||
<pre> | |||
*/ | |||
var searchEngines=[]; | |||
var createSearchForm;//可在用户皮肤JS中自行增加引擎。 | |||
function SpecialSearchEnhanced() | |||
{ | |||
if ( | |||
JSConfig.SpecialSearchEnhancedDisabled || | |||
wgCanonicalNamespace != "Special" || | |||
wgCanonicalSpecialPageName != "Search" | |||
){return;} | |||
if(skin == "monobook" || skin == "cologneblue" || skin == "simple"){ | |||
var mainNode = document.getElementsByTagName("form")[0]; | |||
} | } | ||
if (!mainNode) return; | |||
var searchbox=document.getElementById("lsearchbox"); | |||
var div= createElement("div",null,{styles:{'width':"100%",'textAlign':'center'}}); | |||
mainNode.appendChild(div); | |||
function | /** | ||
* 建立一个搜索引擎 | |||
var | */ | ||
createSearchForm=function(engine_name, engine_url, logo_url, search_action_url, | |||
search_field_name, add_search_field, field_array, logo_width, logo_height) | |||
{ | |||
var input=createElement("input",null,{'type':"hidden",'name':search_field_name}) | |||
var inputs = [input]; | |||
for( var k in field_array){ | |||
inputs.push(createElement( | |||
"input",null,{'type':"hidden",'name':k,'value':field_array[k]} | |||
)); | |||
} | |||
inputs.push(createElement( | |||
"input",null,{'type':"submit",'value':wgULS('搜索','搜尋')} | |||
)); | |||
var form = createElement("form",inputs, | |||
{ | |||
'method':"get", | |||
'action':search_action_url, | |||
'styles':{'display':"inline"}, | |||
'events':{'submit':function(){input.value = searchbox.value+add_search_field;}} | |||
} | |||
); | |||
var img = createElement("img",null,{ | |||
'src':logo_url, | |||
'alt':engine_name, | |||
'styles':{'borderWidth':"0",'padding':"5px",'width':logo_width||'135px','height':logo_height||'35px'} | |||
}); | |||
var a = createElement("a",[img],{'href':engine_url}); | |||
var span= createElement("span",[form,a],{styles:{'marginRight':"1em"}}); | |||
searchEngines.push(span); | |||
searchEngines[engine_name]=span; | |||
div.appendChild(span); | |||
} | } | ||
//於此開始列示各引擎。 | |||
//google | |||
createSearchForm( | |||
"Google","http://www.google.com/", | |||
"http://www.google.com/logos/powered_by_google_135x35.gif", | |||
"http://www.google.com/search","q", "", | |||
{"as_sitesearch": "zh.wikipedia.org"}, | |||
"77px","20px" | |||
); | |||
//live search | |||
createSearchForm( | |||
"Live", "http://search.live.com/", | |||
"http://upload.wikimedia.org/wikipedia/zh/thumb/1/17/Mslivelogo.png/120px-Mslivelogo.png", | |||
"http://search.live.com/results.aspx","q", "", | |||
{"q1":"site:zh.wikipedia.org"}, | |||
'100px','20px' | |||
); | |||
//yahoo | |||
createSearchForm( | |||
"Yahoo!", "http://www.yahoo.com/", | |||
"http://upload.wikimedia.org/wikipedia/zh/thumb/a/ad/Yahoo_Logo.svg/135px-Yahoo_Logo.svg.png", | |||
"http://search.yahoo.com/search","p", "", | |||
{"vs": "zh.wikipedia.org","ei":"UTF-8"}, | |||
'80px','15px' | |||
); | |||
//zhosisterps | |||
createSearchForm( | |||
"中文系維基跨計劃搜尋", "http://www.google.com/coop/", | |||
"http://www.google.com/coop/images/google_coop_sm.gif", | |||
"http://www.google.com/"+"cse","q","", | |||
{"cx":"009212467671870524522:mw9ug06rtl4","cof":"FORID:0","sa":"Search"}, | |||
"51px","20px" | |||
); | |||
//zhsisterps | |||
createSearchForm( | |||
"中文维基媒体搜索", "http://www.google.com/coop/", | |||
"http://www.google.com/coop/images/google_coop_sm.gif", | |||
"http://www.google.com/"+"cse","q","", | |||
{"cx":"012948615710733534834:sce7kigca9g","cof":"FORID:0","sa":"Search"}, | |||
"51px","20px" | |||
); | |||
} | } | ||
/* </pre> */ | addOnloadHook(SpecialSearchEnhanced); //啟動Search Engine | ||
/* | |||
</pre> | |||
=== WikiMiniAtlas世界地圖 === | |||
<pre> | |||
*/ | |||
/** WikiMiniAtlas ******************************************************* | |||
* | |||
* 描述:WikiMiniAtlas是一個popup而可點選與拖曳的世界地圖。 | |||
* 這個腳本將會讓所有的經緯度標示中顯示WikiMiniAtlas的popup開啟按鈕。 | |||
* 由於被許多計畫使用,因此腳本放置在元維基中。 | |||
* 更多資訊請詳見[[Meta:WikiMiniAtlas]]。 | |||
* 創建者:[[:en:User:Dschwen]] | |||
*/ | |||
importScript('m:MediaWiki:Wikiminiatlas.js'); | |||
/* | |||
</pre> | |||
*/ | |||
Revision as of 22:35, 25 July 2008
/*
===onglets===
Auteur: ThomasV
<pre>*/
function ongletCopyright()
{
var a = document.getElementById("p-cactions");
if (a)
{
b = a.getElementsByTagName("ul");
if(b.length > 0)
{
if(document.getElementById("Creative Commons by-nc-sa"))
{ b[0].innerHTML = b[0].innerHTML
+ '<li id="ca-nstab-user">'
+ '<a href="/wiki/Wikilivres:Creative Commons by-nc-sa">'
+ 'License</a></li>';
}
else if(document.getElementById("Copyright-ONU"))
{ b[0].innerHTML = b[0].innerHTML
+ '<li id="ca-nstab-user">'
+ '<a href="/wiki/Wikilivres:Copyright-ONU">'
+ 'License</a></li>';
}
else if(document.getElementById("Copyright-UNESCO"))
{ b[0].innerHTML = b[0].innerHTML
+ '<li id="ca-nstab-user">'
+ '<a href="/wiki/Wikilivres:Copyright-UNESCO">'
+ 'License</a></li>';
}
else if(document.getElementById("GFDL"))
{ b[0].innerHTML = b[0].innerHTML
+ '<li id="ca-nstab-user">'
+ '<a href="/wiki/Wikilivres:Licence GFDL">'
+ 'License</a></li>';
}
}
}
}
addOnloadHook(ongletCopyright);
/*</pre>
===interwikiextra===
Auteur:ThomasV
<pre>*/
function interwikiExtra()
{
// iterate over all <span>-elements
for(var i=0; a = document.getElementsByTagName("span")[i]; i++) {
// if found a linkInfo span
if(a.className == "interwiki-info") {
// iterate over all <li>-elements
var count=0;
for(var j=0; b = document.getElementsByTagName("li")[j]; j++) {
if(b.className == "interwiki-" + a.id) {
b.innerHTML = b.innerHTML + " "+a.title;
if(a.title == "(vo)") { b.title = "Texte original"; }
}
else if(b.className == "interwiki-" + a.id.substr(0,a.id.length-1)) {
count = count+1;
if(a.id.charAt(a.id.length-1) == count) {
b.innerHTML = b.innerHTML + " "+a.title;
}
}
}
}
if(a.className == "AutreVersion") {
p = a.title.indexOf("|");
pvers = document.getElementById("p-version");
if (pvers == null) {
c = document.getElementById("column-one");
c.innerHTML = c.innerHTML
+ "<div class=\"portlet\" id=\"p-version\">"
+ "<h5>Autres versions</h5>"
+ "<div class=\"pBody\">"
+ "<ul>"
+ "</ul>"
+ "</div>";
pvers = document.getElementById("p-version");
}
e = pvers.getElementsByTagName("ul")[0];
e.innerHTML = e.innerHTML
+ "<li class=\"\"><a href='"
+ a.title.substr(0,p)
+ "'>" + a.title.substr(p+1,a.title.length-1)+ "</a> " +"</li>";
}
}
}
addOnloadHook(interwikiExtra);
/*</pre>
===Liens bilingues===
Fonctionne avec l'extension DoubleWiki. Auteur: ThomasV
<pre>*/
function BilingualLink()
{
if( wgNamespaceNumber != 0) return;
var doc_url = document.URL;
var url = '';
// iterate over all <li>-elements
for(var j=0; b = document.getElementsByTagName("li")[j]; j++) {
if(b.className.substring(0,10) == "interwiki-" ) {
var lang = b.className.substring(10,b.className.length);
if( doc_url.indexOf('?title=') != -1 ) {
var qm = doc_url.indexOf('&match=');
if( qm != -1 ) url = doc_url.substring(0,qm)+"&match="+lang;
else url = doc_url+"&match="+lang;
} else {
var qm = doc_url.indexOf('?');
if( qm != -1 ) url = doc_url.substring(0,qm)+"?match="+lang;
else url = doc_url+"?match="+lang;
}
b.innerHTML = b.innerHTML+"<a href='"+url+"'> ⇔</a>";
}
}
}
addOnloadHook(BilingualLink);
/*</pre>
===Edittools===
<pre>*/
/* add menu for selecting subsets of secial characters */
/***** must match MediaWiki:Edittools *****/
function addCharSubsetMenu() {
var specialchars = document.getElementById('specialchars');
if (specialchars) {
var menu = "<select style=\"display:inline\" onChange=\"chooseCharSubset(selectedIndex)\">";
menu += "<option>Wiki</option>";
menu += "<option>Latin/Romain</option>";
menu += "<option>Grec</option>";
menu += "<option>Cyrillique</option>";
menu += "<option>AHD</option>";
menu += "<option>Allemand</option>";
menu += "<option>Catalan</option>";
menu += "<option>Croate</option>";
menu += "<option>Espagnol</option>";
menu += "<option>Espéranto</option>";
menu += "<option>Estonien</option>";
menu += "<option>Gallois</option>";
menu += "<option>Hawaien</option>";
menu += "<option>Hiéroglyphe</option>";
menu += "<option>Islandais</option>";
menu += "<option>Italien</option>";
menu += "<option>Maltais</option>";
menu += "<option>Pinyin</option>";
menu += "<option>Polonais</option>";
menu += "<option>Portugais</option>";
menu += "<option>Rōmaji</option>";
menu += "<option>Roumain</option>";
menu += "<option>Scandinave</option>";
menu += "<option>Serbe</option>";
menu += "<option>Tchèque</option>";
menu += "<option>Vieil anglais</option>";
menu += "<option>Vietnamien</option>";
menu += "</select>";
specialchars.innerHTML = menu + specialchars.innerHTML;
/* default subset - try to use a cookie some day */
chooseCharSubset(0);
}
}
/* select subsection of special characters */
function chooseCharSubset(s) {
var l = document.getElementById('specialchars').getElementsByTagName('p');
for (var i = 0; i < l.length ; i++) {
l[i].style.display = i == s ? 'inline' : 'none';
l[i].style.visibility = i == s ? 'visible' : 'hidden';
}
}
addOnloadHook(addCharSubsetMenu);
/****************************************/
function mwInsertEditButton(parent, item) {
var image = document.createElement("img");
image.width = 23;
image.height = 22;
image.src = item.imageFile;
image.border = 0;
image.style.cursor = "pointer";
var ref = document.createElement("a")
ref.setAttribute("href", "javascript:insertTags(\"" + item.tagOpen + "\",\"" + item.tagClose + "\",\"" + item.sampleText + "\");")
ref.setAttribute("title", item.speedTip);
ref.appendChild(image);
parent.appendChild(ref);
}
/*</pre>
===Générateur de tableaux===
<pre>*/
/**
*
* English: Generate an array using Mediawiki syntax
*
* @author: fr:user:dake
* @version: 0.1
*/
function generateTableau(nbCol, nbRow, border, styleHeader, styleLine)
{
var code = "\n";
if (styleHeader==1) {
code += '{{entête tableau charte}}\n';
} else {
code += '{| border="' + border + '"\n';
code += '|+ Titre du tableau\n';
}
for (var i=0;i<nbCol;i++) code += '! en-tête ' + i + '\n'
for (var j=0;j<nbRow;j++) {
if ((j+1)%2==0 && styleLine==1) {
code += '|-{'+'{ligne grise}'+'}\n'
} else {
code += '|-----\n'
}
for (var i=0;i<nbCol;i++) code += '| élément\n';
}
code += '|}';
insertTags('','', code);
}
/**
*
* English: Open a popup with parameters to generate an array.
* The number of rows/columns can be modified. Some additional
* parameters are related to templates available on :fr
*
* @author: fr:user:dake
* @version: 0.1
*/
function popupTableau()
{
var popup = window.open('','name','height=400,width=500');
javaCode = '<script type="text\/javascript">function insertCode(){';
javaCode += 'var row = parseInt(document.paramForm.inputRow.value); '
javaCode += 'var col = parseInt(document.paramForm.inputCol.value); '
javaCode += 'var bord = parseInt(document.paramForm.inputBorder.value); '
javaCode += 'var styleHeader = document.paramForm.inputHeader.checked; '
javaCode += 'var styleLine = document.paramForm.inputLine.checked; '
javaCode += 'window.opener.generateTableau(col,row,bord,styleHeader,styleLine); '
javaCode += '}<\/script>';
popup.document.write('<html><head><title>Paramètres du tableau</title>');
popup.document.write('<script type="text\/javascript" src="\/skins-1.5\/common\/wikibits.js"><!-- wikibits js --><\/script>');
popup.document.write('<style type="text\/css" media="screen,projection">/*<![CDATA[*/ @import "\/skins-1.5\/monobook\/main.css?5"; /*]]>*/<\/style>');
popup.document.write(javaCode);
popup.document.write('</head><body>');
popup.document.write('<p>Veuillez entrer les paramètres du tableau : </p>');
popup.document.write('<form name="paramForm">');
popup.document.write('Nombre de lignes : <input type="text" name="inputRow" value="3" ><p>');
popup.document.write('Nombre de colonnes : <input type="text" name="inputCol" value="3" ><p>');
popup.document.write('Largeur de la bordure : <input type="text" name="inputBorder" value="1" ><p>');
popup.document.write('En-tête en gris (style « charte graphique ») : <input type="checkbox" name="inputHeader" checked="1" ><p>');
popup.document.write('Lignes grises alternées (style « charte graphique ») : <input type="checkbox" name="inputLine" checked="1" ><p>');
popup.document.write('</form">');
popup.document.write('<p><a href="javascript:insertCode()"> Insérer le code dans la fenêtre d\'édition</a></p>');
popup.document.write('<p><a href="javascript:self.close()"> Fermer</a></p>');
popup.document.write('</body></html>');
popup.document.close();
}
/*</pre>
===Insertion de nouveaux boutons dans la barre d'outil===
<pre>*/
// Début du code pour le modèle interprojet (codice adattato da de:wikt:Mediawiki:monobook.js)
document.write('<style type="text/css">#interProject {display: none; speak: none;} #p-tb .pBody {padding-right: 0;}<\/style>');
function iProject() {
if (document.getElementById("interProject")) {
var iProject = document.getElementById("interProject").innerHTML;
var interProject = document.createElement("div");
interProject.style.marginTop = "0.7em";
interProject.innerHTML = '<h5>compléments<\/h5><div class="pBody">'+iProject+'<\/div>';
document.getElementById("p-tb").appendChild(interProject);
}
}
hookEvent("load", iProject);
// fin du code pour l'interprojet
//============================================================
// Insertion de nouveaux boutons dans la barre d'outil
//============================================================
//Remplit la variable mwCustomEditButtons (voir /skins-1.5/commons/wikibits.js) pour ajouter des boutons à la barre d'outils
function addCustomButton(imageFile, speedTip, tagOpen, tagClose, sampleText)
{
mwCustomEditButtons[mwCustomEditButtons.length] =
{"imageFile": imageFile,
"speedTip": speedTip,
"tagOpen": tagOpen,
"tagClose": tagClose,
"sampleText": sampleText};
}
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/3/30/Btn_toolbar_rayer.png','Rayer','<s>','</s>','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/8/88/Btn_toolbar_enum.png','Énumération','\\n# élément 1\\n# élément 2\\n# élément 3','','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/1/11/Btn_toolbar_liste.png','Liste','\\n* élément A\\n* élément B\\n* élément C','','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/8/8f/Button_poeme.png','Poésie','<poem>\\n\\n','\\n</poem>','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/9/9e/Btn_toolbar_gallery.png','Galerie Photo','<gallery>\\n','\\n</gallery>','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/3/37/Btn_toolbar_commentaire.png','Commentaire','<!--','-->','Insérer votre commentaire');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/c/c8/Button_redirect.png','Redirection','#REDIRECT \[\[','\]\]','nom de la destination');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/b/b4/Button_category03.png','Catégorie','\[\[Catégorie:','\]\]','nom de la catégorie');
addCustomButton('http://upload.wikimedia.org/wikipedia/en/5/5f/Button_center.png','Texte centré','<div style="text-align: center;">','</div>','');
addCustomButton('http://upload.wikimedia.org/wikipedia/en/e/e9/Button_headline2.png','paragraphe niveau 3','===','===','');
addCustomButton('http://upload.wikimedia.org/wikipedia/en/8/8e/Button_shifting.png', 'Insérer un retrait',':','',':' );
addCustomButton('http://upload.wikimedia.org/wikipedia/en/5/58/Button_small.png','Texte plus petit','<small>','</small>','');
addCustomButton('http://upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png','Exposant','<sup>','</sup>','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/4/4b/Button_nbsp.png','Espace insécable',' \;','','');
addCustomButton('http://upload.wikimedia.org/wikipedia/en/9/93/Button_sub_link.png','Lien vers sous-titre','\[\[Page\#','\]\]','Sub_page' );
addCustomButton('http://upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png','Block quote','<blockquote style="border: 1px solid blue; padding: 2em;">\\n','\\n</blockquote>','Block quote');
addCustomButton('http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png','Aller à la ligne','<br />','','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/4/4b/Button_class_text.png', 'Paragraphe texte','<div class=text>\\n\\n','\\n</div>','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/7/78/Button_titre.png','Titre de page','\{\{Titre\|','\|\|\}\}','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/0/03/Button_chapitre.png','Titre de Chapitre','\{\{chapitre\|livre=','\|auteur=\|nrpartie=\|nrchapitre=\|TitreChapitre=\|commentaires=\}\}','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/a/a0/Button_references_alt.png','Ajoute une référence','<ref>','</ref>','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/9/9a/Button_references.png','Liste des références','<references />','','');
addCustomButton('http://upload.wikimedia.org/wikipedia/commons/c/c3/Button_travaux.png','Relecture','\{\{subst:Infoédit\|1=','\|2= \|3= \|4= \|5= \|6= \}\}','');
//Ressemble à la fonction de /skins-1.5/commons/wikibits.js pour insérer un autre lien que insertTags
function marque_tab()
{
var toolbar = document.getElementById('toolbar');
if (!toolbar) return false;
var textbox = document.getElementById('wpTextbox1');
if (!textbox) return false;
if (!document.selection && textbox.selectionStart == null)
return false;
var image = document.createElement("img");
image.width = 23;
image.height = 22;
image.src = 'http://upload.wikimedia.org/wikipedia/fr/0/04/Button_array.png';
image.border = 0;
image.alt = 'Tableau';
image.title = 'Tableau';
image.style.cursor = "pointer";
image.onclick = function() {
popupTableau();
return false;
}
toolbar.appendChild(image);
}
addOnloadHook(marque_tab);
/*</pre>
</div>
===Options d'affichage===
Voir [[:Modèle:Option]]. Auteur:ThomasV
<pre>*/
//Cookies
function SetCookie(name,value) {
document.cookie = name + "=" + escape(value);
}
function GetCookie(name) {
var i =0;
while (i < document.cookie.length) {
if (document.cookie.substr(i,name.length) == name) {
var valend = document.cookie.indexOf(";",i+name.length+1);
if (valend == -1) {
valend = document.cookie.length;
}
return unescape(document.cookie.substring(i+name.length+1,valend));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
}
function OptionText() {
var indexNavigationBar = 0;
// iterate over all < span >-elements until class "OptionText" is found
for(
var i=0;
SpanElem = document.getElementsByTagName("span")[i];
i++
) {
// if found an option span
if (SpanElem.className == "OptionText") {
//SpanElem.style.display = 'none';
OptionTitle = SpanElem.title;
OptionStyle = SpanElem.firstChild.getAttribute('style');
//check if option was already encountered...
if(!document.getElementById(OptionTitle)){
//read cookie
var DisplayOptionDefault = true;
CookieDisplayOption = GetCookie ("Display"+OptionTitle)
if (CookieDisplayOption ) {
if (CookieDisplayOption == "false") DisplayOptionDefault = false; }
var PageDisplay = document.createElement("li");
PageDisplay.setAttribute('id', OptionTitle);
var PageDisplayLink = document.createElement("a");
OptionText = document.createTextNode("Désactiver "+OptionTitle);
PageDisplayLink.appendChild(OptionText);
PageDisplayLink.setAttribute('href','javascript:displayOptionText("'+OptionTitle+'","' + OptionStyle +'", '+DisplayOptionDefault+');');
PageDisplay.appendChild(PageDisplayLink);
var optlist = document.getElementById("optlist");
if(!optlist) {
var displayOptions = document.createElement("div");
displayOptions.style.marginTop = "0.7em";
displayOptions.innerHTML = '<h5>options d’affichage<\/h5><div class="pBody"><ul id="optlist"></ul><\/div>';
document.getElementById("p-tb").appendChild(displayOptions);
optlist = document.getElementById("optlist");
}
optlist.appendChild(PageDisplay);
displayOptionText(OptionTitle,OptionStyle,DisplayOptionDefault);
}
}
}
}
function displayOptionText(optiontitle, optionstyle, bool) {
SetCookie ("Display"+optiontitle,bool);
var PageDisplayLink = document.getElementById(optiontitle).firstChild;;
// iterate over all < span >-elements
for(
var i=0;
SpanElem = document.getElementsByTagName("span")[i];
i++
) {
// if found an option text
if ((SpanElem.className == "OptionText") && (SpanElem.title == optiontitle)) {
if(bool==true ) {
SpanElem.setAttribute('style',optionstyle);
PageDisplayLink.firstChild.data = (optiontitle);
PageDisplayLink.setAttribute('href', 'javascript:displayOptionText("'+optiontitle+'","'+optionstyle+'", false);');
}
if(bool==false) {
SpanElem.setAttribute('style','null');
PageDisplayLink.firstChild.data = (optiontitle);
PageDisplayLink.setAttribute('href', 'javascript:displayOptionText("'+optiontitle+'","'+optionstyle+'", true);');
}
}
}
}
addOnloadHook(OptionText);
function loadImage(ImageSrc,id){
var d = document.getElementById(id);
//if(d.firstChild){d.removeChild(d.firstChild);}
d.firstChild.setAttribute('href', 'javascript:hideImage("'+ImageSrc+'", "'+id+'");');
d.firstChild.setAttribute('title', 'cacher');
d.firstChild.innerHTML='[-]';
var newimg = document.createElement("img");
//newimg.setAttribute("src", "/wiki/index.php/Special:Filepath/"+ImageSrc.substring(6));
newimg.setAttribute("src", "/w/thumb.php?f="+ImageSrc.substring(6)+"&w=650");
newimg.setAttribute("alt", "image not found : "+ImageSrc.substring(6));
newimg.setAttribute("id", "img2");
d.appendChild(newimg);
}
function hideImage(ImageSrc,id){
var d = document.getElementById(id);
d.firstChild.setAttribute('href', 'javascript:loadImage("'+ImageSrc+'", "'+id+'");');
d.firstChild.setAttribute('title', 'montrer');
d.firstChild.innerHTML='[+]';
d.removeChild(d.lastChild);
}
function onclickImages() {
// iterate over all < span >-elements
for(
var i=0;
spanElem = document.getElementsByTagName("span")[i];
i++
) {
if (spanElem.className == "onclickImage") {
spanElem.setAttribute('id', 'onclick'+i);
title = spanElem.firstChild.getAttribute('title');
spanElem.firstChild.setAttribute('href', 'javascript:loadImage("'+title+'", "onclick'+i+'");');
spanElem.firstChild.innerHTML='[+]';
spanElem.firstChild.setAttribute('title', 'montrer');
}
}
}
addOnloadHook(onclickImages);
/**********************
*** Quality indicators on "article" tab
*** by [[user:ThomasV]]
**********************/
function icon_src(t){
var src='';
switch(t){
case "0%": src='http://wikilivres.info/wiki/index.php/Special:Filepath/00%25.png'; break;
case "25%": src='http://wikilivres.info/wiki/index.php/Special:Filepath/25%25.png'; break;
case "50%": src='http://wikilivres.info/wiki/index.php/Special:Filepath/50%25.png'; break;
case "75%": src='http://wikilivres.info/wiki/index.php/Special:Filepath/75%25.png'; break;
case "100%": src='http://wikilivres.info/wiki/index.php/Special:Filepath/100%25.png'; break;
}
return src;
}
function pageQuality() {
var a = document.getElementById("ca-nstab-main");
if(!a) return;
var q = document.getElementById("textquality")
if(q) {
var new_img = document.createElement("img");
new_img.setAttribute("src", icon_src(q.className));
a.firstChild.appendChild(new_img);
}
for(var i=0; spanElem = document.getElementsByTagName("span")[i]; i++) {
if (spanElem.className == "pagequality") {
var new_img = document.createElement("img");
new_img.setAttribute("src", icon_src(spanElem.title));
if(wgCanonicalNamespace == "Page") {
a.firstChild.appendChild(new_img);
}
else {
s1 = spanElem.parentNode.previousSibling;
opttext = s1.firstChild.firstChild;
img = opttext.firstChild.nextSibling.nextSibling.nextSibling;
next = img.nextSibling;
opttext.removeChild(img);
opttext.insertBefore(new_img,next);
}
}
}
}
addOnloadHook(pageQuality);
/* Script from fr.ws replaced by script from en.ws */
/*
function textQuality() {
if(wgAction!='view' && wgAction!='submit' && wgAction!='purge') return;
if(wgCanonicalNamespace != "") return;
if( document.getElementById("Author") ) { a.firstChild.innerHTML = "Auteur"; return;}
if(wgPageName.substring(0,8) == "Portail:") return;
var a = document.getElementById("ca-nstab-main"); if(!a) return;
var q = document.getElementById("textquality")
if( q ) {
var t = q.className;
var new_img = document.createElement("img");
if(t == 'Textes validés') new_img.setAttribute("src", "http://www.wikilivres.info/wiki/images/b/b7/Etoile.png");
else new_img.setAttribute("src", "/wiki/index.php/Special:Filepath/"+t.substring(0,t.length-1)+'%25.png');
new_img.setAttribute("title", "état d'avancement: "+t.substring(0,t.length-1)+'%');
a.firstChild.appendChild(new_img);
}
var q = document.getElementById("pr_index")
if( q ) {
href = q.firstChild; if(!href) return;
q.removeChild(href);
href.innerHTML = "<img src='http://www.wikilivres.info/wiki/images/d/df/Livre.png' />";
href.setAttribute("title", "Voir la liste des pages et participer à la correction de ce livre");
var new_li = document.createElement("li");
new_li.appendChild(href);
a.parentNode.insertBefore(new_li,a.nextSibling);
}
else {
if( ! document.getElementById("pr_page")) {
var c = document.getElementById("contentSub");
c.innerHTML = c.innerHTML + "<span></span>";
}
}
}
addOnloadHook(textQuality);
*/
/**********************
*** Add quality buttons on edit view
*** by [[user:ThomasV]]
**********************/
function addQuality(form,value){
var text="";
switch(value){
//these should be the same as in template:textquality, etc.
case "25%": text = "Incomplete text"; break;
case "50%": text = "Complete text"; break;
case "75%": text = "Correct typography and layout"; break;
case "100%": text = "Proofread"; break;
}
form.elements["wpSummary"].value="/* "+text+" */";
if(wgCanonicalNamespace == "Page") {
s = form.elements["headerTextbox"].value;
s = s.replace(/\{\{PageQuality\|(.*?)\}\}/gi,"")
form.elements["headerTextbox"].value="{"+"{PageQuality|"+value+"}"+"}"+s;
}
else {
s = form.elements["wpTextbox1"].value;
s = s.replace(/\{\{TextQuality\|(.*?)\}\}/gi,"")
form.elements["wpTextbox1"].value="{"+"{TextQuality|"+value+"}"+"}"+s;
}
}
function addQualityButtons(){
if( wgNamespaceNumber != 0) {
return;
}
var ig = document.getElementById("wpWatchthis");
if(ig) {
var f = document.createElement("span");
f.innerHTML = ' <input type="radio" name="quality" value="25%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/index.php/Special:Filepath/25%25.png">'+'<input type="radio" name="quality" value="50%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/index.php/Special:Filepath/50%25.png">'+'<input type="radio" name="quality" value="75%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/index.php/Special:Filepath/75%25.png">'+'<input type="radio" name="quality" value="100%" onclick="addQuality(this.form,this.value)"><img src = "/wiki/index.php/Special:Filepath/100%25.png"><a href="http://www.wikilivres.info/wiki/index.php/Help:Contents#Quality_notation">Text advancement</a>';
ig.parentNode.insertBefore(f,ig.nextSibling.nextSibling.nextSibling)
}
}
addOnloadHook(addQualityButtons);
/* </pre> */
==Chinese converter ==
/*
所有用戶在加載任何頁面時,這裡的JavaScript都會加載
=== 辅助处理 ===
<pre>
*/
//功能設定
if(!window.JSConfig){var JSConfig={};}
JSConfig.collapseText=wgULS('隐藏▲','隱藏▲');//指示折叠收缩的默认文字
JSConfig.expandText=wgULS('显示▼','顯示▼');//指示折叠展开的默认文字
JSConfig.autoCollapse=2; //文章少于 autoCollapse 个折叠块时,不自动折叠
JSConfig.SpecialSearchEnhancedDisabled=false; //是否禁止增加其它搜索引擎
function forEach(callback,array){
var i=0,j=array.length;
while(i<j){callback(array[i++]);}
}
// 移動元素
function elementMoveto(node, refNode, pos){//默认位置为refNode前
if(node && refNode){
var parent=refNode.parentNode;
if (pos && pos=='after') {refNode=refNode.nextSibling;}
try {
if(refNode){
parent.insertBefore(node, refNode);
}else{
parent.appendChild(node);
}
} catch (DOMException) {};
}
}
//创建元素
function createElement(tag,children,props){
var element = document.createElement(tag);
if(!(children instanceof Array)){children=[children];}
forEach(function(child){
if(typeof child=='string'){child=document.createTextNode(child);}
if(child){element.appendChild(child);}
},children);
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;
default:
element.setAttribute(k,props[k]);
}
}
}
return element;
}
//wiki URL
var wgProjectURL={
en:'http://en.wikipedia.org',de:'http://de.wikipedia.org',fr:'http://fr.wikipedia.org',
pl:'http://pl.wikipedia.org',ja:'http://ja.wikipedia.org',it:'http://it.wikipedia.org',
nl:'http://nl.wikipedia.org',pt:'http://pt.wikipedia.org',es:'http://es.wikipedia.org',
sv:'http://sv.wikipedia.org',//僅列前十名其它語言百科
m:'http://meta.wikimedia.org',b:'http://zh.wikibooks.org',q:'http://zh.wikiquote.org',
n:'http://zh.wikinews.org',wikt:'http://zh.wiktionary.org',mw:'http://www.mediawiki.org',
commons:'http://commons.wikimedia.org'
}
/**
* 将页面名称转换为URL
*
* @param page 页面名称
* @param paras 附加后缀对象,用空对象{}做参数可以取得源码
*/
function getWikiPath(page,paras){
var reg=/^[a-z]+:/;
var pre=page.match(reg);
pre = pre && wgProjectURL[pre[0].replace(/:$/,'').toLowerCase()];
if (pre) {page=page.replace(reg,'');} else {pre=wgServer;} //保障没有相对路径,以照顾在线代理。
var url = pre + wgScript + '?title=' + encodeURI( page.replace( ' ', '_' ) );
if(typeof paras=='object'){
paras.ctype=paras.ctype||'text';
paras.dontcountme=paras.dontcountme||'s';
paras.action=paras.action||'raw';
for(var k in paras){url += '&' + k + '=' + paras[k]; }
}
return url;
}
//JS、CSS导入模块
importedURLs = {}; //用以保證腳本和樣式只载入一次
function importScript( page ) {
var src= /^https?:\/\//.test(page) ? page : getWikiPath(page,{'ctype':'text/javascript'});
if( importedURLs[src] ) { return; }
importedURLs[src] = true;
var scriptElem = createElement( 'script',null,{'src':src,'type':'text/javascript'} );
document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
}
function importStylesheet( page ) {//注,目前在IE下还有错,避免调用此函数
var sheet= /^https?:\/\//.test(page) ? page : getWikiPath(page,{'ctype':'text/css'});
if( importedURLs[sheet] ) { return; }
importedURLs[sheet] = true;
var styleElem = createElement( 'style', ['@import "'+sheet+'";'], {'type':'text/css'} );
document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
}
//引入[[Special:Gadgets]]要求的腳本和樣式
if(window.requireScripts instanceof Array){
forEach(importScript,requireScripts);
}
if(window.requireStylesheets instanceof Array){
forEach(importStylesheet,requireStylesheets);
}
/* 测试元素中是否含有指定的样式 **************************************
* Description: 使用正则式与缓存来提高性能
* Maintainers: User:fdcn @zh.wikipedia
* [[en:User:Mike Dillon]], [[en:User:R. Koot]], [[en:User:SG]] @en.wikipedia
*/
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
/*
</pre>
=== 中文處理 ===
<pre>
*/
//设置中文语言页
var htmlE=document.documentElement;
htmlE.setAttribute("lang",wgUserLanguage);
htmlE.setAttribute("xml:lang",wgUserLanguage);
//返回繁簡字串
function wgULS(hans,hant,cn,tw,hk,sg,zh){
return {//保證每一語言有值
'zh-hans':hans||cn||sg,
'zh-hant':hant||tw||hk,
'zh-cn':cn||hans||sg,
'zh-sg':sg||hans||cn,
'zh-tw':tw||hant||hk,
'zh-hk':hk||hant||tw,
'zh':zh||hant||hans||cn||tw||hk||sg
}[wgUserLanguage];
}
/*
</pre>
=== IE兼容性修正 ===
<pre>
*/
function fixIE(){
var oldWidth;
var docEl = document.documentElement;
function fixIEScroll(){
if (!oldWidth || docEl.clientWidth > oldWidth){
doFixIEScroll();
}else{
setTimeout(doFixIEScroll, 1);
}
oldWidth = docEl.clientWidth;
}
function doFixIEScroll() {
docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
}
document.attachEvent("onreadystatechange", fixIEScroll);
attachEvent("onresize", fixIEScroll);
}
if (navigator.appName == "Microsoft Internet Explorer" && document.compatMode == "CSS1Compat"){
fixIE();
}
/*
</pre>
=== 工具提示與快捷鍵 ===
<pre>
*/
ta = {
'ca-article' : ['a',wgULS('浏览条目正文','瀏覽條目正文')],
'ca-nomove' : ['',wgULS('你不能移动这个页面','你不能移動這個頁面')],
'n-Featured_content' : ['',wgULS('查看中文维基百科的特色内容','查看中文維基百科的特色內容')],
'n-indexpage' : ['',wgULS('以分类索引搜寻中文维基百科','以分類索引搜尋中文維基百科')],
'n-commonsupload' : ['',wgULS('把自由版权图片上传到维基共享资源','把自由版權圖片上傳到維基共享資源')],
'n-contact' : ['',wgULS('如何联络维基百科','如何聯絡維基百科')],
'n-villagepump' : ['',wgULS('参与维基百科社群的讨论','參與維基百科社群的討論')],
'n-Information_desk' : ['',wgULS('解答任何与维基百科无关的问题的地方','解答任何與維基百科無關的問題的地方')],
'n-conversion' : ['',wgULS('提出字词转换请求','提出字詞轉換請求')],
'n-allpages' : ['',wgULS('浏览所有页面的清单','瀏覽所有頁面的清單')],
'ca-nstab-project' : ['a',wgULS('查看维基计划页面','查看維基計畫頁面','查看維基計劃頁面')],
'n-policy' : ['',wgULS('查看维基百科的方针和指引','查看維基百科的方針和指引')],
'n-about' : ['',wgULS('查看维基百科的简介','查看維基百科的簡介')]
}
/*
</pre>
=== 特色條目優良與條目鏈接顯示 ===
<pre>
*/
addOnloadHook( function(){
var InterwikiLinks = document.getElementById( "p-lang" );
if ( !InterwikiLinks ) { return; }
forEach( function(link){
if ( document.getElementById( link.className + "-fa" ) ) {
link.className += " FA"
link.title = wgULS("此条目为特色条目。","此條目為特色條目。");
}
if ( document.getElementById( link.className + "-ga" ) ) {
link.className += " GA"
link.title = wgULS("此条目为优良条目。","此條目為優良條目。");
}
},InterwikiLinks.getElementsByTagName("li") );
});
/*
</pre>
=== 編輯工具欄 ===
<pre>
*/
/**
* tip for custom edittools
*
* Maintainers: fdcn@zh.wikipedia
*/
hookEvent("load",function(){
var wpEditToolbar=document.getElementById("toolbar");
if(!wpEditToolbar){return;}
// 增加对未注册用户的提示
if(!mwCustomEditButtons.length){
wpEditToolbar.appendChild( createElement("a","扩展编辑按钮?",{
'href':getWikiPath('Wikipedia:維基百科工具/編輯工具'),
'title':wgULS('注册一个用户,即可以定制自己的编辑按钮','註冊一個賬號,即可以定制自己的編輯按鈕'),
'styles':{'fontSize':'smaller','marginLeft':'1em'}
}));
}
// 有重複按鈕的提示
if(mwCustomEditButtons.state=='rID'){
wpEditToolbar.appendChild( createElement("span"," ! ",{
'title':wgULS('你选择的编辑按钮扩展可能有重复的按钮','你選擇的編輯按鈕擴展可能有重複的按鈕'),
'styles':{'color':'red','cursor':'pointer'}
}));
}
//增加編輯摘要的下拉選單
var wpSummaryLabel=document.getElementById("wpSummaryLabel");
if(!wpSummaryLabel){return;}
var form = document.getElementById('editform');
var summarys={};
var i=0;
function add(label,summary){
var val='summary'+(i++);
summarys[val]=summary;
var option=new Option(label,val);
return menu.options[menu.options.length]=option;
}
var menu=createElement(
"select",
[new Option(wgULS("摘要类型","摘要類型"))],
{id:"summaryMenu",size:1,events:{'change':function(){
var key=menu.options[menu.selectedIndex].value;
var s=summarys[key];
if(s){form.wpSummary.value += ' '+s;}
menu.selectedIndex=0;
}}}
);
add( wgULS('新条目','新條目'), wgULS('新条目','新條目') );
add( wgULS('修饰语句','修飾語句'), wgULS('修饰语句','修飾語句') );
add( wgULS('修正笔误','修正筆誤'), wgULS('修正笔误','修正筆誤') );
add( wgULS('内容扩充','內容擴充'), wgULS('内容扩充','內容擴充') );
add( '排版', wgULS('调整格式、排版','調整格式、排版') );
add( wgULS('段落章节','段落章節'), wgULS('移动或调整段落章节','移動或調整段落章節') );
add( wgULS('内部链接','內部連結'), wgULS('增加或调整内部链接','增加或調整內部連結') );
add( wgULS('跨语言链接','跨語言連結'), wgULS('增加或调整跨语言链接','增加或調整跨語言連結') );
add( wgULS('分类','分類'), wgULS('增加或调整分类','增加或調整分類') );
add( wgULS('小作品标签','小作品標籤'), wgULS('增加或调整小作品标签','增加或調整小作品標籤') );
add( wgULS('字词转换','字詞轉換'), wgULS('增加或调整字词转换代码','增加或調整字詞轉換代碼') );
add( wgULS('消歧义','消歧義'), wgULS('消歧义','消歧義') );
add( wgULS('维基化','維基化'), wgULS('维基化','維基化') );
add( wgULS('标识删除','標識刪除'), wgULS('提交删除讨论或速删','提交刪除討論或速刪') );
add( wgULS('侵权','侵權'), wgULS('提交侵权删除','提交侵權刪除') );
add( wgULS('欢迎','歡迎'), wgULS('欢迎用户','歡迎用戶') );
add( '警告', wgULS('警告用户','警告用戶') );
wpSummaryLabel.appendChild(menu);
//加入對摘要框的限制,以適應中文UTF-8的字節數
var summaryinput=document.getElementById("wpSummary");
if(summaryinput && summaryinput.maxLength)summaryinput.maxLength=83;
});
/*
</pre>
=== 强制预览 ===
<pre>
*/
if ( (wgUserGroups+" ").indexOf("autoconfirmed") == -1 && wgAction == "edit" ) {
addOnloadHook (function(){
var saveButton = document.getElementById("wpSave");
if (!saveButton) return;
saveButton.disabled = true;
saveButton.value += wgULS(" (预览后可用)"," (預覽後可用)");
saveButton.style.fontWeight = "normal";
document.getElementById("wpPreview").style.fontWeight = "bold";
});
}
/*
</pre>
=== 增加摺疊功能 ===
<pre>
*/
/** 摺疊 div table *****************************
* Description: 实现div.NavFrame和table.collapsible的可折叠性。
* JSConfig的collapseText、expandText、autoCollapse属性定义默认文字和默认最少自动折叠块
* Maintainers: User:fdcn
*/
function cancelBubble(e){
e=e||window.event;
if(e.stopPropagation){e.stopPropagation();}else{e.cancelBubble=true;}
}
function createToggleButton(head){
var parent=head;
if( head.tagName.toLowerCase()=='tr' ){//对表格特别处理
if(head.getElementsByTagName("th").length){
parent=head.cells[parent.cells.length-1];
} else {return;}
}
var textS,textH,button=getElementsByClassName(head,"span","NavToggle")[0];
if(button){parent=button.parentNode;} else{
textS=createElement("span",[JSConfig.expandText],{'class':'toggleShow'});
textH=createElement("span",[JSConfig.collapseText],{'class':'toggleHide'});
button=createElement("span",[textS,textH],{'class':'NavToggle',styles:{'width':"3.8em"}});
}
button.style.display="inline";
head.className+=" uncollapse toggleHotspot";
parent.insertBefore( button, parent.childNodes[0] );
}
function wgCollapse(head,container,defaultCollapse){
if(head){ createToggleButton(head); }
var self=this;
this.state=0;
this.container=container;
forEach( function(h){
if ( h.nodeType==1
&& !hasClass(h,"uncollapse")
&& !hasClass(h,"toggleShow")
&& !hasClass(h,"toggleHide")
) { h.className+=" toggleHide"; }
}, defaultCollapse );//预设的隐藏元素
function getArray(clsname){
var r=[],i=0,e,ea=getElementsByClassName(container,"*",clsname);
while(e=ea[i++]){
var parent=e.parentNode;
while(!hasClass(parent,'NavFrame')&&!hasClass(parent,'collapsible')){parent=parent.parentNode;}
if(parent==container){r.push(e);}
}
return r;
}
var toggleA=getArray("toggleShow");
var toggleB=getArray("toggleHide");
var hotspots=getArray("toggleHotspot");
function _toggle(list,state){
var i=0,e;
while(e=list[i++]){e.style.display=state?e.showStyle||'':'none';}
}
this.toggle=function(state){
self.state=(typeof state=='undefined')?1-self.state:state;
_toggle(toggleA,self.state);
_toggle(toggleB,1-self.state);
}
var i=0,h;
while(h=hotspots[i++]){
forEach(function(link){
addClickHandler(link,cancelBubble);
},h.getElementsByTagName("A"));
h.style.cursor = "pointer";
addClickHandler(h,function(){self.toggle();});
}
}
addOnloadHook(function(){
//init
var items=[];
forEach( function(NavFrame){
var i=0,
child=NavFrame.childNodes,
head;
while (head=child[i++]) {
if( head.className&&hasClass(head,"NavHead") ){break;}
}
items.push(new wgCollapse(head,NavFrame,NavFrame.childNodes));
},getElementsByClassName(document,"div","NavFrame") );
forEach ( function(table){
var rows = table.rows;
items.push(new wgCollapse(rows[0],table,rows));
},getElementsByClassName(document,"table","collapsible") );
var item,i=0,count=items.length;
while ( item=items[i++] ) {
item.toggle (
hasClass(item.container,"collapsed")
|| ( count>=JSConfig.autoCollapse&&hasClass(item.container,"autocollapse") )
);
}
});
//修正摺疊後定位變化
hookEvent("load",function(){if(location.hash){location.href=location.hash;}});
/*
</pre>
=== 首頁輸出修正 ===
<pre>
*/
/** 首页输出修正 *******************************************************
描述:
维护者: [[User:Fdcn]]
*/
// "首頁" == wgTitle 代表重定向頁
if ( wgTitle == '首页' && ( wgNamespaceNumber == 0 || wgNamespaceNumber == 1 ) ) {
addOnloadHook( function () {
try {
var Node = document.getElementById( 'ca-nstab-main' ).firstChild;
var label = wgULS('首页','首頁');
if ( Node.textContent ) { // Per DOM Level 3
Node.textContent = label;
} else if ( Node.innerText ) { // IE doesn't handle .textContent
Node.innerText = label;
} else { // Fallback
Node.replaceChild( Node.firstChild, document.createTextNode( label ) );
}
} catch(e) {}// bailing out!
} );
if(wgNamespaceNumber == 0){
addOnloadHook( function () {
addPortletLink('p-lang', getWikiPath('Wikipedia:维基百科语言列表'),
wgULS('维基百科语言列表','維基百科語言列表'), 'interwiki-completelist',wgULS('维基百科的完整各语言列表', '維基百科的完整各語言列表'));
});
}
}
/*
</pre>
=== 取消修訂編輯摘要修正 ===
<pre>
*/
/**
fix edit summary prompt for undo
this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the edit summary unchanged
this was added by [[:en:User:Deskana]], code by [[:en:User:Tra]]
*/
addOnloadHook(function () {
var autoSummary=document.getElementsByName('wpAutoSummary')[0];
if (document.location.search.indexOf("undo=") != -1 && autoSummary)
{ autoSummary.value=''; }
})
/*
</pre>
=== 取消討論頁的[+]按鈕 ===
<pre>
*/
addOnloadHook(function () {
if(document.getElementById('no-newsection') && document.getElementById('ca-addsection')) {
document.getElementById('ca-addsection').style.display="none";
}
});
/*
</pre>
=== [[Special:Search]]其他搜尋引擎連結表單 ===
<pre>
*/
var searchEngines=[];
var createSearchForm;//可在用户皮肤JS中自行增加引擎。
function SpecialSearchEnhanced()
{
if (
JSConfig.SpecialSearchEnhancedDisabled ||
wgCanonicalNamespace != "Special" ||
wgCanonicalSpecialPageName != "Search"
){return;}
if(skin == "monobook" || skin == "cologneblue" || skin == "simple"){
var mainNode = document.getElementsByTagName("form")[0];
}
if (!mainNode) return;
var searchbox=document.getElementById("lsearchbox");
var div= createElement("div",null,{styles:{'width':"100%",'textAlign':'center'}});
mainNode.appendChild(div);
/**
* 建立一个搜索引擎
*/
createSearchForm=function(engine_name, engine_url, logo_url, search_action_url,
search_field_name, add_search_field, field_array, logo_width, logo_height)
{
var input=createElement("input",null,{'type':"hidden",'name':search_field_name})
var inputs = [input];
for( var k in field_array){
inputs.push(createElement(
"input",null,{'type':"hidden",'name':k,'value':field_array[k]}
));
}
inputs.push(createElement(
"input",null,{'type':"submit",'value':wgULS('搜索','搜尋')}
));
var form = createElement("form",inputs,
{
'method':"get",
'action':search_action_url,
'styles':{'display':"inline"},
'events':{'submit':function(){input.value = searchbox.value+add_search_field;}}
}
);
var img = createElement("img",null,{
'src':logo_url,
'alt':engine_name,
'styles':{'borderWidth':"0",'padding':"5px",'width':logo_width||'135px','height':logo_height||'35px'}
});
var a = createElement("a",[img],{'href':engine_url});
var span= createElement("span",[form,a],{styles:{'marginRight':"1em"}});
searchEngines.push(span);
searchEngines[engine_name]=span;
div.appendChild(span);
}
//於此開始列示各引擎。
//google
createSearchForm(
"Google","http://www.google.com/",
"http://www.google.com/logos/powered_by_google_135x35.gif",
"http://www.google.com/search","q", "",
{"as_sitesearch": "zh.wikipedia.org"},
"77px","20px"
);
//live search
createSearchForm(
"Live", "http://search.live.com/",
"http://upload.wikimedia.org/wikipedia/zh/thumb/1/17/Mslivelogo.png/120px-Mslivelogo.png",
"http://search.live.com/results.aspx","q", "",
{"q1":"site:zh.wikipedia.org"},
'100px','20px'
);
//yahoo
createSearchForm(
"Yahoo!", "http://www.yahoo.com/",
"http://upload.wikimedia.org/wikipedia/zh/thumb/a/ad/Yahoo_Logo.svg/135px-Yahoo_Logo.svg.png",
"http://search.yahoo.com/search","p", "",
{"vs": "zh.wikipedia.org","ei":"UTF-8"},
'80px','15px'
);
//zhosisterps
createSearchForm(
"中文系維基跨計劃搜尋", "http://www.google.com/coop/",
"http://www.google.com/coop/images/google_coop_sm.gif",
"http://www.google.com/"+"cse","q","",
{"cx":"009212467671870524522:mw9ug06rtl4","cof":"FORID:0","sa":"Search"},
"51px","20px"
);
//zhsisterps
createSearchForm(
"中文维基媒体搜索", "http://www.google.com/coop/",
"http://www.google.com/coop/images/google_coop_sm.gif",
"http://www.google.com/"+"cse","q","",
{"cx":"012948615710733534834:sce7kigca9g","cof":"FORID:0","sa":"Search"},
"51px","20px"
);
}
addOnloadHook(SpecialSearchEnhanced); //啟動Search Engine
/*
</pre>
=== WikiMiniAtlas世界地圖 ===
<pre>
*/
/** WikiMiniAtlas *******************************************************
*
* 描述:WikiMiniAtlas是一個popup而可點選與拖曳的世界地圖。
* 這個腳本將會讓所有的經緯度標示中顯示WikiMiniAtlas的popup開啟按鈕。
* 由於被許多計畫使用,因此腳本放置在元維基中。
* 更多資訊請詳見[[Meta:WikiMiniAtlas]]。
* 創建者:[[:en:User:Dschwen]]
*/
importScript('m:MediaWiki:Wikiminiatlas.js');
/*
</pre>
*/