v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Difference between revisions of "MediaWiki:Common.js"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
 
(76 intermediate revisions by 6 users not shown)
Line 1: Line 1:
//<source lang="javascript">
+
/* Any JavaScript here will be loaded for all users on every page load. */
  
/* Import more specific scripts if necessary */
+
/** Import module *************************************************************
 +
  *
 +
  *  Description: Includes a raw wiki page as javascript or CSS,
 +
  *              used for including user made modules.
 +
  *  Maintainers: [[User:AzaToth]]
 +
  */
 +
importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
 +
function importScript( page ) {
 +
    if( importedScripts[page] ) {
 +
        return;
 +
    }
 +
    importedScripts[page] = true;
 +
    var url = mw.config.get('wgScriptPath')
 +
            + '/index.php?title='
 +
            + encodeURIComponent( page.replace( / /g, '_' ) )
 +
            + '&action=raw&ctype=text/javascript';
 +
    var scriptElem = document.createElement( 'script' );
 +
    scriptElem.setAttribute( 'src' , url );
 +
    scriptElem.setAttribute( 'type' , 'text/javascript' );
 +
    document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
 +
}
  
if (wgAction == "edit" || wgAction == "submit" || wgPageName == "Special:Upload") //scripts specific to editing pages
+
function importStylesheet( page ) {
{
+
    var sheet = '@import "'
    importScript("MediaWiki:Common.js/edit.js")
+
              + mw.config.get('wgScriptPath')
}
+
              + '/index.php?title='
else if (wgPageName == "Special:Watchlist") //watchlist scripts
+
              + encodeURIComponent( page.replace( / /g, '_' ) )
{
+
              + '&action=raw&ctype=text/css";';
    importScript("MediaWiki:Common.js/watchlist.js")
+
    var styleElem = document.createElement( 'style' );
}
+
    styleElem.setAttribute( 'type' , 'text/css' );
 +
    styleElem.appendChild( document.createTextNode( sheet ) );
 +
    document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
 +
}
  
 
+
/* Test if an element has a certain class **************************************
/** Sysop Javascript *******************************************************
 
 
   *
 
   *
   * Description: Allows for sysop-specific Javascript at [[MediaWiki:Sysop.js]].
+
   * Description: Uses regular expressions and caching for better performance.
 +
  * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 
   */
 
   */
function sysopFunctions() {
+
    if ( wgUserGroups && !window.disableSysopJS ) {
+
var hasClass = (function () {
        for ( var g = 0; g < wgUserGroups.length; ++g ) {
+
    var reCache = {};
            if ( wgUserGroups[g] == "sysop" ) {
+
    return function (element, className) {
                importScript( "MediaWiki:Sysop.js" );
+
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
                break;
+
    };
            }
+
})();
        }
 
    }
 
}
 
 
 
addOnloadHook( sysopFunctions );
 
 
 
  
/** WikiMiniAtlas *******************************************************
+
/** Collapsible tables *********************************************************
 
   *
 
   *
   *  Description: WikiMiniAtlas is a popup click and drag world map.
+
   *  Description: Allows tables to be collapsed, showing only the header. See
  *              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
+
   *              [[Wikipedia:NavFrame]].
   *              The script itself is located on meta because it is used by many projects.
+
   *  Maintainers: [[User:R. Koot]]
  *              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 ************************************************
 
*
 
*  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)) {
 
 
  var wgMainPageName = 'Main_Page';
 
 
   
 
   
  var stopMobileRedirectCookieExists = function() {
+
var autoCollapse = 2;
    return (document.cookie.indexOf("stopMobileRedirect=true") >= 0);
+
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 = {};
 +
    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.style.styleFloat = "right";
 +
            Button.style.cssFloat = "right";
 +
            Button.style.fontWeight = "normal";
 +
            Button.style.textAlign = "right";
 +
            Button.style.width = "6em";
 +
 +
            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( "]" ) );
 
   
 
   
  var mobileSiteLink = function() {
+
            Header.insertBefore( Button, Header.childNodes[0] );
    if (wgCanonicalNamespace == 'Special' && wgCanonicalSpecialPageName == 'Search') {
+
            tableIndex++;
        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()) {
+
    for ( var i = 0;  i < tableIndex; i++ ) {
     document.location = mobileSiteLink();
+
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
  }
+
            collapseTable( i );
}
+
        }
 +
    }
 +
     // Add text selection to gamedata infoboxes
 +
$('.infobox.gamedata').each(function(i,e){
 +
var ospan=$(e).find('th span:nth(0)'),
 +
span=$('<span>').insertAfter(ospan).attr('style',ospan.attr('style'));
 +
ospan.css({width:'auto',paddingLeft:5});
 +
$('<a>').attr('href','#').click(function(v){
 +
v.preventDefault();
 +
SelectText($(this).parents('.infobox.gamedata').find('.gamedata-content')[0]);
 +
}).text('Select all').appendTo(span);
 +
span.append(']').prepend('[');
 +
});
  
 +
}
  
/* Scripts specific to Internet Explorer */
+
$(createCollapseButtons);
  
