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

[염성진] Sprint4 #120

Merged
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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:5500",
"webRoot": "${workspaceFolder}"
}
]
}
104 changes: 51 additions & 53 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,12 @@
<meta property="og:url" content="https://www.codeit.kr" />
<title>판다마켓</title>
<link rel="stylesheet" href="style.css" />
<script>
(function (d) {
var config = {
kitId: 'sjs5cbs',
scriptTimeout: 3000,
async: true,
},
h = d.documentElement,
t = setTimeout(function () {
h.className = h.className.replace(/\bwf-loading\b/g, '') + ' wf-inactive';
}, config.scriptTimeout),
tk = d.createElement('script'),
f = false,
s = d.getElementsByTagName('script')[0],
a;
h.className += ' wf-loading';
tk.src = 'https://use.typekit.net/' + config.kitId + '.js';
tk.async = true;
tk.onload = tk.onreadystatechange = function () {
a = this.readyState;
if (f || (a && a != 'complete' && a != 'loaded')) return;
f = true;
clearTimeout(t);
try {
Typekit.load(config);
} catch (e) {}
};
s.parentNode.insertBefore(tk, s);
})(document);
</script>
<link
rel="stylesheet"
as="style"
crossorigin
href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/variable/pretendardvariable.min.css"
/>
</head>
<body>
<header class="header-nav">
Expand Down Expand Up @@ -66,7 +42,11 @@
<main>
<section>
<div class="section-box">
<img src="image/main/Img_home_hot_item.png" alt="인기 상품 기능 소개 이미지" class="section-image" />
<img
src="image/main/Img_home_hot_item.png"
alt="인기 상품 기능 소개 이미지"
class="section-image"
/>
<div class="contents">
<div class="content-category">Hot item</div>
<div class="content-title">
Expand All @@ -93,12 +73,20 @@
쉽게 찾아보세요
</div>
</div>
<img src="image/main/Img_home_item_search.png" alt="검색 기능 소개 이미지" class="section-image" />
<img
src="image/main/Img_home_item_search.png"
alt="검색 기능 소개 이미지"
class="section-image"
/>
</div>
</section>
<section>
<div class="section-box">
<img src="image/main/Img_home_for_sale_item.png" alt="상품 등록 기능 소개 이미지" class="section-image" />
<img
src="image/main/Img_home_for_sale_item.png"
alt="상품 등록 기능 소개 이미지"
class="section-image"
/>
<div class="contents">
<div class="content-category">Register</div>
<div class="content-title">
Expand All @@ -113,21 +101,21 @@
</div>
</section>
</main>
<footer class="footer-contents">
<div class="footer-contents-background">
<div class="footer-text-image">
<div class="footer-text">
<section class="bottom-contents">
<div class="bottom-contents-background">
<div class="bottom-text-image">
<div class="bottom-text">
<div class="slogan">
믿을 수 있는<br />
판다마켓 중고거래
</div>
</div>
</div>
</div>
</footer>
</section>
<footer class="footer-link-bar-background">
<div class="footer-link-bar">
<div class="codeit">@codeit - 2024</div>
<address class="codeit">@codeit - 2024</address>
<div class="privacy-faq-box">
<div>
<a href="privacy" class="privacy">Privacy Policy</a>
Expand All @@ -136,20 +124,30 @@
<a href="faq" class="faq">FAQ</a>
</div>
</div>
<div class="sns-links">
<a href="/facebook" target="_blank">
<img class="sns-link-mini" src="/image//icon/ic_facebook.png" />
</a>
<a href="/twitter" target="_blank">
<img class="sns-link-mini" src="/image//icon/ic_twitter.png" />
</a>
<a href="/youtube" target="_blank">
<img class="sns-link-mini" src="/image//icon/ic_youtube.png" />
</a>
<a href="/instagram" target="_blank">
<img class="sns-link-mini" src="/image//icon/ic_instagram.png" />
</a>
</div>
<nav class="sns-links">
<ul>
<li>
<a href="/facebook" target="_blank">
Copy link
Collaborator

Choose a reason for hiding this comment

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

targe="_blank"rel="noopener norefferer" 와 함께 사용됩니다(거의 세트로)
이유는 아래 아티클로 첨부해드릴게요!
https://velog.io/@parkseonup/noopener%EC%99%80-noreferrer

