(function($) {
setDateFormat();
function gnb(){
$("#header").on("click", ".mobile-menu", function(){
var ac = $('#sidebar').detach();
if ( $(this).hasClass("on") ){
if(ac.length){
ac.prependTo('#wrap .container');
}
$(this).removeClass("on");
$("#header .menu").removeClass("on");
$("#dimmed").remove();
} else {
$(this).addClass("on");
$("#header .menu").addClass("on");
if(ac.length){
ac.prependTo('nav#gnb');
}
$("body").append('
').on("click", "#dimmed", function(){
$(".mobile-menu").click();
});
}
});
$(window).resize(function(){
if ( $("#gnb").css("position") == "relative" ){
if ( $("#dimmed").is(":visible") ){
$("#dimmed").remove();
}
if ( $(".mobile-menu").hasClass("on") ){
$(".mobile-menu").click();
}
}
});
$(window).scroll(function(){
var height = $(window).scrollTop();
if ( $('.pagination').length){
if(height > 0){
//$('.pagination').addClass('hideanim');
$('.pagination').detach().appendTo('#content');
}else{
//$('.pagination').removeClass('hideanim');
if(!( $('.post-item').length && $('.no-more-next').length )){
$('.pagination').detach().prependTo('.container');
}else{
$('.pagination').remove();
}
}
}
if ( $('.btn-top').length ){
if(height > 0){
$('.btn-top').removeClass('hideanim');
}else{
$('.btn-top').addClass('hideanim');
}
}
});
$(document).on("click", "#header .search", function(){
if ( !$(this).hasClass("on") ){
$(this).addClass("on").find("input").focus();
return false;
}
});
$(document).on("click", ".close-search", function(){
$("#header .search").removeClass("on").find("input").focus();
return false;
});
}
function coverSlider(){
$(".cover-slider").each(function(){
var $this = $(this), //현재 슬라이드 이너 객체
$sliderItems = $(this).find("li"), //슬라이드 아이템들 객체 리스트
$itemsLength = $sliderItems.length, //슬라이드 아이템 갯수
$num = 0, //슬라이드 인덱스
$looper = null; //슬라이드 인터벌 타이머 객체
$interval = 5000;// 슬라이드 이동 간격
$animateTime = 500; //슬라이드 이동시간
$timeouts = [];
if ( $itemsLength > 1 ){
//add prev, next button
$this.append('');
$looper = setLoop();
//add indicator
$this.append('
');
for(let i=0;i<$itemsLength;i++){
var $element = $('');
$element.click(function(){
var $clicked_indicator = parseInt($(this).attr('index'));
if($num != $clicked_indicator){
var sliding_size = Math.abs($num - $clicked_indicator);
clearInterval($looper);
for(let j = 0;j= $sliderItems.length ? 0 : $num+1;
moveSlide();
$($this).find('ol li').removeClass('active');
$($this).find('ol li').eq($num).addClass('active');
}
});
//slide rotate init
function setLoop(){
return setInterval(
function autoScrollSlider(){
$($this).find('.next').trigger( "click" );
}, $interval
);
}
//animate indicator click
function moveCascadeSlides(direction, idx){
var next_num = $num + direction;
$sliderItems.eq($num).animate({ left: (-100*direction)+"%" }, $animateTime ).siblings().css("left",(100*direction)+"%");
$sliderItems.eq(next_num).animate({ left: "0" }, $animateTime );
$($this).find('ol li').removeClass('active');
$($this).find('ol li').eq(next_num).addClass('active');
$num = next_num;
clearTimeout($timeouts[idx]);
}
//animate 1 slide item
function moveSlide(){
$sliderItems.eq($num).animate({ left: "0" }, $animateTime );
$(".cover-slider .paging button").eq($num).addClass("current").siblings().removeClass("current");
}
//add mobile touch
$this.on("touchstart", function(){
var touch = event.touches[0];
touchstartX = touch.clientX,
touchstartY = touch.clientY;
});
//add mobile touch end
$this.on("touchend", function(){
if( event.touches.length == 0 ){
var touch = event.changedTouches[event.changedTouches.length - 1];
touchendX = touch.clientX,
touchendY = touch.clientY,
touchoffsetX = touchendX - touchstartX,
touchoffsetY = touchendY - touchstartY;
if ( Math.abs(touchoffsetX) > 10 && Math.abs(touchoffsetY) <= 100 ){
if (touchoffsetX < 0 ){
$this.find(".next").click();
} else {
$this.find(".prev").click();
}
}
}
});
}
});
}
function coverMasonry(){
var $masonry = $(".cover-masonry");
$.getScript( "//unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js", function( data, textStatus, jqxhr ) {
$masonry.each(function(){
var $this = $(this);
$this.find("ul").css({
"display": "block",
}).masonry({
itemSelector: '.cover-masonry ul li',
columnWidth: '.cover-masonry ul li',
});
});
});
}
function getCookie(name){
name = new RegExp(name + '=([^;]*)');
return name.test(document.cookie) ? unescape(RegExp.$1) : '';
}
function postListType(){
var cookie = document.cookie;
if ( !getCookie('post-type') && !$("body").hasClass("post-type-thumbnail") ){
$(".post-header .list-type .list").addClass("current");
}
if ( $("body").hasClass("post-type-thumbnail") ){
$(".post-header .list-type .thum").addClass("current").siblings().removeClass("current");
} else {
$(".post-header .list-type .list").addClass("current").siblings().removeClass("current");
}
}
function viewMore(){
if ( $(".paging-view-more").length && $(".post-item").length ){
if ( $(".paging-view-more").length && $(".post-item").length ){
viewMoreShow();
}
function viewMoreShow(){
var nextUrl = $(".pagination .next").attr("href");
$(".pagination a").hide();
if( nextUrl ){
$(".pagination .inner").append('더보기 ');
$(".pagination .view-more").on("click", function(){
viewMore(nextUrl);
return false;
});
}
}
function viewMore(url){
$.ajax({
url: url
}).done(function (res) {
var $res = $(res),
$nextPostItem = $res.find(".post-item"),
$paginationInner = $res.find(".pagination").html();
if ( $nextPostItem.length > 0 ){
$("#content .inner").append($nextPostItem);
$(".pagination").html($paginationInner);
setDateFormat();
viewMoreShow();
} else {
$(".pagination").remove();
}
});
}
} else {
var current_num = $(".pagination .selected").text(),
total_num = $(".pagination .next").length ? $(".pagination .next").prev().text() : $(".pagination a:last").text();
$(".pagination .inner").append(''+current_num+'/'+total_num+'');
}
}
function mobileTable(){
var $table = $(".entry-content table");
if( $table.length > 0 ){
$table.each(function(){
if ( $(this).css("table-layout") == "fixed" && !$(this).parent().hasClass("table-wrap") ){
$(this).wrap('');
}
});
}
}
function iframeWrap(){
var $iframe = $(".entry-content iframe");
if( $iframe.length > 0 ){
$iframe.each(function(){
if ( !$(this).parent().hasClass("iframe-wrap") ){
$(this).wrap('');
}
});
}
}
gnb();
coverSlider();
if ( $(".cover-masonry").length ) coverMasonry();
if ( $(".post-header .list-type").length ) postListType();
if ( $(".pagination").length ) viewMore();
if ( $(".entry-content").length ){
mobileTable();
iframeWrap();
}
if ( $(".pagination").length ){
$('.pagination').detach().prependTo('.container');
}
$(window).resize(function(){
mobileTable();
});
//紐⑤컮�� �ㅽ겕濡� �ㅻ쾭 泥섎━
var $is_mobile = false;
checkMobile()
if($is_mobile && $(".post-item").length > 0 && $('body').hasClass('color-mono')){
//紐⑤컮�쇱씠硫� 酉고룷�� �몃쾭 ��
$.fn.isInViewport = function() {
var elementTop = $(this).offset().top;
var elementBottom = elementTop + $(this).outerHeight();
var viewportTop = $(window).scrollTop()+200;
var viewportBottom = viewportTop + $(window).height()-550;
return elementBottom > viewportTop && elementTop < viewportBottom;
};
$(window).on('resize scroll', function() {
$('.thum img').each(function() {
if ($(this).isInViewport()) {
$(this).removeClass('invisible');
$(this).addClass('visible');
} else {
$(this).removeClass('visible');
$(this).addClass('invisible');
}
});
});
}
//紐⑤컮�쇨린湲곗껜�� - @media濡� 泥댄겕
function checkMobile(){
if( $('#header h1 a').css('display')=='block') {
$is_mobile = true;
}else{
$is_mobile = false;
}
}
function setDateFormat(){
checkMobile();
var today = new Date();
var todayymd = today.toISOString().replace(/-/gi,'.').substring(0,10);
$(".date").each(function(){
if($(this).html().length<20){
$(this).html(($(this).html()).substring(0,10))
}
})
}
$('.btn-top').click(function(){
$("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
})(jQuery);