-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (29 loc) · 1.22 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
dayjs.extend(window.dayjs_plugin_advancedFormat);
$(function () {
const now = dayjs();
const today = now.format("dddd, MMMM Do");
$("#currentDay").text(today);
for (let i = 9; i <= 17; i++) {
const hour = i > 12 ? i - 12 + "PM" : i + "AM";
const text = localStorage.getItem(`hour-${i}`) || ""
const timeblock = `
<div id="hour-${i}" class="row time-block ${i < now.hour() ? "past" : i === now.hour() ? "present" : "future"}">
<div class="col-2 col-md-1 hour text-center py-3">${hour}</div>
<textarea class="col-8 col-md-10 description" rows="3">${text}</textarea>
<button class="btn saveBtn col-2 col-md-1" aria-label="save">
<i class="fas fa-save" aria-hidden="true"></i>
</button>
</div>`;
$("#container").append(timeblock);
}
$(".saveBtn").on("click", function () {
const parent = $(this).parent()
const hour = parent.attr("id")
const description = parent.find("textarea").val()
localStorage.setItem(hour, description)
$(`<p id="message"class="text-center">Appointment added to <span class="text-danger">Local Storage</span></p>`).insertAfter("header");
setTimeout(function () {
$("#message").remove();
}, 3000);
});
});