<img class="sns-link-mini" src="/image//icon/ic_facebook.png" />
</a>
</li>
<li>
<a href="/twitter" target="_blank">
<img class="sns-link-mini" src="/image//icon/ic_twitter.png" />
</a>
</li>
<li>
<a href="/youtube" target="_blank">
<img class="sns-link-mini" src="/image//icon/ic_youtube.png" />
</a>
</li>
<li>
<a href="/instagram" target="_blank">
<img class="sns-link-mini" src="/image//icon/ic_instagram.png" />
</a>
</li>
</ul>
</nav>
</div>
</footer>
</body>
Expand Down
11 changes: 11 additions & 0 deletions items.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>items</h1>
</body>
</html>
43 changes: 40 additions & 3 deletions join.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
font-size: 100%;
font: inherit;
vertical-align: baseline;
box-sizing: border-box;
font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui,
Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic',
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif;
}

/* HTML5 display-role reset for older browsers */
Expand Down Expand Up @@ -89,6 +93,7 @@ input {
font-weight: 400;
text-indent: 20px;
}

.logo {
margin-top: 60px;
}
Expand Down Expand Up @@ -151,9 +156,6 @@ input {
cursor: pointer;
display: block;
}
.login-btn:hover {
background-color: var(--blue);
}

.easy-login-background {
background-color: #e6f2ff;
Expand Down Expand Up @@ -238,3 +240,38 @@ input {
margin-bottom: 185px;
}
}
/* 아래로는 로그인, 회원가입 페이지 에러 핸들링용 클래스입니다. */
.error {
outline: 2px solid var(--red);
}

.error2 {
outline: 2px solid var(--red);
}
.error-message {
font-size: 15px;
position: absolute;
opacity: 0;
top: calc(100% + 4px);
left: 16px;
}

.condition-message {
font-size: 15px;
position: absolute;
opacity: 0;
top: calc(100% + 4px);
left: 16px;
}

.waring {
color: var(--red);
opacity: 100;
}
.waring2 {
color: var(--red);
opacity: 100;
}
.accept {
background-color: var(--blue);
}
143 changes: 143 additions & 0 deletions login-signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
const $input = document.getElementsByClassName('input');
const $email = document.getElementById('email');
const $name = document.getElementById('name');
const $password = document.getElementById('password');
const $checkPassword = document.getElementById('checkPassword');
const $loginBtn = document.getElementsByClassName('login-btn');
const $form = document.getElementsByClassName('form');
const $signup = document.getElementsByClassName('signup');
const $login = document.getElementsByClassName('login');
const $loginForm = document.getElementById('loginForm');
const $conditionMessage = document.querySelectorAll('.condition-message');
const $passwordEye = document.getElementById('passwordEye');
const $checkPasswordEye = document.getElementById('checkPasswordEye');
const pattern = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
Copy link
Collaborator

Choose a reason for hiding this comment

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

이런 정규표현식 혹은 변하지 않는 값들은 "상수화" 시켜주는 것이 일반적인 방법이에요.
예를 들어 PATTERN 이라는 대문자 변수명을 사용하면 우린 보통 상수화 시켜줬다 라고 생각합니다!

*참고
대문자 상수 : 기억하기 힘든 값을 변수에 할당해 별칭으로 사용되는 관습으로 대문자 상수는 ‘하드 코딩한’ 값의 별칭을 만들 때 사용


const pass = [false, false, false, false];

// 인풋 입력값있는지 체크
function inputCheck(e) {
const $target = e.target;
const $errorMesaage = $target.nextElementSibling;
if ($target.value === '') {
$target.classList.add('error2');
Copy link
Collaborator

Choose a reason for hiding this comment

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

전 훨씬 좋다고 생각해요!
dom에 직접적인 style을 지정해주는 것이 아닌 classList 추가를 해줌으로써 더 직관적인 코드가 된 것 같아요!

$errorMesaage.classList.add('waring');
} else {
$target.classList.remove('error2');
$errorMesaage.classList.remove('waring');
}
}

// 이메일 정규식 체크
function emailCheck() {
if ($email.value === '') {
$conditionMessage[0].classList.remove('waring');
Copy link
Collaborator

Choose a reason for hiding this comment

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

하지만 결국 conditionMessage 처럼 querySelector로 가져온 친구들도 DOM 자체이기 때문에 어쨌든 DOM에 클래스명을 추가하는 것이에요 :)
다만, style 속성을 직접 부여하지 않고 class명을 지정해줌으로써 다양한 css를 적용하기 더 편해졌다는 장점이 있죠 👍

$input[0].classList.remove('error');
} else if (!pattern.test($email.value)) {
$conditionMessage[0].classList.add('waring');
$input[0].classList.add('error');
} else {
$conditionMessage[0].classList.remove('waring');
$input[0].classList.remove('error');
}
}

