Zum Inhalt springen

MediaWiki:Common.js

Aus Wiktionary, dem freien Wörterbuch
 /* <nowiki> */
 url = document.URL;
 function $t(T) {return document.getElementsByTagName(T);}
 bouncyWiki = "//upload.wikimedia.org/wikipedia/commons/6/6c/Bouncywikilogo.gif";
 barnStar = "//upload.wikimedia.org/wikipedia/commons/a/a2/Tireless_Contributor_Barnstar.gif";

 // Suchfeldfokus
 var doFocus;
 var exFocus;
 var gotFocus;
 var doNotFocus;
 if (!doNotFocus && mw.config.get('wgAction') != "edit" && mw.config.get('wgAction') != "submit" && !(mw.config.get('wgNamespaceNumber') < 0 && mw.config.get('wgCanonicalSpecialPageName').match(/^[Rr]eset|^[Pp]ass|^[Uu]ser[lL]ogin|^[Ll]ogin/))) {
  var actionKey;
  $(document).ready(function() {
   doFocus = 1;
  });
  document.onmousedown = function() {gotFocus = 1;};
  document.onkeydown = function(kEvent) {
   if (doFocus && !gotFocus) {
    if (!kEvent) {kEvent = window.event;}
    if ((!actionKey && (kEvent.which == 16 || (kEvent.which > 40 && kEvent.which < 112) || (!kEvent.which && (!kEvent.keyCode || kEvent.keyCode > 40))) || kEvent.keyCode == 16) || (actionKey && (kEvent.which == 86 || kEvent.keyCode == 86 || kEvent.keyCode == 118))) {
     gotFocus = 1;
     if (exFocus || url.indexOf("#") > 0 || mw.config.get('skin') != "monobook") {focusSearch();}
    } else if ((kEvent.which > 32 && kEvent.which < 41) || (kEvent.keyCode > 32 && kEvent.keyCode < 41)) {
     exFocus = 1;
     focusSearch(8);
    } else if (kEvent.which == 17 || kEvent.which == 18 || kEvent.keyCode == 17 || kEvent.keyCode == 18) {
     actionKey = 1;
    } else if (kEvent.which == 9 || kEvent.keyCode == 9) {
     gotFocus = 1;
    }
   }
  };
 }
 function focusSearch(x) {
  if (document.getElementById("searchText") && url.indexOf("&fulltext=") > 0) {
   if (x) {
    document.getElementById("searchText").blur();
   } else {
    document.getElementById("searchText").focus();
    document.getElementById("searchText").select();
   }
  } else {
   if (x) {
    document.getElementById("searchInput").blur();
   } else {
    document.getElementById("searchInput").focus();
    document.getElementById("searchInput").select();
   }
  }
 }

 // Anonymes Suchprotokoll
 // 17.02.2011: testweise auskommentiert nach problemen mit der ajax-suche
 // importScript('MediaWiki:If-search.js');

 // Ausklappbare Navigationsleisten

 var NavigationBarHide = 'Einklappen ▲';
 var NavigationBarShow = 'Ausklappen ▼';
 var NavigationBarShowDefault = 100;
 var NavigationBarShowLang = '';

 //Einstellungen ([[Wiktionary:Einstellungen]]):
 if ( mw.cookie.get('WiktionaryUseJSPreferences') != 'true' ) {
   NavigationBarShowDefault = 999;
 } else if ( mw.cookie.get('WiktionaryPreferencesHideNav') == 'true' ) {
   NavigationBarShowDefault = 0;
   NavigationBarShowLang = ',' + mw.cookie.get('WiktionaryPreferencesShowLang') + ',';
   NavigationBarShowLang = NavigationBarShowLang.replace(/\s*,\s*/g,','); //remove blanks
 } else if ( mw.cookie.get('WiktionaryPreferencesShowNav') == 'true' ) {
   NavigationBarShowDefault = 999;
 } else {
   NavigationBarShowDefault = 999;
 }


