Difference between revisions of "MediaWiki:Common.js"

From Detective Conan Wiki
m (Not needed here)
m (Compatibility update following latest wiki platform upgrade.)
Line 1: Line 1:
//<source lang="javascript">
+
/**
 +
* Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
 +
* loaded for all users on every wiki page. If possible create a gadget that is
 +
* enabled by default instead of adding it here (since gadgets are fully
 +
* optimized ResourceLoader modules with possibility to add dependencies etc.)
 +
*
 +
* Since Common.js isn't a gadget, there is no place to declare its
 +
* dependencies, so we have to lazy load them with mw.loader.using on demand and
 +
* then execute the rest in the callback. In most cases these dependencies will
 +
* be loaded (or loading) already and the callback will not be delayed. In case a
 +
* dependency hasn't arrived yet it'll make sure those are loaded before this.
 +
*/
 +
mw.loader.using( ['mediawiki.util', 'mediawiki.notify', 'jquery.client'], function () {
 +
/* Begin of mw.loader.using callback */
  
/* Import more specific scripts if necessary */
+
/**
 +
* @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 +
* @rev 5
 +
*/
 +
// CSS
 +
var extraCSS = mw.util.getParamValue( 'withCSS' );
 +
if ( extraCSS ) {
 +
if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
 +
importStylesheet( extraCSS );
 +
} else {
 +
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
 +
}
 +
}
  
if (wgAction == "edit" || wgAction == "submit" || wgPageName == "Special:Upload") //scripts specific to editing pages
+
// JS
{
+
var extraJS = mw.util.getParamValue( 'withJS' );
    importScript("MediaWiki:Common.js/edit.js")
+
if ( extraJS ) {
}
+
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
else if (wgPageName == "Special:Watchlist") //watchlist scripts
+
importScript( extraJS );
{
+
} else {
    importScript("MediaWiki:Common.js/watchlist.js")
+
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
 +
}
 
}
 
}
  
 
+
/**
/** Sysop Javascript *******************************************************
+
* Import more specific scripts if necessary
  *
+
  */
  * Description: Allows for sysop-specific Javascript at [[MediaWiki:Sysop.js]].
+
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
  */
+
    /* scripts specific to editing pages */
function sysopFunctions() {
+
    importScript( 'MediaWiki:Common.js/edit.js' );
    if ( wgUserGroups && !window.disableSysopJS ) {
+
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
        for ( var g = 0; g < wgUserGroups.length; ++g ) {
+
    /* watchlist scripts */
            if ( wgUserGroups[g] == "sysop" ) {
+
    importScript( 'MediaWiki:Common.js/watchlist.js' );
                importScript( "MediaWiki:Sysop.js" );
 
                break;
 
            }
 
        }
 
    }
 
 
}
 
}
 
+
if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
addOnloadHook( sysopFunctions );
+
     /* file description page scripts */
 
+
     importScript( 'MediaWiki:Common.js/file.js' );
 
 
/** WikiMiniAtlas *******************************************************
 
  *
 
  *  Description: WikiMiniAtlas is a popup click and drag world map.
 
  *              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
 
  *              The script itself is located on meta because it is used by many projects.
 
  *              See [[Meta:WikiMiniAtlas]] for more information.
 
  *  Maintainers: [[User:Dschwen]]
 
  */
 
 
 
/*
 
if (wgServer == "https://secure.wikimedia.org") {
 
     var metaBase = "https://secure.wikimedia.org/wikipedia/meta";
 
} else {
 
     var metaBase = "http://meta.wikimedia.org";
 
 
}
 
}
importScriptURI(metaBase+"/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400")
 
*/
 
  
 
+
/**
/** Mobile Redirect Helper ************************************************
+
  * Load scripts specific to Internet Explorer
  *
 
*  Redirects to the mobile-optimized gateway at en.m.wikimedia.org
 
*  for viewers on iPhone, iPod Touch, Palm Pre, and Android devices.
 
*
 
*  You can turn off the redirect by setting the cookie "stopMobileRedirect=true"
 
*
 
*  This code cannot be imported, because the JS only loads after all other files
 
*  and this was causing major issues for users with mobile devices. Must be loaded
 
*  *before* the images and etc of the page on all mobile devices.
 
*
 
*  Maintainer: [[User:Brion VIBBER]], [[User:hcatlin]]
 
 
  */
 
  */
