-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
159 lines (121 loc) · 3.74 KB
/
index.js
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
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
let i;
let slides = document.querySelectorAll(".mySlides");
let dots = document.querySelectorAll(".dot");
if(n > slides.length) {
slideIndex = 1;
}
if(n < 1) {
slideIndex = slides.length;
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none"
}
for(i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace("active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className+= " active";
}
//Back-To-Top Button Scripts
(function() {
'use strict';
function trackScroll() {
let scrolled = window.pageYOffset;
let coords = document.documentElement.clientHeight;
if (scrolled > coords) {
goTopBtn.classList.add('back_to_top-show');
}
if (scrolled < coords) {
goTopBtn.classList.remove('back_to_top-show');
}
}
function backToTop() {
let scrollStep = window.pageYOffset / 40;
if (window.pageYOffset > 0) {
window.scrollBy(0, -(scrollStep));
setTimeout(backToTop, 0);
}
}
let goTopBtn = document.querySelector('.back_to_top');
window.addEventListener('scroll', trackScroll);
goTopBtn.addEventListener('click', backToTop);
})();
/**
*
* @param {HTMLButtonElement} button
*/
function AddToBasket(button) {
debugger;
let id = button.dataset.id;
//Положили картинку, заголовок и цену в переменную
let itemImage = button.dataset.image;
let itemTittle = button.dataset.title;
let price = button.dataset.price;
let tmp = localStorage.getItem("basket");
if (tmp == null) {
tmp = [
{
itemImage : itemImage,
itemTittle : itemTittle,
price : price,
id : id,
count : 1
}
]
} else {
tmp = JSON.parse(tmp);
let element = null;
for (let i = 0; i < tmp.length; i++) {
if (tmp[i].id == id)
element = tmp[i];
}
if (element == null) {
element = {
itemImage : itemImage,
itemTittle : itemTittle,
price : price,
id : id,
count : 1
};
tmp.push(element);
} else {
element.count ++;
}
}
//превращаем объект tmp в JSON-док.
let transformObj = JSON.stringify(tmp);
//Добавляем в localStorage
localStorage.setItem("basket", transformObj);
//достаем объект из localStorage
let returnObj = JSON.parse(localStorage.getItem("basket"))
}
var dialog = document.querySelector('.request-dialog');
document.querySelector('#show').onclick = function() {
dialog.show();
};
document.querySelector('#close').onclick = function() {
dialog.close();
};
function SendPhone() {
var element = document.querySelector("#phone-input");
var value = element.value;
if (value == "") {
alert("Введите номер телефона");
return;
}
var xhr = new XMLHttpRequest();
var body = 'phone=' + encodeURIComponent(value);
xhr.open("POST", '/server/callus/', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send(body);
document.querySelector("#phonedialog").style.display = "none";
}