var pics = d3.select(".pics").select("ul");
var page;
var maxpage;
function init()
{
/* populate data list with tags*/
d3.json(webbase+"/getjson.php?S", function(json) {
d3.select("#MyTags").selectAll("option").data(json)
.enter().append("option").attr("value",function(d) {return d.name});
});
/* update form to point to new link */
d3.select("input").on("keyup", function(d) {
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").selectAll("a")
.data(mycurrenttags).enter()
.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+"*");
if (ID>=0)
url = webbase+"/getjson.php?ID="+ID;
else if(T!="")
url = webbase+"/getjson.php?T="+T+"&P="+page;
else
url = webbase+"/getjson.php?P="+page;
/* update pics */
d3.json(url, function(json) {
count=0;
pics.selectAll("li").remove();
picdata=json;
/* 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("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");
update_thumbnails();
}
else
{
d3.select(".nextprev").select("ul").selectAll("li").remove();
pics.selectAll("li").data(picdata)
.enter().append("li")
.append("a")
.on("click", function(d) { load_pic(d.id); })
.append("img")
.attr("src",function(d) {
count++;
s= d.base_uri+'/'+d.filename;
s = s.replace('file:\/\/'+dbprefix,webbase+'/Photos-tiny/');
return s;
});
};
checkbutton();
update_permalink()
});
}
function update_permalink() {
/* update permalink */
permalink = webbase;
if(T!="")
permalink += '/tag/' + T;
if(page!=1)
permalink += '/page/' + page;
if(ID>0)
permalink += '/pic/' + ID;
d3.select(".permalink").html("Permalink: "+permalink+"");
}
function prev_page() {
if (page>1) page=page-1;
load_content();
update_page_index();
}
function next_page() {
if (page 0)
myID = "&ID="+ID;
if(T!="")
url = webbase+"/getjson.php?C=1&T="+T+myID;
else
url = webbase+"/getjson.php?C=1"+myID;
d3.json(url, function(json) {
/* update index, show only page +-5 pages max */
n = Math.floor( json[0].total/N ); /* how many pages */
nr = Math.floor( (json[0].row-1)/N ); /* which row are we in? rowid starts at 1 not 0 */
maxpage=n+1;
if(nr > 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
if(n>0)
{
mydata.push('{ page:0.1, name:"Prev"}');
if(page>4)
{
mydata.push('{ page:1, name:"1"}');
mydata.push('{ page:1.5, name:"..."}');
start = page-3;
}
else
start=1;
for(i=start;i<=Math.min(n+1,page+3);i++)
mydata.push('{ page:'+i+', name:"'+i+'"}');
if(page+3