/*if (/(Android|iPhone|iPod|webOS)/.test(navigator.userAgent)) {
+
if ( $.client.profile().name === 'msie' ) {
 
+
     importScript( 'MediaWiki:Common.js/IEFixes.js' );
  var wgMainPageName = 'Main_Page';
 
 
  var stopMobileRedirectCookieExists = function() {
 
    return (document.cookie.indexOf("stopMobileRedirect=true") >= 0);
 
  }
 
 
  var mobileSiteLink = function() {
 
    if (wgCanonicalNamespace == 'Special' && wgCanonicalSpecialPageName == 'Search') {
 
        var pageLink = '?search=' + encodeURIComponent(document.getElementById('searchText').value);
 
     } else if (wgPageName == wgMainPageName) {
 
        var pageLink = '::Home'; // Special case
 
    } else {
 
        var pageLink = encodeURIComponent(wgPageName).replace('%2F','/').replace('%3A',':');
 
    }
 
    return 'http://' + wgContentLanguage + '.m.wikipedia.org/wiki/' + pageLink + "?wasRedirected=true"
 
  }
 
 
  if (!stopMobileRedirectCookieExists()) {
 
    document.location = mobileSiteLink();
 
  }
 
}*/
 
 
 
 
 
/* Scripts specific to Internet Explorer */
 
 
 
if (navigator.appName == "Microsoft Internet Explorer")
 
{
 
    /** Internet Explorer bug fix **************************************************
 
    *
 
    *  Description: Fixes IE horizontal scrollbar bug
 
    *  Maintainers: [[User:Tom-]]?
 
    */
 
   
 
    var oldWidth;
 
    var docEl = document.documentElement;
 
   
 
    function fixIEScroll()
 
    {
 
        if (!oldWidth || docEl.clientWidth > oldWidth)
 
            doFixIEScroll();
 
        else
 
            setTimeout(doFixIEScroll, 1);
 
       
 
        oldWidth = docEl.clientWidth;
 
    }
 
   
 
    function doFixIEScroll() {
 
        docEl.style.overflowX = (docEl.scrollWidth - docEl.clientWidth < 4) ? "hidden" : "";
 
    }
 
   
 
    document.attachEvent("onreadystatechange", fixIEScroll);
 
    document.attachEvent("onresize", fixIEScroll);
 
   
 
   
 
    /**
 
    * Remove need for CSS hacks regarding MSIE and IPA.
 
    */
 
    if (document.createStyleSheet) {
 
        document.createStyleSheet().addRule('.IPA', 'font-family: "Doulos SIL", "Charis SIL", Gentium, "DejaVu Sans", Code2000, "TITUS Cyberbit Basic", "Arial Unicode MS", "Lucida Sans Unicode", "Chrysanthi Unicode";');
 
    }
 
 
 
    // In print IE (7?) does not like line-height
 
    appendCSS( '@media print { sup, sub, p, .documentDescription { line-height: normal; }}');
 
   
 
    //Import scripts specific to Internet Explorer 6
 
    if (navigator.appVersion.substr(22, 1) == "6") {
 
        importScript("MediaWiki:Common.js/IE60Fixes.js")
 
    }
 
 
}
 
}
  
 
+
/**
/* Test if an element has a certain class **************************************
+
  * Fix for Windows XP Unicode font rendering
  *
 
* Description: Uses regular expressions and caching for better performance.
 
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 
 
  */
 
  */
 
