Mercurial > code > home > repos > href
comparison static/links.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 | |
children | a8887fb93676 |
comparison
equal
deleted
inserted
replaced
9:7df920c18c83 | 10:e054949143e9 |
---|---|
1 | |
2 $("#filterTag").focus(); | |
3 | |
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().split(","); | |
67 setPageTags(tags); | |
68 return false; | |
69 }); | |
70 | |
71 var filterCompleteWords = ""; | |
72 $("#filterTag").select2({ | |
73 allowClear: true, | |
74 multiple: true, | |
75 tokenSeparators: [' ', ','], | |
76 query: function (opts) { | |
77 $.ajax({ | |
78 url: toRoot + "/tags", | |
79 data: {user: user, have: opts.element.val()}, | |
80 success: function (data) { | |
81 opts.callback({results: data.tags}); | |
82 } | |
83 }); | |
84 }, | |
85 change: function (ev) { | |
86 console.log("ch", ev.val); | |
87 }, | |
88 initSelection: function (element, callback) { | |
89 var data = []; | |
90 $(element.val().split(",")).each(function () { | |
91 data.push({id: this, text: this}); | |
92 }); | |
93 callback(data); | |
94 } | |
95 }); | |
96 $("#filterTag").select2("val", model.filterTags()); | |
97 | |
98 ko.applyBindings(model); |