Mercurial > code > home > repos > href
diff static/gui.js @ 5:f8c4c7ce5f4a
lots of href additions: add/edit, nav fixes
Ignore-this: 863335c4680ac9bcc6a7fc5867638d61
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Thu, 21 Feb 2013 01:39:01 -0800 |
parents | 409da49c148d |
children | be339aa223bf |
line wrap: on
line diff
--- a/static/gui.js Sun Feb 17 21:12:53 2013 -0800 +++ b/static/gui.js Thu Feb 21 01:39:01 2013 -0800 @@ -1,32 +1,47 @@ $("#filterTag").focus(); -function toggleTag(tag) { +function currentFilter() { var p = window.location.pathname; var comps = p.split("/"); - var selected = (comps[2] || "").split("+"); - var add = true; - var others = []; - for (var i=0; i < selected.length; i++) { - if (!selected[i]) { - continue; - } - if (selected[i] == tag) { - add = false; - } else { - others.push(selected[i]); - } + if (toRoot == ".") { + return []; + } else { + return (comps[comps.length-1] || "").split("+"); + } +} + +function toggleTag(tag) { + var selected = currentFilter(); + + if (selected.indexOf(tag) == -1) { + selected.push(tag); + } else { + selected.splice(selected.indexOf(tag), 1); } - if (add) { - others.push(tag); + + var newPath = window.location.pathname; + if (toRoot == ".") { + newPath += "/"; + } else { + newPath = newPath.replace( + /(.*\/)[^\/]*$/, "$1") } - window.location.pathname = "/" + comps[1] + "/" + others.join("+"); + console.log("user root", newPath); + if (selected.length) { + newPath += selected.join("+") + } else { + newPath = newPath.substr(0, newPath.length - 1); + } + console.log("done", newPath); + + window.location.pathname = newPath; } function backspaceLastTag() { var p = window.location.pathname; var comps = p.split("/"); - var selected = (comps[2] || "").split("+"); + var selected = (comps[comps.length-1] || "").split("+"); if (selected.length == 0) { return; }