-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (64 loc) · 2.34 KB
/
script.js
File metadata and controls
72 lines (64 loc) · 2.34 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
$(document).ready(() => {
var displayDate = document.getElementById("currentDay");
// console.log(moment()._locale._calendar.lastDay);
// console.log(document);
// console.log(moment());
// displayDate.innerHTML="Today's date: " + today;
var timeArray = ["9 AM","10 AM","11 AM","12 PM","1 PM","2 PM","3 PM","4 PM","5 PM"];
function resetDate(){
displayDate.innerHTML="Today's date: " + moment().format("dddd, MMMM Do YYYY, h:mm:ss a");
}
setInterval(resetDate, 1000);
var container=$(".container");
function init() {
var tmpOBJ = window.localStorage.getItem("planner")
//not sure if this is needed but it erases the saved data after a day
if (!!tmpOBJ) {
tmpOBJ = JSON.parse(tmpOBJ)
if (tmpOBJ.expires > timeOBJ.expires) {
window.localStorage.removeItem("planner");
}else {
timeOBJ = tmpOBJ;
}
}
for(var i=0;i<9;i++){
container.append(`<section class="row" id="${i}">
<time class="time-block col-md-2 col-sm-2">${timeArray[i]}</time>
<input class="description col-md-8 col-sm-8" Value="${timeOBJ[i.toString()]}"></input>
<button class="saveBtn col-md-2 col-sm-2">click</button>
</section>
`)
}
}
var timeOBJ = {
'0': '',
'1': '',
'2': '',
'3': '',
'4': '',
'5': '',
'6': '',
'7': '',
'8': '',
'9': '',
'expires': (new Date().getTime() + 86400000)
}
//use var if you need to stick with ecma 5
//ecma 6 uses let and const.
$(document).on('click','.saveBtn',function(){
console.log(this)
var parentEl = $(this).parent(),
textBEl = parentEl.find("input");
if (!!textBEl.length) {
var text = textBEl[0].value,
parentID = parentEl.attr("id");
if (!!parentID) {
timeOBJ[parentID.toString()] = text
window.localStorage.removeItem("planner");
window.localStorage.setItem('planner', JSON.stringify(timeOBJ));
}
}
//window.localStorage.setItem('planner', JSON.stringify(timeOBJ));
});
window.onload = init();
})