-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
62 lines (51 loc) · 1.75 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
$(document).ready(function () {
//define my variables for today's date and the time right now
let currentDay = moment().format("LLLL");
let currentTime = moment().hour();
//update elements with localStorage values
for (key = 0; key < localStorage.length; key++) {
timeID = localStorage.key(key);
timeValue = localStorage.getItem(timeID);
$("#" + timeID).val(timeValue);
}
//display today's date in the currentDate id
$("#currentDay").append(currentDay);
$("input").each(function () {
var item = parseInt($(this).attr("time"));
console.log(item);
if (item < currentTime) {
$(this).addClass("past");
}
if (item > currentTime) {
$(this).addClass("present");
}
if (item === currentTime) {
$(this).addClass("future");
}
});
function makeTimeblocks(hour, existingTodo = "") {
//Timeblocks
var currentHour = new Date().getHours();
var presentPastOrFuture = "future";
if (currentHour > hour) presentPastOrFuture = "past";
if (currentHour === hour) presentPastOrFuture = "present";
var saveNotes = localStorage.getItem(`hour${hour}`) || ""
$(".container").append(
$(`
<div class="row time-block">
<div class="hour col-1">${hour}:00</div>
<textarea name="" placeholder="Write your notes here"cols="30" rows="3" class="description col-9 ${presentPastOrFuture}">${saveNotes}</textarea>
<div id="hour${hour}" class=" saveBtn col-2"> Save 💾</div>
</div>`)
);
}
for (var i = 9; i < 19; i++) {
makeTimeblocks(i);
}
$(".saveBtn").on("click", function () {
inputID = $(this).attr("id");
inputEl = $(this).parent().children()[1].value;
console.log(inputEl);
localStorage.setItem(inputID, inputEl);
});
});