diff --git a/README.md b/README.md index 315d532..de1d212 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ $(".pagination").paging(1337, { // make 1337 elements navigatable // add code which gets executed when user selects a page, how about $.ajax() or $(...).slice()? console.log(this); }, - onFormat: function (type) { + onFormat: function (type) { // Gets called for each character of "format" and returns a HTML representation switch (type) { case 'block': // n and c return '' + this.value + ''; @@ -47,8 +47,9 @@ Options - page: The current page to start on - format: A format string, look at Format - lock: Boolean to lock/disable the pager for a while (see examples/lock.html) -- lapping: The number of elements to overlap over the coming pages. +- lapping: The number of elements to overlap over the coming pages, see the [mathematical derivation](https://raw.org/article/derivation-of-pagination-calculation/). - circular: Boolean if next/prev buttons are allowed to go circular +- stepwidth: Number of steps prev/next has to go. Default=1. =0 Gives blockwise steps - onClick: Raw callback to be called instead of the `onSelect` precedure (see examples/onclick.html) - onFormat: Called for every `format` directive. See Format - refresh: `timeout` and `url` to be called periodically for updates. @@ -67,6 +68,7 @@ Every onSelect callback gets a lot of pre-calculated information on the `this` o - page: Current page on - slice: Two element array with bounds to slice elements on the current page (see examples/slice.html) +The return code of `onSelect` indicates if the link of the clicked format element should be followed (otherwise only the click-event is used) Format ====== @@ -180,7 +182,7 @@ Further examples and documentation ========================== For further details and code examples take a look at the demonstration and documentation page on: -http://www.xarg.org/2011/09/jquery-pagination-revised/ +[jQuery Pagination](https://raw.org/article/jquery-pagination-revised/) Build ===== @@ -189,4 +191,5 @@ The library is aggressively size optimized and works best with Closure-Compiler License ====== +Copyright (c) 2013, [Robert Eisele](https://raw.org/) Dual licensed under the MIT or GPL Version 2 licenses. diff --git a/bower.json b/bower.json index 3abefbb..c75b6c7 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "paging", "main": "jquery.paging.js", - "version": "1.2.0", + "version": "1.3.1", "homepage": "http://www.xarg.org/2011/09/jquery-pagination-revised/", "description": "Probably the most advanced jQuery pagination plugin.", "keywords": [ diff --git a/example/basic.html b/example/basic.html index 3d2dcc2..804b3a2 100644 --- a/example/basic.html +++ b/example/basic.html @@ -3,7 +3,7 @@ jQuery Paging Test + + + + + + + + + + + \ No newline at end of file diff --git a/jquery.paging.js b/jquery.paging.js index a3f2ea3..e9d7fb6 100644 --- a/jquery.paging.js +++ b/jquery.paging.js @@ -1,5 +1,5 @@ /** - * @license jQuery paging plugin v1.3.0 23/06/2014 + * @license jQuery paging plugin v1.3.1 23/06/2014 * http://www.xarg.org/2011/09/jquery-pagination-revised/ * * Copyright (c) 2011, Robert Eisele (robert@xarg.org) @@ -96,6 +96,8 @@ "perpage": 10, // number of elements per page "page": 1, // current page + + "stepwidth": 1, // stepwidth for prev/next -> if = 0 then blockwise steps "refresh": { "interval": 10, @@ -313,35 +315,8 @@ } else { /* Calculate the number of pages + * http://www.xarg.org/2016/10/derivation-of-pagination-calculation/ * - * Variables: - * - n: Number of elements - * - p: Elements per page - * - o: Offset (lapping) - * - x: Position of last n (aka virtual number of elements) - * - m: Height aka number of pages - * - * Condition: o < p - * - * Page Last element of page - * ===================================== - * 1 p - * 2 2p - o - * 3 3p - 2o - * ... - * k kp - (k - 1)o - * k + 1 (k + 1)p - ko - * - * => kp - (k - 1)o < n <= (k + 1)p - ko (n is on page k+1) - * <=> k(p - o) + o < n <= k(p - o) + p - * <=> (n - p) / (p - o) <= k < (n - o) / (p - o) - * => k = ceil((n - p) / (p - o)) - * - * We know that kp - ko + i = n - * => i = n - k(p - o) - * - * => m = k + 1 - * x = kp + i */ pages = 1 + Math.ceil((number - opts["perpage"]) / (opts["perpage"] - lapping)); @@ -453,36 +428,52 @@ data["active"] = rStop <= data["value"]; // Don't take group-visibility into account! break; - case "first": - data["value"] = 1; - data["active"] = tmp && 1 < page; - break; - case "prev": - if ((data["active"] = opts["circular"])) { - data["value"] = page === 1 ? pages : page - 1; + case "next": + + var p_ = 0; + + if (opts["stepwidth"] === 0) { + + if (node.ftype === "next") { + + if (page <= format.current) { + p_ = format.current + format.blockwide; + } else { + p_ = page + format.blockwide; + } + + } else { + p_ = page - format.blockwide; + } + } else { - data["value"] = Math.max(1, page - 1); - data["active"] = tmp && 1 < page; + p_ = node.ftype ==="next" ? page + opts["stepwidth"] : page - opts["stepwidth"]; } - break; - - case "last": - if ((data["active"] = (number < 0))) { - data["value"] = 1 + page; + + if (opts["circular"]) { + data["active"] = 1; + data["value"] = 1 + (pages + p_ - 1) % pages; + } else if (node.ftype === "next" && number < 0) { // if type=next and infinity navigation + data["active"] = 1; + data["value"] = p_; } else { - data["value"] = pages; - data["active"] = tmp && page < pages; + data["value"] = Math.max(1, Math.min(p_, pages)); + data["active"] = tmp && 1 < page && page < pages; } break; - case "next": - if ((data["active"] = opts["circular"])) { - data["value"] = 1 + page % pages; - } else if ((data["active"] = (number < 0))) { + case "first": + data["value"] = 1; + data["active"] = tmp && 1 < page; + break; + + case "last": + if (number < 0) { + data["active"] = 1; data["value"] = 1 + page; } else { - data["value"] = Math.min(1 + page, pages); + data["value"] = pages; data["active"] = tmp && page < pages; } break; diff --git a/jquery.paging.min.js b/jquery.paging.min.js index da169cb..d985c62 100644 --- a/jquery.paging.min.js +++ b/jquery.paging.min.js @@ -1,14 +1,14 @@ /* -jQuery paging plugin v1.3.0 23/06/2014 +jQuery paging plugin v1.3.1 23/06/2014 http://www.xarg.org/2011/09/jquery-pagination-revised/ Copyright (c) 2011, Robert Eisele (robert@xarg.org) Dual licensed under the MIT or GPL Version 2 licenses. */ -(function(n,v,r){n.fn.paging=function(z,A){var t=this,b={setOptions:function(a){b.a=n.extend(b.a||{lapping:0,perpage:10,page:1,refresh:{interval:10,url:null},format:"",lock:!1,circular:!1,onClick:null,onFormat:function(){},onSelect:function(){return!0},onRefresh:function(){}},a||{});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&&v.clearInterval(b.interval);b.a.refresh.url&&(b.interval=v.setInterval(function(){n.ajax({url:b.a.refresh.url,success:function(a){if("string"=== -typeof a)try{a=n.parseJSON(a)}catch(m){return}b.a.onRefresh(a)}})},1E3*b.a.refresh.interval));b.format=function(a){for(var b=0,f=0,h=1,g={g:[],i:0,h:0,b:5,current:3,l:0,m:0},c,p=/[*<>pq\[\]().-]|[nc]+!?/g,n={"[":"first","]":"last","<":"prev",">":"next",q:"left",p:"right","-":"fill",".":"leap"},e={};c=p.exec(a);)c=""+c,r===n[c]?"("===c?f=++b:")"===c?f=0:h&&("*"===c?(g.i=1,g.h=0):(g.i=0,g.h="!"===c.charAt(c.length-1),g.b=c.length-g.h,(g.current=1+c.indexOf("c"))||(g.current=1+g.b>>1)),g.g.push({f:"block", -j:0,c:0}),h=0):(g.g.push({f:n[c],j:f,c:r===e[c]?e[c]=1:++e[c]}),"q"===c?++g.m:"p"===c&&++g.l);return g}(b.a.format);return b},setNumber:function(a){b.s=r===a||0>a?-1:a;return b},setPage:function(a){function w(a,b,c){c=""+a.onFormat.call(b,c);p=b.value?p+c.replace(/m?(c=m=-1,h=Math.max(1,a-e.current+1-q),g=h+e.b):(c=1+Math.ceil((m-f.perpage)/(f.perpage-q)),a=Math.max(1,Math.min(0>a?1+c+a:a,c)),e.i?(h=1,g=1+c,e.current=a,e.b=c):(h=Math.max(1,Math.min(a-e.current,c-e.b)+1),g=e.h?h+e.b:Math.min(h+e.b,1+c)));for(;u--;){k=0;l=e.g[u];switch(l.f){case "left":k=l.c>l.j&1;switch(l.f){case "block":for(;hm,d.first=1===h,d.last=h===c&&0m)?d.value=1+a:(d.value=c,d.active=k&&am)?d.value=1+a:(d.value=Math.min(1+a,c),d.active=k&&ab.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(/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>g.j&1;switch(g.c){case "block":for(;km,d.first=1===k,d.last=k===f&&0m?(d.active=1,d.value=w):(d.value=Math.max(1,Math.min(w,f)),d.active=l&&1m?(d.active=1,d.value=1+c):(d.value=f,d.active=l&&c