comparison 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
comparison
equal deleted inserted replaced
1:7cecda055fae 2:80b11112c9e0
1
2 function toggleTag(tag) {
3 var p = window.location.pathname;
4 var comps = p.split("/");
5 var selected = (comps[2] || "").split("+");
6 var add = true;
7 var others = [];
8 for (var i=0; i < selected.length; i++) {
9 if (!selected[i]) {
10 continue;
11 }
12 if (selected[i] == tag) {
13 add = false;
14 } else {
15 others.push(selected[i]);
16 }
17 }
18 if (add) {
19 others.push(tag);
20 }
21 window.location.pathname = "/" + comps[1] + "/" + others.join("+");
22 }
23
24 function backspaceLastTag() {
25 var p = window.location.pathname;
26 var comps = p.split("/");
27 var selected = (comps[2] || "").split("+");
28 if (selected.length == 0) {
29 return;
30 }
31 toggleTag(selected[selected.length-1]);
32 }
33
34 $("a.tag").click(function () {
35 var tag = $(this).text();
36 toggleTag(tag);
37 return false;
38 });
39
40 $("#filterTag").change(function () {
41 var tag = $(this).val();
42 toggleTag(tag);
43 return false;
44 });
45
46 $("#filterTag").keydown(function (ev) {
47 if ($(this).val() == "" && ev.which == 8) {
48 backspaceLastTag();
49 }
50 });
51
52 $("#filterTag").focus();