284 lines
6.4 KiB
JavaScript
284 lines
6.4 KiB
JavaScript
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
"use strict";
|
|
|
|
/**
|
|
* Preloader
|
|
*/
|
|
const preloader = document.querySelector('#preloader');
|
|
if (preloader) {
|
|
window.addEventListener('load', () => {
|
|
preloader.remove();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Sticky header on scroll
|
|
*/
|
|
const selectHeader = document.querySelector('#header');
|
|
if (selectHeader) {
|
|
document.addEventListener('scroll', () => {
|
|
window.scrollY > 100 ? selectHeader.classList.add('sticked') : selectHeader.classList.remove('sticked');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Navbar links active state on scroll
|
|
*/
|
|
let navbarlinks = document.querySelectorAll('#navbar a');
|
|
|
|
function navbarlinksActive() {
|
|
navbarlinks.forEach(navbarlink => {
|
|
|
|
if (!navbarlink.hash) return;
|
|
|
|
let section = document.querySelector(navbarlink.hash);
|
|
if (!section) return;
|
|
|
|
let position = window.scrollY + 200;
|
|
|
|
if (position >= section.offsetTop && position <= (section.offsetTop + section.offsetHeight)) {
|
|
navbarlink.classList.add('active');
|
|
} else {
|
|
navbarlink.classList.remove('active');
|
|
}
|
|
})
|
|
}
|
|
window.addEventListener('load', navbarlinksActive);
|
|
document.addEventListener('scroll', navbarlinksActive);
|
|
|
|
/**
|
|
* Mobile nav toggle
|
|
*/
|
|
const mobileNavShow = document.querySelector('.mobile-nav-show');
|
|
const mobileNavHide = document.querySelector('.mobile-nav-hide');
|
|
|
|
document.querySelectorAll('.mobile-nav-toggle').forEach(el => {
|
|
el.addEventListener('click', function(event) {
|
|
event.preventDefault();
|
|
mobileNavToogle();
|
|
})
|
|
});
|
|
|
|
function mobileNavToogle() {
|
|
document.querySelector('body').classList.toggle('mobile-nav-active');
|
|
mobileNavShow.classList.toggle('d-none');
|
|
mobileNavHide.classList.toggle('d-none');
|
|
}
|
|
|
|
|
|
/**
|
|
* Hide mobile nav on same-page/hash links
|
|
*/
|
|
document.querySelectorAll('#navbar a').forEach(navbarlink => {
|
|
|
|
if (!navbarlink.hash) return;
|
|
|
|
let section = document.querySelector(navbarlink.hash);
|
|
if (!section) return;
|
|
|
|
navbarlink.addEventListener('click', () => {
|
|
if (document.querySelector('.mobile-nav-active')) {
|
|
mobileNavToogle();
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
/**
|
|
* Toggle mobile nav dropdowns
|
|
*/
|
|
const navDropdowns = document.querySelectorAll('.navbar .dropdown > a');
|
|
|
|
navDropdowns.forEach(el => {
|
|
el.addEventListener('click', function(event) {
|
|
if (document.querySelector('.mobile-nav-active')) {
|
|
event.preventDefault();
|
|
this.classList.toggle('active');
|
|
this.nextElementSibling.classList.toggle('dropdown-active');
|
|
|
|
let dropDownIndicator = this.querySelector('.dropdown-indicator');
|
|
dropDownIndicator.classList.toggle('bi-chevron-up');
|
|
dropDownIndicator.classList.toggle('bi-chevron-down');
|
|
}
|
|
})
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Scroll top button
|
|
*/
|
|
const scrollTop = document.querySelector('.scroll-top');
|
|
if (scrollTop) {
|
|
const togglescrollTop = function() {
|
|
window.scrollY > 100 ? scrollTop.classList.add('active') : scrollTop.classList.remove('active');
|
|
}
|
|
window.addEventListener('load', togglescrollTop);
|
|
document.addEventListener('scroll', togglescrollTop);
|
|
scrollTop.addEventListener('click', window.scrollTo({
|
|
top: 0,
|
|
behavior: 'smooth'
|
|
}));
|
|
}
|
|
|
|
/**
|
|
* Initiate glightbox
|
|
*/
|
|
const glightbox = GLightbox({
|
|
selector: '.glightbox'
|
|
});
|
|
|
|
/**
|
|
* Initiate pURE cOUNTER
|
|
*/
|
|
new PureCounter();
|
|
|
|
/**
|
|
* Init swiper slider with 1 slide at once in desktop view
|
|
*/
|
|
new Swiper('.slides-1', {
|
|
speed: 600,
|
|
loop: true,
|
|
autoplay: {
|
|
delay: 5000,
|
|
disableOnInteraction: false
|
|
},
|
|
slidesPerView: 'auto',
|
|
pagination: {
|
|
el: '.swiper-pagination',
|
|
type: 'bullets',
|
|
clickable: true
|
|
},
|
|
navigation: {
|
|
nextEl: '.swiper-button-next',
|
|
prevEl: '.swiper-button-prev',
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Init swiper slider with 3 slides at once in desktop view
|
|
*/
|
|
new Swiper('.slides-3', {
|
|
speed: 600,
|
|
loop: true,
|
|
autoplay: {
|
|
delay: 5000,
|
|
disableOnInteraction: false
|
|
},
|
|
slidesPerView: 'auto',
|
|
pagination: {
|
|
el: '.swiper-pagination',
|
|
type: 'bullets',
|
|
clickable: true
|
|
},
|
|
navigation: {
|
|
nextEl: '.swiper-button-next',
|
|
prevEl: '.swiper-button-prev',
|
|
},
|
|
breakpoints: {
|
|
320: {
|
|
slidesPerView: 1,
|
|
spaceBetween: 40
|
|
},
|
|
|
|
1200: {
|
|
slidesPerView: 3,
|
|
}
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Gallery Slider
|
|
*/
|
|
new Swiper('.gallery-slider', {
|
|
speed: 400,
|
|
loop: true,
|
|
centeredSlides: true,
|
|
autoplay: {
|
|
delay: 5000,
|
|
disableOnInteraction: false
|
|
},
|
|
slidesPerView: 'auto',
|
|
pagination: {
|
|
el: '.swiper-pagination',
|
|
type: 'bullets',
|
|
clickable: true
|
|
},
|
|
breakpoints: {
|
|
320: {
|
|
slidesPerView: 1,
|
|
spaceBetween: 20
|
|
},
|
|
640: {
|
|
slidesPerView: 3,
|
|
spaceBetween: 20
|
|
},
|
|
992: {
|
|
slidesPerView: 5,
|
|
spaceBetween: 20
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
* Animation on scroll function and init
|
|
*/
|
|
/*
|
|
function aos_init() {
|
|
AOS.init({
|
|
duration: 1000,
|
|
easing: 'ease-in-out',
|
|
once: true,
|
|
mirror: false
|
|
});
|
|
}
|
|
window.addEventListener('load', () => {
|
|
aos_init();
|
|
});
|
|
*/
|
|
|
|
});
|
|
|
|
/**
|
|
* Ajax
|
|
*/
|
|
function api(url, data, successCB, failedCB = ajaxDefaultErrorCallBack){
|
|
$.ajax({
|
|
type: 'post',
|
|
url : "assets/internal_api.php?func="+url,
|
|
data: data,
|
|
dataType:"json",
|
|
success : eval(successCB),
|
|
error: eval(failedCB)
|
|
});
|
|
}
|
|
|
|
var ajaxDefaultErrorCallBack = function(response) {
|
|
console.log(response.message);
|
|
}
|
|
|
|
function setCookie(name, value, daysToExpire=365) {
|
|
var date = new Date();
|
|
date.setTime(date.getTime() + (daysToExpire * 24 * 60 * 60 * 1000));
|
|
var expires = "expires=" + date.toUTCString();
|
|
|
|
document.cookie = name + "=" + value + ";" + expires + ";path=/";
|
|
}
|
|
|
|
function getCookie(name) {
|
|
var nameEQ = name + "=";
|
|
var ca = document.cookie.split(';'); // 쿠키를 세미콜론으로 분리하여 배열 생성
|
|
for(var i=0;i < ca.length;i++) {
|
|
var c = ca[i];
|
|
while (c.charAt(0)==' ') c = c.substring(1,c.length); // 공백 제거
|
|
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); // 쿠키 값 반환
|
|
}
|
|
return ""; // 쿠키가 존재하지 않을 경우 빈 문자열 반환
|
|
}
|