From: Arun Persaud Date: Wed, 26 Sep 2012 06:00:12 +0000 (-0700) Subject: fixed pagination to work correctly on index page X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=photo-tags.git;a=commitdiff_plain;h=801ba916b5b5680e10c3b63978034058f7fed840 fixed pagination to work correctly on index page main problem was asynchronus call to handle json data where some variables were set. those were not available in time at other places. fixed by moving those function calls inside the json loop --- diff --git a/js/photo-tags.js b/js/photo-tags.js index 95497bd..71dadd4 100644 --- a/js/photo-tags.js +++ b/js/photo-tags.js @@ -1,4 +1,6 @@ var pics = d3.select(".pics").select("ul"); +var page; +var maxpage; function init() { @@ -30,7 +32,7 @@ function init() } function load_content() { - // d3.select(".debug").text("T,P,N = *"+T+"* *"+page+"* *"+N+"*"); + // d3.select(".debug").text("T,P,N = *"+T+"* *"+page+"* *"+N+"*"); if (ID>=0) url = webbase+"/getjson.php?ID="+ID; @@ -76,9 +78,9 @@ function load_content() { return s; }); }; + checkbutton(); + update_permalink() }); - checkbutton(); - update_permalink() } function update_permalink() { @@ -97,13 +99,15 @@ function update_permalink() { } function prev_page() { - if (page>=2) page=page-1; - load_content(); + if (page>1) page=page-1; + load_content(); + update_page_index(); } function next_page() { - page=page+1; - load_content(); + if (page 0) page = nr+1; var mydata = new Array(); // add json data {page: , name: } ; at end reform array into real json and use d3 to parse it @@ -232,7 +238,7 @@ function update_page_index() if(n>0) { mydata.push('{ page:0.1, name:"Prev"}'); - if(page>7) + if(page>4) { mydata.push('{ page:1, name:"1"}'); mydata.push('{ page:1.5, name:"..."}'); @@ -275,5 +281,7 @@ function update_page_index() d3.select(".pagination").select("ul").selectAll("li").classed("active", false); d3.select(".pagination").select("ul").selectAll("li").classed("active", function(d) {return ( d.page == page ); }); + checkbutton(); } ); + }