MediaWiki:MediaWiki:Onlyifediting.js

aus WB Wiki; freien Wissensdatenbank rund ums Thema Computer
Version vom 16. November 2008, 22:27 Uhr von DerZong (Diskussion | Beiträge)

(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Bitte beachte: Um die Einstellungen im Browser zu übernehmen, muss die Seite ggf. neu geladen werden:

Mozilla/Firefox: Strg-Shift-R, IE: Strg-F5, Safari: Cmd-Shift-R, Konqueror: F5. </div>

/* <pre><nowiki> */
 // wird in [[MediaWiki:Monobook.js]] ganz unten eingebunden

 //================================================================================
 // Optionen für das Sonderzeichenmenü in [[MediaWiki:Edittools]]
 
 // Diese Variablen können in den Benutzer-Javascripts angepasst werden
 var SpecCharsMove = true;
 SpecCharsAccesskeys = new Array();

 function addCharSubsetMenu() {
        var toolbar = document.getElementById('toolbar');
        var specialchars = document.getElementById('specialchars');
        if (specialchars) {
                var menu = "\n\r<select id=\"CharSelect\" name=\"CharSelect\" tabindex=\"8\" accesskey=\"a\" style=\"display:inline; vertical-align:middle\" onChange=\"chooseCharSubset(selectedIndex)\">";
                var l = document.getElementById('specialchars').getElementsByTagName('p');
 
                for(var i=0; i < l.length; i++) {
                        if(l[i].className == "specialbasic" || l[i].className == "speciallang") {
                                var charname = l[i].title;
                                menu += "<option>" + charname + "</option>";
                        }
                }
                menu += "</select>";
                specialchars.innerHTML = menu + specialchars.innerHTML;
 
                // Standard-CharSubset oder aus Cookie
                var stdsubset = 0;
                if (GetCookie ("CharSubset")) stdsubset = GetCookie ("CharSubset");
                document.editform.CharSelect.options[stdsubset].selected = true;
                chooseCharSubset(stdsubset);

                //Umhängen von Specialchars in die Toolbar
                if (SpecCharsMove) { 
                        if (toolbar) { 
                                toolbar.appendChild(specialchars.parentNode.removeChild(specialchars));
                                toolbar.className='toolbar'; 
                        } 
                }
        }
        //Gleicher Tabindex für alle Elemente der Toolbar
        if (toolbar) {
                var charlinks = toolbar.getElementsByTagName('a');
                for (var i=0; i < charlinks.length; i++) {
                    charlinks[i].setAttribute("tabindex",8);
                }
        }
 }

 // CharSubset-Auswahl
 function chooseCharSubset(s) {
	if (SpecCharsAccesskeys.length==0) {
		if (is_opera) SpecCharsAccesskeys = new Array("!","\"","§","$","%","&","/","(",")","=");
		else SpecCharsAccesskeys = new Array("1","2","3","4","5","6","7","8","9","0","!","\"","§","$","%","&","/","(",")","=");
	}
	if (s>=0) {
		var l = document.getElementById('specialchars').getElementsByTagName('p');
		for (var i = 0; i < l.length ; i++) {
			if (i==s) {
				l[i].style.display = 'inline';  
				SetArrayAccessKeys(l[i].getElementsByTagName('a'), SpecCharsAccesskeys);
			} 
			else {
				l[i].style.display =  'none';
			}
		}
		if (GetCookie ("CharSubset") && (i = GetCookie ("CharSubset")) != s) {
			SetArrayAccessKeys(l[i].getElementsByTagName('a'),"");
		}
		SetCookie ("CharSubset",s);
	} 
 }

 // Ein Array von Accesskeys an ein Array von Elementen
 function SetArrayAccessKeys(elements, keys) {
 	for (var i =0; i < elements.length;i++) {
		if (i < keys.length) {
			elements[i].setAttribute("accessKey",keys[i]);
			elements[i].setAttribute("title","alt-"+keys[i]);
		} 
		else {
			elements[i].setAttribute("accessKey","");
			elements[i].setAttribute("title","");
		}
	}
 }

 // Menü-Einfügung
 function customizeWikipedia() {
	AddMyChars();
	addCharSubsetMenu();
 }

 // Vorfunktion für eigene Sonderzeichenleiste, nutzt globale Variablen
 function AddMyChars() {
	 if (MyChar[0]) AddMyCharsDo(MyChar, MyCharEnd, MyCharText, MyCharDefault);
 }

 // Eigene Sonderzeichenliste
 function AddMyCharsDo(thechar, thecharend, thechartext, thechardefault) {
	var specialcharslist = document.getElementById('specialchars');
 
	var addtext = "<p class=\"specialbasic\" id=\"Eigene\" title=\"Eigene\" style=\"display: none;\">\n\r";
	addtext += "Eigene Zeichen:\n\r";
	addtext += "<font style=\"text-decoration: none;\" face=\"Arial Unicode MS,Lucida Sans Unicode,MS Mincho,Arial,sans-serif\">";
  
	for (var i = 0; i < thechar.length; i++) {
		if (!thecharend[i]) thecharend[i]="";
		if (!thechardefault[i]) thechardefault[i]="";
		jsfunction ="insertTags('" + thechar[i] + "','" + thecharend[i] + "','" +  thechardefault[i] +"')";
		//Autoinkrement-Funktion einsetzen
		if (thechardefault[i].charAt(0) == "+" && !isNaN(parseInt(thechardefault[i].substr(1)))) {
			jsfunction = "insertTagsValue('" + thechar[i] + "','" + thecharend[i] + "','" +  thechardefault[i] + "','" + i +"')";
		}
		if (!thechartext[i]) thechartext[i] = thechar[i]+" "+thecharend[i];
		addtext += "<a href=\"javascript:" +jsfunction +"\">" + thechartext[i] + "</a>\n\r";
	}
	addtext += "</font></p>";
	specialcharslist.innerHTML = addtext+specialcharslist.innerHTML;
 }

 // Autoinkrement-Tags
 function insertTagsValue(uchar, ucharend, uchardefault, ucharnr) {
	var txtarea = document.editform.wpTextbox1;
 
	if (document.selection  && !is_gecko) {
		// IE
		var theSelection = document.selection.createRange().text;
	} 
	else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
		// Mozilla
		var replaced = false;
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		if (endPos-startPos)
			replaced = true;
		var scrollTop = txtarea.scrollTop;
		var theSelection = (txtarea.value).substring(startPos, endPos);
	}
	
	if (theSelection == "") {
		if (!(lastVal = GetCookie("CharDefaultValue-"+ ucharnr))) lastVal ="0";
		theSelection= parseInt(lastVal) + parseInt(uchardefault.substr(1));
		theSelection= theSelection.toString();
	}
 
	SetCookie("CharDefaultValue-"+ ucharnr,theSelection);
	insertTags(uchar,ucharend,theSelection);
 }
 
 // onload einbinden
 addLoadEvent(customizeWikipedia);

 //================================================================================
 //## replace
 
 // anscheinend ungenutzt, siehe ende dieses abschnitts

 // Replace-Button
 function AddReplaceButton() {
	var ButtonHTML = "<a href=\"javascript:stringReplaceBox();\"><img src=\"http://upload.wikimedia.org/wikipedia/commons/5/59/Button_replace.png\" alt=\"Text ersetzen\" title=\"Text ersetzen\" border=\"0\" height=\"22\" width=\"23\"></a>";
	var toolbar = document.getElementById("toolbar");
	if (toolbar)	toolbar.innerHTML	+= ButtonHTML;
 }

 function stringReplaceBox() {
	Valreplace=GetCookie ("StrReplace");
	Valreplacement=GetCookie ("StrReplacement");
	if (Valreplace && Valreplacement) {
		//Anführungszeichen ersetzen
		Valreplace=Valreplace.replace(/"/g,"&#34;");
		Valreplacement=Valreplacement.replace(/"/g,"&#34;");
	} else {
		Valreplace="";
		Valreplacement="";
	}

	PromptWin = window.open("about:blank", "PromptWin", "width=280,height=120,dependent=yes,location=no,menubar=no,resizable=yes,status=no,toolbar=no");
	PromptWin.focus();

	PromptWin.document.open();
	PromptWin.document.write("<title>Text ersetzen</title>");
	PromptWin.document.write("<body style=\"background-color: threedface;\">");
	PromptWin.document.write("<form id=\"replaceform\" name=\"replaceform\" method=POST action=\"javascript:void(0)\">");
	PromptWin.document.write("<center><table border=\"0\">");
	PromptWin.document.write("<tr><td style=\"font: message-box\">ersetzen:</td> <td><input type=TEXT name=\"valreplace\" value=\"" + Valreplace + "\" size=25 tabindex=\"1\"></td></tr>");
	PromptWin.document.write("<tr><td style=\"font: message-box\">durch:</td> <td><input type=TEXT name=\"valreplacement\" value=\"" + Valreplacement + "\" size=25 tabindex=\"2\"></td></tr></table>");
	PromptWin.document.write("<p><input type=SUBMIT value=\"&nbsp;OK&nbsp;\" tabindex=\"3\" onclick=\"opener.stringReplace(document.replaceform.valreplace.value,document.replaceform.valreplacement.value); self.close()\"> ");
	PromptWin.document.write("<input type=RESET value=\"Abbrechen\" tabindex=\"4\" onclick=\"self.close()\"></p>");
	PromptWin.document.write("</center></form></body>");
	PromptWin.document.close();
	PromptWin.document.replaceform.valreplace.select();
 }

 function stringReplace(inReplace,inReplacement) {
	SetCookie ("StrReplace", inReplace);
	SetCookie ("StrReplacement", inReplacement);
	var StrReplace = new RegExp(inReplace, "g");
	var StrReplacement=inReplacement;

	if (document.editform) {
		var txtarea = document.editform.wpTextbox1;
	}
	else {
		// some alternate form? take the first one we can find
		var areas = document.getElementsByTagName('textarea');
		var txtarea = areas[0];
	}
	txtarea.value = txtarea.value.replace(StrReplace, StrReplacement);
 }
 
 // Achtung! Wenn man den hier einschaltet, funktioniert die Toolbar nicht mehr!
 //addLoadEvent(AddReplaceButton);

 //================================================================================
 //## proofreading
 
 //Height of ProofReadDiv
 var DivHeight = 0;

 function ProofReading () {
	if (window.location.search.indexOf("image=") != -1) {
	   if (window.location.search.indexOf("image=/wiki/") != -1) {
		   var ImageString = window.location.search.substring(window.location.search.indexOf("image=/wiki/")+12,window.location.search.length);
	   } 
	   else {
		   var ImageString = window.location.search.substring(window.location.search.indexOf("image=")+6,window.location.search.length);
	   }
	   if (ImageString != "") {
			TextBoxRows= document.getElementsByName("wpTextbox1")[0].getAttribute('rows');
			TextBoxRows=Math.ceil(TextBoxRows/2);
			document.getElementsByName("wpTextbox1")[0].setAttribute('rows',TextBoxRows);

			var ImageFrame = "<div id=\"ImageFrame\">" + ImageFrameContent(ImageString) + "</div>";
			document.getElementById("contentSub").innerHTML += ImageFrame
		}
	}
 }

 function ImageFrameContent(ImageString) {
	if (DivHeight == 0) {
		if(document.selection  && !is_gecko) {
			//IE: 
			DivHeight=Math.ceil(document.body.clientHeight*0.5)+"px";
		}
		else {
			//andere: 
			DivHeight=Math.ceil(window.innerHeight*0.4)+"px";
		}
	}
 
	var ZoomInIcon = "<a href=\"javascript:Zoom(50)\"><img src=\"http://upload.wikimedia.org/wikipedia/commons/0/04/Button_zoom_in.png\" title=\"vergrö&szlig;ern\" width=24 height=24></a>";
	var ZoomOutIcon = "<a href=\"javascript:Zoom(-50)\"><img src=\"http://upload.wikimedia.org/wikipedia/commons/0/03/Button_zoom_out.png\" title=\"verkleinern\" width=24 height=24></a>";
	var ZoomStdIcon = "<a href=\"javascript:Zoom(0)\"><img src=\"http://upload.wikimedia.org/wikipedia/commons/2/2a/Button_examine.png\" title=\"Fensterbreite\" width=24 height=24></a>";
 
	var ImageFrame = ZoomOutIcon + " " + ZoomStdIcon + " " + ZoomInIcon;
 
	var ImageApp = /\.png$|\.jpeg$|\.jpg$|\.gif$|\.PNG$|\.JPEG$|\.JPG$|\.GIF$/;
	if (ImageApp.test(ImageString) == true) {
		ImageFrame += "<div style=\"overflow: scroll; height: " + DivHeight + "; width: 100%;\">";
		ImageFrame += "<img onerror=\"ImageError('"+ ImageString+"')\" id=\"ProofReadImage\" src=\""+ GetImageUrl(ImageString) +"\" alt=\""+ GetImageUrl(ImageString) +"\"";
		if (GetCookie("PrImageWidth")) {
			ImageFrame +="width = \"" + GetCookie("PrImageWidth") +"\"";
		}
		ImageFrame += "></div>";
	} 
	else {
		ImageFrame += "<iframe id=\"ProofReadImage\" src=\""+ GetImageUrl(ImageString) +"\" style=\"height: " + DivHeight + "; width: 100%;\">";
	}
	return ImageFrame
 }

 function GetImageUrl(name) {
 	 // don't change absolute URLs
 	 if (name.indexOf("http:") == 0)	return name;
	 return "http://de.wikisource.org/wiki/Special:Filepath/" + name;
	 /*
	 var retval = name;
	 if (name.indexOf("http:") != 0) retval = "index.php/Special:Filepath/" + name;
	 return retval;
	 */
 }

 function ImageError(imagename) {
	if (document.getElementById("ProofReadImage").src.indexOf("commons") == -1 && document.getElementById("ProofReadImage").src.indexOf("Special:Filepath") != -1) {
		//image not from commons
		document.getElementById("ProofReadImage").src = "http://wiki.winboard.org/index.php/Spezial:Filepath/" + imagename;
	}
 }

 function Zoom(value) {
	PrImage = document.getElementById("ProofReadImage");
 
	if (value == 0) PrImage.width = document.getElementById("ImageFrame").offsetWidth-15;
	else PrImage.width=PrImage.width+value;
	SetCookie("PrImageWidth",PrImage.width);
	if(document.selection  && !is_gecko) {
		//IE: 
		document.getElementById("ImageFrame").innerHTML = ImageFrameContent(PrImage.src);
	}
 }

 // onload einbinden
 addLoadEvent(ProofReading);

/* </nowiki></pre> */