MediaWiki:Common.js: Unterschied zwischen den Versionen

Zur Navigation springen Zur Suche springen
K
K (Die Seite wurde geleert.)
Zeile 1: Zeile 1:
////Buttons f. Bearbeitungsfenster ganz unten!
 
  
/*** POPUPS ***/
 
// Altes speichern und neue Elemente gestalten
 
var bilder = [[]];
 
 
function getThumbs() {
 
  var a=0;
 
  for (i=0;i<document.getElementsByTagName('img').length;i++) {
 
    if (document.getElementsByTagName('img')[i].src.indexOf('thumb')!=-1) {
 
      var thumb = document.getElementsByTagName('img')[i];
 
      var bildSrc = thumb.src.replace(/thumb\//, '');
 
        bildSrc = bildSrc.slice(0,(bildSrc.indexOf(bildSrc.split('/')[bildSrc.split('/').length-1]))-1);
 
      var bildname = bildSrc.split('/')[bildSrc.split('/').length-1];
 
      var namensgeber=document.getElementById('pp_'+bildname)||document.getElementById('pp_'+bildname.toLowerCase())||false;
 
 
      bilder[0][a] = new Image;
 
      bilder[0][a].src = bildSrc;
 
      bilder[0][a].text = namensgeber? namensgeber.innerHTML : '';
 
 
      if (thumb.parentNode.tagName=='A') {
 
        var bildlink  = '<a href="'+thumb.parentNode.href+'">[Bildseite]</a> ';
 
        if (sysopRights)
 
          bildlink += '<a href="'+thumb.parentNode.href.replace(/an\//,"w/index.php?title=")+'&action=edit">[bearbeiten]</a> ';
 
        bilder[0][a].text +=  '<p class="editsection">' + bildlink + '</p>';
 
thumb.parentNode.href= "javascript:pp_open("+a+",0)";
 
thumb.parentNode.title="Popup öffnen"; 
 
      }
 
      a++;
 
    }
 
  }
 
 
  body_width = document.body.offsetWidth;
 
  body_height = document.body.offsetHeight;
 
  screen_height = window.innerHeight || document.documentElement.offsetHeight;
 
  screen_width = window.innerWidth-15 || document.documentElement.offsetWidth-15;
 
 
  writeImgDiv();
 
}
 
 
//Pfeiltasten
 
var usePfeil = 0;
 
 
function writeImgDiv() {
 
  ppImgScreen = document.body.appendChild(document.createElement('div'));
 
    ppImgScreen.id = "ppScreen"; ppImgScreen.style.display = "none";
 
  ppImgDiv = document.body.appendChild(document.createElement('div'));
 
    ppImgDiv.id = "ppImgDiv"; 
 
ppImgDiv.style.display = "none";
 
  ppImg = ppImgDiv.appendChild(document.createElement('div')).appendChild(document.createElement('img'));
 
  ppImgTop = ppImgDiv.appendChild(document.createElement('div'));
 
  ppImgInfo = ppImgDiv.appendChild(document.createElement('div'));
 
  ppImgInfo.className = "ppFloat";
 
  ppImgClick = ppImgDiv.appendChild(document.createElement('div'));   
 
  ppImgClick.className = "ppClick";
 
 
  ppImgScreen.onclick =
 
  ppImgInfo.onclick = hideDiv;
 
}
 
 
function pp_open(indexB, arrayB) {
 
      //welcher Bilderarray?
 
  var aIndex = arrayB || 0;
 
  var auswahl = bilder[aIndex];
 
      //welches Bild?
 
  var x = indexB || 0;
 
 
    //Scrollposition ermitteln
 
  var scrY = document.documentElement.scrollTop || // Explorer 6 Strict
 
document.body.scrollTop || //all other Explorers
 
self.pageYOffset ||
 
0;
 
 
  with (ppImgScreen.style) {
 
    width = document.body.offsetWidth+"px";
 
    height = document.body.offsetHeight+"px";
 
display = "block";
 
  }  
 
//Anpassen an Fenster
 
  if (auswahl[x].height>(screen_height)) {
 
    auswahl[x].width=auswahl[x].width/auswahl[x].height*screen_height;
 
    auswahl[x].height=screen_height;
 
    }
 
  if (auswahl[x].width>(screen_width)) {
 
    auswahl[x].height=auswahl[x].height/auswahl[x].width*screen_width;
 
    auswahl[x].width=screen_width;
 
    }
 
//
 
  var ppH = auswahl[x].height+28, // Maße für das Schriftfenster (ppImgInfo)
 
    ppW = auswahl[x].width+10,
 
    ppBoTop = ((ppH+10) < screen_height) ? //wenn Bildübergröße
 
      0 : ((ppH+10)-screen_height)/2 +"px";
 
 
 
    //Bild gestalten
 
  ppImg.src = auswahl[x].src;
 
  ppImg.height= auswahl[x].height;
 
  ppImg.width= auswahl[x].width;
 
  ppImgInfo.innerHTML=auswahl[x].text; //Begleittext...
 
 
 
  with (ppImgInfo.style) {
 
if ( (ppW+300)<body_width) {
 
  left = ppW+"px"; top = ppBoTop; width = (body_width-ppW-64)/2+"px";}
 
else {
 
  left = (auswahl[x].width/2-10)+"px"; top = ppH+"px"; width = (body_width/2-32)+"px";
 
}
 
  }
 
  ppImgTop.innerHTML="Bild "+(x+1)+"/"+auswahl.length;
 
  ppImgTop.id="ppIndex";
 
  ppImgClick.style.width=450+"px";
 
  ppImgClick.style.left=ppW-543+"px"; 
 
 
 
  if (auswahl.length>1) {// mehr als ein bild
 
bck=ppImgTop.insertBefore(document.createElement('a'), ppImgTop.firstChild);
 
    nxt=ppImgTop.appendChild(document.createElement('a'));
 
bck.id="bck1";
 
nxt.id="nxt1";
 
ppH=auswahl[x].height+28;
 
ppW=(auswahl[x].width+10)/2;
 
  with (bck.style) { left=0; height=ppH+"px"; width=ppW+"px"; }
 
  with (nxt.style){ left=ppW+"px"; height=ppH+"px"; width=ppW+"px"; }
 
  //neues Bild aufrufen
 
    vor=(x+1<auswahl.length)? x+1:0;
 
zur=(x-1>-1)? x-1:auswahl.length-1;
 
    nxt.href="javascript:pp_open("+vor+","+aIndex+")";
 
    bck.href="javascript:pp_open("+zur+","+aIndex+")";
 
 
ppImgClick.innerHTML = "<span>Ins Bild klicken oder Pfeiltasten [&larr;] [&rarr;] = Neues Bild! <br/>Sonst wo klicken oder [Esc] = Bild schließen!</span>"
 
 
    ppImgClick.onclick =
 
    ppImgScreen.onclick =
 
    ppImgInfo.onclick = hideDiv;
 
 
  }
 
  else {
 
ppImgDiv.onclick=hideDiv;
 
ppImgClick.innerHTML = "<span>Beliebiger Klick oder [Esc] = Bild schließen!<br/>&nbsp;</span>";
 
  }
 
   
 
  usePfeil=1; //Schalter für Pfeilfunktion
 
  pfeil=function(e) {
 
    e=e||event;
 
    if (e.keyCode&&usePfeil&&(typeof(vor)!="undefined"||typeof(zur)!="undefined"))
 
      if (e.keyCode==39||e.keyCode==102) pp_open(vor,aIndex);
 
    else if (e.keyCode==37||e.keyCode==100) pp_open(zur,aIndex);
 
    else if (e.keyCode==27) hideDiv();
 
  }
 
  document.onkeydown = pfeil;
 
 
//ppImgDiv positionieren und zeigen
 
  abstand_x = auswahl[x].width < document.body.clientWidth ?
 
(document.body.clientWidth - auswahl[x].width-10)/2 : 0;
 
  abstand_y = scrY + (screen_height-auswahl[x].height)/3;
 
 
  with (ppImgDiv.style) {
 
left = abstand_x+"px";
 
top  = abstand_y+"px";
 
  }
 
//Image Screen Größe (falls Bild größer als body)
 
  var maxW = ((auswahl[x].width+12) > body_width) ?
 
    (auswahl[x].width+12) : body_width;
 
  with (ppImgScreen.style) {
 
    width =  maxW + "px";
 
    height = document.body.offsetHeight+"px";
 
display = "block";
 
  }  
 
  ppImgDiv.style.display = "block";
 
  /*
 
  function aaa(){newDiv.parentNode.removeChild(newDiv)}
 
  window.setTimeout('aaa()', 500);
 
  //Bild anzeigen
 
  newDiv = document.body.appendChild(ppImgDiv.cloneNode(true)); 
 
    newDiv.style.display = "block"; */
 
}
 
 
    //popup-Div SCHLIESSEN
 
 
function hideDiv() {
 
  ppImgScreen.style.display =
 
  ppImgDiv.style.display = "none";
 
  usePfeil=0; //Pfeiltasten nicht mehr verwenden
 
}
 
 
 
 
/*** PRELOAD ***/
 
importScript('mediawiki:bilder.js');
 
importScript('mediawiki:loadGlossar.js');
 
importScript('mediawiki:literatur.js');
 
 
function anmToc(){
 
if (wgPageName&&wgPageName.indexOf('Metalog:Glossar')!=-1) {
 
var anm = document.createElement('DIV');
 
anm.innerHTML="Anmerkung: „ō“ und „ū“ sind alphabetisch wie „ou“ und „uu“ eingeordnet";
 
anm.className="anmToc";
 
document.getElementById('toc').appendChild(anm);
 
}
 
}
 
addOnloadHook(anmToc);
 
 
/*********USER RIGHTS*************/
 
var sysopRights = false;
 
var userRights = false;
 
function setSysopRights(){
 
for (i in wgUserGroups) {
 
  if (wgUserGroups[i]== "user")
 
    userRights = true;
 
  if (wgUserGroups[i]== "sysop")
 
    sysopRights = true;
 
  }
 
}
 
addOnloadHook(setSysopRights);
 
/******************************/
 
function clickEdit() {
 
if (sysopRights && wgNamespaceNumber>-1 && wgAction=="view")
 
  window.ondblclick = function(e) {
 
  if (e.target.nodeName == "DIV")
 
    document.location.href = wgScript+"?title="+wgPageName+"&action=edit";
 
  }
 
}
 
addOnloadHook(clickEdit);
 
/******************************/
 
//Nach dem Einloggen wieder zur Ausgangsseite:
 
if (wgCanonicalSpecialPageName == "Userlogin")
 
addOnloadHook( function() { document.location = document.getElementById('mw-returnto').getElementsByTagName('a')[0].href; } );
 
 
// Welche Scripts für welche Seiten...
 
 
var jsOK = false;
 
var useNewJs = [
 
  newJS_Spaces = [wgNamespaceNumber,0,4,12,14,100,102,104,106,108,110,112,],
 
  newJS_Pages = [wgPageName,'Hauptseite','Benutzer:Bescheid','Benutzer:WikiSysop',]
 
];
 
 
function setJsOK(array) {
 
  for (var i in array) 
 
    for (var n=1; n<array[i].length; n++)
 
      if (array[i][n] == array[i][0]) jsOK = true;
 
}
 
 
setJsOK(useNewJs);
 
if (!wgIsArticle || wgAction != "view") jsOK = false;
 
 
 
function sizeY() {
 
//Maße und Elemente 
 
  var body_width = document.body.offsetWidth,
 
    body_height = document.body.offsetHeight,
 
    screen_height = window.innerHeight ||
 
      document.documentElement.offsetHeight;
 
    var spacer = document.getElementById("content").appendChild( document.createElement("DIV") );
 
  // Höhe anpassen
 
  spacer = document.getElementById("thisway") || spacer;
 
    spacer.style.paddingTop = (body_height+10) < screen_height ?
 
      screen_height-(body_height+10) +"px" : 0;
 
}
 
 
if (jsOK)
 
{ //eigentliches Script ab hier. Achtung auf "}" !
 
 
///////// var für Maße und Elemente/////////////// 
 
 
var body_width, body_height, screen_height;
 
 
/***********************************
 
      Stylesheet changes
 
***********************************/
 
 
document.write (
 
    '<style>' +
 
    ' #column-content {}' + //0
 
    ' #column-one {}' + //1
 
    ' #toc{}' +  //2
 
    ' #content #bodyContent{}' + //3
 
    ' #siteNotice.fixed{}' + //4
 
    ' #p-personal{}' + //5
 
    ' #p-cactions {}' + //6
 
    ' #dropdown {}' + //7
 
    ' .glossar2:hover small small {}' + //8
 
    ' .sysop {}' + //9
 
    ' .user {}' + //10
 
    ' .anon{}' + //11
 
    ' </style>'
 
    ); 
 
var newCSS = document.styleSheets[document.styleSheets.length-1],
 
  newRules = newCSS.cssRules || newCSS.rules;  // für alle Browser ansprechbar
 
 
/***********************************
 
    Anpassen an Browserfenster, u.a.
 
************************************/
 
 
function sizeX() {
 
 
  var normW = 1024,
 
    thisW = window.innerWidth ||  document.documentElement.offsetWidth || 0,
 
    rand_abstand = (thisW > normW)? Math.round((thisW - normW)/20*3) : 0;
 
  if (newRules) {
 
      //--------- neue Abstaende ---------------
 
    newRules[0].style.marginRight =  // #column-content
 
    newRules[0].style.marginLeft =
 
    //newRules[1].style.left =  // #column-one
 
    //newRules[2].style.marginRight =  //#toc
 
    newRules[4].style.marginLeft =  // #sidebar
 
    //newRules[5].style.marginLeft =  //#p-personal
 
    //newRules[6].style.marginLeft =  //#p-cactions
 
    //newRules[7].style.marginLeft =  //#dropdown
 
      rand_abstand+'px';
 
    newRules[3].style.marginRight =  //#bodyContent
 
    newRules[3].style.marginLeft =
 
      rand_abstand/2+'px';
 
    //---------- Glossar, falls JS ----------------
 
  newRules[8].style.display = 'none'; //Glossar
 
      //---------- falls Sysop ----------------
 
  if (sysopRights) {
 
        newRules[9].style.display='block';
 
        newRules[10].style.display='block';
 
        newRules[11].style.display='none';
 
    }
 
  }
 
 
}
 
addOnloadHook(sizeX);
 
window.onresize = function() {sizeX();};
 
 
//die wichtigsten Funktionen:
 
 
/*** NAVIGATION ***/
 
 
var nv = document.getElementById('siteNotice');
 
function findPos(b) {  //Position von b ( = nv) ermitteln
 
  var a = 0;
 
  if(b.offsetParent)
 
    for(a = b.offsetTop;b = b.offsetParent;)
 
      a += b.offsetTop;
 
  return[a];
 
}
 
var nvY = findPos(nv);
 
//alert(nvY);
 
 
function fixNv() {
 
    //Scrollposition ermitteln
 
  var scrY = document.documentElement.scrollTop || // Explorer 6 Strict
 
document.body.scrollTop || //all other Explorers
 
self.pageYOffset ||
 
0;
 
  if(self.pageYOffset)
 
    scrY = self.pageYOffset;
 
  else if(document.documentElement && document.documentElement.scrollTop)
 
    scrY = document.documentElement.scrollTop;
 
  else if(document.body)
 
    scrY = document.body.scrollTop;
 
  if(typeof document.body.style.maxHeight != "undefined" && nv!='') // nur neuere Browser
 
    nv.className = scrY > nvY - 16 ? "fixed" : "absolute";
 
}
 
 
function styleNv() {
 
  var selflink = document.getElementById('chapters').getElementsByTagName('STRONG')[0]||0;
 
  if (selflink && selflink.parentNode.parentNode.parentNode.parentNode.tagName == 'LI') {
 
    selflink.parentNode.parentNode.parentNode.parentNode.className='self_parent';
 
  } 
 
}
 
styleNv();
 
window.onscroll = fixNv;
 
/*** GLOSSAR ***/
 
importScript('mediawiki:glossar.js');
 
 
}// ende "jsOK"
 
 
//Vielleicht für später
 
//importStylesheet('mediawiki:abc' + wgCanonicalNamespace + '.css');
 
//importScript('mediawiki:abc' + wgCanonicalNamespace + '.js');
 
 
 
//////////////////////////
 
//—‚ ‘„ “ōŌūŪ&shy;&nbsp;
 
//////////////////////////
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/no.gif",
 
    "speedTip": "",
 
    "tagOpen": "",
 
    "tagClose": "",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/ndash.jpg",
 
    "speedTip": "kurzer Bindestrich (n–dash)",
 
    "tagOpen": "–",
 
    "tagClose": "",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/mdash.jpg",
 
    "speedTip": "Text zwischen langen Bindestrichen (m—dash)",
 
    "tagOpen": "— ",
 
    "tagClose": " — ",
 
    "sampleText": "Text"};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/hyphens1_dt.jpg",
 
    "speedTip": "dt. Anführungszeichen einfach",
 
    "tagOpen": "‚",
 
    "tagClose": "‘",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/hyphens2_dt.jpg",
 
    "speedTip": "dt. Anführungszeichen doppelt",
 
    "tagOpen": "„",
 
    "tagClose": "“",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/oo.jpg",
 
    "speedTip": "langes o, klein",
 
    "tagOpen": "ō",
 
    "tagClose": "",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/oo_gr.jpg",
 
    "speedTip": "langes O, gross",
 
    "tagOpen": "Ō",
 
    "tagClose": "",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/uu.jpg",
 
    "speedTip": "langes u, klein",
 
    "tagOpen": "ū",
 
    "tagClose": "",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/uu_gr.jpg",
 
    "speedTip": "langes U, gross",
 
    "tagOpen": "Ū",
 
    "tagClose": "",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/shy.jpg",
 
    "speedTip": "stummes Trennzeichen",
 
    "tagOpen": "·",
 
    "tagClose": "",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/nbsp.jpg",
 
    "speedTip": "festes Leerzeichen (no breaking space)",
 
    "tagOpen": "&nbsp;",
 
    "tagClose": "",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/no.gif",
 
    "speedTip": "",
 
    "tagOpen": "",
 
    "tagClose": "",
 
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/ref.jpg",
 
    "speedTip": "Fussnoten",
 
    "tagOpen": "<ref>",
 
    "tagClose": "</ref>",
 
    "sampleText": "Text"};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/cat.jpg",
 
    "speedTip": "Kategorie",
 
    "tagOpen": "[[Kategorie:",
 
    "tagClose": "]]",
 
    "sampleText": " "};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/glo.jpg",
 
    "speedTip": "Glossar",
 
    "tagOpen": "{{glossar:",
 
    "tagClose": "}}",
 
    "sampleText": " "};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/skt.jpg",
 
    "speedTip": "Sanskrit",
 
    "tagOpen": "{{skt:",
 
    "tagClose": "}}",
 
    "sampleText": " "};
 