+
if ( navigator.appVersion.search(/windows nt 5/i) !== -1 ) {
var hasClass = (function () {
+
     mw.util.addCSS( '.IPA { font-family: "Lucida Sans Unicode", "Arial Unicode MS"; } ' +
    var reCache = {};
+
                '.Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; } ' );
     return function (element, className) {
 
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
 
    };
 
})();
 
 
 
 
 
/** Interwiki links to featured articles ***************************************
 
*
 
*  Description: Highlights interwiki links to featured articles (or
 
*              equivalents) by changing the bullet before the interwiki link
 
*              into a star.
 
*  Maintainers: [[User:R. Koot]]
 
*/
 
 
 
function LinkFA()
 
{
 
    if ( document.getElementById( "p-lang" ) ) {
 
        var InterwikiLinks = document.getElementById( "p-lang" ).getElementsByTagName( "li" );
 
 
 
        for ( var i = 0; i < InterwikiLinks.length; i++ ) {
 
            if ( document.getElementById( InterwikiLinks[i].className + "-fa" ) ) {
 
                InterwikiLinks[i].className += " FA"
 
                InterwikiLinks[i].title = "This is a featured article in another language.";
 
            }
 
        }
 
    }
 
 
}
 
}
  
addOnloadHook( LinkFA );
+
/**
 
+
* Collapsible tables *********************************************************
 
 
/** Collapsible tables *********************************************************
 
 
  *
 
  *
  * Description: Allows tables to be collapsed, showing only the header. See
+
  * Description: Allows tables to be collapsed, showing only the header. See
  *               [[Wikipedia:NavFrame]].
+
  *             [[Wikipedia:NavFrame]].
  * Maintainers: [[User:R. Koot]]
+
  * Maintainers: [[User:R. Koot]]
 
  */
 
  */
  
 
var autoCollapse = 2;
 
var autoCollapse = 2;
var collapseCaption = "hide";
+
var collapseCaption = 'hide';
var expandCaption = "show";
+
var expandCaption = 'show';
  
