-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
109 lines (79 loc) · 3.1 KB
/
app.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//userInput is targeting the input bar
let userInput = document.getElementById('userInput');
let listID = document.getElementById('list');
const exportToExcel = document.getElementById('export');
function addListItem() {
//initalize the HTML element UL, I initially used .addElementByTagName but it it not work.
//Using querySelector works!
let ul = document.querySelector('ul');
//creating a li element
let li = document.createElement('li');
li.className = "border border-secondary rounded mt-1 p-1";
li.appendChild(document.createTextNode(userInput.value));
//append to the UI
ul.appendChild(li);
//delete
let del = document.createElement('i');
del.className = 'fas fa-trash float-right mt-1';
li.appendChild(del);
del.addEventListener('click', delEvent);
function delEvent() {
li.classList.add('delete');
}
//down
let down = document.createElement('i');
down.className = 'fas fa-arrow-down float-right mr-2 mt-1';
li.appendChild(down);
down.addEventListener('click',downEvent);
function downEvent() {
next = li.nextSibling;
li.parentNode.insertBefore(next, li);
}
//up
let up = document.createElement('i');
up.className = 'fas fa-arrow-up float-right mr-2 mt-1';
li.appendChild(up);
up.addEventListener('click', upEvent);
function upEvent() {
previous = li.previousSibling;
li.parentNode.insertBefore(li, previous);
}
//check
let check = document.createElement('i');
check.className = 'far fa-check-circle float-right mr-2 mt-1';
li.appendChild(check);
check.addEventListener('click', checkEvent);
function checkEvent() {
//removing important element adjustments if any
li.classList.remove('border-danger');
important.classList.remove('danger');
//this portion adds the green border color and green color to the check mark.
li.classList.toggle('border-success');
check.classList.toggle('success');
}
//important
//makes the li border red and makes the icon also red.
let important = document.createElement('i');
important.className = 'fas fa-exclamation float-right mr-2 mt-1';
li.appendChild(important);
important.addEventListener('click', importantEvent);
function importantEvent() {
//removing success element adjustments if any
li.classList.remove('border-success');
check.classList.remove('success');
li.classList.toggle('border-danger');
important.classList.toggle('danger');
}
userInput.value = '';
}
//when this funciton is called, call the function that adds elements.
function enterKeypress(e) {
if(userInput.value.length > 0 && e.which === 13) {
addListItem();
}
}
function exportExcel() {
console.log('help');
}
//when the input bar is selected and a keypress is 'heard' run the function enterKeypress
userInput.addEventListener('keypress', enterKeypress);