annotate static/gui.js @ 8:be339aa223bf

tag/filter autocompelte Ignore-this: f6235de879c1ce62a8fc41e890edd0d2
author Drew Perttula <drewp@bigasterisk.com>
date Wed, 06 Mar 2013 23:22:24 -0800
parents f8c4c7ce5f4a
children e054949143e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
1
409da49c148d partway though add
drewp@bigasterisk.com
parents: 2
diff changeset
2 $("#filterTag").focus();
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
3
8
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
4 var model = {
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
5 filterTags: ko.observableArray(currentFilter())
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
6 };
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
7
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
8 function currentFilter() {
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
9 var p = window.location.pathname;
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
10 var comps = p.split("/");
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
11 if (toRoot == ".") {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
12 return [];
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
13 } else {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
14 return (comps[comps.length-1] || "").split("+");
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
15 }
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
16 }
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
17
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
18 function toggleTag(tag) {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
19 var selected = currentFilter();
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
20
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
21 if (selected.indexOf(tag) == -1) {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
22 selected.push(tag);
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
23 } else {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
24 selected.splice(selected.indexOf(tag), 1);
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
25 }
8
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
26 setPageTags(selected);
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
27 }
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
28
8
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
29 function setPageTags(tags) {
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
30
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
31 var newPath = window.location.pathname;
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
32 if (toRoot == ".") {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
33 newPath += "/";
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
34 } else {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
35 newPath = newPath.replace(
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
36 /(.*\/)[^\/]*$/, "$1")
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
37 }
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
38 console.log("user root", newPath);
8
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
39 if (tags.length) {
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
40 newPath += tags.join("+")
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
41 } else {
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
42 newPath = newPath.substr(0, newPath.length - 1);
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
43 }
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
44 console.log("done", newPath);
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
45
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
46 window.location.pathname = newPath;
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
47 }
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
48
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
49 function backspaceLastTag() {
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
50 var p = window.location.pathname;
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
51 var comps = p.split("/");
5
f8c4c7ce5f4a lots of href additions: add/edit, nav fixes
Drew Perttula <drewp@bigasterisk.com>
parents: 4
diff changeset
52 var selected = (comps[comps.length-1] || "").split("+");
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
53 if (selected.length == 0) {
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
54 return;
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
55 }
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
56 toggleTag(selected[selected.length-1]);
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
57 }
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
58
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
59 $("a.tag").click(function () {
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
60 var tag = $(this).text();
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
61 toggleTag(tag);
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
62 return false;
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
63 });
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
64
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
65 $("#filterTag").change(function () {
8
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
66 var tags = $(this).val();
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
67 setPageTags(tags);
2
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
68 return false;
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
69 });
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
70
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
71 $("#filterTag").keydown(function (ev) {
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
72 if ($(this).val() == "" && ev.which == 8) {
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
73 backspaceLastTag();
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
74 }
80b11112c9e0 web app for query urls like /user and /user/tag+tag
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
75 });
8
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
76
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
77 $("#filterTag").chosen({
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
78
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
79 });
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
80
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
81 ko.applyBindings(model);
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
82 $("#filterTag").trigger("liszt:updated");
be339aa223bf tag/filter autocompelte
Drew Perttula <drewp@bigasterisk.com>
parents: 5
diff changeset
83