-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
176 lines (154 loc) · 3.67 KB
/
Copy pathscript.js
File metadata and controls
176 lines (154 loc) · 3.67 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
var dayArray = [
{
id: "0",
hour: "8",
time: "08",
meridiem: "am",
textevent: ""
},
{
id: "0",
hour: "9",
time: "09",
meridiem: "am",
textevent: ""
},
{
id: "1",
hour: "10",
time: "10",
meridiem: "am",
textevent: ""
},
{
id: "2",
hour: "11",
time: "11",
meridiem: "am",
textevent: ""
},
{
id: "3",
hour: "12",
time: "12",
meridiem: "pm",
textevent: ""
},
{
id: "4",
hour: "1",
time: "13",
meridiem: "pm",
textevent: ""
},
{
id: "5",
hour: "2",
time: "14",
meridiem: "pm",
textevent: ""
},
{
id: "6",
hour: "3",
time: "15",
meridiem: "pm",
textevent: ""
},
{
id: "7",
hour: "4",
time: "16",
meridiem: "pm",
textevent: ""
},
{
id: "8",
hour: "5",
time: "17",
meridiem: "pm",
textevent: ""
},
]
// Displays current date in the header
function titleDate() {
var currentDate = moment().format('dddd, MMMM Do');
$("#currentDay").text(currentDate);
}
// Loads current date in the header
titleDate();
// Creates and append the visual aspects of the planner
dayArray.forEach(function(hourDiv) {
// Time block rows
var timeRow =
$("<form>").attr({
"class": "row"
});
$(".container").append(timeRow);
// Time spots
var hourSpot =
$("<div>")
.text(`${hourDiv.hour}${hourDiv.meridiem}`)
.attr({
"class": "col-md-1 hour"
});
// Text area where the user is going to add data
var textDiv = $("<div>")
.attr({
"class": "col-md-8 description"
});
var textArea = $("<textarea>");
textDiv.append(textArea);
textArea.attr("id", hourDiv.id);
if (hourDiv.time < moment().format("HH")) {
textArea.attr ({
"class": "past",
})
} else if (hourDiv.time === moment().format("HH")) {
textArea.attr({
"class": "present"
})
} else if (hourDiv.time > moment().format("HH")) {
textArea.attr({
"class": "future"
})
}
// Save button
var saveBtn = $("<i class='far fa-save fa-lg'></i>")
var saveEvent = $("<button>")
.attr({
"class": "col-md-1 saveBtn"
});
saveEvent.append(saveBtn);
timeRow.append(hourSpot, textDiv, saveEvent);
})
// Saves the data to be stored in the local storage
$(".saveBtn").on("click", function(event) {
event.preventDefault();
var saveIndex = $(this).siblings(".description").children().css(".present", ".past", "future").attr("id");
dayArray[saveIndex].textevent = $(this).siblings(".description").children().css(".present", ".past", "future").val();
console.log(dayArray[saveIndex].textevent);
saveEvents();
displayEvents();
})
// Local storage
function saveEvents() {
localStorage.setItem("dayArray", JSON.stringify(dayArray));
}
// Sets the data entered, links its value to its id
function displayEvents() {
dayArray.forEach(function (eventDisplay) {
$(`#${eventDisplay.id}`).val(eventDisplay.textevent);
})
}
// Sets any data saved in the local storage to be displayed
function initialPage() {
var recordedDay = JSON.parse(localStorage.getItem("dayArray"));
if (recordedDay) {
dayArray = recordedDay;
}
saveEvents();
displayEvents();
}
// Loads existing local storage data
initialPage();