diff options
author | Arun Persaud <arun@nubati.net> | 2012-01-31 22:54:34 -0800 |
---|---|---|
committer | Arun Persaud <apersaud@lbl.gov> | 2012-01-31 22:54:34 -0800 |
commit | 50a8a0b9eae779f0e50530ac984bc6ded17ff5f6 (patch) | |
tree | 14c9fffa7b47f30991dc568f06d4eb7507e17daf | |
parent | fb410dcb5dd4c7f626a8672b0153d195c510946e (diff) | |
download | photo-tags-50a8a0b9eae779f0e50530ac984bc6ded17ff5f6.tar.gz photo-tags-50a8a0b9eae779f0e50530ac984bc6ded17ff5f6.tar.bz2 photo-tags-50a8a0b9eae779f0e50530ac984bc6ded17ff5f6.zip |
add prev/next pictures for easier slide show mode
for some reason all new elements show up in the enter-selection of d3. Should really be just the new pics...
-rw-r--r-- | getjson.php | 42 | ||||
-rw-r--r-- | index.php | 36 | ||||
-rw-r--r-- | style.css | 9 |
3 files changed, 84 insertions, 3 deletions
diff --git a/getjson.php b/getjson.php index 07294ba..d5dab8b 100644 --- a/getjson.php +++ b/getjson.php @@ -23,6 +23,48 @@ if (isset($_REQUEST["S"])) $result = $DB->query("SELECT name FROM tags"); } + else if (isset($_REQUEST["NP"])) + { + /* get +- 5 pics from ordered list to show next to a large image */ + + /* first create a temp table with all images and then use rowid to get +-5 images */ + + if (isset($_REQUEST["T"])) + { + /* single tag or part of tag */ + $tags = $_REQUEST["T"]; + $tags = explode(",",$tags); + $nrtags = count($tags); + + foreach ($tags as $key => $value) + $tags[$key]=sqlite_escape_string(trim($value)); + $tags = "'".implode("','",$tags)."'"; + + $DB->query("CREATE TEMP TABLE NEXTPREV AS SELECT base_uri, filename, p.id as id FROM photo_tags pt, photos p, tags t". + " WHERE pt.tag_id = t.id". + " AND (t.name COLLATE NOCASE IN ($tags))". + " AND p.id = pt.photo_id ". + " GROUP BY p.id HAVING COUNT( p.id )=$nrtags"); + + } + else + { + $DB->query("CREATE TEMP TABLE NEXTPREV AS SELECT base_uri, filename, p.id as id FROM photos p"); + }; + + if (isset($_REQUEST["ID"])) + { + $ID=intval($_REQUEST["ID"]); + $result = $DB->query("SELECT * FROM NEXTPREV". + " WHERE rowid > (select rowid from NEXTPREV where id=$ID) -5". + " AND rowid < (select rowid from NEXTPREV where id=$ID) +5"); + } + else + { + $result = $DB->query("SELECT 1 where 1=2"); + } + + } else if (isset($_REQUEST["ID"])) { $id = intval($_REQUEST["ID"]); @@ -58,7 +58,9 @@ else <button class="next" type="button" onclick="cloud()">tag cloud</button> </div> -<div class="pics"> </div> +<div class="nextprev"> <ul></ul></div> + +<div class="pics"><ul></ul> </div> <footer> This gallery belongs to <?php echo htmlspecialchars($admin) ?>. @@ -68,7 +70,7 @@ else <script type="text/javascript" > -var pics = d3.select(".pics").append("ul"); +var pics = d3.select(".pics").select("ul"); var page=<?php echo $page ?>; var N=<?php echo $N ?>; @@ -132,9 +134,39 @@ function load_content(a) { s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-small/'); return s; }); + + /* update thumbnails */ + if(T!="") + url2 = "<?php echo $webbase?>/getjson.php?NP=1&T="+T+"&ID="+ID; + else + url2 = "<?php echo $webbase?>/getjson.php?NP=1&ID="+ID; + + d3.json(url2, function(json2) { + var thumbs= d3.select(".nextprev").select("ul").selectAll("li").data(json2); + thumbs.enter().append("li") + .append("a") + .attr("href",function(d) { + s = '<?php echo $webbase; ?>'; + if(T!="") + s = s + '/tag/' + T; + s = s + '/pic/' + d.id; + return s; + }) + .append("img") + .attr("src",function(d) { + s= d.base_uri+'/'+d.filename; + s = s.replace('file:\/\/<?php echo "".str_replace("/","\/",$dbprefix); ?>','<?php echo $webbase?>/Photos-tiny/'); + return s; + }); + + thumbs.exit().remove(); + + + }); } else { + d3.select(".nextprev").select("ul").selectAll("li").remove(); pics.selectAll("li").data(picdata) .enter().append("li") .append("a") @@ -52,4 +52,11 @@ footer { } -.debug { position: absolute; top:0; left:0}
\ No newline at end of file +.debug { position: absolute; top:0; left:0} + +.nextprev ul li { + display:inline; +} +.nextprev ul li img { + padding-right: 5px; +}
\ No newline at end of file |