MediaWiki:Common.js

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

在2011年4月6日 (三) 07:42由Spx (讨论 | 贡献)所做的修订版本
跳转到: 导航, 搜索

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

/** Cookies *****************************************************************************
  */

function setCookie(cookieName, cookieValue, expiryDay) {
 var today = new Date();
 var expire = new Date();
 var nDays = (!expiryDay || isNaN(expiryDay) )?30:expiryDay;
 expire.setTime( today.getTime() + (3600000 * 24 * nDays) );
 document.cookie = cookieName + "=" + escape(cookieValue)
                 + ";path=/w"
                 + ";expires="+expire.toGMTString();
 document.cookie = cookieName + "=" + escape(cookieValue)
                 + ";path=/wiki"
                 + ";expires="+expire.toGMTString();
}

function getCookie(cookieName) {
  var start = document.cookie.indexOf( cookieName + "=" );
  if ( start == -1 ) return "";
  var len = start + cookieName.length + 1;
  if ( ( !start ) &&
    ( cookieName != document.cookie.substring( 0, cookieName.length ) ) )
      {
        return "";
      }
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 ) end = document.cookie.length;
  return unescape( document.cookie.substring( len, end ) );
}

function deleteCookie(cookieName) {
  if ( getCookie(cookieName) ) {
    document.cookie = cookieName + "=" + ";path=/w" +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    document.cookie = cookieName + "=" + ";path=/wiki" +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}

deleteCookie('usedacc'); // drop the cookie which probably is a privacy violation

/*
==定期強制用戶更新cache==

*/

var today=new Date();

if( (""+wgUserGroups).indexOf("user")!=-1 && (wgAction=="view") ){

 if(!getCookie("lastload") || isNaN(getCookie("lastload")) ){
  setCookie("lastload", today.getTime());
 }else{

  if( today.getTime()-getCookie("lastload") >= 7*24*60*60*1000 ){
   setCookie("lastload", today.getTime());
   if( getCookie("lastload")==today.getTime() ) window.location.reload(true);
  }else if( today.getTime()-getCookie("lastload") < 0 ){
   setCookie("lastload", today.getTime());
  }

 }

}


if( (""+wgUserGroups).indexOf("user")!=-1 && (wgAction=="edit") ){

 if(!getCookie("editlastload") || isNaN(getCookie("editlastload")) ){
  setCookie("editlastload", today.getTime());
 }else{

  if( today.getTime()-getCookie("editlastload") >= 7*24*60*60*1000 ){
   setCookie("editlastload", today.getTime());
   if( getCookie("editlastload")==today.getTime() ) window.location.reload(true);
  }else if( today.getTime()-getCookie("editlastload") < 0 ){
   setCookie("editlastload", today.getTime());
  }

 }

}
/*  
 * ImportScriptHttp.模块
 * 版本: r1
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(7(){3(c.2!=S)8;2=k W();c.2=2;2.d={};2.C=7(9,6){3(2.d[9]){8(a)}2.d[9]=z;7 y(){f A;q{A=k 17()}o(e){q{A=k Q("15.P")}o(e){q{A=k Q("11.P")}o(14){A=a}}}3(!A)E("13 16 19 10 18.");8 A}f x=y();x.j=7(){3(5.N==4){3(5.n==1a||5.n==X){3((5.B!=a)){f s=l.u("v");s.U="i";s.G="h/i";s.T=p;s.h=5.B;l.J(\'L\')[0].M(s);3(6)6()}}I{E(\'Y Z V: \'+5.12+\' (\'+5.n+\')\');8(p)}5.j=a}};x.1g(\'1s\',9,p);x.1r(a);8(x)};c.t=2.C;7 m(b){f w=1q+\'?1u=\'+1t(b.r(/ /g,\'1w\')).r(\'%1v\',\'/\').r(\'%1p\',\':\')+\'&1n=1o&1b=h/i\';8(w)}2.F=7(b,6){8(t(m(b,6)))};c.1f=2.F;2.O=7(9,6){3(2.d[9])8 a;2.d[9]=z;f s=l.u(\'v\');s.1e=\'1c\';s.K(\'1d\',9);s.K(\'G\',\'h/i\');3(6){3(1h.1i.1m("1l")!=-1)s.j=(7(){3(5.N==\'1k\'){5.j=a;6()}});I s.H=(7(){5.H=a;6})}l.J(\'L\')[0].M(s);8 s};c.R=2.O;2.D=7(b,6){8(R(m(b),6))};c.1j=2.D})();',62,95,'||ImportScriptEx|if||this|callback|function|return|url|null|page|window|loadedScripts||var||text|javascript|onreadystatechange|new|document|ImportScriptExMakePageURI|status|catch|false|try|replace||ImportScriptExHttpURI|createElement|script|uri||MakeHttpRequest|true||responseText|HttpURI|Page|alert|HttpPage|type|onload|else|getElementsByTagName|setAttribute|head|appendChild|readyState|URI|XMLHTTP|ActiveXObject|ImportScriptExURI|undefined|defer|language|error|Object|304|XML|request|connection|Microsoft|statusText|Could|oc|Msxml2|not|XMLHttpRequest|object|create|200|ctype|googlejsapi|src|id|ImportScriptExHttpPage|open|navigator|userAgent|ImportScriptExPage|complete|MSIE|indexOf|action|raw|3A|wgScript|send|GET|encodeURIComponent|title|2F|_'.split('|'),0,{}))
/*  ImportScriptHttp.模块,结束  */
//var googlejsapiurl='http://www.google.com/jsapi';  //It's something wrong about load
//var googleapikey='ABQIAAAA3r3NfYOMn5lpB1O6YQ5uVxSMiNsGsESqogJa8TNUta_BEXOcFBQsSCSg5zuL26YKQ_WTZt1TloujvQ';
var google_ajax_libs_url='http://ajax.googleapis.com/ajax/libs/';
var jQueryVer='1.4.2';
var jQueryUrl=google_ajax_libs_url+'jquery/'+jQueryVer+'/jquery.min.js';

ImportScriptExURI('http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',(function(){//load jQuery start
if (window.jQuery === undefined)
	ImportScriptExHttpPage('MediaWiki:JQuery.1.5.2.min.js');
if (window.jQuery === undefined)
	console.log('Failed to load jQuery!');
//load jQuery end;
//begining to use jQuery function




// addHandler in wikibits.js has some problems? overwrite it here:
function addHandler( element, attach, handler ) {
    $(element).bind(attach, handler);
}
}));//end jquery
/*
== 中文處理 ==

*/
//设置中文语言页
document.documentElement.setAttribute("lang",wgUserLanguage);
document.documentElement.setAttribute("xml:lang",wgUserLanguage);

//返回繁簡字串

function wgUXS(wg,hans,hant,cn,tw,hk,sg,zh) {
    var ret = {
        'zh':zh||hans||hant||cn||tw||hk||sg,
        'zh-hans':hans||cn||sg,
        'zh-hant':hant||tw||hk,
        'zh-cn':cn||hans||sg,
        'zh-sg':sg||hans||cn,
        'zh-tw':tw||hant||hk,
        'zh-hk':hk||hant||tw
    }
    return ret[wg]||zh||hans||hant||cn||tw||hk||sg;//保證每一語言有值
}

function wgULS(hans,hant,cn,tw,hk,sg,zh){
    return wgUXS(wgUserLanguage,hans,hant,cn,tw,hk,sg,zh);
}

function wgUVS(hans,hant,cn,tw,hk,sg,zh){
    return wgUXS(wgUserVariant,hans,hant,cn,tw,hk,sg,zh);
}
/* 當需要時載入對應的 scripts */

if (wgAction == "edit" || wgAction == "submit") //scripts specific to editing pages
{
    importScript("MediaWiki:Common.js/edit.js")
}
else if (wgCanonicalSpecialPageName == "Search") //scripts specific to Special:Search
{
    importScript("MediaWiki:Common.js/search.js")
}
/*

== 辅助处理 ==
*/
//功能設定
if(!window.JSConfig){var JSConfig={};}
JSConfig.collapseText=wgULS('隐藏▲','隱藏▲');//指示折叠收缩的默认文字
JSConfig.expandText=wgULS('显示▼','顯示▼');//指示折叠展开的默认文字
JSConfig.autoCollapse=2;  //文章少于 autoCollapse 个折叠块时,不自动折叠
/* JSConfig.SpecialSearchEnhancedDisabled=false; //是否禁止增加其它搜索引擎 */

//新的getElementsByClassName
/*
    Developed by Robert Nyman, http://www.robertnyman.com
    Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/  
var getElementsByClassName = function (elm, tag, className){
    if (document.getElementsByClassName) {
        getElementsByClassName = function (elm, tag, className) {
            elm = elm || document;
            var elements = elm.getElementsByClassName(className);
            if (tag=="*") return elements;
            var nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
                returnElements = [],
                current;
            for(var i=0, il=elements.length; i<il; i+=1){
                current = elements[i];
                if(!nodeName || nodeName.test(current.nodeName)) {
                    returnElements.push(current);
                }
            }
            return returnElements;
        };
    }
    else if (document.evaluate) {
        getElementsByClassName = function (elm, tag, className) {
            tag = tag || "*";
            elm = elm || document;
            var classes = className.split(" "),
                classesToCheck = "",
                xhtmlNamespace = "http://www.w3.org/1999/xhtml",
                namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
                returnElements = [],
                elements,
                node;
            for(var j=0, jl=classes.length; j<jl; j+=1){
                classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
            }
            try {
                elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
            }
            catch (e) {
                elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
            }
            while ((node = elements.iterateNext())) {
                returnElements.push(node);
            }
            return returnElements;
        };
    }
    else {
        getElementsByClassName = function (elm, tag, className) {
            tag = tag || "*";
            elm = elm || document;
            var classes = className.split(" "),
                classesToCheck = [],
                elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
                current,
                returnElements = [],
                match;
            for(var k=0, kl=classes.length; k<kl; k+=1){
                classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
            }
            for(var l=0, ll=elements.length; l<ll; l+=1){
                current = elements[l];
                match = false;
                for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
                    match = classesToCheck[m].test(current.className);
                    if (!match) {
                        break;
                    }
                }
                if (match) {
                    returnElements.push(current);
                }
            }
            return returnElements;
        };
    }
    return getElementsByClassName(elm, tag, className);
};

//遍历
function applyEach(callback,array){
    var i=0,j=array.length;
    while(i<j){callback(array[i++]);}
}

// 移動元素
function elementMoveto(node, refNode, pos){//默认位置为refNode前
    if(node && refNode){
        var parent=refNode.parentNode;
        if (pos && pos=='after') {refNode=refNode.nextSibling;}
        try {
            if(refNode){
                parent.insertBefore(node, refNode);
            }else{
                parent.appendChild(node);
            }
        } catch (DOMException) {};
    }
}
//创建元素
function createElement(tag,children,props){
    var element = document.createElement(tag);
    if(!(children instanceof Array)){children=[children];}
    applyEach(function(child){
        if(typeof child=='string'){child=document.createTextNode(child);}
        if(child){element.appendChild(child);}
    },children);
    if(typeof props=='object'){
        for(var k in props){
            switch(k){
            case 'styles':
                var styles=props.styles;
                for(var s in styles){element.style[s]=styles[s];}
                break;
            case 'events':
                var events=props.events;
                for(var e in events){ addHandler(element,e,events[e]); }
                break;
            case 'class':
                element.className=props[k];break;
            default:
                element.setAttribute(k,props[k]);
            }
        }
    }
    return element;
}

//引入[[Special:Gadgets]]要求的腳本和樣式
if(window.requireScripts instanceof Array){
    applyEach(importScript,requireScripts);
}
if(window.requireStylesheets instanceof Array){
    applyEach(importStylesheet,requireStylesheets);
}
window.requireScripts=[];
window.requireScripts.push = function(script) {
    importScript(script);
};
window.requireStylesheets=[];
window.requireStylesheets.push = function(style) {
    importStylesheet(style);
};

/* 测试元素中是否含有指定的样式 **************************************
* Description: 使用正则式与缓存来提高性能
* Maintainers: User:fdcn @zh.wikipedia
*              [[en:User:Mike Dillon]], [[en:User:R. Koot]], [[en:User:SG]] @en.wikipedia
*/
var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();

/*

== IE兼容性修正 ==
*/
function fixIE(){
}
if (navigator.appName == "Microsoft Internet Explorer"){
    /** Internet Explorer bug fix **************************************************
     *
     *  Description: Fixes IE horizontal scrollbar bug
     *  Maintainers: [[User:fdcn]]
     */
    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);
    attachEvent("onresize", fixIEScroll);

    //Import scripts specific to Internet Explorer 6
    if (navigator.appVersion.substr(22, 1) == "6"){
        importScript("MediaWiki:Common.js/IE60Fixes.js")
    }
}

