comparison static/gui.js @ 10:e054949143e9

reworking addlink and shareWith support Ignore-this: b1665b776f3964f7fde219acadc51f32
author drewp@bigasterisk.com
date Fri, 15 Mar 2013 00:29:53 -0700
parents be339aa223bf
children
comparison
equal deleted inserted replaced
9:7df920c18c83 10:e054949143e9
1 1
2 $("#filterTag").focus();
3 2
4 var model = {
5 filterTags: ko.observableArray(currentFilter())
6 };
7
8 function currentFilter() {
9 var p = window.location.pathname;
10 var comps = p.split("/");
11 if (toRoot == ".") {
12 return [];
13 } else {
14 return (comps[comps.length-1] || "").split("+");
15 }
16 }
17
18 function toggleTag(tag) {
19 var selected = currentFilter();
20
21 if (selected.indexOf(tag) == -1) {
22 selected.push(tag);
23 } else {
24 selected.splice(selected.indexOf(tag), 1);
25 }
26 setPageTags(selected);
27 }
28
29 function setPageTags(tags) {
30
31 var newPath = window.location.pathname;
32 if (toRoot == ".") {
33 newPath += "/";
34 } else {
35 newPath = newPath.replace(
36 /(.*\/)[^\/]*$/, "$1")
37 }
38 console.log("user root", newPath);
39 if (tags.length) {
40 newPath += tags.join("+")
41 } else {
42 newPath = newPath.substr(0, newPath.length - 1);
43 }
44 console.log("done", newPath);
45
46 window.location.pathname = newPath;
47 }
48
49 function backspaceLastTag() {
50 var p = window.location.pathname;
51 var comps = p.split("/");
52 var selected = (comps[comps.length-1] || "").split("+");
53 if (selected.length == 0) {
54 return;
55 }
56 toggleTag(selected[selected.length-1]);
57 }
58
59 $("a.tag").click(function () {
60 var tag = $(this).text();
61 toggleTag(tag);
62 return false;
63 });
64
65 $("#filterTag").change(function () {
66 var tags = $(this).val();
67 setPageTags(tags);
68 return false;
69 });
70
71 $("#filterTag").keydown(function (ev) {
72 if ($(this).val() == "" && ev.which == 8) {
73 backspaceLastTag();
74 }
75 });
76
77 $("#filterTag").chosen({
78
79 });
80
81 ko.applyBindings(model);
82 $("#filterTag").trigger("liszt:updated");
83