Skip to content
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

Open
wants to merge 4 commits into
base: part1-박운성
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions week4/folder.html
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>
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
6 changes: 6 additions & 0 deletions week4/images/sign/eye-on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
55 changes: 55 additions & 0 deletions week4/js/signModule/email_validation.js
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();
Copy link
Collaborator

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를 부여해서 직접 접근하는 방법으로 사용해주세요.

}
}
}

// 이벤트 등록
function emailCheck(em) {
em.addEventListener('focusout', emailEmptyCheck, usingEmail);
}

export { emailInput, emailCheck, emailEmptyCheck, emailValidation };
26 changes: 26 additions & 0 deletions week4/js/signModule/eye.js
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수명은 setEyeEvent 가 자연스럽네요.

for(let eye of eyes) {
eye.addEventListener('click', eyeBlink);
}
}

export { eyes, eyeEvent };
13 changes: 13 additions & 0 deletions week4/js/signModule/print_error.js
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 };
29 changes: 29 additions & 0 deletions week4/js/signModule/pwd_confirm.js
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 };
39 changes: 39 additions & 0 deletions week4/js/signModule/pwd_validation.js
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 };
11 changes: 11 additions & 0 deletions week4/js/signin.js
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);
24 changes: 24 additions & 0 deletions week4/js/signin_btn.js
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 };
12 changes: 12 additions & 0 deletions week4/js/signup.js
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);
25 changes: 25 additions & 0 deletions week4/js/signup_btn.js
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 };
File renamed without changes.
11 changes: 6 additions & 5 deletions signin.html → week4/signin.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@
<form class="sign-form">
<div class="sign-form-section">
<div>
<label for="signin-email">
<label for="sign-email">
이메일
</label>
<div>
<input id="singin-email" name="email" type="email" autocomplete="off" placeholder="이메일" required>
<input id="sign-email" name="email" type="text" autocomplete="off" placeholder="이메일">
</div>
</div>
<div>
<label for="signin-password">
<label for="sign-password">
비밀번호
</label>
<div class="pwd-section">
<input id="signin-password" name="password" type="password" placeholder="비밀번호" required>
<span class="eye">
<input id="sign-password" name="password" type="password" placeholder="비밀번호">
<span class="eye off">
<img src="images/sign/eye-off.svg">
</span>
</div>
Expand All @@ -65,5 +65,6 @@
</div>
</div>
</div>
<script type="module" src="./js/signin.js"></script>
</body>
</html>
13 changes: 7 additions & 6 deletions signup.html → week4/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@
<form class="sign-form">
<div class="sign-form-section">
<div>
<label for="signup-email">
<label for="sign-email">
이메일
</label>
<div>
<input id="singup-email" name="email" type="email" autocomplete="off" placeholder="이메일" required>
<input id="sign-email" name="email" type="email" autocomplete="off" placeholder="이메일">
</div>
</div>
<div>
<label for="signup-password">
<label for="sign-password">
비밀번호
</label>
<div class="pwd-section">
<input id="signup-password" name="password" type="password" placeholder="비밀번호" required>
<input id="sign-password" name="password" type="password" placeholder="비밀번호">
<span class="eye">
<img src="images/sign/eye-off.svg">
</span>
</div>
</div>
<div>
<label for="signup-password-comfirm">
<label for="sign-password-confirm">
비밀번호 확인
</label>
<div class="pwd-section">
<input id="signup-password-comfirm" name="password" type="password" placeholder="비밀번호" required>
<input id="sign-password-confirm" name="password" type="password" placeholder="비밀번호">
<span class="eye">
<img src="images/sign/eye-off.svg">
</span>
Expand All @@ -83,5 +83,6 @@
</div>
</div>
</div>
<script type="module" src="./js/signup.js"></script>
</body>
</html>
27 changes: 6 additions & 21 deletions src/index-media.css → week4/src/index-media.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@

.tablet-padding {
display: block;
flex: 0 99 20rem;
min-width: 3.2rem;
}

.tablet-padding-center {
min-width: 53.8rem;
}

nav {
display: grid;
grid-template: 9.4rem / 1fr 133px 1fr 128px 1fr;
display: flex;
max-width: 192rem;
height: 9.4rem;
padding: 0;
}

.tablet-padding-center {
flex: 10 1 538px;
}

.hero-header {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -77,21 +77,6 @@
}
}

/* tablet nav padding */
@media screen and (max-width: 862px) {
.tablet-padding {
width: 3.2rem;
}

.tablet-padding-center {
min-width: auto;
}

nav {
display: grid;
grid-template: 9.4rem / 32px 133px 1fr 128px 32px;
}
}

/* mobile */
@media screen and (max-width: 767px) {
Expand Down
File renamed without changes.
File renamed without changes.
Loading