//---------------------------------------------------- // 쓰로틀링, 디바운스 //---------------------------------------------------- /* * jQuery throttle / debounce - v1.1 - 3/7/2010 * http://benalman.com/projects/jquery-throttle-debounce-plugin/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this); //---------------------------------------------------- // GNB //---------------------------------------------------- function getHighestNavi(){ var height = 0; $('.depth2').each(function(i, v){ if ($(this).outerHeight() > height) height = $(this).outerHeight() + 10; }); return height; } function setHighestNavi(){ var naviHeight = getHighestNavi(); $('.navigation-back').css('height', naviHeight); } setHighestNavi(); // 로드시 세팅 $(document).on('mousemove touchstart', $.throttle(60, function(e){ var $target = $(e.target); //열릴 때 if($target.closest('.depth1-li').length) { $('.header').addClass('opened'); setHighestNavi(); } //닫힐 때 if(!$target.closest('.navigation').length && !$target.closest('.navigation-back').length) { $('.header').removeClass('opened'); } })); //---------------------------------------------------- // 모바일 클래스 //---------------------------------------------------- $(function(){ function setMobileSize(){ var winWidth = $(window).width(); if (winWidth > 1024) $('body').removeClass('is-mobile'); else $('body').addClass('is-mobile'); } $(window).on('load resize', function(){ setMobileSize(); }); // $('.sub-more a').on('click', function(e){ // alert() // // $('.is-mobile .sub-more').child('.bc-a').on('click', function(e){ // e.preventDefault(); // }); }); //---------------------------------------------------- // 모바일 테이블 처리 //---------------------------------------------------- var win = jQuery(window), prev_width = win.width(), prev_height = win.height(); win.on('resize', function () { var width = win.width(), height = win.height(); if (width !== prev_width) { win.trigger('hresize'); } if (height !== prev_height) { win.trigger('vresize'); } prev_width = width; prev_height = height; }); function resizeTable(){ $('.table-wrapper').removeClass('actived'); overflowTable(); } function overflowTable(){ $('.table-scrollable').each(function(){ var $this = $(this); var wrapWidth = $this.outerWidth(); var table = $this.find('table'); var tableWidth = table.outerWidth(); if (wrapWidth < tableWidth) $this.closest('.table-wrapper').addClass('overflow'); else $this.closest('.table-wrapper').removeClass('overflow'); }); } overflowTable(); $(window).on('hresize', function(){ resizeTable(); }); $('.table-overlay').click(function(){ $(this).closest('.table-wrapper').addClass('actived'); }); //---------------------------------------------------- // GNB //---------------------------------------------------- // on scroll hide/show menu var header = $('.header'); //---------------------------------------------------- // 레이어 팝업시 BODY 스크롤 고정 //---------------------------------------------------- var currentScrollPosition = 0; $(window).scroll(function(){ currentScrollPosition = $(window).scrollTop(); }); function fixedBody(){ $body = $('body'); $body.addClass('fixed').css('top', '-' + currentScrollPosition + 'px'); } function relativeBody(){ $body = $('body'); var getScrollPosition = $body.css('top'); var keepScrollPosition = getScrollPosition.match(/(\d+)/); var resultScrollPosition = parseInt(keepScrollPosition[0]); $body.removeClass('fixed').removeAttr('style'); $(window).scrollTop(resultScrollPosition); } //---------------------------------------------------- // 모바일 메뉴 토클 //---------------------------------------------------- $(document).on('click', '.btn-hamburg', function(){ var $el = $('.wrap').toggleClass('navi-opened'); if ($el.hasClass('navi-opened')) fixedBody(); else relativeBody(); }); $(document).on("click", ".offcanvas-closer", function() { $(".wrap").removeClass("navi-opened"); relativeBody(); }), $(document).on("click", ".gnb-mb .depth1-li", function() { var e = $(".depth2-wrapper") , t = $(this).find(".depth2-wrapper") , n = $(this).find(".depth2").outerHeight(); e.removeAttr("style"), $(this).hasClass("actived") ? (t.removeAttr("style"), $(this).removeClass("actived")) : (t.css("height", n + "px"), $(this).addClass("actived").siblings().removeClass("actived")) }), $(document).ready(function() { $(".gnb-mb").find(".depth1-li").each(function() { if ($(this).hasClass("current")) { var e = $(this).find(".depth2") , t = $(this).find(".depth2-wrapper") , n = e.outerHeight(); t.css("height", n + "px"); $(this).addClass('actived'); return false; } }) });