-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.paginate.min.js
1 lines (1 loc) · 3.05 KB
/
jquery.paginate.min.js
1
(function(a){a.fn.paginate=function(b){return this.each(function(){var h={first_label:"First",prev_label:"Previous",next_label:"Next",last_label:"Last",ellipse_label:"...",pushstate:false,content:".page_content",navigation:".page_navigation",contain_navigation:true,items_per_page:5,abort_on_small_lists:false,num_page_links:5,show_first:true,show_last:true,show_next:true,show_prev:true,show_ellipse:true,events:{afterPage:function(){}}};var g=a.extend(true,{},h,b);var f=a(this);var k=a(g.content,f);var l=a(k).children();var q=g.contain_navigation?a(g.navigation,f):a(g.navigation);var n=l.size();var o=Math.ceil(n/g.items_per_page);var j=window.history&&window.history.pushState&&window.history.replaceState&&!navigator.userAgent.match(/((iPod|iPhone|iPad).+\bOS\s+[1-4]|WebApps\/.+CFNetwork)/);var e=false;a(q).html("");f.removeClass("no-pagination");if(g.abort_on_small_lists&&(n<=g.items_per_page)){a(l).show();f.addClass("no-pagination");return true}c();if(j&&g.pushstate){var d=window.history.state;if(d&&d.page){p(d.page,false)}else{e=true;p(1)}}else{p(1,false)}function p(t,v){if(v==undefined){v=true}var w=g.items_per_page*(t-1);var s=w+g.items_per_page;var u=a(l).slice(w,s);a(l).hide();a(u).show();a(".page_link",q).removeClass("active");a('.page_link[data-page="'+t+'"]',q).addClass("active");var r=a(".page_link[data-page]",q);w=t-((g.num_page_links-1)/2)-1;s=t+((g.num_page_links-1)/2);if(s>r.size()){s=r.size();w=r.size()-g.num_page_links}if(w<0){w=0;s=g.num_page_links}if(s>r.size()){s=r.size()}a(r).hide();a(r).slice(w,s).show();a(".ellipse",q).hide();if(a(".page_link[data-page]",q).first().css("display")=="none"){a(".ellipse.less",q).show()}if(a(".page_link[data-page]",q).last().css("display")=="none"){a(".ellipse.more",q).show()}if(j&&v&&g.pushstate){m(t)}g.events.afterPage.call(this,t)}function c(){if(g.show_first){q.append(a('<span class="page_link first"><a href="#">'+g.first_label+"</a></span>").data("page",1))}if(g.show_prev){q.append(a('<span class="page_link prev"><a href="#">'+g.prev_label+"</a></span>"))}if(g.show_ellipse){q.append(a('<span class="ellipse less">'+g.ellipse_label+"</span>"))}for(i=1;i<=o;i++){q.append(a('<span class="page_link" data-page="'+i+'"><a href="#">'+i+"</a></span>").data("page",i))}if(g.show_ellipse){q.append(a('<span class="ellipse more">'+g.ellipse_label+"</span>"))}if(g.show_prev){q.append(a('<span class="page_link next"><a href="#">'+g.next_label+"</a></span>"))}if(g.show_last){q.append(a('<span class="page_link last"><a href="#">'+g.last_label+"</a></span>").data("page",o))}a(".page_link:not(.next, .prev)",q).click(function(){var r=a(this).data("page");p(r);return false});a(".page_link.next",q).click(function(){var r=a(".page_link.active",q).data("page");if(r<o){p(r+1)}return false});a(".page_link.prev",q).click(function(){var r=a(".page_link.active",q).data("page");if(r>1){p(r-1)}return false})}a(window).bind("popstate",function(){var r=window.event.state;if(r&&r.page){p(r.page,false)}});function m(s){var r={page:s};if(e){window.history.replaceState(r,null,null);e=false}else{window.history.pushState(r,null,null)}}})}})(jQuery);