/** * pagination分页插件 * @version 1.3.1 * @author mss * @url http://maxiaoxiang.com/jquery-plugins/plugins/pagination.html * * @调用方法 * $(selector).pagination(); */ ; (function (factory) { if (typeof define === "function" && (define.amd || define.cmd) && !jquery) { // amd或cmd define(["jquery"], factory); } else if (typeof module === 'object' && module.exports) { // node/commonjs module.exports = function (root, jquery) { if (jquery === undefined) { if (typeof window !== 'undefined') { jquery = require('jquery'); } else { jquery = require('jquery')(root); } } factory(jquery); return jquery; }; } else { //browser globals factory(jquery); } }(function ($) { //(默认不修改)配置参数 var defaults = { totaldata: 0, //数据总条数 showdata: 0, //每页显示的条数 pagecount: 9, //总页数,默认为9 current: 1, //当前第几页 prevcls: '', //上一页class nextcls: '', //下一页class prevcontent: '', //上一页内容 nextcontent: '', //下一页内容 normalcls: '', //普通页class activecls: '', //当前页选中状态 coping: false, //首页和尾页 ishide: true, //当前页数为0页或者1页时不显示分页 homepage: '首页', //首页内容 endpage: '尾页', //尾页内容 midlleshowcla: "1", //显示样式 1为普通样式(1,2,3,4,5,6) 2为另一种样式(上一页,1/6,下一页) firstshownum: 5,//最前面或者最后面显示的个数 endshownum: 5,//最前面或者最后面显示的个数 keepshowpn: false, //是否一直显示上一页下一页 count: 1, //当前页的左右两边显示个数 jump: false, //跳转到指定页数 jumpiptcls: 'jump-ipt', //文本框内容 jumpbtncls: 'jump-btn', //跳转按钮 jumpbtn: '跳转', //跳转按钮文本 callback: function () { } //回调 }; var pagination = function (element, options) { //全局变量 var opts = options, //配置 current, //当前页 $document = $(document), $obj = $(element); //容器 // // 设置总页数 // param int page 页码 // return opts.pagecount 总页数配置 this.setpagecount = function (page) { return opts.pagecount = page; }; opts.endshownum--; // 获取总页数 // 如果配置了总条数和每页显示条数,将会自动计算总页数并略过总页数配置,反之 // return int p 总页数 this.getpagecount = function () { return opts.totaldata || opts.showdata ? math.ceil(parseint(opts.totaldata) / opts.showdata) : opts.pagecount; }; //获取当前页 //@return int current 当前第几页 this.getcurrent = function () { return current; }; //填充数据 this.filling = function (index) { var html = ''; var temphtml = ''; current = index || opts.current; //当前页码 var pagecount = this.getpagecount(); //获取的总页数 var pre = current - opts.count; var next = current + opts.count; if (opts.keepshowpn || current > 1) {//上一页 html += '' + opts.prevcontent + ''; } else { if (opts.keepshowpn == false) { $obj.find('.' + opts.prevcls) && $obj.find('.' + opts.prevcls).remove(); } } html += ''; //显示模板切换 if (opts.midlleshowcla == "2") { var start = 1; var temp = []; for (; start <= pagecount; start++) { if (start != current) { temp.push('' + start + ''); } else { temp.push('' + start + ''); } } for (var re = 0; re < temp.length; re++) { temphtml += temp[re]; } //渲染数据但不显示 html = html + " "; html += "" + current + ""; html += "/" + pagecount + ""; } else { if (pagecount < 10) {//总页数小于10页,不做特殊处理 for (var i = 1; i <= pagecount; i++) { if (current == i) { html += '' + i + ''; } else { html += '' + i + ''; } } } else {//总页数大于10页时 if (current < opts.firstshownum) {//前面6页显示样式 1 2 3 4 5 6 7 8 ... 14 15 for (var i = 1; i <= opts.firstshownum; i++) { if (current == i) { html += '' + i + ''; } else { html += '' + i + ''; } } html += '...'; for (var i = pagecount - 1; i <= pagecount; i++) { html += '' + i + ''; } } else if (pagecount - current < opts.endshownum) { //后面5页显示样式 1 2....8 9 10 11 12 13 14 15 for (var i = 1; i <= 2; i++) { html += '' + i + ''; } html += '...'; for (var i = pagecount - opts.endshownum; i <= pagecount; i++) { if (current == i) { html += '' + i + ''; } else { html += '' + i + ''; } } } else { //前面数据处理 1 2 ....4 5 6 7 8 .... 15 16 for (var i = 1; i <= 2; i++) { html += '' + i + ''; } html += '...'; for (var i = pre; i <= next; i++) { if (current == i) { html += '' + i + ''; } else { html += '' + i + ''; } } html += '...'; for (var i = pagecount - 1; i <= pagecount; i++) { html += '' + i + ''; } } } } html += ''; //显示下一页按钮 if (opts.keepshowpn || current < pagecount) { html += '' + opts.nextcontent + ''; } else { if (opts.keepshowpn == false) { $obj.find('.' + opts.nextcls) && $obj.find('.' + opts.nextcls).remove(); } } //结束显示下一页按钮 // html += '