AJAX Pager_v2.0
1
/*
2
* Version:2.0
3
* Copyright (C) 2008.12.2 skylark
4
* Mail:aohailin@gmail.com
5
* ClassName:PagerControl
6
* dataSource:xml childNode <PagerData CurrentPage="1" PageSize="10" PageCount="5"/>
7
* Eg: var Pager=new PagerControl();
8
Pager.Title="分页测试";
9
Pager.CallbackFun=NewsPager;
10
Pager.ContainerId="newsDemo";
11
Pager.PagerStyleStr="common";
12
Pager.LinkActiveStyle="margin:0 5px;font-size:12px;background:none;text-decoration:none;border:1px solid #a3b4da;padding:2px 5px;color:green;";
13
Pager.LinkNormalStyle="margin:0 5px;font-size:12px;background:none;text-decoration:underline;cursor:pointer;border:1px solid #a3b4da;padding:2px 5px;color:orange;";
14
Pager.PageStep=5;
15
Pager.DataSource=pds;
16
Pager.DataBind();
17
18
var Pager2=new PagerControl();
19
Pager2.Config({DataSource:pds,Title:"分页测试",CallbackFun:NewsPager,PagerStyleStr:"single",Container:"newsDemo",PageStep:5});
20
Pager2.DataBind();
21
*/
22
function PagerControl(){
23
this.Title=""; //标题
24
this.CallbackFun=""; //回调函数
25
this.CallbackPar=null; //回调函数参数
26
this.ContainerId=""; //容器Id
27
this.PageStep=9; //分页步长
28
this.PageCount=0; //页数
29
this.CurrentPage=1; //当前页
30
this.PageSize=0; //页长
31
this.PagerDemo=""; //pager容器
32
this.DataSource=""; //数据源
33
this.PagerStyleStr="common"; //分页样式
34
this.LinkActiveStyle="margin:0 5px;font-size:12px;background:none;text-decoration:none;";
35
this.LinkNormalStyle="margin:0 5px;font-size:12px;background:none;text-decoration:underline;cursor:pointer;";
36
this.BtnActiveStyle="margin:0 2px;border:0;background:none;text-decoration:none;";
37
this.BtnNormalStyle="margin:0 5px;font-size:12px;background:none;text-decoration:underline;color:gray;cursor:pointer;";
38
this.PagerDemoStyle="padding:0;text-align:center;font-size:12px";
39
this.PagerDemoNoDataTemp="\u6682\u65E0\u4FE1\u606F";
40
this.PagerDemoHeadTemp="{$Title} \u7B2C {$CurrentPage}/{$PageCount} \u9875 {$PageSize}\u6761/\u9875";
41
}
42
PagerControl.prototype.createLink=function(){var me=this;for(i=arguments[0];i<=arguments[1];i++){var a=document.createElement("a");a.innerHTML=i;if(i==this.CurrentPage){a.style.cssText=this.LinkActiveStyle;}else{a.style.cssText=this.LinkNormalStyle;a.onclick=function(e){e=window.event||e;var obj=e.srcElement||e.target;me.CallbackPar==null?me.CallbackFun(obj.innerHTML):me.CallbackFun({Page:obj.innerHTML,CallbackPar:me.CallbackPar});}}this.PagerDemo.appendChild(a);}};
43
PagerControl.prototype.createBtn=function(){var me=this;for(i=arguments[0];i<=arguments[1];i++){var btn=document.createElement("input");btn.setAttribute("type","button");btn.setAttribute("value",i);if(i==this.CurrentPage){btn.style.cssText=this.BtnActiveStyle;}else{btn.style.cssText=this.BtnNormalStyle;btn.onclick=function(e){e=window.event||e;var obj=e.srcElement||e.target;me.CallbackPar==null?me.CallbackFun(obj.innerHTML):me.CallbackFun({Page:obj.innerHTML,CallbackPar:me.CallbackPar});}}}};
44
PagerControl.prototype.commonPagerStyle=function(){
45
var me=this;
46
var fstBtn=document.createElement("a");
47
fstBtn.innerHTML="\u9996\u9875";
48
fstBtn.title="\u9996\u9875";
49
if(this.CurrentPage==1){fstBtn.style.cssText=this.LinkActiveStyle;}else{fstBtn.style.cssText=this.LinkNormalStyle;fstBtn.onclick=function(){if(me.CallbackPar==null){if(me.CurrentPage!=1)me.CallbackFun(1);}else{if(me.CurrentPage!=1)me.CallbackFun({Page:1,CallbackPar:me.CallbackPar});}};fstBtn.href="javascript:void(0);";}
50
this.PagerDemo.appendChild(fstBtn);
51
var preBtn=document.createElement("a");
52
preBtn.innerHTML="\u4E0A\u4E00\u9875";
53
preBtn.title="\u4E0A\u4E00\u9875";
54
if(this.CurrentPage==1){preBtn.style.cssText=this.LinkActiveStyle;}else{preBtn.style.cssText=this.LinkNormalStyle;preBtn.onclick=function(){if(me.CallbackPar==null){if(me.CurrentPage!=1)me.CurrentPage-1<=1?me.CallbackFun(1):me.CallbackFun(me.CurrentPage-1);}else{if(me.CurrentPage!=1)me.CurrentPage-1<=1?me.CallbackFun({Page:1,CallbackPar:me.CallbackPar}):me.CallbackFun({Page:me.CurrentPage-1,CallbackPar:me.CallbackPar});}};preBtn.href="javascript:void(0);";}
55
this.PagerDemo.appendChild(preBtn);
56
if(((this.CurrentPage-parseInt(this.PageStep/2))<=1&&this.PageCount<=this.PageStep)||((this.CurrentPage-parseInt(this.PageStep/2))>1&&this.PageCount<=this.PageStep)){this.createLink(1,this.PageCount);}
57
if((this.CurrentPage-parseInt(this.PageStep/2))<=1&&this.PageCount>this.PageStep){this.createLink(1,this.PageStep);}
58
if((this.CurrentPage-parseInt(this.PageStep/2))>1&&this.PageCount>this.PageStep&&(this.CurrentPage+parseInt(this.PageStep/2))<=this.PageCount){this.createLink(this.CurrentPage-parseInt(this.PageStep/2),this.CurrentPage+parseInt(this.PageStep/2));}
59
if((this.CurrentPage-parseInt(this.PageStep/2))>1&&this.PageCount>this.PageStep&&(this.CurrentPage+parseInt(this.PageStep/2))>this.PageCount){this.createLink(this.PageCount-this.PageStep+1,this.PageCount);}
60
var nxtBtn=document.createElement("a");
61
nxtBtn.innerHTML="\u4E0B\u4E00\u9875";
62
nxtBtn.title="\u4E0B\u4E00\u9875";
63
nxtBtn.style.margin="0 5px";
64
if(this.CurrentPage==this.PageCount){nxtBtn.style.cssText=this.LinkActiveStyle;}else{nxtBtn.style.cssText=this.LinkNormalStyle;nxtBtn.onclick=function(){if(me.CallbackPar==null){if(me.CurrentPage!=me.PageCount)me.CurrentPage+1>=me.PageCount?me.CallbackFun(me.PageCount):me.CallbackFun(me.CurrentPage+1);}else{if(me.CurrentPage!=me.PageCount)me.CurrentPage+1>=me.PageCount?me.CallbackFun({Page:me.PageCount,CallbackPar:me.CallbackPar}):me.CallbackFun({Page:me.CurrentPage+1,CallbackPar:me.CallbackPar});}};nxtBtn.href="javascript:void(0);";}
65
this.PagerDemo.appendChild(nxtBtn);
66
var latBtn=document.createElement("a");
67
latBtn.innerHTML="\u5C3E\u9875";
68
latBtn.title="\u5C3E\u9875";
69
latBtn.style.margin="0 5px";
70
if(this.CurrentPage==this.PageCount){latBtn.style.cssText=this.LinkActiveStyle;}else{latBtn.style.cssText=this.LinkNormalStyle;latBtn.onclick=function(){if(me.CallbackPar==null){if(me.CurrentPage!=me.PageCount)me.CallbackFun(me.PageCount);}else{if(me.CurrentPage!=me.PageCount)me.CallbackFun({Page:me.PageCount,CallbackPar:me.CallbackPar});}};latBtn.href="javascript:void(0);";}
71
this.PagerDemo.appendChild(latBtn);
72
73
this.singlePagerStyle();
74
};
75
PagerControl.prototype.singlePagerStyle=function(){
76
var me=this;
77
var font=document.createElement("font");
78
font.innerHTML=" \u8F6C\u81F3\uFF1A\u7B2C";
79
this.PagerDemo.appendChild(font);
80
var select=document.createElement("select");
81
with(select.style){margin="0 4px";}
82
select.onchange=function(e){e=window.event||e;var obj=e.srcElement||e.target;me.CallbackPar==null?me.CallbackFun(obj.options[obj.selectedIndex].value):me.CallbackFun({Page:obj.options[obj.selectedIndex].value,CallbackPar:me.CallbackPar});};
83
for(var i=1;i<=this.PageCount;i++){var option=document.createElement("option");option.setAttribute("value",i);option.innerHTML=" "+i+" ";if(i==this.CurrentPage){option.setAttribute("selected","selected");with(option.style){height="18px";margin="0";}}select.appendChild(option);}
84
this.PagerDemo.appendChild(select);
85
var font=document.createElement("font");
86
font.innerHTML="\u9875";
87
this.PagerDemo.appendChild(font);
88
};
89
PagerControl.prototype.Config=function(){
90
this.Title=arguments[0].Title;
91
this.CallbackFun=arguments[0].CallbackFun;
92
this.CallbackPar=arguments[0].CallbackPar||null;
93
this.ContainerId=arguments[0].Container;
94
this.PagerStyleStr=arguments[0].PagerStyleStr;
95
this.PageStep=arguments[0].PageStep||this.PageStep;
96
this.DataSource=arguments[0].DataSource;
97
};
98
PagerControl.prototype.Init=function(){
99
this.PagerDemo=document.createElement("p");
100
this.PagerDemo.style.cssText=this.PagerDemoStyle;
101
if(this.PageCount==0){this.PagerDemo.innerHTML=this.PagerDemoNoDataTemp;$(this.ContainerId).appendChild(this.PagerDemo);return false;}
102
this.PagerDemo.innerHTML=this.PagerDemoHeadTemp.replace("{$Title}",this.Title).replace("{$CurrentPage}",this.CurrentPage).replace("{$PageCount}",this.PageCount).replace("{$PageSize}",this.PageSize);
103
if(this.PagerStyleStr=="common"){this.commonPagerStyle()}else{this.singlePagerStyle();}
104
$(this.ContainerId).appendChild(this.PagerDemo);
105
};
106
PagerControl.prototype.DataBind=function(){
107
this.PageCount=parseInt(this.DataSource.getAttribute("PageCount"));
108
this.CurrentPage=parseInt(this.DataSource.getAttribute("CurrentPage"));
109
this.PageSize=parseInt(this.DataSource.getAttribute("PageSize"));
110
this.Init();
111
};
/*2
* Version:2.03
* Copyright (C) 2008.12.2 skylark4
* Mail:aohailin@gmail.com5
* ClassName:PagerControl6
* dataSource:xml childNode <PagerData CurrentPage="1" PageSize="10" PageCount="5"/>7
* Eg: var Pager=new PagerControl();8
Pager.Title="分页测试";9
Pager.CallbackFun=NewsPager;10
Pager.ContainerId="newsDemo";11
Pager.PagerStyleStr="common";12
Pager.LinkActiveStyle="margin:0 5px;font-size:12px;background:none;text-decoration:none;border:1px solid #a3b4da;padding:2px 5px;color:green;";13
Pager.LinkNormalStyle="margin:0 5px;font-size:12px;background:none;text-decoration:underline;cursor:pointer;border:1px solid #a3b4da;padding:2px 5px;color:orange;";14
Pager.PageStep=5;15
Pager.DataSource=pds;16
Pager.DataBind();17
18
var Pager2=new PagerControl();19
Pager2.Config({DataSource:pds,Title:"分页测试",CallbackFun:NewsPager,PagerStyleStr:"single",Container:"newsDemo",PageStep:5});20
Pager2.DataBind();21
*/22
function PagerControl(){23
this.Title=""; //标题24
this.CallbackFun=""; //回调函数25
this.CallbackPar=null; //回调函数参数26
this.ContainerId=""; //容器Id27
this.PageStep=9; //分页步长28
this.PageCount=0; //页数29
this.CurrentPage=1; //当前页30
this.PageSize=0; //页长31
this.PagerDemo=""; //pager容器32
this.DataSource=""; //数据源33
this.PagerStyleStr="common"; //分页样式34
this.LinkActiveStyle="margin:0 5px;font-size:12px;background:none;text-decoration:none;";35
this.LinkNormalStyle="margin:0 5px;font-size:12px;background:none;text-decoration:underline;cursor:pointer;";36
this.BtnActiveStyle="margin:0 2px;border:0;background:none;text-decoration:none;";37
this.BtnNormalStyle="margin:0 5px;font-size:12px;background:none;text-decoration:underline;color:gray;cursor:pointer;";38
this.PagerDemoStyle="padding:0;text-align:center;font-size:12px";39
this.PagerDemoNoDataTemp="\u6682\u65E0\u4FE1\u606F";40
this.PagerDemoHeadTemp="{$Title} \u7B2C {$CurrentPage}/{$PageCount} \u9875 {$PageSize}\u6761/\u9875";41
}42
PagerControl.prototype.createLink=function(){var me=this;for(i=arguments[0];i<=arguments[1];i++){var a=document.createElement("a");a.innerHTML=i;if(i==this.CurrentPage){a.style.cssText=this.LinkActiveStyle;}else{a.style.cssText=this.LinkNormalStyle;a.onclick=function(e){e=window.event||e;var obj=e.srcElement||e.target;me.CallbackPar==null?me.CallbackFun(obj.innerHTML):me.CallbackFun({Page:obj.innerHTML,CallbackPar:me.CallbackPar});}}this.PagerDemo.appendChild(a);}};43
PagerControl.prototype.createBtn=function(){var me=this;for(i=arguments[0];i<=arguments[1];i++){var btn=document.createElement("input");btn.setAttribute("type","button");btn.setAttribute("value",i);if(i==this.CurrentPage){btn.style.cssText=this.BtnActiveStyle;}else{btn.style.cssText=this.BtnNormalStyle;btn.onclick=function(e){e=window.event||e;var obj=e.srcElement||e.target;me.CallbackPar==null?me.CallbackFun(obj.innerHTML):me.CallbackFun({Page:obj.innerHTML,CallbackPar:me.CallbackPar});}}}};44
PagerControl.prototype.commonPagerStyle=function(){45
var me=this;46
var fstBtn=document.createElement("a");47
fstBtn.innerHTML="\u9996\u9875";48
fstBtn.title="\u9996\u9875";49
if(this.CurrentPage==1){fstBtn.style.cssText=this.LinkActiveStyle;}else{fstBtn.style.cssText=this.LinkNormalStyle;fstBtn.onclick=function(){if(me.CallbackPar==null){if(me.CurrentPage!=1)me.CallbackFun(1);}else{if(me.CurrentPage!=1)me.CallbackFun({Page:1,CallbackPar:me.CallbackPar});}};fstBtn.href="javascript:void(0);";}50
this.PagerDemo.appendChild(fstBtn);51
var preBtn=document.createElement("a");52
preBtn.innerHTML="\u4E0A\u4E00\u9875";53
preBtn.title="\u4E0A\u4E00\u9875";54
if(this.CurrentPage==1){preBtn.style.cssText=this.LinkActiveStyle;}else{preBtn.style.cssText=this.LinkNormalStyle;preBtn.onclick=function(){if(me.CallbackPar==null){if(me.CurrentPage!=1)me.CurrentPage-1<=1?me.CallbackFun(1):me.CallbackFun(me.CurrentPage-1);}else{if(me.CurrentPage!=1)me.CurrentPage-1<=1?me.CallbackFun({Page:1,CallbackPar:me.CallbackPar}):me.CallbackFun({Page:me.CurrentPage-1,CallbackPar:me.CallbackPar});}};preBtn.href="javascript:void(0);";}55
this.PagerDemo.appendChild(preBtn);56
if(((this.CurrentPage-parseInt(this.PageStep/2))<=1&&this.PageCount<=this.PageStep)||((this.CurrentPage-parseInt(this.PageStep/2))>1&&this.PageCount<=this.PageStep)){this.createLink(1,this.PageCount);}57
if((this.CurrentPage-parseInt(this.PageStep/2))<=1&&this.PageCount>this.PageStep){this.createLink(1,this.PageStep);}58
if((this.CurrentPage-parseInt(this.PageStep/2))>1&&this.PageCount>this.PageStep&&(this.CurrentPage+parseInt(this.PageStep/2))<=this.PageCount){this.createLink(this.CurrentPage-parseInt(this.PageStep/2),this.CurrentPage+parseInt(this.PageStep/2));}59
if((this.CurrentPage-parseInt(this.PageStep/2))>1&&this.PageCount>this.PageStep&&(this.CurrentPage+parseInt(this.PageStep/2))>this.PageCount){this.createLink(this.PageCount-this.PageStep+1,this.PageCount);}60
var nxtBtn=document.createElement("a");61
nxtBtn.innerHTML="\u4E0B\u4E00\u9875";62
nxtBtn.title="\u4E0B\u4E00\u9875";63
nxtBtn.style.margin="0 5px";64
if(this.CurrentPage==this.PageCount){nxtBtn.style.cssText=this.LinkActiveStyle;}else{nxtBtn.style.cssText=this.LinkNormalStyle;nxtBtn.onclick=function(){if(me.CallbackPar==null){if(me.CurrentPage!=me.PageCount)me.CurrentPage+1>=me.PageCount?me.CallbackFun(me.PageCount):me.CallbackFun(me.CurrentPage+1);}else{if(me.CurrentPage!=me.PageCount)me.CurrentPage+1>=me.PageCount?me.CallbackFun({Page:me.PageCount,CallbackPar:me.CallbackPar}):me.CallbackFun({Page:me.CurrentPage+1,CallbackPar:me.CallbackPar});}};nxtBtn.href="javascript:void(0);";}65
this.PagerDemo.appendChild(nxtBtn);66
var latBtn=document.createElement("a");67
latBtn.innerHTML="\u5C3E\u9875";68
latBtn.title="\u5C3E\u9875";69
latBtn.style.margin="0 5px";70
if(this.CurrentPage==this.PageCount){latBtn.style.cssText=this.LinkActiveStyle;}else{latBtn.style.cssText=this.LinkNormalStyle;latBtn.onclick=function(){if(me.CallbackPar==null){if(me.CurrentPage!=me.PageCount)me.CallbackFun(me.PageCount);}else{if(me.CurrentPage!=me.PageCount)me.CallbackFun({Page:me.PageCount,CallbackPar:me.CallbackPar});}};latBtn.href="javascript:void(0);";}71
this.PagerDemo.appendChild(latBtn);72
73
this.singlePagerStyle();74
};75
PagerControl.prototype.singlePagerStyle=function(){76
var me=this;77
var font=document.createElement("font");78
font.innerHTML=" \u8F6C\u81F3\uFF1A\u7B2C";79
this.PagerDemo.appendChild(font);80
var select=document.createElement("select");81
with(select.style){margin="0 4px";}82
select.onchange=function(e){e=window.event||e;var obj=e.srcElement||e.target;me.CallbackPar==null?me.CallbackFun(obj.options[obj.selectedIndex].value):me.CallbackFun({Page:obj.options[obj.selectedIndex].value,CallbackPar:me.CallbackPar});};83
for(var i=1;i<=this.PageCount;i++){var option=document.createElement("option");option.setAttribute("value",i);option.innerHTML=" "+i+" ";if(i==this.CurrentPage){option.setAttribute("selected","selected");with(option.style){height="18px";margin="0";}}select.appendChild(option);}84
this.PagerDemo.appendChild(select);85
var font=document.createElement("font");86
font.innerHTML="\u9875";87
this.PagerDemo.appendChild(font);88
};89
PagerControl.prototype.Config=function(){90
this.Title=arguments[0].Title;91
this.CallbackFun=arguments[0].CallbackFun;92
this.CallbackPar=arguments[0].CallbackPar||null;93
this.ContainerId=arguments[0].Container;94
this.PagerStyleStr=arguments[0].PagerStyleStr;95
this.PageStep=arguments[0].PageStep||this.PageStep;96
this.DataSource=arguments[0].DataSource;97
};98
PagerControl.prototype.Init=function(){99
this.PagerDemo=document.createElement("p");100
this.PagerDemo.style.cssText=this.PagerDemoStyle;101
if(this.PageCount==0){this.PagerDemo.innerHTML=this.PagerDemoNoDataTemp;$(this.ContainerId).appendChild(this.PagerDemo);return false;}102
this.PagerDemo.innerHTML=this.PagerDemoHeadTemp.replace("{$Title}",this.Title).replace("{$CurrentPage}",this.CurrentPage).replace("{$PageCount}",this.PageCount).replace("{$PageSize}",this.PageSize);103
if(this.PagerStyleStr=="common"){this.commonPagerStyle()}else{this.singlePagerStyle();}104
$(this.ContainerId).appendChild(this.PagerDemo);105
};106
PagerControl.prototype.DataBind=function(){107
this.PageCount=parseInt(this.DataSource.getAttribute("PageCount"));108
this.CurrentPage=parseInt(this.DataSource.getAttribute("CurrentPage"));109
this.PageSize=parseInt(this.DataSource.getAttribute("PageSize"));110
this.Init();111
};

浙公网安备 33010602011771号