| author | ymh <ymh.work@gmail.com> |
| Tue, 12 Feb 2013 10:54:34 +0100 | |
| changeset 134 | 678b07d351ef |
| parent 73 | fb4d0566ab19 |
| permissions | -rw-r--r-- |
| 50 | 1 |
function showTags() { |
2 |
var tagsOuter = $(".taglist_container"), |
|
3 |
tagsInner = $(".taglist_container table"), |
|
4 |
acInput = $("#form_tag input[type=search]"), |
|
5 |
acdata = [], |
|
6 |
labels = { |
|
7 |
content: "Séquence", |
|
| 64 | 8 |
tag: "Mot-clé" |
9 |
}, |
|
10 |
replacerx; |
|
| 50 | 11 |
|
12 |
acInput.autocomplete({ |
|
13 |
source: function( request, response ) { |
|
| 64 | 14 |
var charsub = [ '[aáàâä]', '[cç]', '[eéèêë]', '[iíìîï]', '[oóòôö]' ], |
15 |
terms = request.term.split(/[\s,]/), |
|
16 |
escterms = terms.map(function(term) { |
|
17 |
var t = term.replace(/([\\\*\+\?\|\{\[\}\]\(\)\^\$\.\#\/])/gm, '\\$1'); |
|
18 |
_(charsub).each(function(chars) { |
|
19 |
var tmprx = new RegExp(chars,"gim"); |
|
20 |
t = t.replace(tmprx, chars); |
|
21 |
}); |
|
22 |
return t; |
|
23 |
}).filter(_.identity); |
|
24 |
var searchrxs = _(escterms).map(function(term) { |
|
25 |
return new RegExp("(^|\\s)" + term, "i") |
|
26 |
}); |
|
27 |
replacerx = new RegExp("(^|\\s)(" + escterms.join("|") + ")", "gi"); |
|
28 |
var filtered = acdata |
|
29 |
.filter(function(d) { |
|
30 |
return _(searchrxs).reduce(function(memo, rx) { |
|
31 |
return memo && rx.test(d.label); |
|
32 |
}, true); |
|
33 |
}) |
|
34 |
.sort(function(a, b) { |
|
35 |
if (a.type === b.type) { |
|
36 |
return (a.label > b.label ? 1 : (a.label < b.label ? -1 : 0)); |
|
37 |
} else { |
|
38 |
return (a.type === "content" ? -1 : 1); |
|
39 |
} |
|
40 |
}); |
|
41 |
response(filtered); |
|
| 50 | 42 |
}, |
43 |
select: function(event, ui) { |
|
44 |
document.location.href = ui.item.href; |
|
45 |
} |
|
46 |
}).data("autocomplete")._renderItem = function(ul, item) { |
|
47 |
return $( "<li>" ) |
|
48 |
.data( "item.autocomplete", item ) |
|
| 64 | 49 |
.append( "<a href='" + item.href + "'>" + labels[item.type] + " : " + item.label.replace(replacerx, '$1<b>$2</b>') + "</a>" ) |
| 50 | 50 |
.appendTo( ul ); |
51 |
}; |
|
| 64 | 52 |
acInput.on("keyup input paste", function() { |
53 |
acInput.val(acInput.val().toUpperCase()); |
|
54 |
}); |
|
| 50 | 55 |
|
56 |
$("#form_tag").submit(function() { |
|
57 |
return false; |
|
58 |
}); |
|
59 |
|
|
60 |
tagsInner.draggable(); |
|
61 |
|
|
| 64 | 62 |
var dragtimeout; |
63 |
|
|
64 |
$(".arrow_left").data({xdelta: 6, ydelta: 0}); |
|
65 |
$(".arrow_right").data({xdelta: -6, ydelta: 0}); |
|
66 |
$(".arrow_top").data({xdelta: 0, ydelta: 6}); |
|
67 |
$(".arrow_bottom").data({xdelta: 0, ydelta: -6}); |
|
68 |
|
|
69 |
$(".arrow") |
|
|
73
fb4d0566ab19
Bugfixes, Segment list now moves when changing segments
veltr
parents:
64
diff
changeset
|
70 |
.on("touchstart mousedown", function(evt) { |
| 64 | 71 |
var deltas = $(this).data(), |
72 |
move = function() { |
|
73 |
tagsInner.css({ |
|
74 |
"left": deltas.xdelta + parseInt(tagsInner.css("left")), |
|
75 |
"top": deltas.ydelta + parseInt(tagsInner.css("top")) |
|
76 |
}); |
|
77 |
} |
|
78 |
window.clearInterval(dragtimeout); |
|
79 |
dragtimeout = window.setInterval(move, 20); |
|
80 |
move(); |
|
|
73
fb4d0566ab19
Bugfixes, Segment list now moves when changing segments
veltr
parents:
64
diff
changeset
|
81 |
return false; |
| 64 | 82 |
}) |
83 |
.on( |
|
|
73
fb4d0566ab19
Bugfixes, Segment list now moves when changing segments
veltr
parents:
64
diff
changeset
|
84 |
"touchend mouseout mouseup", |
| 64 | 85 |
function() { |
86 |
window.clearInterval(dragtimeout); |
|
87 |
} |
|
88 |
); |
|
89 |
|
|
| 50 | 90 |
function resizeTags() { |
91 |
tagsInner.css({ |
|
92 |
"margin-left": - Math.floor(tagsInner.width()/2) + "px", |
|
93 |
"margin-top": - Math.floor(tagsInner.height()/2) + "px", |
|
94 |
"left": Math.floor(tagsOuter.width()/2) + "px", |
|
95 |
"top": Math.floor(tagsOuter.height()/2) + "px" |
|
96 |
}); |
|
97 |
} |
|
98 |
$(window).on("resize",resizeTags); |
|
99 |
|
|
100 |
$.ajax({ |
|
101 |
url: endpoints.contents_api, |
|
102 |
dataType: "jsonp", //TODO: JSON if on Platform |
|
103 |
data: { |
|
104 |
limit: 0, |
|
105 |
format: "jsonp" |
|
106 |
}, |
|
107 |
success: function(data) { |
|
108 |
_(data.objects).each(function(content) { |
|
| 64 | 109 |
var fpmatch = (content.front_project || "").match(/projects\/([0-9a-f\-]+)/), |
| 50 | 110 |
fproj = fpmatch ? fpmatch[1] : ""; |
111 |
acdata.push({ |
|
112 |
label: content.title, |
|
113 |
type: "content", |
|
114 |
href: endpoints.content_page.replace("__CONTENT_ID__", content.iri_id).replace("__FRONT_PROJECT_ID__", fproj) |
|
115 |
}); |
|
116 |
}); |
|
117 |
} |
|
118 |
}) |
|
119 |
|
|
120 |
$.ajax({ |
|
121 |
url: endpoints.tag_api, |
|
122 |
dataType: "json", |
|
123 |
data: { |
|
124 |
contents: "all", |
|
125 |
format: "json", |
|
126 |
limit: 0, |
|
127 |
steps: 100 |
|
128 |
}, |
|
129 |
success: function(data) { |
|
130 |
var grouped = {}; |
|
131 |
_(data.objects).each(function(t) { |
|
132 |
var upt = t.name.toUpperCase(), |
|
133 |
w = t.weight + (grouped[upt] || 0); |
|
134 |
grouped[upt] = w; |
|
135 |
}); |
|
136 |
_(grouped).each(function(v, k) { |
|
137 |
acdata.push({ |
|
138 |
label: k, |
|
139 |
type: "tag", |
|
140 |
href: endpoints.tag_page.replace("__TAG__", k) |
|
141 |
}); |
|
142 |
}); |
|
143 |
var ordered = _(grouped) |
|
144 |
.chain() |
|
145 |
.map(function(v, k) { |
|
146 |
return { |
|
147 |
label: k, |
|
148 |
weight: v |
|
149 |
} |
|
150 |
}) |
|
151 |
.sortBy(function(t) { |
|
152 |
return -t.weight; |
|
153 |
}) |
|
154 |
.value(); |
|
155 |
var l = ordered.length, |
|
156 |
max = ordered[0].weight, |
|
157 |
min = Math.min(max - 1, ordered[l - 1].weight), |
|
| 64 | 158 |
colorscale = 160 / (max - min), |
| 50 | 159 |
ncols = Math.floor(.65*Math.sqrt(l)), |
160 |
nlines = Math.ceil(l/ncols); |
|
161 |
var cells = _(nlines * ncols) |
|
162 |
.chain() |
|
163 |
.range() |
|
164 |
.map(function(i) { |
|
165 |
var x = i % ncols, |
|
166 |
y = Math.floor(i / ncols), |
|
167 |
dx = x - ((ncols - 1) / 2), |
|
168 |
dy = y - ((nlines - 1) / 2), |
|
169 |
d = Math.sqrt(dx*dx + dy*dy); |
|
170 |
return { |
|
171 |
n: i, |
|
172 |
x: x, |
|
173 |
y: y, |
|
174 |
d: d |
|
175 |
} |
|
176 |
}) |
|
177 |
.sortBy(function(c) { |
|
178 |
return c.d; |
|
179 |
}) |
|
180 |
.value(); |
|
181 |
_(ordered).each(function(v, k) { |
|
182 |
cells[k].tag = v; |
|
183 |
}); |
|
184 |
cells = _(cells).sortBy(function(c) { return c.n }); |
|
185 |
var _html = ""; |
|
186 |
_(cells).each(function(c) { |
|
187 |
if (c.x === 0) { |
|
188 |
_html += "<tr>"; |
|
189 |
} |
|
190 |
_html += "<td>"; |
|
191 |
if (c.tag) { |
|
| 64 | 192 |
var color = Math.floor( 95 + (c.tag.weight - min) * colorscale ); |
| 50 | 193 |
_html += '<a href="' |
194 |
+ endpoints.tag_page.replace("__TAG__",encodeURIComponent(c.tag.label)) |
|
195 |
+ '" style="color: rgb(' |
|
196 |
+ [color,color,color].join(",") |
|
197 |
+ ')">' |
|
198 |
+ c.tag.label |
|
199 |
+ '</a>'; |
|
200 |
} |
|
201 |
_html += "</td>"; |
|
202 |
if (c.x === (ncols - 1)) { |
|
203 |
_html += "</tr>"; |
|
204 |
} |
|
205 |
}); |
|
206 |
tagsInner.html(_html); |
|
207 |
resizeTags(); |
|
208 |
} |
|
209 |
}); |
|
|
73
fb4d0566ab19
Bugfixes, Segment list now moves when changing segments
veltr
parents:
64
diff
changeset
|
210 |
|
|
fb4d0566ab19
Bugfixes, Segment list now moves when changing segments
veltr
parents:
64
diff
changeset
|
211 |
$("#btnInfo, .lightBoxClose").click(function() { |
|
fb4d0566ab19
Bugfixes, Segment list now moves when changing segments
veltr
parents:
64
diff
changeset
|
212 |
$(".lightBoxWrap").toggle(); |
|
fb4d0566ab19
Bugfixes, Segment list now moves when changing segments
veltr
parents:
64
diff
changeset
|
213 |
return false; |
|
fb4d0566ab19
Bugfixes, Segment list now moves when changing segments
veltr
parents:
64
diff
changeset
|
214 |
}); |
|
fb4d0566ab19
Bugfixes, Segment list now moves when changing segments
veltr
parents:
64
diff
changeset
|
215 |
|
| 50 | 216 |
} |