if (navigator.appName == "Microsoft Internet Explorer")
+
/*******************
{
+
********************
    /** Internet Explorer bug fix **************************************************
+
DF Wiki-specific scripts
    *
+
********************
    * 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
+
/************* Sidebar stuff *************/
    appendCSS( '@media print { sup, sub, p, .documentDescription { line-height: normal; }}');
 
  
    // IE overflow bug
+
function addSidebarLink(title, page, sidebar, position){
    appendCSS('div.overflowbugx { overflow-x: scroll !important; overflow-y: hidden !important; } div.overflowbugy { overflow-y: scroll !important; overflow-x: hidden !important; }');
+
$('<li>').append(
   
+
$('<a>').attr('href', encodeURIComponent(page)).text(title)
    //Import scripts specific to Internet Explorer 6
+
).insertBefore('#mw-panel ul:nth('+sidebar+') li:nth('+position+')');
    if (navigator.appVersion.substr(22, 1) == "6") {
 
        importScript("MediaWiki:Common.js/IE60Fixes.js")
 
    }
 
 
}
 
}
  
 
+
// ***** Masterwork sidebar links
/* Test if an element has a certain class **************************************
+
if(mw.config.get('wgCanonicalNamespace').toLowerCase().indexOf('masterwork')==0){
*
+
  addSidebarLink('Main Page (MDF)', 'Masterwork:Main Page', 0, 1);
* Description: Uses regular expressions and caching for better performance.
+
  addSidebarLink('Community portal (MDF)', 'Masterwork:Community portal', 0, 4);
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
+
  addSidebarLink('Random page (MDF)', 'Special:Random/Masterwork' , 0, 8);
*/
 
 
 
var hasClass = (function () {
 
    var reCache = {};
 
    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 );
+
// ***** Older version links
 
+
var vns = mw.config.get('wgCanonicalNamespace').replace(/_talk/ig, '');
 
+
if(['23a', '40d', 'v0.31', 'v0.34'].indexOf(vns)>=0) addSidebarLink(vns + ' Main Page', vns+':Main_Page', 0,1);
/** Collapsible tables *********************************************************
 
*
 
*  Description: Allows tables to be collapsed, showing only the header. See
 
*              [[Wikipedia:NavFrame]].
 
*  Maintainers: [[User:R. Koot]]
 
*/
 
  
var autoCollapse = 2;
+
// ***** Color [tags] in sidebar
var collapseCaption = "hide";
+
$('#mw-panel li a').map(function(i,e){
var expandCaption = "show";
+
e=$(e);
 +
e.html(e.html().replace(/\[([^\]]+)\]/g, function(m,a){
 +
return '<span style="color:white;background-color:red;font-size:80%;padding:1px">'+a.toUpperCase()+'</span>';
 +
}));
 +
});
  
