MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus SchnuppTrupp
Wechseln zu: Navigation, Suche
K
Zeile 8: Zeile 8:
 
   }
 
   }
 
}
 
}
 +
 +
$( setup );
 +
 
function toSt2(n) {
 
function toSt2(n) {
 
   s = "";
 
   s = "";
Zeile 55: Zeile 58:
 
}
 
}
  
//================================================================================
+
/** Collapsible tables *********************************************************
//*** Dynamic Navigation Bars
+
*
 +
* Description: Allows tables to be collapsed, showing only the header. See
 +
*               [[Wikipedia:NavFrame]].
 +
*  Maintainers: [[User:R. Koot]]
 +
*/
 
   
 
   
// set up the words in your language
+
var autoCollapse = 2;
var NavigationBarHide = 'Einklappen';
+
var collapseCaption = "verbergen";
var NavigationBarShow = 'Ausklappen';
+
var expandCaption = "anzeigen";
 
   
 
   
// set up max count of Navigation Bars on page,
+
function collapseTable( tableIndex ){
// if there are more, all will be hidden
+
    var Button = document.getElementById( "collapseButton" + tableIndex );
NavigationBarShowDefault = 0; // all bars will be hidden
+
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
+
if (typeof NavigationBarShowDefault == 'undefined' ) {
+
    if ( !Table || !Button ) {
     var NavigationBarShowDefault = 1;
+
        return false;
 +
    }
 +
 +
    var Rows = Table.rows;
 +
 +
    if ( Button.firstChild.data == collapseCaption ) {
 +
        for ( var i = 1; i < Rows.length; i++ ) {
 +
            Rows[i].style.display = "none";
 +
        }
 +
        Button.firstChild.data = expandCaption;
 +
     } else {
 +
        for ( var i = 1; i < Rows.length; i++ ) {
 +
            Rows[i].style.display = Rows[0].style.display;
 +
        }
 +
        Button.firstChild.data = collapseCaption;
 +
    }
 
}
 
}
 
   
 
   
// adds show/hide-button to navigation bars
+
function createCollapseButtons(){
addOnloadHook(function() {
+
    var tableIndex = 0;
// shows and hides content and picture (if available) of navigation bars
+
     var NavigationBoxes = new Object();
// Parameters:
+
    var Tables = document.getElementsByTagName( "table" );
//     indexNavigationBar: the index of navigation bar to be toggled
+
function toggleNavigationBar(NavToggle, NavFrame)
+
{
+
  if (!NavFrame || !NavToggle) {
+
  return false;
+
  }
+
 
   
 
   
  // if shown now
+
    for ( var i = 0; i < Tables.length; i++ ) {
  if (NavToggle.firstChild.data == NavigationBarHide) {
+
        if ( hasClass( Tables[i], "collapsible" ) ) {
  for (
+
  var 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;
+
  }
+
  }
+
 
   
 
   
  // if hidden now
+
            /* only add button and increment count if there is a header row to work with */
  } else if (NavToggle.firstChild.data == NavigationBarShow) {
+
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
  for (
+
            if (!HeaderRow) continue;
  var NavChild = NavFrame.firstChild;
+
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
  NavChild != null;
+
            if (!Header) continue;
  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;
+
  }
+
  }
+
  }
+
}
+
 
   
 
   
function toggleNavigationBarFunction(NavToggle, NavFrame) {
+
            NavigationBoxes[ tableIndex ] = Tables[i];
return function() {
+
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
toggleNavigationBar(NavToggle, NavFrame);
+
return false;
+
};
+
}
+
// iterate over all NavFrames
+
var content = document.getElementById("content") || document.getElementById("mw_content");
+
var NavFrames = getElementsByClassName(content, "div", "NavFrame");
+
// if more Navigation Bars found and not template namespace than Default: hide all
+
var initiallyToggle = NavigationBarShowDefault < NavFrames.length && wgNamespaceNumber != 10;
+
for (var i=0; i<NavFrames.length; i++) {
+
var NavFrame = NavFrames[i];
+
var NavToggle = document.createElement("a");
+
NavToggle.className = 'NavToggle';
+
NavToggle.setAttribute('href', '#');
+
 
   
 
   
var NavToggleText = document.createTextNode(NavigationBarHide);
+
            var Button    = document.createElement( "span" );
NavToggle.appendChild(NavToggleText);
+
            var ButtonLink = document.createElement( "a" );
 +
            var ButtonText = document.createTextNode( collapseCaption );
 
   
 
   
// add NavToggle-Button as first div-element
+
            Button.className = "collapseButton";  //Styles are declared in Common.css
// in < div class="NavFrame" >
+
NavFrame.insertBefore(NavToggle, NavFrame.firstChild);
+
            ButtonLink.style.color = Header.style.color;
 +
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
 +
            ButtonLink.setAttribute( "href", "#" );
 +
            addHandler( ButtonLink,  "click", new Function( "evt", "collapseTable(" + tableIndex + " ); return killEvt( evt );") );
 +
            ButtonLink.appendChild( ButtonText );
 +
 +
            Button.appendChild( document.createTextNode( "[" ) );
 +
            Button.appendChild( ButtonLink );
 +
            Button.appendChild( document.createTextNode( "]" ) );
 +
 +
            Header.insertBefore( Button, Header.childNodes[0] );
 +
            tableIndex++;
 +
        }
 +
    }
 +
 +
    for ( var i = 0;  i < tableIndex; i++ ) {
 +
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
 +
            collapseTable( i );
 +
        }
 +
        else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
 +
            var element = NavigationBoxes[i];
 +
            while (element = element.parentNode) {
 +
                if ( hasClass( element, "outercollapse" ) ) {
 +
                    collapseTable ( i );
 +
                    break;
 +
                }
 +
            }
 +
        }
 +
    }
 +
}
 +
 +
