MediaWiki:Common.js

出自【暗黑百科】DiabloWiki_凯恩之角

在2011年5月27日 (五) 13:03由Spx (讨论 | 贡献)所做的修订版本
跳转到: 导航, 搜索

注意:在保存以后,您必须清除浏览器的缓存才能看到所作出的改变。 Mozilla / Firefox / Safari:按住Shift再点击刷新,或按下Ctrl-F5Ctrl-R(在Macintosh上按下Command-R); Konqueror:只需点击刷新或按下F5Opera:在工具→首选项中完整清除它们的缓存,或按下Alt-F5Internet Explorer:按住Ctrl再点击刷新,或按下Ctrl-F5

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 = "隐藏▲";
var expandCaption = "显示▼";

 
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].oldDisplayValue = Rows[i].style.display;
            Rows[i].style.display = "none";

        }
        Button.firstChild.data = expandCaption;
    } else {

        for ( var i = 1; i < Rows.length; i++ ) {

            Rows[i].style.display = Rows[i].oldDisplayValue;

        }
        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++ ) {
        var parent = Tables[i].parentNode.parentNode.parentNode.parentNode;
        if ( hasClass( Tables[i], "collapsible" ) || (hasClass(parent, "navbox") && hasClass(Tables[i], "navbox")) ) {

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

            }
        }
    }
}
个人工具
分享到: 更多
名字空间
变换
动作
网站地图
暗黑破坏神 III
暗黑破坏神 II
暗黑破坏神
工具箱
编辑箱
关于暗黑百科