-
Notifications
You must be signed in to change notification settings - Fork 0
/
commute.js
58 lines (49 loc) · 1.6 KB
/
commute.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
var commuteModule = (function(){
function cache_display(elm, origin) {
/* Displays result from cache server to DOM */
encoded_origin = encodeURIComponent(origin);
$.ajax({
url: config['cache-server'] + '/' + config['mode'] + '/' + encoded_origin,
dataType: 'json',
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error retrieving data from cache server!");
error_elm(elm);
},
success: function(data, textStatus, jgXHR) {
if (data['status'] == 'success') {
append_time_to_elm(elm, data['time']);
} else {
error_elm(elm);
}
}
});
}
function cache_display_list(elm_list, origins) {
/* Displays result from cache server to DOM */
$.ajax({
url: config['cache-server'] + '/' + config['mode'] + '/' + origins.join('|'),
dataType: 'json',
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error retrieving data from cache server!");
error_elm_list(elm_list);
},
success: function(data, textStatus, jgXHR) {
if (data['status'] == 'success') {
append_time_to_elm_list(elm_list, data['time']);
} else {
error_elm_list(elm_list);
}
}
});
}
return {
display_time : function(elm, origin) {
/* Public function that will append time results to DOM */
cache_display(elm, origin);
},
display_time_list : function(elm_list, origin_list) {
/* Public function that will append time results to DOM */
cache_display_list(elm_list, origin_list);
}
}
})();