-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
147 lines (133 loc) · 5.59 KB
/
Copy pathscript.js
File metadata and controls
147 lines (133 loc) · 5.59 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
const year = document.getElementById('year');
if (year) year.textContent = new Date().getFullYear();
const lightbox = document.getElementById('lightbox');
const lightboxImage = document.getElementById('lightboxImage');
const lightboxCaption = document.getElementById('lightboxCaption');
const closeButton = document.querySelector('.lightbox-close');
for (const trigger of document.querySelectorAll('.gallery-item, .lightbox-trigger')) {
trigger.addEventListener('click', () => {
if (!lightbox || !lightboxImage || !lightboxCaption) return;
lightboxImage.src = trigger.dataset.image || '';
lightboxCaption.textContent = trigger.dataset.caption || '';
lightbox.showModal();
});
}
closeButton?.addEventListener('click', () => lightbox?.close());
lightbox?.addEventListener('click', (event) => {
const rect = lightbox.getBoundingClientRect();
const inside =
rect.top <= event.clientY &&
event.clientY <= rect.top + rect.height &&
rect.left <= event.clientX &&
event.clientX <= rect.left + rect.width;
if (!inside) lightbox.close();
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && lightbox?.open) {
lightbox.close();
}
});
const form = document.getElementById('requestForm');
const waSend = document.getElementById('waSend');
const tgSend = document.getElementById('tgSend');
const copyRequest = document.getElementById('copyRequest');
const requestNote = document.getElementById('requestNote');
function buildRequestText(lang = 'ru') {
const name = document.getElementById('clientName')?.value.trim() || '—';
const phone = document.getElementById('clientPhone')?.value.trim() || '—';
const car = document.getElementById('carModel')?.value.trim() || '—';
const route = document.getElementById('routeText')?.value.trim() || '—';
const problem = document.getElementById('problemText')?.value.trim() || '—';
if (lang === 'uk') {
return [
'Добрий день! Потрібен евакуатор.',
`Ім\'я: ${name}`,
`Телефон: ${phone}`,
`Автомобіль: ${car}`,
`Маршрут: ${route}`,
`Що сталося: ${problem}`
].join('\n');
}
if (lang === 'en') {
return [
'Hello! I need a tow truck.',
`Name: ${name}`,
`Phone: ${phone}`,
`Vehicle: ${car}`,
`Route: ${route}`,
`What happened: ${problem}`
].join('\n');
}
return [
'Здравствуйте! Нужен эвакуатор.',
`Имя: ${name}`,
`Телефон: ${phone}`,
`Автомобиль: ${car}`,
`Маршрут: ${route}`,
`Что случилось: ${problem}`
].join('\n');
}
function setNote(text, type = 'default') {
if (!requestNote) return;
requestNote.textContent = text;
requestNote.dataset.state = type;
}
if (form) {
const lang = form.dataset.lang || document.documentElement.lang || 'ru';
waSend?.addEventListener('click', () => {
const text = buildRequestText(lang);
const url = `https://wa.me/380661019851?text=${encodeURIComponent(text)}`;
window.open(url, '_blank', 'noopener,noreferrer');
setNote(
lang === 'uk'
? 'Відкрили WhatsApp із готовим текстом заявки.'
: lang === 'en'
? 'Opened WhatsApp with a prepared request message.'
: 'Открыли WhatsApp с готовым текстом заявки.',
'success'
);
});
tgSend?.addEventListener('click', async () => {
const text = buildRequestText(lang);
try {
await navigator.clipboard.writeText(text);
setNote(
lang === 'uk'
? 'Текст заявки скопійовано. Telegram відкривається окремо — просто вставте повідомлення в чат.'
: lang === 'en'
? 'Request text copied. Telegram opens separately — just paste the message into the chat.'
: 'Текст заявки скопирован. Telegram открывается отдельно — просто вставьте сообщение в чат.',
'success'
);
} catch {
setNote(
lang === 'uk'
? 'Не вдалося автоматично скопіювати текст. Ви все одно можете відкрити Telegram.'
: lang === 'en'
? 'Could not copy automatically. You can still open Telegram.'
: 'Не удалось автоматически скопировать текст. Вы всё равно можете открыть Telegram.',
'warning'
);
}
window.open('https://t.me/+380661019851', '_blank', 'noopener,noreferrer');
});
copyRequest?.addEventListener('click', async () => {
const text = buildRequestText(lang);
try {
await navigator.clipboard.writeText(text);
setNote(
lang === 'uk' ? 'Текст заявки скопійовано в буфер обміну.' : lang === 'en' ? 'Request text copied to clipboard.' : 'Текст заявки скопирован в буфер обмена.',
'success'
);
} catch {
setNote(
lang === 'uk'
? 'Не вдалося скопіювати автоматично. Спробуйте ще раз або виділіть текст вручну.'
: lang === 'en'
? 'Could not copy automatically. Try again or select the text manually.'
: 'Не удалось скопировать автоматически. Попробуйте ещё раз или выделите текст вручную.',
'warning'
);
}
});
}