-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.js
More file actions
95 lines (83 loc) · 3.88 KB
/
Copy pathmain.js
File metadata and controls
95 lines (83 loc) · 3.88 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
/* Секретарь24 — лендинг. Интерактив без зависимостей. */
(function () {
'use strict';
var header = document.getElementById('header');
var burger = document.getElementById('burger');
/* --- Переключатель языков: запоминаем выбор пользователя, чтобы авто-редирект
с корня по browser-language больше не срабатывал --- */
document.querySelectorAll('.lang-switcher a').forEach(function (a) {
a.addEventListener('click', function () {
try { localStorage.setItem('s24_lang', a.getAttribute('hreflang') || ''); } catch (e) {}
});
});
/* --- Шапка: фон при скролле --- */
function onScroll() {
header.classList.toggle('scrolled', window.scrollY > 8);
}
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
/* --- Мобильное меню --- */
var nav = document.getElementById('nav');
function syncMobileNavHeight() {
/* CSS использует --mobile-nav-h для позиционирования actions под пунктами nav,
чтобы не зависеть от magic numbers и количества ссылок. */
if (!nav) return;
var h = nav.getBoundingClientRect().height || 0;
if (h > 0) header.style.setProperty('--mobile-nav-h', h + 'px');
}
burger.addEventListener('click', function () {
var open = header.classList.toggle('nav-open');
burger.setAttribute('aria-expanded', open ? 'true' : 'false');
if (open) {
/* Меряем после применения класса, чтобы nav уже был развёрнут. */
requestAnimationFrame(syncMobileNavHeight);
}
});
window.addEventListener('resize', function () {
if (header.classList.contains('nav-open')) syncMobileNavHeight();
});
document.querySelectorAll('#nav a, .header__actions a, .lang-switcher a').forEach(function (link) {
link.addEventListener('click', function () {
header.classList.remove('nav-open');
burger.setAttribute('aria-expanded', 'false');
});
});
/* --- Переключатель тарифов: помесячно / за год --- */
var billingSwitch = document.getElementById('billingSwitch');
var lblMonthly = document.getElementById('lblMonthly');
var lblYearly = document.getElementById('lblYearly');
function applyBilling(yearly) {
var mode = yearly ? 'yearly' : 'monthly';
document.querySelectorAll('[data-monthly]').forEach(function (el) {
var val = el.getAttribute('data-' + mode);
if (val !== null) el.textContent = val;
});
billingSwitch.setAttribute('aria-checked', yearly ? 'true' : 'false');
lblMonthly.classList.toggle('is-active', !yearly);
lblYearly.classList.toggle('is-active', yearly);
}
billingSwitch.addEventListener('click', function () {
applyBilling(billingSwitch.getAttribute('aria-checked') !== 'true');
});
/* --- Лид-форма --- */
var form = document.getElementById('leadForm');
var success = document.getElementById('leadSuccess');
form.addEventListener('submit', function (e) {
e.preventDefault();
var name = form.name.value.trim();
var contact = form.contact.value.trim();
if (!name || !contact) {
if (!name) form.name.focus();
else form.contact.focus();
return;
}
/* TODO (Фаза 2): отправить заявку на backend.
Пример: fetch('/admin/leads', { method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: name, contact: contact, role: form.role.value }) })
Лид уйдёт в amoCRM через существующее событие WidgetContactSubmitted. */
form.hidden = true;
success.hidden = false;
success.scrollIntoView({ behavior: 'smooth', block: 'center' });
});
})();