sozday-sovremennyy-dostupnyy/script.js

259 lines
8.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

document.addEventListener('DOMContentLoaded', function() {
const reveals = document.querySelectorAll('.reveal');
const faqItems = document.querySelectorAll('.faq-item');
const sizeBtns = document.querySelectorAll('.size-btn');
const contrastBtns = document.querySelectorAll('.contrast-btn');
const amountBtns = document.querySelectorAll('.amount-btn');
const customAmount = document.getElementById('custom-amount');
function checkReveal() {
const triggerBottom = window.innerHeight * 0.85;
reveals.forEach(reveal => {
const boxTop = reveal.getBoundingClientRect().top;
if (boxTop < triggerBottom) {
reveal.classList.add('in');
}
});
}
window.addEventListener('scroll', checkReveal);
checkReveal();
faqItems.forEach(item => {
const question = item.querySelector('.faq-question');
question.addEventListener('click', function() {
const isExpanded = this.getAttribute('aria-expanded') === 'true';
faqItems.forEach(i => {
i.classList.remove('active');
i.querySelector('.faq-question').setAttribute('aria-expanded', 'false');
});
if (!isExpanded) {
item.classList.add('active');
this.setAttribute('aria-expanded', 'true');
}
});
});
sizeBtns.forEach(btn => {
btn.addEventListener('click', function() {
sizeBtns.forEach(b => b.classList.remove('active'));
this.classList.add('active');
document.body.classList.remove('text-normal', 'text-large', 'text-xlarge');
document.body.classList.add('text-' + this.dataset.size);
});
});
contrastBtns.forEach(btn => {
btn.addEventListener('click', function() {
contrastBtns.forEach(b => b.classList.remove('active'));
this.classList.add('active');
document.body.classList.remove('contrast-normal', 'contrast-high');
if (this.dataset.contrast === 'high') {
document.body.classList.add('contrast-high');
}
});
});
amountBtns.forEach(btn => {
btn.addEventListener('click', function() {
amountBtns.forEach(b => b.classList.remove('active'));
this.classList.add('active');
if (customAmount) customAmount.value = '';
});
});
if (customAmount) {
customAmount.addEventListener('input', function() {
amountBtns.forEach(b => b.classList.remove('active'));
});
}
});
function openModal(modalId) {
const modal = document.getElementById(modalId);
if (modal) {
modal.removeAttribute('hidden');
modal.setAttribute('aria-hidden', 'false');
document.body.style.overflow = 'hidden';
const focusable = modal.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
if (focusable) focusable.focus();
modal.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeModal(modalId);
}
if (e.key === 'Tab') {
const focusableElements = modal.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
const first = focusableElements[0];
const last = focusableElements[focusableElements.length - 1];
if (e.shiftKey && document.activeElement === first) {
e.preventDefault();
last.focus();
} else if (!e.shiftKey && document.activeElement === last) {
e.preventDefault();
first.focus();
}
}
});
}
}
function closeModal(modalId) {
const modal = document.getElementById(modalId);
if (modal) {
modal.setAttribute('hidden', '');
modal.setAttribute('aria-hidden', 'true');
document.body.style.overflow = '';
}
}
let currentStep = 1;
const totalSteps = 10;
function showStep(step) {
const steps = document.querySelectorAll('.form-step:not(.result-step)');
steps.forEach((s, index) => {
s.classList.remove('active');
if (index === step - 1) {
s.classList.add('active');
}
});
currentStep = step;
}
function nextStep(current) {
const currentStepEl = document.querySelectorAll('.form-step:not(.result-step)')[current - 1];
const inputs = currentStepEl.querySelectorAll('input[type="radio"], input[type="checkbox"]');
let answered = false;
inputs.forEach(input => {
if (input.checked) answered = true;
});
if (!answered) {
alert('Пожалуйста, выберите вариант ответа');
return;
}
if (current < totalSteps) {
showStep(current + 1);
}
}
function prevStep(current) {
if (current > 1) {
showStep(current - 1);
}
}
function submitTest() {
const resultsDiv = document.getElementById('test-results');
const answers = {
disability: document.querySelector('input[name="disability"]:checked'),
work: document.querySelector('input[name="work"]:checked'),
location: document.querySelector('input[name="location"]:checked'),
income: document.querySelector('input[name="income"]:checked'),
housing: document.querySelector('input[name="housing"]:checked'),
tsr: document.querySelectorAll('input[name="tsr"]:checked'),
employment: document.querySelector('input[name="employment"]:checked'),
children: document.querySelector('input[name="children"]:checked'),
legal: document.querySelector('input[name="legal"]:checked'),
volunteer: document.querySelector('input[name="volunteer"]:checked')
};
let results = [];
if (answers.disability && answers.disability.value !== 'none') {
results.push({
title: 'Пенсия по инвалидности',
desc: 'Положена всем гражданам с инвалидностью. Размер зависит от группы.'
});
results.push({
title: 'Ежемесячная выплата (ЕДВ)',
desc: 'Дополнительная выплата для отдельных категорий.'
});
}
if (answers.income && answers.income.value === 'low') {
results.push({
title: 'Материальная помощь',
desc: 'Единовременная выплата в трудной жизненной ситуации.'
});
}
if (answers.housing && answers.housing.value === 'yes') {
results.push({
title: 'Субсидия на оплату ЖКУ',
desc: 'Компенсация до 50% расходов на коммунальные услуги.'
});
results.push({
title: 'Программа доступного жилья',
desc: 'Постановка в очередь на социальное жильё.'
});
}
if (answers.tsr && answers.tsr.length > 0) {
results.push({
title: 'Технические средства реабилитации',
desc: 'Бесплатное получение колясок, протезов и других ТСР.'
});
}
if (answers.employment && answers.employment.value === 'yes') {
results.push({
title: 'Содействие в трудоустройстве',
desc: 'Квоты для людей с инвалидностью, программы переобучения.'
});
}
if (answers.volunteer && answers.volunteer.value !== 'no') {
results.push({
title: 'Волонтёрская поддержка',
desc: 'Помощь волонтёров в быту, сопровождении, транспорте.'
});
}
if (answers.children && answers.children.value === 'yes') {
results.push({
title: 'Пособие на детей',
desc: 'Дополнительные выплаты на детей в семье.'
});
}
if (answers.legal && answers.legal.value === 'yes') {
results.push({
title: 'Юридическая помощь',
desc: 'Бесплатные консультации юриста по вопросам инвалидности.'
});
}
if (results.length === 0) {
results.push({
title: 'Обратитесь в центр соцзащиты',
desc: 'Специалисты подберут индивидуальную программу поддержки.'
});
}
resultsDiv.innerHTML = results.map(r =>
'<div class="result-item"><h4>' + r.title + '</h4><p>' + r.desc + '</p></div>'
).join('');
const steps = document.querySelectorAll('.form-step:not(.result-step)');
steps.forEach(s => s.classList.remove('active'));
document.querySelector('.result-step').classList.add('active');
}
function resetTest() {
const form = document.getElementById('test-form');
form.reset();
showStep(1);
}
if (window.location.hash) {
setTimeout(function() {
const element = document.querySelector(window.location.hash);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
}
}, 100);
}