function collapseTable( tableIndex )
+
window.collapseTable = function ( tableIndex ) {
{
+
     var Button = document.getElementById( 'collapseButton' + tableIndex );
     var Button = document.getElementById( "collapseButton" + tableIndex );
+
     var Table = document.getElementById( 'collapsibleTable' + tableIndex );
     var Table = document.getElementById( "collapsibleTable" + tableIndex );
 
  
 
     if ( !Table || !Button ) {
 
     if ( !Table || !Button ) {
Line 196: Line 89:
  
 
     var Rows = Table.rows;
 
     var Rows = Table.rows;
 +
    var i;
  
     if ( Button.firstChild.data == collapseCaption ) {
+
     if ( Button.firstChild.data === collapseCaption ) {
         for ( var i = 1; i < Rows.length; i++ ) {
+
         for ( i = 1; i < Rows.length; i++ ) {
             Rows[i].style.display = "none";
+
             Rows[i].style.display = 'none';
 
         }
 
         }
 
         Button.firstChild.data = expandCaption;
 
         Button.firstChild.data = expandCaption;
 
     } else {
 
     } else {
         for ( var i = 1; i < Rows.length; i++ ) {
+
         for ( i = 1; i < Rows.length; i++ ) {
 
             Rows[i].style.display = Rows[0].style.display;
 
             Rows[i].style.display = Rows[0].style.display;
 
         }
 
         }
 
         Button.firstChild.data = collapseCaption;
 
         Button.firstChild.data = collapseCaption;
 
     }
 
     }
}
+
};
  
function createCollapseButtons()
+
function createCollapseButtons() {
{
 
 
     var tableIndex = 0;
 
     var tableIndex = 0;
     var NavigationBoxes = new Object();
+
     var NavigationBoxes = {};
     var Tables = document.getElementsByTagName( "table" );
+
     var Tables = document.getElementsByTagName( 'table' );
 +
    var i;
 +
 
 +
    function handleButtonLink( index, e ) {
 +
        window.collapseTable( index );
 +
        e.preventDefault();
 +
    }
  
     for ( var i = 0; i < Tables.length; i++ ) {
+
     for ( i = 0; i < Tables.length; i++ ) {
         if ( hasClass( Tables[i], "collapsible" ) ) {
+
         if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
  
 
             /* only add button and increment count if there is a header row to work with */
 
             /* only add button and increment count if there is a header row to work with */
             var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
+
             var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
             if (!HeaderRow) continue;
+
             if ( !HeaderRow ) continue;
             var Header = HeaderRow.getElementsByTagName( "th" )[0];
+
             var Header = HeaderRow.getElementsByTagName( 'th' )[0];
             if (!Header) continue;
+
             if ( !Header ) continue;
  
 
             NavigationBoxes[ tableIndex ] = Tables[i];
 
             NavigationBoxes[ tableIndex ] = Tables[i];
             Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
+
             Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
  
             var Button    = document.createElement( "span" );
+
             var Button    = document.createElement( 'span' );
             var ButtonLink = document.createElement( "a" );
+
             var ButtonLink = document.createElement( 'a' );
 
             var ButtonText = document.createTextNode( collapseCaption );
 
             var ButtonText = document.createTextNode( collapseCaption );
  
             Button.className = "collapseButton";  //Styles are declared in Common.css
+
             Button.className = 'collapseButton';  /* Styles are declared in Common.css */
  
 
             ButtonLink.style.color = Header.style.color;
 
             ButtonLink.style.color = Header.style.color;
             ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
+
             ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
             ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
+
             ButtonLink.setAttribute( 'href', '#' );
 +
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
 
             ButtonLink.appendChild( ButtonText );
 
             ButtonLink.appendChild( ButtonText );
  
             Button.appendChild( document.createTextNode( "[" ) );
+
             Button.appendChild( document.createTextNode( '[' ) );
 
             Button.appendChild( ButtonLink );
 
             Button.appendChild( ButtonLink );
             Button.appendChild( document.createTextNode( "]" ) );
+
             Button.appendChild( document.createTextNode( ']' ) );
  
             //Modified by Maurice to allow for better flexibility
+
             Header.insertBefore( Button, Header.firstChild );
            //Header.insertBefore( Button, Header.childNodes[0] );
 
            Header.appendChild( Button );
 
 
             tableIndex++;
 
             tableIndex++;
 
         }
 
         }
 
     }
 
     }
  
     for ( var i = 0;  i < tableIndex; i++ ) {
+
     for ( i = 0;  i < tableIndex; i++ ) {
         if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
+
         if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
             collapseTable( i );
+
             window.collapseTable( i );
 
         }  
 
         }  
         else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
+
         else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
 
             var element = NavigationBoxes[i];
 
             var element = NavigationBoxes[i];
             while (element = element.parentNode) {
+
             while ((element = element.parentNode)) {
                 if ( hasClass( element, "outercollapse" ) ) {
+
                 if ( $( element ).hasClass( 'outercollapse' ) ) {
                     collapseTable ( i );
+
                     window.collapseTable ( i );
 
                     break;
 
                     break;
 
                 }
 
                 }
Line 266: Line 164:
 
}
 
}
  
addOnloadHook( createCollapseButtons );
+
$( createCollapseButtons );
 
 
  
/** Dynamic Navigation Bars (experimental) *************************************
+
/**
 +
* Dynamic Navigation Bars (experimental)
 
  *
 
  *
  * Description: See [[Wikipedia:NavFrame]].
+
  * Description: See [[Wikipedia:NavFrame]].
  * Maintainers: UNMAINTAINED
+
  * Maintainers: UNMAINTAINED
 
  */
 
  */
  
// set up the words in your language
+
/* set up the words in your language */
 
var NavigationBarHide = '[' + collapseCaption + ']';
 
var NavigationBarHide = '[' + collapseCaption + ']';
 
var NavigationBarShow = '[' + expandCaption + ']';
 
var NavigationBarShow = '[' + expandCaption + ']';
  
// shows and hides content and picture (if available) of navigation bars
+
/**
// Parameters:
+
* Shows and hides content and picture (if available) of navigation bars
//     indexNavigationBar: the index of navigation bar to be toggled
+
* Parameters:
function toggleNavigationBar(indexNavigationBar)
+
*     indexNavigationBar: the index of navigation bar to be toggled
{
+
**/
     var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
+
window.toggleNavigationBar = function ( indexNavigationBar ) {
     var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
+
     var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
 +
     var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
 +
    var NavChild;
  
     if (!NavFrame || !NavToggle) {
+
     if ( !NavFrame || !NavToggle ) {
 
         return false;
 
         return false;
 
     }
 
     }
  
     // if shown now
+
     /* if shown now */
     if (NavToggle.firstChild.data == NavigationBarHide) {
+
     if ( NavToggle.firstChild.data === NavigationBarHide ) {
         for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
+
         for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
             if ( hasClass( NavChild, 'NavPic' ) ) {
+
             if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'none';
 
            }
 
            if ( hasClass( NavChild, 'NavContent') ) {
 
 
                 NavChild.style.display = 'none';
 
                 NavChild.style.display = 'none';
 
             }
 
             }
Line 303: Line 200:
 
     NavToggle.firstChild.data = NavigationBarShow;
 
     NavToggle.firstChild.data = NavigationBarShow;
  
     // if hidden now
+
     /* if hidden now */
     } else if (NavToggle.firstChild.data == NavigationBarShow) {
+
     } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
         for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
+
         for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
             if (hasClass(NavChild, 'NavPic')) {
+
             if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
 
            }
 
            if (hasClass(NavChild, 'NavContent')) {
 
 
                 NavChild.style.display = 'block';
 
                 NavChild.style.display = 'block';
 
             }
 
             }
Line 315: Line 209:
 
         NavToggle.firstChild.data = NavigationBarHide;
 
         NavToggle.firstChild.data = NavigationBarHide;
 
     }
 
     }
}
+
};
  