mwCustomEditButtons[mwCustomEditButtons.length] =
 
  {"imageFile": "/rel_jap/w/skins/common/images/shy.jpg",
 
    "speedTip": "TITEL",
 
    "tagOpen": "{{DISPLAYTITLE:",
 
    "tagClose": "",
 
    "sampleText": "\}\}<!-- \n -->"};
 
 
/*********** WIKI GADGETS *****************/
 
function PageHomeArrows()
 
{
 
        //if (!wgNamespaceNumber || wgNamespaceNumber <100) return;
 
        var c = document.getElementById("bodyContent") || document.getElementById("mw_content") || document.getElementById("article");
 
        if (!c) return;
 
        for (var level = 2; level <= 3; ++level) {
 
                var h = c.getElementsByTagName("h" + level);
 
                for (var i = 0; i < h.length; ++i) {
 
                        var mwh = h[i].lastChild; // moveEditsection not run yet
 
                        if (mwh && mwh.className == "mw-headline" && mwh.offsetTop>screen.availHeight) {
 
                                var arrow = document.createElement("a");
 
                                arrow.className = "toparrow noprint";
 
                                arrow.title= "zum Seitenanfang";
 
                                arrow.appendChild(document.createTextNode("top↑"));
 
                                arrow.href = "javascript:window.scrollTo(0,0); void 0;";
 
                                mwh.insertBefore(arrow, mwh.firstChild);
 
                        }
 
                }
 
        }
 
}
 
