MediaWiki:Common.js

Aus BS-Wiki: Wissen teilen
Version vom 1. Dezember 2011, 05:12 Uhr von Dg (Diskussion | Beiträge)
(Unterschied) nächstältere Version→ | Aktuelle Version (Unterschied) | ←nächstjüngere Version (Unterschied)
Wechseln zu: Navigation, Suche
/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */
// <source lang="javascript">
//============================================================
// en: ADD SOME EXTRA BUTTONS TO THE EDITPANEL [[:en:User:MarkS/Extra edit buttons]]
// de: FÜGE NEUE BUTTON IN DIE WERKZEUGLEISTE [[:de:Benutzer:Olliminatore/Extra-Editbuttons]]
//   Converted by [[User:Olliminatore]] 25.09.2006 
//============================================================
// de: Die Reihenfolge und Anzahl der Buttons ist über die (alphabetische) Variable customEditButtons wählbar.

var XEBOrder=[];
var attributes = ["imageFile","speedTip","tagOpen","tagClose","sampleText"];
// isMSIE55

//fills the variable mwCustomEditButtons (s. function in /wikibits.js), with buttons for the toolbar  
function addCustomButton(){
 var a = {};
 for (d in attributes) a[attributes[d]] = arguments[d];
 mwCustomEditButtons.push(a);
};

if (typeof usersignature == 'undefined') var usersignature = '-- \~\~\~\~';