function toggleNavigationBarAll(indexNavigationBar) {
  var mode;
  var NavChild;
  var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
  var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
  if (!NavFrame || !NavToggle) {return false;}

  mode = NavToggle.firstChild.data;

  var collection = document.getElementsByClassName("NavFrame");
  for (var i = 0; i < collection.length; i++) {
    if (mode == NavigationBarHide) {
      for (NavChild = collection[i].firstChild; NavChild !== null; NavChild = NavChild.nextSibling) {
        if (NavChild.className == 'NavPic')     {NavChild.style.display = 'none';}
        if (NavChild.className == 'NavContent') {NavChild.style.display = 'none';}
        if (NavChild.className == 'NavToggle')  {NavChild.firstChild.data = NavigationBarShow;}
      }
      copyLanguages(collection[i]);
    } else if (mode == NavigationBarShow) {
      for (NavChild = collection[i].firstChild; NavChild !== null; NavChild = NavChild.nextSibling) {
        if (NavChild.className == 'NavPic') {NavChild.style.display = 'block';}
        if (NavChild.className == 'NavContent') {NavChild.style.display = 'block';}
        if (NavChild.className == 'NavToggle') {NavChild.firstChild.data = NavigationBarHide;}
      }
      removeLanguages(collection[i]);
    }
  }
}


function toggleNavigationBar(indexNavigationBar) {
  var NavChild;
  var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
  var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
  if (!NavFrame || !NavToggle) {return false;}
  if (NavToggle.firstChild.data == NavigationBarHide) {
   for (NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling) {
    if (NavChild.className == 'NavPic') {NavChild.style.display = 'none';}
    if (NavChild.className == 'NavContent') {NavChild.style.display = 'none';}
    if (NavChild.className == 'NavToggle') {NavChild.firstChild.data = NavigationBarShow;}
   }
   copyLanguages(NavFrame);
  } else if (NavToggle.firstChild.data == NavigationBarShow) {
   for (NavChild = NavFrame.firstChild; NavChild !== null; NavChild = NavChild.nextSibling) {
    if (NavChild.className == 'NavPic') {NavChild.style.display = 'block';}
    if (NavChild.className == 'NavContent') {NavChild.style.display = 'block';}
    if (NavChild.className == 'NavToggle') {NavChild.firstChild.data = NavigationBarHide;}
   }
   removeLanguages(NavFrame);
  }
}


function allowedLanguage(lang) {
 if (NavigationBarShowLang.indexOf(',' + lang + ',') >= 0) {return true;}
 return false;
}


function copyLanguages(NavFrame) {
 // Ausnahme für "Deutsch"; die deutsche Übersetzungszeile enthält ein <b> (bold)
 var a = NavFrame.querySelectorAll(
   ".uetab:not(.dialekte) ~ ul li > a:first-of-type, .uetab:not(.dialekte) ~ ul li > b > a:first-of-type"
 );

 var node,ulnode;

 var nh = NavFrame.getElementsByClassName("NavHead");
 if (nh && nh.length > 0) {
  if (nh[0].getElementsByClassName('NavHeadUl')[0]) {
   // already there
   return;
  }

  ulnode = document.createElement("ul");
  ulnode.classList.add("NavHeadUl");
  nh[0].appendChild(ulnode);

  var i = 0;
  for (i = 0; i < a.length; i++) {
   node = a[i];
   if (allowedLanguage(node.textContent)) {
    var clone = node.parentNode.cloneNode(true);
    if (clone.tagName == "B") {
      clone = node.parentNode.parentNode.cloneNode(true);
    }
    clone.removeAttribute("style");
    if (clone.firstChild) {
      clone.firstChild.setAttribute("style","display:inline-block;min-width:7em");
    }
    ulnode.appendChild(clone); 
   }
  }
 }

}


