/* kkpager v1.3 https://github.com/pgkk/kkpager copyright (c) 2013 cqzhangkang@163.com licensed under the gnu general public license */ /*! url - v2.0.0 - 2015-09-02 */ window.url=function(){function a(){}function b(a){return decodeuricomponent(a.replace(/\+/g," "))}function c(a,b){var c=a.charat(0),d=b.split(c);return c===a?d:(a=parseint(a.substring(1),10),d[0>a?d.length+a:a-1])}function d(a,c){var d=a.charat(0),e=c.split("&"),f=[],g={},h=[],i=a.substring(1);for(var j in e)if(f=e[j].split(/=(.*)/),""!==f[0].replace(/\s/g,"")){if(f[1]=b(f[1]||""),i===f[0])return f[1];h=f[0].match(/(.*)\[([0-9]+)\]/),h?(g[h[1]]=g[h[1]]||[],g[h[1]][h[2]]=f[1]):g[f[0]]=f[1]}return d===a?g:g[i]}return function(b,e){var f,g,h={};if("tld?"===b)return a();if(e=e||window.location.tostring(),!b)return e;if(b=b.tostring(),e.match(/^mailto:[^\/]/))h.protocol="mailto",h.email=e.split(/mailto\:/)[1];else{if(f=e.split(/#(.*)/),h.hash=f[1]?f[1]:void 0,h.hash&&b.match(/^#/))return d(b,h.hash);if(f=f[0].split(/\?(.*)/),h.query=f[1]?f[1]:void 0,h.query&&b.match(/^\?/))return d(b,h.query);if(f=f[0].split(/\:?\/\//),h.protocol=f[1]?f[0].tolowercase():void 0,f=(f[1]?f[1]:f[0]).split(/(\/.*)/),h.path=f[1]?f[1]:"",h.path=h.path.replace(/^([^\/])/,"/$1").replace(/\/$/,""),b.match(/^[\-0-9]+$/)&&(b=b.replace(/^([^\/])/,"/$1")),b.match(/^\//))return c(b,h.path.substring(1));if(g=c("/-1",h.path.substring(1)),g=g.split(/\.(.*)/),g[1]&&(h.file=g[0]+"."+g[1],h.filename=g[0],h.fileext=g[1]),f=f[0].split(/\:([0-9]+)$/),h.port=f[1]?f[1]:void 0,f=f[0].split(/@/),h.auth=f[1]?f[0]:void 0,h.auth&&(g=h.auth.split(/\:(.*)/),h.user=g[0],h.pass=g[1]),h.hostname=(f[1]?f[1]:f[0]).tolowercase(),"."===b.charat(0))return c(b,h.hostname);a()&&(f=h.hostname.match(a()),f&&(h.tld=f[3],h.domain=f[2]?f[2]+"."+f[3]:void 0,h.sub=f[1]||void 0)),h.port=h.port||("https"===h.protocol?"443":"80"),h.protocol=h.protocol||("443"===h.port?"https":"http")}return b in h?h[b]:"[]"===b?h:void 0}}(),"undefined"!=typeof jquery&&jquery.extend({url:function(a,b){return window.url(a,b)}}); var zhizhangpages = []; var zhizhangpages_findpage = function(obj){ if(zhizhangpages.length == 0) return null; var pagerid = $(obj).data("pagerid").tostring(); for(var i in zhizhangpages) if(zhizhangpages[i].id == pagerid) return zhizhangpages[i].obj; } var createkkpager = function(config){ // zhizhangfenye var kkpager = { pagerid : 'kkpager', //divid mode : 'link', //模式(link 或者 click) pno : 1, //当前页码 total : 1, //总页码 totalrecords : 0, //总数据条数 isshowfirstpagebtn : true, //是否显示首页按钮 isshowlastpagebtn : true, //是否显示末页按钮 isshowprepagebtn : true, //是否显示上一页按钮 isshownextpagebtn : true, //是否显示下一页按钮 isshowtotalpage: true, //是否显示总页数 isshowcurrpage : true,//是否显示当前页 isshowtotalrecords : true, //是否显示总记录数 isgopage : true, //是否显示页码跳转输入框 iswrapedpagebtns : true, //是否用span包裹住页码按钮 iswrapedinfotextandgopagebtn : true, //是否用span包裹住分页信息和跳转按钮 hrefformer : '', //链接前部 hreflatter : '', //链接尾部 gopagewrapid : 'kkpager-gopage-wrap', gopagebuttonid : 'kkpager-btn-go', gopagetextboxid : 'kkpager-btn-go-input', lang : { firstpagetext : '首页', firstpagetiptext : '首页', lastpagetext : '末页', lastpagetiptext : '末页', prepagetext : '上一页', prepagetiptext : '上一页', nextpagetext : '下一页', nextpagetiptext : '下一页', totalpagebeforetext : '共', totalpageaftertext : '页', currpagebeforetext : '当前第', currpageaftertext : '页', totalinfosplitstr : '/', totalrecordsbeforetext : '共', totalrecordsaftertext : '条数据', gopagebeforetext : '到第', gopagebuttonoktext : '确定', gopageaftertext : '页', buttontipbeforetext : '第', buttontipaftertext : '页' }, //链接算法(当处于link模式),参数n为页码 getlink : function(n){ //这里的算法适用于比如: //hrefformer=http://www.xx.com/news/20131212 //hreflatter=.html //那么首页(第1页)就是http://www.xx.com/news/20131212.html //第2页就是http://www.xx.com/news/20131212_2.html //第n页就是http://www.xx.com/news/20131212_n.html if(n == 1){ return this.hrefformer + this.hreflatter; } return this.hrefformer + '_' + n + this.hreflatter; }, //页码单击事件处理函数(当处于mode模式),参数n为页码 click : function(n){ //这里自己实现 //这里可以用this或者kkpager访问kkpager对象 return false; }, //获取href的值(当处于mode模式),参数n为页码 gethref : function(n){ //默认返回'#' return '#'; }, //跳转框得到输入焦点时 // focus_gopage : function (){ // var btngo = $('#'+this.gopagebuttonid); // $('#'+this.gopagetextboxid).attr('hidefocus',true); // btngo.show(); // btngo.css('left','10px'); // $('#'+this.gopagetextboxid).addclass('focus'); // btngo.animate({left: '+=30'}, 50); // }, // //跳转框失去输入焦点时 // blur_gopage : function(){ // var _this = this; // settimeout(function(){ // var btngo = $('#'+_this.gopagebuttonid); // btngo.animate({ // left: '-=25' // }, 100, function(){ // btngo.hide(); // $('#'+_this.gopagetextboxid).removeclass('focus'); // }); // },400); // }, //跳转输入框按键操作 keypress_gopage : function(){ var event = arguments[0] || window.event; var code = event.keycode || event.charcode; //delete key if(code == 8) return true; //enter key if(code == 13){ kkpager.gopage(); return false; } //copy and paste if(event.ctrlkey && (code == 99 || code == 118)) return true; //only number key if(code<48 || code>57)return false; return true; }, //跳转框页面跳转 gopage : function(){ var str_page = $('#'+this.gopagetextboxid).val(); if(isnan(str_page)){ $('#'+this.gopagetextboxid).val(this.next); return; } var n = parseint(str_page); if(n < 1) n = 1; if(n > this.total) n = this.total; if(this.mode == 'click'){ this._clickhandler(n); }else{ window.location = this.getlink(n); } }, //不刷新页面直接手动调用选中某一页码 selectpage : function(n){ this._config['pno'] = n; this.generpagehtml(kkpager, true); }, //生成控件代码 generpagehtml: function (config, enforceinit) { if (enforceinit || !this.inited) { this.init(config); } var str_first='',str_prv='',str_next='',str_last=''; if(this.isshowfirstpagebtn){ if(this.hasprv){ str_first = ''+this.lang.firstpagetext+''; }else{ str_first = ''+this.lang.firstpagetext+''; } } if(this.isshowprepagebtn){ if(this.hasprv){ str_prv = ''+this.lang.prepagetext+''; }else{ str_prv = ''+this.lang.prepagetext+''; } } if(this.isshownextpagebtn){ if(this.hasnext){ str_next = ''+this.lang.nextpagetext+''; }else{ str_next = ''+this.lang.nextpagetext+''; } } if(this.isshowlastpagebtn){ if(this.hasnext){ str_last = ''+this.lang.lastpagetext+''; }else{ str_last = ''+this.lang.lastpagetext+''; } } var str = ''; var dot = '...'; var total_info=''; var total_info_splitstr = ''+this.lang.totalinfosplitstr+''; if(this.isshowcurrpage){ total_info += this.lang.currpagebeforetext + '' + this.pno + '' + this.lang.currpageaftertext; if(this.isshowtotalpage){ total_info += total_info_splitstr; total_info += this.lang.totalpagebeforetext + ''+this.total + '' + this.lang.totalpageaftertext; }else if(this.isshowtotalrecords){ total_info += total_info_splitstr; total_info += this.lang.totalrecordsbeforetext + ''+this.totalrecords + '' + this.lang.totalrecordsaftertext; } }else if(this.isshowtotalpage){ total_info += this.lang.totalpagebeforetext + ''+this.total + '' + this.lang.totalpageaftertext;; if(this.isshowtotalrecords){ total_info += total_info_splitstr; total_info += this.lang.totalrecordsbeforetext + ''+this.totalrecords + '' + this.lang.totalrecordsaftertext; } }else if(this.isshowtotalrecords){ total_info += this.lang.totalrecordsbeforetext + ''+this.totalrecords + '' + this.lang.totalrecordsaftertext; } total_info += ''; var gopage_info = ''; if(this.isgopage){ gopage_info = ''+this.lang.gopagebeforetext+''+ ''+ ''+this.lang.gopageaftertext+''; } //分页处理 if(this.total <= 8){ for(var i=1;i<=this.total;i++){ if(this.pno == i){ str += ''+i+''; }else{ str += ''+i+''; } } }else{ if(this.pno <= 5){ for(var i=1;i<=7;i++){ if(this.pno == i){ str += ''+i+''; }else{ str += ''+i+''; } } str += dot; }else{ str += '1'; str += '2'; str += dot; var begin = this.pno - 2; var end = this.pno + 2; if(end > this.total){ end = this.total; begin = end - 4; if(this.pno - begin < 2){ begin = begin-1; } }else if(end + 1 == this.total){ end = this.total; } for(var i=begin;i<=end;i++){ if(this.pno == i){ str += ''+i+''; }else{ str += ''+i+''; } } if(end != this.total){ str += dot; } } } var pagerhtml = '
'; if(this.iswrapedpagebtns){ pagerhtml += ''+ str_prv + str_first + str +str_last + str_next + '' }else{ pagerhtml +=str_prv + str_first + str + str_last+ str_next; } if(this.iswrapedinfotextandgopagebtn){ pagerhtml += '' + gopage_info + ''; }else{ pagerhtml += gopage_info; } pagerhtml += '
'; $("#"+this.pagerid).html(pagerhtml); return this; }, //分页按钮控件初始化 init: function (config) { this.pno = isnan(config.pno) ? 1 : parseint(config.pno); this.total = isnan(config.total) ? 1 : parseint(config.total); this.totalrecords = isnan(config.totalrecords) ? 0 : parseint(config.totalrecords); if(config.pagerid){this.pagerid = config.pagerid;} if(config.mode){this.mode = config.mode;} if(config.gopagewrapid){this.gopagewrapid = config.gopagewrapid;} if(config.gopagebuttonid){this.gopagebuttonid = config.gopagebuttonid;} if(config.gopagetextboxid){this.gopagetextboxid = config.gopagetextboxid;} if(config.isshowfirstpagebtn != undefined){this.isshowfirstpagebtn=config.isshowfirstpagebtn;} if(config.isshowlastpagebtn != undefined){this.isshowlastpagebtn=config.isshowlastpagebtn;} if(config.isshowprepagebtn != undefined){this.isshowprepagebtn=config.isshowprepagebtn;} if(config.isshownextpagebtn != undefined){this.isshownextpagebtn=config.isshownextpagebtn;} if(config.isshowtotalpage != undefined){this.isshowtotalpage=config.isshowtotalpage;} if(config.isshowcurrpage != undefined){this.isshowcurrpage=config.isshowcurrpage;} if(config.isshowtotalrecords != undefined){this.isshowtotalrecords=config.isshowtotalrecords;} if(config.iswrapedpagebtns){this.iswrapedpagebtns=config.iswrapedpagebtns;} if(config.iswrapedinfotextandgopagebtn){this.iswrapedinfotextandgopagebtn=config.iswrapedinfotextandgopagebtn;} if(config.isgopage != undefined){this.isgopage=config.isgopage;} if(config.lang){ for(var key in config.lang){ this.lang[key] = config.lang[key]; } } this.hrefformer = config.hrefformer || ''; this.hreflatter = config.hreflatter || ''; if(config.getlink && typeof(config.getlink) == 'function'){this.getlink = config.getlink;} if(config.click && typeof(config.click) == 'function'){this.click = config.click;} if(config.gethref && typeof(config.gethref) == 'function'){this.gethref = config.gethref;} if(!this._config){ this._config = config; } //validate if(this.pno < 1) this.pno = 1; this.total = (this.total <= 1) ? 1 : this.total; if(this.pno > this.total) this.pno = this.total; this.prv = (this.pno<=2) ? 1 : (this.pno-1); this.next = (this.pno >= this.total-1) ? this.total : (this.pno + 1); this.hasprv = (this.pno > 1); this.hasnext = (this.pno < this.total); this.inited = true; }, _gethandlerstr : function(n){ if(this.mode == 'click'){ return 'href="'+this.gethref(n)+'" data-pagerid="'+this.pagerid+'" onclick="zhizhangpages_findpage(this)._clickhandler('+n+')"'; } //link模式,也是默认的 return 'href="'+this.getlink(n)+'"'; }, _clickhandler : function(n){ var res = false; if(this.click && typeof this.click == 'function'){ res = this.click.call(this,n) || false; } return res; } }; zhizhangpages.push({"id": config.pagerid, "obj": kkpager.generpagehtml(config)}); }