MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus HuskyWiki
Die Seite wurde neu angelegt: →‎Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen.: //============================================================= //*** Configuration for "s...
 
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */
/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */


//=============================================================
/* Any JavaScript here will be loaded for all users on every page load. */
//*** Configuration for "star" logo in front of interwiki links to Featured Articles


/** set to false in Special:Mypage/monobook.js to switch off this "feature" */
// <syntax type="javascript">
var linkFA_enabled  = true;
/** description that is displayed when cursor hovers above FA interwiki links */
var linkFA_description = "Dieser Artikel wurde als exzellent bewertet.";


// linkFA_bullet and linkFA_style werden nur für cologneblue, nostalgia and standard verwendet,
    /**
// für monobook und simple siehe [[MediaWiki:Common.css]]
        Toggles the display of elements on a page
        Author/contact: Austin Che http://openwetware.org/wiki/User:Austin_J._Che
        See http://openwetware.org/wiki/OpenWetWare:Toggle for examples and documentation
    */


/** image to use instead of the standard bullet (for cologneblue, nostalgia and standard */
// indexed array of toggler ids to array of associated toggle operations
var linkFA_bullet = "http://upload.wikimedia.org/wikipedia/commons/d/d0/Monobook-bullet-star-transparent.png";
// each operation is a two element array, the first being the type, the second a class name or array of elements
// operation types are strings like "_reset" or "" for the default toggle operation
var togglers = new Array();   
var allClasses = new Object(); // associative map of class names to page elements


/** style to use for the linkFA_bullet img */
function toggler(id)
var linkFA_style = "margin-right: 0.2em;";
{
    var toBeToggled = togglers[id];
    if (!toBeToggled)
        return;


/**
     // if some element is in list more than once, it will be toggled multiple times
* star logo for featured articles in other languages,
     for (var i = 0; i < toBeToggled.length; i++)
* see Template:Link_FA and MediaWiki:Common.css
    {
*/
        // get array of elements to operate on
addOnloadHook(function() {
        var toggles = toBeToggled[i][1];
     // early exit when disabled
        if (typeof(toggles) == "string")
    if (!linkFA_enabled) return;
         {
   
            if (toggles.charAt(0) == '-')
    // skins need to be treated differently
             {
    if (skin == "monobook" || skin == "simple") {
                // treat as an element ID, not as class
        newer();
                toggles = document.getElementById(toggles.substring(1));
    }
                if (toggles)
    else if (skin == "cologneblue" || skin == "nostalgia" || skin == "standard") {
                    toggles = new Array(toggles);
        older();
    }
      
    /** skin == "monobook" || skin == "simple" */
    function newer() {
        // links are to replaced in p-lang only
        var pLang = document.getElementById("p-lang");
        if (!pLang) return;
        var lis = pLang.getElementsByTagName("li");
        for (var i = 0; i < lis.length; i++) {
            var li = lis[i];
            // only links with a corresponding Link_FA template are interesting
            if (!document.getElementById(li.className + "-fa"))   continue;
            // additional class so the template can be hidden with CSS
            li.className += " FA";
            // change title
            li.title = linkFA_description;
        }
    }
   
    /** skin == "cologneblue" || skin == "nostalgia" || skin == "standard" */
    function older() {
         // these root elements can contain FA-links
        var rootIds = new Array("topbar", "footer");
        for (var i=0; i<rootIds.length; i++) {
            var rootId  = rootIds[i];
            var root    = document.getElementById(rootId);
             if (!root)  continue;
           
            // if the root exists, try to decorate all the links within
            var links  = root.getElementsByTagName("a");
            for (var j=0; j<links.length; j++) {
                var link    = links[j];
                decorate(link);
             }
             }
            else
                toggles = allClasses[toggles];
         }
         }
    }
         if (!toggles || !toggles.length)
   
            continue;
    /** id necessary, modify a link to show the FA-star (older) */
    function decorate(link) {
        // exit if not a FA-link
        var lang    = link.title.split(":")[0]; // not precise enough
        var fa      = document.getElementById("interwiki-" + lang + "-fa");
         if (!fa)    return;
        // possible problem owing the standard skin: "Link FA" template is transcluded with a non-interwiki parameter, for example "Special"
        // result: links to special pages in the topbar and/or footer might also be marked as a Featured Article
       
        // build an image-node for the FA-star
        var img = document.createElement("img");
        img.setAttribute("src",    linkFA_bullet);
        img.setAttribute("alt",    linkFA_description);
        img.setAttribute("style",  linkFA_style);
       
        // decorate the link with the image
        link.appendChild(img);
        link.appendChild(link.removeChild(link.firstChild));
        link.setAttribute("title", linkFA_description);
    }
});


//==============================================================================
        var op = toBeToggled[i][0]; // what the operation will be
//*** Fügt einen Link "Alle Sprachen" auf der Hauptseite unter die Sprachverweise hinzu
addOnloadHook(function() {
  // only on the main page
  if ( wgTitle != 'Hauptseite' || wgNamespaceNumber != 0 )    return;
 
  try {
      var node = document.getElementById( "p-lang" )
                          .getElementsByTagName('div')[0]
                          .getElementsByTagName('ul')[0];


      var aNode = document.createElement( 'a' );
        switch (op)
      var liNode = document.createElement( 'li' );
        {
 
            case "_reset":
      aNode.appendChild( document.createTextNode( 'Alle Sprachen' ) );
                for (var j in toggles)
      aNode.setAttribute( 'href' , 'http://de.wikipedia.org/wiki/Wikipedia:Sprachen' );
                    toggles[j].style.display = toggles[j]._toggle_original_display;
      liNode.appendChild( aNode );
                break;
      liNode.className = 'interwiki-completelist';
            case "_show":
      node.appendChild( liNode );
                for (var j in toggles)
    } catch(e) {
                    toggles[j].style.display = '';
        // lets just ignore what's happened
                break;
            case "_hide":
                for (var j in toggles)
                    toggles[j].style.display = 'none';
                break;
            case "":
            default:
                // Toggle
                for (var j in toggles)
                    toggles[j].style.display = ((toggles[j].style.display == 'none') ? '' : 'none');
                break;
        }
     }
     }
});
//==============================================================================
//*** Verändert die Tabellensortierfunktion so, dass auch deutsche Tausenderpunkt und Dezimalkommata gehen
// Original aus sv.wikipedia.org
function ts_parseFloat(num) {
    if (!num) return 0;
    num = num.replace(/\./g, "");
    num = num.replace(/,/, ".");
    num = parseFloat(num);
    return (isNaN(num) ? 0 : num);
}
}


