!function (a) { "use strict"; a.jqpaginator = function (b, c) { if (!(this instanceof a.jqpaginator)) return new a.jqpaginator(b, c); var d = this; return d.$container = a(b), d.$container.data("jqpaginator", d), d.init = function () { (c.first || c.prev || c.next || c.last || c.page || c.before || c.after) && (c = a.extend({}, { first: "", prev: "", next: "", last: "", page: "", before: "", after: "" }, c)), d.options = a.extend({}, a.jqpaginator.defaultoptions, c), d.verify(), d.extendjquery(), d.render(), d.fireevent(this.options.currentpage, "init") }, d.verify = function () { var a = d.options; if (!d.isnumber(a.totalpages)) throw new error("[jqpaginator] type error: totalpages"); if (!d.isnumber(a.totalcounts)) throw new error("[jqpaginator] type error: totalcounts"); if (!d.isnumber(a.pagesize)) throw new error("[jqpaginator] type error: pagesize"); if (!d.isnumber(a.currentpage)) throw new error("[jqpaginator] type error: currentpage"); if (!d.isnumber(a.visiblepages)) throw new error("[jqpaginator] type error: visiblepages"); if (!a.totalpages && !a.totalcounts) throw new error("[jqpaginator] totalcounts or totalpages is required"); if (!a.totalpages && !a.totalcounts) throw new error("[jqpaginator] totalcounts or totalpages is required"); if (!a.totalpages && a.totalcounts && !a.pagesize) throw new error("[jqpaginator] pagesize is required"); if (a.totalcounts && a.pagesize && (a.totalpages = math.ceil(a.totalcounts / a.pagesize)), a.currentpage < 1 || a.currentpage > a.totalpages) throw new error("[jqpaginator] currentpage is incorrect"); if (a.totalpages < 1) throw new error("[jqpaginator] totalpages cannot be less currentpage") }, d.extendjquery = function () { a.fn.jqpaginatorhtml = function (b) { return b ? this.before(b).remove() : a("

").append(this.clone()).html() } }, d.render = function () { d.renderhtml(), d.setstatus(), d.bindevents() }, d.renderhtml = function () { var c, e, f, b = []; if (d.options.totalcounts) { for (c = d.getpages(), e = 0, f = c.length; f > e; e++)b.push(d.builditem("page", c[e])); d.isenable("prev") && b.unshift(d.builditem("prev", d.options.currentpage - 1)), d.isenable("first") && b.unshift(d.builditem("first", 1)), d.isenable("statistics") && b.unshift(d.builditem("statistics")), d.isenable("next") && b.push(d.builditem("next", d.options.currentpage + 1)), d.isenable("last") && b.push(d.builditem("last", d.options.totalpages)), d.isenable("before") && b.unshift(d.builditem("before")), d.isenable("after") && b.push(d.builditem("after", c[0])) } d.options.wrapper ? d.$container.html(a(d.options.wrapper).html(b.join("")).jqpaginatorhtml()) : d.$container.html(b.join("")) }, d.builditem = function (b, c) { var e = d.options[b].replace(/{{page}}/g, c).replace(/{{totalpages}}/g, d.options.totalpages).replace(/{{totalcounts}}/g, d.options.totalcounts); return a(e).attr({ "jp-role": b, "jp-data": c }).jqpaginatorhtml() }, d.setstatus = function () { var b = d.options; d.isenable("before") || a("[jp-role=before]", d.$container), d.isenable("first") && 1 !== b.currentpage || a("[jp-role=first]", d.$container).addclass(b.disableclass), d.isenable("prev") && 1 !== b.currentpage || a("[jp-role=prev]", d.$container).addclass(b.disableclass), (!d.isenable("next") || b.currentpage >= b.totalpages) && a("[jp-role=next]", d.$container).addclass(b.disableclass), (!d.isenable("last") || b.currentpage >= b.totalpages) && a("[jp-role=last]", d.$container).addclass(b.disableclass), d.isenable("after") || a("[jp-role=after]", d.$container), a("[jp-role=page]", d.$container).removeclass(b.activeclass), a("[jp-role=page][jp-data=" + b.currentpage + "]", d.$container).addclass(b.activeclass) }, d.getpages = function () { var f, g, h, i, a = [], b = d.options.visiblepages, c = d.options.currentpage, e = d.options.totalpages; for (b > e && (b = e), f = math.floor(b / 2), g = c - f + 1 - b % 2, h = c + f, 1 > g && (g = 1, h = b), h > e && (h = e, g = 1 + e - b), i = g; h >= i;)a.push(i), i++; return a }, d.isnumber = function (a) { var b = typeof a; return "number" === b || "undefined" === b }, d.isenable = function (a) { return d.options[a] && "string" == typeof d.options[a] }, d.switchpage = function (a) { d.options.currentpage = a, d.render() }, d.fireevent = function (a, b) { return "function" != typeof d.options.onpagechange || d.options.onpagechange(a, b) !== !1 }, d.callmethod = function (b, c) { switch (b) { case "option": d.options = a.extend({}, d.options, c), d.verify(), d.render(); break; case "destroy": d.$container.empty(), d.$container.removedata("jqpaginator"); break; default: throw new error('[jqpaginator] method "' + b + '" does not exist') }return d.$container }, d.bindevents = function () { var b = d.options; d.$container.off(), d.$container.on("click", "[jp-role]", function () { var e, f, g, c = a(this); if (!c.hasclass(b.disableclass) && !c.hasclass(b.activeclass) && (e = c.attr("jp-role"), "before" != e && "after" != e)) { if (f = +c.attr("jp-data"), "go" == e) { if (g = d.$container.find("[jp-data='go']").val(), isnan(g) || g > d.options.totalpages || 0 >= g) return d.$container.find("[jp-data='go']").val(""), void 0; if (g == d.options.currentpage) return; f = +g } else if ("more" == e) { if (g = d.options.currentpage + 1, g >= d.options.totalpages) return; f = g } d.fireevent(f, "change") && d.switchpage(f) } }), d.$container.on("change", "[jp-data='go']", function () { var b = a(this), c = b.val(); isnan(c) && b.val("") }), d.$container.on("keyup", "[jp-data='go']", function (a) { "13" == a.keycode && d.$container.find("[jp-role='go']").click() }) }, d.init(), d.$container }, a.jqpaginator.defaultoptions = { wrapper: "", first: '

  • first
  • ', prev: '', next: '', last: '
  • last
  • ', page: '
  • {{page}}
  • ', before: "", after: "", totalpages: 0, totalcounts: 0, pagesize: 0, currentpage: 1, visiblepages: 7, disableclass: "disabled", activeclass: "active", onpagechange: null }, a.fn.jqpaginator = function () { var d, b = this, c = array.prototype.slice.call(arguments); if ("string" == typeof c[0]) { if (d = a(b).data("jqpaginator")) return d.callmethod(c[0], c[1]); throw new error("[jqpaginator] the element is not instantiated") } return new a.jqpaginator(this, c[0]) } }(jquery);