// adds show/hide-button to navigation bars
+
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton()
+
function createNavigationBarToggleButton() {
{
 
 
     var indexNavigationBar = 0;
 
     var indexNavigationBar = 0;
     // iterate over all < div >-elements  
+
    var NavFrame;
     var divs = document.getElementsByTagName("div");
+
    var NavChild;
     for (var i = 0; NavFrame = divs[i]; i++) {
+
     /* iterate over all < div >-elements */
         // if found a navigation bar
+
     var divs = document.getElementsByTagName( 'div' );
         if (hasClass(NavFrame, "NavFrame")) {
+
     for ( var i = 0; (NavFrame = divs[i]); i++ ) {
 +
         /* if found a navigation bar */
 +
         if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
  
 
             indexNavigationBar++;
 
             indexNavigationBar++;
             var NavToggle = document.createElement("a");
+
             var NavToggle = document.createElement( 'a' );
 
             NavToggle.className = 'NavToggle';
 
             NavToggle.className = 'NavToggle';
             NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
+
             NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
             NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
+
             $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
  
             var isCollapsed = hasClass( NavFrame, "collapsed" );
+
             var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
             /*
+
             /**
 
             * Check if any children are already hidden.  This loop is here for backwards compatibility:
 
             * 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"
 
             * the old way of making NavFrames start out collapsed was to manually add style="display:none"
Line 341: Line 236:
 
             * "collapsed" to the NavFrame itself, just like with collapsible tables.
 
             * "collapsed" to the NavFrame itself, just like with collapsible tables.
 
             */
 
             */
             for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
+
             for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
                 if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
+
                 if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                     if ( NavChild.style.display == 'none' ) {
+
                     if ( NavChild.style.display === 'none' ) {
 
                         isCollapsed = true;
 
                         isCollapsed = true;
 
                     }
 
                     }
 
                 }
 
                 }
 
             }
 
             }
             if (isCollapsed) {
+
             if ( isCollapsed ) {
                 for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
+
                 for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
                     if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
+
                     if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
 
                         NavChild.style.display = 'none';
 
                         NavChild.style.display = 'none';
 
                     }
 
                     }
 
                 }
 
                 }
 
             }
 
             }
             var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
+
             var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
             NavToggle.appendChild(NavToggleText);
+
             NavToggle.appendChild( NavToggleText );
  
             // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
