-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathjquery.paging.min.js
14 lines (13 loc) · 3.48 KB
/
jquery.paging.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
jQuery paging plugin v1.3.1 23/06/2014
http://www.xarg.org/2011/09/jquery-pagination-revised/
Copyright (c) 2011, Robert Eisele ([email protected])
Dual licensed under the MIT or GPL Version 2 licenses.
*/
(function(p,x,u){p.fn.paging=function(A,B){var v=this,b={setOptions:function(c){b.a=p.extend(b.a||{lapping:0,perpage:10,page:1,stepwidth:1,refresh:{interval:10,url:null},format:"",lock:!1,circular:!1,onClick:null,onFormat:function(){},onSelect:function(){return!0},onRefresh:function(){}},c||{});b.a.lapping|=0;b.a.perpage|=0;null!==b.a.page&&(b.a.page|=0);1>b.a.perpage&&(b.a.perpage=10);b.interval&&x.clearInterval(b.interval);b.a.refresh.url&&(b.interval=x.setInterval(function(){p.ajax({url:b.a.refresh.url,
success:function(c){if("string"===typeof c)try{c=p.parseJSON(c)}catch(m){return}b.a.onRefresh(c)}})},1E3*b.a.refresh.interval));b.format=function(c){for(var b=0,e=0,q=1,h={g:[],i:0,h:0,b:5,current:3,l:0,m:0},a,p=/[*<>pq\[\]().-]|[nc]+!?/g,r={"[":"first","]":"last","<":"prev",">":"next",q:"left",p:"right","-":"fill",".":"leap"},n={};a=p.exec(c);)a=""+a,u===r[a]?"("===a?e=++b:")"===a?e=0:q&&("*"===a?(h.i=1,h.h=0):(h.i=0,h.h="!"===a.charAt(a.length-1),h.b=a.length-h.h,(h.current=1+a.indexOf("c"))||(h.current=
1+h.b>>1)),h.g.push({c:"block",j:0,f:0}),q=0):(h.g.push({c:r[a],j:e,f:u===n[a]?n[a]=1:++n[a]}),"q"===a?++h.m:"p"===a&&++h.l);return h}(b.a.format);return b},setNumber:function(c){b.s=u===c||0>c?-1:c;return b},setPage:function(c){function y(c,a,b){b=""+c.onFormat.call(a,b);q=a.value?q+b.replace(/<a/i,'<a data-page="'+a.value+'"'):q+b}if(b.a.lock)return b.a.onSelect(0,v),b;if(u===c){if(c=b.a.page,null===c)return b}else if(b.a.page==c)return b;b.a.page=c|=0;var m=b.s,e=b.a,q,h=1,a=b.format,z=a.g.length,
r=z;e.perpage<=e.lapping&&(e.lapping=e.perpage-1);var n=m<=e.lapping?0:e.lapping|0;if(0>m){var f=m=-1;var k=Math.max(1,c-a.current+1-n);var t=k+a.b}else f=1+Math.ceil((m-e.perpage)/(e.perpage-n)),c=Math.max(1,Math.min(0>c?1+f+c:c,f)),a.i?(k=1,t=1+f,a.current=c,a.b=f):(k=Math.max(1,Math.min(c-a.current,f-a.b)+1),t=a.h?k+a.b:Math.min(k+a.b,1+f));for(;r--;){var l=0;var g=a.g[r];switch(g.c){case "left":l=g.f<k;break;case "right":l=t<=f-a.l+g.f;break;case "first":l=a.current<c;break;case "last":l=a.b<
a.current+f-c;break;case "prev":l=1<c;break;case "next":l=c<f}h|=l<<g.j}var d={number:m,lapping:n,pages:f,perpage:e.perpage,page:c,slice:[(l=c*(e.perpage-n)+n)-e.perpage,Math.min(l,m)]};for(q="";++r<z;){g=a.g[r];l=h>>g.j&1;switch(g.c){case "block":for(;k<t;++k)d.value=k,d.pos=1+a.b-t+k,d.active=k<=f||0>m,d.first=1===k,d.last=k===f&&0<m,y(e,d,g.c);continue;case "left":d.value=g.f;d.active=g.f<k;break;case "right":d.value=f-a.l+g.f;d.active=t<=d.value;break;case "prev":case "next":var w=0;w=0===e.stepwidth?
"next"===g.c?c<=a.current?a.current+a.b:c+a.b:c-a.b:"next"===g.c?c+e.stepwidth:c-e.stepwidth;e.circular?(d.active=1,d.value=1+(f+w-1)%f):"next"===g.c&&0>m?(d.active=1,d.value=w):(d.value=Math.max(1,Math.min(w,f)),d.active=l&&1<c&&c<f);break;case "first":d.value=1;d.active=l&&1<c;break;case "last":0>m?(d.active=1,d.value=1+c):(d.value=f,d.active=l&&c<f);break;case "leap":case "fill":d.pos=g.f;d.active=l;y(e,d,g.c);continue}d.pos=g.f;d.last=d.first=u;y(e,d,g.c)}v.length&&(p("a",v.html(q)).click(e.onClick||
function(a){a.preventDefault();a=this;do if("a"===a.nodeName.toLowerCase())break;while(a=a.parentNode);b.setPage(p(a).data("page"));b.o&&(x.location=a.href)}),b.o=e.onSelect.call({number:m,lapping:n,pages:f,slice:d.slice},c,v));return b}};return b.setNumber(A).setOptions(B).setPage()}})(jQuery,this);