Welcome to Square Enix Wiki! Be sure to check out our To-Do List to see what work we need done!

Difference between revisions of "MediaWiki:Common.js"

From Square Enix Wiki, the Fan-wiki for all things Square Enix
Jump to navigationJump to search
7,392 bytes removed ,  01:14, 15 March 2014
no edit summary
m (1 revision: test)
Line 15: Line 15:
     };
     };
})();
})();
/***********************************************************
*  Name: collapseTable
*  Description: Collapses a single table, showing only the header.
*  Maintainers: (Wikipedia) [[User:R. Koot]], (Dragon Quest Wiki) [[User:FlyingRagnar]]
*  Source: Wikipedia Common.js, imported 2/1/10
*  Additional Notes: This is the primary method used to collapse navigational templates.
*  This code has been updated to use the jQuery toggle() function.  Various effects were tested, but due
*  to the fact that multiple <tr>s are being toggled, they did not look good.  As a result, it does just a basic toggle
*  with no effects.
*/
mw.loader.load( 'jquery.effects.core' );
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 targt = "#collapsibleTable" + tableIndex + " tr";
    $( targt + ":first-child").addClass("master");   
    $( targt + ":not(.master)").toggle();
    if ( Button.firstChild.data == collapseCaption ) {
        Button.firstChild.data = expandCaption;
    } else {
        Button.firstChild.data = collapseCaption;
    }
}
/***********************************************************
*  Name: createTableCollapseButtons
*  Description: Runs at page load, finds each table with class collapsible and inserts the necessary
*  elements to make the table have collapsible functionality.  The actual collapsing is then handled
*  by the collapseTable function.
*  Maintainers: (Wikipedia) [[User:R. Koot]], (Dragon Quest Wiki) [[User:FlyingRagnar]]
*  Source: Wikipedia Common.js, imported 2/1/10
*  Additional Notes: This method sets up the collapsing functionality. Dragon Quest wiki does not currently use the 'innercollapse', 'outercollapse', or 'autocollapse' 
*  functionality. It is generally preferred to allow tables to size themselves rather than specify a fixed width.
*  Usage: Create a table and give it the class "collapsible".  Ensure that the table has a header row.  Add the class
*  "collapsed" if you wish the table to be collapsed on page load.
*/
function createTableCollapseButtons()
{
    var tableIndex = 0;
    var NavigationBoxes = new Object();
    var Tables = document.getElementsByTagName( "table" );
    for ( var i = 0; i < Tables.length; i++ ) {
        if ( hasClass( Tables[i], "collapsible" ) ) {
            // only add button and increment count if there is a header row to work with
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
            if (!HeaderRow) continue;
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
            if (!Header) continue;
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
            var Button    = document.createElement( "span" );
            var ButtonLink = document.createElement( "a" );
            var ButtonText = document.createTextNode( collapseCaption );
            Button.className = "collapseButton";  //Styles are declared in Common.css
            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
            ButtonLink.appendChild( ButtonText );
            // fix width of table to be the same when shown or hidden (IE only)
            // Tables[i].style.width = Tables[i].offsetWidth;
            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( createTableCollapseButtons );


/***********************************************************
/***********************************************************
Line 306: Line 201:


     addPortletLink("p-tb", url, "Page logs", "pt-logs");
     addPortletLink("p-tb", url, "Page logs", "pt-logs");
});
//
// --------------------------------------------------------
// user rights
// adds a link in the tool box while on user pages to a user's rights management page.
// --------------------------------------------------------
addOnloadHook(function () {
    if (!rights_isAdmin)
        return; //Restrict this feature to admins.
    if (wgNamespaceNumber != "2" && wgNamespaceNumber != "3")
        return;  // restrict to User and User talk
    var title = wgTitle;
    addPortletLink('p-tb', '/wiki/index.php?title=Special:Userrights/'+title,
                  'User rights', 't-userrights', 'User rights for "'+title+'"');
});
});
//
//
Line 410: Line 288:
}
}
addOnloadHook(patroltab);
addOnloadHook(patroltab);
//
// --------------------------------------------------------
// Recent Changes Edit Colors
// Colors the page size changes on the recent changes
// --------------------------------------------------------
importStylesheetURI("http://zeldawiki.org/User:Matt/RC_Colors.css" + "&ctype=text/css&action=raw");
//
//


Line 470: Line 341:
   return node;
   return node;
}
}
/*</pre>
/*
/*
#########
### ProjectLinks
###  by [[user:Pathoschild]] (idea from an older, uncredited script)
###    * generates a sidebar list of links to other projects from {{projectlinks}}
#########
*/
function Projectlinks() {
        var elements = new Array();
        var spans = document.getElementsByTagName('span');
       
        // filter for projectlinks
        for (var i=0, j=0; i<spans.length; i++) {
                if (spans[i].className == 'interProject') {
                        elements[j] = spans[i].getElementsByTagName('a')[0];
                        j++;
                }
        }
        if (j == 0)
            return;
       
        // sort alphabetically
        function sortbylabel(a,b) {
                // get labels
                a = a.innerHTML.replace(/^.*<a[^>]*>(.*)<\/a>.*$/i,'$1');
                b = b.innerHTML.replace(/^.*<a[^>]*>(.*)<\/a>.*$/i,'$1');
                // return sort order
                if (a < b) return -1;
                if (a > b) return 1;
                return 0;
        }
        elements.sort(sortbylabel);
       
        // Create the list of project links
        var pllist = newNode('ul');
        for (var i=0; i<elements.length; i++) {
                pllist.appendChild(newNode('li', elements[i]));
        }
        var projectBox = newNode('div', {'class': 'portlet portal', id: 'p-projects'},
            newNode('h5', 'On other wikis'),
            newNode('div', {'class': 'pBody body'}, pllist)
        );
        var insert = document.getElementById('p-tb');
        if (!insert)
            return;
        if (insert.nextSibling)
            insert.parentNode.insertBefore(projectBox, insert.nextSibling);
        else
            insert.parentNode.appendChild(projectBox);
}
addOnloadHook(Projectlinks);


/************/
/************/
48

edits

Navigation menu