7 maxYear: 2010, |
7 maxYear: 2010, |
8 tlPixels: 960, |
8 tlPixels: 960, |
9 tlGamma: 6, |
9 tlGamma: 6, |
10 heatGamma: 4, |
10 heatGamma: 4, |
11 displayedDates: [-5000,0,500,1000,1200,1400,1600,1700,1750,1800,1850,1900,1950,2010], |
11 displayedDates: [-5000,0,500,1000,1200,1400,1600,1700,1750,1800,1850,1900,1950,2010], |
12 urls: {} |
12 mappingLibrary: 'leaflet', |
13 } |
13 } |
14 |
14 |
15 function yearToPx(year) { |
15 function yearToPx(year) { |
16 return gomNs.tlPixels * Math.pow( ( year - gomNs.minYear ) / ( gomNs.maxYear - gomNs.minYear ), gomNs.tlGamma ); |
16 return gomNs.tlPixels * Math.pow( ( year - gomNs.minYear ) / ( gomNs.maxYear - gomNs.minYear ), gomNs.tlGamma ); |
17 } |
17 } |
57 return '<li class="content-tag-item"><a href="#" onclick="tagInfo($(this).text()); return false;">' |
57 return '<li class="content-tag-item"><a href="#" onclick="tagInfo($(this).text()); return false;">' |
58 + d |
58 + d |
59 + '</a></li>'; |
59 + '</a></li>'; |
60 }).join('') |
60 }).join('') |
61 + '</ul>'; |
61 + '</ul>'; |
62 } |
62 } */ |
63 $("#tagdata").html(_html); |
63 $("#tagdata").html(_html); |
64 }); |
64 }); |
65 filterTag(_taglabel); |
65 addFilter('tag', _taglabel); |
66 $("#showlist").removeClass("actif"); |
66 $("#showlist").removeClass("actif"); |
67 } |
67 } |
68 |
68 |
69 function filterTag(_tagLabel) { |
69 function addFilter(_type, _label) { |
70 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
70 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
71 if (_curView.type == 'filter') { |
71 if (_curView.type == 'filter') { |
72 _curView.tag.push(_tagLabel); |
72 _curView[_type].push(_label); |
|
73 console.log(_curView[_type]); |
73 updateFilters(); |
74 updateFilters(); |
74 debouncedSaveChanges(); |
75 debouncedSaveChanges(); |
75 } |
76 } |
76 } |
77 } |
77 |
78 |
78 function removeFilter(_index) { |
79 function removeFilter(_type, _index) { |
79 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
80 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
80 if (_curView.type == 'filter') { |
81 if (_curView.type == 'filter') { |
81 _curView.tag.splice(_index,1); |
82 _curView[_type].splice(_index,1); |
82 updateFilters(); |
83 updateFilters(); |
83 debouncedSaveChanges(); |
84 debouncedSaveChanges(); |
84 } |
85 } |
85 } |
86 } |
86 |
87 |
87 function getUpdates() { |
88 function getUpdates() { |
88 var _params = {}, |
89 var _params = {}, |
89 _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
90 _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
90 if (_curView.type == 'filter') { |
91 if (_curView.type == 'filter') { |
91 if (_curView.period && !(_curView.period[0] == gomNs.minYear && _curView.period[1] == gomNs.maxYear)) { |
92 if (!(_curView.period[0] == gomNs.minYear && _curView.period[1] == gomNs.maxYear)) { |
92 _params.period = _curView.period.join(','); |
93 _params.period = _curView.period.join(','); |
93 } |
94 } |
94 if (_curView.tag.length) { |
95 if (_curView.tag.length) { |
95 _params.label = _curView.tag.join(','); |
96 _params.label = _curView.tag.join(','); |
96 } |
97 } |
|
98 if (_curView.country.length) { |
|
99 _params.country = _curView.country.join(','); |
|
100 } |
97 $.getJSON(gomNs.urls['filter'], _params, updateDisplay); |
101 $.getJSON(gomNs.urls['filter'], _params, updateDisplay); |
|
102 animLoad(); |
98 } |
103 } |
99 } |
104 } |
100 |
105 |
101 var debouncedGetUpdates = _.debounce(getUpdates, 300); |
106 var debouncedGetUpdates = _.debounce(getUpdates, 300); |
102 |
107 |
109 _curView.period[_n] = _int; |
114 _curView.period[_n] = _int; |
110 } |
115 } |
111 updateFilters(); |
116 updateFilters(); |
112 debouncedSaveChanges(); |
117 debouncedSaveChanges(); |
113 } |
118 } |
|
119 } |
|
120 } |
|
121 |
|
122 function removePeriod() { |
|
123 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
|
124 if (_curView.type == 'filter') { |
|
125 _curView.period[0] = gomNs.minYear; |
|
126 _curView.period[1] = gomNs.maxYear; |
|
127 updateFilters(); |
|
128 debouncedSaveChanges(); |
114 } |
129 } |
115 } |
130 } |
116 |
131 |
117 function changeSpan(_this) { |
132 function changeSpan(_this) { |
118 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
133 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
140 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
155 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
141 if (_curView.type != 'filter') { |
156 if (_curView.type != 'filter') { |
142 return; |
157 return; |
143 } |
158 } |
144 var _htmFilters = '', |
159 var _htmFilters = '', |
145 _fl = _curView.tag.length; |
160 _fl = _curView.tag.length, |
146 if (!_curView.period && !_fl) { |
161 _cl = _curView.country.length; |
|
162 /* if (!_curView.period && !_fl && !_cl) { |
147 _htmFilters = '<li class="nofilter">Aucun filtre</li>'; |
163 _htmFilters = '<li class="nofilter">Aucun filtre</li>'; |
148 } |
164 } */ |
149 if (_curView.period) { |
165 if (_curView.period[0] == gomNs.minYear && _curView.period[1] == gomNs.maxYear) { |
150 _htmFilters += '<li class="filperiod"><span class="spyr" id="sp_0" onclick="changeSpan(this);">' |
166 _htmFilters += '<li class="filperiod">Toutes périodes</li>'; |
|
167 } else { |
|
168 _htmFilters += '<li class="filperiod">Période : <span class="spyr" id="sp_0" onclick="changeSpan(this);">' |
151 + _curView.period[0] |
169 + _curView.period[0] |
152 + '</span> à <span class="spyr" id="sp_1" onclick="changeSpan(this);">' |
170 + '</span> à <span class="spyr" id="sp_1" onclick="changeSpan(this);">' |
153 + _curView.period[1] |
171 + _curView.period[1] |
154 + '</span></li>'; |
172 + '</span><a href="#" class="remfil" onclick="removePeriod(); return false;">[x]</a></li>'; |
155 $("#handle_0").css({ |
173 } |
156 "left" : yearToPx(_curView.period[0])+"px", |
174 $("#handle_0").css({ |
157 }).attr("year", _curView.period[0]) |
175 "left" : yearToPx(_curView.period[0])+"px", |
158 .find(".handleinner") |
176 }).attr("year", _curView.period[0]) |
159 .css({ |
177 .find(".handleinner") |
160 "margin-left" : "-20px" |
178 .css({ |
161 }); |
179 "margin-left" : "-20px" |
162 $("#handle_1").css({ |
180 }); |
163 "left" : yearToPx(_curView.period[1])+"px", |
181 $("#handle_1").css({ |
164 }).attr("year", _curView.period[1]) |
182 "left" : yearToPx(_curView.period[1])+"px", |
165 .find(".handleinner") |
183 }).attr("year", _curView.period[1]) |
166 .css({ |
184 .find(".handleinner") |
167 "margin-left" : "0" |
185 .css({ |
168 }); |
186 "margin-left" : "0" |
|
187 }); |
|
188 if (_cl) { |
|
189 _htmFilters += _(_curView.country).map(function(_t, _i) { |
|
190 return '<li class="filcountry">Pays : ' |
|
191 + ( (typeof gomNs.countries == "object" && typeof gomNs.countries[_t] == "object") ? gomNs.countries[_t].properties.label_fr : decodeURIComponent(_t.match('[^/]+$')[0]).replace('_',' ')) |
|
192 + '<a href="#" class="remfil" onclick="removeFilter(\'country\',' |
|
193 + _i |
|
194 + '); return false;">[x]</a></li>'; |
|
195 }).join(""); |
169 } |
196 } |
170 if (_fl) { |
197 if (_fl) { |
171 _htmFilters += _(_curView.tag).map(function(_t, _i) { |
198 _htmFilters += _(_curView.tag).map(function(_t, _i) { |
172 return '<li class="filtag">' |
199 return '<li class="filtag">Tag : ' |
173 + _t |
200 + _t |
174 + '<a href="#" class="remfil" onclick="removeFilter(' |
201 + '<a href="#" class="remfil" onclick="removeFilter(\'tag\',' |
175 + _i |
202 + _i |
176 + '); return false;">[x]</a></li>'; |
203 + '); return false;">[x]</a></li>'; |
177 }).join(""); |
204 }).join(""); |
178 } |
205 } |
179 $("#filters").html(_htmFilters); |
206 $("#filters").html(_htmFilters); |
184 if (contentdata && contentdata.length) { |
211 if (contentdata && contentdata.length) { |
185 var _htmlCl = '<ul id="contentlist">' |
212 var _htmlCl = '<ul id="contentlist">' |
186 + contentdata.map(function(_d) { |
213 + contentdata.map(function(_d) { |
187 var _html = '<li class="content-item"><h3>' |
214 var _html = '<li class="content-item"><h3>' |
188 + _d.title |
215 + _d.title |
189 + '</h3><h4><a href="' |
216 + '</h3>' |
|
217 + ( typeof _d.coords == "object" ? |
|
218 '<div class="maplet"><img src="http://maps.googleapis.com/maps/api/staticmap?center=47,1.5&zoom=4&size=160x160&maptype=roadmap&markers=color:red%7C' |
|
219 + _d.coords.latitude |
|
220 + ',' |
|
221 + _d.coords.longitude |
|
222 + '&sensor=false" /><h4>Localisation : ' |
|
223 + _d.coords.city_name |
|
224 + '</h4></div>' |
|
225 : '') |
|
226 + '<h4><a href="' |
190 + _d.url |
227 + _d.url |
191 + '" target="_blank">' |
228 + '" target="_blank">' |
192 + _d.url |
229 + _d.url.replace(/(^.{40}).+(.{30}$)/m,'$1 … $2') |
193 + '</a></h4><p>' |
230 + '</a></h4><p>' |
194 + _d.description |
231 + _d.description.replace(/(^.{0,160})([\s]|$)(.*)/,'$1…') |
195 + '</p><ul class="content-tags">' |
232 + '</p><ul class="content-tags">' |
196 + _d.tags.map(function(_t) { |
233 + _d.tags.map(function(_t) { |
197 return '<li class="content-tag-item"><a href="#" onclick="tagInfo($(this).text()); return false;"' |
234 return '<li class="content-tag-item"><a href="#" onclick="tagInfo($(this).text()); return false;"' |
198 + (_t.match ? ' class="tagmatch"' : '') |
235 + (_t.match ? ' class="tagmatch"' : '') |
199 + '>' |
236 + '>' |
309 } |
347 } |
310 if (data.tags.length) { |
348 if (data.tags.length) { |
311 var _scores = _(data.tags).map(function(_d) { return parseInt(_d.score)}), |
349 var _scores = _(data.tags).map(function(_d) { return parseInt(_d.score)}), |
312 _maxTag = _(_scores).max(), |
350 _maxTag = _(_scores).max(), |
313 _minTag = Math.min(_(_scores).min(), _maxTag - 1), |
351 _minTag = Math.min(_(_scores).min(), _maxTag - 1), |
314 _scale = 20 / Math.sqrt(_maxTag - _minTag), |
352 _scale = 10 / Math.sqrt(_maxTag - _minTag), |
315 _htmlTc = '<ul id="tclist">' |
353 _htmlTc = '<ul id="tclist">' |
316 + _(data.tags).map(function(_d) { |
354 + _(data.tags).map(function(_d) { |
317 return '<li style="font-size:' |
355 return '<li style="font-size:' |
318 + parseInt(10 + _scale * Math.sqrt(_d.score - _minTag)) |
356 + parseInt(10 + _scale * Math.sqrt(_d.score - _minTag)) |
319 + 'px;"><a href="#" onclick="tagInfo($(this).text()); return false;"' |
357 + 'px;"><a href="#" onclick="tagInfo($(this).text()); return false;"' |
328 else { |
366 else { |
329 $("#tagcloud").html("<h4>Pas de mots-clés trouvés</h4>"); |
367 $("#tagcloud").html("<h4>Pas de mots-clés trouvés</h4>"); |
330 } |
368 } |
331 displayContents(data.contents); |
369 displayContents(data.contents); |
332 if (gomNs.countries && data.countries) { |
370 if (gomNs.countries && data.countries) { |
333 var _max = Math.max(1, _(data.countries).max(function(_c) { return _c.score}).score); |
371 var _max = Math.max(1, _(data.countries).max()); |
334 _(data.countries).each(function(_c) { |
372 _(gomNs.countries).each(function(_country, _k) { |
335 var _cc = gomNs.countries[_c.isocode]; |
373 var _val = data.countries[_k] || 0, |
336 if (_cc) { |
374 _gb = parseInt(255 * (1 - _val / _max )), |
337 var _gb = parseInt(255 * (1 - _c.score / _max )); |
375 _fill = ( _val ? "rgb(255," + _gb + "," + _gb + ")" : "#7070a0" ), |
338 _(_cc.gPolygons).each(function(_p) { |
376 _op = (_val ? .9 : .3); |
339 _p.setOptions({ |
377 switch(gomNs.mappingLibrary) { |
340 "fillColor" : ( _c.score ? "rgb(255," + _gb + "," + _gb + ")" : "#7070a0" ), |
378 case 'gmaps': |
|
379 _(_country.gPolygons).each(function(_p) { |
|
380 _p.setOptions({ |
|
381 "fillColor" : _fill, |
|
382 "fillOpacity": _op |
|
383 }); |
341 }); |
384 }); |
342 }); |
385 break; |
|
386 case 'leaflet': |
|
387 _country.layer.setStyle({ |
|
388 "fillColor" : _fill, |
|
389 "fillOpacity": _op |
|
390 }) |
|
391 break; |
343 } |
392 } |
344 }); |
393 }); |
345 } |
394 } |
346 if (data.disciplines) { |
395 if (data.disciplines) { |
347 var _disc = data.disciplines.filter(function(_d) { |
396 var _disc = data.disciplines.filter(function(_d) { |
472 } else { |
522 } else { |
473 $("#partagerw").hide(); |
523 $("#partagerw").hide(); |
474 } |
524 } |
475 var _baseUrl = document.location.href.split("#")[0]; |
525 var _baseUrl = document.location.href.split("#")[0]; |
476 $("#rourl").html(_baseUrl + "#" + data.sessionid ); |
526 $("#rourl").html(_baseUrl + "#" + data.sessionid ); |
477 gomNs.hash = "#" + data.sessionid + (data.sessionkey ? ':' + data.sessionkey : ''); |
527 gomNs.hash = "#" + data.sessionid + (data.sessionkey ? (':' + data.sessionkey) : ''); |
478 document.location.hash = gomNs.hash; |
528 document.location.hash = gomNs.hash; |
479 $("#rwurl").html(_baseUrl + gomNs.hash); |
529 $("#rwurl").html(_baseUrl + gomNs.hash); |
480 gomNs.sessiondata = JSON.parse(data.data); |
530 gomNs.sessiondata = typeof data.data == "string" ? JSON.parse(data.data) : (typeof data.data == "object" ? data.data : {}); |
481 if (!gomNs.sessiondata.title) { |
531 if (!gomNs.sessiondata.title) { |
482 gomNs.sessiondata.title = 'Nouvelle session'; |
532 gomNs.sessiondata.title = 'Nouvelle session'; |
483 } |
533 } |
484 if (!gomNs.sessiondata.views) { |
534 if (!gomNs.sessiondata.views) { |
485 gomNs.sessiondata.views = []; |
535 gomNs.sessiondata.views = []; |
523 }; |
573 }; |
524 switch(viewtype) { |
574 switch(viewtype) { |
525 case 'filter': |
575 case 'filter': |
526 _content.period = [ gomNs.minYear, gomNs.maxYear ]; |
576 _content.period = [ gomNs.minYear, gomNs.maxYear ]; |
527 _content.tag = []; |
577 _content.tag = []; |
|
578 _content.country = []; |
528 gomNs.sessiondata.view = gomNs.sessiondata.views.length; |
579 gomNs.sessiondata.view = gomNs.sessiondata.views.length; |
529 break; |
580 break; |
530 case 'list': |
581 case 'list': |
531 _content.list = []; |
582 _content.list = []; |
532 break; |
583 break; |
533 } |
584 } |
534 gomNs.sessiondata.views.push(_content); |
585 gomNs.sessiondata.views.push(_content); |
535 debouncedSaveChanges(); |
586 debouncedSaveChanges(); |
536 } |
587 } |
537 |
588 |
|
589 function animLoad() { |
|
590 var _d = $("#lightboxbg"), |
|
591 _w = _d.width(), |
|
592 _h = _d.height(), |
|
593 _r = .33*Math.min(_w,_h), |
|
594 _count = 24, |
|
595 _html = '', |
|
596 _f = 2* Math.PI / _count; |
|
597 _d.empty().show(); |
|
598 for (var _i = 0; _i < _count; _i++) { |
|
599 var _x = Math.floor(Math.sin(_i * _f)*_r + _w/2), |
|
600 _y = Math.floor(-Math.cos(_i * _f)*_r + _h/2), |
|
601 _el = document.createElement('div'); |
|
602 _d.append(_el); |
|
603 $(_el).css({ |
|
604 "position": "absolute", |
|
605 "left": _x + "px", |
|
606 "top": _y + "px", |
|
607 "width": "30px", |
|
608 "height": "30px", |
|
609 "background": "#ffffff", |
|
610 "border-radius": "15px", |
|
611 "display": "none" |
|
612 }).delay(200*_i).fadeIn(400).delay(600 + 200* _i).fadeOut(); |
|
613 } |
|
614 } |
|
615 |
|
616 function animStop() { |
|
617 $("#lightboxbg").empty().fadeOut(); |
|
618 } |
|
619 |
538 $(document).ready(function() { |
620 $(document).ready(function() { |
539 gomNs.map = new google.maps.Map(document.getElementById("map"), |
621 switch(gomNs.mappingLibrary) { |
540 { |
622 case 'gmaps': |
541 center: new google.maps.LatLng(30, 0), |
623 gomNs.map = new google.maps.Map(document.getElementById("map"), |
542 zoom: 1, |
624 { |
543 mapTypeId: google.maps.MapTypeId.SATELLITE |
625 center: new google.maps.LatLng(30, 0), |
544 }); |
626 zoom: 1, |
545 $.getJSON(gomNs.urls['countries'], showCountries); |
627 mapTypeId: google.maps.MapTypeId.SATELLITE |
|
628 }); |
|
629 $.getJSON(gomNs.urls['countries'], showCountriesGmap); |
|
630 break; |
|
631 case 'leaflet': |
|
632 gomNs.map = new L.Map('map', { |
|
633 center: new L.LatLng(30, 0), |
|
634 zoom: 1 |
|
635 }); |
|
636 gomNs.map.addLayer(new L.TileLayer("http://s3.amazonaws.com/com.modestmaps.bluemarble/{z}-r{y}-c{x}.jpg", {maxZoom: 9})); |
|
637 $.getJSON(gomNs.urls['countries'], showCountriesLeaflet); |
|
638 break; |
|
639 } |
546 var _html = gomNs.displayedDates.map(function(_v) { |
640 var _html = gomNs.displayedDates.map(function(_v) { |
547 return '<li style="left: ' |
641 return '<li style="left: ' |
548 + parseInt(yearToPx(_v)) |
642 + parseInt(yearToPx(_v)) |
549 + 'px"><div class="datelabel">' |
643 + 'px"><div class="datelabel">' |
550 + _v |
644 + _v |
608 $(this).html(_el); |
702 $(this).html(_el); |
609 _el.focus(); |
703 _el.focus(); |
610 _el.select(); |
704 _el.select(); |
611 } |
705 } |
612 }); |
706 }); |
613 $("#titrevue").change(function() { |
707 $("#titrevue").keyup(function() { |
614 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
708 var _curView = gomNs.sessiondata.views[gomNs.sessiondata.view]; |
615 _curView.name = $(this).val(); |
709 _curView.name = $(this).val(); |
616 $("#view_" + gomNs.sessiondata.view + " a").html(_.escape(_curView.name)) |
710 $("#view_" + gomNs.sessiondata.view + " a").html(_.escape(_curView.name)) |
|
711 $("#bloc_gestvue h2").html('Gérer la vue "' + _.escape(_curView.name) + '"'); |
617 debouncedSaveChanges(); |
712 debouncedSaveChanges(); |
618 }); |
713 }); |
619 $("#notes").click(function() { |
714 $("#notes").click(function() { |
620 if (gomNs.write_allowed) { |
715 if (gomNs.write_allowed) { |
621 if (this.children[0].tagName == 'UL') { |
716 if (this.children[0].tagName == 'UL') { |