var kkpager = { pagerid: 'kkpager', mode: 'link', pno: 1, total: 1, totalrecords: 0, isshowfirstpagebtn: true, isshowlastpagebtn: true, isshowprepagebtn: true, isshownextpagebtn: true, isshowtotalpage: true, isshowcurrpage: true, isshowtotalrecords: false, isgopage: true, iswrapedpagebtns: true, iswrapedinfotextandgopagebtn: true, 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: '页' }, getlink: function(n) { if (n == 1) { return this.hrefformer + this.hreflatter } return this.hrefformer + '_' + n + this.hreflatter }, click: function(n) { return false }, 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; if (code == 8) return true; if (code == 13) { kkpager.gopage(); return false } if (event.ctrlkey && (code == 99 || code == 118)) return true; 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(this._config, 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_first + str_prv + str + str_next + str_last + '' } else { pagerhtml += str_first + str_prv + str + str_next + str_last } if (this.iswrapedinfotextandgopagebtn) { pagerhtml += '' + total_info + gopage_info + '' } else { pagerhtml += total_info + gopage_info } pagerhtml += '
'; $("#" + this.pagerid).html(pagerhtml) }, 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 } 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) + '" onclick="return kkpager._clickhandler(' + n + ')"' } 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 } };