addOnloadHook(PageHomeArrows);
 
 
/**********************/
 
 
 
// Search box for Mediawiki
 
// (c) 2006 [[User:Zocky]], released under GPL
 
//<pre><nowiki>
 
 
importStylesheetURI('http://en.wikipedia.org/w/index.php?title=User:Zocky/SearchBox.css&action=raw&ctype=text/css');
 
 
var sr$t;
 
var sr$f;
 
var sr$s;
 
var sr$r;
 
var sr$w;
 
var sr$i;
 
var sr$re;
 
var sr$mc;
 
 
function $e(id) {return document.getElementById(id)}
 
 
function srBack()
 
{
 
  if (sr$s.value=='') {sr$t.focus(); return }
 
 
  if (sr$re.checked) {
 
    var searchString = sr$s.value;
 
  } else {
 
    searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
 
  }
 
 
  searchString="("+searchString+")(?![\\s\\S]*"+searchString+")";
 
  if (sr$mc.checked)
 
    var re=new RegExp(searchString);
 
  else
 
    var re=new RegExp(searchString,"i");
 
 
  var res = re.exec (sr$t.value.substring(0,sr$t.selectionStart));
 
  if (!res) {
 
    var res = re.exec (sr$t.value)
 
  }
 
 
  if (res)
 
  {
 
    sr$t.selectionStart=res.index;
 
    sr$t.selectionEnd=res.index+res[1].length;
 
  }
 
  else sr$t.selectionStart=sr$t.selectionEnd;
 
 
 
  srSync();
 
}
 
 
function srNext()
 
