/*
* Name : sub.js
* Version : 1.0
* Author : onepixel studio
* Date : 2020-05-23
---------------------------------------------------
Table of contents
---------------------------------------------------
01. functions
02. init
03. review swiper
04. zoom gallery init
05. masonry init
06. board common
07. gallery setting
---------------------------------------------------
*/
'use strict';
$(function() {
// functions
// get parameter
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
};
// init
review_swiper_init();
zoom_gallery_init();
masonry_init();
board_common_init();
gallery_setting();
faq_init();
// review swiper
function review_swiper_init() {
var $swiper = new Swiper('.customer-review .review-swiper', {
loop: true,
navigation: {
prevEl: '.customer-review .navigation-arrow .prev',
nextEl: '.customer-review .navigation-arrow .next',
},
pagination: {
el: '.customer-review .swiper-pagination',
clickable: true,
}
});
}
// zoom gallery init
function zoom_gallery_init() {
$('.zoom-gallery').magnificPopup({
delegate: 'a',
type: 'image',
closeOnContentClick: false,
closeBtnInside: false,
mainClass: 'mfp-with-zoom mfp-img-mobile',
image: {
verticalFit: true,
},
gallery: {
enabled: true
},
zoom: {
enabled: true,
duration: 300, // don't foget to change the duration also in CSS
opener: function(element) {
return element.find('img');
}
}
});
}
// masonry init
function masonry_init() {
var $el = $('.masonry-group');
$el.imagesLoaded(function() {
$el.masonry({
itemSelector: '.col-item',
columnWidth: '.sizer',
gutter: 10
});
});
}
// board common
function board_common_init() {
// replace category items to link
if ( $('.board-category').length ) {
if ( $('.board-category').find('select').length ) {
var $ca_link = [],
$ca_name = [],
$ca_current = getUrlParameter('com_board_category_code'),
$html = '
';
$('.board-category select option').each(function (i) {
$ca_name[i] = $(this).text();
$ca_link[i] = $(location).attr('pathname') + '?com_board_category_code=' + $(this).val();
$html += '- ' + $ca_name[i] + '
';
});
$html += '
';
$('.board-category').html($html);
$('.board-category ul li').each(function () {
if ($(this).find('a').attr('href').indexOf($ca_current) > -1 && $ca_current != '') $(this).addClass('is-active');
});
if ( !$('.board-category .is-active').length ) $('.board-category ul li:first-child').addClass('is-active');
} else {
$('.board-category').remove();
}
}
// category text replace
$('.gallery_etc').each(function() {
$(this).html($.trim($(this).text().replace('[','').replace(']','').split(':')[1]));
});
// image buttons to text button
var $btn_keywords = ['삭제', '이동', '복사', '글쓰기', '검색', '이전', '목록보기', '다음', '수정', '작성완료', '취소', '스팸신고', '답글쓰기', '댓글달기'];
var $btn_type_input = $("input[type=image]"),
$btn_type_img = $("img");
$btn_type_input.each(function () {
var $src = $(this).attr('src');
if ( $src.indexOf('search.gif') > -1 ) {
$(this).before('');
$(document).on('click', '#btn-search', function () {
$(this).next('input[type=image]').trigger('click');
});
$(this).hide();
}
if ( $src.indexOf('confirm.gif') > -1 ) {
$(this).before('');
$(this).hide();
}
if ( $src.indexOf('comment_write.gif') > -1 ) {
$(this).before('');
$(document).on('click', '#btn-comment-write', function () {
$(this).next('input[type=image]').trigger('click');
});
$(this).hide();
}
});
$btn_type_img.each(function () {
var $src = $(this).attr('src');
var $event = $(this).attr('onclick');
if ( $src.indexOf('btn_sdel.gif') > -1 ) {
$(this).before("");
$(this).remove();
}
if ( $src.indexOf('move.gif') > -1 ) {
$(this).before("");
$(this).remove();
}
if ( $src.indexOf('copy.gif') > -1 ) {
$(this).before("");
$(this).remove();
}
if ( $src.indexOf('/prev.gif') > -1 ) {
$(this).parent().addClass('button button-default').text($btn_keywords[5]);
}
if ( $src.indexOf('list.gif') > -1 ) {
$(this).parent().addClass('button button-black').text($btn_keywords[6]);
}
if ( $src.indexOf('/next.gif') > -1 ) {
$(this).parent().addClass('button button-default').text($btn_keywords[7]);
}
if ( $src.indexOf('spam.gif') > -1 ) {
$(this).before('');
$(this).remove();
}
if ( $src.indexOf('modify.gif') > -1 ) {
$(this).parent().addClass('button button-black').text($btn_keywords[8]);
}
if ( $src.indexOf('delete.gif') > -1 ) {
$(this).parent().addClass('button button-black').text($btn_keywords[0]);
}
if ( $src.indexOf('reply.gif') > -1 ) {
$(this).parent().addClass('button button-secondary').text($btn_keywords[12]);
}
if ( $src.indexOf('write.gif') > -1 ) {
$(this).parent().addClass('button button-secondary').text($btn_keywords[3]);
}
if ( $src.indexOf('btn_confirm.gif') > -1 ) {
$(this).parent().addClass('button button-primary btn-large').text($btn_keywords[9]);
}
if ( $src.indexOf('cancel.gif') > -1 ) {
$(this).parent().addClass('button button-secondary btn-large').text($btn_keywords[10]);
}
});
}
// gallery setting
function gallery_setting() {
// change row orders
$('.photo-list .table-photo .bbsnewf5').each(function() {
var $this = $(this);
if ( $this.find('.gallery_subject').length ) {
var $row = $this.find('.gallery_subject').parent();
$row.insertAfter($row.next());
}
});
}
// faq init
function faq_init() {
var $post = $('.faq-list .titdesign'),
$html = '',
$answer = [],
$answerURL = [];
$post.each(function(i) {
var $this = $(this);
$answerURL[i] = $this.find('a').attr('href');
$.ajax({
url: $answerURL[i],
async: false,
cache: false,
dataType: 'html',
type: 'GET',
contentType: 'application/x-www-form-urlencoded;charset=euc-kr',
beforeSend: function (jqXHR) {
jqXHR.overrideMimeType('application/x-www-form-urlencoded;charset=euc-kr');
},
success: function (data) {
$html = $(data).find('#post_area').html();
$answer = '';
$answer += $html;
$answer += ' | ';
$this.find('.bbsnewf5').after($answer);
},
error: function (response) {
console.log(response);
}
});
});
$('.faq-list .bbsnewf5 a').on('click', function (e) {
if ( !$(".board_admin_bgcolor").length ) {
e.preventDefault();
if ( !$(this).closest('tr').hasClass('is-open') ) {
$('.faq-list .is-open').removeClass('is-open');
$(this).closest('tr').addClass('is-open');
} else {
$(this).closest('tr').removeClass('is-open');
}
}
});
}
});