Mercurial > code > home > repos > href
diff static/gui.js @ 2:80b11112c9e0
web app for query urls like /user and /user/tag+tag
Ignore-this: bb1f40dd6bbff4c3ee463b440738726d
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sun, 17 Feb 2013 03:56:28 -0800 |
parents | |
children | 409da49c148d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/static/gui.js Sun Feb 17 03:56:28 2013 -0800 @@ -0,0 +1,52 @@ + +function toggleTag(tag) { + 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 (add) { + others.push(tag); + } + window.location.pathname = "/" + comps[1] + "/" + others.join("+"); +} + +function backspaceLastTag() { + var p = window.location.pathname; + var comps = p.split("/"); + var selected = (comps[2] || "").split("+"); + if (selected.length == 0) { + return; + } + toggleTag(selected[selected.length-1]); +} + +$("a.tag").click(function () { + var tag = $(this).text(); + toggleTag(tag); + return false; +}); + +$("#filterTag").change(function () { + var tag = $(this).val(); + toggleTag(tag); + return false; +}); + +$("#filterTag").keydown(function (ev) { + if ($(this).val() == "" && ev.which == 8) { + backspaceLastTag(); + } +}); + +$("#filterTag").focus();