1 var pics = d3.select(".pics").select("ul");
5 /* populate data list with tags*/
6 d3.json(webbase+"/getjson.php?S", function(json) {
7 d3.select("#MyTags").selectAll("option").data(json)
8 .enter().append("option").attr("value",function(d) {return d.name});
11 /* update form to point to new link */
12 d3.select("input").on("keyup", function(d) {
13 d3.select('form').attr("action",webbase+"/tag/"+document.getElementById('MyTagsInput').value.replace(" ","+"));
18 var mycurrenttags = T.split(",");
20 d3.select("#currenttags").select("button").remove();
21 d3.select("#currenttags").selectAll("button")
22 .data(mycurrenttags).enter()
23 .append("button").attr("type","button").text( function(d) {return d;} );
27 d3.select("#currenttags").select("button").remove();
28 d3.select("#currenttags").append("span").text( ' none');
32 function load_content() {
33 // d3.select(".debug").text("T,P,N = *"+T+"* *"+page+"* *"+N+"*");
36 url = webbase+"/getjson.php?ID="+ID;
38 url = webbase+"/getjson.php?T="+T+"&P="+page;
40 url = webbase+"/getjson.php?P="+page;
43 d3.json(url, function(json) {
45 pics.selectAll("li").remove();
48 /* if ID is set, just show one pictures, else create an array of pictures */
51 var singlepicspace=pics.selectAll("li").data(picdata, function(d){return ID;}).enter().append("li").append("div").attr("class","singlepic");
52 singlepicspace.append("div").attr("class","left").append("img").attr("src",webbase+"/icons/left.png");
53 singlepicspace.append("img")
54 .attr("class","large")
55 .attr("src",function(d) {
56 s = d.base_uri+'/'+d.filename;
57 s = s.replace('file:\/\/'+dbprefix,webbase+'/Photos-small/');
60 singlepicspace.append("div").attr("class","right").append("img").attr("src",webbase+"/icons/right.png");
66 d3.select(".nextprev").select("ul").selectAll("li").remove();
67 pics.selectAll("li").data(picdata)
70 .on("click", function(d) { load_pic(d.id); })
72 .attr("src",function(d) {
74 s= d.base_uri+'/'+d.filename;
75 s = s.replace('file:\/\/'+dbprefix,webbase+'/Photos-tiny/');
84 function update_permalink() {
85 /* update permalink */
90 permalink += '/tag/' + T;
92 permalink += '/page/' + page;
94 permalink += '/pic/' + ID;
96 d3.select(".permalink").html("Permalink: <a href=\""+permalink+"\">"+permalink+"</a>");
99 function prev_page() {
100 if (page>=2) page=page-1;
104 function next_page() {
109 function prev_pic() {
112 function next_pic() {
115 function load_pic(myid) {
122 function tagcloud() {
124 url = webbase+"/getjson.php?CLOUD=1";
126 pics.selectAll("li").remove();
128 var svgelement=pics.append("li")
129 .append("svg").attr("width",400).attr("height",400);
132 d3.json(url, function(json) {
133 svgelement.selectAll("text").data(json).enter().append("text")
134 .style("font-size", function(d){return (Math.log(d.count+1)/2.0)+"em"})
135 .text(function(d) { return d.name+" "; })
136 .on("mouseover", function(d){ d3.select(this).style("color","red")} )
137 .on("mouseout", function(d){ d3.select(this).style("color","white")} )
138 .on("click", function(d) { document.location.href=webbase+'/tag/'+d.name })
142 function update_thumbnails(){
144 url2 = webbase+"/getjson.php?NP=1&T="+T+"&ID="+ID;
146 url2 = webbase+"/getjson.php?NP=1&ID="+ID;
151 d3.json(url2, function(json2) {
152 /* figure out where the arrows on the pic should link to */
154 for (var i in json2){
159 IDnext = json2[i].id;
163 var thumbs= d3.select(".nextprev").select("ul").selectAll("li").data(json2, function(d) {return d.id;});
165 thumbs.enter().append("li")
167 .on("click", function(d) {
171 .attr("src",function(d) {
172 s= d.base_uri+'/'+d.filename;
173 s = s.replace('file:\/\/'+dbprefix,webbase+'/Photos-tiny/');
177 .transition().duration(1000)
178 .style("height","100px");
180 thumbs.exit().select("img").transition().duration(1000).style("height","0");
181 thumbs.exit().transition().duration(1050).remove();
183 /* resort elements */
184 d3.select(".nextprev").select("ul").selectAll("li").sort(function(a,b){return a.id-b.id;});
185 d3.select(".nextprev").select("ul").selectAll("li").select("a").select("img").classed("current",false);
186 d3.select(".nextprev").select("ul").selectAll("li").select("a").select("img").classed("current",function(d){return (d.id==IDcurr);});
189 /* add links for left/right arrows */
191 d3.select(".left").on("click", function() { load_pic(IDprev); });
193 d3.select(".right").on("click", function() { load_pic(IDnext); });
198 function checkbutton()
201 { d3.select(".pagination ul li:first-child").classed("disabled", true);}
203 { d3.select(".pagination ul li:first-child").classed("disabled", false);};
206 { d3.select(".pagination ul li:last-child").classed("disabled", true);}
208 { d3.select(".pagination ul li:last-child").classed("disabled", false);}
211 function update_page_index()
213 /* load number of pictures */
219 url = webbase+"/getjson.php?C=1&T="+T+myID;
221 url = webbase+"/getjson.php?C=1"+myID;
223 d3.json(url, function(json) {
224 /* update index, show only page +-5 pages max */
225 n = Math.floor( json[0].total/N ); /* how many pages */
226 nr = Math.floor( (json[0].row-1)/N ); /* which row are we in? rowid starts at 1 not 0 */
228 if(nr > 0) page = nr+1;
230 var mydata = new Array(); // add json data {page: <nr>, name: <name>} ; at end reform array into real json and use d3 to parse it
234 mydata.push('{ page:0.1, name:"Prev"}');
237 mydata.push('{ page:1, name:"1"}');
238 mydata.push('{ page:1.5, name:"..."}');
244 for(i=start;i<=Math.min(n+1,page+3);i++)
245 mydata.push('{ page:'+i+', name:"'+i+'"}');
249 mydata.push('{ page:'+(n+0.5)+', name:"..."}');
250 mydata.push('{ page:'+(n+1)+', name:"'+(n+1)+'"}');
253 mydata.push('{ page:'+(n+1)+', name:"'+(n+1)+'"}');
255 mydata.push('{ page:'+(n+2.1)+', name:"Next"}');
257 mydata = "["+mydata.join(",")+"]";
258 mydata = eval('(' + mydata + ')');
260 /* remove old elements */
261 d3.selectAll(".pagination").select("ul").selectAll("li").remove();
263 /* create new ones */
264 var pageindex = d3.selectAll(".pagination").select("ul").selectAll("li").data(mydata, function(d){return d.page});
265 pageindex.selectAll("li").data(mydata, function(d){ return d.page; });
266 pageindex.enter().append("li").append("a")
267 .on("click", function(d) { if( (d.page - Math.floor(d.page)) ==0 ) {page=d.page; ID=-1;load_content(); update_page_index();} })
268 .text(function(d) {return " "+d.name+" "});
270 pageindex.sort( function(a,b) { return a.page- b.page;} );
272 /* add callbacks to prev and next buttons */
273 d3.selectAll(".pagination ul li:first-child a").on("click", function(){prev_page();});
274 d3.selectAll(".pagination ul li:last-child a").on("click", function(){next_page();});
276 d3.select(".pagination").select("ul").selectAll("li").classed("active", false);
277 d3.select(".pagination").select("ul").selectAll("li").classed("active", function(d) {return ( d.page == page ); });