{
 
  if (sr$s.value=='') {sr$t.focus(); return }
 
 
  if (sr$re.checked) {
 
    var searchString = sr$s.value;
 
  } else {
 
    searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
 
  }
 
 
  if (sr$mc.checked)
 
    var re=new RegExp(searchString,"g");
 
  else
 
    var re=new RegExp(searchString,"gi");
 
 
  re.lastIndex=sr$t.selectionEnd;
 
  var res = re.exec (sr$t.value)
 
  if (!res) {
 
    re.lastIndex=0;
 
    var res = re.exec (sr$t.value)
 
  }
 
 
  if (res)
 
  {
 
    sr$t.selectionStart=res.index;
 
    sr$t.selectionEnd=res.index+res[0].length;
 
  }
 
  else sr$t.selectionStart=sr$t.selectionEnd;
 
  srSync();
 
}
 
 
function srReplace()
 
{
 
 
  var sels=sr$t.selectionStart;
 
  var sele=sr$t.selectionEnd;
 
  var selr=sr$t.value.length-sele;
 
 
  if (sr$s.value=='' || sels==sele) {sr$t.focus(); return }
 
 
  if (sr$re.checked) {
 
    var searchString = sr$s.value;
 
    var replaceString = sr$r.value;
 
 
  } else {
 
    searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
 
    replaceString=sr$r.value.replace(/([\$\\])/g,'\\$1');
 
  }
 
 
  if (sr$mc.checked)
 
    var re=new RegExp(searchString,"g");
 
  else
 
    var re=new RegExp(searchString,"gi");
 
 
  re.lastIndex=sels;
 
  var res = re.exec (sr$t.value);
 
  var $$=0;
 
  if (res && res.index==sels && res[0].length==sele-sels)
 
  {
 
    if (sr$re.checked) {
 
      replaceString=replaceString.replace(/\\\\/g,'&backslash;');
 
      var replaceBits=(" "+replaceString).split(/(?=\$\d)/);
 
      replaceString=replaceBits[0].substring(1);
 
      for (var i=1; i<replaceBits.length; i++)
 
      {
 
        $$=replaceBits[i][1]-'0';
 
        if ($$<res.length)
 
          replaceString += res[$$] + replaceBits[i].substring(2)
 
        else
 
          replaceString += replaceBits[i];
 
    }
 
    replaceString=replaceString.replace (/\\n/,"\n").replace (/&backslash;/g,"\\").replace
 
                                        (/&dollar;/g,"\$")
 
 
    }
 
    sr$t.value= sr$t.value.substring(0,sels) + replaceString + sr$t.value.substring(sele);
 
  }
 
 
  sr$t.selectionStart=sels;
 
  sr$t.selectionEnd=sr$t.value.length-selr;
 
  srSync();
 
}
 
 
 
