MediaWiki:Common.js

Aus Wiktionary, dem freien Wörterbuch
Zur Navigation springen Zur Suche springen
 /* <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 = 10;

 //Einstellungen ([[Wiktionary:Einstellungen]]):
mw.loader.using( ['jquery.cookie'], function () {
 if ( $.cookie('WiktionaryUseJSPreferences') != 'true' ) {
         NavigationBarShowDefault = 999;
    } else if ( $.cookie('WiktionaryPreferencesHideNav') == 'true' ) {
         NavigationBarShowDefault = 0;
    } else if ( $.cookie('WiktionaryPreferencesShowNav') == 'true' ) {
         NavigationBarShowDefault = 999;
    } else {
         NavigationBarShowDefault = 999;
    }
});

 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;}
   }
  }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;}
   }
  }
 }
 indexNavigationBar = 0;
 function createNavigationBarToggleButton() {
  for (i=0; NavFrame = $t("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+')');
    var NavToggleText = document.createTextNode(NavigationBarHide);
    NavToggle.appendChild(NavToggleText);
    NavFrame.insertBefore(NavToggle, NavFrame.firstChild);
    NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
   }
  }
  if (NavigationBarShowDefault < indexNavigationBar) {
   for (var i=1; i<=indexNavigationBar; i++) {toggleNavigationBar(i);}
  }
 }
 $(document).ready(createNavigationBarToggleButton);

 // Urgently change ID to class...
 function closedNavBar() {
 	mw.loader.using( ['jquery.cookie'], function () {
    if ($.cookie('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 ($.cookie('WiktionaryPreferencesHideNav') == 'true' ) {
         toggleNavigationBar(100);
    } else if ($.cookie('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) {
   if (document.getElementById("Vorlage_Siehe_auch")) {
    document.getElementById("contentSub").style.margin = "0";
    document.getElementById("contentSub").innerHTML += document.getElementById("Vorlage_Siehe_auch").innerHTML;
   } else if (document.getElementById("showSeeAlso")) {
    document.getElementById("contentSub").style.margin = "0";
    document.getElementById("contentSub").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
if (mw.config.get('wgPageName') == "Hilfe:Reime") {
 mw.loader.load(["mediawiki.action.edit", "mediawiki.toolbar"]);
 }

 /* </nowiki> */