var Isrc='http://upload.wikimedia.org/wikipedia/commons/';
var BDict={
// pro Forma auch Standardbuttons listen, andernfalls Skriptfehler beim Auslesen von BDict
'0':['fett'],
'1':['kursiv'],
'2':['in-Link'],
'3':['www-Link'],
'4':['Bild'],
'5':['Mediendatei'],
'6':['Überschrift'],
     '7':['Formel'],
'8':['<nowiki>'],
'9':['Signatur'],
'10':['Linie'],
'A':['e/e9/Button_headline2.png','Sekundäre Überschrift','\n=== ',' ===','Sekundäre Überschrift'],
     'A3':['/3/3a/Button_headline3.png','Untergeordnete Überschrift','\n==== ',' ====','Untergeordnete Überschrift'],
'B':['1/13/Button_enter.png','Zeilenumbruch','<br />','',''],
     'B1':['6/62/Button_desambig.png','Begriffsklärungseite','{{Begriffsklärung}}','',''],
     'B3':['5/5e/Button_disambig_small.png','Begriffsklärungshinweis','{{Begriffsklärungshinweis}}','',''],
'C':['5/5f/Button_center.png','Zentriert','<div style="text-align: center;">\n','\n<\/div>','Zentriert'],
     'CF':['3/37/Btn_toolbar_commentaire.png','Chemische Formel',':<math>\u005Cmathrm{','}</math>',''],
     'CO':['6/6c/Button_commons.png','Commons','{{Commons|Category:','}}','Seitenname'],
     'D':['e/ea/Button_align_left.png','Left-Align','<div style="text-align: left; direction: ltr; margin-left: 1em;">\n','\n<\/div>','Left-aligned Text'],
     'DS':['4/4e/Button_romain.png','DEFAULTSORT','{{DEFAULTSORT:','}}','Sortierbegriff'],
     'DO':['e/e9/Button_done.png','Erledigt (kurz)','{{Erl.}}','',''],
     'ER':['9/9d/Button_fait.png','Erledigt (lang)','{{Erledigt|1=' + usersignature,'}}',''],
     'E':['0/04/Button_array.png','Tabelle','\n{| class="prettytable" \n|- \n| 1 || 2\n|- \n| 3 || 4','\n|}\n',''],
     'F':['8/8f/Button_poeme.png','Farbiger Text','<span style="color: color">','<\/span>','Farbig'],
'FO':['/5/5b/Math_icon.png','Formel','\n{\{Formel|1=','}}\n','E = mc²'],
     'FS':['1/1b/Button_miss_signature.png','Fehlende Signatur','\{\{subst\:Unsigned|','3='+usersignature+'}}',''],
'H':['7/74/Button_comment.png','Versteckter Kommentar',"<!--","-->",'Versteckt'],
     'I':['4/41/Button_hr_halfwidth.png','Gedankenstrich','–','',''],
'I1':['6/6a/Button_sup_letter.png','Hochgestellter Text (superscript)','<sup>','<\/sup>','Hochgestellt'],
'I2':['a/aa/Button_sub_letter.png','Tiefgestellter Text (subscript)','<sub>','<\/sub>','Tiefgestellt'],
'J1':['5/58/Button_small.png','Kleingeschriebener Text (small)','<small>','<\/small>','Klein'],
'J2':['5/56/Button_big.png','Größerer Text (big)','<big>','<\/big>','Groß'],
'K':['b/b4/Button_category03.png','Kategorie',"[[Kategorie:","]]",'Name der Kategorie'],
     'KR':['b/b1/Button_dagger.png','Kreuz','†','',''],
     'L':['8/8e/Button_shifting.png','Setze Tab(s)',':','',':'],
'M':['f/fd/Button_blockquote.png','Markiert ein Zitat mit Absatz','<blockquote style="border: 1px solid blue; padding: 2em;">\n','\n<\/blockquote>','Text'],
'MA':['3/3d/Button_marker.png','Textmarker','{{Mark\n|','}}','Textmarker'],
'N':['4/4b/Button_nbsp.png','Geschütztes Leerzeichen (nonbreaking space)','&nbsp;','',''],
     'NT':['b/bf/Button_thinsp.png','Schmales geschütztes Leerzeichen','&thinsp;','',''],
     'O':['2/23/Button_code.png','Code einfügen','<code>','<\/code>','Code'],
     'P':['3/3c/Button_pre.png','Vorformatierter Text','<pre>','<\/pre>','Präformatierter Text'],
     'P1':['9/93/Button_sub_link.png','Link zu einem Seiten-Abschnitt','[[Seite#',']]','Abschnitt'],
'PF':['f/ff/Button_arrow_right.png','Pfeil nach rechts','[[Bild:Pfeil.gif]]','',''],
'Q':['d/d3/Button_definition_list.png','Definitionsliste','\n; ',' : ','Text'],
'Q1':['0/05/Button_Anf%C3%BChrung.png','Anführungszeichen',"„","“",'Text'],
     'Q2':['2/26/Button_latinas.png','Latinas',"«","»",'Text'],
     'Q3':['b/bc/Button_guillemet.png','Guillemets',"»","«",'Text'],
     'R':['7/79/Button_reflink.png','Markiere eine Referenz','<ref>','<\/ref>','Bezugsangabe'],
     'R1':['c/c4/Button_ref.png','Referenz mit Name','<ref name="">','<\/ref>','Bezugsangabe'],
     'R2':['f/fe/Button_refs.png','Wiederholungs-Referenz','<ref name="','"/>','Referenzname'],
     'R3':['9/9a/Button_references.png','Referenz-Footer','\n== Einzelnachweise ==\n<references/>\n','',''],
     'RD':['7/70/Button_fusion.png','Redundanz','{{subst:Redundanz|','}}','Artikel1|Artikel2|Artikel3…'], 
'S':['c/c9/Button_strike.png','Durchgestrichener Text',"<s>","<\/s>",'Durchgestrichen'],
     'SA':['b/bb/Seealso.png','Siehe auch','\n== Siehe auch ==\n','',''],
     'SC':['0/02/Button_S_yellow.png','SourceCode hervorheben','<source lang="javascript">',"<\/source>",'Quelltext'], 
     'SM':['7/74/Button_oeil.png','Smiley','<tt style="background:#FE3">','</tt>',':D'],
     'ST':['7/72/Button_span_2.png','span-tag mit CSS-Angabe','<span style="">','<\/span>','Markierter Inhalt'],
'T':['e/eb/Button_plantilla.png','Vorlage','{{','}}','Vorlagenname'],
'T1':['b/ba/Search_button_bckg.png','Abstand (ohne Funktion)','','',''],
'T2':['b/ba/Search_button_bckg.png','Abstand (ohne Funktion)','','',''],
'T3':['b/ba/Search_button_bckg.png','Abstand (ohne Funktion)','','',''],
'T4':['b/ba/Search_button_bckg.png','Abstand (ohne Funktion)','','',''],
     'TL':['e/eb/Button_templatelink.png','Vorlagenlink','{{[[Vorlage:','|]]}}','Vorlagenname'],
'TT':['3/30/Tt_icon.png','Schreibmaschinenstil','<tt>','<\/tt>','Teletyper Text'],
'U':['f/fd/Button_underline.png','Unterstreichen',"<u>","<\/u>",'Unterstrichener Text'],
     'UR':['e/ec/Button_aviso.png','Urheberrecht ungeklärt',"{{Urheberrecht ungeklärt}}","",''],
     'URV':['9/9d/Button_halt.png','Urheberrechtsverletzung',"{{URV}} [","] " + usersignature,'Url'],
'V':['c/c8/Button_redirect.png','Weiterleitung (Redirect)',"#REDIRECT [[","]]",'Ziel einfügen'],
     'VP':['b/ba/Button_conserver.png','Vote *pro*',"# {{pro}} " + usersignature,"",''],
     'VC':['f/fc/Button_supp.png','Vote *contra*',"# {{contra}} " + usersignature,"",''],
     'VN':['4/4e/Button_neutre.png','Vote *neutral*',"# {{neutral}} " + usersignature,"",''],
     'WB':['6/61/Button_wikibooks.png','Wikibooks',"{{Wikibooks","}}",'|Seitenname'],
     'WS':['e/eb/Button_wikisource.png','Wikisource',"{{Wikisource","}}",'|Seitenname'],
     'WT':['b/bf/WP-icon.png','Wiktionary',"{{Wiktionary","}}",'|Seitenname'],
     'WV':['b/b5/Button_wikiversity.png','Wikiversity',"{{Wikiversity","}}",'|Seitenname'],
'W':['8/88/Btn_toolbar_enum.png','Nummerierung',"\n# Element 1\n# Element 2\n# Element 3","",''],
     'X':['1/11/Btn_toolbar_liste.png','Liste',"\n* Element A\n* Element B\n* Element C","",''],
'Y1':['c/ce/Button_no_include.png','No Include',"<noinclude>","<\/noinclude>",'Text'],
'Y2':['7/79/Button_include.png','Include only',"<includeonly>","<\/includeonly>",'Text'],
     'Z':['3/35/Button_substitute.png','Substitute',"{{subst:","}}",'Vorlage'],

};

