better display of description and time for a single photo
[photo-tags.git] / js / photo-tags.js
index 4b8d397f4c2f0c1125f00b63994449421415f89e..ce4ee497e2628674d5a4688f2c59f1bd2693d732 100644 (file)
@@ -1,3 +1,23 @@
+  /**
+    copyright 2012,2013 Arun Persaud <arun@nubati.net>
+
+    This file is part of photo-tags.
+
+    Photo-tags is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Photo-tags is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Photo-tags.  If not, see <http://www.gnu.org/licenses/>.
+
+  **/
+
 var pics = d3.select(".pics").select("ul");
 var page;
 var maxpage;
@@ -76,22 +96,26 @@ function load_content() {
                .text(function(d) {
                    var date = new Date(d.time*1000);
                    if (d.description=="")
-                       return "Time: "+date.toUTCString();
+                       return " "+date.toUTCString();
                    else
-                       return "Description: "+d.description + "Time: "+date.toUTCString();
+                       return " "+d.description + " "+date.toUTCString();
                });
            /* show tags */
-           tags="";
            d3.json(webbase+"/getjson.php?IDT="+ID, function(jsontag) {
-               singlepicspace.append("p").selectAll("span").data(jsontag)
+               tags=0;
+               d3.select("#pictags").selectAll("span").remove();
+               d3.select("#pictags").selectAll("span").data(jsontag)
                    .enter().append("span")
                    .attr("class","btn btn-small")
                    .text( function(t) {
+                       tags=1;
                        return t.name;
                    })
-                   .on("mouseover", function(d){ d3.select(this).classed("btn-danger",true)})
-                   .on("mouseout", function(d){ d3.select(this).classed("btn-danger",false)})
-                   .on("click", function(d) { document.location.href=webbase+'/tag/'+d.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});
+               if(tags)
+               d3.select("#pictags").insert("span",":first-child").text("tags in current picture:");
            });
 
            update_thumbnails();
@@ -143,16 +167,9 @@ function next_page() {
     update_page_index();
 }
 
-function prev_pic() {
-}
-
-function next_pic() {
-}
-
 function load_pic(myid) {
   ID=myid;
   update_page_index();
-  update_thumbnails();
   load_content();
 }
 
@@ -218,16 +235,23 @@ function update_thumbnails(){
 
       /* resort elements */
       d3.select(".nextprev").select("ul").selectAll("li").sort(function(a,b){return a.id-b.id;});
-      d3.select(".nextprev").select("ul").selectAll("li").select("a").select("img").classed("current",function(d){return (d.id==IDcurr);});
+      d3.select(".nextprev").select("ul").selectAll("li").select("a").select("img")
+         .classed("current",function(d){return (d.id==IDcurr);});
 
 
       /* add links for left/right arrows */
       if (IDprev != -1 )
-       d3.select(".left").on("click", function() { load_pic(IDprev); });
+         d3.select(".left" ).on("click", function() { load_pic(IDprev); });
       if (IDnext != -1 )
-       d3.select(".right").on("click", function() { load_pic(IDnext); });
-
-    });
+         d3.select(".right").on("click", function() { load_pic(IDnext); });
+
+      /* keyboard shortcuts */
+      $(document)
+         .keydown(  function (e) {
+             if(e.which == 37 && IDprev != -1) { $(document).unbind('keydown'); load_pic(IDprev);  }
+             if(e.which == 39 && IDnext != -1) { $(document).unbind('keydown'); load_pic(IDnext);  }
+         });
+  });
 }
 
 function checkbutton()