Merge pull request #110 from kberg/master
[dygraphs.git] / gallery / gallery.js
index 08299aa..dec3cb3 100644 (file)
@@ -17,11 +17,16 @@ 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.subtitle.id = "subtitle";
   Gallery.workareaChild = Gallery.create("div", Gallery.workarea);
-  Gallery.workarea.style.visibility = "hidden";
+  Gallery.title = document.getElementById("title");
+  Gallery.textarea = new TextArea();
+  Gallery.textarea.width = 600;
+  Gallery.textarea.height = 400;
+
   for (var idx in Gallery.entryOrder) {
     var id = Gallery.entryOrder[idx];
     var demo = Gallery.entries[id];
@@ -42,8 +47,11 @@ 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 = "g/" + id;
@@ -51,6 +59,11 @@ Gallery.start = function() {
       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);
@@ -75,6 +88,8 @@ Gallery.hashChange = function(event) {
       var id = location.hash.substring(3) + "-toc";
       var elem = document.getElementById(id);
       elem.onclick();
+      return;
     }
   }
-};
\ No newline at end of file
+  Gallery.workareaChild.innerHTML = "<h3>Select a demo from the gallery on the left</h3>"
+};