//==============================================================================
function createTogglerLink(toggler, id)
//*** forcePreview: erzwungene vorschau für IPs
{
 
     var toggle = document.createElement("a");
/*
     toggle.className = 'toggler-link';
* Zwingt IPs zuerst die Vorschau zu benutzen, bevor sie speichern können.
     toggle.setAttribute('id', 'toggler' + id);
* Copyright Marc Mongenet, 2006 aus frwp
     toggle.setAttribute('href', 'javascript:toggler("' + id + '");');
*/
    var child = toggler.firstChild;
addOnloadHook(function() {
    toggler.removeChild(child);
     if (wgUserName != null || wgAction != "edit") return;
    toggle.appendChild(child);
    saveButton = document.getElementById("wpSave");
     toggler.insertBefore(toggle, toggler.firstChild);
     if (!saveButton) return;
    saveButton.disabled = true;
     saveButton.value = "Seite speichern (Bitte erst die Vorschau benutzen)";
     saveButton.style.fontWeight = "normal";
    document.getElementById("wpPreview").style.fontWeight = "bold";
});
 
//==============================================================================
//*** Fügt der Suche weitere Suchengines hinzu (kopiert aus eswp)
 
/*
document.write('<script type="text/javascript" src="'  
        + '/w/index.php?title=MediaWiki:SpezialSuche.js'
        + '&action=raw&ctype=text/javascript&dontcountme=s&smaxage=3600"></script>');
*/
 
//================================================================================
//*** force the loading of another JavaScript file (Kopie von [[Commons:Common.js]])
// Local Maintainer: [[Commons:User:Dschwen]]
 
function includePage(name) {
     document.write('<script type="text/javascript" src="' + wgScript + '?title='
        + name
        + '&action=raw&ctype=text/javascript"><\/script>');
}
}


//================================================================================
function toggleInit()
//*** import Onlyifuploading-functions
// SEE ALSO [[MediaWiki:Onlyifuploading.js]]
 
