$(function () { /* ================================================== container.sub 클래스 (있을 때만) ================================================== */ const $container = $(".container.sub"); const section = $("h2.sub_title").data("section"); if ($container.length && section) { $container .removeClass("company major_result platform_tech") .addClass(section); } /* ================================================== src 경로 보정 ================================================== */ $("[src]").each(function () { const src = $(this).attr("src"); if (src && src.startsWith("../")) { $(this).attr("src", src.replace(/^\.\.\//, "/publish/usr/")); } }); /* ================================================== Sub Visual SNB 기본 세팅 ================================================== */ $(".icon.home").closest("a").attr("href", "/web/main/mainPage.do"); const $wraps = $(".sub_visual_nav .snb_wrap"); if ($wraps.length < 2) return; const $snbDepth01 = $wraps.eq(0).find(".snb_select"); const $snbDepth02 = $wraps.eq(1).find(".snb_select"); if ($snbDepth01.data("init")) return; $snbDepth01.data("init", true); const params = new URLSearchParams(location.search); const proFn = params.get("proFn"); const bbsId = params.get("bbsId"); const pathname = location.pathname; const isCommunity = pathname.includes("/bbsWeb/"); const isCommunityDetail = pathname.includes("selectBoardDetail.do"); const $gnb = $(".gnb").first(); /* ================================================== 현재 depth01 / depth02 결정 ================================================== */ let $currentDepth01Li = $(); let $currentDepth02 = $(); if (isCommunity) { $currentDepth01Li = $gnb.find("> li").filter(function () { return $(this).find("> .depth01").text().trim().toLowerCase() === "community"; }).first(); } else if (proFn) { $currentDepth02 = $gnb.find(`.depth02[href*="proFn=${proFn}"]`).first(); $currentDepth01Li = $currentDepth02.closest(".depth02_container").closest("li"); } if (!$currentDepth01Li.length) { $currentDepth01Li = $gnb.find("> li").first(); } const currentDepth01Text = $currentDepth01Li.find("> .depth01").text().trim(); /* ================================================== SNB depth01 생성 (대표 링크 = 첫 depth02) ================================================== */ $snbDepth01.empty(); $gnb.find("> li").each(function () { const text = $(this).find("> .depth01").text().trim(); if (!text) return; const firstHref = $(this).find(".depth02").first().attr("href") || "#"; const isActive = text === currentDepth01Text; $snbDepth01.append(`
  • ${text}
  • `); }); /* ================================================== SNB depth02 생성 + active 처리 ================================================== */ $snbDepth02.empty(); $currentDepth01Li.find(".depth02").each(function (index) { const href = $(this).attr("href"); const text = $(this).text().trim(); let isActive = false; if (!isCommunity && proFn) { isActive = href.includes(`proFn=${proFn}`); } if (isCommunity && bbsId) { isActive = href.includes(`bbsId=${bbsId}`); } if (isCommunityDetail) { isActive = index === 1; } $snbDepth02.append(`
  • ${text}
  • `); }); /* ================================================== SNB 타이틀 ================================================== */ $wraps.eq(0).find(".snb_title").text(currentDepth01Text || "메뉴"); if (isCommunityDetail) { const firstText = $currentDepth01Li.find(".depth02").first().text().trim(); $wraps.eq(1).find(".snb_title").text(firstText || "메뉴"); } else { const activeText = $snbDepth02.find("li.active a").text(); $wraps.eq(1).find(".snb_title").text(activeText || "메뉴"); } /* ================================================== SNB 토글 ================================================== */ $(".snb_title").on("click", function () { const $wrap = $(this).closest(".snb_wrap"); $(".snb_wrap").not($wrap) .removeClass("active") .find(".snb_select").slideUp(200); $wrap.toggleClass("active") .find(".snb_select").stop(true, true).slideToggle(250); }); /* ================================================== depth01 클릭 시 첫 depth02 이동 ================================================== */ $snbDepth01.on("click", "a", function (e) { e.preventDefault(); location.href = $(this).attr("href"); }); /* ================================================== 외부 클릭 시 닫기 ================================================== */ $(document).on("click", function (e) { if (!$(e.target).closest(".snb_wrap").length) { $(".snb_wrap") .removeClass("active") .find(".snb_select") .slideUp(200); } }); });