if (typeof customEditButtons!='string') // can be modified
//XEBOrder="A,A3,B,E,F,G,H,I1,I2,J1,K,M,Q,R,R1,R2,R3,S,T,U,V,W,X".split(",");
//XEBOrder="T1,U,I1,I2,F,MA,C,E,T1,K,V,T2,T,A,W,X,T3,N,PF,B,T4,H,0".split(",");
//XEBOrder="0,1,U,I1,I2,F,MA,C,E,T1,2,3,5,6,K,V,T2,T,4,A,W,X,10,T3,N,PF,B,T4,8,H,9".split(",");
//XEBOrder="0,1,2,3,4,5,6,7,8,9,A,10,B,E,F,I1,I2,K,MA,PF,TT,U,V,W".split(",");
XEBOrder="0,1,U,I1,I2,F,MA,J1,J2,C,E,T1,2,3,5,6,K,V,T2,FO,T,4,A,W,X,10,T3,N,PF,B,T4,8,H,9".split(",");


else if (customEditButtons.toLowerCase()=='all') 
	for (b in BDict) XEBOrder.push(b);
else XEBOrder=customEditButtons.split(",");


function initButtons(){
  var bc,d;
	for (b in BDict) BDict[b][0] = Isrc+BDict[b][0]; // // Add the start of the URL (Isrc) to the XEB buttons
	// If the user has defined any buttons then add them into the available button lists 
	if (typeof myButtons=='object')
	  for (b in myButtons) BDict[b] = myButtons[b];	// custom user buttons
  // Add the media wiki standard buttons into the available buttons 
	for (b in mwEditButtons) { // add standard buttons for full XEB order changing
		BDict[b]=[];
	//	for (d in mwEditButtons[b]) 
		for (d in attributes) BDict[b].push(mwEditButtons[b][attributes[d]]);
	}
	
	// Build the new buttons 
	for (i=0;i<XEBOrder.length;i++) {
		bc = BDict[XEBOrder[i]];
		//try { // catch not existing button names
		addCustomButton(bc[0],bc[1],bc[2],bc[3],bc[4]);
		//}
		// catch(e) {continue}
	}
	// Remove the default buttons (if requested by the user)
eraseButtons();
};