if (wgCanonicalSpecialPageName == "Upload") {
    document.write('<script type="text/javascript" src="/w/index.php?title=MediaWiki:Onlyifuploading.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
}
 
//================================================================================
//*** Dynamic Navigation Bars
 
// set up the words in your language
var NavigationBarHide = 'Einklappen';
var NavigationBarShow = 'Ausklappen';
 
// set up max count of Navigation Bars on page,
// if there are more, all will be hidden
// NavigationBarShowDefault = 0; // all bars will be hidden
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
if (typeof NavigationBarShowDefault == 'undefined' ) {
    var NavigationBarShowDefault = 1;
}
 
// shows and hides content and picture (if available) of navigation bars
// Parameters:
//    indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
{
  var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
    var togglerElems = new Array();
  var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
    var toggleGroup = new Array();


  if (!NavFrame || !NavToggle) {
    // initialize/clear any old information
      return false;
    togglers = new Array();   
  }
    allClasses = new Object();
       
    // make list of all document classes
    var elems = document.getElementsByTagName("*");
    var numelems = elems.length;
    for (var i = 0; i < elems.length; i++)
    {
        var elem = elems[i];
        if (!elem.className)
            continue;


  // if shown now
        elem._toggle_original_display = elem.style.display;
  if (NavToggle.firstChild.data == NavigationBarHide) {
        var togglerID = -1;
      for (
        var elemClasses = elem.className.split(' '); // get list of classes
              var NavChild = NavFrame.firstChild;
        for (var j = 0; j < elemClasses.length; j++)
              NavChild != null;
        {
              NavChild = NavChild.nextSibling
            var elemClass = elemClasses[j];
          ) {
            if (! allClasses[elemClass])
          if (NavChild.className == 'NavPic') {
                allClasses[elemClass] = new Array();
              NavChild.style.display = 'none';
            allClasses[elemClass].push(elem);
          }
          if (NavChild.className == 'NavContent') {
              NavChild.style.display = 'none';
          }
          if (NavChild.className == 'NavToggle') {
              NavChild.firstChild.data = NavigationBarShow;
          }
      }


  // if hidden now
            // all the special classes begin with _toggle
  } else if (NavToggle.firstChild.data == NavigationBarShow) {
            if (elemClass.substring(0, 7) != "_toggle")
      for (
                continue;
              var 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;
          }
      }
  }
}


// adds show/hide-button to navigation bars
            if (elemClass == "_togglegroup")
function createNavigationBarToggleButton()
                toggleGroup = new Array();
{
            else if (elemClass == "_toggle")
  var indexNavigationBar = 0;
                toggleGroup.push(elem);
  // iterate over all < div >-elements
            else if (elemClass.substring(0, 12) == "_toggle_init")
  var divs = document.getElementsByTagName("div");
            {
  for (var i=0;  i<divs.length; i++) {
                // set initial value for display (ignore the original CSS set value)
      var NavFrame = divs[i];
                // understands _toggle_initshow and _toggle_inithide
      // if found a navigation bar
                var disp = elemClass.substring(12);
      if (NavFrame.className == "NavFrame") {
                if (disp == "show")
                    elem.style.display = '';
                else if (disp == "hide")
                    elem.style.display = 'none';
                elem._toggle_original_display = disp;
            }
            else if (elemClass.substring(0, 8) == "_toggler")
            {
                if (togglerID == -1)
                {
                    togglerID = togglers.length;
                    togglers[togglerID] = new Array();
                    togglerElems[togglerID] = elem;
                }


          indexNavigationBar++;
                // all classes are of form _toggler_op-CLASS
          var NavToggle = document.createElement("a");
                // figure out what class we're toggling
          NavToggle.className = 'NavToggle';
                // if none is specified, then we use the current toggle group
          NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
                var toBeToggled;
          NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
                var hyphen = elemClass.indexOf('-');
                if (hyphen != -1)
                    toBeToggled = elemClass.substring(hyphen+1);
                else
                {
                    toBeToggled = toggleGroup;
                    hyphen = elemClass.length;
                }


          var NavToggleText = document.createTextNode(NavigationBarHide);
                var op = elemClass.substring(8, hyphen);
          NavToggle.appendChild(NavToggleText);
                togglers[togglerID].push(new Array(op, toBeToggled));
 
            }
          // add NavToggle-Button as first div-element
        }
          // in < div class="NavFrame" >
    }
          NavFrame.insertBefore(
              NavToggle,
              NavFrame.firstChild
          );
          NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
      }
  }
  // if more Navigation Bars found than Default: hide all
  if (NavigationBarShowDefault < indexNavigationBar) {
      for(
              var i=1;
              i<=indexNavigationBar;
              i++
      ) {
          toggleNavigationBar(i);
      }
  }


    // add javascript links to all toggler elements
    for (var i = 0; i < togglerElems.length; i++)
        createTogglerLink(togglerElems[i], i);
}
}


addOnloadHook(createNavigationBarToggleButton);
addOnloadHook(toggleInit);


