Show introductory text.
[dygraphs.git] / gallery / gallery.js
index dc50813..bdf2386 100644 (file)
@@ -17,11 +17,13 @@ Gallery.create = function(type, parent, className) {
 };
 
 Gallery.start = function() {
-  google.load('visualization', '1', {'packages':['annotatedtimeline']});
   Gallery.toc = document.getElementById("toc");
   Gallery.workarea = document.getElementById("workarea");
+  Gallery.subtitle = Gallery.create("div", Gallery.workarea);
   Gallery.workareaChild = Gallery.create("div", Gallery.workarea);
-  Gallery.workarea.style.visibility = "hidden";
+  Gallery.title = document.getElementById("title");
+  Gallery.textarea = new TextArea();
+
   for (var idx in Gallery.entryOrder) {
     var id = Gallery.entryOrder[idx];
     var demo = Gallery.entries[id];
@@ -42,15 +44,23 @@ Gallery.start = function() {
           Gallery.runningDemo.clean(Gallery.workareaChild);
         }
       }
-      Gallery.workarea.style.visibility = "visible";
-      document.getElementById("title").textContent = demo.title ? demo.title : "";
+      Gallery.subtitle.innerHTML = "";
+      var codeLink = Gallery.create("a", Gallery.subtitle);
+      codeLink.textContent = "code";
+      codeLink.href = "#";
+      Gallery.title.textContent = demo.title ? demo.title : "";
       demo.innerDiv.className = "selected";
       Gallery.workareaChild.id = id;
-      location.hash = id;
+      location.hash = "g/" + id;
       Gallery.workareaChild.innerHTML='';
       if (demo.setup) {
         demo.setup(Gallery.workareaChild);
       }
+      var html = Gallery.workareaChild.innerHTML;
+      codeLink.onclick = function() {
+        var javascript = demo.run.toString();
+        Gallery.textarea.show("Code", "HTML\n\n" + html + "\n\njavascript\n\n" + javascript);
+      };
       demo.run(Gallery.workareaChild);
       Gallery.runningDemo = demo;
     }; }(demo, id);
@@ -70,7 +80,13 @@ Gallery.register = function(id, demo) {
 };
 
 Gallery.hashChange = function(event) {
-  var id = location.hash.substring(1) + "-toc";
-  var elem = document.getElementById(id);
-  elem.onclick();
-};
\ No newline at end of file
+  if (location.hash) {
+    if (location.hash.indexOf("#g/") == 0) {
+      var id = location.hash.substring(3) + "-toc";
+      var elem = document.getElementById(id);
+      elem.onclick();
+      return;
+    }
+  }
+  Gallery.workareaChild.innerHTML = "<h3>Select a demo from the gallery on the left</h3>"
+};