Skip to content

Commit 41652fd

Browse files
committed
Update Item
1 parent 4cec339 commit 41652fd

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

TodoList/script.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ const modalBtn = document.getElementById("modal-btn");
55

66
function showAddModal(){
77
modalContainer.classList.remove("hide");
8+
document.body.classList.add("hideScrollBar");
89
modalContainer.classList.add('show-modal');
910
}
1011

1112
function hideAddModal(){
1213
modalContainer.classList.remove('show-modal');
13-
modalContainer.classList.add('hide')
14+
document.body.classList.remove("hideScrollBar");
15+
modalContainer.classList.add('hide');
1416
}
1517

1618
add.addEventListener('click', showAddModal);
@@ -92,7 +94,9 @@ modalBtn.addEventListener('click', (e)=>{
9294
document.querySelector('.modal__form').reset();
9395

9496
if(modalContainer.classList.contains("show-modal")){
97+
9598
modalContainer.classList.remove('show-modal');
99+
document.body.classList.remove("hideScrollBar");
96100
modalContainer.classList.add('hide');
97101
}
98102

@@ -131,6 +135,45 @@ function addItem(id, imgFile, title, description){
131135
`
132136
}
133137

138+
139+
// Script to update item
140+
141+
function updatItem(){
142+
143+
let currentContentElement = null;
144+
145+
document.querySelector(".content").addEventListener('click', (e)=>{
146+
if(e.target.classList.contains('bi-pen')){
147+
148+
currentContentElement = e.target.closest(".content__item");
149+
150+
if(modalContainer.classList.contains("hide")){
151+
152+
modalContainer.classList.remove("hide");
153+
document.body.classList.add("hideScrollBar");
154+
modalContainer.classList.add("show-modal");
155+
156+
document.getElementById("image-preview").src = currentContentElement.querySelector('.item__image img').src;
157+
document.getElementById("title").value = currentContentElement.querySelector(".item__infos h1").textContent;
158+
document.getElementById("description").value = currentContentElement.querySelector(".item__infos p").textContent;
159+
160+
}
161+
}
162+
})
163+
164+
document.getElementById("modal-btn").addEventListener('click', ()=>{
165+
if(currentContentElement){
166+
currentContentElement.querySelector('.item__image img').src = document.getElementById("image-preview").src;
167+
currentContentElement.querySelector(".item__infos h1").textContent = document.getElementById("title").value;
168+
currentContentElement.querySelector(".item__infos p").textContent = document.getElementById("description").value;
169+
}
170+
})
171+
172+
}
173+
174+
updatItem()
175+
176+
134177
// Script to remove item
135178

136179
document.querySelector(".content").addEventListener("click", (e)=>{

TodoList/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ h1{
4949
body{
5050
background: var(--bs-gray-100);
5151
}
52+
body.hideScrollBar{
53+
overflow: hidden;
54+
}
5255

5356

5457
/* NAV BAR */

0 commit comments

Comments
 (0)