Benutzer:Bawolff/sandbox.js
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Strg+F5
/* <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 = mw.config.get('wgUserName') ? true : false;
SpecCharsAccesskeys = new Array();
function addCharSubsetMenu() {
var toolbar = document.getElementById('toolbar');
var specialchars = document.getElementById('specialchars');
if (specialchars) {
var $menu = $("<select id=\"CharSelect\" name=\"CharSelect\" tabindex=\"8\" accesskey=\"a\" style=\"display:inline; vertical-align:middle\"></select>" ).change( chooseCharSubset );
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.append( $( '<option></option>' ).text( charname ) );
}
}
$( specialchars ).prepend( $menu );
// Standard-CharSubset oder aus Cookie
var stdsubset = 0;
if (GetCookie ("CharSubset")) stdsubset = GetCookie ("CharSubset");
document.editform.CharSelect.options[stdsubset].selected = true;
chooseCharSubset( { target: {selectedIndex: 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(evt) {
s = evt.target.selectedIndex;
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
$(document).ready(customizeWikipedia);
//================================================================================
//## replace
// anscheinend ungenutzt, siehe ende dieses abschnitts
// Replace-Button
function AddReplaceButton() {
var ButtonHTML = "<a href=\"javascript:stringReplaceBox();\"><img src=\"//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,""");
Valreplacement=Valreplacement.replace(/"/g,""");
} 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=\" OK \" 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!
//$(document).ready(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=\"//upload.wikimedia.org/wikipedia/commons/0/04/Button_zoom_in.png\" title=\"vergrößern\" width=24 height=24></a>";
var ZoomOutIcon = "<a href=\"javascript:Zoom(-50)\"><img src=\"//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=\"//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.toLowerCase().indexOf("//") !== -1) return name;
return "//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 = "//commons.wikimedia.org/wiki/Special: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
$(document).ready(ProofReading);
/* </nowiki></pre> */