+
             /* 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++) {
+
             for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
                 if (hasClass(NavFrame.childNodes[j], "NavHead")) {
+
                 if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
                     NavFrame.childNodes[j].appendChild(NavToggle);
+
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
 +
                     NavFrame.childNodes[j].appendChild( NavToggle );
 
                 }
 
                 }
 
             }
 
             }
             NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
+
             NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
 
         }
 
         }
 
     }
 
     }
 
}
 
}
  
addOnloadHook( createNavigationBarToggleButton );
+
$( createNavigationBarToggleButton );
  
 
+
/*
/** Main Page layout fixes *********************************************************
+
$( function() {
*
+
    sups = document.getElementsByTagName("sup");
*  Description: Adds an additional link to the complete list of languages available.
+
    for (i=0; i<sups.length; i++) {
*  Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
+
        note_id = sups[i].childNodes[0].href;
*/
+
        if (note_id && (note_id.indexOf("#") != -1)) {
 
+
            note_id = document.getElementById(note_id.substr(note_id.ind exOf("#")+1));
if (wgPageName == 'Main_Page' || wgPageName == 'Talk:Main_Page')
+
            if (note_id) {
    addOnloadHook(function () {
+
                if (document.all)
        addPortletLink('p-lang', 'http://meta.wikimedia.org/wiki/List_of_Wikipedias',
+
                {
                'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias')
+
                    sups[i].title = note_id.innerText;
        var nstab = document.getElementById('ca-nstab-main')
+
                    sups[i].childNodes[0].title = note_id.innerText;
        if (nstab && wgUserLanguage=='en')
+
                }
            nstab.firstChild.firstChild.nodeValue = 'Main Page'
+
                else
    }
+
                {
)
+
                    sups[i].title = note_id.textContent;
 
+
                }
 
+
             }
/** Table sorting fixes ************************************************
 
  *
 
  *  Description: Disables code in table sorting routine to set classes on even/odd rows
 
  *  Maintainers: [[User:Random832]]
 
  */
 
 
 
ts_alternate_row_colors = false;
 
 
 
 
 
/***** uploadwizard_newusers ********
 
* Switches in a message for non-autoconfirmed users at [[Wikipedia:Upload]]
 
*
 
*  Maintainers: [[User:Krimpet]]
 
****/
 
function uploadwizard_newusers() {
 
  if (wgNamespaceNumber == 4 && wgTitle == "Upload" && wgAction == "view") {
 
    var oldDiv = document.getElementById("autoconfirmedusers"),
 
        newDiv = document.getElementById("newusers");
 
    if (oldDiv && newDiv) {
 
      if (typeof wgUserGroups == "object" && wgUserGroups) {
 
        for (i = 0; i < wgUserGroups.length; i++) {
 
          if (wgUserGroups[i] == "autoconfirmed") {
 
            oldDiv.style.display = "block";
 
            newDiv.style.display = "none";
 
             return;
 
          }
 
 
         }
 
         }
      }
 
      oldDiv.style.display = "none";
 
      newDiv.style.display = "block";
 
      return;
 
 
     }
 
     }
  }
+
});
}
+
*/
addOnloadHook(uploadwizard_newusers);
 
 
 
 
 
/** IPv6 AAAA connectivity testing **/
 
 
 
var __ipv6wwwtest_factor = 100;
 
var __ipv6wwwtest_done = 0;
 
if ((wgServer != "https://secure.wikimedia.org") && (Math.floor(Math.random()*__ipv6wwwtest_factor)==42)) {
 
    importScript("MediaWiki:Common.js/IPv6.js");
 
}
 
 
 
/** Magic editintros ****************************************************
 
*
 
*  Description: Adds editintros on disambiguation pages and BLP pages.
 
*  Maintainers: [[User:RockMFR]]
 
*/
 
 
 
function addEditIntro(name)
 
{
 
  var el = document.getElementById('ca-edit');
 
  if (!el)
 
    return;
 
  el = el.getElementsByTagName('a')[0];
 
  if (el)
 
    el.href += '&editintro=' + name;
 
}
 
 
 
 
 
