X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=photo-tags.git;a=blobdiff_plain;f=js%2Fphoto-tags.js;h=238575d12cf17611c3919afbbead29dc414789e0;hp=95497bd73ecbb1fbf68d631a3d726625b6b2955c;hb=68246bb37ea3eaba59e3fb6af80d541bfd345f38;hpb=2edbbec973793211aa5683ce6f69fba2ff953f03 diff --git a/js/photo-tags.js b/js/photo-tags.js index 95497bd..238575d 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() { @@ -13,24 +15,34 @@ function init() d3.select('form').attr("action",webbase+"/tag/"+document.getElementById('MyTagsInput').value.replace(" ","+")); }); + d3.select("#currenttags").select("a").remove(); if (T!="") { var mycurrenttags = T.split(","); - d3.select("#currenttags").select("button").remove(); - d3.select("#currenttags").selectAll("button") + d3.select("#currenttags").selectAll("a") .data(mycurrenttags).enter() - .append("button").attr("type","button").text( function(d) {return d;} ); - } - else - { - d3.select("#currenttags").select("button").remove(); - d3.select("#currenttags").append("span").text( ' none'); + .append("a").attr("class","btn btn-small").text( function(d) {return d;} ) + .on("mouseover", function(d){ d3.select(this).classed("btn-danger",true)}) + .on("mouseout", function(d){ d3.select(this).classed("btn-danger",false)}) + .attr("href", function(d) { return removeTag(T.split(","),d) }); }; } +function removeTag(alltags,removetag) +{ + /* return a link to a page with 'removetag' removed from the array of tags*/ + var index = alltags.indexOf(removetag); + alltags.splice(index, 1); + if (alltags.length) + return webbase+'/tag/'+alltags.join(","); + else + return webbase; +} + + 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; @@ -48,18 +60,41 @@ function load_content() { /* if ID is set, just show one pictures, else create an array of pictures */ if (ID>=0) { - var singlepicspace=pics.selectAll("li").data(picdata, function(d){return ID;}).enter().append("li").append("div").attr("class","singlepic"); - singlepicspace.append("div").attr("class","left").append("img").attr("src",webbase+"/icons/left.png"); - singlepicspace.append("img") - .attr("class","large") - .attr("src",function(d) { - s = d.base_uri+'/'+d.filename; - s = s.replace('file:\/\/'+dbprefix,webbase+'/Photos-small/'); - return s; - }); - singlepicspace.append("div").attr("class","right").append("img").attr("src",webbase+"/icons/right.png"); - - update_thumbnails(); + var singlepicspace=pics.selectAll("li").data(picdata, function(d){return ID;}). + enter().append("li").append("div").attr("class","singlepic"); + singlepicspace.append("img").attr("class","left").attr("src",webbase+"/icons/left.png"); + singlepicspace.append("img") + .attr("class","large") + .attr("src",function(d) { + s = d.base_uri+'/'+d.filename; + s = s.replace('file:\/\/'+dbprefix,webbase+'/Photos-small/'); + return s; + }); + singlepicspace.append("img").attr("class","right").attr("src",webbase+"/icons/right.png"); + /* show description and time of photo */ + singlepicspace.append("p") + .text(function(d) { + var date = new Date(d.time*1000); + if (d.description=="") + return "Time: "+date.toUTCString(); + else + return "Description: "+d.description + "Time: "+date.toUTCString(); + }); + /* show tags */ + tags=""; + d3.json(webbase+"/getjson.php?IDT="+ID, function(jsontag) { + singlepicspace.append("p").selectAll("span").data(jsontag) + .enter().append("span") + .attr("class","btn btn-small") + .text( function(t) { + return t.name; + }) + .on("mouseover", function(d){ d3.select(this).classed("btn-success",true)}) + .on("mouseout", function(d){ d3.select(this).classed("btn-success",false)}) + .on("click", function(d) { document.location.href=webbase+'/tag/'+d.name}); + }); + + update_thumbnails(); } else { @@ -76,9 +111,9 @@ function load_content() { return s; }); }; + checkbutton(); + update_permalink() }); - checkbutton(); - update_permalink() } function update_permalink() { @@ -97,25 +132,20 @@ 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(); -} - -function prev_pic() { -} - -function next_pic() { + 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 +269,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:"..."}'); @@ -253,7 +290,13 @@ function update_page_index() mydata.push('{ page:'+(n+1)+', name:"'+(n+1)+'"}'); mydata.push('{ page:'+(n+2.1)+', name:"Next"}'); - }; + } + else + { + mydata.push('{ page:0.1, name:"Prev"}'); + mydata.push('{ page:1.1, name:"Next"}'); + } + mydata = "["+mydata.join(",")+"]"; mydata = eval('(' + mydata + ')'); @@ -275,5 +318,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(); } ); + }