$( createCollapseButtons );
 +
 +
 +
/** Dynamic Navigation Bars (experimental) *************************************
 +
*
 +
*  Description: See [[Wikipedia:NavFrame]].
 +
*  Maintainers: UNMAINTAINED
 +
*/
 +
 +
// set up the words in your language
 +
var NavigationBarHide = '[' + collapseCaption + ']';
 +
var NavigationBarShow = '[' + expandCaption + ']';
 +
 +
// 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 NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
 +
 +
    if (!NavFrame || !NavToggle) {
 +
        return false;
 +
    }
 +
 +
    // if shown now
 +
    if (NavToggle.firstChild.data == NavigationBarHide) {
 +
        for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
 +
            if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
 +
                NavChild.style.display = 'none';
 +
            }
 +
        }
 +
    NavToggle.firstChild.data = NavigationBarShow;
 +
 +
    // if hidden now
 +
    } else if (NavToggle.firstChild.data == NavigationBarShow) {
 +
        for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
 +
            if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
 +
                NavChild.style.display = 'block';
 +
            }
 +
        }
 +
        NavToggle.firstChild.data = NavigationBarHide;
 +
    }
 +
}
 +
 +
// adds show/hide-button to navigation bars
 +
function createNavigationBarToggleButton(){
 +
    var indexNavigationBar = 0;
 +
    // iterate over all < div >-elements
 +
    var divs = document.getElementsByTagName("div");
 +
    for (var i = 0; NavFrame = divs[i]; i++) {
 +
        // if found a navigation bar
 +
        if (hasClass(NavFrame, "NavFrame")) {
 +
 +
            indexNavigationBar++;
 +
            var NavToggle = document.createElement("a");
 +
            NavToggle.className = 'NavToggle';
 +
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
 +
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
 +
 +
            var isCollapsed = hasClass( NavFrame, "collapsed" );
 +
            /*
 +
            * Check if any children are already hidden.  This loop is here for backwards compatibility:
 +
            * the old way of making NavFrames start out collapsed was to manually add style="display:none"
 +
            * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
 +
            * the content visible without JavaScript support), the new recommended way is to add the class
 +
            * "collapsed" to the NavFrame itself, just like with collapsible tables.
 +
            */
 +
            for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
 +
                if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
 +
                    if ( NavChild.style.display == 'none' ) {
 +
                        isCollapsed = true;
 +
                    }
 +
                }
 +
            }
 +
            if (isCollapsed) {
 +
                for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
 +
                    if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
 +
                        NavChild.style.display = 'none';
 +
                    }
 +
                }
 +
            }
 +
            var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
 +
            NavToggle.appendChild(NavToggleText);
 +
 +
            // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
 +
            for(var j=0; j < NavFrame.childNodes.length; j++) {
 +
                if (hasClass(NavFrame.childNodes[j], "NavHead")) {
 +
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
 +
                    NavFrame.childNodes[j].appendChild(NavToggle);
 +
                }
 +
            }
 +
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
 +
        }
 +
    }
 +
}
 
   
 
   
NavToggle.onclick = toggleNavigationBarFunction(NavToggle, NavFrame);
+
$( createNavigationBarToggleButton );
if (initiallyToggle) {
+
          
toggleNavigationBar(NavToggle, NavFrame);
+
}
+
}
+
         setup();
+
 
});
 
});

Version vom 6. Juli 2011, 14:18 Uhr

/* Das folgende JavaScript wird für alle Benutzer geladen. */

function setup() {
  if (document.getElementById('countdown')) {
    if (end = new Date(document.getElementById('countdown').innerHTML)) {
      setTimeout("countdown()", 500);
    }
  }
}

$( setup );