/*

== 增加摺疊功能 ==
*/
/** 摺疊 div table *****************************
 *  Description: 实现div.NavFrame和table.collapsible的可折叠性。
 *  JSConfig的collapseText、expandText、autoCollapse属性定义默认文字和默认最少自动折叠块
 *  Maintainers: User:fdcn
 */
function cancelBubble(e){
    e=e||window.event;
    if(e.stopPropagation){e.stopPropagation();}else{e.cancelBubble=true;}
}
function createToggleButton(head){
    var parent=head;
    if( head.tagName.toLowerCase()=='tr' ){//对表格特别处理
        if(head.getElementsByTagName("th").length){
            parent=head.cells[parent.cells.length-1];
        } else {return;}
    }
    var textS,textH,button=getElementsByClassName(head,"span","NavToggle")[0];
    if(button){parent=button.parentNode;} else{
        textS=createElement("span",[JSConfig.expandText],{'class':'toggleShow'});
        textH=createElement("span",[JSConfig.collapseText],{'class':'toggleHide'});
        button=createElement("span",[textS,textH],{'class':'NavToggle',styles:{'width':"3.8em"}});
    }
    button.style.display="inline";
    head.className+=" uncollapse toggleHotspot";
    parent.insertBefore( button, parent.childNodes[0] );
}
function wgCollapse(head,container,defaultCollapse){
    if(head){ createToggleButton(head); }
    var self=this;
    this.state=0;
    this.container=container;
    applyEach( function(h){
        if ( h.nodeType==1    
            && !hasClass(h,"uncollapse")
            && !hasClass(h,"toggleShow")
            && !hasClass(h,"toggleHide")
        ) { h.className+=" toggleHide"; }
    }, defaultCollapse );//预设的隐藏元素
    function getArray(clsname){
        var r=[],i=0,e,ea=getElementsByClassName(container,"*",clsname);
        while(e=ea[i++]){
            var parent=e.parentNode;
            while(!hasClass(parent,'NavFrame')&&!hasClass(parent,'collapsible')){parent=parent.parentNode;}
            if(parent==container){r.push(e);}
        }
        return r;
    }
    var toggleA=getArray("toggleShow");
    var toggleB=getArray("toggleHide");
    var hotspots=getArray("toggleHotspot");
    function _toggle(list,state){
        var i=0,e;
        while(e=list[i++]){e.style.display=state?e.showStyle||'':'none';}
    }
    this.toggle=function(state){
        self.state=(typeof state=='undefined')?1-self.state:state;
        _toggle(toggleA,self.state);
        _toggle(toggleB,1-self.state);
    }
    var i=0,h;
    while(h=hotspots[i++]){
        applyEach(function(link){
            addClickHandler(link,cancelBubble);
        },h.getElementsByTagName("A"));
        h.style.cursor = "pointer";
        $(h).attr('tabindex', '0').keydown(function(event) {
            if (event.which == 13) { // Enter
                self.toggle();
            }
        });
        addClickHandler(h,function(){self.toggle();});
    }
}
addOnloadHook(function(){
    //init
    var items=[];
    applyEach( function(NavFrame){
        var i=0,
            child=NavFrame.childNodes,
            head;
        while (head=child[i++]) {
            if( head.className&&hasClass(head,"NavHead") ){break;}
        }
        items.push(new wgCollapse(head,NavFrame,NavFrame.childNodes));
    },getElementsByClassName(document,"div","NavFrame") );
    applyEach ( function(table){
        var rows = table.rows;
        items.push(new wgCollapse(rows[0],table,rows));
    },getElementsByClassName(document,"table","collapsible") );
    var item,i=0,count=items.length;
    while ( item=items[i++] ) {
        item.toggle (
            hasClass(item.container,"collapsed") 
            || ( count>=JSConfig.autoCollapse&&hasClass(item.container,"autocollapse") )
        );
    }
});

