-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyScriptView.js
73 lines (62 loc) · 2.44 KB
/
myScriptView.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
// loads background colours for each of the to-do lists
function loadColours() {
var max = colours.length;
// generate random palette
var randomIndex = Math.floor(Math.random() * (max + 1));
console.log("hex colour palette: " + colours[randomIndex]);
for (let i = 0; i < allLists.length; i++) {
document.getElementById(allLists[i].boxID).style.backgroundColor =
'#' + colours[randomIndex][i];
}
}
// Create a "close" button and append it to each list item
function generateCloseButton() {
var myNodelist = document.getElementsByTagName("LI");
for (let i = 0; i < myNodelist.length; i++) {
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
myNodelist[i].appendChild(span);
}
}
// Generate new element with the new task and adds it to the list
function newElementView(dayOfWeekToDoList) {
var inputValue = document.getElementById(dayOfWeekToDoList.inputID).value;
var li = document.createElement("li");
var t = document.createTextNode(inputValue);
var text = document.createElement("div");
text.className = "listText";
text.appendChild(t);
li.appendChild(text);
if (inputValue !== '') {
document.getElementById(dayOfWeekToDoList.name).appendChild(li);
}
document.getElementById(dayOfWeekToDoList.inputID).value = ""; // reset the input text back to blank
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7"); // add the "close" symbol to the end of the task
span.className = "close";
span.appendChild(txt);
li.appendChild(span);
}
// Generate the HTML elements for all the tasks loaded from chrome.storage
function newElementfromStorageView(theUL, inputTask) {
var li = document.createElement("li");
var t = document.createTextNode(inputTask.taskDescription);
var text = document.createElement("div");
text.className = "listText";
text.appendChild(t);
li.appendChild(text);
document.getElementById(theUL).appendChild(li);
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7"); // add close symbol
span.className = "close";
span.appendChild(txt);
li.appendChild(span);
if (inputTask.strikethrough) {
li.classList.toggle('checked');
}
}
function checkIfCloseView(div) {
div.style.display = "none";
}