-
Notifications
You must be signed in to change notification settings - Fork 56
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
[박운성] week5 #217
base: part1-박운성
Are you sure you want to change the base?
The head ref may contain hidden characters: "part1-\uBC15\uC6B4\uC131-week5"
[박운성] week5 #217
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>folder</title> | ||
</head> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { printError } from "./print_error.js"; | ||
|
||
const emailInput = document.querySelector('#sign-email'); | ||
const emailForm = emailInput.parentElement; | ||
|
||
const emailValidation = /^[A-Za-z0-9_\.\-]+@[A-Za-z0-9\.\-]{1,10}\.[A-za-z0-9\-]{2,3}$/; | ||
|
||
// 비어있는지 체크 | ||
function emailEmptyCheck(e) { | ||
if(!emailInput.value) { | ||
emailInput.classList.add('error'); | ||
printError(emailInput, '이메일을 입력해주세요.'); | ||
} else { | ||
if(emailForm.querySelector('.error-message')) { | ||
emailForm.lastElementChild.remove(); | ||
} | ||
emailValidationCheck(e); | ||
} | ||
} | ||
|
||
// 올바른 이메일인지 체크 | ||
function emailValidationCheck(e) { | ||
if(emailValidation.test(emailInput.value)) { | ||
emailInput.classList.remove('error'); | ||
if(emailForm.querySelector('.error-message')) { | ||
emailForm.lastElementChild.remove(); | ||
} | ||
if(document.querySelector('title').text === '회원가입') { | ||
usingEmail(e); | ||
} | ||
} else { | ||
emailInput.classList.add('error'); | ||
printError(emailInput, '올바른 이메일 주소가 아닙니다.'); | ||
} | ||
} | ||
|
||
// 사용중인 이메일인지 체크 | ||
function usingEmail(e) { | ||
if(emailInput.value === '[email protected]') { | ||
emailInput.classList.add('error'); | ||
printError(emailInput, '이미 사용 중인 이메일입니다.'); | ||
} else { | ||
if(emailInput.parentElement.querySelector('.error')) { | ||
emailInput.classList.remove('error'); | ||
emailInput.parentElement.lastElementChild.remove(); | ||
} | ||
} | ||
} | ||
|
||
// 이벤트 등록 | ||
function emailCheck(em) { | ||
em.addEventListener('focusout', emailEmptyCheck, usingEmail); | ||
} | ||
|
||
export { emailInput, emailCheck, emailEmptyCheck, emailValidation }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const eyes = document.querySelectorAll('.eye'); | ||
|
||
function eyeBlink (e) { | ||
const eyeClass = e.target.parentElement.classList; | ||
const pwdText = e.target.parentElement.parentElement.firstElementChild; | ||
console.log('o'); | ||
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 너무 parentElement랑 elementChild 종류를 많이 쓰는 것 같습니다. console.log('o'); 코드가 꼭 필요한 게 아니면 지우는 게 좋을 것 같습니다 |
||
if(eyeClass.contains('off')) { | ||
e.target.src = '../../images/sign/eye-on.svg'; | ||
eyeClass.remove('off'); | ||
eyeClass.add('on'); | ||
pwdText.type = 'text'; | ||
} else { | ||
e.target.src = '../../images/sign/eye-off.svg'; | ||
eyeClass.remove('on'); | ||
eyeClass.add('off'); | ||
pwdText.type = 'password'; | ||
} | ||
} | ||
|
||
const eyeEvent = function (eyes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수명은 |
||
for(let eye of eyes) { | ||
eye.addEventListener('click', eyeBlink); | ||
} | ||
} | ||
|
||
export { eyes, eyeEvent }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function printError(input, message) { | ||
if(input.parentElement.querySelector('.error-message')) { | ||
input.parentElement.lastElementChild.remove(); | ||
} | ||
if(!input.parentElement.querySelector('.error-message')) { | ||
const emailError = document.createElement('p'); | ||
emailError.classList.add('error-message'); | ||
emailError.textContent = message; | ||
input.parentElement.append(emailError); | ||
} | ||
} | ||
|
||
export { printError }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { printError } from "./print_error.js"; | ||
import { pwdInput } from "./pwd_validation.js"; | ||
|
||
const pwdConfirmInput = document.querySelector('#sign-password-confirm'); | ||
const pwdConfirmForm = pwdConfirmInput.parentElement; | ||
|
||
// 비밀번호 확인 | ||
function pwdConfirm(e) { | ||
if(!pwdConfirmInput.value) { | ||
pwdConfirmInput.classList.add('error'); | ||
printError(pwdConfirmInput, '비밀번호를 확인해주세요.'); | ||
} else { | ||
if(pwdConfirmInput.value !== pwdInput.value) { | ||
pwdConfirmInput.classList.add('error'); | ||
printError(pwdConfirmInput, '비밀번호가 일치하지 않아요.'); | ||
} else { | ||
pwdConfirmInput.classList.remove('error'); | ||
if(pwdConfirmForm.querySelector('.error-message')) { | ||
pwdConfirmForm.lastElementChild.remove(); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
function pwdConfirmCheck(e) { | ||
pwdConfirmInput.addEventListener('focusout', pwdConfirm); | ||
}; | ||
|
||
export { pwdConfirmInput, pwdConfirm, pwdConfirmCheck }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { printError } from "./print_error.js"; | ||
|
||
const pwdInput = document.querySelector('#sign-password'); | ||
const pwdForm = pwdInput.parentElement; | ||
|
||
const pwdValidation = /^(?=.*\d)(?=^.{8,15}$)(?=.*[a-zA-Z]).*$/; | ||
|
||
// 비어있는지 체크 | ||
function pwdEmptyCheck(e) { | ||
if(!pwdInput.value) { | ||
pwdInput.classList.add('error'); | ||
printError(pwdInput, '비밀번호를 입력해주세요.'); | ||
} else if(pwdInput.value) { | ||
if(pwdForm.querySelector('.error-message')) { | ||
pwdForm.lastElementChild.remove(); | ||
} | ||
pwdValidationCheck(e); | ||
} | ||
} | ||
|
||
// 올바른 형식인지 체크 | ||
function pwdValidationCheck(e) { | ||
if(pwdValidation.test(pwdInput.value)) { | ||
pwdInput.classList.remove('error'); | ||
if(pwdForm.querySelector('.error-message')) { | ||
pwdForm.lastElementChild.remove(); | ||
} | ||
} else { | ||
printError(pwdInput, '비밀번호는 영문, 숫자 조합 8자 이상 입력해 주세요.'); | ||
pwdInput.classList.add('error'); | ||
} | ||
} | ||
|
||
// 이벤트 등록 | ||
function pwdCheck(pw) { | ||
pw.addEventListener('focusout', pwdEmptyCheck); | ||
} | ||
|
||
export { pwdInput, pwdCheck, pwdEmptyCheck, pwdValidation }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { eyes, eyeEvent } from './signModule/eye.js'; | ||
import { emailInput, emailCheck } from './signModule/email_validation.js'; | ||
import { pwdInput, pwdCheck } from './signModule/pwd_validation.js'; | ||
import { btn, btnCheck } from './signin_btn.js'; | ||
|
||
|
||
|
||
eyeEvent(eyes); | ||
emailCheck(emailInput); | ||
pwdCheck(pwdInput); | ||
btnCheck(btn); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { printError } from "./signModule/print_error.js"; | ||
import { emailInput } from "./signModule/email_validation.js"; | ||
import { pwdInput } from "./signModule/pwd_validation.js"; | ||
|
||
const btn = document.querySelector('.sign-button'); | ||
|
||
function btnEmptyCheck(e) { | ||
e.preventDefault(); | ||
if(emailInput.value === '[email protected]' && pwdInput.value === 'codeit101') { | ||
location.href = "./folder.html"; | ||
} | ||
else { | ||
emailInput.classList.add('error'); | ||
printError(emailInput, '이메일을 확인해주세요.'); | ||
pwdInput.classList.add('error'); | ||
printError(pwdInput, '비밀번호를 확인해주세요.'); | ||
} | ||
} | ||
|
||
function btnCheck(btn) { | ||
btn.addEventListener('click', btnEmptyCheck); | ||
} | ||
|
||
export { btn, btnCheck }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { eyes, eyeEvent } from './signModule/eye.js'; | ||
import { emailInput, emailCheck } from './signModule/email_validation.js'; | ||
import { pwdInput, pwdCheck } from './signModule/pwd_validation.js'; | ||
import { pwdConfirmInput, pwdConfirmCheck } from './signModule/pwd_confirm.js'; | ||
import { btn, btnCheck } from './signup_btn.js'; | ||
|
||
|
||
emailCheck(emailInput); | ||
pwdCheck(pwdInput); | ||
pwdConfirmCheck(pwdConfirmInput); | ||
eyeEvent(eyes); | ||
btnCheck(btn); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { emailInput, emailEmptyCheck, emailValidation } from "./signModule/email_validation.js"; | ||
import { pwdInput, pwdEmptyCheck, pwdValidation } from "./signModule/pwd_validation.js"; | ||
import { pwdConfirmInput, pwdConfirm } from "./signModule/pwd_confirm.js"; | ||
|
||
const btn = document.querySelector('.sign-button'); | ||
|
||
let userEmail = '[email protected]' | ||
|
||
function btnSignupCheck(e) { | ||
e.preventDefault(); | ||
if(emailInput.value && emailInput.value !== userEmail && emailValidation.test(emailInput.value)) { | ||
if(pwdInput.value && pwdConfirmInput.value === pwdInput.value && pwdValidation.test(pwdInput.value)) { | ||
location.href = './folder.html'; | ||
} | ||
} | ||
} | ||
|
||
function btnCheck(btn) { | ||
btn.addEventListener('click', btnSignupCheck); | ||
btn.addEventListener('click', emailEmptyCheck); | ||
btn.addEventListener('click', pwdEmptyCheck); | ||
btn.addEventListener('click', pwdConfirm); | ||
} | ||
|
||
export { btn, btnCheck }; |
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.
parentElement
,lastElementChild
이런 종류의 property는 html 구조에 의존하게 됩니다. 즉, 추가적인 요구사항에 따라 구조가 바뀌게 되는 경우 해당 코드를 다시 수정해야하는 번거로움이 생기죠.해당 태그를 한번에 찾아갈 수 있게 적절히
class
,id
를 부여해서 직접 접근하는 방법으로 사용해주세요.