From f4b54839e3681b73ac3a584367c9acccd204ea26 Mon Sep 17 00:00:00 2001 From: Thomas Wilburn Date: Fri, 20 Mar 2015 18:44:30 -0700 Subject: [PATCH] Expand/contract works, nothing else does. --- js/project/node.js | 29 +++++++++++++++++++++-------- js/project/tree.js | 13 +++++++++++-- js/ui/projectManager.js | 1 + 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/js/project/node.js b/js/project/node.js index 4eb5d88..6bd2e8d 100644 --- a/js/project/node.js +++ b/js/project/node.js @@ -1,11 +1,11 @@ -define(["util/manos", "util/dom2"], function(M) { +define(["util/manos", "util/elementData", "util/dom2"], function(M, elementData) { var noop = function() {}; var Node = function(entry) { this.entry = entry; this.name = entry.name - this.isOpen = true; + this.isOpen = false; this.isDirty = true; this.isDir = entry.isDirectory; this.children = []; @@ -22,7 +22,12 @@ define(["util/manos", "util/dom2"], function(M) { children: null, element: null, toggle: function(done) { - + this.isOpen = !this.isOpen; + this.render(done); + }, + setElement: function(element) { + this.element = element; + elementData.set(element, this); }, render: function(done) { var self = this; @@ -31,14 +36,22 @@ define(["util/manos", "util/dom2"], function(M) { var a = this.element.find("a.label"); if (!a) { a = document.createElement("a"); - a.className = "label"; + if (this.isDir) a.className = "directory"; + a.addClass("label"); this.element.append(a); } a.innerHTML = this.name; - if (!this.isOpen) return done(); + if (!this.isOpen) { + this.element.removeClass("expanded"); + return done(); + } + this.element.addClass("expanded"); if (this.isDirty && this.isDir) { this.readdir(function() { - self.renderChildren(done); + self.renderChildren(function() { + self.isDirty = false; + done(); + }); }); } else { this.renderChildren(done); @@ -54,10 +67,10 @@ define(["util/manos", "util/dom2"], function(M) { M.map(this.children, function(item, i, c) { if (!item.element) { var li = document.createElement("li"); - item.element = li; + item.setElement(li); ul.append(li); } - item.render(); + item.render(c); }, done) }, readdir: function(done) { diff --git a/js/project/tree.js b/js/project/tree.js index 244872e..48698af 100644 --- a/js/project/tree.js +++ b/js/project/tree.js @@ -1,8 +1,9 @@ define([ "project/node", "command", + "util/elementData", "util/dom2"], -function(Node, command) { +function(Node, command, elementData) { var directories = []; var container = document.find(".project"); @@ -17,11 +18,19 @@ function(Node, command) { var rootElement = document.createElement("li"); tree.append(element); element.append(rootElement); - root.element = rootElement; + root.setElement(rootElement); root.isOpen = true; root.render(); }) }); + tree.on("click", function(e) { + if (e.target.hasClass("directory")) { + var li = e.target.findUp("li"); + var node = elementData.get(li); + node.toggle(); + } + }); + }); \ No newline at end of file diff --git a/js/ui/projectManager.js b/js/ui/projectManager.js index 8bea280..2614a85 100644 --- a/js/ui/projectManager.js +++ b/js/ui/projectManager.js @@ -331,6 +331,7 @@ define([ }, bindEvents: function() { + return; var self = this; this.element.on("click", function(e) { e.preventDefault();