if (wgNamespaceNumber == 0) {
 
  addOnloadHook(function(){
 
    if (document.getElementById('disambigbox'))
 
      addEditIntro('Template:Disambig_editintro');
 
  });
 
 
 
  addOnloadHook(function(){
 
    var cats = document.getElementById('mw-normal-catlinks');
 
    if (!cats)
 
      return;
 
    cats = cats.getElementsByTagName('a');
 
    for (var i = 0; i < cats.length; i++) {
 
      if (cats[i].title == 'Category:Living people' || cats[i].title == 'Category:Possibly living people') {
 
        addEditIntro('Template:BLP_editintro');
 
        break;
 
      }
 
    }
 
  });
 
}
 
 
 
var OnloadHook = {};
 
 
 
function addTabsToHook (jsId, width) {
 
OnloadHook[jsId] = {
 
                name: jsId,
 
                jsWidth: width,
 
check: function () {
 
if (typeof($) == "undefined") return true;
 
if (typeof($.ui) == "undefined") return true;
 
if (typeof($.fn["tabs"]) == "undefined") return true;
 
if (typeof($("#"+this.name).tabs) == "undefined") return true;
 
this.initTabLink();
 
return false;
 
},
 
initTabLink: function ()
 
{
 
var strTabLink = "";
 
for(var name in TabsIndex)
 
{
 
var jsId = name;
 
var strTitle = TabsIndex[name].title;
 
strTabLink += "<li><a href=\"#"+jsId+"\"><span>"+strTitle+"</span></a></li>";
 
}
 
var tabs = $("#" + this.name + "_ul");
 
tabs.html(strTabLink);
 
},
 
func: function ()
 
{
 
var jsId = this.name;
 
var jsWidth = this.jsWidth;
 
var cmd = this;
 
if (cmd.check()) {
 
cmd.hTimer = setTimeout("OnloadHook['"+jsId+"'].func()",500);
 
} else
 
{
 
clearTimeout(cmd.hTimer);
 
$(document).ready(function(){
 
with ($("#"+jsId))
 
{
 
css("display", "inline-block");
 
css("overflow", "hidden");
 
if (jsWidth > 0)
 
css("width", jsWidth + "px");
 
tabs();
 
}
 
});
 
}
 
}
 
};
 
}
 
 
 
window.runOnloadHook = function() {
 
    for(var name in OnloadHook)
 
        OnloadHook[name].func();
 
}
 
  
//</source>
+
/* End of mw.loader.using callback */
 +
} );
 +
/* DO NOT ADD CODE BELOW THIS LINE */

Revision as of 00:34, 29 January 2013

/**
 * Keep code in MediaWiki:Common.js to a minimum as it is unconditionally
 * loaded for all users on every wiki page. If possible create a gadget that is
 * enabled by default instead of adding it here (since gadgets are fully
 * optimized ResourceLoader modules with possibility to add dependencies etc.)
 *
 * Since Common.js isn't a gadget, there is no place to declare its
 * dependencies, so we have to lazy load them with mw.loader.using on demand and
 * then execute the rest in the callback. In most cases these dependencies will
 * be loaded (or loading) already and the callback will not be delayed. In case a
 * dependency hasn't arrived yet it'll make sure those are loaded before this.
 */
