var MAIN_LAYOUT_CASE = 1920; function id(a){return document.getElementById(a);} function getTarget(a){return a.getElementsByTagName("a")[0].href.split("#")[1];} function skipTextNodes(list){var i = 0, arr = [];for(; i < list.length; i++){if(list[i].nodeType == 1){arr.push(list[i]);}}return arr;} $(function(){ var ui = MADEWEB.UI, api = MADEWEB.API, util = MADEWEB.UTIL, wj = WOONGJIN; wj.gnb(); }); //ui namespace var MADEWEB = {}; var WOONGJIN = {}; WOONGJIN = { gnb : function(){ var gnb = $("#gnb"), ul = $(".depth1 > ul", gnb), old_li = li = $("li", ul), a = $("a", ul), m = $(".m_nav, .m_nav_close", "#header"), m_state = true, cnt = 0, dep2, dep2_before = null, dep3, dep3_before = null, dep2_h, dep3_h, default_active = ul.find(".depth2 li.on"); while(ul.find("li").size() > 0){ cnt++; ul.find("li").attr("stack","dep" + cnt); ul = ul.find("ul"); } var stack = {}; a.bind("click",function(e){ var e = e || window.event; e.stopPropagation(); if(this.parentNode.className == "on"){ resizing($(this).next(), 0); dep3_before = null; this.parentNode.className = ""; return false; }else{ if($(this).next().attr("class") == "depth3"){ default_active.removeClass("on"); resizing(default_active.find(".depth3"), 0); } if(document.body.clientWidth < 1920){//테블릿~모바일 경우... var my = $(this).parent(); if(my.attr("stack") == "dep1" && my[0].getElementsByTagName("ul")[0]){ dep2 = my.find(".depth2"); dep2_h = dep2.find(" > ul").height() + 2; if(dep2_before == null){ resizing(dep2, dep2_h); dep2_before = dep2; }else{ if(dep2[0] === dep2_before[0]){ resizing(dep2, 0); dep2_before = null; }else{ resizing(dep2, dep2_h); resizing(dep2_before, 0); dep2_before = dep2; } } if(dep3 != undefined){ dep3.css("height",0); dep3_before = null; } }else if(my.attr("stack") == "dep2" && my[0].getElementsByTagName("ul")[0]){ dep3 = my.find(".depth3"); dep3_h = dep3.find(" > ul").height() + 20; if(dep3_before == null){ resizing(dep2, dep2_h + dep3_h); resizing(dep3, dep3_h); dep3_before = dep3; }else{ if(dep3[0] === dep3_before[0]){ resizing(dep3, 0); resizing(dep2, dep2_h); dep3_before = null; }else{ resizing(dep2, dep2_h + dep3_h); resizing(dep3, dep3_h); resizing(dep3_before, 0); dep3_before = dep3; } } } }else{//pc 화면일 경우 var my = $(this).parent(); if(my.attr("stack") == "dep2" && my[0].getElementsByTagName("ul")[0]){ dep3 = my.find(".depth3"); dep3_h = dep3.find(" > ul").height() + 20; if(dep3_before == null){ resizing(dep3, dep3_h); dep3_before = dep3; }else{ if(dep3[0] === dep3_before[0]){ resizing(dep3, 0); dep3_before = null; }else{ resizing(dep3, dep3_h); resizing(dep3_before, 0); dep3_before = dep3; } } } } } function resizing(a, b, c){ a.stop().animate({ "height" : b + "px" }); } if(stack[$(this).parent().attr("stack")] != undefined){ if(stack[$(this).parent().attr("stack")][0] === this.parentNode){ if(this.parentNode.className.length > 0){ this.parentNode.className = ""; }else{ this.parentNode.className = "on"; } }else{ stack[$(this).parent().attr("stack")].removeClass("on"); this.parentNode.className = "on"; } }else{ this.parentNode.className = "on"; } stack[$(this).parent().attr("stack")] = $(this).parent(); }); $(document.body).click(function(e){ if(document.body.clientWidth >= 1023){ for(var i in stack){ if(i != "dep2"){ stack[i].removeClass("on"); } } } }); m.click(function(e){ if(m_state == false) return false; m_state = false; e.stopPropagation(); var w, o; gnb.css("height",document.body.clientHeight + "px").find(" > ul").css("height",document.body.clientHeight + "px"); //모바일에서 gnb를 열때 높이를 최대 사이즈로 고정(플로팅바로 만들기) if(parseInt(gnb.css("right"),10) <= -2){ w = 0; o = 1; m.eq(1).show(); createDimd(); }else{ w = -237; o = 0; m.eq(1).hide(); removeDimd(); } gnb.animate({ "right" : w + "px" },{ complete : function(){ m_state = true; } }); m.eq(1).css({ "opacity" : o }); }); }, gnb_reset : function(dir){//해상도 변경시 gnb 리셋 var gnb = $("#gnb"), ul = $(" > .depth1 > ul", gnb), li = $("li", ul); li.removeClass("on"); if(dir == "to_pc"){//해상도 변경시 pc로 갈때... gnb.css("height","auto").find(".depth2").css("height","auto").find(".depth3").css("height", 0 + "px");//gnb의 높이를 자동으로 }else if(dir == "to_tablet"){//해상도 변경시 태블릿으로 갈때... gnb.css("height",document.body.clientHeight + "px").find(".depth2, .depth3").css("height", 0 + "px");//gnb 높이를 최대 사이즈로 고정(플로팅바로 만들기) }else{} //this.gnb(); }, } function imgCenter(arg){ if(!id(arg["valid"])) return false; var imgs = $(arg["selector"]); imgs.each(function(){ $(this).css("margin-left", -($(this).width() / 2) + "px"); }); } function createDimd(){ var dimd, h, t; if(id("dimdLayer")){ dimd = id("dimdLayer"); }else{ dimd = document.createElement("div"); dimd.id = dimd.className = "dimdLayer"; document.body.appendChild(dimd); } dimd.style.top = 0 + "px"; dimd.style.height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight) - 0 + "px"; $(dimd).fadeIn(500); } function removeDimd(){ if(!id("dimdLayer")) return false; document.body.removeChild(id("dimdLayer")); } function wow_ready(src){ var layer, dimd; $(layer).bind("click",function(){ document.body.removeChild(dimd); document.body.removeChild(layer); }); }