function srReplaceall()
 
{
 
  if (!sr$s.value) {sr$t.focus(); return }
 
 
  var sels=sr$t.selectionStart;
 
  var sele=sr$t.selectionEnd;
 
  var selr=sr$t.value.length-sele;
 
 
  var reps;
 
 
  if (sr$re.checked) {
 
    var searchString = sr$s.value;
 
    var replaceString = sr$r.value.replace(/\\\\/,'&backslash;').replace(/\\n/,'\n').replace(/&backslash;/,"\\");
 
  } else {
 
    searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,'\\$1');
 
    replaceString=sr$r.value.replace(/([\$\\])/g,'\\$1');
 
  }
 
 
  if (sele>sels)
 
    reps=sr$t.value.substring(sels,sele);
 
  else
 
    reps=sr$t.value;
 
 
  if (sr$mc.checked)
 
    var re=new RegExp(searchString,"g");
 
  else
 
    var re=new RegExp(searchString,"gi");
 
 
 
  var replaceCounter=0;
 
 
  var replaceFunc=function(){replaceCounter++;return replaceString};
 
 
  reps=reps.replace(re,replaceFunc);
 
 
  if (sele>sels)
 
    sr$t.value = sr$t.value.substring(0,sels) + reps + sr$t.value.substring(sele);
 
  else
 
    sr$t.value = reps;
 
 
  sr$t.selectionStart=sels;
 
  sr$t.selectionEnd=sele>sels ? sr$t.value.length-selr : sels;
 
  window.status = replaceCounter+" ocurrences of " + searchString + " replaced.";
 
  srSync();
 
}
 
 
function srToggleCase()
 
