-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
125 lines (115 loc) · 4.49 KB
/
index.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
<html>
<head>
<title>Divvy Suggestions</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name = "format-detection" content = "telephone=no"/>
<script src="js/jquery-2.0.3.min.js"></script>
<script src="js/jquery.mobile-1.3.2.min.js"></script>
<link rel="stylesheet" href="styles/styles.css" />
<link rel="stylesheet" href="styles/jquery.mobile-1.3.2.min.css" />
<script>
// Start the app!
function onBodyLoad() {
init(); // comment me in Xcode
$("#json").hide();
$("#listContainer").hide();
}
function init() {
console.log("init() has been called");
getUrl(url);
//$('#listview').html('');
}
function sortJSON(data, key, way) {
// code from http://stackoverflow.com/a/14949429
return data.sort(function(a, b) {
var x = a[key]; var y = b[key];
if (way === '123' ) { return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }
if (way === '321') { return ((x > y) ? -1 : ((x < y) ? 1 : 0)); }
});
}
//var url = "http://shareaboutsapi2.herokuapp.com/api/v2/divvy/datasets/divvy/places?include_submissions";
var url = "http://divvy.bikechi.com/php/getsuggestions.php?action=getjson";
var total,next,description,support,id,date,station;
var downloaded = 0;
var stationsCounter = 0;
var stations = [];
var stationsSorted;
function getUrl(url) {
console.log("Getting URL: " + url);
$.getJSON(url)
.done( function(data) {
console.log("Looks like we got the URL just fine");
total = data.length;
console.log(data);
//$("#total").html(total + " stations suggested.");
//next = data.metadata.next;
$.each(data.data, function(i, feature) {
id = feature.id;
lat = feature.lat;
lng = feature.lng;
if(feature.s) {
support = feature.s;
}
if(support > 1) {
//support++;
description = "(" + support + ") " + feature.d;
} else {
description = "(1) " + feature.d;
support = 0;
}
date = feature.t;
// build the station and add it to the stations array
station = {id:id,support:support,description:feature.d,date:date,lat:lat,lng:lng}
stations.push(station);
support = "";
stationsCounter++;
$("#total").html(stationsCounter);
}); // end each
// sort the stations
//popularStationsSorted = popularStations.support.sort(function(a,b){return a-b});
stationsSorted = sortJSON(stations,'support', '321'); // 123 or 321
//console.log(stationsSorted);
// do these things when all lists have finished downloading
if(stationsCounter == total) {
$("#progress").html("Finished downloading list!");
finished();
return false;
} else {
$("#progress").html("Finished downloading suggestion lists!");
finished(data);
}
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log("Looks like something failed: text status: " + textStatus + "; error thrown: " + errorThrown);
console.log(jqXHR);
});
}
function finished(data) {
var json = JSON.stringify(data);
$("#json").val(json);
$("#json").show();
$.each(stationsSorted, function(i, feature) {
$('#listview').append("<li><a href='http://suggest.divvybikes.com/place/" + feature.id + "' target='_blank'> (" + feature.support + ") " + feature.description + "</a></li>");
});
$("#listview").listview ("refresh");
$("#listContainer").show();
}
</script>
</head>
<body onload="onBodyLoad()">
<div data-role="page" id="page">
<div data-role="content" id="content" class="small">
<h1>Where are people suggesting Divvy stations?</h1>
<p>Divvy and the Chicago Department of Transportation are <a href="http://chi.streetsblog.org/2013/12/10/new-site-helps-you-suggest-locations-for-up-to-250-more-divvy-stations/" target="_blank">soliciting input</a> for the next 175 Divvy bike-share station locations. Created by <a href="http://twitter.com/stevevance" target="_blank">Steven Vance</a>. Fork this on <a href="https://github.com/stevevance/Divvy-Suggestions/tree/master" target="_blank">GitHub</a>.</p>
<h2 id="progress">Loading...<span id="iteration"></span></h2>
<textarea id="json"></textarea>
<br />
<div id="listContainer">
<p><span id="total">0</span> total stations suggested, sorted by number of supporters.</p>
<ul data-filter-placeholder="Search suggested Divvy locations..." data-role="listview" data-inset="false" class="" id="listview" data-filter="true"><li>Most recent suggestions are first</li></ul>
</div>
</div>
</div>
</body>
</html>