$(function () { // depth02 없는 메뉴에 no-depth 추가 $(".depth01").each(function () { var $submenu = $(this).find(".depth02"); if ($submenu.length == 0 || $submenu.find("li").length == 0) { $(this).addClass("no-depth"); } }); $(".depth02").slideUp(0); setTimeout(function(){ $(".on .depth02").slideDown(0); },100) $(".depth01.on").each(function () { var $submenu = $(this).find(".depth02"); if ($submenu.find("li").length > 0) { $submenu.slideDown(0); $(this).find(".menu_title").attr("title", "하위메뉴 닫기"); } }); $(".menu_title").on("click", function () { var $parent = $(this).closest(".depth01"); var $submenu = $parent.find(".depth02"); var hasDepth02 = $submenu.find("li").length > 0; var url = "/cmm/main/mainPage.do"; var titleText = $(this).text().trim().toLowerCase(); // dashboard는 무조건 바로 이동 if (titleText === "dashboard") { if (url) location.href = url; return; } // depth02 없는 메뉴는 바로 이동 if (!hasDepth02) { // if (url) location.href = url; return; } // depth02 있는 경우 슬라이드 if ($parent.hasClass("on")) { $submenu.slideUp(300); $parent.removeClass("on"); $(this).attr("title", "하위메뉴 열기"); } else { $(".depth01").removeClass("on").find(".depth02").slideUp(300); $(".menu_title").attr("title", "하위메뉴 열기"); $parent.addClass("on"); $submenu.slideDown(300); $(this).attr("title", "하위메뉴 닫기"); } }); });