-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
85 lines (70 loc) · 2.15 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
$(document).ready(function () {
console.log("ready!");
var now = moment().format("dddd, MMMM Do, YYYY");
var time = moment().format("HH");
console.log(time);
$("#currentDay").append(now);
var clearButton = $('<button type="button" class="btn btn-info""></button');
clearButton.text("Clear schedule");
$("#clearBtn").append(clearButton);
clearButton.click(function () {
localStorage.clear()
clearSchedule();
});
var events = ["", "", "", "", "", "", "", ""];
var container = $(".container");
//pull events from local storage
if (localStorage.getItem("events")) {
events = JSON.parse(localStorage.getItem("events"));
}
for (var i = 0; i < 8; i++) {
var style
if (time == i + 9) {
style = "present";
} else if (time < i + 9) {
style = "future";
} else {
style = "past";
}
var rowDiv = $('<div class="row hour"/>');
var col1 = $('<div class="col-2 time-block"></div>');
col1.text(convertTime(i + 9));
var col2 = $('<div class="col-8"></div>');
var textarea = $('<textarea class="form-control textarea" aria-label="With textarea"></textarea>');
textarea.attr("id", i + "_textarea");
textarea.val(events[i]);
// textarea.click(function(e) { e.target.value = ''; }).
textarea.addClass(style);
col2.append(textarea);
var col3 = $('<div class="col-2"></div>');
var saveButton = $('<button type="button" class="saveBtn"></button');
saveButton.text("Save");
saveButton.attr("id", i);
saveButton.click(function (event) {
save(event);
});
col3.append(saveButton);
container.append(rowDiv);
rowDiv.append(col1, col2, col3);
}
function save(event) {
var id = event.target.id;
var text = $("#" + id + "_textarea").val();
events[id] = text;
console.log(events);
localStorage.setItem("events", JSON.stringify(events));
}
function convertTime(hour) {
if (hour > 12) {
var milHour = hour - 12;
return milHour + "pm";
} else {
return hour + "am";
}
}
function clearSchedule(){
for (var i = 0; i < 8; i++){
$("#" + i + "_textarea").val(' ');
}
}
});