Skip to content

Commit

Permalink
Merge pull request #57 from ViktorSvertoka/bmifix
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka authored Dec 18, 2023
2 parents b494c6b + f7ecfae commit c15fc88
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 230 deletions.
101 changes: 0 additions & 101 deletions src/css/layout/02-hero.css
Original file line number Diff line number Diff line change
Expand Up @@ -213,104 +213,3 @@
color: var(--color-white);
opacity: 0.8;
}

/* BMI */

/* .hero__bmi-wrap {
padding-top: 20px;
}
@media screen and (min-width: 768px) {
.hero__bmi-wrap {
padding-top: 16px;
}
}
@media screen and (min-width: 1440px) {
.hero__bmi-wrap {
padding-top: 20px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
}
.hero__bmi {
display: flex;
flex-direction: column;
}
.hero__bmi-title {
font-size: 40px;
color: var(--color-black);
font-weight: 400;
letter-spacing: -0.88px;
line-height: 1.1em;
margin-bottom: 20px;
}
.hero__bmi-title-part {
font-style: italic;
}
.hero__label {
display: flex;
flex-direction: column;
font-size: 14px;
line-height: 1.29;
letter-spacing: -0.28px;
}
.hero__input {
display: inline-flex;
padding: 12px 14px;
align-items: center;
gap: 10px;
border-radius: 30px;
border: 1px solid var(--color-black);
background-color: var(--color-white);
font-size: 18px;
margin: 10px;
}
.hero__btn {
border-radius: 30px;
background: var(--color-white);
color: var(--color-black);
border: none;
padding: 10px 20px;
margin: 10px;
font-size: 20px;
box-shadow: 0 0 4px rgba(0, 0, 0, .3);
cursor: pointer;
transition: all var(--transition-dur-and-func);
}
.hero__btn:hover,
.hero__btn:focus {
color: var(--color-white);
background-color: var(--color-black);
opacity: 0.8;
}
.hero__info-text {
padding-top: 10px;
font-size: 20px;
font-weight: 500;
}
.hero__bmi-pic {
display: none;
}
@media screen and (min-width: 1440px) {
.hero__bmi-pic {
display: inline-flex;
top: 12px;
right: 0;
width: 444px;
height: 296px;
border-radius: 30px;
}
} */
167 changes: 75 additions & 92 deletions src/js/16-modal-bmi.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,89 @@
const teamLink = document.querySelector('.bmi__link');
const teamBackdrop = document.querySelector('.bmi__backdrop');
const teamCloseBtn = document.querySelector('.bmi__modal-close-btn');
const asideImg = document.querySelector('.aside__img');
const bmiInputEl = document.getElementById('bmi-result');

const heightInput = document.getElementById('height');
const weightInput = document.getElementById('weight');

function onLinkClick(event) {
event.preventDefault();

heightInput.value = '180';
weightInput.value = '80';
bmiInputEl.value = '';

teamBackdrop.classList.remove('is-hidden');
document.body.classList.add('modal-open');

addAllEventListeners();
}

function onAsideImgClick() {

heightInput.value = '180';
weightInput.value = '80';
bmiInputEl.value = '';

teamBackdrop.classList.remove('is-hidden');
document.body.classList.add('modal-open');

addAllEventListeners();
}

