PageSourceSearch

https://xingkongmt.com/js/kkpager.js?v=1.00

js xingkongmt.com collected 2026-10-08 12:27:17 UTC 13,124 bytes, 330 lines download raw bytes

1/*
2  kkpager V1.3
3  https://github.com/pgkk/kkpager
4
5  Copyright (c) 2013 [email protected]
6  Licensed under the GNU GENERAL PUBLIC LICENSE
7*/
8var kkpager = {
9  pagerid 			: 'kkpager', //divID
10  mode				: 'link', //模式(link 或者 click)
11  pno					: 1, //当前页码
12  total				: 1, //总页码
13  totalRecords		: 0, //总数据条数
14  isShowFirstPageBtn	: true, //是否显示首页按钮
15  isShowLastPageBtn	: true, //是否显示尾页按钮
16  isShowPrePageBtn	: true, //是否显示上一页按钮
17  isShowNextPageBtn	: true, //是否显示下一页按钮
18  isShowTotalPage 	: true, //是否显示总页数
19  isShowCurrPage		: true,//是否显示当前页
20  isShowTotalRecords 	: false, //是否显示总记录数
21  isGoPage 			: true,	//是否显示页码跳转输入框
22  isWrapedPageBtns	: true,	//是否用span包裹住页码按钮
23  isWrapedInfoTextAndGoPageBtn : true, //是否用span包裹住分页信息和跳转按钮
24  hrefFormer			: '', //链接前部
25  hrefLatter			: '', //链接尾部
26  gopageWrapId		: 'kkpager_gopage_wrap',
27  gopageButtonId		: 'kkpager_btn_go',
28  gopageTextboxId		: 'kkpager_btn_go_input',
29  lang				: {
30    firstPageText			: '首页',
31    firstPageTipText		: '首页',
32    lastPageText			: '尾页',
33    lastPageTipText			: '尾页',
34    prePageText				: '上一页',
35    prePageTipText			: '上一页',
36    nextPageText			: '下一页',
37    nextPageTipText			: '下一页',
38    totalPageBeforeText		: '共',
39    totalPageAfterText		: '页',
40    currPageBeforeText		: '当前第',
41    currPageAfterText		: '页',
42    totalInfoSplitStr		: '/',
43    totalRecordsBeforeText	: '共',
44    totalRecordsAfterText	: '条数据',
45    gopageBeforeText		: ' è½¬åˆ°',
46    gopageButtonOkText		: '确定',
47    gopageAfterText			: '页',
48    buttonTipBeforeText		: '第',
49    buttonTipAfterText		: '页'
50  },
51  //链接算法(当处于link模式),参数n为页码
52  getLink	: function(n){
53    //这里的算法适用于比如:
54    //hrefFormer=http://www.xx.com/news/20131212
55    //hrefLatter=.html
56    //那么首页(第1页)就是http://www.xx.com/news/20131212.html
57    //第2页就是http://www.xx.com/news/20131212_2.html
58    //第n页就是http://www.xx.com/news/20131212_n.html
59    if(n == 1){
60      return this.hrefFormer + this.hrefLatter;
61    }
62    return this.hrefFormer + '_' + n + this.hrefLatter;
63  },
64  //页码单击事件处理函数(当处于mode模式),参数n为页码
65  click	: function(n){
66    //这里自己实现
67    //这里可以用this或者kkpager访问kkpager对象
68    return false;
69  },
70  //获取href的值(当处于mode模式),参数n为页码
71  getHref	: function(n){
72    //默认返回'#'
73    return '#';
74  },
75  //跳转框得到输入焦点时
76  focus_gopage : function (){
77    var btnGo = $('#'+this.gopageButtonId);
78    $('#'+this.gopageTextboxId).attr('hideFocus',true);
79    btnGo.show();
80    btnGo.css('left','10px');
81    $('#'+this.gopageTextboxId).addClass('focus');
82    btnGo.animate({left: '+=70px'}, 50);
83  },
84  //跳转框失去输入焦点时
85  blur_gopage : function(){
86    var _this = this;
87    setTimeout(function(){
88      var btnGo = $('#'+_this.gopageButtonId);
89      btnGo.animate({
90          left: '-=25'
91        }, 100, function(){
92          btnGo.hide();
93          $('#'+_this.gopageTextboxId).removeClass('focus');
94        });
95    },400);
96  },
97  //跳转输入框按键操作
98  keypress_gopage : function(){
99    var event = arguments[0] || window.event;
100    var code = event.keyCode || event.charCode;
101    //delete key
102    if(code == 8) return true;
103    //enter key
104    if(code == 13){
105      kkpager.gopage();
106      return false;
107    }
108    //copy and paste
109    if(event.ctrlKey && (code == 99 || code == 118)) return true;
110    //only number key
111    if(code<48 || code>57)return false;
112    return true;
113  },
114  //跳转框页面跳转
115  gopage : function(){
116    var str_page = $('#'+this.gopageTextboxId).val();
117    if(isNaN(str_page)){
118      $('#'+this.gopageTextboxId).val(this.next);
119      return;
120    }
121    var n = parseInt(str_page);
122    if(n < 1) n = 1;
123    if(n > this.total) n = this.total;
124    if(this.mode == 'click'){
125      this._clickHandler(n);
126    }else{
127      window.location = this.getLink(n);
128    }
129  },
130  //不刷新页面直接手动调用选中某一页码
131  selectPage : function(n){
132    this._config['pno'] = n;
133    this.generPageHtml(this._config,true);
134  },
135  //生成控件代码
136  generPageHtml : function(config,enforceInit){
137    if(enforceInit || !this.inited){
138      this.init(config);
139    }
140    
141    var str_first='',str_prv='',str_next='',str_last='';
142    if(this.isShowFirstPageBtn){
143      if(this.hasPrv){
144        str_first = '<a '+this._getHandlerStr(1)+' title="'
145          +(this.lang.firstPageTipText || this.lang.firstPageText)+'">'+this.lang.firstPageText+'</a>';
146      }else{
147        str_first = '<span class="disabled">'+this.lang.firstPageText+'</span>';
148      }
149    }
150    if(this.isShowPrePageBtn){
151      if(this.hasPrv){
152        str_prv = '<a '+this._getHandlerStr(this.prv)+' title="'
153          +(this.lang.prePageTipText || this.lang.prePageText)+'">'+this.lang.prePageText+'</a>';
154      }else{
155        str_prv = '<span class="disabled">'+this.lang.prePageText+'</span>';
156      }
157    }
158    if(this.isShowNextPageBtn){
159      if(this.hasNext){
160        str_next = '<a '+this._getHandlerStr(this.next)+' title="'
161          +(this.lang.nextPageTipText || this.lang.nextPageText)+'">'+this.lang.nextPageText+'</a>';
162      }else{
163        str_next = '<span class="disabled">'+this.lang.nextPageText+'</span>';
164      }
165    }
166    if(this.isShowLastPageBtn){
167      if(this.hasNext){
168        str_last = '<a '+this._getHandlerStr(this.total)+' title="'
169          +(this.lang.lastPageTipText || this.lang.lastPageText)+'">'+this.lang.lastPageText+'</a>';
170      }else{
171        str_last = '<span class="disabled">'+this.lang.lastPageText+'</span>';
172      }
173    }
174    var str = '';
175    var dot = '<span class="spanDot">...</span>';
176    var total_info='<span class="totalText">';
177    var total_info_splitstr = '<span class="totalInfoSplitStr">'+this.lang.totalInfoSplitStr+'</span>';
178    if(this.isShowCurrPage){
179      total_info += this.lang.currPageBeforeText + '<span class="currPageNum">' + this.pno + '</span>' + this.lang.currPageAfterText;
180      if(this.isShowTotalPage){
181        total_info += total_info_splitstr;
182        total_info += this.lang.totalPageBeforeText + '<span class="totalPageNum">'+this.total + '</span>' + this.lang.totalPageAfterText;
183      }else if(this.isShowTotalRecords){
184        total_info += total_info_splitstr;
185        total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">'+this.totalRecords + '</span>' + this.lang.totalRecordsAfterText;
186      }
187    }else if(this.isShowTotalPage){
188      total_info += this.lang.totalPageBeforeText + '<span class="totalPageNum">'+this.total + '</span>' + this.lang.totalPageAfterText;;
189      if(this.isShowTotalRecords){
190        total_info += total_info_splitstr;
191        total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">'+this.totalRecords + '</span>' + this.lang.totalRecordsAfterText;
192      }
193    }else if(this.isShowTotalRecords){
194      total_info += this.lang.totalRecordsBeforeText + '<span class="totalRecordNum">'+this.totalRecords + '</span>' + this.lang.totalRecordsAfterText;
195    }
196    total_info += '</span>';
197    
198    var gopage_info = '';
199    if(this.isGoPage){
200      gopage_info = '<span class="goPageBox">'+this.lang.gopageBeforeText+'<span id="'+this.gopageWrapId+'">'+
201        '<input type="button" id="'+this.gopageButtonId+'" onclick="kkpager.gopage()" value="'
202          +this.lang.gopageButtonOkText+'" />'+
203        '<input type="text" id="'+this.gopageTextboxId+'" onfocus="kkpager.focus_gopage()"  onkeypress="return kkpager.ke
203ypress_gopage(event);"   onblur="kkpager.blur_gopage()" value="'+this.next+'" /></span>'+this.lang.gopageAfterText+'</span>';
204    }
205    
206    //分页处理
207    if(this.total <= 8){
208      for(var i=1;i<=this.total;i++){
209        if(this.pno == i){
210          str += '<span class="curr">'+i+'</span>';
211        }else{
212          str += '<a '+this._getHandlerStr(i)+' title="'
213            +this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText+'">'+i+'</a>';
214        }
215      }
216    }else{
217      if(this.pno <= 5){
218        for(var i=1;i<=7;i++){
219          if(this.pno == i){
220            str += '<span class="curr">'+i+'</span>';
221          }else{
222            str += '<a '+this._getHandlerStr(i)+' title="'+
223              this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText+'">'+i+'</a>';
224          }
225        }
226        str += dot;
227      }else{
228        str += '<a '+this._getHandlerStr(1)+' title="'
229          +this.lang.buttonTipBeforeText + '1' + this.lang.buttonTipAfterText+'">1</a>';
230        str += '<a '+this._getHandlerStr(2)+' title="'
231          +this.lang.buttonTipBeforeText + '2' + this.lang.buttonTipAfterText +'">2</a>';
232        str += dot;
233        
234        var begin = this.pno - 2;
235        var end = this.pno + 2;
236        if(end > this.total){
237          end = this.total;
238          begin = end - 4;
239          if(this.pno - begin < 2){
240            begin = begin-1;
241          }
242        }else if(end + 1 == this.total){
243          end = this.total;
244        }
245        for(var i=begin;i<=end;i++){
246          if(this.pno == i){
247            str += '<span class="curr">'+i+'</span>';
248          }else{
249            str += '<a '+this._getHandlerStr(i)+' title="'
250              +this.lang.buttonTipBeforeText + i + this.lang.buttonTipAfterText+'">'+i+'</a>';
251          }
252        }
253        if(end != this.total){
254          str += dot;
255        }
256      }
257    }
258    var pagerHtml = '<div>';
259    if(this.isWrapedPageBtns){
260      pagerHtml += '<span class="pageBtnWrap">' + str_first + str_prv + str + str_next + str_last + '</span>'
261    }else{
262      pagerHtml += str_first + str_prv + str + str_next + str_last;
263    }
264    if(this.isWrapedInfoTextAndGoPageBtn){
265      pagerHtml += '<span class="infoTextAndGoPageBtnWrap">' + total_info + gopage_info + '</span>';
266    }else{
267      pagerHtml += total_info + gopage_info;
268    }
269    pagerHtml += '</div><div style="clear:both;"></div>';
270    $("#"+this.pagerid).html(pagerHtml);
271  },
272  //分页按钮控件初始化
273  init : function(config){
274    this.pno = isNaN(config.pno) ? 1 : parseInt(config.pno);
275    this.total = isNaN(config.total) ? 1 : parseInt(config.total);
276    this.totalRecords = isNaN(config.totalRecords) ? 0 : parseInt(config.totalRecords);
277    if(config.pagerid){this.pagerid = config.pagerid;}
278    if(config.mode){this.mode = config.mode;}
279    if(config.gopageWrapId){this.gopageWrapId = config.gopageWrapId;}
280    if(config.gopageButtonId){this.gopageButtonId = config.gopageButtonId;}
281    if(config.gopageTextboxId){this.gopageTextboxId = config.gopageTextboxId;}
282    if(config.isShowFirstPageBtn != undefined){this.isShowFirstPageBtn=config.isShowFirstPageBtn;}
283    if(config.isShowLastPageBtn != undefined){this.isShowLastPageBtn=config.isShowLastPageBtn;}
284    if(config.isShowPrePageBtn != undefined){this.isShowPrePageBtn=config.isShowPrePageBtn;}
285    if(config.isShowNextPageBtn != undefined){this.isShowNextPageBtn=config.isShowNextPageBtn;}
286    if(config.isShowTotalPage != undefined){this.isShowTotalPage=config.isShowTotalPage;}
287    if(config.isShowCurrPage != undefined){this.isShowCurrPage=config.isShowCurrPage;}
288    if(config.isShowTotalRecords != undefined){this.isShowTotalRecords=config.isShowTotalRecords;}
289    if(config.isWrapedPageBtns){this.isWrapedPageBtns=config.isWrapedPageBtns;}
290    if(config.isWrapedInfoTextAndGoPageBtn){this.isWrapedInfoTextAndGoPageBtn=config.isWrapedInfoTextAndGoPageBtn;}
291    if(config.isGoPage != undefined){this.isGoPage=config.isGoPage;}
292    if(config.lang){
293      for(var key in config.lang){
294        this.lang[key] = config.lang[key];
295      }
296    }
297    this.hrefFormer = config.hrefFormer || '';
298    this.hrefLatter = config.hrefLatter || '';
299    if(config.getLink && typeof(config.getLink) == 'function'){this.getLink = config.getLink;}
300    if(config.click && typeof(config.click) == 'function'){this.click = config.click;}
301    if(config.getHref && typeof(config.getHref) == 'function'){this.getHref = config.getHref;}
302    if(!this._config){
303      this._config = config;
304    }
305    //validate
306    if(this.pno < 1) this.pno = 1;
307    this.total = (this.total <= 1) ? 1: this.total;
308    if(this.pno > this.total) this.pno = this.total;
309    this.prv = (this.pno<=2) ? 1 : (this.pno-1);
310    this.next = (this.pno >= this.total-1) ? this.total : (this.pno + 1);
311    this.hasPrv = (this.pno > 1);
312    this.hasNext = (this.pno < this.total);
313    
314    this.inited = true;
315  },
316  _getHandlerStr : function(n){
317    if(this.mode == 'click'){
318      return 'href="'+this.getHref(n)+'" onclick="return kkpager._clickHandler('+n+')"';
319    }
320    //link模式,也是默认的
321    return 'href="'+this.getLink(n)+'"';
322  },
323  _clickHandler	: function(n){
324    var res = false;
325    if(this.click && typeof this.click == 'function'){
326      res = this.click.call(this,n) || false;
327    }
328    return res;
329  }
330};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.