$(function(){ console.log('??!!???'); const currentPath = window.location.pathname; console.log(currentPath); if (currentPath !== '/web/main/mainPage.do') { if (currentPath === '/web/content.do') { fn_getSubMenu(); } } $(document).on("click", ".snb_title", 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); }); $(document).on("click", function (e) { if (!$(e.target).closest(".snb_wrap").length) { $(".snb_wrap") .removeClass("active") .find(".snb_select") .slideUp(200); } }); }); function fn_getSubMenu(){ var title = $('#container .sub_title').text(); var subTitle; var depth3Title = $.trim($('.content_title').text()); $(".header_container .depth03").each(function(idx, itm){ let text = $.trim($(itm).text()); if(depth3Title === text){ subTitle = $(itm).closest(".depth03_ul").siblings(".depth02").text(); subTitle = $.trim(subTitle); return false; }else{ subTitle = depth3Title; } }); var sendData = { "depth1MenuNm" : title, "depth2MenuNm" : subTitle, "depth3MenuNm" : depth3Title } console.log('title ::', title); console.log('subTitle ::', subTitle); console.log('depth3Title ::', depth3Title); $.ajax({ type: 'POST', url: "/web/com/subMenu.do", contentType: 'application/json', data: JSON.stringify(sendData), dataType: 'json', success: function(data) { console.log(data); if(data.status == 'OK'){ renderSubVisualNav(data); } }, error: function(err) { console.error(err); } }); setTimeout(function(){ $(".snb_select li a").each(function(idx,itm){ $(".header_container .gnb a").each(function(index,item){ var itemUrl = $(item).attr("href"); if($(itm).text().trim() == $(item).text().trim()){ $(itm).attr("href",itemUrl); } }) }) },1000) } // AJAX 성공 시 호출되는 함수 내부 function renderSubVisualNav(res) { const result = res.data || res; // res.data가 있으면 쓰고, 없으면 res 자체를 사용 const depth1List = result.depth1List || []; // 데이터가 없으면 빈 배열로 초기화 const depth2List = result.depth2List || []; const depth3List = result.depth3List || []; const selected1 = result.selectedDepth1; const selected2 = result.selectedDepth2; const selected3 = result.selectedDepth3; let html = ''; // 1. 기본 홈 아이콘 html += ''; // 2. 1Depth 메뉴 생성 if (depth1List.length > 0) { // 리스트가 있을 때만 실행 html += '