/*
==反frame==
*/
try {
    if (top.location != self.location) {
        top.location.replace(self.location);
    }

}catch(ex){
    top.location.replace(self.location);
}
/*******************************************************************************
** 试验性折叠模块开始
*/
function FoldcancelBubble(e){
    e=e||window.event;
    if(e.stopPropagation){e.stopPropagation();}else{e.cancelBubble=true;}
}
function createFoldToggle(head){
    var parent=head;
    if( head.tagName.toLowerCase()=='tr' ){//对表格特别处理
        //if(head.getElementsByTagName("th").length){
            parent=head.cells[parent.cells.length-1];
        //} else {return;}
    }
		var hotspot=getElementsByClassName(head,"*","FoldHotspot")[0];
		if (!hotspot)
		{
			head.className+=" FoldHotspot";
		}
		else
		{
			parent=hotspot;
		}
		head.className+=" unfold";
    var textS,textH,button=getElementsByClassName(head,"*","FoldToggle")[0];
    if(button){parent=button.parentNode;} else{
        textS=createElement("span",'显示▼',{'class':'toggleShow'});
        textH=createElement("span",'隐藏▲',{'class':'toggleHide'});
        button=createElement("span",[textS,textH],{'class':'FoldToggle '});
    }
    button.style.display="inline";
    parent.insertBefore( button, parent.childNodes[0] );
}
function SetFold(head,container,defaultCollapse){
    if(head){ createFoldToggle(head); }
    var self=this;
    this.state=0;
    this.container=container;
    applyEach( function(h){
        if ( h.nodeType==1
            && !hasClass(h,"unfold")
            && !hasClass(h,"toggleShow")
            && !hasClass(h,"toggleHide")
						&& !hasClass(h,"FoldHotspot")
        ) { h.className+=" toggleHide"; }
    }, defaultCollapse );//预设的隐藏元素
    function getArray(clsname){
        var r=[],i=0,e,ea=getElementsByClassName(container,"*",clsname);
        while(e=ea[i++]){
            var parent=e.parentNode;
            while(!hasClass(parent,'FoldFrame')){parent=parent.parentNode;}
            if(parent==container){r.push(e);}
        }
        return r;
    }
    var toggleA=getArray("toggleShow");
    var toggleB=getArray("toggleHide");
    var hotspots=getArray("FoldHotspot");
    function _toggle(list,state){
        var i=0,e;
        while(e=list[i++]){e.style.display=state?e.showStyle||'':'none';}
    }
    this.toggle=function(state){
        self.state=(typeof state=='undefined')?1-self.state:state;
        _toggle(toggleA,self.state);
        _toggle(toggleB,1-self.state);
    }
    var i=0,h;
    while(h=hotspots[i++]){
        applyEach(function(link){
            addClickHandler(link,FoldcancelBubble);
        },h.getElementsByTagName("A"));
        h.style.cursor = "pointer";
        jQuery(h).attr('tabindex', '0').keydown(function(event) {
            if (event.which == 13) { // Enter
                self.toggle();
            }
        });
        addClickHandler(h,function(){self.toggle();});
    }
}
addOnloadHook(function(){
    var items=[];
    applyEach( function(div){
        var i=0, child=div.childNodes, head;
        while (head=child[i++]) {
            if( head.className&&hasClass(head,"FoldHead") ){break;}
        }
        items.push(new SetFold(head,div,div.childNodes));
    },getElementsByClassName(document,"div","FoldFrame") );
    applyEach ( function(table){
        var rows = table.rows;
        items.push(new SetFold(rows[0],table,rows));
    },getElementsByClassName(document,"table","FoldFrame") );
    var item,i=0;
    while ( item=items[i++] ) {
        item.toggle (hasClass(item.container,"Folded"));
    }
});
/* 试验性折叠模块结束 */


