jQuery(function () { 'use strict'; /* Widscreen Widget Toggle */ (function toggleWidget () { var $body = $('body'); $(document).on('click', '.js-toggle-widget', function () { $body.toggleClass('is-widget-collapse'); }) .on('click', '.js-open-widget', function () { $body.removeClass('is-widget-collapse'); setTimeout(function () { $('.widget').find('a, button, input, select').get(0).focus(); }, 100); }) .on('click', '.js-close-widget', function () { $body.addClass('is-widget-collapse'); setTimeout(function () { $('.js-open-widget')[0].focus(); }, 100); }); }()); /* Mobile Side Navigation Toggle */ (function toggleMobileGNB () { var $body = $('body'); $(document).on('click', '.js-open-menu',function (e) { e.preventDefault(); $body.addClass('is-open-side-nav'); $(this).attr('aria-expanded', true); $('.js-close-menu').attr('aria-expanded', true); }) .on('click', '.js-close-menu', function (e) { e.preventDefault(); $body.removeClass('is-open-side-nav'); $(this).attr('aria-expanded', false); $('.js-open-menu').attr('aria-expanded', false); }); }()); /* 맨위로 가기 버튼 설정 */ (function setGotoTop () { $('.btn-goto-top').on('click', function (e) { e.preventDefault(); $('html, body').stop().animate({'scrollTop': 0}, 200); }); }()); /* 모달 팝업 설정 */ (function setModalPopup () { /* 모달 팝업 열기 */ window.openPopup = function (id, startEl) { var $target = $(id); var $startEl = (startEl ? $(startEl) : ''); var instance = $target.find('.os-host').overlayScrollbars(); if ($target.length) { if ($startEl) { $startEl.addClass('is-trigger'); } $('body').addClass('has-modal').css('overflow', 'hidden'); if (id.indexOf('surveyPopup') > -1) { $('body').css('overflow', ''); } $target.addClass('open').find('a, input, select, textarea, button').first().get(0).focus(); setTimeout(function () { if (instance) { instance.update(); } }, 100); setTimeout(function () { if ($target.find('.slick-slider').length) { $target.find('.slick-slider').addClass('show').slick('setPosition'); } }, 1000); } }; /* 모달 팝업 닫기 */ window.closePopup = function (id) { var $target = $(id); var $beforeBtn = $('.is-trigger'); if ($target.length) { $target.removeClass('open'); $('body').removeClass("has-modal").css('overflow', ''); if ($beforeBtn.length) { $beforeBtn.removeClass('is-trigger').get(0).focus(); } } }; /* 기타 이벤트 */ $(document).on('click', '.js-open-popup', function (e) { e.preventDefault(); openPopup($(this).attr('href'), this); }) .on('click', '.js-close-popup', function (e) { e.preventDefault(); closePopup('#' + $(this).closest('.layer-popup').attr('id')); }) .on('keydown', '.has-modal .layer-popup', function (e) { var $modal = $(this); var keycode = e.keycode || e.which; var current = e.target || e.srcElement; var firstEl = $modal.find('a, input, select, textarea, button').first().get(0) || null; var lastEl = $modal.find('a, input, select, textarea, button').last().get(0) || null; switch(keycode) { case 27: // esc key closePopup('#' + $(this).attr('id')); break; case 9: // tab key if (lastEl && current === lastEl && !e.shiftKey) { e.preventDefault(); firstEl.focus(); } if (firstEl && current === firstEl && e.shiftKey ) { e.preventDefault(); lastEl.focus(); } break; default: } }); }()); /* Toggle Box */ (function toggleItem () { $(document).on('click', '.js-toggle-content', function (e) { e.preventDefault(); var $this = $(this); var target = $this.attr('href'); var $wrap = $(this).parent(); var item = $wrap.find('.os-host').overlayScrollbars(); if (!target) { return false; } if (item) { item.update(); } $wrap.toggleClass('is-expanded'); if ($wrap.hasClass('is-expanded')) { $this.attr('aria-expanded', true); } else { $this.attr('aria-expanded', false); } }) .on('mouseover', '.js-toggle-content', function (e) { e.preventDefault(); if ($(this).hasClass('btn-notify') || window.innerWidth < 1024) return; var $this = $(this); var target = $this.attr('href'); var $wrap = $(this).parent(); var item = $wrap.find('.os-host').overlayScrollbars(); if (!target) { return false; } if (item) { item.update(); } $wrap.addClass('is-expanded'); $this.attr('aria-expanded', true); }) .on('mouseleave', '.toggle-box.is-expanded', function () { if (window.innerWidth < 1024) return; var $this = $(this); $this.removeClass('is-expanded'); $this.find('.js-toggle-content').attr('aria-expanded', false); }) .on('keyup', '.toggle-content', function (e) { var $this = $(this); var $wrap = $this.parent(); var $focusable = $this.find('a,button,input,select'); if (e.keyCode == 9 && !e.shiftKey && e.target == $focusable.last().get(0)) { $wrap.removeClass('is-expanded'); $this.attr('aria-expanded', false); } if (e.keyCode == 9 && e.shiftKey && e.target == $focusable.get(0) ) { $wrap.removeClass('is-expanded'); $this.attr('aria-expanded', false); } }) .on('click', function (e) { if (!$('.toggle-box.is-expanded').length || (window.innerWidth < 1024 && $('.widget-header .is-expanded').length)) return; var $eTarget = $(e.target); if (!$eTarget.closest('.btn-toggle').length && !$eTarget.hasClass('btn-toggle')) { $('.toggle-box.is-expanded').removeClass('is-expanded'); } }); $(document).on('click', '.tooltip .js-close-popup', function () { $(this).closest('.is-expanded').removeClass('is-expanded'); }); $(document).on('click', '.js-view-all', function (e) { e.preventDefault(); $(this).parent().toggleClass('is-expanded'); }); }()); /* Widget Tabs Toggle */ (function toggleWidgetTab() { $('.widget-body').on('click', '.btn-tab[aria-expanded]', function (e) { e.preventDefault(); var $this = $(this); var $wrap = $this.closest('li'); var instance = $wrap.find('.os-host').overlayScrollbars(); var idx = $wrap.index(); var $MobileList = $('.widget-body .tab-list'); if ($('.is-widget-collapse').length) { $('.is-widget-collapse').removeClass('is-widget-collapse'); $wrap.addClass('on'); } else { $wrap.toggleClass('on'); } if($wrap.hasClass('on')) { $wrap.parent().addClass('is-expanded'); $wrap.siblings().removeClass('on').find('.tab-region').removeClass('on'); $this.attr('aria-expanded', true); $MobileList.children().removeClass('on').eq(idx).addClass('on').find('a').attr('aria-expanded', true); if (instance && window.innerWidth < 1024) { instance.destroy(); } else if (instance) { instance.update(); } } else { $this.attr('aria-expanded', false); $wrap.find('.tab-region').removeClass('on'); $wrap.parent().removeClass('is-expanded'); $MobileList.children().eq(idx).removeClass('on').find('a').attr('aria-expanded', false); } if (!$wrap.parent().find('.on').length) { $MobileList.children().removeClass('on').eq(0).addClass('on').find('a').attr('aria-expanded', true); $('.tab-region').eq(0).addClass('on'); } }) .on('click', '.tab-list a', function () { var $this = $(this); var idx = $this.parent().index(); var offset = $('.header').outerHeight(); if (!$this.parent().hasClass('on')) { $('.widget-body .btn-tab').eq(idx).trigger('click'); } $('.is-fixed').each(function () { if ($(this).css('display') !== 'none') { offset += $(this).outerHeight(); } }); }); }()); /* Scroll Sticky */ (function setStickyElement () { $('.js-sticky').each(function () { var $this = $(this); var min = $this.offset().top; var ptop = $this.parent().top; $(window).on('scroll', function () { if (window.innerWidth > 1023) return; if (ptop !== $this.parent().offset().top) { $this.removeClass('is-fixed'); min = $this.offset().top; ptop = $this.parent().offset().top; } var curY = $(window).scrollTop(); var offset = $('.header').outerHeight(); var $fixedItems = $('.is-fixed').not($this); if ($fixedItems.length) { $fixedItems.each(function () { if ($(this).css('display') !== 'none') { offset += $(this).outerHeight(); } }); } if (curY + offset > min) { $this.addClass('is-fixed'); } else { $this.removeClass('is-fixed'); } }) .on('resize', function () { if (window.innerWidth > 1023) return; if ($this.hasClass('is-fixed')) { $this.removeClass('is-fixed'); min = $this.offset().top; $(window).trigger('scroll'); } else { min = $this.offset().top; } }); }); }()); /* Tab List show, hide */ (function setTabList () { function activePosition(elm) { var $elm = $(elm); var $active = $elm.find('.on'); var instance = $elm.find('.os-host').overlayScrollbars(); var xpos = 0; if (!$active.length) return; if (window.innerWidth < 1024) { xpos = $active.position().left + ($active.outerWidth() / 2) - (window.innerWidth / 2); } else if ($elm.children().hasClass('js-scrollbar')) { xpos = $active.position().left + ($active.outerWidth() / 2) - ($elm.children().outerWidth() / 2); } else { xpos = $active.position().left + ($active.outerWidth() / 2) - ($elm.outerWidth() / 2); } if (typeof instance !== 'undefined') { instance.scroll({ x : xpos }, 200); } else { $elm.stop().animate({'scrollLeft': xpos}, 200); } } $(document).on('click', '.tab-list [role="tab"]',function (e) { e.preventDefault(); var $tab = $(this); var target = $tab.attr('href') || $tab.attr('aria-controls'); var item = null; $tab.parent().addClass('on').attr('aria-selected', true).siblings().removeClass('on').attr('aria-selected', false); if (target && $(target).length) { $(target).addClass('on').siblings().removeClass('on'); } }); $(window).on('load resize', function () { setTimeout(function () { $('.tab-list').each(function () { activePosition(this); }); }, 600); }); }()); /* OverlayScrollbar init */ (function initOverlayScrollbar () { if (typeof OverlayScrollbars == 'undefined' || !$('.js-scrollbar').length) { return false; } var updateScrollbar = null; function init (elm) { if (window.innerWidth < 1024) { elm.css({'width':'','height':''}); return; } if (elm.parent().hasClass('tab-list')) { elm.overlayScrollbars({ overflowBehavior : { x : 'scroll', y: 'hidden' } }).overlayScrollbars(); } else { elm.overlayScrollbars({}).overlayScrollbars(); } elm.on('mouseenter', function () { var item = elm.overlayScrollbars(); if (typeof item !== 'undefined') { item.update(); } }) .on('mouseleave', function () { var item = elm.overlayScrollbars(); if (typeof item !== 'undefined') { item.sleep(); } }); } function update (elm) { if (!elm || !elm.length) return; if (elm.length == 1) { elm.update(); elm.sleep(); } else { $.each(elm, function (idx, item) { item.update(); item.sleep(); }); } } $(window).on('load', function () { setTimeout( function() { if (!$('.os-host').length) return; $('.os-host').css({'width':'','height':''}); }, 500); }) .on('resize', function () { if (!$('.js-scrollbar').length) return; var instance = null; if (updateScrollbar) { clearTimeout(updateScrollbar); updateScrollbar = null; } if (window.innerWidth < 1024) { $('.tab-region .os-host').each(function () { var instance = $(this).overlayScrollbars(); instance.destroy(); }); return; } else { $('.js-scrollbar').not('.os-host').each(function () { var $this = $(this); $this.css({'width': $this.outerWidth(),'height': $this.outerHeight()}); init($this); }); } instance = $('.os-host').css({'width':'','height':''}).overlayScrollbars(); updateScrollbar = setTimeout( function() { update(instance); }, 100); }); $('.js-scrollbar').each(function () { var $this = $(this); $this.css({'width': $this.outerWidth(),'height': $this.outerHeight()}); init($this); }); }()); /* ChartJs init */ (function initChartJs () { if (typeof Chart == 'undefined') return; Chart.defaults.global.defaultFontFamily = "'Roboto', 'Noto Sans KR', sans-serif"; Chart.defaults.global.defaultFontSize = 11; Chart.defaults.global.legend.display = false; if (typeof Chart.defaults.global.plugins.datalabels !== 'undefind') { Chart.plugins.unregister(ChartDataLabels); Chart.defaults.global.plugins.datalabels.align = 'end'; Chart.defaults.global.plugins.datalabels.anchor = 'end'; Chart.defaults.global.plugins.datalabels.padding = 0; Chart.defaults.global.plugins.datalabels.color = '#000'; Chart.defaults.global.plugins.datalabels.font.family = Chart.defaults.global.defaultFontFamily; Chart.defaults.global.plugins.datalabels.font.size = 12; Chart.defaults.global.plugins.datalabels.font.weight = 'bold'; } window.JSChart = { options: { colors: { 'red': 'rgb(255, 99, 132)', 'blue': 'rgb(54, 162, 235)', 'orange': 'rgb(253,159,64)', 'yellow': 'rgb(254,205,86)', 'mint': 'rgb(112,190,191)', 'redAlpha': 'rgba(255, 99, 132, 0.7)', 'blueAlpha': 'rgba(54, 162, 235, 0.7)', 'orangeAlpha': 'rgba(253,159,64, 0.7)', 'yellowAlpha': 'rgba(254,205,86, 0.7)', 'mintAlpha': 'rgba(112,190,191, 0.7)' } } }; }()); /* 로그인메뉴 보기 */ (function showSideMenu () { $('.btn_side_menu').on('click', function (e) { e.preventDefault(); $(".side_menu").show(); $(".side_menu_in").animate({'right': 0}, 200); $(".side_menu .modal").animate({'opacity': "0.73"}, 200); }); }()); /* 로그인메뉴 닫기 */ (function hideSideMenu () { $('.side_menu .clo').on('click', function (e) { e.preventDefault(); $(".side_menu").fadeOut(200); $(".side_menu_in").animate({'right': "-80%"}, 200); $(".side_menu_in .modal").animate({'opacity': "0"}, 200); }); $('.side_menu .modal').on('click', function (e) { e.preventDefault(); $(".side_menu").fadeOut(200); $(".side_menu_in").animate({'right': "-80%"}, 200); $(".side_menu .modal").animate({'opacity': "0"}, 200); }); }()); }());