-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
113 lines (86 loc) · 2.69 KB
/
script.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
$(document).ready(function() {
// variables.
var date = moment().format('MMMM Do, YYYY');
var hour = moment().format('hh a');
var currentTime = moment().format('hh' + ':' + 'mm a');
var timeOfDay = moment().format('k');
var timeOfNight = moment().format('a');
var minuteOfHour = moment().format('m');
var timeTilNextHour = 60 - minuteOfHour;
var apptsArr = [{
time: "9",
msg: ""
},{
time: "10",
msg: ""
},{
time: "11",
msg: ""
},{
time: "12",
msg: ""
},{
time: "13",
msg: ""
},{
time: "14",
msg: ""
},{
time: "15",
msg: ""
},{
time: "16",
msg: ""
},{
time: "17",
msg: ""
}];
// display current date and time in header.
$("#currentDay").text(date).append($('<div>').text(currentTime));
// Update colors to show which blocks are past, present, and future.
updateColors = () => {
timeTilNextHour = timeTilNextHour * 60 * 1000;
$(".description").each(function() {
if((parseInt($(this).attr('data-time')) ) < timeOfDay) {
$(this).addClass("past");
};
if((parseInt($(this).attr('data-time')) ) == timeOfDay) {
$(this).addClass("present");
};
if((parseInt($(this).attr('data-time')) ) > timeOfDay) {
$(this).addClass("future");
};
});
setTimeout(updateColors, 60 * 60 * 1000);
}
// Check time to update colors every hour.
setTimeout(updateColors, timeTilNextHour);
// Render key/value to message text space.
renderMsg = () => {
for (var i = 0;i < apptsArr.length; i++){
$(`td[data-time="${apptsArr[i].time}"]`).children("textarea").val(apptsArr[i].msg);
}
}
// Get stored key/value pair from local storage and update array.
grabAppts = () => {
var storedAppts = JSON.parse(localStorage.getItem('Appointments'));
if (storedAppts) {
apptsArr = storedAppts;
}
renderMsg();
}
// Save text to local storage on click event.
$(".saveBtn").on('click', function(event) {
event.preventDefault();
var textVal = $(this).prev().children("textarea").val();
var textTime = $(this).prev().attr("data-time");
for (var i = 0;i < apptsArr.length; i++){
if (apptsArr[i].time === textTime){
apptsArr[i].msg = textVal;
}
}
localStorage.setItem('Appointments', JSON.stringify(apptsArr));
renderMsg();
})
grabAppts();
});