mw.loader.using( ['mediawiki.util', 'mediawiki.notify', 'jquery.client'], function () {
/* Begin of mw.loader.using callback */

/**
 * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @rev 5
 */
// CSS
var extraCSS = mw.util.getParamValue( 'withCSS' );
if ( extraCSS ) {
	if ( extraCSS.match( /^MediaWiki:[^&<>=%#]*\.css$/ ) ) {
		importStylesheet( extraCSS );
	} else {
		mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
	}
}

// JS
var extraJS = mw.util.getParamValue( 'withJS' );
if ( extraJS ) {
	if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
		importScript( extraJS );
	} else {
		mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
	}
}

/**
 * Import more specific scripts if necessary
 */
if ( mw.config.get( 'wgAction' ) === 'edit' || mw.config.get( 'wgAction' ) === 'submit' || mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Upload' ) {
    /* scripts specific to editing pages */
    importScript( 'MediaWiki:Common.js/edit.js' );
} else if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Watchlist' ) {
    /* watchlist scripts */
    importScript( 'MediaWiki:Common.js/watchlist.js' );
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 6 ) {
    /* file description page scripts */
    importScript( 'MediaWiki:Common.js/file.js' );
}

/**
 * Load scripts specific to Internet Explorer
 */
if ( $.client.profile().name === 'msie' ) {
    importScript( 'MediaWiki:Common.js/IEFixes.js' );
}

/**
 * Fix for Windows XP Unicode font rendering
 */
if ( navigator.appVersion.search(/windows nt 5/i) !== -1 ) {
    mw.util.addCSS( '.IPA { font-family: "Lucida Sans Unicode", "Arial Unicode MS"; } ' + 
                '.Unicode { font-family: "Arial Unicode MS", "Lucida Sans Unicode"; } ' );
}

/**
 * Collapsible tables *********************************************************
 *
 * Description: Allows tables to be collapsed, showing only the header. See
 *              [[Wikipedia:NavFrame]].
 * Maintainers: [[User:R. Koot]]
 */

var autoCollapse = 2;
var collapseCaption = 'hide';
var expandCaption = 'show';

window.collapseTable = function ( tableIndex ) {
    var Button = document.getElementById( 'collapseButton' + tableIndex );
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );

    if ( !Table || !Button ) {
        return false;
    }

    var Rows = Table.rows;
    var i;

    if ( Button.firstChild.data === collapseCaption ) {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = 'none';
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( 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 = {};
    var Tables = document.getElementsByTagName( 'table' );
    var i;

    function handleButtonLink( index, e ) {
        window.collapseTable( index );
        e.preventDefault();
    }

    for ( i = 0; i < Tables.length; i++ ) {
        if ( $( Tables[i] ).hasClass( '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', '#' );
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
            ButtonLink.appendChild( ButtonText );

            Button.appendChild( document.createTextNode( '[' ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( ']' ) );

            Header.insertBefore( Button, Header.firstChild );
            tableIndex++;
        }
    }

    for ( i = 0;  i < tableIndex; i++ ) {
        if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
            window.collapseTable( i );
        } 
        else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
            var element = NavigationBoxes[i];
            while ((element = element.parentNode)) {
                if ( $( element ).hasClass( 'outercollapse' ) ) {
                    window.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
 **/
window.toggleNavigationBar = function ( indexNavigationBar ) {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    var NavChild;

    if ( !NavFrame || !NavToggle ) {
        return false;
    }

    /* if shown now */
    if ( NavToggle.firstChild.data === NavigationBarHide ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;

    /* if hidden now */
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }
};

/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton() {
    var indexNavigationBar = 0;
    var NavFrame;
    var NavChild;
    /* iterate over all < div >-elements */
    var divs = document.getElementsByTagName( 'div' );
    for ( var i = 0; (NavFrame = divs[i]); i++ ) {
        /* if found a navigation bar */
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {

            indexNavigationBar++;
            var NavToggle = document.createElement( 'a' );
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );

            var isCollapsed = $( NavFrame ).hasClass( '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 ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
                if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                    if ( NavChild.style.display === 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if ( isCollapsed ) {
                for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
                    if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( '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 ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild( NavToggle );
                }
            }
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
        }
    }
}

$( createNavigationBarToggleButton );

/*
$( function() {
    sups = document.getElementsByTagName("sup");
    for (i=0; i<sups.length; i++) {
        note_id = sups[i].childNodes[0].href;
        if (note_id && (note_id.indexOf("#") != -1)) {
            note_id = document.getElementById(note_id.substr(note_id.ind exOf("#")+1));
            if (note_id) {
                if (document.all)
                {
                    sups[i].title = note_id.innerText;
                    sups[i].childNodes[0].title = note_id.innerText;
                }
                else
                {
                    sups[i].title = note_id.textContent;
                }
            }
        }
    }
});
*/

/* End of mw.loader.using callback */
} );
/* DO NOT ADD CODE BELOW THIS LINE */