/*! jqpaginator-1.2.0 * http://jqpaginator.keenwon.com */ !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=a.extend({},{first:"",prev:"",next:"",last:"",page:""},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.eq(0).clone()).html()}},d.render=function(){d.renderhtml(),d.setstatus(),d.bindevents()},d.renderhtml=function(){for(var b=[],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.$container.html(d.options.wrapper?a(d.options.wrapper).html(b.join("")).jqpaginatorhtml():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("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),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 a=[],b=d.options.visiblepages,c=d.options.currentpage,e=d.options.totalpages;b>e&&(b=e);var 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);for(var 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 c=a(this);if(!c.hasclass(b.disableclass)&&!c.hasclass(b.activeclass)){var e=+c.attr("jp-data");d.fireevent(e,"change")&&d.switchpage(e)}})},d.init(),d.$container},a.jqpaginator.defaultoptions={wrapper:"",first:'

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