Skip to content

Commit 8bd9f42

Browse files
committed
[PROJ-18.14/compl] selecting-icon-in-pop-up-window
Adding "icon/habit" selection in "pop-up" window. Hidden "input.. this". Worth noting - onclick="" logic, everything through it. FS-dev: B-3 / JS basic
1 parent f20967d commit 8bd9f42

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

full-stack-dev/3-js-basic/18-proj-habit-tracker/18-14-selecting-icon-in-pop-up-window/index.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<link rel="icon" href="./images/favicon/favicon.svg" type="image/svg+xml" sizes="any">
1010
<link rel="shortcut icon" href="./images/favicon/favicon.ico" type="image/x-icon">
1111
<link rel="apple-touch-icon" href="./images/favicon/apple-touch-icon.png" sizes="180x180">
12-
<meta name="apple-mobile-web-app-title" content="HabitTracker">
12+
<meta name="apple-mobile-web-app-title" content="HabbitTracker">
1313
<!-- <link rel="manifest" href="./site.webmanifest"> -->
1414
<link rel="stylesheet" href="./css/normalize.css">
1515
<link rel="stylesheet" href="./css/style.css">
@@ -65,20 +65,22 @@ <h2 class="pop-up__title">Новая привычка</h2>
6565
<span class="pop-up__icons-label">Иконка</span>
6666
<ul class="pop-up__icons-list">
6767
<li class="pop-up__icons-item">
68-
<button class="pop-up__icons-btn" type="button" aria-label="Выбрать иконку" title="Спорт">
68+
<button class="pop-up__icons-btn" type="button" aria-label="Выбрать иконку" title="Спорт"
69+
onclick="setHabbitIcon(this, 'gantel-icon')">
6970
<img class="pop-up__icons-icon" src="./images/gantel-icon.svg" width="23" height="23"
7071
alt="Иконка: Гантеля">
7172
</button>
7273
</li>
7374
<li class="pop-up__icons-item">
7475
<button class="pop-up__icons-btn pop-up__icons-btn_active" type="button" aria-label="Выбрать иконку"
75-
title="Жидкости">
76+
title="Жидкости" onclick="setHabbitIcon(this, 'water-icon')">
7677
<img class="pop-up__icons-icon" src="./images/water-icon.svg" width="25" height="25"
7778
alt="Иконка: Бутылка с водой">
7879
</button>
7980
</li>
8081
<li class="pop-up__icons-item">
81-
<button class="pop-up__icons-btn" type="button" aria-label="Выбрать иконку" title="Питание">
82+
<button class="pop-up__icons-btn" type="button" aria-label="Выбрать иконку" title="Питание"
83+
onclick="setHabbitIcon(this, 'food-icon')">
8284
<img class="pop-up__icons-icon" src="./images/food-icon.svg" width="23" height="24"
8385
alt="Иконка: Тарелка с едой">
8486
</button>
@@ -89,6 +91,8 @@ <h2 class="pop-up__title">Новая привычка</h2>
8991
<form class="pop-up__form" id="pop-up-form">
9092
<input class="pop-up__form-input" id="title-input" type="text" name="title-habbit" placeholder="Название"
9193
autocomplete="off">
94+
<input class="pop-up__form-input" id="hidden-input" type="text" name="icon-habbit" placeholder="Иконка"
95+
autocomplete="off" value="water-icon" hidden>
9296
<input class="pop-up__form-input" id="target-input" type="number" name="target-habbit"
9397
placeholder="Цель/дней" autocomplete="off">
9498
<button class="pop-up__form-btn" type="submit">Добавить</button>

full-stack-dev/3-js-basic/18-proj-habit-tracker/18-14-selecting-icon-in-pop-up-window/js/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const app = {
5454
'pop-up': {
5555
popupCover: document.getElementById('pop-up-cover'),
5656
popupElement: document.getElementById('pop-up'),
57+
hiddenIconInput: document.getElementById('hidden-input'),
5758
},
5859
};
5960

@@ -237,6 +238,16 @@ function deleteCommentDay(index) {
237238
saveData(); // обновление/сохранение в localStorage
238239
}
239240

241+
function setHabbitIcon(context, iconName) {
242+
app['pop-up'].hiddenIconInput.value = iconName; // обновление value у "скрытого" инпута
243+
const activeIcon = document.querySelector(
244+
'.pop-up__icons-btn.pop-up__icons-btn_active'
245+
);
246+
247+
activeIcon.classList.remove('pop-up__icons-btn_active'); // у ранее "активной" удаление
248+
context.classList.add('pop-up__icons-btn_active'); // текущей кнопке добавление, т.е. по котрой onclick=""
249+
}
250+
240251
// init
241252
(() => {
242253
// загрузка данных.. по сути автоматическая/сразу (соответственно через IIFE)

full-stack-dev/3-js-basic/18-proj-habit-tracker/18-14-selecting-icon-in-pop-up-window/site.webmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "HabitTracker",
2+
"name": "HabbitTracker",
33
"short_name": "HT",
44
"icons": [
55
{

0 commit comments

Comments
 (0)