Mercurial > code > home > repos > href
comparison 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 |
comparison
equal
deleted
inserted
replaced
7:93d94f327e82 | 8:be339aa223bf |
---|---|
1 | 1 |
2 $("#filterTag").focus(); | 2 $("#filterTag").focus(); |
3 | |
4 var model = { | |
5 filterTags: ko.observableArray(currentFilter()) | |
6 }; | |
3 | 7 |
4 function currentFilter() { | 8 function currentFilter() { |
5 var p = window.location.pathname; | 9 var p = window.location.pathname; |
6 var comps = p.split("/"); | 10 var comps = p.split("/"); |
7 if (toRoot == ".") { | 11 if (toRoot == ".") { |
17 if (selected.indexOf(tag) == -1) { | 21 if (selected.indexOf(tag) == -1) { |
18 selected.push(tag); | 22 selected.push(tag); |
19 } else { | 23 } else { |
20 selected.splice(selected.indexOf(tag), 1); | 24 selected.splice(selected.indexOf(tag), 1); |
21 } | 25 } |
26 setPageTags(selected); | |
27 } | |
22 | 28 |
29 function setPageTags(tags) { | |
30 | |
23 var newPath = window.location.pathname; | 31 var newPath = window.location.pathname; |
24 if (toRoot == ".") { | 32 if (toRoot == ".") { |
25 newPath += "/"; | 33 newPath += "/"; |
26 } else { | 34 } else { |
27 newPath = newPath.replace( | 35 newPath = newPath.replace( |
28 /(.*\/)[^\/]*$/, "$1") | 36 /(.*\/)[^\/]*$/, "$1") |
29 } | 37 } |
30 console.log("user root", newPath); | 38 console.log("user root", newPath); |
31 if (selected.length) { | 39 if (tags.length) { |
32 newPath += selected.join("+") | 40 newPath += tags.join("+") |
33 } else { | 41 } else { |
34 newPath = newPath.substr(0, newPath.length - 1); | 42 newPath = newPath.substr(0, newPath.length - 1); |
35 } | 43 } |
36 console.log("done", newPath); | 44 console.log("done", newPath); |
37 | 45 |
53 toggleTag(tag); | 61 toggleTag(tag); |
54 return false; | 62 return false; |
55 }); | 63 }); |
56 | 64 |
57 $("#filterTag").change(function () { | 65 $("#filterTag").change(function () { |
58 var tag = $(this).val(); | 66 var tags = $(this).val(); |
59 toggleTag(tag); | 67 setPageTags(tags); |
60 return false; | 68 return false; |
61 }); | 69 }); |
62 | 70 |
63 $("#filterTag").keydown(function (ev) { | 71 $("#filterTag").keydown(function (ev) { |
64 if ($(this).val() == "" && ev.which == 8) { | 72 if ($(this).val() == "" && ev.which == 8) { |
65 backspaceLastTag(); | 73 backspaceLastTag(); |
66 } | 74 } |
67 }); | 75 }); |
76 | |
77 $("#filterTag").chosen({ | |
78 | |
79 }); | |
80 | |
81 ko.applyBindings(model); | |
82 $("#filterTag").trigger("liszt:updated"); | |
83 |