74 lines
2.4 KiB
JavaScript
74 lines
2.4 KiB
JavaScript
// recall.js - Скрипты для страницы отзывов
|
|
function openModal(imageUrl, title) {
|
|
console.log('Opening modal with:', imageUrl);
|
|
const modal = document.getElementById('imageModal');
|
|
const modalImg = document.getElementById('modalImage');
|
|
const modalTitle = document.getElementById('modalTitle');
|
|
|
|
if (modal && modalImg) {
|
|
modal.style.display = "block";
|
|
modalImg.src = imageUrl;
|
|
if (title && modalTitle) {
|
|
modalTitle.textContent = title;
|
|
}
|
|
|
|
// Добавляем класс для анимации
|
|
setTimeout(() => {
|
|
modal.classList.add('active');
|
|
}, 10);
|
|
|
|
// Подстраиваем размер изображения
|
|
adjustModalImageSize();
|
|
}
|
|
}
|
|
|
|
function closeModal() {
|
|
const modal = document.getElementById('imageModal');
|
|
if (modal) {
|
|
modal.classList.remove('active');
|
|
setTimeout(() => {
|
|
modal.style.display = "none";
|
|
}, 300);
|
|
}
|
|
}
|
|
|
|
function adjustModalImageSize() {
|
|
const modalImg = document.getElementById('modalImage');
|
|
const modalContent = document.querySelector('.modal-content');
|
|
|
|
if (modalImg && modalContent) {
|
|
const maxWidth = window.innerWidth * 0.9;
|
|
const maxHeight = window.innerHeight * 0.8;
|
|
|
|
modalImg.style.maxWidth = `${maxWidth}px`;
|
|
modalImg.style.maxHeight = `${maxHeight}px`;
|
|
}
|
|
}
|
|
|
|
// Инициализация после загрузки DOM
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Закрытие модального окна при клике вне изображения
|
|
document.addEventListener('click', function(event) {
|
|
const modal = document.getElementById('imageModal');
|
|
if (event.target === modal) {
|
|
closeModal();
|
|
}
|
|
});
|
|
|
|
// Закрытие по ESC
|
|
document.addEventListener('keydown', function(event) {
|
|
if (event.key === 'Escape') {
|
|
closeModal();
|
|
}
|
|
});
|
|
|
|
// Адаптация размера изображения при изменении размера окна
|
|
window.addEventListener('resize', function() {
|
|
const modalImg = document.getElementById('modalImage');
|
|
if (modalImg && modalImg.src) {
|
|
adjustModalImageSize();
|
|
}
|
|
});
|
|
|
|
console.log('Recall page scripts initialized');
|
|
}); |