filesbox/web/dist/design/designstatic/front/js/jquery.pagination.min.js

2 lines
3.0 KiB
JavaScript
Raw Normal View History

2024-07-26 06:10:54 +00:00
(function(o,d,g,l){var h=function(t,a){this.ele=t,this.defaults={currentPage:1,totalPage:10,isShow:!0,count:5,homePageText:"\u9996\u9875",endPageText:"\u5C3E\u9875",prevPageText:"\u4E0A\u4E00\u9875",nextPageText:"\u4E0B\u4E00\u9875",callback:function(){}},this.opts=o.extend({},this.defaults,a),this.current=this.opts.currentPage,this.total=this.opts.totalPage,this.init()};h.prototype={init:function(){this.render(),this.eventBind()},render:function(){var t=this.opts,a=this.current,i=this.total,n=this.getPagesTpl(),r=this.ele.empty();this.isRender=!0,this.homePage='<a href="javascript:void(0);" class="ui-pagination-page-item" data-current="1">'+t.homePageText+"</a>",this.prevPage='<a href="javascript:void(0);" class="ui-pagination-page-item" data-current="'+(a-1)+'">'+t.prevPageText+"</a>",this.nextPage='<a href="javascript:void(0);" class="ui-pagination-page-item" data-current="'+(a+1)+'">'+t.nextPageText+"</a>",this.endPage='<a href="javascript:void(0);" class="ui-pagination-page-item" data-current="'+i+'">'+t.endPageText+"</a>",this.checkPage(),this.isRender&&r.html("<div class='ui-pagination-container'>"+this.prevPage+n+this.nextPage+"</div>")},checkPage:function(){var t=this.opts,a=this.total,i=this.current;t.isShow||(this.homePage=this.endPage=""),i===1&&(this.homePage=this.prevPage='<a href="javascript:void(0);" class="ui-pagination-page-item" style="opacity: 0.5;">'+t.prevPageText+"</a>"),i===a&&(this.endPage=this.nextPage='<a href="javascript:void(0);" class="ui-pagination-page-item" style="opacity: 0.5;" >'+t.nextPageText+"</a>"),a<=1&&(this.isRender=!1)},getPagesTpl:function(){var t=this.opts,a=this.total,i=this.current,n="",r=t.count;if(a<=r)for(e=1;e<=a;e++)n+=e===i?'<a href="javascript:void(0);" class="ui-pagination-page-item active" data-current="'+e+'">'+e+"</a>":'<a href="javascript:void(0);" class="ui-pagination-page-item" data-current="'+e+'">'+e+"</a>";else{var p=r/2;if(i<=p)for(e=1;e<=r;e++)n+=e===i?'<a href="javascript:void(0);" class="ui-pagination-page-item active" data-current="'+e+'">'+e+"</a>":'<a href="javascript:void(0);" class="ui-pagination-page-item" data-current="'+e+'">'+e+"</a>";else{var u=Math.floor(p),s=i+u,c=i-u,v=r%2==0;s>a&&(v?(c-=s-a-1,s=a+1):(c-=s-a,s=a)),v||s++;for(var e=c;e<s;e++)n+=e===i?'<a href="javascript:void(0);" class="ui-pagination-page-item active" data-current="'+e+'">'+e+"</a>":'<a href="javascript:void(0);" class="ui-pagination-page-item" data-current="'+e+'">'+e+"</a>"}}return n},setPage:function(t,a){return t===this.current&&a===this.total?this.ele:(this.current=t,this.total=a,this.render(),this.ele)},getPage:function(){return{current:this.current,total:this.total}},eventBind:function(){var t=this,a=this.opts.callback;this.ele.off("click").on("click",".ui-pagination-page-item",function(){var i=o(this).data("current");i&&t.current!=i&&(t.current=i,t.render(),a&&typeof a=="function"&&a(i))})}},o.fn.pagination=function(t,a,i){if(typeof t=="object"){var n=new h(this,t);this.data("pagination",n)}return typeof t=="string"?this.data("pagination")[t](a,i):this}})(jQuery,window,document);