{
 
  var sels=sr$t.selectionStart;
 
  var sele=sr$t.selectionEnd;
 
  var selr=sr$t.value.length-sele;
 
  var selt=sr$t.value.substring(sels,sele);
 
 
  if (sele>sels)
 
  {
 
    if (selt==selt.toUpperCase())
 
      selt=selt.toLowerCase()
 
    else if (selt==selt.toLowerCase() && sele-sels>1)
 
      selt=selt.substring(0,1).toUpperCase()+selt.substring(1).toLowerCase()
 
    else
 
      selt=selt.toUpperCase();
 
 
    sr$t.value = sr$t.value.substring(0,sels) + selt + sr$t.value.substring(sele);
 
    sr$t.selectionStart=sels;
 
    sr$t.selectionEnd=sele>sels ? sr$t.value.length-selr : sels;
 
  }
 
  srSync();
 
}
 
 
 
function srSync()
 
{
 
    var i;
 
    var allLines=0;
 
    var lineNo=0;
 
    var w=sr$t.cols-5;
 
 
    var dummy=sr$t.value.split("\n");
 
    for (i=0;i<dummy.length;i++){allLines+=Math.ceil(dummy[i].length/w)}
 
 
    var dummy=sr$t.value.substring(0,sr$t.selectionStart).split("\n");
 
    for (i=0;i<dummy.length;i++){lineNo+=Math.ceil(dummy[i].length/w)}
 
 
//    alert (w+" "+lineNo+"/"+allLines);
 
 
    sr$t.scrollTop=sr$t.scrollHeight*(lineNo-10)/allLines;
 
    sr$t.focus();
 
}
 
 
 
