Difference between revisions of "MediaWiki:Common.js"

From EncyclopAtys

Jump to: navigation, search
(Fixed directories)
(Code is obsolete)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
βˆ’
function hs(id,mod) {
+
/* nothing anymore */
βˆ’
if(document.getElementById(id).style.display == 'none') {
 
βˆ’
document.getElementById(id).style.display=mod;
 
βˆ’
}
 
βˆ’
else {
 
βˆ’
document.getElementById(id).style.display='none';
 
βˆ’
}
 
βˆ’
}
 
βˆ’
 
 
βˆ’
/** Collapsible tables *********************************************************
 
βˆ’
*
 
βˆ’
*  Description: Allows tables to be collapsed, showing only the header. See
 
βˆ’
*              http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
 
βˆ’
*  Maintainers: [[**MAINTAINERS**]]
 
βˆ’
*/
 
βˆ’
var autoCollapse = 2;
 
βˆ’
var collapseCaption = 'hide';
 
βˆ’
var expandCaption = 'show';
 
βˆ’
 
βˆ’
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 Button2    = document.createElement( 'span' );
 
βˆ’
var Button    = document.createElement( 'span' );
 
βˆ’
var ButtonLink = document.createElement( 'a' );
 
βˆ’
var ButtonText = document.createTextNode( collapseCaption );
 
βˆ’
 
βˆ’
Button2.className = 'collapseButton_outer';
 
βˆ’
Button.className = 'collapseButton'; // Styles are declared in MediaWiki:Common.css
 
βˆ’
                        if(hasClass( Tables[i], 'dark' )) {
 
βˆ’
                          Button.className = Button.className+'_dark';
 
βˆ’
                        }
 
βˆ’
 
 
βˆ’
ButtonLink.style.color = Header.style.color;
 
βˆ’
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
 
βˆ’
ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" );
 
βˆ’
ButtonLink.appendChild( ButtonText );
 
βˆ’
 
βˆ’
Button.appendChild( document.createTextNode( '[' ) );
 
βˆ’
Button.appendChild( ButtonLink );
 
βˆ’
Button.appendChild( document.createTextNode( ']' ) );
 
βˆ’
Button2.appendChild( Button );
 
βˆ’
Header.insertBefore( Button2, Header.childNodes[0] );
 
βˆ’
tableIndex++;
 
βˆ’
}
 
βˆ’
}
 
βˆ’
 
βˆ’
for ( var i = 0;  i < tableIndex; i++ ) {
 
βˆ’
if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
 
βˆ’
collapseTable( i );
 
βˆ’
}
 
βˆ’
}
 
βˆ’
}
 
βˆ’
 
βˆ’
// addOnloadHook( createCollapseButtons );
 
βˆ’
 
βˆ’
/** Test if an element has a certain class **************************************
 
βˆ’
*
 
βˆ’
* Description: Uses regular expressions and caching for better performance.
 
βˆ’
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 
βˆ’
*/
 
βˆ’
 
βˆ’
var hasClass = (function() {
 
βˆ’
var reCache = {};
 
βˆ’
return function( element, className ) {
 
βˆ’
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
 
βˆ’
};
 
βˆ’
})();
 
βˆ’
 
βˆ’
 
βˆ’
/** 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")) {
 
βˆ’
                    NavFrame.childNodes[j].appendChild(NavToggle);
 
βˆ’
                }
 
βˆ’
            }
 
βˆ’
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
 
βˆ’
        }
 
βˆ’
    }
 
βˆ’
}
 
βˆ’
 
βˆ’
// addOnloadHook( createNavigationBarToggleButton );
 
βˆ’
 
 
βˆ’
 
 
βˆ’
/** <nowiki> **/
 
βˆ’
/** additional scripts **/
 
βˆ’
if ( wgIsArticle || window.location.href.indexOf( 'action=submit' ) > -1 )
 