// 비밀번호 8글자 이상인지 체크
function passwordCheck(e) {
if (e.target.id === 'password') {
const $target = e.target;
const $Message = $target.nextElementSibling.nextElementSibling;
Copy link
Collaborator

Choose a reason for hiding this comment

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

앞으로는 변수명에도 컨벤션 (일정한 규칙) 이 있어야해요
얘만 대문자로 시작하는 이유가 따로 있을까요!? (한번 고민해보세요! 없다면 소문자로 바꿔보세요 👍 )

if ($target.value.length < 8 && $target.value.length > 0) {
$Message.classList.add('waring');
$target.classList.add('error');
} else {
$Message.classList.remove('waring');
$target.classList.remove('error');
}
}
}
// 비밀번호 재확인 체크
function ReCheckPassword() {
if ($password.value !== $checkPassword.value) {
$conditionMessage[2].classList.add('waring');
$input[3].classList.add('error');
} else {
$conditionMessage[2].classList.remove('waring');
$input[3].classList.remove('error');
}
}

// 조건 충족했는지 체크
function meetsCondition() {
for (let i = 0; i < $input.length; i++) {
if ($input[i].value !== '') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

const isError = $input[i].classList.contains('error') || $input[i].classList.contains('error2')

pass.splice(i,  1, isError ? false : true)

요런식으로 코드를 바꿔볼 수 있겠네요
중첩 if문이 나온다면 다시 한번 고민해보는 것을 추천할게요!

제가 위에서 사용한 건 "삼항 연산자"입니다!

if ($input[i].classList.contains('error') || $input[i].classList.contains('error2')) {
pass.splice(i, 1, false);
} else {
pass.splice(i, 1, true);
}
}
}
}

// 모든 조건을 충족했는지 체크 후 충족했다면 버튼 활성화
function meetAallConditions() {
if ($input.length === 2) {
const loginPass = pass.slice(0, 2);
if (loginPass.every((value) => value === true)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

요기도 if문이 중복으로 쓰였는데 다른 방법은 없을까요!?

$loginBtn[0].classList.add('accept');
} else {
$loginBtn[0].classList.remove('accept');
}
} else if (pass.every((value) => value === true)) {
$loginBtn[0].classList.add('accept');
} else {
$loginBtn[0].classList.remove('accept');
}
}

// 포커스 아웃 시에 함수들을 실행하여 조건 확인
$loginForm.addEventListener('focusout', (e) => {
emailCheck();
passwordCheck(e);
if ($input.length === 4) {
ReCheckPassword();
}
inputCheck(e);
meetsCondition();
meetAallConditions();
});

// 모든 조건 만족 시 submit 하여 페이지 이동
$loginForm.addEventListener('submit', (e) => {
e.preventDefault();
Copy link
Collaborator

Choose a reason for hiding this comment

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

혹시 e.preventDefault() vs e.stopPropagination()의 차이점을 아시나요?

모르신다면 아래 아티클을 공부해보시면 좋을 것 같아요 👍
https://velog.io/@yiyb0603/JS-e.preventDefault%EC%99%80-e.stopPropagation%EC%9D%98-%EC%B0%A8%EC%9D%B4%EC%A0%90

meetsCondition();
meetAallConditions();
if ($loginBtn[0].classList.contains('accept')) {
if ($input.length === 2) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기서도 삼항연산자로 한번 바꿔보시겠어요!?

window.location.href = '/items';
} else {
window.location.href = '/signin';
}
}
});

// 패스워드 눈알 아이콘 클릭 시 패스워드 보임/숨김 변경
$passwordEye.addEventListener('click', () => {
if ($password.type === 'text') {
$password.type = 'password';
$passwordEye.src = 'image/icon/btn_icon/visibilty_off.png';
} else {
$password.type = 'text';
$passwordEye.src = 'image/icon/btn_icon/visibilty_on.png';
}
});
$checkPasswordEye.addEventListener('click', () => {
if ($checkPassword.type === 'text') {
$checkPassword.type = 'password';
$checkPasswordEye.src = 'image/icon/btn_icon/visibilty_off.png';
} else {
$checkPassword.type = 'text';
$checkPasswordEye.src = 'image/icon/btn_icon/visibilty_on.png';
}
});
Loading
Loading