//================================================================================
// </syntax>
//*** import Onlyifediting-functions
// SEE ALSO [[MediaWiki:Onlyifediting.js]]
if (document.URL.indexOf("action=edit") > 0 || document.URL.indexOf("action=submit") > 0) {
    document.write('<script type="text/javascript" src="/w/index.php?title=MediaWiki:Onlyifediting.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
}

Version vom 10. Mai 2008, 15:28 Uhr

/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */

/* Any JavaScript here will be loaded for all users on every page load. */

// <syntax type="javascript">

    /** 
        Toggles the display of elements on a page 
        Author/contact: Austin Che http://openwetware.org/wiki/User:Austin_J._Che
        See http://openwetware.org/wiki/OpenWetWare:Toggle for examples and documentation
     */

// indexed array of toggler ids to array of associated toggle operations
// each operation is a two element array, the first being the type, the second a class name or array of elements
// operation types are strings like "_reset" or "" for the default toggle operation
var togglers = new Array();     
var allClasses = new Object(); // associative map of class names to page elements

function toggler(id)
{
    var toBeToggled = togglers[id];
    if (!toBeToggled)
        return;

    // if some element is in list more than once, it will be toggled multiple times
    for (var i = 0; i < toBeToggled.length; i++)
    {
        // get array of elements to operate on
        var toggles = toBeToggled[i][1];
        if (typeof(toggles) == "string")
        {
            if (toggles.charAt(0) == '-')
            {
                // treat as an element ID, not as class
                toggles = document.getElementById(toggles.substring(1));
                if (toggles)
                    toggles = new Array(toggles);
            }
            else
                toggles = allClasses[toggles];
        }
        if (!toggles || !toggles.length)
            continue;

        var op = toBeToggled[i][0]; // what the operation will be

        switch (op)
        {
            case "_reset":
                for (var j in toggles)
                    toggles[j].style.display = toggles[j]._toggle_original_display;
                break;
            case "_show":
                for (var j in toggles)
                    toggles[j].style.display = '';
                break;
            case "_hide":
                for (var j in toggles)
                    toggles[j].style.display = 'none';
                break;
            case "":
            default:
                // Toggle
                for (var j in toggles)
                    toggles[j].style.display = ((toggles[j].style.display == 'none') ? '' : 'none');
                break;
        }
    }
}

function createTogglerLink(toggler, id)
{
    var toggle = document.createElement("a");
    toggle.className = 'toggler-link';
    toggle.setAttribute('id', 'toggler' + id);
    toggle.setAttribute('href', 'javascript:toggler("' + id + '");');
    var child = toggler.firstChild;
    toggler.removeChild(child);
    toggle.appendChild(child);
    toggler.insertBefore(toggle, toggler.firstChild);
}

function toggleInit()
{
    var togglerElems = new Array();
    var toggleGroup = new Array();

    // initialize/clear any old information
    togglers = new Array();     
    allClasses = new Object();
        
    // make list of all document classes
    var elems = document.getElementsByTagName("*");
    var numelems = elems.length;
    for (var i = 0; i < elems.length; i++)
    {
        var elem = elems[i];
        if (!elem.className)
            continue;

        elem._toggle_original_display = elem.style.display;
        var togglerID = -1;
        var elemClasses = elem.className.split(' '); // get list of classes
        for (var j = 0; j < elemClasses.length; j++)
        {
            var elemClass = elemClasses[j];
            if (! allClasses[elemClass])
                allClasses[elemClass] = new Array();
            allClasses[elemClass].push(elem);

            // all the special classes begin with _toggle
            if (elemClass.substring(0, 7) != "_toggle")
                continue;

            if (elemClass == "_togglegroup")
                toggleGroup = new Array();
            else if (elemClass == "_toggle")
                toggleGroup.push(elem);
            else if (elemClass.substring(0, 12) == "_toggle_init")
            {
                // set initial value for display (ignore the original CSS set value)
                // understands _toggle_initshow and _toggle_inithide
                var disp = elemClass.substring(12);
                if (disp == "show")
                    elem.style.display = '';
                else if (disp == "hide")
                    elem.style.display = 'none';
                elem._toggle_original_display = disp;
            }
            else if (elemClass.substring(0, 8) == "_toggler")
            {
                if (togglerID == -1)
                {
                    togglerID = togglers.length;
                    togglers[togglerID] = new Array();
                    togglerElems[togglerID] = elem;
                }

                // all classes are of form _toggler_op-CLASS
                // figure out what class we're toggling
                // if none is specified, then we use the current toggle group
                var toBeToggled;
                var hyphen = elemClass.indexOf('-');
                if (hyphen != -1)
                    toBeToggled = elemClass.substring(hyphen+1);
                else
                {
                    toBeToggled = toggleGroup;
                    hyphen = elemClass.length;
                }

                var op = elemClass.substring(8, hyphen);
                togglers[togglerID].push(new Array(op, toBeToggled));
            }
        }
    }

    // add javascript links to all toggler elements
    for (var i = 0; i < togglerElems.length; i++)
        createTogglerLink(togglerElems[i], i);
}

addOnloadHook(toggleInit);

// </syntax>