function removeLanguages(NavFrame) {

  var node,ulnode;
  var nh = NavFrame.getElementsByClassName("NavHead");
  if (nh && nh.length > 0) {
    ulnode = nh[0].getElementsByClassName("NavHeadUl")[0];
    if (ulnode) {
      nh[0].removeChild(ulnode);
    }
  }

}

 indexNavigationBar = 0;
 function createNavigationBarToggleButton() {
  for (i=0; NavFrame = document.getElementsByTagName("div")[i]; i++) {
   if (NavFrame.className == "NavFrame") {
    indexNavigationBar++;
    var NavToggle = document.createElement("a");
    NavToggle.className = 'NavToggle';
    NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
    NavToggle.setAttribute('href', 'javascript:toggleNavigationBar('+indexNavigationBar+')');
    NavToggle.innerText = NavigationBarHide;

    var node = document.createElement("a");  // Config/Einstellungen
    node.setAttribute('href', '//de.wiktionary.org/wiki/Wiktionary:Einstellungen');
    node.setAttribute('title', 'Wiktionary:Einstellungen');
    node.className = 'NavToggleConfig';
    node.innerText = " \u00A0 \u2261 \u00A0 ";
    NavFrame.insertBefore(node, NavFrame.firstChild);
  
    node = document.createElement("a");  // Toggle all
    node.setAttribute('href', 'javascript:toggleNavigationBarAll('+indexNavigationBar+')');
    node.setAttribute('title', 'Alle klappbaren Elemente der Seite Ein-/Ausklappen');
    node.className = 'NavToggleAll';
    node.innerText = "\u00A0Alle\u00A0";
    NavFrame.insertBefore(node, NavFrame.firstChild);
 
    NavFrame.insertBefore(NavToggle, NavFrame.firstChild);
    NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
   }
  }
  if (NavigationBarShowDefault < indexNavigationBar) {
   for (var i=1; i<=indexNavigationBar; i++) {toggleNavigationBar(i);}
  }
/*
  if (mw.user.getId() == 38134) {
    var hash = window.location.hash;
    window.location.hash = '';
    window.location.hash = hash;
  }
*/
 }
 $(document).ready(createNavigationBarToggleButton);

 // Urgently change ID to class...
 function closedNavBar() {

    if (mw.cookie.get('WiktionaryUseJSPreferences') != 'true' ) {
        for (var i = 0; i < indexNavigationBar; i++) {
            var j = i+1;
            if (document.getElementById("NavFrame"+j).parentNode.parentNode.parentNode.parentNode.id == "closedNavBar") {toggleNavigationBar(j);}
            else {toggleNavigationBar(0);}
        }
    } else if (mw.cookie.get('WiktionaryPreferencesHideNav') == 'true' ) {
         toggleNavigationBar(100);
    } else if (mw.cookie.get('WiktionaryPreferencesShowNav') == 'true' ) {
         toggleNavigationBar(0);
    } else {
        for (var i = 0; i < indexNavigationBar; i++) {
            var j = i+1;
            if (document.getElementById("NavFrame"+j).parentNode.parentNode.parentNode.parentNode.id == "closedNavBar") {toggleNavigationBar(j);}
            else {toggleNavigationBar(0);}
        }
    }

 }
 $(document).ready(closedNavBar);

 // Import von MediaWiki:Onlyifediting.js (Sonderzeichenmenü)

 if (url.indexOf("=edit") > 0 || url.indexOf("=submit") > 0) {
  importScript('MediaWiki:Onlyifediting.js');
 }


 // (Auto-)Reload-Funktion
 var CSSnJScacheID;
 importScript('MediaWiki:If-cached.js');
 function autoReload() {
  if (CSSnJScacheID && mw.config.get('wgAction') == "view" && document.getElementById("autoReload")) {
   var aRclass = document.getElementById("siteNotice").getElementsByTagName("span")[0].className;
   if (document.getElementById("siteNotice").getElementsByTagName("span")[0].id == "autoReload" && aRclass != "CSSnJScacheID="+CSSnJScacheID+";" && document.getElementById("siteNotice").getElementsByTagName("script")[0]) {//safe
    var HTMLcacheID = aRclass.replace(/^CSSnJScacheID=([0-9]+);$/, "$1");
    if (HTMLcacheID > CSSnJScacheID && window.name != HTMLcacheID) {
     window.name = HTMLcacheID;//conflicting?
     if (window.name == HTMLcacheID) {//safe
      location.reload(true);
     }
    }
   } else if (document.getElementById("hideSiteNotice")) {//IE8?
    var HTMLcacheID = aRclass.replace(/^CSSnJScacheID=([0-9]+);$/, "$1");
    if (window.name == HTMLcacheID) {
     document.getElementById("siteNotice").style.display = "none";
    }
   }
  }
 }
 $(document).ready(autoReload);
 function reload() {//obsolete
  var reload = document.getElementById("reload");
  if (reload) {
   reload.innerHTML = '<a href="javascript:location.reload(true)">Wiktionary neu laden!<\/a>';
  }
 }
 $(document).ready(reload);

 // siehe-auch-feld auf eintragsseiten, die auch ein case-(in)sensitive-äquivalent haben
 mw.loader.using( ['mediawiki.util'] ).done( function () {
  mw.util.addCSS('#showSeeAlso {display: none;}');
 });
 function showSeeAlso() {
  if (mw.config.get('wgNamespaceNumber') == 0 && url.indexOf("oldid=") < 0) {
   var vsa = document.getElementById("Vorlage_Siehe_auch");
   var cs = document.getElementById("contentSub");
   var s0 = document.getElementById("section_0");
   if (vsa) {
    if (!cs) {
     if (s0) {
      // Hier sind wir im desktop-modus, da gerade MediaWiki:Common.js abläuft
      // und der User hat Minerva als Skin eingestellt, da cs fehlt
      s0.parentNode.innerHTML += vsa.innerHTML;
      document.getElementById("vsa_minerva").style.display = "initial";
     } else {  // der User hat Vector (2022) eingestellt
      var vector = document.querySelector("div.mw-parser-output");
      if (vector) {
       vector.insertAdjacentHTML('afterbegin',vsa.innerHTML);
      }
     }
    } else {
     cs.style.margin = "0";
     cs.innerHTML += vsa.innerHTML;
    }
   } else if (document.getElementById("showSeeAlso")) {  // automatische Vorlage
    if (!cs) {
     if (s0) {
      // Hier sind wir im desktop-modus, da gerade MediaWiki:Common.js abläuft
      // und der User hat Minerva als Skin eingestellt, da cs fehlt
      s0.parentNode.innerHTML += document.getElementById("showSeeAlso").innerHTML;
     }
    } else {
     cs.style.margin = "0";
     cs.innerHTML += document.getElementById("showSeeAlso").innerHTML;
    }
   }
  }
 }
 $(document).ready(showSeeAlso);


 // Drop-Down-Menü für [[Vorlage:Formatvorlagen-Menü]]
 function chooseLanguage(s) {
  var l = document.getElementById('formatmenue').getElementsByTagName('p');
  for (var i = 0; i < l.length ; i++) {
    l[i].style.display = i == s ? 'inline' : 'none';
  }
 }
 
 function addNewarticleSubsetMenu() {
  var formatmenue = document.getElementById('formatmenue');
  if (formatmenue) {
   var menu = "<select style=\"display:inline\" onChange=\"chooseLanguage(selectedIndex)\">";
   var l = formatmenue.getElementsByTagName('p');
   for (var i = 0; i < l.length ; i++) {
     menu += "<option>" + l[i].title + "</option>";
   }
   menu += "</select>";
   formatmenue.innerHTML = menu + formatmenue.innerHTML;
   chooseLanguage(0); // wähle oberste Option aus
  }
 }
 $(document).ready(addNewarticleSubsetMenu);
 

 // Skript für Einstellungen laden
 importScript('MediaWiki:Wiktionary-Einstellungen.js');


 // Anpassung der [bearbeiten]-Links

 //   Folgendes Script basiert auf einem Element aus dem MediaWiki:Monobook.js in der französischen
 //   Wikipedia und steht unter unter der GNU Lizenz für freie Dokumentation. Der Autor des Codes ist
 //   Marc Mongenet, Copyright 2006.

 setModifySectionStyle = function()
 {
 try {
        if (!(typeof oldEditsectionLinks == 'undefined' || oldEditsectionLinks == false)) return;
        var spans = $t("span");
        for (var s = 0; s < spans.length; ++s) {
                var span = spans[s];
                if (span.className == "editsection") {
                        span.style.fontSize = "x-small";
                        span.style.fontWeight = "normal";
                        span.style.cssFloat = span.style.styleFloat = "none";
                        span.parentNode.appendChild(document.createTextNode(" "));
                        span.parentNode.appendChild(span);
                }
        }
 } catch (e) { /* something went wrong */ }
 }
 $(document).ready(setModifySectionStyle);


