Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (59 loc) · 2.19 KB
/
Copy pathscript.js
File metadata and controls
68 lines (59 loc) · 2.19 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
document.getElementById("main-action-button").onclick = function () {
document.getElementById("products").scrollIntoView({behavior: "smooth"});
}
let links = document.querySelectorAll(".menu-item > a");
for (let i = 0; i < links.length; i++) {
links[i].onclick = function () {
document.getElementById(links[i].getAttribute("data-link")).scrollIntoView({behavior: "smooth"});
}
}
let buttons = document.getElementsByClassName("product-button")
for (let i = 0; i < buttons.length; i++) {
buttons[i].onclick = function () {
document.getElementById("order").scrollIntoView({behavior: "smooth"});
}
}
let burger = document.getElementById("burger");
let name = document.getElementById("name");
let phone = document.getElementById("phone");
document.getElementById("order-action").onclick = function () {
let hasError = false;
[burger, name, phone].forEach(item => {
if (!item.value) {
item.parentElement.style.background = "red";
hasError = true;
} else {
item.parentElement.style.background = "";
}
});
if (!hasError) {
[burger, name, phone].forEach(item => {
item.value = "";
});
alert("Спасибо за заказ! Мы скоро свяжемся с Вами!");
}
}
let prices = document.getElementsByClassName('products-item-price');
document.getElementById("change-currency").onclick = function (e) {
let currentCurrency = e.target.innerText;
let newCurrency = "$";
let coefficient = 1;
if (currentCurrency === "$") {
newCurrency = "₽";
coefficient = 90;
} else if (currentCurrency === "₽") {
newCurrency = "BYN";
coefficient = 3;
}
else if (currentCurrency === 'BYN') {
newCurrency = '€';
coefficient = 0.9;
} else if (currentCurrency === '€') {
newCurrency = '¥';
coefficient = 6.9;
}
e.target.innerText = newCurrency;
for (let i = 0; i < prices.length; i++) {
prices[i].innerText = +(prices[i].getAttribute("data-base-price") * coefficient).toFixed(1) + " " + newCurrency;
}
}