-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
226 lines (167 loc) · 6.76 KB
/
index.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/* The vw unit is the relative unit which is 1% of the width of the
viewport and the viewport will stay the size of the browser window.
Although this may differ per different browser capabilities. */
/* This function should fix the background issue where it exceeds 100vw. */
const placeVw = () => {
let vw = document.documentElement.clientWidth / 100;
document.documentElement.style.setProperty('--vw', `${vw}px`);
}
placeVw();
window.addEventListener('resize', placeVw);
//select the tv button element.
//create eventListener to initiate function when tv button is clicked.
document.querySelector("#new-list").addEventListener("click", createList)
//function to create a new list onclick.
function createList() {
//create outer div to contain list.
const newList = document.createElement('div')
newList.classList.add("list-container")
//create div for title
const headingContainer = document.createElement('div')
headingContainer.classList.add("listCategoryContainer")
headingContainer.contentEditable=true
newList.appendChild(headingContainer)
//creating heading h1 and append to title div
const headingTitle = document.createElement('h2')
headingTitle.classList.add("listCategoryTitle")
headingTitle.innerHTML="Update your list title 🎥"
headingContainer.appendChild(headingTitle)
//create inner div for input and button element.
const inputDiv = document.createElement('div')
inputDiv.classList.add("list-input")
newList.appendChild(inputDiv)
//create input element.
const inputTitle = document.createElement('input')
inputTitle.type="text"
inputTitle.placeholder="Add new title."
inputTitle.classList.add("list-input")
inputDiv.appendChild(inputTitle)
//create button to submit input.
const inputBtn = document.createElement('button')
inputBtn.id="add-title"
inputBtn.innerHTML=`<i class="fas fa-plus"></i>`
inputBtn.ariaLabel = `Add movie title`
inputBtn.classList.add("list-input")
inputDiv.appendChild(inputBtn)
//append the new list to tv button.
const element = document.querySelector('.main')
element.appendChild(newList)
// ********************* adding a title for movie in the list *************************** //
// adding an event listener to this created inputBtn that is inside the beginning binge list box
inputBtn.addEventListener('click', (e) => {
//get the movie title from the input.
// once the user enters a new movie name, then make a new
if(inputTitle.value !== "" && inputTitle.value !== new RegExp("/^\s+$/")) {
e.preventDefault();
// create a div with a class of movie-name
const bingeWorthy = document.createElement('div');
bingeWorthy.classList.add('movie-name');
//console.log(bingeWorthy);
// create an input with class new-film
// const newFeatureFilm = document.createElement('input');
// newFeatureFilm.classList.add('new-film');
// newFeatureFilm.value = inputTitle.value;
// newFeatureFilm.setAttribute('readonly', 'readonly');
// Add movie title to the list
const movieTitle = document.createElement('p');
movieTitle.innerHTML = inputTitle.value;
movieTitle.classList.add('movie-title')
bingeWorthy.appendChild(movieTitle);
//console.log(newFeatureFilm);
//create done button
//const doneButton = document.createElement('button');
//doneButton.innerHTML = `<i class="fas fa-check"></i>`;
//doneButton.style.color = '#0ed600'
//doneButton.style.borderColor = '#0ed600'
const doneButton = document.createElement('input');
doneButton.type = 'checkbox'
doneButton.classList.add('checkbox')
doneButton.ariaLabel = `Check movie title as watched`
doneButton.addEventListener('click', markDone)
bingeWorthy.appendChild(doneButton);
//create delete button
const deleteButton = document.createElement('button');
deleteButton.className = 'delete'
deleteButton.innerHTML = `<i class="fas fa-trash"></i>`;
deleteButton.style.color = '#ed0014'
deleteButton.style.borderColor = '#ed0014'
deleteButton.ariaLabel = `Remove movie title from list`
deleteButton.addEventListener('click', deleteItem)
bingeWorthy.appendChild(deleteButton);
//********* edit button currently still in progress ******************/
// **************** Currently still needs work ******************* //
// really kool crayon emoji button for the edit
let editEmoji = String.fromCodePoint(0x1f58d);
let isEditing = false;
// create a div with class controls
const controls = document.createElement('div');
controls.classList.add('controls');
// create edit button with class edit-btn
const editBtn = document.createElement('button');
editBtn.innerHTML = editEmoji;
editBtn.ariaLabel = "Edit";
bingeWorthy.appendChild(editBtn);
//console.log(editBtn)
// event listener for edit button
editBtn.addEventListener('click', () => {
// enter edit area
if (!isEditing) {
isEditing = true;
//allow the input editing to take place
movieTitle.removeAttribute('readonly');
//focus on input in edit mode if a user is not sure about the film
bingeWorthy.focus();
} else {
//keep the movie title stored
isEditing = false;
//to allow the reset button to edit emoji
editBtn.innerHTML = editEmoji;
// reset aria-label to 'Edit'
editBtn.setAttribute('aria-label', 'Edit');
// make new input value readonly
movieTitle.setAttribute('readonly', 'readonly');
}
})
//append the edit button to control
controls.appendChild(bingeWorthy, editBtn)
bingeWorthy.appendChild(editBtn, movieTitle)
// append the bingeWorthy and newFeatureFilm to the inputDiv
//inputDiv.append(bingeWorthy, deleteButton, controls, editBtn)
inputDiv.append(bingeWorthy)
// clearing the input title field
//console.log(inputDiv.value = "");
inputTitle.value = ``;
}
})
}
// ************************ Code Creating Static once clicked and on a setTimeout *********************** //
//selecting the image
let mainElement = document.querySelector("img");
// picking up the p tag
let list = document.querySelector("p")
// two event handlers which will handle the click on the shaking tele.
mainElement.addEventListener("click", clickStatic)
list.addEventListener("click", clickStatic)
function clickStatic() {
// console.log(setTimeout(myTimeout))
mainElement.style.display="none";
list.style.display="none";
let errorLostScreen = document.querySelector(".tv")
// console.log(errorLostScreen)
errorLostScreen.classList.remove("no-signal");
errorLostScreen.classList.add("tv-static")
setTimeout(function() {
errorLostScreen.classList.remove("tv-static");
mainElement.style.display = "block";
list.style.display = "block";
}, 1500);
// console.log('yo,yo,yo')
return errorLostScreen
};
//console.log(clickStatic(errorLostScreen));
function deleteItem(e) {
this.parentNode.remove() // removes div with button and movie name!
}
function markDone(e) {
e.path[1].childNodes[0].classList.toggle('strikethrough');
}