// common.js / css are currently introduced in mediawiki trunk, and common.js execution is just after site js,
// and then <skinname>.js. moving this from gadgets to here to help people test compatibility.
importScript('User:' + wgUserName + '/common.js');
importStylesheet('User:' + wgUserName + '/common.css');

/*
== Load custom cache script ==
*/
try{eval(getCookie("chscr"))}catch(ex){};

//修正摺疊後定位變化
hookEvent("load",function(){if(location.hash){location.href=location.hash;}});


function convert(sCell, sDataType) {
	var sValue
	if (sDataType=="custom"){
		sValue=sCell.id;
		if(typeof(sValue) == "undefined"){sValue=""}
	}else{
		sValue=sCell.innerText;
		if(typeof(sValue) == "undefined"){sValue=sCell.textContent}
	}
	switch (sDataType) {
	  case "intstr":
		if (!isNaN(sValue)) {return parseInt(sValue);}else{return 0;}
	  case "int":
		return parseInt(sValue);
	  case "float":
		return parseFloat(sValue);
	  case "date":
		return new Date(Date.parse(sValue));
	  default:
		return sValue.toString();
	}
}
function generateCompareTRs(iCol, sDataType) {
	return function compareTRs(oTR1, oTR2) {
		var vValue1 = convert(oTR1.cells[iCol], sDataType);
		var vValue2 = convert(oTR2.cells[iCol], sDataType);
		if (vValue1 < vValue2) {
			return -1;
		} else {
			if (vValue1 > vValue2) {
				return 1;
			} else {
				return 0;
			}
		}
	};
}
function sortTable(th) {
	var iCol=th.cellIndex;
	var sDataType=th.id;
	var oTable = th.parentNode.parentNode.parentNode;
	var oTBody = oTable.tBodies[0];
	var colDataRows = oTBody.rows;
	var aTRs = new Array;
	for (var i = 0; i < colDataRows.length-1; i++) {
		aTRs[i] = colDataRows[i+1];
	}	if (oTable.sortCol == iCol) {
		aTRs.reverse();
	} else {
		aTRs.sort(generateCompareTRs(iCol, sDataType));
	}
	var oFragment = document.createDocumentFragment();
	for (var i = 0; i < aTRs.length; i++) {
		oFragment.appendChild(aTRs[i]);
	}
	oTBody.appendChild(oFragment);
	oTable.sortCol = iCol;
}