function toSt2(n) {
  s = "";
  if (n < 10) s += "0";
  return (s + n).toString();
}
function toSt3(n) {
  s = "";
  if (n < 10) s += "00";
  else if (n < 100) s += "0";
  return (s + n).toString();
}
function countdown() {
  var tname = ' Tage ';
  var hname = ' Stunden ';
  var mname = ' Minuten ';
  var sname = ' Sekunden ';
  var d = new Date();
  var count = Math.floor(end.getTime() - d.getTime());
  if(count > 0) {
    var miliseconds = toSt3(count%1000); count = Math.floor(count/1000);
    var seconds = toSt2(count%60); count = Math.floor(count/60);
    if (seconds==1) {
      sname = ' Sekunde ';
    }
    var minutes = toSt2(count%60); count = Math.floor(count/60);
    if (minutes==1) {
      mname = ' Minute ';
    }
    var hours = toSt2(count%24); count = Math.floor(count/24);
    if (hours==1) {
      hname = ' Stunde ';
    }
    var days = count;
    if (days==1) {
      tname = ' Tag ';
    }
    document.getElementById('countdown').innerHTML = days + tname + hours + hname + minutes + mname + seconds + sname +'';
    setTimeout("countdown()", 1000);
  }
}

function rskpopup (url,name,x,y) {
    newwindow= window.open(url, name, "width=" + x + ",height=" + y + ",scrollbars=no,location=no");
    newwindow.focus();

}

/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               [[Wikipedia:NavFrame]].
 *  Maintainers: [[User:R. Koot]]
 */
 
var autoCollapse = 2;
var collapseCaption = "verbergen";
var expandCaption = "anzeigen";
 
function collapseTable( tableIndex ){
    var Button = document.getElementById( "collapseButton" + tableIndex );
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
 
    if ( !Table || !Button ) {
        return false;
    }
 
    var Rows = Table.rows;
 
    if ( Button.firstChild.data == collapseCaption ) {
        for ( var i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = "none";
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( var i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
}
 
function createCollapseButtons(){
    var tableIndex = 0;
    var NavigationBoxes = new Object();
    var Tables = document.getElementsByTagName( "table" );
 
    for ( var i = 0; i < Tables.length; i++ ) {
        if ( hasClass( Tables[i], "collapsible" ) ) {
 
            /* only add button and increment count if there is a header row to work with */
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
            if (!HeaderRow) continue;
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
            if (!Header) continue;
 
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
 
            var Button     = document.createElement( "span" );
            var ButtonLink = document.createElement( "a" );
            var ButtonText = document.createTextNode( collapseCaption );
 
            Button.className = "collapseButton";  //Styles are declared in Common.css
 
            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
            ButtonLink.setAttribute( "href", "#" );
            addHandler( ButtonLink,  "click", new Function( "evt", "collapseTable(" + tableIndex + " ); return killEvt( evt );") );
            ButtonLink.appendChild( ButtonText );
 
            Button.appendChild( document.createTextNode( "[" ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( "]" ) );
 
            Header.insertBefore( Button, Header.childNodes[0] );
            tableIndex++;
        }
    }
 
    for ( var i = 0;  i < tableIndex; i++ ) {
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
            collapseTable( i );
        } 
        else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
            var element = NavigationBoxes[i];
            while (element = element.parentNode) {
                if ( hasClass( element, "outercollapse" ) ) {
                    collapseTable ( i );
                    break;
                }
            }
        }
    }
}
 
$( createCollapseButtons );
 
 
/** Dynamic Navigation Bars (experimental) *************************************
 *
 *  Description: See [[Wikipedia:NavFrame]].
 *  Maintainers: UNMAINTAINED
 */
 
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
 
// 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 NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
 
    if (!NavFrame || !NavToggle) {
        return false;
    }
 
    // if shown now
    if (NavToggle.firstChild.data == NavigationBarHide) {
        for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
            if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;
 
    // if hidden now
    } else if (NavToggle.firstChild.data == NavigationBarShow) {
        for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
            if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }
}
 
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton(){
    var indexNavigationBar = 0;
    // iterate over all < div >-elements 
    var divs = document.getElementsByTagName("div");
    for (var i = 0; NavFrame = divs[i]; i++) {
        // if found a navigation bar
        if (hasClass(NavFrame, "NavFrame")) {
 
            indexNavigationBar++;
            var NavToggle = document.createElement("a");
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
 
            var isCollapsed = hasClass( NavFrame, "collapsed" );
            /*
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
             * the old way of making NavFrames start out collapsed was to manually add style="display:none"
             * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
             * the content visible without JavaScript support), the new recommended way is to add the class
             * "collapsed" to the NavFrame itself, just like with collapsible tables.
             */
            for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
                if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
                    if ( NavChild.style.display == 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if (isCollapsed) {
                for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
                    if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
            NavToggle.appendChild(NavToggleText);
 
            // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
            for(var j=0; j < NavFrame.childNodes.length; j++) {
                if (hasClass(NavFrame.childNodes[j], "NavHead")) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild(NavToggle);
                }
            }
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
        }
    }
}
 
$( createNavigationBarToggleButton );
        
});