added init function for code that needs to be called after the script has been loaded
authorArun Persaud <arun@nubati.net>
Sun, 3 Jun 2012 17:28:12 +0000 (10:28 -0700)
committerArun Persaud <arun@nubati.net>
Sun, 3 Jun 2012 17:28:12 +0000 (10:28 -0700)
index.php
js/photo-tags.js

index a2de85ae3ff7cdd432afa29051d14bbf98baa0a1..353a848b0972f7c6726d46f8abb1e06bd53f68e0 100644 (file)
--- a/index.php
+++ b/index.php
@@ -85,6 +85,7 @@ page <span class="index"></span>
 
 <script src = "<?php echo $webbase.autoversion("/js/photo-tags.js")?>"></script>
 <script type="text/javascript" >
 
 <script src = "<?php echo $webbase.autoversion("/js/photo-tags.js")?>"></script>
 <script type="text/javascript" >
+
 /*hand parameters over to javascript*/
 var page=<?php echo $page ?>;
 var N=<?php echo $N ?>;
 /*hand parameters over to javascript*/
 var page=<?php echo $page ?>;
 var N=<?php echo $N ?>;
@@ -94,6 +95,7 @@ var count=0;
 var dbprefix="<?php echo $dbprefix ?>".replace(/\//g,"\/");
 var webbase = "<?php echo $webbase?>";
 
 var dbprefix="<?php echo $dbprefix ?>".replace(/\//g,"\/");
 var webbase = "<?php echo $webbase?>";
 
+init();
 load_content();
 update_page_index();
 
 load_content();
 update_page_index();
 
index 7fce2f2290cb785f073f90b87446bf9b29d35199..c178fe1eb3ed81a261976a1fcdbfd068a07f9ef8 100644 (file)
@@ -1,30 +1,33 @@
 var pics = d3.select(".pics").select("ul");
 
 var pics = d3.select(".pics").select("ul");
 
-/* 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});
+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(" ","+"));
   });
 
   });
 
-/* 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(" ","+"));
-});
-
-if (T!="")
-  {
-    var mycurrenttags = T.split(",");
-
-    d3.select("#currenttags").select("button").remove();
-    d3.select("#currenttags").selectAll("button")
-      .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');
-  };
+  if (T!="")
+    {
+      var mycurrenttags = T.split(",");
+
+      d3.select("#currenttags").select("button").remove();
+      d3.select("#currenttags").selectAll("button")
+        .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');
+    };
+}
 
 function load_content() {
   //  d3.select(".debug").text("T,P,N = *"+T+"* *"+page+"* *"+N+"*");
 
 function load_content() {
   //  d3.select(".debug").text("T,P,N = *"+T+"* *"+page+"* *"+N+"*");