-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
119 lines (98 loc) · 2.82 KB
/
app.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
var App = (function(window, document, d3) {
var selctedDistrict = 0,
disrticts = null;
d3.json('data/districts.json', function(error, districtsData) {
districts = districtsData;
});
function selectNewDistrict(id) {
console.log({ type: 'selectNewDistrict', id: id, context: this });
if (id !== 0) {
$('#detailCollapse').collapse('show');
selctedDistrict = id;
Text.loadDistrict(id);
Chart.loadDistrict(id);
Hexmap.loadDistrict(id);
setNavBar();
var target = $('#detailCollapse');
if (target.length) {
event.preventDefault();
$('html, body').animate(
{
scrollTop: target.offset().top
},
1050
); // 500 (0.5sek) legt Geschwindkeit fest
}
} else {
$('#detailCollapse').collapse('hide');
selctedDistrict = 0;
}
}
function setNavBar() {
var index,
previousButton,
nextButton,
previousDistrict = 0,
nextDistrict = 1;
if (
selctedDistrict === 0 ||
districts === null ||
districts === undefined
) {
return;
}
index = districts.findIndex(function(district) {
return district.id === selctedDistrict;
});
if (index === 0) {
previousDistrict = 0;
nextDistrict = 1;
} else if (index === 24) {
previousDistrict = 23;
nextDistrict = 24;
} else {
previousDistrict = index - 1;
nextDistrict = index + 1;
}
previousButton = $('#previousbutton');
nextButton = $('#nextbutton');
previousButton.val(districts[previousDistrict].id);
previousButton.html(
'<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span> ' +
districts[previousDistrict].name
);
nextButton.val(districts[nextDistrict].id);
nextButton.html(
districts[nextDistrict].name +
' <span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span>'
);
}
function clickedNextDistrict(e) {
console.log({ type: 'clickedPreviousDistrict', event: e, context: this });
var id = +e.currentTarget.value;
selectNewDistrict(id);
}
function clickedUp(e) {
console.log({ type: 'clickedUp', event: e, context: this });
var target = $('#top');
if (target.length) {
event.preventDefault();
$('html, body').animate(
{
scrollTop: target.offset().top
},
1050
); // 500 (0.5sek) legt Geschwindkeit fest
}
}
$(document).ready(function() {
window.addEventListener('resize', Chart.render);
window.addEventListener('resize', Mucmap.render);
$('#previousbutton').click(clickedNextDistrict);
$('#nextbutton').click(clickedNextDistrict);
$('#upbutton').click(clickedUp);
});
return {
selectNewDistrict: selectNewDistrict
};
})(window, document, d3);