//============================================================
// Table generator 
//============================================================
/** en: Generate an array using Mediawiki syntax
* @author: originally from fr:user:dake
* @version: 0.2 */
function generateTable(caption, exhead, nbCol, nbRow, exfield, align){
	var code = "\n{| {{Tabelle";
	code += '}}\n ' + align + '\n'
		+ caption + exhead;
	if (exfield) code += '!\n';
	for (i=1;i<nbCol+1;i++) code += '! Spalte ' + i + '\n';
	var items = 0;
	for (var j=0;j<nbRow;j++){
		if (exfield) { 
			items++;
			code += '|-\n! style="background: #FFDDDD;"|ITEM ' + items + '\n';
		}	else code += '|-\n';
                var zeile = j+1;
                
		for (i=0;i<nbCol;i++){
                   var spalte = i+1;
                   code += '| Feld ' + spalte + '-' + zeile + '\n';
}
	}
	code += '|}\n';
	insertTags('','', code);
	editform.elements['wpSummary'].value+=' table+';
	return false
};


/** en: Open a popup with parameters to generate an array. 
* The number of rows/columns can be modified.
* @author: originally fr:user:dake 
* @version: 0.2 */
function popupTable(){
  var popup = window.open('about:blank','WPtable','height=500,width=400,scrollbars=yes');
  var javaCode = '<script type="text\/javascript">function insertCode(){'
  +'var caption = (document.paramForm.inputCaption.checked)?"\|\+ Tabellenüberschrift \\n":""; '
  +'var exhead = (document.paramForm.inputHead.checked)?\'\|\- style=\"background: #DDFFDD;\"\\n\':""; '
  +'var row = parseInt(document.paramForm.inputRow.value); '
  +'var col = parseInt(document.paramForm.inputCol.value); '
  +'var exfield = document.paramForm.inputItems.checked; '
  +'var align = (document.paramForm.inputAlign.checked)?\'align="center"\':""; '
  +'window.opener.generateTable(caption,exhead,col,row,exfield,align); '
  +'window.close()}<\/script>';
  
  popup.document.write('<html><head><title>Make table<\/title>'
// +'<script type="text\/javascript" src="\/skins-1.5\/common\/wikibits.js"><\/script>'
//+'<style type="text\/css" media="screen,projection">/*<![CDATA[*/ @import "\/skins-1.5\/monobook\/main.css?5"; /*]]>*/<\/style>'
  + javaCode +'<\/head><body>'
  +'<p>Wie soll die Tabelle aussehen? <\/p>'
  +'<form name="paramForm">'
  +'mit Überschrift: <input type="checkbox" name="inputCaption"><p\/>'
  +'Ausrichtung: center<input type="checkbox" name="inputAlign"><p\/>'
  +'Kopfzeile farbig:<input type="checkbox" name="inputHead"><p\/>'
  +'Anzahl der Zeilen: <input type="text" name="inputRow" value="3" size="2"><p\/>'
  +'Anzahl der Spalten: <input type="text" name="inputCol" value="3" size="2"><p\/>'
  //+'Alternating grey lines: <input type="checkbox" name="inputLine" checked="1" ><p\/>'
  +'Köpfe: <input type="checkbox" name="inputItems" ><p\/>'
  +'<\/form">'
  +'<p><a href="javascript:insertCode()"> Tabelle einfügen<\/a> &nbsp;&nbsp;&nbsp; |'
  +' &nbsp;&nbsp;&nbsp;<a href="javascript:self.close()">Abbruch<\/a><\/p>'
  +'<\/body><\/html>');
  popup.document.close();
  return false
};

/** en: Removes arbitrary standard buttons from the toolbar
* @author: [[:de:User:Olliminatore]]
* @version: 0.2 (01.10.2006) **/
function eraseButtons(){
rmEditButtons=['all'];
	if(typeof rmEditButtons!='object') return;
	if (rmEditButtons[0].toLowerCase() == 'all') 
//	if (typeof rmEditButtons[0] == 'string' && rmEditButtons[0].toLowerCase() == 'all') 
		return mwEditButtons=[];
	//Remove the buttons the user doesn't want 
	for(i=0;i<rmEditButtons.length;i++){
		var n=rmEditButtons[i]-i;
		if(n>=0 && n<mwEditButtons.length){
			if(n<mwEditButtons.length){
				var x = -1;
				while((++x)<mwEditButtons.length)
					if(x>=n)
						mwEditButtons[x] = mwEditButtons[x+1];
			}
		mwEditButtons.pop();
		}
	}
};