//********Fügt einen Link "Alle Sprachen" auf der Hauptseite unter die Sprachverweise hinzu, aus [[w:en:MediaWiki:Common.js]] ********************
function mainPageAppendCompleteListLink() {
    try {
        var node = document.getElementById( "p-lang" )
                           .getElementsByTagName('div')[0]
                           .getElementsByTagName('ul')[0];

        var aNode = document.createElement( 'a' );
        var liNode = document.createElement( 'li' );

        aNode.appendChild( document.createTextNode( 'Alle Sprachen' ) );
        aNode.setAttribute( 'href' , '//de.wiktionary.org/wiki/Wiktionary:Liste_der_Wiktionarys_in_anderen_Sprachen' );
        liNode.appendChild( aNode );
        liNode.className = 'interwiki-completelist';
        liNode.style.fontWeight = 'bold';
        node.appendChild( liNode );
     } catch(e) {
       // lets just ignore what's happened
       return;
    }
}

if ( mw.config.get('wgTitle') == 'Hauptseite' && mw.config.get('wgNamespaceNumber') == 4 ) {
       $(document).ready( mainPageAppendCompleteListLink );
}

//********Fügt einen Link "Alle Sprachen" auf der Hauptseite unter die Sprachverweise hinzu ********************

if ( mw.config.get('wgCanonicalSpecialPageName') == "Upload" ) {
 function setSpecialUploadTemplate() {
    var editbox = document.getElementById('wpUploadDescription');
    if (!editbox)            return;
    if (editbox.value != '') return;
    editbox.value = "{"+"{Information\n"
                  + "|Beschreibung = \n"
                  + "|Quelle = \n"
                  + "|Urheber = \n"
                  + "|Datum = \n"
                  + "|Genehmigung = \n"
                  + "|Andere Versionen = \n"
                  + "|Anmerkungen = \n"
                  + "}"+"}";
 }
 $(document).ready(setSpecialUploadTemplate);
}

 // Wiktionary zur Browser-Suchleiste hinzufügen (FF / IE7)
 function aspWikt() {
  var asp = document.getElementById("addWiktSearch");
  if (asp) {
   asp.innerHTML = '<a href="javascript:addWiktSearch()">Wiktionary zur Browser-Suchleiste hinzufügen!<\/a>';
  }
 }
 $(document).ready(aspWikt);
 function addWiktSearch() {
  if (typeof window.external == "object" && (typeof window.external.AddSearchProvider == "unknown" || typeof window.external.AddSearchProvider == "function") && !window.opera) {
   window.external.AddSearchProvider("//de.wiktionary.org/w/opensearch_desc.php");
  } else {
   alert("Bei deinem Browser musst du das leider manuell machen!");
  }
 }

