// ๐ก [ํต์ฌ ์์ ] ๋ชจ๋ ๋ก์ง์ ์ด๊ธฐํ ํจ์ ์์ผ๋ก ์ฎ๊ธฐ๊ณ , ๋ชจ๋์ ๊ณ ์ ID๋ฅผ ์ธ์๋ก ๋ฐ๋๋ก ๋ณ๊ฒฝํฉ๋๋ค.
function initTechSectionModule(moduleId) {
// ๐ก [ํต์ฌ ์์ ] document๊ฐ ์๋, ์ ๋ฌ๋ฐ์ moduleId๋ฅผ ๊ธฐ์ค์ผ๋ก ์์๋ฅผ ์ฐพ์ต๋๋ค.
const moduleElement = document.getElementById(moduleId);
if (!moduleElement) return;
// ์ด๋ฏธ ์ด๊ธฐํ๋ ๋ชจ๋์ ๋ค์ ์คํํ์ง ์์ต๋๋ค.
if (moduleElement.classList.contains('initialized')) {
return;
}
const section = moduleElement.querySelector('.products-trend-section');
const patentGrid = moduleElement.querySelector('.product-grid');
const modal = moduleElement.querySelector('.image-modal');
if (!section || !patentGrid || !modal) {
console.error('Module elements not found in:', moduleId);
return;
}
/**
* ๊ทธ๋ฆฌ๋์ ํนํ ์นด๋๋ฅผ ๋ ๋๋งํ๋ ํจ์
*/
function renderGrid() {
const patentsJson = section.dataset.patents;
let patentsData;
try {
patentsData = JSON.parse(patentsJson);
} catch (e) {
patentGrid.innerHTML = '
๊ธฐ์ ์๋ฃ๋ฅผ ๋ถ๋ฌ์ค๋ ๋ฐ ์คํจํ์ต๋๋ค.
';
return;
}
if (!patentsData || patentsData.length === 0) {
patentGrid.innerHTML = 'ํ์ํ ๊ธฐ์ ์๋ฃ๊ฐ ์์ต๋๋ค.
';
return;
}
const patentCardsHTML = patentsData.map(item => `
${item.title}
${item.description}
`).join('');
patentGrid.innerHTML = patentCardsHTML;
}
/**
* ๋ชจ๋ฌ ๊ด๋ จ ์ด๋ฒคํธ๋ฅผ ์ค์ ํ๋ ํจ์
*/
function setupModalEvents() {
const modalImage = modal.querySelector('.modal-image');
const modalTitle = modal.querySelector('.modal-title');
const modalDesc = modal.querySelector('.modal-desc');
const closeBtn = modal.querySelector('.close-btn');
// ๋ชจ๋ฌ ์ด๊ธฐ (์ด๋ฒคํธ ์์)
patentGrid.addEventListener('click', function(event) {
const card = event.target.closest('.js-modal-trigger');
if (card) {
modalImage.src = card.dataset.img;
modalTitle.textContent = card.dataset.title;
modalDesc.textContent = card.dataset.desc;
modal.classList.add('is-active');
}
});
// ๋ชจ๋ฌ ๋ซ๊ธฐ ํจ์
function closeModal() {
modal.classList.remove('is-active');
}
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก
closeBtn.addEventListener('click', closeModal);
modal.addEventListener('click', function(event) {
if (event.target === modal) closeModal();
});
// ESC ํค ์ด๋ฒคํธ๋ document์ ๋ฑ๋กํด์ผ ํ๋ฏ๋ก, ๋ชจ๋ฌ์ด ํ์ฑํ ์ํ์ผ ๋๋ง ๋์ํ๋๋ก ์กฐ๊ฑด ์ถ๊ฐ
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape' && modal.classList.contains('is-active')) {
closeModal();
}
});
}
// ํจ์ ์คํ
renderGrid();
setupModalEvents();
// ์ด๊ธฐํ ์๋ฃ ํด๋์ค ์ถ๊ฐ
moduleElement.classList.add('initialized');
}
// ๐ก [ํต์ฌ ์์ ] ๋ค๋ฅธ ๊ณณ์์ ์ด ํจ์๋ฅผ ๋ค์ ํธ์ถํ ์ ์๋๋ก ์ ์ญ์ ๋
ธ์ถ์ํต๋๋ค.
window.initTechSectionModule = initTechSectionModule;