βˆ’
{
 
βˆ’
  addScript( 'MediaWiki:CollapsibleTables.js' );
 
βˆ’
  hookEvent( 'load', function()
 
βˆ’
  {
 
βˆ’
    new CollapsibleTables();
 
βˆ’
    diffwithFix();
 
βˆ’
   
 
βˆ’
    // Extension for the deletion drop down list
 
βˆ’
    if ( wgAction == 'delete' && ( delReasonBtn = document.getElementById( 'wpConfirmB' ) ) )
 
βˆ’
    {
 
βˆ’
      var delReasonList        = document.getElementById( 'wpDeleteReasonList' );
 
βˆ’
      var delLink              = document.createElement( 'a' );
 
βˆ’
      delLink.href            = 'javascript:void(0);'
 
βˆ’
      delLink.title            = document.getElementById( 'wpReason' ).value;
 
βˆ’
      delLink.style.fontSize  = '0.9em';
 
βˆ’
      delLink.style.marginLeft = '1em';
 
βˆ’
      delLink.onclick          = function()
 
βˆ’
      {
 
βˆ’
        document.getElementById( 'wpReason' ).value = this.title;
 
βˆ’
      }
 
βˆ’
      delReasonList.onchange  = function ()
 
βˆ’
      {
 
βˆ’
        document.getElementById( 'wpReason' ).value = '';
 
βˆ’
        this.onchange = null;
 
βˆ’
      }
 
βˆ’
      delLink.appendChild( document.createTextNode( 'restore default reason' ) );
 
βˆ’
      delReasonBtn.parentNode.appendChild( delLink );
 
βˆ’
      delete delLink, delReasonList, delReasonBtn;
 
βˆ’
    }
 
βˆ’
  } );
 
βˆ’
}
 
βˆ’
if ( wgPageName == 'Special:Upload' && document.getElementById( 'mw-upload-form' ) !== 'undefined' )
 
βˆ’
{
 
βˆ’
  addScript( 'MediaWiki:UploadForm.js' );
 
βˆ’
  hookEvent( 'load', function()
 
βˆ’
  {
 
βˆ’
    new UploadForm();
 
βˆ’
  } );
 
βˆ’
}
 
βˆ’
 
 
βˆ’
/**** function addScript.js
 
βˆ’
* by Patrick Westerhoff [poke]
 
βˆ’
*/
 
βˆ’
function addScript ( pagename )
 
βˆ’
{
 
βˆ’
  var script  = document.createElement( 'script' );
 
βˆ’
  pagename    = encodeURI( pagename.replace( ' ', '_' ) );
 
βˆ’
  script.src  = '/w/index.php?title=' + pagename + '&action=raw&ctype=text/javascript';
 
βˆ’
  script.type = 'text/javascript';
 
βˆ’
 
 
βˆ’
  document.getElementsByTagName( 'head' )[0].appendChild( script );
 
βˆ’
}
 
βˆ’
 
 
βˆ’
/**** function diffwithFix.js
 
βˆ’
* by Patrick Westerhoff [poke]
 
βˆ’
*/
 
βˆ’
function diffwithFix ()
 
βˆ’
{
 
βˆ’
  var diffSpan = document.getElementById( 'diffwith' );
 
βˆ’
  if ( diffSpan == undefined )
 
βˆ’
    return;
 
βˆ’
 
 
βˆ’
  var diffLink  = diffSpan.getElementsByTagName( 'a' )[0];
 
βˆ’
  var diffTitle = diffSpan.title;
 
βˆ’
  var xmlHttp;
 
βˆ’
 
 
βˆ’
  try
 
βˆ’
  {
 
βˆ’
    xmlHttp = new XMLHttpRequest();
 
βˆ’
  }
 
βˆ’
  catch ( e )
 
βˆ’
  {
 
βˆ’
    try
 
βˆ’
    {
 
βˆ’
      xmlHttp = new ActiveXObject( 'Msxml2.XMLHTTP' );
 
βˆ’
    }
 
βˆ’
    catch ( e )
 
βˆ’
    {
 
βˆ’
      try
 
βˆ’
      {
 
βˆ’
        xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
 
βˆ’
      }
 
βˆ’
      catch ( e )
 
βˆ’
      {
 
βˆ’
        diffSpan.style.fontSize = '90%';
 
βˆ’
        diffSpan.innerHTML      = '(Automated diff <b>not available</b>.)';
 
βˆ’
        return;
 
βˆ’
      }
 
βˆ’
    }
 
βˆ’
  }
 
βˆ’
 
 
βˆ’
  xmlHttp.onreadystatechange = function ()
 
βˆ’
  {
 
βˆ’
    if ( xmlHttp.readyState != 4 )
 
βˆ’
      return;
 
βˆ’
   
 
βˆ’
    revs = xmlHttp.responseXML.getElementsByTagName( 'rev' );
 
βˆ’
   
 
βˆ’
    if ( revs.length > 0 )
 
βˆ’
    {
 
βˆ’
      diffLink.href += '&oldid=' + revs[0].getAttribute( 'revid' );
 
βˆ’
      diffSpan.title = '';
 
βˆ’
    } 
 
βˆ’
  }
 
βˆ’
  xmlHttp.open( 'GET', '/w/api.php?format=xml&action=query&prop=revisions&rvprop=ids&rvlimit=1&titles=' + diffTitle, true );
 
βˆ’
  xmlHttp.send( null );
 
βˆ’
}
 
βˆ’
/** </nowiki> **/
 

Latest revision as of 13:17, 22 October 2017

/* nothing anymore */