changeset 10:c4f96938c259

url hash can now be used to show a part of the source code tree.
author Atul Varma <varmaa@toolness.com>
date Sun, 13 Dec 2009 00:38:24 -0800
parents 7928f100d810
children dc89fb1726b4
files moztree.html moztree.js
diffstat 2 files changed, 52 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/moztree.html	Sun Dec 13 00:01:07 2009 -0800
+++ b/moztree.html	Sun Dec 13 00:38:24 2009 -0800
@@ -7,6 +7,7 @@
 </head>
 <body>
 <h1>this is the mozilla tree.</h1>
+<div id="tree" style="display: none;"></div>
 </body>
 <script src="jquery.js"></script>
 <script src="moztree.js"></script>
--- a/moztree.js	Sun Dec 13 00:01:07 2009 -0800
+++ b/moztree.js	Sun Dec 13 00:38:24 2009 -0800
@@ -92,18 +92,54 @@
   return svg;
 }
 
-$(window).ready(
-  function() {
-    getJSON('moztree.json',
-            function(tree) {
-              var svg = makeTree(tree, {height: 2800,
-                                        dirWidth: 120,
-                                        dirDepth: 6,
-                                        landscape: false,
-                                        textPadding: 4,
-                                        minHeight: 16});
-              $(document.body).append(svg);
-              $(svg).hide();
-              $(svg).fadeIn("fast");
-            });
-  });
+function getTreePath(tree, path) {
+  var pathParts = path.split("/");
+  pathParts.reverse();
+  while (pathParts.length > 0) {
+    var dirName = pathParts.pop();
+    tree.subdirs.forEach(
+      function(subdir) {
+        if (subdir.name == dirName)
+          tree = subdir;
+      });
+  }
+  return tree;
+}
+
+var App = {
+  tree: null,
+  lastHash: null,
+  onIdle: function onIdle() {
+    if (window.location.hash != this.lastHash)
+      this.updateTree();
+  },
+  updateTree: function updateTree() {
+    var dir = this.tree;
+    if (window.location.hash && window.location.hash.length > 1)
+      dir = getTreePath(dir, window.location.hash.slice(1));
+    this.lastHash = window.location.hash;
+
+    var svg = makeTree(dir,
+                       {height: 2800,
+                        dirWidth: 120,
+                        dirDepth: 6,
+                        landscape: false,
+                        textPadding: 4,
+                        minHeight: 16});
+    $("#tree").empty();
+    $("#tree").append(svg);
+    $("#tree").fadeIn("fast");
+  },
+  start: function start() {
+    var self = this;
+    getJSON(
+      'moztree.json',
+      function(tree) {
+        self.tree = tree;
+        self.updateTree();
+        window.setInterval(function() { self.onIdle(); }, 500);
+      });
+  }
+};
+
+$(window).ready(function() { App.start(); });