addOnloadHook(initButtons);

// Adds extended onclick-function to some buttons 
function extendButtons(){
	if(!(allEditButtons = document.getElementById('toolbar'))) return false;
	if(typeof editform == 'undefined')
		if(!(window.editform = document.editform)) return false;

	XEBOrder.getIndex = function (item){
	 if(is_gecko) return this.indexOf(item);
	 else //is IE (Opera < 9)
		 for (var i=0;i < this.length;i++) if (this[i]==item) return Number(i);
   	return -1
	}
	var searchbox = allEditButtons.getElementsByTagName('span')[0];
	if (searchbox) allEditButtons.appendChild(searchbox) // pay Zocky/Search Box
	
	allEditButtons = allEditButtons.getElementsByTagName('img');

	var bu_len = mwEditButtons.length;
	var c=0;

	if(!allEditButtons.length) return false;

	// own signature
	if (bu_len>0){
		if(typeof rmEditButtons=='object' && rmEditButtons.pop()==10) c=1;
			mwEditButtons[bu_len-2+c].tagOpen=usersignature;
		if(usersignature != '-- \~\~\~\~')
			allEditButtons[bu_len-2+c].src=Isrc+'d/d1/Button_mysignature.png';
	}

	//  table
	if((c=XEBOrder.getIndex('E')) != -1) allEditButtons[bu_len+c].onclick=popupTable;

	//  farbwahl
	if((c=XEBOrder.getIndex('F')) != -1) allEditButtons[bu_len+c].onclick=popupfarbe;

	// spacer width
	if((c = XEBOrder.getIndex('T1')) != -1) allEditButtons[bu_len+c].width = 6;
};

//============================================================
// Farbwahl
//============================================================
/** de: Textfarbe wählen
* @author: originally from de:user:dg.de
* @version: 2008-03-06 */
function popupfarbe(){
  var popup = window.open('about:blank','WPtable','height=80,width=240');
  var javaCode = '<script type="text\/javascript">function insertCode(farbe){'
  +'window.opener.generateFarbe(farbe); '
  +'window.close()}<\/script>';
  
  popup.document.write('<html><head><title>Farbwahl<\/title>'

  + javaCode +'<\/head><body>'
  +'<p>Welche Farbe soll der Text haben? <\/p>'
//  +'<form name="paramForm">'
+ '<select onchange="insertCode(this.value)">'
+ '<option value="black" style="color:black">&#x2588;&#x2588; Schwarz'
+ '<option value="maroon" style="color:maroon">&#x2588;&#x2588; Rotbraun'
+ '<option value="purple" style="color:purple">&#x2588;&#x2588; Violett'
+ '<option value="navy" style="color:navy">&#x2588;&#x2588; Dunkelblau'
+ '<option value="blue" style="color:blue">&#x2588;&#x2588; Blau'
+ '<option value="aqua" style="color:aqua">&#x2588;&#x2588; Hellblau'
+ '<option value="oliv" style="color:oliv">&#x2588;&#x2588; Oliv'
+ '<option value="teal" style="color:teal">&#x2588;&#x2588; teal'
+ '<option value="green" style="color:green">&#x2588;&#x2588; Grün'
+ '<option value="lime" style="color:lime">&#x2588;&#x2588; Limone'
+ '<option value="yellow" style="color:yellow">&#x2588;&#x2588; Gelb'
+ '<option value="orange" style="color:orange">&#x2588;&#x2588; Orange'
+ '<option value="red" style="color:red">&#x2588;&#x2588; Rot'
+ '<option value="fuchsia" style="color:fuchsia">&#x2588;&#x2588; Pink'
+ '<option value="white" style="color:white">&#x2588;&#x2588; Weiß'
+ '<option value="silver" style="color:silver">&#x2588;&#x2588; Silber'
+ '<option value="gray" style="color:gray">&#x2588;&#x2588; Grau'
+ '</select>'
//  +'</form>'
  +'<\/body><\/html>');
  popup.document.close();
  return false
};

function generateFarbe(farbe){
	var code = '<span style="color: ';
	code += farbe;
	code += '">';
	insertTags(code,"</span>",'Text');
	editform.elements['wpSummary'].value+=' table+';
	return false
};

if(!wgIsArticle) // only if edit
	hookEvent("load", extendButtons);
//</nowiki></pre>