-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
36 lines (33 loc) · 1.49 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
currentTime =moment().format("H");
var textArea=$(".text-area")
window.setInterval(function () {
$('#currentDay').html(moment().format('ddd MM/DD/YYYY H:mm:ss'))
}, 1000);
//This loop increments through all text areas and checks for entries saved in local storage based on id
for (i=0; i < textArea.length; i++){
var userInput=localStorage.getItem(textArea[i].id);
if (userInput){
textArea[i].textContent = userInput;
}
//Then it compares their id value (9-17) with the current hour to assign the past, present and future classes.
if (parseInt(textArea[i].id) < currentTime){
textArea[i].setAttribute('class','past');
}
else if (parseInt(textArea[i].id) === currentTime){
textArea[i].setAttribute('class','present');
}
else if (parseInt(textArea[i].id) > currentTime) {
textArea[i].setAttribute('class','future')
}
}
//This function sets user entered strings into local storage on a click event.
function saveItem(event) {
//This targets the previous element in relation to the clicked button, which finds the corresponding text-area
var previousElement = $(event.target).prev()
//This saves the value of that text area as a variable and then saves it to local storage using the id value of the element as its key
var savedText = previousElement.val();
localStorage.setItem(previousElement.attr('id'), savedText)
console.log(previousElement.attr('id'))
}
//This click event triggers the saveItem
$('.saveBtn').click(saveItem);