/* * K-homepage theme * Copyright (c) 2023 K-homepage * https://k-homepage.com/ */ // 페이지 이동 function go_page(url) { document.location.href = decodeURIComponent(url); return false; } // 검색창 function tsearch_submit(f) { if (f.stx.value.length < 2) { alert("검색어는 두글자 이상 입력하십시오."); f.stx.select(); f.stx.focus(); return false; } f.action = f.url.value; return true; } // swiper v11 이상 // 슬라이드 갯수 모자라면 자동으로 채움 function swiper_slide_add(el, num) { const $swiperWrapper = el.querySelectorAll(".swiper-wrapper"); if(!num) num = 5; $swiperWrapper.forEach(function(wrap) { let $swiperSlides = wrap.querySelectorAll(".swiper-slide"); let i = $swiperSlides.length; let j = 0; if(i == 0 || i == num) return; while(j num) { wrap.lastElementChild.remove(); } }); } // a태그에 해쉬태그 클릭시 스크롤 function hash_scroll(btns, i=0) { let window_h = window.innerHeight; let document_h = document.documentElement.offsetHeight; btns.forEach( function(btn) { if(!btn.hash) return false; btn.onclick = function(e) { let id = this.hash.replace('#', ''); let ele = document.getElementById(id); let scrollTop = parseInt(window.scrollY); let eTop = parseInt(ele.getBoundingClientRect().top) - i; let gap, amount, remain; e.preventDefault(); e.stopPropagation(); if(ele) { eTop = parseInt(scrollTop + ele.getBoundingClientRect().top) - i; let scrollInterval = setInterval(function() { scrollTop = parseInt(window.scrollY); let scrollBottom = scrollTop + (window_h); if(scrollTop > eTop) { gap = scrollTop - eTop; amount = -55; remain = -gap; } else { gap = eTop - scrollTop; amount = +55; remain = +gap; } if(scrollTop == eTop || document_h - amount <= scrollBottom) { clearInterval(scrollInterval); } else { if(gap >= amount) { window.scrollBy(0, amount); } else { window.scrollBy(0, remain); } } }, 15); } } }); return false; } // 메뉴 링크에 #태그 있을 경우 메뉴 on function url_hash_menu_on() { const $btns = document.querySelectorAll('#menu .sub-a, #sub-menu .sub-a, #m-menu .sub-a'); let hash = window.location.hash; if(hash){ $btns.forEach(function(e) { let on = e.closest('.on'); let url = e.getAttribute('href'); if(on == e) { e.dataset.real = 'myself'; } else if(on != e && on == e.parentElement) { e.dataset.real = 'parent'; } else { e.dataset.real = ''; } if(url.includes('#')) { if(url.includes(hash)) { on.classList.add('on'); } else { on.classList.remove('on'); } e.addEventListener('click', function() { for(var i=0; i<$btns.length; i++) { if(url == $btns[i].getAttribute('href')) { if($btns[i].dataset.real == 'myself') { $btns[i].classList.add('on'); } else if($btns[i].dataset.real == 'parent') { $btns[i].parentElement.classList.add('on'); } } else { if($btns[i].dataset.real == 'myself') { $btns[i].classList.remove('on'); } else if($btns[i].dataset.real == 'parent') { $btns[i].parentElement.classList.remove('on'); } } } }); } }); } } // 오늘하루 창닫기 function day_pop_closed(e) { var cookieid = e.closest('.modal').getAttribute('id'); Cookies.set('No-'+cookieid, '1', { expires: 1 }); setTimeout(function () { $(e).parents('#' + cookieid).modal('hide'); }, 200); return false; } // 개인정보처리방침 등 팝업 버튼 function site_info_btn(btns) { const $body = document.querySelector('body'); let $bottom, footer, agree, in_btns = ''; if(!btns) { //버튼 지정안하면 푸터버튼 작동 in_btns = false; $bottom = document.getElementById('bottom'); footer = $bottom.querySelector('.footer'); btns = footer.querySelectorAll('.site-link button[data-toggle="modal"]'); btns.forEach( function(btn) { btns_click(btn); }); } else { in_btns = true; agree = '
'; agree += ''; agree += ''; agree += '
'; btns_click(btns); } let site_modal = document.getElementById('modal-siteinfo'); let site_modal_h = site_modal.querySelector('.head'); let site_modal_d = site_modal.querySelector('.desc'); function btns_click(e) { e.addEventListener('click', function() { let head = e.innerText; let desc = this.dataset.desc; let agree_id = this.dataset.agree; scroll_impossible($body); site_modal_h.innerText = head; site_modal_d.innerHTML = site_info_con(desc); if(site_modal_d.querySelector('header.header')) { site_modal_d.querySelector('header.header').remove(); } if(site_modal.querySelector('.btns')){ site_modal.querySelector(".btns").remove(); } if(in_btns == true) { site_modal_d.insertAdjacentHTML("afterend", agree); if(agree_id) { site_modal.querySelector('.btn-ok').addEventListener('click', function() { document.getElementById(agree_id).checked = true; }); site_modal.querySelector('.btn-cancel').addEventListener('click', function() { document.getElementById(agree_id).checked = false; }); } } }); return false; } site_modal.addEventListener('click', function() { if($body.classList.contains('modal-open')) { scroll_possible($body); } }); } // 개인정보처리방침 등 팝업 내용 불러오기 function site_info_con(el) { var url = "../bbs/content.php?co_id="+el; var content = ""; $.ajax({ type:"get", url:url, dataType:"html", async :false, success: function(html){ content = html.split('
'); content = content[1].split(''); } }); return content[0]; } // 드래그 금지 function scroll_impossible(el) { el.addEventListener('scroll', preventDefault); el.addEventListener('touchmove', preventDefault); el.addEventListener('wheel', preventDefault); } // 드래그 가능 function scroll_possible(el) { el.removeEventListener('scroll', preventDefault); el.removeEventListener('touchmove', preventDefault); el.removeEventListener('wheel', preventDefault); } function preventDefault(e) { e.preventDefault(); e.stopPropagation(); return false; } // 숫자롤링 function count_rolling(e) { $(e).each(function() { var $this = $(this); var countFrom = $this.attr('data-from'); var countTo = $this.attr('data-count'); var comma_no = $this.attr('data-nocomma'); var speed = Math.floor($this.attr('data-duration')); var delay = Math.floor($this.attr('data-delay')); var isComma = /^[0-9]+\.?[0-9]+$/; var num = ''; $({ val: countFrom }).delay(delay).animate({ val: countTo }, { duration: speed, easing:'linear', step: function() { if(isComma.test(countFrom)) { num = numberCommas(parseFloat(this.val).toFixed(1)); } else { num = numberCommas(Math.floor(this.val)); } $this.text(num); }, complete: function() { if (Number.isInteger(this.val)){ num = numberCommas(Math.floor(this.val)); } else { num = numberCommas(this.val.toFixed(1)); } $this.text(num); } }); function numberCommas(x) { if(comma_no != '1') { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } else { return x; } } }); } // 서브페이지 서브메뉴까지 자동 스크롤 function subpage_scroll(e) { if(!e) return; const $body = document.querySelector('body'); const $subpg = document.querySelector('.is-subpage'); let scrollTop = window.scrollY; let eTop = parseInt(window.scrollY + e.getBoundingClientRect().top); let amount = 15; let remain = parseInt(eTop%amount); let document_h = document.documentElement.offsetHeight; let window_h = window.innerHeight; let scrollBottom = scrollTop + window_h; let isOn = false; window.addEventListener('wheel', function() { let wheelInterval = setInterval(function() { if(!isOn) { isOn = true; } else { clearInterval(wheelInterval); } }, 10); }); setTimeout(function () { if($subpg && scrollTop < eTop && !$body.classList.contains('no_scroll') && document_h != scrollBottom) { let scrollInterval = setInterval(function() { scrollTop = window.scrollY; if(scrollTop < eTop && !isOn){ if(scrollTop < eTop + amount) { window.scrollBy(0, +amount); } else { window.scrollBy(0, +remain); } } else { clearInterval(scrollInterval); } }, 10); } }, 300); } // 풀페이지 function fullpage_act(page, $anchors, $nav, $nav_position, $speed, $scrollBar=false, $effect=false) { if(!$speed) $speed = 1000; var isAutoHeightMode = false; var $header = $(page).find('.section .header'); var $body = $('body'); $body.addClass('fullpage'); if($effect == true) { function class_add() { if ($(window).width() > 1024 && $(window).height() > 800) { $(page).addClass('fullpage-effect'); } else { $(page).removeClass('fullpage-effect'); } } class_add(); $(window).on('resize', function() { class_add(); }); } $header.each(function() { var $header_obj = $(this).children(); $header_obj.each(function(i, e) { if(!$(e).data('ani-name')) { $(e).data('ani-name', 'fadeInUp'); } $(e).css({'animation-delay':i*250+'ms'}).addClass('animated').addClass( $(e).data('ani-name') ); }); }); $(page).fullpage({ autoScrolling: true, css3: true, scrollingSpeed: $speed, anchors: $anchors, verticalCentered: false, scrollBar: $scrollBar, fitToSection: false, navigation: true, navigationPosition: $nav_position, navigationTooltips: $nav, bigSectionsDestination: 'top', slidesNavigation: false, slidesNavPosition: 'top', controlArrows: false, responsiveWidth: 1024, responsiveHeight: 800, responsiveSlides: true, onLeave: function(index, nextIndex) { var $sections = $(page + ' > .section'); var $next = $sections.eq(nextIndex - 1); var $header = $next.find('.header'); var $numbering = $next.find('.count-num'); if (!isAutoHeightMode) { $header.each(function() { var $header_obj = $(this).children(); $header_obj.each(function(i, e) { if(!$(e).data('ani-name')) { $(e).data('ani-name', 'fadeInUp'); } $(e).css({'visibility':'hidden', 'animation-delay':''}).removeClass('animated').removeClass( $(e).data('ani-name') ); setTimeout(function () { $(e).css({'visibility':'visible', 'animation-delay':i*250+'ms'}).addClass('animated').addClass( $(e).data('ani-name') ); }, 1000); }); }); if($(page).hasClass('fullpage-effect')) { $next.prevAll().css({'top':'-50%'}); $next.nextAll().css({'top':'100%'}); $next.css({'top':'0'}); $('#top').removeClass('bg'); if($next.attr('id') == 'bottom') { var h = Math.ceil($next.innerHeight()); $next.css({'top':'calc(100vh - '+h+'px)'}); if(h < $(window).innerHeight()/2) { $next.prev().css({'top':'calc(-'+h+'px)'}); } $('#top').addClass('bg'); } if($next.hasClass('top-white')) { $('#top').addClass('bg'); } } } if($next.hasClass('white-')) { $body.addClass('no-bg'); } else { $body.removeClass('no-bg'); } if($numbering) count_rolling($numbering); if(nextIndex != '1') { $body.addClass('scrolled').removeClass('not-scrolled'); } else { $body.removeClass('scrolled').addClass('not-scrolled'); } }, afterRender: function() { $(page + ' .section').css({'visibility':'visible', 'top':''}); } }); var sec_objs = $(page).find('.section'); function section_option() { sec_objs.each(function() { var $this = $(this); if ($(window).width() <= 1024 || $(window).height() <= 800) { $this.addClass('fp-auto-height'); isAutoHeightMode = true; } else { $this.removeClass('fp-auto-height'); isAutoHeightMode = false; } if($this.attr('id') == 'bottom') { $this.addClass('fp-auto-height'); } }); } $(window).on('resize', function() { section_option(); }); section_option(); if (isAutoHeightMode) { $.fn.fullpage.moveTo(1, 0); $('html, body').animate({ scrollTop: '0px' }, 0); } else { if(window.location.hash) { var url = window.location.pathname + window.location.search; history.scrollRestoration = "manual"; history.pushState("", "", url); $.fn.fullpage.moveTo(1, 0); } } if($(page).hasClass('fullpage-effect')) { $('.go-top').click(function() { $.fn.fullpage.moveTo(1, 0); }); } } // 주소찾기 팝업창 닫기 function closeDaumPostcode(e) { // iframe을 넣은 element를 안보이게 한다. e.style.display = 'none'; } // 주소찾기 팝업창 열기 function execDaumPostcode(e) { new daum.Postcode({ oncomplete: function(data) { // 검색결과 항목을 클릭했을때 실행할 코드를 작성하는 부분. // 각 주소의 노출 규칙에 따라 주소를 조합한다. // 내려오는 변수가 값이 없는 경우엔 공백('')값을 가지므로, 이를 참고하여 분기 한다. var addr = data.address; // 주소 변수 var extraAddr = ''; // 참고항목 변수 //사용자가 선택한 주소 타입에 따라 해당 주소 값을 가져온다. if (data.userSelectedType === 'R') { // 사용자가 도로명 주소를 선택했을 경우 addr = data.roadAddress; } else { // 사용자가 지번 주소를 선택했을 경우(J) addr = data.jibunAddress; } // 법정동명이 있을 경우 추가한다. (법정리는 제외) // 법정동의 경우 마지막 문자가 "동/로/가"로 끝난다. if(data.bname !== '' && /[동|로|가]$/g.test(data.bname)){ extraAddr += data.bname; } // 건물명이 있고, 공동주택일 경우 추가한다. if(data.buildingName !== '' && data.apartment === 'Y'){ extraAddr += (extraAddr !== '' ? ', ' + data.buildingName : data.buildingName); } // 표시할 참고항목이 있을 경우, 괄호까지 추가한 최종 문자열을 만든다. if(extraAddr !== ''){ extraAddr = ' (' + extraAddr + ')'; } // 우편번호와 주소 정보를 해당 필드에 넣는다. document.getElementById('w_zipcode').value = data.zonecode; document.getElementById("w_address1").value = addr; // 커서를 상세주소 필드로 이동한다. document.getElementById("w_address2").focus(); // iframe을 넣은 element를 안보이게 한다. // (autoClose:false 기능을 이용한다면, 아래 코드를 제거해야 화면에서 사라지지 않는다.) e.style.display = 'none'; }, width : '100%', height : '100%' }).embed(e); // iframe을 넣은 element를 보이게 한다. e.style.display = 'block'; } // ScrollReveal window.sr = ScrollReveal({ reset: false, distance: '100px', easing: 'ease', viewFactor: 0.3 }); // image lazyload function lazyload() { const wrapper = document.getElementById('theme_wrapper'); if(wrapper) { const lazy = wrapper.querySelectorAll('[data-lazy], [data-lazy-img], [data-lazy-video]'); lazy.forEach(function(e) { let url; let eTop = e.getBoundingClientRect().top; if(e.dataset.lazy) url = e.dataset.lazy; if(e.dataset.lazyVideo) url = e.dataset.lazyVideo; if(e.dataset.lazyImg) url = e.dataset.lazyImg; function viewport() { let winTop = window.scrollY + window.innerHeight; if(winTop >= eTop) { if(e.dataset.lazy && !e.style.backgroundImage) e.style = url; if((e.dataset.lazyImg || e.dataset.lazyVideo) && !e.src) e.setAttribute('src', url); } } viewport(); window.addEventListener("scroll", function() { eTop = window.scrollY + e.getBoundingClientRect().top; viewport(); }); }); } } window.addEventListener('DOMContentLoaded', function() { // Index Page sr.reveal('#main-slide1', { delay: 0 }); sr.reveal('.pg-main .reveal', { reset: true }); sr.reveal('.pg-main .reveal-once', { reset: false }); // Sub Pages sr.reveal('.page-content .reveal', { reset: true }); sr.reveal('.page-content .reveal-once', { reset: false }); const $body = document.body; const $top = document.getElementById('top'); const $bottom = document.getElementById('bottom'); const $wrapper = document.getElementById('theme_wrapper'); // Effect $body.classList.add('load-on'); if($wrapper) { const $page = document.getElementById('page'); let $page_class = $page.classList.value; // Favorite $('#favorite').on('click', function(e) { var bookmarkURL = window.location.href; var bookmarkTitle = document.title; var triggerDefault = false; if (window.sidebar && window.sidebar.addPanel) { // Firefox version < 23 window.sidebar.addPanel(bookmarkTitle, bookmarkURL, ''); } else if ((window.sidebar && (navigator.userAgent.toLowerCase().indexOf('firefox') > -1)) || (window.opera && window.print)) { // Firefox version >= 23 and Opera Hotlist var $this = $(this); $this.attr('href', bookmarkURL); $this.attr('title', bookmarkTitle); $this.attr('rel', 'sidebar'); $this.off(e); triggerDefault = true; } else if (window.external && ('AddFavorite' in window.external)) { // IE Favorite window.external.AddFavorite(bookmarkURL, bookmarkTitle); } else { // WebKit - Safari/Chrome alert((navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Cmd' : 'Ctrl') + '+D 키를 눌러 즐겨찾기에 등록하실 수 있습니다.'); } return triggerDefault; }); // Main mouse scroll const mainScrollDown = document.getElementById('main-mouse-scroll'); if(mainScrollDown) { mainScrollDown.addEventListener('click', function(e) { if($body.classList.contains('fullpage')) { $.fn.fullpage.moveSectionDown(); } else { let window_h = window.innerHeight; window.addEventListener('resize', function() { window_h = window.innerHeight; }); e.preventDefault(); e.stopPropagation(); let scrollInterval = setInterval(function() { let document_h = document.documentElement.offsetHeight; let scrollTop = window.scrollY; let num = window_h - scrollTop; let scrollBottom = scrollTop + window_h; if(scrollTop >= window_h || document_h == scrollBottom) { clearInterval(scrollInterval); } else { if(scrollTop <= window_h - 55){ window.scrollBy(0, +55); } else { window.scrollBy(0, +num); } } }, 15); } }); } // Family Site const family_site = document.querySelectorAll('.family-box'); family_site.forEach(function(e) { let btn = e.querySelector('.family-btn'); let parent = btn.parentElement; btn.addEventListener("click", function() { parent.classList.toggle('on'); }); }); // Tooltip $('body').tooltip({ selector: "[data-toggle='tooltip']", items: "" }); // Go button const goTop = document.querySelectorAll(".at-go .go-top"); goTop.forEach(function(go) { go.addEventListener("click", function(e) { e.preventDefault(); e.stopPropagation(); let scrollInterval = setInterval(function() { let scrollTop = window.scrollY; if(scrollTop > 0){ window.scrollBy(0, -55); } else { clearInterval(scrollInterval); } }, 15); }); }); // Scroll add Class let scrollTop = window.scrollY; let window_h = window.innerHeight; let scrollBottom = scrollTop + window_h; let lastScroll = 0; let document_h, scrolling; function scroll_class() { document_h = document.documentElement.scrollHeight; // 스크롤 최상단보다 아래 if (scrollTop > 0) { $body.classList.add('scrolled'); } else { $body.classList.remove('scrolled'); } // 스크롤 최하단보다 약간 위 if (scrollTop >= document_h - window_h - 150) { $body.classList.add('scroll-bt-up'); } else { $body.classList.remove('scroll-bt-up'); } // 스크롤 최하단 if (document_h == scrollBottom) { $body.classList.add('scroll-bt'); } else { $body.classList.remove('scroll-bt'); } } setTimeout(function() { scroll_class(); }, 400); window.addEventListener("scroll", function() { scrollTop = window.scrollY; scrollBottom = scrollTop + window_h; scroll_class(); // 스크롤 올릴때 if(scrollTop <= lastScroll) { $body.classList.add('scroll-up'); } else { $body.classList.remove('scroll-up'); } if(scrollTop == 0) $body.classList.remove('scroll-up'); lastScroll = scrollTop; // 스크롤중일때 $body.classList.add('scroll-ing'); clearTimeout(scrolling); scrolling = setTimeout(function() { scrolling = undefined; if(scrolling == undefined) { $body.classList.remove('scroll-ing'); } }, 500); }); // Tab const tabBtn = document.querySelectorAll(".tab-btn"); tabBtn.forEach(function(tab) { const btns = tab.children; const parent = tab.parentElement; const tabCon = parent.querySelector('.tab-con'); const scrs = tabCon.querySelectorAll('.scr-el, .scr-el-one, .scrs'); const cons = tabCon.children; let hash = window.location.hash; let delay; scrs.forEach(function(el) { setTimeout(function() { if(el.classList.contains('scrs')) { let scrDelay = el.querySelectorAll('.scr-delay'); scrDelay.forEach(function(d) { delay = d.style.transitionDelay; d.dataset.delay = delay; }); } else { delay = el.style.transitionDelay; el.dataset.delay = delay; } }, 200); }); for(let i=0; i 0) { $('#hd_pop').show(); $('.hd_pops').click(function(){ $(this).each(function(){ if($(this).is(':visible') != true && $('.hd_pops').not($(this)).is(':visible') != true) { $('#hd_pop').hide(); } }); }); } var $grid = $('#hd_pop').imagesLoaded( function() { $grid.masonry({ itemSelector: '.hd_pops', gutter: 10, horizontalOrder: true, stagger: 500, columnWidth: 1, }); }); if($page_class.includes('pg-main')) { const pop_objs = document.querySelectorAll('#center-popup, #right-popup'); pop_objs.forEach(function(e) { const thisid = e.getAttribute('id'); const slides = e.querySelectorAll('.swiper-slide'); let $autoH = false; if (Cookies.get('No-'+thisid) === '1') return; if(thisid.includes('center') == false) { $(e).modal({ backdrop: false }); } else { $body.style.overflow = 'visible'; } if(thisid == 'center-popup') { $autoH = true; } let opts = {}; if ( slides.length > 1 ) { opts = { loop: true, speed:2000, autoplay: { delay: 3000, disableOnInteraction: true }, pagination: { el: '#'+thisid+' .pg', clickable: true }, navigation: { prevEl: '#'+thisid+' .prev', nextEl: '#'+thisid+' .next' }, autoHeight: $autoH, } } else { opts = { allowTouchMove: false, } } let SW; setTimeout(function () { $(e).modal('show'); SW = new Swiper('#'+thisid+' .swiper', opts); }, 200); slides.forEach(function(slide) { let href = slide.dataset.href; let self = slide.dataset.self; target = '_self'; if(self == '2') { target = '_blank'; } if(href) { if(!href.includes('https://') && !href.includes('http://') && href != '#') { href = 'https://' + href; } slide.insertAdjacentHTML('afterbegin', ''); } }); }); setTimeout(function () { const modalBack = document.querySelector('.modal-backdrop'); if(modalBack) { modalBack.addEventListener('click', function() { $(e).modal('hide'); }); } }, 300); $('.modal').on('hidden.bs.modal', function () { $(this).find('iframe').attr('src', ''); }); } ////////////////////////////////// main ////////////////////////////////// ////////////////////////////////// board ////////////////////////////////// if($page_class.includes('board-')) { const $board = document.querySelectorAll('#bo_list, #bo_w, #bo_v'); const ca_name = document.getElementById('ca_name'); $board.forEach( function(e) { // Editor if(e) { e.closest('.content-body').classList.add('ck-content'); } // Write if(e.id == 'bo_w' && ca_name) { if(ca_name.lastElementChild.value == '공지') { ca_name.lastElementChild.remove(); } } }); } ////////////////////////////////// board ////////////////////////////////// } }); window.addEventListener('load', function() { site_info_btn(); lazyload(); });