(function () { const COOKIE_KEY = 'lang'; const LS_KEY = 'lang'; const ONE_YEAR = 60 * 60 * 24 * 365; // ¡Ú ¸ÞÀÎ ÆäÀÌÁö(Ȩ) °æ·Î: ÇÊ¿äÇϸé "/default/index.php" µîÀ¸·Î ±³Ã¼ const HOME_URL = "/"; // cookie helpers function getCookie(name) { const m = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)')); return m ? decodeURIComponent(m[1]) : null; } function setCookie(name, value, maxAge) { document.cookie = name + '=' + encodeURIComponent(value) + '; path=/; max-age=' + maxAge + '; SameSite=Lax'; } // Ãʱ⠾ð¾î (ÄíŰ > ·ÎÄýºÅ丮Áö > ±âº» KOR) const initialLang = getCookie(COOKIE_KEY) || localStorage.getItem(LS_KEY) || 'KOR'; // ¾ð¾îº° URL ¸ÅÇÎ (location.pathname ½ÇÁ¦ °ª°ú µ¿ÀÏÇÏ°Ô ÀÛ¼ºÇØ¾ß ÇÔ) const URL_MAP = { "/default/face/sub01.php": "/default/face/sub01.php", "/default/face/sub02.php": "/default/face/TMJ.php", "/default/face/sub03.php": "/default/face/FNP.php", "/default/face/sub04.php": "/default/face/TN.php", "/default/diet/sub01.php": "/default/diet/dietEn.php", "/default/about/01.php": "/default/basic/01.php", "/default/health/sub01.php": "/default/Acupuncture/acupuncture.php", "/default/woman/sub01.php": "/default/Acupuncture/acupuncture.php", // ÇÊ¿ä ½Ã Ãß°¡ }; // ¸ðµç ÄÄÆ÷³ÍÆ® ÃʱâÈ­ function initDropdown(root) { const wrap = root.querySelector('.lang-select'); const native = root.querySelector('.lang-native'); // ¼û°ÜÁø select if (!wrap || !native) return; const trigger = wrap.querySelector('.lang-trigger'); const current = wrap.querySelector('.lang-current'); const list = wrap.querySelector('.lang-list'); const items = Array.from(list.querySelectorAll('li')); // select¿Í ¸®½ºÆ® °ªÀ» µ¿±âÈ­ function sync(val) { const matchItem = items.find(li => li.getAttribute('data-value') === val); if (matchItem) { current.textContent = matchItem.textContent.trim(); items.forEach(x => x.classList.toggle('is-active', x === matchItem)); } native.value = val; } // open/close const open = () => { wrap.dataset.open = 'true'; trigger.setAttribute('aria-expanded', 'true'); }; const close = () => { wrap.dataset.open = 'false'; trigger.setAttribute('aria-expanded', 'false'); }; const toggle= () => { (wrap.dataset.open === 'true') ? close() : open(); }; // ÃÖÃÊ µ¿±âÈ­(ÄíŰ/LS ±âÁØ) sync(initialLang); // ¿­±â/´Ý±â trigger.addEventListener('click', (e) => { e.stopPropagation(); toggle(); }); // Ç׸ñ Ŭ¸¯ items.forEach(li => { li.addEventListener('click', (e) => { const val = li.getAttribute('data-value'); sync(val); // ÄíŰ/LS ÀúÀå setCookie(COOKIE_KEY, val, ONE_YEAR); localStorage.setItem(LS_KEY, val); // change À̺¥Æ® (±âÁ¸ ÄÚµå¿ÍÀÇ È£È¯) native.dispatchEvent(new Event('change', { bubbles: true })); // === URL ¸ÅÇΠó¸® (+ ¸ÅÇÎ ¾øÀ¸¸é ȨÀ¸·Î) === const path = location.pathname; // ¿¹: "/default/face/sub02.php" if (val === 'EN') { if (URL_MAP[path]) { location.href = URL_MAP[path]; // KOR ¡æ EN ¸ÅÇÎ return; } else { location.href = HOME_URL; // ¸ÅÇÎ ¾øÀ¸¸é Ȩ return; } } if (val === 'KOR') { const back = Object.entries(URL_MAP).find(([kor, en]) => en === path); if (back) { location.href = back[0]; // EN ¡æ KOR ¸ÅÇÎ return; } else { location.href = HOME_URL; // ¸ÅÇÎ ¾øÀ¸¸é Ȩ return; } } // === ³¡ === // (¿©±â±îÁö ¸ø ¿ÔÀ¸¸é) ¸ÅÇÎ ¾øÀ» ¶§ ±âÁ¸Ã³·³ »õ·Î°íħ location.reload(); }); }); // ¿ÜºÎ Ŭ¸¯ ´Ý±â document.addEventListener('click', close); // Űº¸µå Á¢±Ù¼º trigger.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggle(); } if (e.key === 'Escape') close(); if (e.key === 'ArrowDown') { e.preventDefault(); open(); (items[0] || trigger).focus?.(); } }); // ¿ÜºÎ ½ºÅ©¸³Æ®°¡ native °ªÀ» ¹Ù²Ü °æ¿ì µ¿±âÈ­ native.addEventListener('change', () => sync(native.value)); } // ÆäÀÌÁö ³» ¸ðµç lang-select-wrap ÃʱâÈ­ function boot() { document.querySelectorAll('.lang-select-wrap').forEach(initDropdown); } (document.readyState === 'loading') ? document.addEventListener('DOMContentLoaded', boot) : boot(); })();