From eda159900118f9be2b27178b34a81b5e2a0420ca Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 31 Aug 2010 15:30:56 -0400 Subject: [PATCH] Add an ability to navigate upwards. --- web_frontend/main.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/web_frontend/main.js b/web_frontend/main.js index eaf67d0..be0ea1e 100644 --- a/web_frontend/main.js +++ b/web_frontend/main.js @@ -51,6 +51,10 @@ armadillo.prototype.list = function(path) { var list = goog.dom.getElement('ls'); goog.dom.removeChildren(list); + // Add a previous directory entry. + if (path != '/' && path != '') + goog.array.insertAt(data, '../', 0); + // Add items for each entry. goog.array.forEach(data, function(file) { var elm = goog.dom.createElement('li'); @@ -68,8 +72,11 @@ armadillo.prototype.list = function(path) { * @param {Event} e */ armadillo.prototype.clickHandler_ = function(e) { - if (this.isDirectory_(goog.dom.getTextContent(e.target))) { - this.list(this.currentPath_ + goog.dom.getTextContent(e.target)); + var target = goog.dom.getTextContent(e.target); + if (target == '../') { + this.list(this.stripLastPathComponent_(this.currentPath_)); + } else if (this.isDirectory_(target)) { + this.list(this.currentPath_ + target); } }; @@ -90,3 +97,19 @@ armadillo.prototype.hashChanged_ = function(e) { armadillo.prototype.isDirectory_ = function(path) { return path[path.length - 1] == '/'; }; + +/** + * Strips the last path component from a path. + * @param {string} path + * @returns string + */ +armadillo.prototype.stripLastPathComponent_ = function(path) { + for (var i = path.length - 1; i >= 0; --i) { + if (path[i] == '/') { + if (i != path.length - 1) { + return path.substring(0, i + 1); + } + } + } + return '/'; +}; -- 2.43.5