function onEscClick(event) {
event.preventDefault();

if (event.code !== 'Escape') {
return;
document.addEventListener('DOMContentLoaded', function () {
const teamLink = document.querySelector('.bmi__link');
const teamBackdrop = document.querySelector('.bmi__backdrop');
const teamCloseBtn = document.querySelector('.bmi__modal-close-btn');
const asideImg = document.querySelector('.aside__img');
const bmiInputEl = document.getElementById('bmi-result');
const heightInput = document.getElementById('height');
const weightInput = document.getElementById('weight');
const btnEl = document.getElementById('btn');
const weightConditionEl = document.getElementById('weight-condition');

function onLinkClick(event) {
event.preventDefault();
resetInputs();
openModal();
}

closingModalStaff();
}

function onBackdropClick(event) {
if (event.target.closest('.bmi__wrapper')) {
return;
function onAsideImgClick() {
resetInputs();
openModal();
}

closingModalStaff();
}

function onCloseBtnClick(event) {
event.preventDefault();

closingModalStaff();
}

function addAllEventListeners() {
document.addEventListener('keydown', onEscClick);
teamBackdrop.addEventListener('click', onBackdropClick);
teamCloseBtn.addEventListener('click', onCloseBtnClick);
asideImg.addEventListener('click', onAsideImgClick);
}

function closingModalStaff() {
document.removeEventListener('keydown', onEscClick);
teamBackdrop.removeEventListener('click', onBackdropClick);
teamCloseBtn.removeEventListener('click', onCloseBtnClick);
asideImg.removeEventListener('click', onAsideImgClick);

teamBackdrop.classList.add('is-hidden');
document.body.classList.remove('modal-open');
function onEscClick(event) {
if (event.code === 'Escape') {
closingModalStaff();
}
}

addAllEventListeners();
}
function onBackdropClick(event) {
if (!event.target.closest('.bmi__wrapper')) {
closingModalStaff();
}
}

document.addEventListener('DOMContentLoaded', function () {
addAllEventListeners();
});
function onCloseBtnClick(event) {
event.preventDefault();
closingModalStaff();
}

teamLink.addEventListener('click', onLinkClick);
function addAllEventListeners() {
document.addEventListener('keydown', onEscClick);
teamBackdrop.addEventListener('click', onBackdropClick);
teamCloseBtn.addEventListener('click', onCloseBtnClick);
asideImg.addEventListener('click', onAsideImgClick);
}

const btnEl = document.getElementById('btn');
const weightConditionEl = document.getElementById('weight-condition');
function closingModalStaff() {
document.removeEventListener('keydown', onEscClick);
teamBackdrop.removeEventListener('click', onBackdropClick);
teamCloseBtn.removeEventListener('click', onCloseBtnClick);
asideImg.removeEventListener('click', onAsideImgClick);

function calculateBMI() {
const heightValue = document.getElementById('height').value / 100;
const weightValue = document.getElementById('weight').value;
teamBackdrop.classList.add('is-hidden');
document.body.classList.remove('modal-open');
}

const bmiValue = (weightValue / (heightValue * heightValue)).toFixed(1);
function openModal() {
teamBackdrop.classList.remove('is-hidden');
document.body.classList.add('modal-open');
addAllEventListeners();
}

bmiInputEl.value = bmiValue;
function resetInputs() {
heightInput.value = '180';
weightInput.value = '80';
bmiInputEl.value = '';
}

if (bmiValue < 18.5) {
weightConditionEl.innerText = 'Under weight!';
} else if (bmiValue >= 18.5 && bmiValue <= 24.9) {
weightConditionEl.innerText = 'Normal weight!';
} else if (bmiValue >= 25 && bmiValue <= 29.9) {
weightConditionEl.innerText = 'Overweight!';
} else if (bmiValue >= 30) {
weightConditionEl.innerText = 'Obesity!';
function calculateBMI() {
const heightValue = heightInput.value / 100;
const weightValue = weightInput.value;
const bmiValue = (weightValue / (heightValue * heightValue)).toFixed(1);

bmiInputEl.value = bmiValue;

if (bmiValue < 18.5) {
weightConditionEl.innerText = 'Under weight!';
} else if (bmiValue >= 18.5 && bmiValue <= 24.9) {
weightConditionEl.innerText = 'Normal weight!';
} else if (bmiValue >= 25 && bmiValue <= 29.9) {
weightConditionEl.innerText = 'Overweight!';
} else if (bmiValue >= 30) {
weightConditionEl.innerText = 'Obesity!';
}
}
}

btnEl.addEventListener('click', calculateBMI);
btnEl.addEventListener('click', calculateBMI);
teamLink.addEventListener('click', onLinkClick);
});
37 changes: 0 additions & 37 deletions src/partials/02-hero.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,42 +80,5 @@ <h1 class="hero__title">
</li>
</ul>
</div>
<!-- <div class="hero__bmi-wrap">
<img
class="hero__bmi-pic"
src="./img/hero-image-bmi.jpg"
srcset="./img/[email protected] 2x"
alt="young woman working out alone outdoors"
/>
<div class="hero__bmi">
<h2 class="hero__bmi-title">
<span class="hero__bmi-title-part">Body</span> Mass Index (BMI)
Calculator
</h2>
<label class="hero__label">
Your Height (cm):
<input
type="number"
class="hero__input"
id="height"
value="180"
placeholder="Enter your height in cm"
/></label>
<label class="hero__label"
>Your Weight (kg):
<input
type="number"
class="hero__input"
id="weight"
value="80"
placeholder="Enter your weight in kg"
/></label>
<button class="hero__btn" id="btn">Compute BMI</button>
<input disabled type="text" class="hero__input" id="bmi-result" />
<h3 class="hero__info-text">
Weight Condition: <span id="weight-condition"></span>
</h3>
</div>
</div> -->
</div>
</section>

0 comments on commit c15fc88

Please sign in to comment.