function srInit()
 
{
 
 
  if($e('wpTextbox1')) {
 
   
 
var srBoxCode ='<div id="srForm"><table id="srBox" cellpadding="0" cellspacing="2"><tr>'
 
          +'<td></td>'
 
          +'<td valign="middle">'
 
          +'<input type="checkbox" id="srCase" onclick="sr$t.focus()" tabindex="10"/><small><span style="color:#000000;">match case</span</small>&nbsp;'
 
          +'<input type="checkbox" id="srRegexp" onclick="sr$t.focus()" tabindex="11"/><small><span style="color:#000000;">use regexp</span></small>&nbsp;&nbsp;'
 
          +'<a href="javascript:srBack()" onmouseover="sr$t.focus()" title="find previous match [alt-2]" accesskey="2">&lt;</a>&nbsp;'
 
          +'<a href="javascript:srNext()" onmouseover="sr$t.focus()" title="find next match [alt-3]" accesskey="3">find&nbsp;&nbsp;&gt;</a>&emsp;'
 
          +'<a href="javascript:srReplace();srBack()" onmouseover="sr$t.focus()" title="replace and find previous match [alt-4]" accesskey="4">&lt;</a>&nbsp;'
 
          +'<a href="javascript:srReplace()" onmouseover="sr$t.focus()" title="replace this match">replace</a>&nbsp;'
 
          +'<a href="javascript:srReplace();srNext()" onmouseover="sr$t.focus()" title="replace and find next match [alt-5]" accesskey="5">&gt;</a>&emsp;'
 
          +'<a href="javascript:srReplaceall()" onmouseover="sr$t.focus()" title="replace all matches [alt-7]" accesskey="7">replace&nbsp;all</a>&emsp;'
 
          +'</td>'
 
          +'</tr><tr>'
 
          +'<td valign="bottom"><small><span style="color:#000000;">search for:</span></small></td>'
 
          +'<td valign="bottom"><input type="text" id="srSearch" accesskey="F" tabindex="8" onkeypress="event.which == 13 && srNext()"; value=""/></td>'
 
          +'</tr><tr>'
 
          +'<td valign="bottom"><small><span style="color:#000000;">replace with:</span></small></td>'
 
          +'<td valign="bottom"><input type="text" id="srReplace" accesskey="G" tabindex="9" onkeypress="event.which == 13 && srNext()"; value=""/></td>'
 
          +'</tr></table></div>'
 
 
    var ep=$e('searchInput');
 
    if (ep) ep.accessKey='none';
 
 
    sr$t=document.editform.wpTextbox1;
 
    sr$w=sr$t.style.width;
 
 
    var sr=document.createElement('div');
 
    sr.innerHTML=srBoxCode;
 
 
    var im=document.createElement('span');
 
    im.innerHTML='<a id="SearchIcon" href="javascript:srShowHide()"><img style="cursor: pointer;" title="Search/Replace" alt="Search/Replace" src="http://upload.wikimedia.org/wikipedia/en/1/12/Button_find.png" border="0" height="22" width="23"></a><a href="javascript:srToggleCase()"><img style="cursor: pointer;" title="Toggle case" alt="Toggle case" src="http://upload.wikimedia.org/wikipedia/en/1/12/Button_case.png" border="0" height="22" width="23"></a>';
 
 
    var ep=$e('toolbar');
 
    if (ep)
 
    {
 
      ep.appendChild(im)
 
    }
 
    else
 
    {
 
      var ep=$e('editform');
 
      ep.parentNode.insertBefore(im,ep);
 
    }
 
 
    sr$i=$e('SearchIcon');
 
    sr$i.accessKey="F";
 
    sr.firstChild.style.display='none';
 
 
 
    var ep=$e('editform');
 
    ep.parentNode.insertBefore(sr,ep);
 
 
    sr$f=$e('srForm');
 
    sr$s=$e('srSearch');
 
    sr$r=$e('srReplace');
 
    sr$re=$e('srRegexp');
 
    sr$mc=$e('srCase');
 
 
  }
 
}
 
 
function srShowHide()
 
{
 
  if (sr$f.style.display=='none')
 
  {
 
    sr$f.style.display='block';
 
    sr$i.accessKey="none";
 
    sr$t.style.width='auto';
 
    sr$s.focus();
 
  }
 
  else
 
  {
 
    sr$f.style.display='none';
 
    sr$t.style.width=sr$w;
 
    sr$i.accessKey="F";
 
  }
 
}
 
 
addOnloadHook(srInit);
 
//</nowiki></pre>
 

Version vom 4. Januar 2012, 15:38 Uhr