/* schamlos aus en.wikinews gestohlen */

 /*
==CGI:IRC login form==
 */
 // See [[MediaWiki:Irc.js]], Author: Bawolff.

 //load irc login box if on page
 $(function () {
  if (document.getElementById("cgiircbox")) {
   importScript('MediaWiki:Irc.js');
  }
 });

/**
 * geklaut von de.wiki erzeuge einen "Neuen Abschnitt"-Link an der letzten Überschrift
*/
$( function() {
 var newSectionLink = $( '#ca-addsection a' );
 if( newSectionLink.length ) {
  var link = newSectionLink.clone(); //create a copy
  //avoid duplicate accesskey
  link.removeAttr( 'accesskey' ).attr( 'title', function ( index, oldTitle ) {
   return oldTitle.replace( /\s*\[.*\]\s*$/, '' );
  } );
  //add it within the brackets
  //.editsection can be removed after June 7 (see [[gerrit:61075]])
  var lastEditsectionLink = $( 'span.editsection,span.mw-editsection' ).filter( ':last' ).find( 'a' );
  lastEditsectionLink.after( link );
  lastEditsectionLink.after( ' | ' ); //see [[MediaWiki:Pipe-separator]]
 }
});


// Handle {{InterProjekt}}
importScript('MediaWiki:InterProject.js');


// Edittools für Eingabefeld auf Hilfe:Reime
// Nicht mehr nötig, da charinsert mittlerweile anders arbeitet. 01.06.2020 Formatierer
// if (mw.config.get('wgPageName') == "Hilfe:Reime") {
//  mw.loader.load(["mediawiki.action.edit", "mediawiki.toolbar"]);
// }


// Erzeugt ein vereinfachtes Inhaltsverzeichnis, wenn keines existiert
// und genau zwei Ebene 3 Überschriften vorhanden sind

( function () {
  var ns = mw.config.get("wgNamespaceNumber");

  if ((ns == 0) && mw.config.get("wgAction") == "view") {

    var toc = $("#toc");
    if (!toc || toc.length == 0) {
      var h3 = $("#mw-content-text h3");

      if (h3 && h3.length == 2) {
        var h2 = $("#mw-content-text h2");

        if (h2 && h2.length == 1) {
          // [Bearbeiten]-Links entfernen, diese sind sprachspezifisch!

          var h30 = h3[0].innerText.replace(/\[.*/,'');
          var h31 = h3[1].innerText.replace(/\[.*/,'');
          var h20 = h2[0].innerText.replace(/\[.*/,'');

          h2[0].parentElement.insertAdjacentHTML('beforebegin',
            '<div id="toc" class="toc"><h2>Inhaltsverzeichnis</h2>' +
            '<ul><li>1 <a href="#' + mw.util.wikiUrlencode(h20) + '">' + h20 +
            '</li><li>1.1 <a href="#' + mw.util.wikiUrlencode(h30) + '">' + h30 +
            '</li><li>1.2 <a href="#' + mw.util.wikiUrlencode(h31) + '">' + h31 +
            '</li></ul></div>'
          );

        }
      }
    }

  }

})();


 /* </nowiki> */