-
Notifications
You must be signed in to change notification settings - Fork 1
/
focus.js
95 lines (84 loc) · 3.1 KB
/
focus.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
//localStorage.clear();
var inputDiv = document.getElementById("inputDiv");//form div
var taskDiv = document.getElementById('taskDiv'); //task div to display entered task
var dayTask = document.getElementById("dayTask"); //text input
var task = document.getElementById("task"); //task span
var dayTasks = []; //array to store tasks
var cross = document.getElementById("cross"); //cross icon to cancel/delete the task
var plus = document.getElementById("plus"); //cross icon to cancel/delete the task
plus.style.display = 'none';
inputDiv.style.display = 'none'; //initially hide input div
taskDiv.style.display ='none'; //initially hide task display div
var checkBox = document.getElementById("check");
if(!localStorage['task']){
taskDiv.style.display ='none';
inputDiv.style.display = 'block';
dayTask.addEventListener('keydown', dayFocus);
}
else{
displayTask();
}
function dayFocus(e){
if(dayTask.value.length !== 0){ //dont process if no character is entered
if(e.keyCode == 13){
inputDiv.style.display='none';
dayTasks.push(dayTask.value);
localStorage.setItem('task',dayTasks[dayTasks.length - 1]); //the latest task entered is stored in localStorage
displayTask();
document.getElementById("randomQuotes").style.padding = "7.5vw 0vw 10vw 0vw";
};
}
}
function displayTask(){
task.innerHTML = localStorage.getItem('task');
if(localStorage['textStyle']){
task.style.textDecoration = localStorage.getItem('textStyle');
}
if(localStorage['checkbox']){
checkBox.checked = (localStorage.getItem('checkbox')) == 'true';
testCheck();
}
taskDiv.style.display = 'inline';
checkBox.addEventListener('click', function(){
if(task.style.textDecoration === 'line-through'){
task.style.textDecoration = 'none';
checkBox.checked == false;
localStorage.setItem('checkbox','false');
localStorage.setItem('textStyle','none');
testCheck();
}
else{
task.style.textDecoration = 'line-through';
checkBox.checked == true;
localStorage.setItem('checkbox','true');
localStorage.setItem('textStyle','line-through');
testCheck();
}
});
cross.addEventListener('click', deleteTask);
}
function deleteTask(){
localStorage.removeItem('task');
localStorage.removeItem('checkbox');
localStorage.removeItem('textStyle');
taskDiv.style.display = 'none';
task.style.textDecoration = 'none';
checkBox.checked = false;
testCheck();
dayTask.value = '';
inputDiv.style.display='block';
dayTask.addEventListener('keydown', dayFocus);
document.getElementById("randomQuotes").style.padding = "2vw 0vw 10vw 0vw";
}
function testCheck(){
if(checkBox.checked){
cross.style.display = 'none';
plus.style.display = 'inline';
plus.addEventListener('click', deleteTask);
}
else{
cross.style.display = 'inline';
plus.style.display = 'none';
cross.addEventListener('click', deleteTask);
}
}