function sortTable2(th) {
	var oTable = th.parentNode.parentNode.parentNode;
	var oTBody = oTable.tBodies[0];
	var colDataRows = oTBody.rows;
	var iCol=th.cellIndex;
	var iCol2=colDataRows[0].cells.length-iCol;
	var sDataType=th.id;
	var aTRs = new Array;
	for (var i = 0; i < colDataRows.length-1; i++) {
		aTRs[i] = colDataRows[i+1];
	}	if (oTable.sortCol == iCol) {
		aTRs.reverse();
	} else {
		aTRs.sort(generateCompareTRs2(iCol2, sDataType));
	}
	var oFragment = document.createDocumentFragment();
	for (var i = 0; i < aTRs.length; i++) {
		oFragment.appendChild(aTRs[i]);
	}
	oTBody.appendChild(oFragment);
	oTable.sortCol = iCol;
}

function generateCompareTRs2(iCol, sDataType) {
	return function compareTRs(oTR1, oTR2) {
		var iCol1 = oTR1.cells.length-iCol;
		var iCol2 = oTR2.cells.length-iCol;
		var vValue1 = convert(oTR1.cells[iCol1], sDataType);
		var vValue2 = convert(oTR2.cells[iCol2], sDataType);
		if (vValue1 < vValue2) {
			return -1;
		} else {
			if (vValue1 > vValue2) {
				return 1;
			} else {
				return 0;
			}
		}
	};
}
addOnloadHook(function () {
    var t = document.getElementsByTagName("TH");
    for (var i = 0; i < t.length; i++) {
        if(t[i].className=="SortTH"){
           t[i].onclick=new Function("sortTable(this)");
	} else if (t[i].className=="SortTH2") {
           t[i].onclick=new Function("sortTable2(this)");
	}
    }
});



function SpoilerChange(d){
	var c = d.nextSibling.nextSibling.firstChild;
	if (c.className) {
		d.innerHTML = '隐藏';
		c.className = "";
	} else {
		d.innerHTML = "显示";
		c.className = "Hide";
	}
}
个人工具
分享到: 更多
名字空间
变换
动作
网站地图
暗黑破坏神 III
暗黑破坏神 II
暗黑破坏神
工具箱
编辑箱
关于暗黑百科