function collapseTable( tableIndex )
+
/*********** Misc **********/
{
 
    var Button = document.getElementById( "collapseButton" + tableIndex );
 
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
 
  
    if ( !Table || !Button ) {
+
// ***** Text selection
        return false;
+
function SelectText(element) {
    }
+
var range, selection;  
 
+
if (document.body.createTextRange) {
    var Rows = Table.rows;
+
range = document.body.createTextRange();  
 
+
range.moveToElementText(element);  
    if ( Button.firstChild.data == collapseCaption ) {
+
range.select();
        for ( var i = 1; i < Rows.length; i++ ) {
+
}  
            Rows[i].style.display = "none";
+
else if (window.getSelection) {
        }
+
selection = window.getSelection();  
        Button.firstChild.data = expandCaption;
+
range = document.createRange();
    } else {
+
range.selectNodeContents(element);  
        for ( var i = 1; i < Rows.length; i++ ) {
+
selection.removeAllRanges();
            Rows[i].style.display = Rows[0].style.display;
+
selection.addRange(range);
        }
+
}
        Button.firstChild.data = collapseCaption;
 
    }
 
 
}
 
}
  
function createCollapseButtons()
+
// ***** CP437 palette
{
+
$.when($.ready, mw.loader.using('ext.wikiEditor')).then(function(){
    var tableIndex = 0;
+
  $('#wpTextbox1').wikiEditor('addToToolbar', {
    var NavigationBoxes = new Object();
+
    'section': 'characters',
    var Tables = document.getElementsByTagName( "table" );
+
     'pages': {
 
+
      'cp437': {
     for ( var i = 0; i < Tables.length; i++ ) {
+
         'layout': 'characters',
         if ( hasClass( Tables[i], "collapsible" ) ) {
+
        'label': 'CP437',
 
+
        'characters': ["\u263A", "\u263B", "\u2665", "\u2666", "\u2663", "\u2660", "\u2022", "\u25D8", "\u25CB", "\u25D9", "\u2642", "\u2640", "\u266A", "\u266B", "\u263C", "\u25BA", "\u25C4", "\u2195", "\u203C", "\u00B6", "\u00A7", "\u25AC", "\u21A8", "\u2191", "\u2193", "\u2192", "\u2190", "\u221F", "\u2194", "\u25B2", "\u25BC", "\u0020", "\u0021", "\u0022", "\u0023", "\u0024", "\u0025", "\u0026", "\u0027", "\u0028", "\u0029", "\u002A", "\u002B", "\u002C", "\u002D", "\u002E", "\u002F", "\u0030", "\u0031", "\u0032", "\u0033", "\u0034", "\u0035", "\u0036", "\u0037", "\u0038", "\u0039", "\u003A", "\u003B", "\u003C", "\u003D", "\u003E", "\u003F", "\u0040", "\u0041", "\u0042", "\u0043", "\u0044", "\u0045", "\u0046", "\u0047", "\u0048", "\u0049", "\u004A", "\u004B", "\u004C", "\u004D", "\u004E", "\u004F", "\u0050", "\u0051", "\u0052", "\u0053", "\u0054", "\u0055", "\u0056", "\u0057", "\u0058", "\u0059", "\u005A", "\u005B", "\u005C", "\u005D", "\u005E", "\u005F", "\u0060", "\u0061", "\u0062", "\u0063", "\u0064", "\u0065", "\u0066", "\u0067", "\u0068", "\u0069", "\u006A", "\u006B", "\u006C", "\u006D", "\u006E", "\u006F", "\u0070", "\u0071", "\u0072", "\u0073", "\u0074", "\u0075", "\u0076", "\u0077", "\u0078", "\u0079", "\u007A", "\u007B", "\u007C", "\u007D", "\u007E", "\u2302", "\u00C7", "\u00FC", "\u00E9", "\u00E2", "\u00E4", "\u00E0", "\u00E5", "\u00E7", "\u00EA", "\u00EB", "\u00E8", "\u00EF", "\u00EE", "\u00EC", "\u00C4", "\u00C5", "\u00C9", "\u00E6", "\u00C6", "\u00F4", "\u00F6", "\u00F2", "\u00FB", "\u00F9", "\u00FF", "\u00D6", "\u00DC", "\u00A2", "\u00A3", "\u00A5", "\u20A7", "\u0192", "\u00E1", "\u00ED", "\u00F3", "\u00FA", "\u00F1", "\u00D1", "\u00AA", "\u00BA", "\u00BF", "\u2310", "\u00AC", "\u00BD", "\u00BC", "\u00A1", "\u00AB", "\u00BB", "\u2591", "\u2592", "\u2593", "\u2502", "\u2524", "\u2561", "\u2562", "\u2556", "\u2555", "\u2563", "\u2551", "\u2557", "\u255D", "\u255C", "\u255B", "\u2510", "\u2514", "\u2534", "\u252C", "\u251C", "\u2500", "\u253C", "\u255E", "\u255F", "\u255A", "\u2554", "\u2569", "\u2566", "\u2560", "\u2550", "\u256C", "\u2567", "\u2568", "\u2564", "\u2565", "\u2559", "\u2558", "\u2552", "\u2553", "\u256B", "\u256A", "\u2518", "\u250C", "\u2588", "\u2584", "\u258C", "\u2590", "\u2580", "\u03B1", "\u00DF", "\u0393", "\u03C0", "\u03A3", "\u03C3", "\u00B5", "\u03C4", "\u03A6", "\u0398", "\u03A9", "\u03B4", "\u221E", "\u03C6", "\u03B5", "\u2229", "\u2261", "\u00B1", "\u2265", "\u2264", "\u2320", "\u2321", "\u00F7", "\u2248", "\u00B0", "\u2219", "\u00B7", "\u221A", "\u207F", "\u00B2", "\u25A0", "\u00A0"]
            /* 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", "javascript:collapseTable(" + tableIndex + ");" );
 
            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;
 
                }
 
            }
 
        }
 
    }
 
}
 
 
 
addOnloadHook( 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, 'NavPic' ) ) {
 
                NavChild.style.display = 'none';
 
            }
 
            if ( hasClass( NavChild, 'NavContent') ) {
 
                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, 'NavPic')) {
 
                NavChild.style.display = 'block';
 
            }
 
            if (hasClass(NavChild, 'NavContent')) {
 
                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 );
 
 
 
 
 
/** Main Page layout fixes *********************************************************
 
*
 
*  Description: Adds an additional link to the complete list of languages available.
 
*  Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
 
*/
 
 
 
if (wgPageName == 'Main_Page' || wgPageName == 'Talk:Main_Page')
 
    addOnloadHook(function () {
 
        addPortletLink('p-lang', 'http://meta.wikimedia.org/wiki/List_of_Wikipedias',
 
                'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias')
 
        var nstab = document.getElementById('ca-nstab-main')
 
        if (nstab && wgUserLanguage=='en') {
 
            while (nstab.firstChild) nstab = nstab.firstChild
 
            nstab.nodeValue = 'Main Page'
 
        }
 
    }
 
)
 
 
 
 
 
/** 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;
 
 
       }
 
       }
 
     }
 
     }
 
   });
 
   });
}
+
  $('.section-characters .index div:first').before($('.section-characters .index div[rel=cp437]'));
 
+
});
//</source>
 

Latest revision as of 03:54, 12 November 2022

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

/** Import module *************************************************************
  *
  *  Description: Includes a raw wiki page as javascript or CSS, 
  *               used for including user made modules.
  *  Maintainers: [[User:AzaToth]]
  */
 importedScripts = {}; // object keeping track of included scripts, so a script ain't included twice
 function importScript( page ) {
     if( importedScripts[page] ) {
         return;
     }
     importedScripts[page] = true;
     var url = mw.config.get('wgScriptPath')
             + '/index.php?title='
             + encodeURIComponent( page.replace( / /g, '_' ) )
             + '&action=raw&ctype=text/javascript';
     var scriptElem = document.createElement( 'script' );
     scriptElem.setAttribute( 'src' , url );
     scriptElem.setAttribute( 'type' , 'text/javascript' );
     document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
 }

 function importStylesheet( page ) {
     var sheet = '@import "'
               + mw.config.get('wgScriptPath')
               + '/index.php?title='
               + encodeURIComponent( page.replace( / /g, '_' ) )
               + '&action=raw&ctype=text/css";';
     var styleElem = document.createElement( 'style' );
     styleElem.setAttribute( 'type' , 'text/css' );
     styleElem.appendChild( document.createTextNode( sheet ) );
     document.getElementsByTagName( 'head' )[0].appendChild( styleElem );
 }

 /* 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);
     };
 })();

 /** 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";
 
 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 = {};
     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.style.styleFloat = "right";
             Button.style.cssFloat = "right";
             Button.style.fontWeight = "normal";
             Button.style.textAlign = "right";
             Button.style.width = "6em";
 
             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( "]" ) );
 
             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 );
         }
     }
    // Add text selection to gamedata infoboxes
	$('.infobox.gamedata').each(function(i,e){
		var ospan=$(e).find('th span:nth(0)'),
			span=$('<span>').insertAfter(ospan).attr('style',ospan.attr('style'));
		ospan.css({width:'auto',paddingLeft:5});
		$('<a>').attr('href','#').click(function(v){
			v.preventDefault();
			SelectText($(this).parents('.infobox.gamedata').find('.gamedata-content')[0]);
		}).text('Select all').appendTo(span);
		span.append(']').prepend('[');
	});

 }

$(createCollapseButtons);

/*******************
********************
DF Wiki-specific scripts
********************
********************/

/************* Sidebar stuff *************/

function addSidebarLink(title, page, sidebar, position){
	$('<li>').append(
		$('<a>').attr('href', encodeURIComponent(page)).text(title)
	).insertBefore('#mw-panel ul:nth('+sidebar+') li:nth('+position+')');
}

// ***** Masterwork sidebar links
if(mw.config.get('wgCanonicalNamespace').toLowerCase().indexOf('masterwork')==0){
  addSidebarLink('Main Page (MDF)', 'Masterwork:Main Page', 0, 1);
  addSidebarLink('Community portal (MDF)', 'Masterwork:Community portal', 0, 4);
  addSidebarLink('Random page (MDF)', 'Special:Random/Masterwork' , 0, 8);
}

// ***** Older version links
var vns = mw.config.get('wgCanonicalNamespace').replace(/_talk/ig, '');
if(['23a', '40d', 'v0.31', 'v0.34'].indexOf(vns)>=0) addSidebarLink(vns + ' Main Page', vns+':Main_Page', 0,1);

// ***** Color [tags] in sidebar
$('#mw-panel li a').map(function(i,e){
	e=$(e);
	e.html(e.html().replace(/\[([^\]]+)\]/g, function(m,a){
		return '<span style="color:white;background-color:red;font-size:80%;padding:1px">'+a.toUpperCase()+'</span>';
	}));
});

/*********** Misc **********/

// ***** Text selection
function SelectText(element) {
	var range, selection; 
	if (document.body.createTextRange) {
		range = document.body.createTextRange(); 
		range.moveToElementText(element); 
		range.select();
	} 
	else if (window.getSelection) {
		selection = window.getSelection(); 
		range = document.createRange(); 
		range.selectNodeContents(element); 
		selection.removeAllRanges(); 
		selection.addRange(range);
	}
}

// ***** CP437 palette
$.when($.ready, mw.loader.using('ext.wikiEditor')).then(function(){
  $('#wpTextbox1').wikiEditor('addToToolbar', {
    'section': 'characters',
    'pages': {
      'cp437': {
        'layout': 'characters',
        'label': 'CP437',
        'characters': ["\u263A", "\u263B", "\u2665", "\u2666", "\u2663", "\u2660", "\u2022", "\u25D8", "\u25CB", "\u25D9", "\u2642", "\u2640", "\u266A", "\u266B", "\u263C", "\u25BA", "\u25C4", "\u2195", "\u203C", "\u00B6", "\u00A7", "\u25AC", "\u21A8", "\u2191", "\u2193", "\u2192", "\u2190", "\u221F", "\u2194", "\u25B2", "\u25BC", "\u0020", "\u0021", "\u0022", "\u0023", "\u0024", "\u0025", "\u0026", "\u0027", "\u0028", "\u0029", "\u002A", "\u002B", "\u002C", "\u002D", "\u002E", "\u002F", "\u0030", "\u0031", "\u0032", "\u0033", "\u0034", "\u0035", "\u0036", "\u0037", "\u0038", "\u0039", "\u003A", "\u003B", "\u003C", "\u003D", "\u003E", "\u003F", "\u0040", "\u0041", "\u0042", "\u0043", "\u0044", "\u0045", "\u0046", "\u0047", "\u0048", "\u0049", "\u004A", "\u004B", "\u004C", "\u004D", "\u004E", "\u004F", "\u0050", "\u0051", "\u0052", "\u0053", "\u0054", "\u0055", "\u0056", "\u0057", "\u0058", "\u0059", "\u005A", "\u005B", "\u005C", "\u005D", "\u005E", "\u005F", "\u0060", "\u0061", "\u0062", "\u0063", "\u0064", "\u0065", "\u0066", "\u0067", "\u0068", "\u0069", "\u006A", "\u006B", "\u006C", "\u006D", "\u006E", "\u006F", "\u0070", "\u0071", "\u0072", "\u0073", "\u0074", "\u0075", "\u0076", "\u0077", "\u0078", "\u0079", "\u007A", "\u007B", "\u007C", "\u007D", "\u007E", "\u2302", "\u00C7", "\u00FC", "\u00E9", "\u00E2", "\u00E4", "\u00E0", "\u00E5", "\u00E7", "\u00EA", "\u00EB", "\u00E8", "\u00EF", "\u00EE", "\u00EC", "\u00C4", "\u00C5", "\u00C9", "\u00E6", "\u00C6", "\u00F4", "\u00F6", "\u00F2", "\u00FB", "\u00F9", "\u00FF", "\u00D6", "\u00DC", "\u00A2", "\u00A3", "\u00A5", "\u20A7", "\u0192", "\u00E1", "\u00ED", "\u00F3", "\u00FA", "\u00F1", "\u00D1", "\u00AA", "\u00BA", "\u00BF", "\u2310", "\u00AC", "\u00BD", "\u00BC", "\u00A1", "\u00AB", "\u00BB", "\u2591", "\u2592", "\u2593", "\u2502", "\u2524", "\u2561", "\u2562", "\u2556", "\u2555", "\u2563", "\u2551", "\u2557", "\u255D", "\u255C", "\u255B", "\u2510", "\u2514", "\u2534", "\u252C", "\u251C", "\u2500", "\u253C", "\u255E", "\u255F", "\u255A", "\u2554", "\u2569", "\u2566", "\u2560", "\u2550", "\u256C", "\u2567", "\u2568", "\u2564", "\u2565", "\u2559", "\u2558", "\u2552", "\u2553", "\u256B", "\u256A", "\u2518", "\u250C", "\u2588", "\u2584", "\u258C", "\u2590", "\u2580", "\u03B1", "\u00DF", "\u0393", "\u03C0", "\u03A3", "\u03C3", "\u00B5", "\u03C4", "\u03A6", "\u0398", "\u03A9", "\u03B4", "\u221E", "\u03C6", "\u03B5", "\u2229", "\u2261", "\u00B1", "\u2265", "\u2264", "\u2320", "\u2321", "\u00F7", "\u2248", "\u00B0", "\u2219", "\u00B7", "\u221A", "\u207F", "\u00B2", "\u25A0", "\u00A0"]
      }
    }
  });
  $('.section-characters .index div:first').before($('.section-characters .index div[rel=cp437]'));
});