-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCls_jsPage.js
executable file
·272 lines (271 loc) · 8.65 KB
/
Cls_jsPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/**
*=================================================================
*Name: 叶子js分页样式(ShowoPage Style With JS)
*RCSfile: Cls_jsPage.js
*Revision: 0.09
*Author: Yehe(叶子)
*Released: 2005-05-12 23:00:15
*Description: js分页样式,显示上一页下一页的翻页结果
*Contact: QQ:311673,MSN:[email protected]
*WebSite: http://www.yehe.org,http://www.showo.com
*=================================================================
*/
function Cls_jsPage(iRecCount,iPageSize,iPageNum,sName){
this.iRC=this.FormatNum(iRecCount,1,0,0,0);//总记录条数
this.iPS=this.FormatNum(iPageSize,1,0,1,0);//每页记录数目
this.iPN=this.FormatNum(iPageNum,0,0,0,0);//显示的前后页数,0为显示所有,负数为这么多页面一个跳转
this.sN=sName;//实例对象名
this.sTPage="{$Page}";//页数
this.sTPageCount="{$PageCount}";//总页数
this.sTRecCount="{$RecCount}";//总记录数
this.sTPageSize="{$PageSize}";//每页记录数
this.sTPageFrist="{$PageFrist}";//首页
this.sTPagePrev="{$PagePrev}";//上页
this.sTPageNext="{$PageNext}";//下页
this.sTPageLast="{$PageLast}";//尾页
this.sTPageText="{$PageText}";//数字跳转
this.sTPageTextF="{$PageTextF}";//数字跳转框架
this.sTPageInput="{$PageInput}";//输入框跳转
this.sTPageSelect="{$PageSelect}";//下拉菜单跳转
this.sTPageNum="{$PageNum}";//数字页数
this.iPC=this.getPageCount();//得到页数
}
//输入 页数开始值,结尾值
Cls_jsPage.prototype.setPageSE=function(sPageStart,sPageEnd){
var sPS=sPageStart,sPE=sPageEnd;
this.sPS=(sPS.length>0)?sPS:"Page=";
this.sPE=(sPE.length>0)?sPE:"";
}
//输入 网址
Cls_jsPage.prototype.setUrl=function(sUrl){
var s=sUrl;
this.Url=(s.length>0)?s:""+document.location.href;
}
//输入 输入框&下拉框name值
Cls_jsPage.prototype.setPageInput=function(sPageInput){
var sPI=sPageInput;
this.sPI=(sPI.length>0)?sPI:"Page";
}
//输入 语言 首页(Disable,Enale)
Cls_jsPage.prototype.setPageFrist=function(sDis,sEn){
this.PF_D=sDis;
this.PF_E=sEn;
}
//输入 语言 上页
Cls_jsPage.prototype.setPagePrev=function(sDis,sEn){
this.PP_D=sDis;
this.PP_E=sEn;
}
//输入 语言 下页
Cls_jsPage.prototype.setPageNext=function(sDis,sEn){
this.PN_D=sDis;
this.PN_E=sEn;
}
//输入 语言 尾页
Cls_jsPage.prototype.setPageLast=function(sDis,sEn){
this.PL_D=sDis;
this.PL_E=sEn;
}
//输入 语言 数字跳转
Cls_jsPage.prototype.setPageText=function(sDis,sEn){
this.PT_D=sDis;//"[{$PageNum}]"
this.PT_E=sEn;//"第{$PageNum}页"
}
//输入 语言 数字跳转外围模板
Cls_jsPage.prototype.setPageTextF=function(sDis,sEn){
this.PTF_D=sDis;//" {$PageTextF} "
this.PTF_E=sEn;//" {$PageTextF} "
}
//输入 语言 下拉菜单跳转
Cls_jsPage.prototype.setPageSelect=function(sDis,sEn){
this.PS_D=sDis;//"[{$PageNum}]"
this.PS_E=sEn;//"第{$PageNum}页"
}
//输入 css
Cls_jsPage.prototype.setPageCss=function(sCssPageText,sCssPageInput,sCssPageSelect){
this.CPT=sCssPageText;//数字跳转css
this.CPI=sCssPageInput;//输入框跳转css
this.CPS=sCssPageSelect;//下拉菜单跳转css
}
//输入 Html模板
Cls_jsPage.prototype.setHtml=function(sHtml){
this.Html=sHtml;//Html模板
}
//计算页数
Cls_jsPage.prototype.getPageCount=function(){
var iRC=this.iRC,iPS=this.iPS;
var i=Math.ceil(iRC / iPS);//(iRC%iPS==0)?(iRC/iPS):(this.FormatNum((iRC/iPS),1,0,0,0)+1);
return (i);
}
//取得模板页数和当前页数
Cls_jsPage.prototype.getUrl=function(iType){
var s=this.Url,sPS=this.sPS,sPE=this.sPE,sTP=this.sTPage,iPC=this.iPC;
var iT=iType,i;
if (s.indexOf(sPS)==-1) {
s+=((s.indexOf("?")==-1)?"?":"&")+sPS+sTP;
i=1;
}
else {
sReg="(\\S.*)"+this.FormatReg(sPS)+"(\\d*)"+this.FormatReg(sPE)+"(\\S.*|\\S*)";
var sPIndex=this.Reg(s,sReg,"$3");
s=s.replace(sPS+sPIndex+sPE,sPS+sTP+sPE);
i=this.FormatNum(sPIndex,1,1,0,iPC);
}
s=this.Reg(s,"(&+)","&");
s=this.Reg(s,"(\\?&)","?");
return (iT==0?s:i);
}
//页面跳转
Cls_jsPage.prototype.PageJump=function(){
var sPL,sPV,sP;
var sU=this.getUrl(0),iPI=this.getUrl(1);
var sPI=this.sPI,sTP=this.sTPage,iPC=this.iPC;
sPL=document.getElementsByName(sPI).length;
for (var i=0;i<sPL;i++) {
sPV=document.getElementsByName(sPI)[i].value;
sP=this.FormatNum(sPV,1,1,0,iPC);
if (sP>0) {
location.href=sU.replace(sTP,sP);
break;
}
}
}
//输出
Cls_jsPage.prototype.Write=function(){
var sU=this.getUrl(0),iPI=this.getUrl(1);
var sN=this.sN,sPI=this.sPI;
var iPC=this.iPC,iPN=this.iPN;;
var iRC=this.iRC,iPS=this.iPS;
var PF_D=this.PF_D,PF_E=this.PF_E;
var PP_D=this.PP_D,PP_E=this.PP_E;
var PN_D=this.PN_D,PN_E=this.PN_E;
var PL_D=this.PL_D,PL_E=this.PL_E;
var PT_D=this.PT_D,PT_E=this.PT_E;
var PTF_D=this.PTF_D,PTF_E=this.PTF_E;
var PS_D=this.PS_D,PS_E=this.PS_E;
var CPT=this.CPT,CPI=this.CPI;
var CPS=this.CPS,iPN=this.iPN;
var s=this.Html;
sTPage=this.sTPage;
sTPageCount=this.sTPageCount;
sTRecCount=this.sTRecCount;
sTPageSize=this.sTPageSize;
sTPFrist=this.sTPageFrist;
sTPPrev=this.sTPagePrev;
sTPNext=this.sTPageNext;
sTPLast=this.sTPageLast;
sTPText=this.sTPageText;
sTPTextF=this.sTPageTextF;
sTPInput=this.sTPageInput;
sTPSelect=this.sTPageSelect;
sTPageNum=this.sTPageNum;
var PrevP=this.FormatNum((iPI-1),1,1,1,iPC),NextP=this.FormatNum((iPI+1),1,1,1,iPC);
var FU,PU,NU,LU;
var s1="<span class=\""+CPT+"\"><A href=\"",s2="\">",s3="</A></span>";
var s4="<span class=\""+CPT+"\">",s5="</span>";
if (iPI<=1&&iPC<=1) {
FU=s4+PF_D+s5;
PU=s4+PP_D+s5;
NU=s4+PN_D+s5;
LU=s4+PL_D+s5;
}
else if (iPI==1&&iPC>1) {
FU=s4+PF_D+s5;
PU=s4+PP_D+s5;
NU=s1+sU.replace(sTPage,NextP)+s2+PN_E+s3;
LU=s1+sU.replace(sTPage,iPC)+s2+PL_E+s3;
}
else if (iPI==iPC) {
FU=s1+sU.replace(sTPage,1)+s2+PF_E+s3;
PU=s1+sU.replace(sTPage,PrevP)+s2+PP_E+s3;
NU=s4+PN_D+s5;
LU=s4+PL_D+s5;
}
else {
FU=s1+sU.replace(sTPage,1)+s2+PF_E+s3;
PU=s1+sU.replace(sTPage,PrevP)+s2+PP_E+s3;
NU=s1+sU.replace(sTPage,NextP)+s2+PN_E+s3;
LU=s1+sU.replace(sTPage,iPC)+s2+PL_E+s3;
}
var PageStart,PageEnd;
if (iPN<0) {
iPN=Math.abs(iPN);
PageStart=(iPI%iPN==0)?(iPI/iPN):(this.FormatNum((iPI/iPN),1,0,0,0));
PageStart=(PageStart*iPN==iPI)?((PageStart-1)*iPN+1):(PageStart*iPN+1);
PageEnd=this.FormatNum(PageStart+iPN,0,1,0,iPC)
}
else if (iPN==0) {
PageStart=1;
PageEnd=iPC;
}
else {
PageStart=this.FormatNum((iPI-iPN),1,0,1,0);
PageEnd=this.FormatNum((PageStart+iPN*2),0,1,0,iPC);
PageStart=(PageEnd==iPC)?this.FormatNum((PageEnd-iPN*2),1,0,1,0):PageStart;
}
var PSelect="",PText="",PInput="",p;
if (iPC>=1) {
PSelect="<Select class=\""+CPS+"\" name=\""+sPI+"\" onChange=\""+sN+".PageJump()\">";
PInput="<Input class=\""+CPI+"\" type=\"text\" name=\""+sPI+"\" size=\"5\" maxlength=\"10\" onkeydown=\"if (event.keyCode==13) "+sN+".PageJump()\">";
for (var i=PageStart;i<=PageEnd;i++) {
if (i!=iPI) {
p=s1+sU.replace(sTPage,i)+s2+PT_E.replace(sTPageNum,i)+s3;
PText+=PTF_E.replace(sTPTextF,p);
PSelect+="<Option value=\""+i+"\">"+PS_E.replace(sTPageNum,i)+"</Option>";
}
else {
p=s4+PT_D.replace(sTPageNum,i)+s5;
PText+=PTF_D.replace(sTPTextF,p);
PSelect+="<Option Selected=\"Selected\">"+PS_D.replace(sTPageNum,i)+"</Option>";
}
}
PSelect+="</Select>";
}
s=s.replace(sTPage,iPI);
s=s.replace(sTPageCount,iPC);
s=s.replace(sTRecCount,iRC);
s=s.replace(sTPageSize,iPS);
s=s.replace(sTPFrist,FU);
s=s.replace(sTPPrev,PU);
s=s.replace(sTPNext,NU);
s=s.replace(sTPLast,LU);
s=s.replace(sTPText,PText);
s=s.replace(sTPInput,PInput);
s=s.replace(sTPSelect,PSelect);
document.write (s);
}
//输入:欲格式化字符,是否有最小值(0表示没有,1表示有),是否有最大值,最小值(默认值),最大值
Cls_jsPage.prototype.FormatNum=function(sNum,bMin,bMax,iMinNum,iMaxNum){
var i,iN,sN=""+sNum,iMin=iMinNum,iMax=iMaxNum;
if (sN.length>0) {
iN=parseInt(sN,10);
i=(isNaN(iN))?iMin:iN;
i=(i<iMin&&bMin==1)?iMin:i;
i=(i>iMax&&bMax==1)?iMax:i;
}
else {
i=iMin;
}
return (i);
}
//输入:欲正则字符,正则表达式,替换后字符
Cls_jsPage.prototype.Reg=function(sStr,sReg,sRe){
var s="",sS=sStr,sR=sReg,sRe=sRe;
if ((sS.length>0)&&(sR.length>0)) {
eval("re=/"+sR+"/gim;");
s=sS.replace(re,sRe);
}
return (s);
}
//格式化正则中的特殊字符
Cls_jsPage.prototype.FormatReg=function(sReg){
var s="",sR=sReg;
var sF=new Array ("/",".","+","[","]","{","}","$","^","?","*");
if (sR.length>0) {
for (var i=0;i<=sF.length;i++) {
sR=sR.replace(sF[i],"\\"+sF[i]);
}
s="("+sR+")";
}
return (s);
}