-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
71 lines (59 loc) · 1.8 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
function convertDataToArray(data){
return data.split(',');
}
function saveDayProgress(day, state){
var allDays = convertDataToArray(localStorage.days)
if(state === 'f' || state === 't'){
allDays[day - 1] = state;
}
localStorage.days = allDays.join(',');
}
var days = new Array();
function reloadIndex(){
days = convertDataToArray(localStorage.days);
for(var i = 1; i <= 27; i++){
if(days[i - 1] === 't'){
$("." + i + "-day-completed-img").html("<img src='done.png' class='complete' />");
} else if(days[i - 1] === 'f'){
$("." + i + "-day-completed-img").html("");
}
}
}
if(localStorage.length > 0){
days = convertDataToArray(localStorage.days);
console.log(localStorage.days);
} else {
localStorage.days = "f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f,f"
}
function dayStatus(day){
return days[day - 1];
}
$('#home').live( 'pageinit', function(event){
reloadIndex();
});
$( '#day' ).live( 'pageinit',function(event){
console.log(dayStatus($('#completed').data('day')));
if(dayStatus($('#completed').data('day')) === 't'){
$("#completed").prop("checked", true).checkboxradio("refresh");
} else if (dayStatus($('#completed').data('day')) === 'f') {
$('#completed').prop('checked', false).checkboxradio("refresh");
}
$(".treadmill-display").hide();
$(".street").click(function(){
$(".street-display").show();
$(".treadmill-display").hide();
});
$(".treadmill").click(function(){
$(".treadmill-display").show();
$(".street-display").hide();
});
$("input[type='checkbox']").bind( "change", function(event, ui) {
if($('#completed').is(':checked')){
saveDayProgress($('#completed').data('day'), 't')
reloadIndex();
} else {
saveDayProgress($('#completed').data('day'), 'f')
reloadIndex();
}
});
});