Site/static/programmer/js/competence.js

73 lines
2.4 KiB
JavaScript

// competence.js - Скрипты для страницы компетенций
function openCompetenceModal(imageUrl, title) {
console.log('Opening competence modal with:', imageUrl);
const modal = document.getElementById('competenceModal');
const modalImg = document.getElementById('competenceModalImage');
const modalTitle = document.getElementById('competenceModalTitle');
if (modal && modalImg) {
modal.style.display = "block";
modalImg.src = imageUrl;
if (title && modalTitle) {
modalTitle.textContent = title;
}
// Добавляем класс для анимации
setTimeout(() => {
modal.classList.add('active');
}, 10);
// Подстраиваем размер изображения
adjustCompetenceModalImageSize();
}
}
function closeCompetenceModal() {
const modal = document.getElementById('competenceModal');
if (modal) {
modal.classList.remove('active');
setTimeout(() => {
modal.style.display = "none";
}, 300);
}
}
function adjustCompetenceModalImageSize() {
const modalImg = document.getElementById('competenceModalImage');
if (modalImg) {
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('competenceModal');
if (event.target === modal) {
closeCompetenceModal();
}
});
// Закрытие по ESC
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
closeCompetenceModal();
}
});
// Адаптация размера изображения при изменении размера окна
window.addEventListener('resize', function() {
const modalImg = document.getElementById('competenceModalImage');
if (modalImg && modalImg.src) {
adjustCompetenceModalImageSize();
}
});
console.log('Competence page scripts initialized');
});