60 lines
2.5 KiB
JavaScript
60 lines
2.5 KiB
JavaScript
|
|
|||
|
<!--
|
|||
|
var ETNGpager = function( srcName, dstName, cntPP, cntPS )
|
|||
|
{
|
|||
|
this.srcName = srcName;
|
|||
|
this.dstName = dstName;
|
|||
|
this.curP = 1;//Ĭ<>ϵ<EFBFBD>ǰҳΪ<D2B3><CEAA>һҳ
|
|||
|
this.cntPP = cntPP || 2;//Ĭ<><C4AC>ÿҳ<C3BF><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼
|
|||
|
this.cntPS = cntPS || 3;//Ĭ<><C4AC>ÿҳ<C3BF><D2B3>ʾ5<CABE><35><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
this.items = [];
|
|||
|
this.showPNP = true;/*<2A><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>*/
|
|||
|
this.showType = true;/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ*/
|
|||
|
this.result = {pagedata:[],pagebar:'',limit:[0,0],report:''};
|
|||
|
this.parse();/*<2A>ܼ<EFBFBD>¼<EFBFBD><C2BC>*/
|
|||
|
}
|
|||
|
ETNGpager.prototype.page = function (){
|
|||
|
this.cntP = Math.ceil(this.cntR/this.cntPP);/*<2A><>ҳ<EFBFBD><D2B3>*/
|
|||
|
this.cntS = Math.ceil(this.cntP/this.cntPS);/*<2A>ܶ<EFBFBD><DCB6><EFBFBD>*/
|
|||
|
this.curS = Math.ceil(this.curP/this.cntPS);/*<2A><>ǰ<EFBFBD><C7B0>*/
|
|||
|
this.preP = this.curP -1;/*<2A><>һҳ*/
|
|||
|
this.nextP = this.curP +1;/*<2A><>һҳ*/
|
|||
|
this.preS = this.curS -1;/*<2A><>һ<EFBFBD><D2BB>*/
|
|||
|
this.nextS = this.curS +1;/*<2A><>һ<EFBFBD><D2BB>*/
|
|||
|
this.startR = (this.curP -1)*this.cntPP + 1;/*<2A><>ʼ<EFBFBD><CABC>¼*/
|
|||
|
this.endR = (this.curP*this.cntPP >this.cntR)?this.cntR:this.curP*this.cntPP;/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼*/
|
|||
|
this.result['pagedata']=[];
|
|||
|
if(this.showType){
|
|||
|
this.perSide = Math.floor(this.cntPS/2);
|
|||
|
this.startP = (this.curP > this.perSide)?(this.curP - this.perSide):1;
|
|||
|
this.endP = (this.startP + this.cntPS)>this.cntP?this.cntP:(this.startP + this.cntPS);
|
|||
|
}else{
|
|||
|
this.startP = (this.curS-1)*this.cntPS+1;
|
|||
|
this.endP = (this.curS*this.cntPS>this.cntP)?this.cntP:(this.curS*this.cntPS);
|
|||
|
}
|
|||
|
for(var i = this.startP;i<=this.endP;i++){
|
|||
|
this.result['pagedata'].push((i==this.curP)?'<a href="#" class="curPage">'+i+'</a>':'<a href="#" onclick="page('+i+')">'+i+'</a>');
|
|||
|
}
|
|||
|
if(this.showPNP){
|
|||
|
if(this.curP>1)this.result['pagedata'].unshift('<a href="#" onclick="page('+(this.curP-1)+')"><3E><>һҳ</a>');
|
|||
|
if(this.curP<this.cntP)this.result['pagedata'].push('<a href="#" onclick="page('+(this.curP+1)+')"><3E><>һҳ</a>');
|
|||
|
}
|
|||
|
this.result['pagebar'] = this.result['pagedata'].join(' ');
|
|||
|
this.result['limit'] = [this.startR,this.endR];
|
|||
|
this.result['report'] ='<a class="allpage"><b>'+this.cntR+'</b></a> ' ;
|
|||
|
}
|
|||
|
ETNGpager.prototype.parse = function (){
|
|||
|
var obj = document.getElementById(this.srcName);
|
|||
|
for(var i = 0;i<obj.childNodes.length;i++){
|
|||
|
if(obj.childNodes[i].nodeType!=3)this.items[this.items.length]=obj.childNodes[i].innerHTML;
|
|||
|
}
|
|||
|
this.cntR = this.items.length;
|
|||
|
return this.items.length;
|
|||
|
}
|
|||
|
ETNGpager.prototype.create=function(){
|
|||
|
this.page();
|
|||
|
document.getElementById(this.dstName).innerHTML='<li>'+this.items.slice(this.startR-1,this.endR).join('</li><li>')+'</li>';
|
|||
|
document.getElementById(this.dstName).innerHTML+='<div class="pagelist">'+this.result['report']+this.result['pagebar']+'</div>';
|
|||
|
}
|
|||
|
//-->
|