-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
76 lines (64 loc) · 2.78 KB
/
main.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
let addToDoButton = document.getElementById("addToDo"); //this is for the button. id = addToDo.
let toDoContainer = document.getElementById('toDoContainer');
let inputField = document.getElementById('inputField');
//create function here so I do not have to repeat
const appendToDoContainer = function (item) {
item.classList.add("paragraph-styling");//grabs the style in the css file and adds it to this paragraph
toDoContainer.appendChild(item);//we need to append the paragraph to our toDoContainer. puts the paragraph that was created into the div class toDoContainer
inputField.value = "";//empties the input field after each click
item.addEventListener("click", function () {
item.style.textDecoration = "line-through";//when the paragraph word is clicked, a line will cross thru it. indicating the task is complete
})
item.addEventListener("dblclick", () => {
toDoContainer.removeChild(item);
})
};
//<p>
const p = function () {
if(inputField.value) {
let paragraph = document.createElement('p'); //everytime we push this butto a new paragraph will be created with document.createElement('p')
paragraph.classList.add("paragraph-styling");//grabs the style in the css file and adds it to this paragraph
paragraph.innerText = inputField.value;// adds the input field value -what ever you type in the input- to the paragraph
appendToDoContainer(paragraph);
}else {
alert("The field can not be empty ");
};
};
//<ul>
const createList = function () {
if (inputField.value) {
let listView = document.createElement('ul');
let listViewItem=document.createElement('li');
listViewItem.appendChild(document.createTextNode(inputField.value));
listView.appendChild(listViewItem);
appendToDoContainer(listView);
}else {
alert("The field is empty");
};
};
addToDoButton.addEventListener("click", function () {
createList();
// p();
})
//this was originally document.body. but, it was working funny when I I would tab over to the button. I changed it to inputField and now it works better.
inputField.addEventListener('keypress', function (e) { //specifically for the inputfield
if (e.key === "Enter") {
createList();
// p()
}else{
};
})
// function setCaret() {
// var el = document.getElementById("editable")
// var range = document.createRange()
// var sel = window.getSelection()
// range.setStart(el.childNodes[2], 5)
// range.collapse(true)
// sel.removeAllRanges()
// sel.addRange(range)
// }
// <div id="editable" contenteditable="true">
// text text text<br>text text text<br>text text text<br>
// </div>
// <button id="button" onclick="setCaret()">focus</button>
/*it is 206pm */