-
Notifications
You must be signed in to change notification settings - Fork 7
/
mobile.html
146 lines (128 loc) · 3.75 KB
/
mobile.html
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
<!DOCTYPE html>
<html>
<head>
<title>Kivabeta</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<style type="text/css">
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript">
var loans = [];
function fragmentLoan(i) {
var loan = loans[i];
return 'href="#detail" onclick="renderLoan(\''+loan.name+'\','+i+');" data-transition="slide"';
}
function renderCountries() {
var loan, country, countries = {}, output = [];
for(loan in loans) {
loan = loans[loan];
if(loan.country in countries)
countries[loan.country]++;
else
countries[loan.country] = 1;
}
for(country in countries)
output.push('<li><a onclick="render(function(){return renderCountry(\''+country+'\');});">'+country+' ('+countries[country]+')</a></li>');
output.sort();
return output.join("");
}
function renderCountry(country) {
var i, loan, output = [];
for(i in loans) {
loan = loans[i];
if(loan.country == country)
output.push('<li><a '+fragmentLoan(i)+'>'+loan.name+' ('+loan.sector+' '+loan.activity+')</a></li>');
}
output.sort();
return output.join("");
}
function renderSectors() {
var loan, sector, sectors = {}, output = [];
for(loan in loans) {
loan = loans[loan];
if(loan.sector in sectors)
sectors[loan.sector]++;
else
sectors[loan.sector] = 1;
}
for(sector in sectors)
output.push('<li><a onclick="render(function(){return renderSector(\''+sector+'\');});">'+sector+' ('+sectors[sector]+')</a></li>');
output.sort();
return output.join("");
}
function renderSector(sector) {
var i, loan, output = [];
for(i in loans) {
loan = loans[i];
if(loan.sector == sector)
output.push('<li><a '+fragmentLoan(i)+'>'+loan.name+' ('+loan.country+', '+loan.activity+')</a></li>');
}
output.sort();
return output.join("");
}
function renderAll() {
var i, loan, output = [];
for(i in loans) {
loan = loans[i];
output.push('<li><a '+fragmentLoan(i)+'>'+loan.name+' ('+loan.country+', '+loan.sector+' '+loan.activity+')</a></li>');
}
output.sort();
return output.join("");
}
function render(filter) {
jQuery("#list").html("<li>filtering...</li>");
jQuery("#list").listview('refresh');
setTimeout(function(){
var list;
if(!loans.length)
list = "<li>(no loans)</li>";
else
list = filter();
jQuery("#list").html(list);
jQuery("#list").listview('refresh'); //its the listview refresh that's so slow for 'all'
});
}
function renderLoan(name,loan) {
loan = loans[loan];
jQuery("#name").html(name);
}
function receiveKBFile(data) {
loans = data.Loans;
jQuery("#by_country").click();
}
jQuery(document).ready(function(){
jQuery("#by_country").click(function(){render(renderCountries);});
jQuery("#by_sector").click(function(){render(renderSectors);});
jQuery("#all").click(function(){render(renderAll);});
});
jQuery.getJSON("jsonloans.json", null, receiveKBFile);
</script>
</head>
<body>
<div id="main" data-role="page">
<div data-role="header">
<h1>Kivabeta</h1>
<div data-role="navbar" data-iconpos="bottom">
<ul>
<li id="by_country"><a class="ui-btn-active" href="#">by country</a></li>
<li id="by_sector"><a href="#" >by sector</a></li>
<li id="all"><a href="#">all</a></li>
</ul>
</div>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true" data-filter="true" id="list">
<li>loading...</li>
</ul>
</div>
</div>
<div id="detail" data-role="page">
<div data-role="content">
<h1 id="name"></h1>
<p>(details of loanee here)</p>
</div>
</div>
</body>
</html>