-
Notifications
You must be signed in to change notification settings - Fork 6
[뉴스 뷰어 페이지 2단계] 이수진 미션 제출합니다. #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sujin0707
wants to merge
9
commits into
LIN-KHU:sujin0707
Choose a base branch
from
sujin0707:sujin0707
base: sujin0707
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ff92039
모달창 버튼 스타일 추가
sujin0707 3c59dbb
의견 남기기 모달창 기능 구현
sujin0707 34a39a1
오타 수정
sujin0707 c69c9d1
edit 버튼 기능 수정
sujin0707 4c02086
오타 수정
sujin0707 f561487
모달 기능 별도의 파일로 분리
sujin0707 c92f379
기능에 따라 함수 총 2개로 분리
sujin0707 be78885
모달창 스타일 부분 추가
sujin0707 3b7d32f
preventDefault 메소드 추가
sujin0707 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| export function openModal(article) { | ||
| const modal = document.getElementById("modal"); | ||
| const closeModal = document.querySelector(".close-modal"); | ||
|
|
||
| modal.classList.add("open"); | ||
|
|
||
| closeModal.addEventListener("click", () => { | ||
| modal.classList.remove("open"); | ||
| }); | ||
|
|
||
| window.addEventListener("click", (event) => { | ||
| if (event.target === modal) { | ||
| modal.classList.remove("open"); | ||
| } | ||
| }); | ||
|
|
||
| const storedOpinion = localStorage.getItem(article); | ||
| DisplayOpinion(article, storedOpinion); | ||
| } | ||
|
|
||
| function DisplayOpinion(article, storedOpinion) { | ||
| const opinionForm = document.getElementById("opinion-form"); | ||
| const opinionTitle = document.getElementById("opinion-title"); | ||
| const opinionContent = document.getElementById("opinion-content"); | ||
|
|
||
| if (storedOpinion) { | ||
| const parseOpinion = JSON.parse(storedOpinion); | ||
|
|
||
| const SavedOpinion = document.getElementById("modal-header"); | ||
| SavedOpinion.innerHTML = ` | ||
| <h3>${parseOpinion.title}</h3> | ||
| <p>${parseOpinion.content}</p> | ||
| `; | ||
|
|
||
| opinionTitle.value = parseOpinion.title; | ||
| opinionContent.value = parseOpinion.content; | ||
|
|
||
| const saveButton = document.getElementById("save-opinion"); | ||
| let editButton = document.getElementById("edit-opinion"); | ||
| let deleteButton = document.getElementById("delete-opinion"); | ||
|
|
||
| if(saveButton) { | ||
| saveButton.remove(); | ||
| } | ||
|
|
||
| if (!editButton) { | ||
| editButton = document.createElement("button"); | ||
| editButton.textContent = "edit"; | ||
| editButton.id = "edit-opinion"; | ||
|
|
||
| editButton.addEventListener("click", () => { | ||
| event.preventDefault(); | ||
|
|
||
| const editedTitle = opinionTitle.value; | ||
| const editedContent = opinionContent.value; | ||
|
|
||
| if (editedTitle !== "" && editedContent !== "") { | ||
| localStorage.removeItem(article); | ||
|
|
||
| const opinion = { title:editedTitle, content:editedContent }; | ||
| localStorage.setItem(article, JSON.stringify(opinion)); | ||
| modal.classList.remove("open"); | ||
| } else { | ||
| alert("제목과 내용을 모두 입력하세요."); | ||
| } | ||
| }); | ||
|
|
||
| opinionForm.appendChild(editButton); | ||
| } | ||
|
|
||
| if (!deleteButton) { | ||
| deleteButton = document.createElement("button"); | ||
| deleteButton.textContent = "delete"; | ||
| deleteButton.id = "delete-opinion"; | ||
|
|
||
| deleteButton.addEventListener("click", () => { | ||
| localStorage.removeItem(article); | ||
| modal.classList.remove("open"); | ||
| }); | ||
|
|
||
| opinionForm.appendChild(deleteButton); | ||
| } | ||
| } else { | ||
| opinionTitle.value = ""; | ||
| opinionContent.value = ""; | ||
|
|
||
| const saveButton = document.getElementById("save-opinion"); | ||
| const editButton = document.getElementById("edit-opinion"); | ||
| const deleteButton = document.getElementById("delete-opinion"); | ||
|
|
||
| saveButton.textContent = "save"; | ||
| saveButton.addEventListener("click", () => { | ||
| const savedTitle = opinionTitle.value; | ||
| const savedContent = opinionContent.value; | ||
|
|
||
| if (savedTitle !== "" && savedContent !== "") { | ||
| localStorage.removeItem(article); | ||
|
|
||
| const opinion = { title: savedTitle, content: savedContent }; | ||
| localStorage.setItem(article, JSON.stringify(opinion)); | ||
| modal.classList.remove("open"); | ||
| } else { | ||
| alert("제목과 내용을 모두 입력하세요."); | ||
| } | ||
| }); | ||
|
|
||
| if (editButton) { | ||
| editButton.remove(); | ||
| } | ||
|
|
||
| if (deleteButton) { | ||
| deleteButton.remove(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모달 html요소를 직접적으로 html 내에 작성하기 보다는 별도로 js파일을 만들어 작성하는걸 추천드립니다.
html내에는
<div id="root-modal">과 같이 진입점만 존재해도 될 것 같아요