-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
215 lines (175 loc) · 6.66 KB
/
script.js
File metadata and controls
215 lines (175 loc) · 6.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
window.onload = function() {
addMenuClickHandler();
//slider
addIphoneClickHandler();
//Tags
addTagsClickHandler();
getMessage();
}
/* Vnu_navigation */
function addMenuClickHandler() {
const menu = document.getElementById('nav_list');
menu.addEventListener('click', menuClickHandle);
function menuClickHandle(event) {
const menu = document.getElementById('nav_list');
menu.querySelectorAll('a').forEach(el => el.classList.remove('first'));
const element = event.target;
element.classList.add('first');
console.log (element);
const dataSelector = element.getAttribute("data-selector");
const elToScroll = document.querySelector(dataSelector);
scrollToElement(elToScroll);
};
function scrollToElement(pageElement) {
let positionY = 0;
while (pageElement !== null) {
positionY += pageElement.offsetTop;
pageElement = pageElement.offsetParent;
window.scrollTo(0, positionY - 50);
}
};
}
/* Portfolio */
const addTagsClickHandler = () => {
document.querySelector('.portfolio_tags').addEventListener('click', (e) => {
if (e.target.classList.contains('portfolio_tag')) {
let clickedTag = e.target;
removeSelectedTags();
selectClickedTag(clickedTag);
if (clickedTag.innerText === 'All') {
showAllPortfolioWork();
} else {
showFilterPortfolioWorkBySelectedTag(clickedTag.innerText);
}
}
});
const removeSelectedTags = () => {
let tags = document.querySelectorAll('.portfolio_tags .portfolio_tag');
tags.forEach(portfolio_tag => {
portfolio_tag.classList.remove('active');
});
}
const selectClickedTag = (clickedTag) => {
clickedTag.classList.add('active');
}
const showAllPortfolioWork = () => {
let portfolioWork = document.querySelectorAll('.portfolio_work .portfolio_work_img');
portfolioWork.forEach(portfolio_work_img => {
portfolio_work_img.classList.remove('portfolio_hidden');
});
}
const showFilterPortfolioWorkBySelectedTag = (clickedTagText) => {
console.log(selectClickedTag);
let portfolioWork = document.querySelectorAll('.portfolio_work .portfolio_work_img');
portfolioWork.forEach(portfolio_work_img => {
if (portfolio_work_img.dataset.selector != clickedTagText) {
portfolio_work_img.classList.add('portfolio_hidden');
} else {
portfolio_work_img.classList.remove('portfolio_hidden');
}
});
}
};
/* Iphone_on/of */
function addIphoneClickHandler () {
const iphone = document.querySelector(".slide__number-one");
iphone.addEventListener('click', iphoneClickHandle);
function iphoneClickHandle(event) {
const clickedSliderTarget = event.target;
if (clickedSliderTarget.classList.contains('iphone') ) {
clickedSliderTarget.classList.toggle('off');
}
console.log(clickedSliderTarget.classList);
};
}
/* Slider */
let items = document.querySelectorAll('.slider_wrap .slide');
console.log(items);
let currentItem = 0;
let isEnabled = true;
function changeCurrentItem(n) { /*give the value(currentItem) of a variable*/
currentItem = (n + items.length) % items.length;
};
function hideItem(direction) {
isEnabled = false;
items[currentItem].classList.add(direction);
items[currentItem].addEventListener('animationend', function() {
console.log(this);
console.log(this.classList);
this.classList.remove("slide_active", direction);
});
};
function showItem(direction) {
items[currentItem].classList.add('next', direction);
items[currentItem].addEventListener('animationend', function() {
console.log(this);
console.log(this.classList);
this.classList.remove('next', direction);
this.classList.add('slide_active');
isEnabled = true;
});
};
function nextItem(n) {
hideItem('to-left');
changeCurrentItem(n + 1);
showItem('from-right');
};
function previousItem(n) {
hideItem('to-right');
changeCurrentItem(n - 1);
showItem('from-left');
};
const left = document.querySelector('.arrow.left')
left.addEventListener('click', function() {
if (isEnabled) {
previousItem(currentItem);
}
});
const right = document.querySelector('.arrow.right')
right.addEventListener('click', function() {
if (isEnabled) {
nextItem(currentItem);
}
});
function getMessage() {
let errorMessageBlock = document.getElementById('error-message-block');
let messageBlock = document.getElementById('message-block');
let messageName = document.getElementById('message-name');
let messageEmail = document.getElementById('message-email');
let messageSubject = document.getElementById('message-subject');
let messageDescription = document.getElementById('message-description');
document.getElementById('submit-button').addEventListener('click', () => {
let nameValue = document.getElementById('name-input').value;
let emailValue = document.getElementById('email-input').value.toString();
let subjectValue = document.getElementById('subject-input').value;
let descriptionValue = document.getElementById('description-input').value.toString();
if (nameValue == '' || emailValue == '' || !(/.+@.+\..+/i.test(document.getElementById('email-input').value))) {
errorMessageBlock.classList.remove('hide-window');
document.getElementById('error-close-button').addEventListener('click', () => {
errorMessageBlock.classList.add('hide-window');
});
return false;
};
messageBlock.classList.remove('hide-window');
messageName.append(`Ваше имя: ${nameValue}`);
messageEmail.append(`Ваша электронная почта: ${emailValue}`);
if (subjectValue == '') {
messageSubject.append('Без темы');
} else {
messageSubject.append(`Тема: ${subjectValue}`);
};
if (descriptionValue == '') {
messageDescription.append('Без описания');
} else {
messageDescription.append(`Описание: ${descriptionValue}`);
};
});
document.getElementById('close-button').addEventListener('click', () => {
document.getElementById('form').reset();
messageBlock.classList.add('hide-window');
messageName.innerHTML = '';
messageEmail.innerHTML = '';
messageSubject.innerHTML = '';
messageDescription.innerHTML = '';
});
};