-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
executable file
·376 lines (342 loc) · 12.5 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
function showList(id, extraAction)
{
switchStyle = $('#p'+id).css('display');
if(switchStyle == 'none')
{
$('#p'+id).show();
if(extraAction) extraAction();
}else{
$('#p'+id).hide();
if(extraAction) extraAction();
}
$('#p'+id).toggle('hack');
$(id).toggle('expandedMenu');
}
function getSidebar(id){
$('#mapSide').empty();
var id1 = (id*1)-1;
var id2 = (id*1)+1;
id1 = id1+'';
id2 = id2+'';
//clear the sidebar
$.getJSON('/DHDSP/maps/gisx/javascripts/maps.json?314786', function(text) {
// var text = data.responseText;
var k = text.maps.length;
var counter = 1;
if(id1=='0'){
counter = 2;
}
var category= new Array();
for(l=0;l<k;l++)
{
var mapId = text.maps[l].id;
if(mapId ==id1 || mapId ==id2)
{
//if optional thumbnail is present, show it in the map index instead of full image
var src = text.maps[l].src;
if(text.maps[l].thumbnail!==undefined)
{
src = "/DHDSP/maps/gisx/"+text.maps[l].thumbnail;
}
if(counter == 1){
$('#mapSide').append('<li id="'+text.maps[l].title+'"><a id="'+text.maps[l].title+'a" href="'+text.maps[l].page+'">Previous Map<br/><img width="70px" src="'+src+'" /></a></li>');
counter=counter+1;
}else if(counter == 2){
$('#mapSide').append('<li id="'+text.maps[l].title+'"><a id="'+text.maps[l].title+'a" href="'+text.maps[l].page+'">Next Map<br/><img width="70px" src="'+src+'" /></a></li>');
counter=1;
}
}
}
});
}
function switchView(showId, hideId)
{
$('#'+hideId).hide();
$('#'+showId).show();
$('#switchOption').replace("<a id=\"switchOption\" onclick=\"switchView('"+hideId+"', '"+showId+"');\">Options</a>");
}
function sideHighlight(mapId, category){
var cat = category.split(",");
var anchor = mapId +'a';
$('#'+anchor).attr('title','');
for(i=0;i<cat.length;i++){
if($(cat[i]).hasClass('selected')==false){
$(cat[i]).toggle('highlight');
}
}
}
function sideNormal(category){
var cat = category.split(",");
for(i=0;i<cat.length;i++){
if($(cat[i]).hasClass('selected')==false){
$(cat[i]).toggle('highlight');
}
}
}
function removeSelected(){
var highlight = [];
highlight = $('li.selected');
var a = highlight.length;
if(a>0){
for(b=0;b<a;b++){
$('#'+highlight[b]).removeClass('selected');
}
}
}
var mapList = [];
var currentSort = "Newest";
var currentCategory = {};
var startAtMap = 0;
if(window.location.hash.indexOf("#p")===0) {
startAtMap = parseInt(window.location.hash.substr(2))*9;
}
function loadRandomMaps() {
$.getJSON('/DHDSP/maps/gisx/javascripts/maps.json?314786', function(data) {
processRandomMaps(data.maps);
});
}
function processRandomMaps(maps) {
var map1, map2;
if(maps.length<2) return;
map1 = Math.floor(Math.random()*maps.length);
do {
map2 = Math.floor(Math.random()*maps.length);
} while(map1===map2);
updateMapTitle(".featuredMapName1", maps[map1].id, maps[map1].title);
updateMapImage(".featuredMapImage1", maps[map1].id, maps[map1].src);
updateMapTitle(".featuredMapName2", maps[map2].id, maps[map2].title);
updateMapImage(".featuredMapImage2", maps[map2].id, maps[map2].src);
function updateMapTitle(container, id, title) {
var text = "<a href='/DHDSP/maps/gisx/mapgallery/maps/detail/index.html?"+id+"#"+id+"'>"+title+"</a>";
text = "<div class='threeLineAdjust'>"+text+"</div>";
$(container).each(function(div) { div.html(text) });
}
function updateMapImage(container, id, image) {
var text = "<img src='/DHDSP/maps/gisx/mapgallery/"+image+"' width='175' style='max-height:175px' />";
text = "<a href='/DHDSP/maps/gisx/mapgallery/maps/detail/index.html?"+id+"#"+id+"'>"+text+"</a>";
$(container).each(function(div) { div.html(text) });
}
}
function loadMapData(callback) {
$.ajax( {
dataType: "json",
url:'/DHDSP/maps/gisx/javascripts/maps.json',
success:function(data) {
callback(data.maps);
},
error:function(xhr,err){
console.log("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
console.log("responseText: "+xhr.responseText);
}
});
}
function loadMapGallery() {
$.ajax( {
dataType: "json",
url:'/DHDSP/maps/gisx/javascripts/maps.json',
success:function(data) {
mapList = data.maps;
setupCategoryControls(data.categories);
refreshMapGallery();
},
error:function(xhr,err){
console.log("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
console.log("responseText: "+xhr.responseText);
}
});
}
var categoryData = {
"Health Topic": ["Heart disease", "Stroke"],
"Impact Area": ["Document burden", "Inform policy"],
"Data Source": ["Vital Statistics", "CDC Wonder", "NCHS Compressed Mortality"],
"Location": ["AR", "CO", "MA", "MI", "MT"]
};
var categoryTitle = {
"Health Topic": "Health Topic",
"Impact Area": "How the Map is Used",
"Data Source": "Type of Data Used",
"Location": "Location"
};
function resetSearchCategories() {
currentCategory = {};
for(var cat in categoryData) currentCategory[cat] = "(all)";
$.cookie("mapFilter", currentCategory);
}
var catUpdate = [];
function setupCategoryControls(categoryChoices) {
text = "";
var catId = 0;
for(var cat in categoryData) {
(function(cat, catId){
catUpdate[catId] = function(value){mapCategory(cat, value);};
text += "<p><b>"+categoryTitle[cat]+"</b><br />";
text += "<select id='catSelect"+catId+"' onchange=\"catUpdate["+catId+"]($('#catSelect"+catId+" >option:selected').text())\">";
text += "<option value='(all)'>(all)</option>";
for(var i=0; i<categoryChoices[cat].length; i++) {
var item = categoryChoices[cat][i];
text += "<option value='"+item+"'"+((item===currentCategory[cat])?" selected":"")+">"+item+"</option>";
}
text += "</select></p>";
})(cat, catId);
catId++;
}
$('#categoryControls').html(text);
}
// produce filteredList from mapList, containing only the maps that match currentCategory
function filteredMapList(mapList) {
var filteredList = [];
for(var i=0; i<mapList.length; i++) {
var map = mapList[i];
var isInCategory, isShown = true;
for(var j2 in currentCategory) {
if(currentCategory[j2]!=="(all)") {
isInCategory = false;
for(var j=0; j<map.categories.length; j++) {
if(currentCategory[j2].toLowerCase()===map.categories[j].toLowerCase()) {
isInCategory = true;
break;
}
}
if(isInCategory===false) {
isShown = false;
break;
}
}
}
if(isShown) {
filteredList.push(map);
}
}
// sort the filteredList according to currentSort
filteredList.sort(function(map1, map2) {
if(currentSort==="Newest") {
return ((map2.dateStamp<map1.dateStamp)? -1 : ((map2.dateStamp>map1.dateStamp)? 1 : 0));
} else if(currentSort==="Oldest") {
return ((map1.dateStamp<map2.dateStamp)? -1 : ((map1.dateStamp>map2.dateStamp)? 1 : 0));
} else if(currentSort==="State (A-Z)") {
var state1 = map1.state.toLowerCase();
var state2 = map2.state.toLowerCase();
return ((state1<state2)? -1 : ((state1>state2)? 1 : 0));
} else {
return 0;
}
});
return filteredList;
}
function refreshMapGallery() {
$('#testUl').empty();
$('#tooltipContainer').empty();
var filteredList = filteredMapList(mapList);
if(startAtMap>=filteredList.length) startAtMap = 0;
refreshMapNav('mapNav1', startAtMap, filteredList.length);
refreshMapNav('mapNav2', startAtMap, filteredList.length);
if(filteredList.length===0) $('#mapNav2').empty();
for(var k=startAtMap; k<startAtMap+9 && k<filteredList.length; k++) {
var map = filteredList[k];
var categoryList = [];
var i = map.categories.length;
//loop to build the category links
for(j=0;j<i;j++) {
categoryList.push(map.categories[j]);
}
var tooltipText = map.title;
//if optional thumbnail is present, show it in the map index instead of full image
var src = map.src;
if(map.thumbnail!==undefined) {
src = map.thumbnail;
}
$('#tooltipContainer').append("<div id='tooltip"+k+"' class='tooltip'>"+tooltipText+"</div>");
$('#testUl').append('<li id="map'+k+'"><a id="'+map.title+'a" class="imageLink" href="maps/detail/index.html?'+map.id+'#'+map.id+'"><img style="max-width:200px; max-height:200px" class="imageReg3" src="'+src+'" /></a></li>');
// new Tooltip("map"+k, "tooltip"+k);
}
}
function refreshSortingLinks() {
$('#mapSorting').html("Sort maps by: ");
$('#mapSorting').append(sortingLink("Newest")+" ");
$('#mapSorting').append(sortingLink("Oldest")+" ");
$('#mapSorting').append(sortingLink("State (A-Z)"));
}
function sortingLink(category) {
if(currentSort===category) {
return '<span class="active">'+category+'</span>';
} else {
return '<a href="#" onClick="sortMapsBy(\''+category+'\'); return false;">'+category+'</a>';
}
}
function sortMapsBy(category) {
currentSort = category;
refreshMapGallery();
}
function refreshMapNav(divId, startIndex, totalMaps) {
var currentPage = Math.floor(startIndex/9)+1;
var totalPages = Math.ceil(totalMaps/9);
var text = "Page "+currentPage+" of "+totalPages;
if(currentPage>1) text += "<a class='left' href='#' onclick='prevMapPage(); return false;'>« Previous page</a>";
else text += "<a class='left' href='#' style='visibility:hidden'> </a>";
if(currentPage<totalPages) text += "<a class='right' href='#' onclick='nextMapPage(); return false;'>Next page »</a>";
else text += "<a class='right' href='#' style='visibility:hidden'> </a>";
if(totalMaps===0) text = "No maps found.";
$(divId).html(text);
}
function prevMapPage() {
startAtMap -= 9;
refreshMapGallery();
}
function nextMapPage() {
startAtMap += 9;
refreshMapGallery();
}
function createLinks(categories)
{
var smallCat = categories.split(",");
var anchors;
for(i=0;i<smallCat.length;i++)
{
if(i==0){
anchors ="<a href='#' onclick=\"cat2('"+smallCat[i]+"');\">"+smallCat[i]+"</a> ";
}else{
anchors = anchors + "| <a href='#' onclick=\"cat2('"+smallCat[i]+"');\">"+smallCat[i]+"</a> ";
}
}
return anchors;
}
function mapCategory(category, value) {
currentCategory[category] = value;
$.cookie("mapFilter", currentCategory);
console.log($.cookie("mapFilter"))
refreshMapGallery();
}
function xmapCategory(category) {
var cat = new Array();
var links;
removeSelected();
$.getJSON('/DHDSP/maps/gisx/javascripts/maps.json?314786', function(text) {
var k = text.maps.length;
$('#testUl').empty();
//clears out the test div
$(category).addClass('selected');
$(category).css({});
for(l=0;l<k;l++) {
cat[l]=[];
var i = text.maps[l].categories.length;
//loop to build the category links
for(j=0;j<i;j++) {
cat[l].push(text.maps[l].categories[j]);
}
for(m=0;m<i;m++) {
if(text.maps[l].categories[m] == category) {
//build the category links under the map image
links = createLinks(''+cat[l]+'');
//store the title in a var so we can send it in a function
var title1 = "<p>"+text.maps[l].title+"</p><a href="+text.maps[l].page+">Learn more about this map:how it was made and how it was used</a>";
//if optional thumbnail is present, show it in the map index instead of full image
var src = text.maps[l].src;
if(text.maps[l].thumbnail!==undefined) {
src = text.maps[l].thumbnail;
}
$('#testUl').append('<li id="'+text.maps[l].title+'" onmouseover="sideHighlight(this.id, \''+cat[l]+'\')" onmouseout="sideNormal(\''+cat[l]+'\')" class="\category'+text.maps[l].category+'\"><a id="'+text.maps[l].title+'a" href="'+text.maps[l].src+'" rel="lightbox[roadtrip]" title="'+title1+'" onclick="getTitle(this.id, \''+title1+'\');"><img class="imageReg3" src="'+src+'" /></a></li>');
}
}
}
});
}