This commit is contained in:
shim
2023-04-17 11:06:08 +09:00
parent d0b393aa97
commit 76264e09ad
4686 changed files with 552713 additions and 0 deletions

View File

@@ -0,0 +1,153 @@
/**
* --------------------------------------------------------------------------
* kimsQ Rb v2.4 데스크탑 시작하기 레이아웃 스크립트 (bs4-starter)
* Homepage: http://www.kimsq.com
* Licensed under RBL
* Copyright 2019 redblock inc
* --------------------------------------------------------------------------
*/
var noti_sort = 'uid';
var noti_orderby = 'desc';
var noti_recnum = '10';
$('[data-plugin="timeago"]').timeago(); // 상대시간 플러그인 초기화
// 사용자 액션에 대한 피드백 메시지 제공을 위해 액션 실행후 쿠키에 저장된 결과 메시지를 출력시키고 초기화 시킵니다.
putCookieAlert('site_common_result') // 실행결과 알림 메시지 출력
$(document).ready(function() {
// navbar dropdown 로그인 - 실행
$('#popover-loginform').submit(function(e){
e.preventDefault();
e.stopPropagation();
var form = $(this)
siteLogin(form)
});
// navbar dropdown 로그인 - 로그인 영역 내부 클릭시 dropdown 닫히지 않도록
$(document).on('click', '#navbarPopoverLogin .dropdown-menu', function (e) {
e.stopPropagation();
});
// navbar dropdown 로그인 - dropdown 열릴때
$('#navbarPopoverLogin').on('shown.bs.dropdown', function () {
$(this).find('[name=id]').focus() // 아이디 focus
$(this).find('.form-control').val('').removeClass('is-invalid') //에러이력 초기화
})
$(document).on('keyup','#popover-loginform .form-control',function(){
$(this).removeClass('is-invalid') //에러 흔적 초기화
});
// navbar dropdown 내알림보기 - dropdown 열릴때
$('#navbarPopoverNoti').on('show.bs.dropdown', function () {
var dropdown = $(this)
var mobile = ''
$('.js-tooltip').tooltip('hide')
dropdown.attr('data-original-title','')
dropdown.find('[data-role="noti-list"]').isLoading({
text: "불러오는중...",
position: "inside"
});
$.post(rooturl+'/?r='+raccount+'&m=notification&a=get_notiList',{
sort: noti_sort,
orderby: noti_orderby,
recnum: noti_recnum,
callMod: 'unread'
},function(response){
var result = $.parseJSON(response);
var content=result.content;
dropdown.find('[data-role="noti-list"]').html(content);
dropdown.find('[data-plugin="timeago"]').timeago();
dropdown.find('[data-role="noti-status"]').text('');
});
})
// navbar dropdown 알림보기 - dropdown 닫힐때
$('#navbarPopoverNoti').on('hidden.bs.dropdown', function () {
var dropdown = $(this)
dropdown.attr('data-original-title','알림')
dropdown.find('[data-role="noti-list"]').html('');
})
//modal 로그인 - 실행
$('#modal-login').find('form').submit(function(e){
e.preventDefault();
e.stopPropagation();
var form = $(this)
siteLogin(form)
});
// modal 로그인 - modal 열릴때
$('#modal-login').on('shown.bs.modal', function () {
$(this).find('[name=id]').focus() // 아이디 focus
$(this).find('.form-control').val('').removeClass('is-invalid') //에러 흔적 초기화
})
$("#modal-login").find('.form-control').keyup(function() {
$(this).removeClass('is-invalid') //에러 흔적 초기화
});
//modal 변경
$(document).on('click','[data-toggle="changeModal"]', function (e) {
var $this = $(this)
var href = $this.attr('href')
var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, '')))
var $start = $($this.closest('.modal'))
if ($this.is('a')) e.preventDefault()
$start.modal('hide')
setTimeout(function(){ $target.modal({show:true,backdrop:'static'}); }, 300);
});
$('[data-toggle="tooltip"]').tooltip() // 툴팁 플러그인 초기화
$('.js-tooltip').tooltip();
initPhotoSwipeFromDOM('[data-plugin="photoswipe"]'); // 포토갤러리 초기화
//외부서비스 사용자 인증요청
$('[data-connect]').on("click", function(){
var provider = $(this).data('connect')
// /core/engine/cssjs.engine.php 참고
if (provider=='naver') var target = connect_naver
if (provider=='kakao') var target = connect_kakao
if (provider=='google') var target = connect_google
if (provider=='facebook') var target = connect_facebook
if (provider=='instagram') var target = connect_instagram
var referer = window.location.href // 연결후, 원래 페이지 복귀를 위해
$("body").isLoading({
text: "연결 중..",
position: "overlay"
});
$.post(rooturl+'/?r='+raccount+'&m=connect&a=save_referer',{
referer : referer
},function(response,status){
if(status=='success'){
document.location = target;
}else{
alert(status);
}
});
});
// 로그아웃
$('[data-act="logout"]').click(function(){
$('body').isLoading({
position: 'inside',
text: '<div class="d-flex justify-content-center align-items-center"><div class="spinner-border" role="status"><span class="sr-only">Loading...</span></div></div>',
});
getIframeForAction('');
setTimeout(function(){
frames.__iframe_for_action__.location.href = '/?r=home&m=site&a=logout';
}, 100);
});
// history.back
$(document).on('click','[data-history="back"]',function(){
window.history.back();
});
})

View File

@@ -0,0 +1,271 @@
/**
* --------------------------------------------------------------------------
* FCM(Firebase 클라우드 메시징)을 활용한 포그라운드 알림 처리 (데스크탑 전용)
* 참조코드 : https://github.com/firebase/quickstart-js/tree/master/messaging
* Licensed under an Apache-2 license.
* Firebase Quickstart Samples for Web https://firebase.google.com
* --------------------------------------------------------------------------
*/
firebase.initializeApp({'messagingSenderId': fcmSenderId});
const messaging = firebase.messaging();
messaging.usePublicVapidKey(fcmVAPID); //FCM 웹 푸시 인증서 키쌍(VAPID)
const permissionDivId = 'permission_div';
const permissionAlertId = 'permission_alert';
const tokenDivId = 'token_div';
const pushSettingId = 'push_setting';
const pushDisabledId = 'push_disabled';
const modalNoti = $('#modal-noti');
if (isNewUser(memberid)) {
console.log('새 사용자로 로그인 되었습니다.')
deleteToken() // 기존 토큰 삭제
window.localStorage.clear(); // 로컬 스토리지 초기화
}
// 인스턴스 ID 토큰이 업데이트되면 콜백이 시작됩니다.
messaging.onTokenRefresh(function() {
messaging.getToken().then(function(refreshedToken) {
console.log('토큰이 새로고침 되었습니다.'); // 새 인스턴스 ID 토큰이 아직 전송되지 않았 음을 나타냅니다.
setTokenSentToServer(false);
sendTokenToServer(refreshedToken); // 인스턴스 ID 토큰을 앱 서버로 전송합니다.
resetNotiUI(); // 새로운 인스턴스 ID 토큰을 표시하고 모든 이전 메시지의 UI를 지웁니다.
}).catch(function(err) {
console.log('새로 변경된 토큰을 검색 할 수 없습니다. ', err);
});
});
// - 앱에 포커스가 있는 동안 메시지가 수신됩니다.
messaging.onMessage(function(payload) {
console.log('메시지가 도착했습니다. ', payload);
var result = JSON.stringify(payload, null, 2);
var msg = JSON.parse(result);
var title=msg.notification.title;
var mbody=msg.notification.body;
var icon=msg.notification.icon;
var _mbody = mbody.replace(/(\n|\r\n)/g, '<br>');
console.log(_mbody)
$.notify({
icon: icon,
title: title,
message: mbody
}, {
type: 'media',
delay: 3000,
icon_type: 'image',
template: '<div data-notify="container" class="col-xs-11 col-sm-3 alert alert-{0}" role="alert">' +
'<img data-notify="icon" class="img-circle pull-left">' +
'<span data-notify="title">{1}</span>' +
'<span data-notify="message">{2}</span>' +
'</div>'
});
});
function resetNotiUI() {
clearMessages();
showToken('처리중...');
setMemberId(memberid) // 로그인 사용자의 아이디를 로컬 스토리지에 저장
// Get Instance ID token. Initially this makes a network call, once retrieved
// subsequent calls to getToken will return from cache. 이후의 getToken의 호출은 캐쉬로부터 돌아옵니다.
messaging.getToken().then(function(currentToken) {
if (currentToken) {
sendTokenToServer(currentToken);
updateUIForPushEnabled(currentToken);
} else {
// Show permission request.
if (!isRequestPermission()) {
setRequestPermission(false)
}
console.log('사용할수 있는 인스턴스 ID 토큰이 없습니다. 알림권한을 요청하십시오.');
// 알림권한요청 UI 를 보여줌.
setTimeout(function(){
updateUIForPushPermissionRequired();
}, 1000);
setTokenSentToServer(false);
}
}).catch(function(err) {
console.log('알림권한이 없거나 토큰을 검색하는 중 오류가 발생했습니다. ', err);
updateUIForPushDisabled()
setRequestPermission(false)
});
}
function showToken(currentToken) {
// 콘솔과 페이지에서 토큰을 보여줌
var tokenElement = document.querySelector('.token');
if (tokenElement) {
tokenElement.textContent = currentToken;
}
}
// Rb2에 인스턴스 ID 토큰을 보내세요.:
// - 이 앱으로 메시지를 다시 보내세요.
// - 주제 토큰 구독 / 탈퇴
function sendTokenToServer(currentToken) {
if (!isTokenSentToServer()) {
console.log('Rb2 서버에 토큰 보내기 중 ...');
var agent = navigator.userAgent, match;
var browser, version;
if((match = agent.match(/MSIE ([0-9]+)/)) || (match = agent.match(/Trident.*rv:([0-9]+)/))) browser = 'Internet Explorer';
else if(match = agent.match(/Chrome\/([0-9]+)/)) browser = 'Chrome';
else if(match = agent.match(/Firefox\/([0-9]+)/)) browser = 'Firefox';
else if(match = agent.match(/Safari\/([0-9]+)/)) browser = 'Safari';
else if((match = agent.match(/OPR\/([0-9]+)/)) || (match = agent.match(/Opera\/([0-9]+)/))) browser = 'Opera';
else browser = 'Unknown';
if(browser !== 'Unknown') version = match[1];
$.post(rooturl+'/?r='+raccount+'&m=notification&a=save_token',{
browser : browser,
version : version,
token : currentToken
},function(response){
var result = $.parseJSON(response);
console.log('토큰이 저장되었습니다.' + currentToken)
});
setTokenSentToServer(true);
} else {
console.log('토큰이 이미 서버에 전송 되었으므로 토큰이 변경되지 않는한 재전송되지 않습니다.');
}
}
function isTokenSentToServer() {
return window.localStorage.getItem('sentToServer') == 1;
}
function setTokenSentToServer(sent) {
window.localStorage.setItem('sentToServer', sent ? 1 : 0);
}
function isRequestPermission() {
return window.localStorage.getItem('setRequestPermission') == 1;
}
function setRequestPermission(allow) {
window.localStorage.setItem('setRequestPermission', allow ? 1 : 0);
}
function isNewUser(memberid) {
return window.localStorage.getItem('setMemberId') != memberid;
}
function setMemberId(memberid) {
window.localStorage.setItem('setMemberId', memberid ? memberid : 0);
}
function showHideDiv(divId, show) {
const div = document.querySelector('#' + divId);
if (div) {
if (show) {
div.style = 'display: visible';
} else {
div.style = 'display: none';
}
}
}
function requestPermission() {
console.log('권한 요청 중 ...');
messaging.requestPermission().then(function() {
var nt_web = ''; //알림수신
var nt_fcm = '1'; //푸시 알림수신
console.log('알림권한이 부여 되었습니다.');
$.notify({message: '알림권한이 부여 되었습니다.'});
resetNotiUI();
$.post(rooturl+'/?r='+raccount+'&m=notification&a=notice_config_user',{
sendAjax : true,
nt_web : nt_web,
nt_email : nt_email,
nt_fcm : nt_fcm
},function(response){
var result = $.parseJSON(response);
var error=result.error;
if (!error) console.log('웹알림/푸시알림 수신처리 되었습니다.')
});
}).catch(function(err) {
var nt_fcm = '';
showHideDiv(permissionAlertId, false);
showHideDiv(permissionDivId, false);
showHideDiv(pushDisabledId, true);
console.log('알림을 실행 할수있는 권한이 없습니다.', err);
$.notify({message: '알림 권한이 차단 되었습니다.'},{type: 'danger'});
});
}
function deleteToken() {
// 인스턴스 ID 토큰 삭제.
// [START delete_token]
messaging.getToken().then(function(currentToken) {
messaging.deleteToken(currentToken).then(function() {
console.log('토큰이 삭제 되었습니다.');
setTokenSentToServer(false);
// [START_EXCLUDE]
// 토큰이 삭제되면 관련 UI를 업데이트 합니다..
resetNotiUI();
// [END_EXCLUDE]
}).catch(function(err) {
console.log('토큰을 삭제할 수 없습니다. ', err);
});
// [END delete_token]
}).catch(function(err) {
console.log('인스턴스 ID 토큰을 가져 오는 중 오류가 발생했습니다. ', err);
});
}
// 메시지 모달을 닫고 내용을 초기화 합니다.
function clearMessages() {
modalNoti.modal('hide')
}
function updateUIForPushEnabled(currentToken) {
showHideDiv(permissionAlertId, false);
showHideDiv(tokenDivId, true);
showHideDiv(pushSettingId, true);
showHideDiv(permissionDivId, false);
showToken(currentToken);
}
function updateUIForPushDisabled() {
showHideDiv(pushDisabledId, true);
showHideDiv(permissionAlertId, false);
}
function updateUIForPushPermissionRequired() {
if (!isRequestPermission()) {
console.log('브라우저 알림 권한요청 이력이 없음')
if (!nt_web) {
showHideDiv(permissionAlertId, true);
} else {
console.log('사용자의 모든 알림수신을 차단하였습니다.')
}
} else {
console.log('브라우저 알림 권한요청 이력이 있음')
showHideDiv(permissionDivId, true);
}
}
//알림권한 요청 alert가 닫혔을때(나중에 설정)
$('#permission_alert').on('closed.bs.alert', function () {
$.notify({message: '설정 페이지에서 다시 권한설정 할 수 있습니다.'},{type: 'primary'});
setRequestPermission(true) // 요청이력을 로컬 스토리지에 저장하여 이후에 띄우지 않음
showHideDiv(permissionDivId, true);
})
resetNotiUI();

View File

@@ -0,0 +1,199 @@
/*! PhotoSwipe
* http://photoswipe.com
* Copyright (c) 2017 Dmitry Semenov; */
var initPhotoSwipeFromDOM = function(gallerySelector) {
// parse slide data (url, title, size ...) from DOM elements
// (children of gallerySelector)
var parseThumbnailElements = function(el) {
var thumbElements = el.childNodes,
numNodes = thumbElements.length,
items = [],
figureEl,
linkEl,
size,
item;
for(var i = 0; i < numNodes; i++) {
figureEl = thumbElements[i]; // <figure> element
// include only element nodes
if(figureEl.nodeType !== 1) {
continue;
}
linkEl = figureEl.children[0]; // <a> element
size = linkEl.getAttribute('data-size').split('x');
// create slide object
item = {
src: linkEl.getAttribute('href'),
w: parseInt(size[0], 10),
h: parseInt(size[1], 10)
};
if(figureEl.children.length > 1) {
// <figcaption> content
item.title = figureEl.children[1].innerHTML;
}
if(linkEl.children.length > 0) {
// <img> thumbnail element, retrieving thumbnail url
item.msrc = linkEl.children[0].getAttribute('src');
}
item.el = figureEl; // save link to element for getThumbBoundsFn
items.push(item);
}
return items;
};
// find nearest parent element
var closest = function closest(el, fn) {
return el && ( fn(el) ? el : closest(el.parentNode, fn) );
};
// triggers when user clicks on thumbnail
var onThumbnailsClick = function(e) {
e = e || window.event;
e.preventDefault ? e.preventDefault() : e.returnValue = false;
var eTarget = e.target || e.srcElement;
// find root element of slide
var clickedListItem = closest(eTarget, function(el) {
return (el.tagName && el.tagName.toUpperCase() === 'FIGURE');
});
if(!clickedListItem) {
return;
}
// find index of clicked item by looping through all child nodes
// alternatively, you may define index via data- attribute
var clickedGallery = clickedListItem.parentNode,
childNodes = clickedListItem.parentNode.childNodes,
numChildNodes = childNodes.length,
nodeIndex = 0,
index;
for (var i = 0; i < numChildNodes; i++) {
if(childNodes[i].nodeType !== 1) {
continue;
}
if(childNodes[i] === clickedListItem) {
index = nodeIndex;
break;
}
nodeIndex++;
}
if(index >= 0) {
// open PhotoSwipe if valid index found
openPhotoSwipe( index, clickedGallery );
}
return false;
};
// parse picture index and gallery index from URL (#&pid=1&gid=2)
var photoswipeParseHash = function() {
var hash = window.location.hash.substring(1),
params = {};
if(hash.length < 5) {
return params;
}
var vars = hash.split('&');
for (var i = 0; i < vars.length; i++) {
if(!vars[i]) {
continue;
}
var pair = vars[i].split('=');
if(pair.length < 2) {
continue;
}
params[pair[0]] = pair[1];
}
if(params.gid) {
params.gid = parseInt(params.gid, 10);
}
return params;
};
var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {
var pswpElement = document.querySelectorAll('.pswp-gallery')[0],
gallery,
options,
items;
items = parseThumbnailElements(galleryElement);
// define options (if needed)
options = {
// define gallery index (for URL)
galleryUID: galleryElement.getAttribute('data-pswp-uid'),
};
// PhotoSwipe opened from URL
if(fromURL) {
if(options.galleryPIDs) {
// parse real index when custom PIDs are used
// http://photoswipe.com/documentation/faq.html#custom-pid-in-url
for(var j = 0; j < items.length; j++) {
if(items[j].pid == index) {
options.index = j;
break;
}
}
} else {
// in URL indexes start from 1
options.index = parseInt(index, 10) - 1;
}
} else {
options.index = parseInt(index, 10);
}
// exit if index not found
if( isNaN(options.index) ) {
return;
}
if(disableAnimation) {
options.showAnimationDuration = 0;
}
// Pass data to PhotoSwipe and initialize it
gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
gallery.init();
};
// loop through all gallery elements and bind events
var galleryElements = document.querySelectorAll( gallerySelector );
for(var i = 0, l = galleryElements.length; i < l; i++) {
galleryElements[i].setAttribute('data-pswp-uid', i+1);
galleryElements[i].onclick = onThumbnailsClick;
}
// Parse URL and open gallery if it contains #&pid=3&gid=1
var hashData = photoswipeParseHash();
if(hashData.pid && hashData.gid) {
openPhotoSwipe( hashData.pid , galleryElements[ hashData.gid - 1 ], true, true );
}
};

View File

@@ -0,0 +1,499 @@
function setWidgetConfig(id,name,path,wdgvar,area) {
$('[data-role="widgetConfig"] [data-role="form"]').html('');
$.post(rooturl+'/?r='+raccount+'&m=site&a=get_widgetConfig',{
name : name,
widget : path,
wdgvar : wdgvar,
area : area
},function(response,status){
if(status=='success'){
var result = $.parseJSON(response);
var page=result.page;
var widget=result.widget;
if (!page) {
$.notify({message: '위젯설정을 확인해주세요.'},{type: 'danger'});
resetPage()
return false
}
$('[data-role="widgetConfig"]').attr('data-id',id);
$('[data-role="widgetConfig"]').attr('data-name',name);
$('[data-role="widgetConfig"]').attr('data-path',path);
$('[data-role="widgetConfig"] [data-role="form"]').html(page);
$('[data-role="widgetConfig"]').removeClass('d-none');
$('[data-role="widgetConfig"] [data-toggle="tooltip"]').tooltip();
setTimeout(function(){
$('[data-role="widgetConfig"] [data-role="form"]').find('.form-control')[0].focus();
}, 100);
//게시판 선택시
$('[data-role="widgetConfig"]').find('[name="bid"]').change(function(){
var name = $(this).find('option:selected').attr('data-name');
var link = $(this).find('option:selected').attr('data-link');
var id = $(this).find('option:selected').val();
if (id) {
$('[data-role="widgetConfig"]').find('[name="title"]').val(name);
$('[data-role="widgetConfig"]').find('[name="link"]').val(link);
} else {
$('[data-role="widgetConfig"]').find('[name="title"]').val('');
$('[data-role="widgetConfig"]').find('[name="link"]').val('');
}
});
} else {
$.notify({message: '위젯설정을 확인해주세요.'},{type: 'danger'});
return false
}
});
}
function resetPage() {
$('[data-role="widgetConfig"]').addClass('d-none');
$('[data-role="addWidget"]').removeClass('active');
$('[name="widget_selector"]').prop('selectedIndex',0);
$('[data-role="widgetPage"] [data-role="item"]').removeClass('active shadow-sm')
}
var layout_settings_tab = Cookies.get('layout-settings-tab')?Cookies.get('layout-settings-tab'):'01';
$('#layout-settings-tab [data-order="'+layout_settings_tab+'"]').tab('show')
$('a[data-toggle="pill"]').on('shown.bs.tab', function (e) {
var order = $(e.target).attr('data-order');
Cookies.set('layout-settings-tab', order)
})
$('[data-act="submit"]').click(function(e){
var form = $(this).closest('form');
$(this).attr('disabled',true)
setTimeout(function(){ form.submit(); }, 300);
});
$('[data-act="reset"]').click(function(){
var page = $(this).attr('data-page');
$.post(rooturl+'/?r='+raccount+'&m=site&a=deletelayoutpage',{
page : page
},function(response,status){
if(status=='success'){
var result = $.parseJSON(response);
var error=result.error;
if (!error) location.reload();
} else {
alert('다시시도 해주세요.')
return false
}
});
});
$('[data-role="widgetPage"]').on('click','[data-act="edit"]',function(e) {
e.preventDefault();
var item = $(this).closest('[data-role="item"]')
var id = item.attr('id');
var name = item.attr('data-name');
var path = item.attr('data-path');
var wdgvar = item.find('[name="widget_members[]"]').val();
var area;
if (!wdgvar) wdgvar = 'blank';
setWidgetConfig(id,name,path,wdgvar,area)
$('[data-role="widgetPage"] [data-role="item"]').removeClass('active shadow-sm');
$('[data-role="widgetConfig"]').attr('data-id',id);
$('[data-role="addWidget"]').removeClass('active');
item.addClass('active shadow-sm');
});
$('[name="settingMain"] [data-act="submit"]').click(function(){
$(this).attr('disabled', true);
var top_widgets=$(document).find('[data-area="top"] input[name="widget_members[]"]').map(function(){return $(this).val()}).get();
var left_widgets=$(document).find('[data-area="left"] input[name="widget_members[]"]').map(function(){return $(this).val()}).get();
var right_widgets=$(document).find('[data-area="right"] input[name="widget_members[]"]').map(function(){return $(this).val()}).get();
var new_widgets='';
if(top_widgets){
for(var i=0;i<top_widgets.length;i++) {
new_widgets+=top_widgets[i];
}
$('input[name="main_widget_top"]').val(new_widgets);
}
var new_widgets='';
if(left_widgets){
for(var i=0;i<left_widgets.length;i++) {
new_widgets+=left_widgets[i];
}
$('input[name="main_widget_left"]').val(new_widgets);
}
var new_widgets='';
if(right_widgets){
for(var i=0;i<right_widgets.length;i++) {
new_widgets+=right_widgets[i];
}
$('input[name="main_widget_right"]').val(new_widgets);
}
setTimeout(function(){
$('[name="settingMain"]').submit();
resetPage(); // 상태초기화
}, 500);
});
$( document ).ready(function() {
//순서변경
$('[data-plugin="nestable"]').nestable({
group: 1,
maxDepth: 1
});
$('#modal-widget-selector').on('show.bs.modal', function (event) {
var modal = $(this)
var button = $(event.relatedTarget);
var area = button.attr('data-area');
resetPage();
setTimeout(function(){ modal.find('[name="widget_selector"]').attr('data-area',area).trigger('focus'); }, 100);
})
$('#modal-widget-selector').find('[name="widget_selector"]').change(function(){
var modal = $('#modal-widget-selector');
var path = $(this).val();
var name = $(this).find('option:selected').text();
var id = randomId();
var area = $(this).attr('data-area');
var wdgvar = '';
var button = $('#modal-widget-selector').find('[data-act="submit"]');
modal.find('[data-role="none"]').removeClass('d-none');
modal.find('[data-role="thumb"]').attr('src','').addClass('d-none');
modal.find('[data-role="readme"]').html('');
button.attr('data-path',path);
button.attr('data-name',name);
button.attr('data-id',id);
button.attr('data-area',area);
$.post(rooturl+'/?r='+raccount+'&m=site&a=get_widgetGuide',{
widget : path
},function(response,status){
if(status=='success'){
var result = $.parseJSON(response);
var readme=result.readme;
var thumb=result.thumb;
if (!thumb) {
modal.find('[data-role="none"]').removeClass('d-none');
modal.find('[data-role="thumb"]').addClass('d-none');
} else {
modal.find('[data-role="none"]').addClass('d-none');
modal.find('[data-role="thumb"]').attr('src',thumb).removeClass('d-none');
modal.find('[data-role="readme"]').html(readme);
}
} else {
alert('위젯설정을 확인해주세요.')
return false
}
});
});
$('#modal-widget-selector').find('[data-act="submit"]').click(function(){
var button = $(this)
var path = button.attr('data-path');
var name = button.attr('data-name');
var id = button.attr('data-id');
var area = button.attr('data-area');
var wdgvar = '';
var modal = $('#modal-widget-selector');
if (!path) {
modal.find('[name="widget_selector"]').focus();
return false;
}
modal.modal('hide');
$('[data-role="widgetConfig"] [data-role="form"]').html('');
$('[data-role="widgetPage"] [data-role="item"]').removeClass('active shadow-sm')
if (path) {
setWidgetConfig(id,name,path,wdgvar,area)
$('[data-role="widgetPage"][data-area="'+area+'"] [data-role="addWidget"]').addClass('active');
} else {
$('[data-role="widgetConfig"]').addClass('d-none');
}
});
$('#modal-widget-selector').on('hidden.bs.modal', function (event) {
var modal = $(this)
var button = modal.find('[data-act="submit"]');
var selector = modal.find('[name="widget_selector"]');
button.removeAttr('data-path').removeAttr('data-id').removeAttr('data-area').removeAttr('data-name');
selector.removeAttr('data-area');
modal.find('[name="widget_selector"]').prop('selectedIndex',0);
modal.find('[data-role="readme"]').html('');
modal.find('[data-role="thumb"]').attr('src','')
$('[data-role="addWidget"]').removeClass('active');
})
$('[data-role="widgetConfig"]').on('click','[data-act="save"]',function() {
var name = $('[data-role="widgetConfig"]').attr('data-name');
var title = $('[data-role="widgetConfig"] [name="title"]').val();
var path = $('[data-role="widgetConfig"]').attr('data-path');
var id = $('[data-role="widgetConfig"]').attr('data-id');
var mod = $(this).attr('data-mod');
var area = $(this).attr('data-area');
$(this).attr('disabled', true);
if (!title) title = $('[data-role="widgetConfig"] [name="title"]').attr('placeholder');
$(document).find('[data-role="widgetPage"] .card').removeClass('animated fadeInUp')
var widget_var = id+'^'+title+'^'+path+'^';
$('[data-role="widgetConfig"] [name]').each(function(index){
var _name = $(this).attr('name');
if ( !$(this).val() && $(this).attr('placeholder')) {
var _var = $(this).attr('placeholder');
} else {
var _var = $(this).val()?$(this).val():'';
}
widget_var += _name+'='+_var+',';
});
setTimeout(function(){
resetPage();
if (mod=='add') {
var box = '<li class="card round-0 mb-3 text-muted text-center animated fadeInUp dd-item" data-name="'+name+'" data-path="'+path+'" data-role="item" id="'+id+'">'+
'<a href="" data-act="remove" title="삭제" class="badge badge-light border-0"><i class="fa fa-times" aria-hidden="true"></i></a>'+
'<span data-act="move" class="badge badge-light border-0 dd-handle"><i class="fa fa-arrows" aria-hidden="true"></i></span>'+
'<input type="hidden" name="widget_members[]" value="['+widget_var+']">'+
'<div class="card-body"><a href="#" class="text-reset" data-role="title" data-act="edit">'+title+'</a></div>'+
'</li>';
$('[data-role="widgetPage"][data-area="'+area+'"] .dd-list').append(box);
$('[data-role="widgetPage"] [data-toggle="tooltip"]').tooltip();
} else {
$(document).find('#'+id+' [name="widget_members[]"]').val('['+widget_var+']');
$(document).find('#'+id+'').addClass('animated fadeInUp');
$(document).find('#'+id+' [data-role="title"]').text(title);
$('[data-role="widgetPage"] [data-role="item"]').removeClass('active shadow-sm')
}
$('[name="settingMain"] [data-act="submit"]').click();
}, 600);
});
$('[data-role="widgetConfig"]').on('click','[data-act="code"]',function() {
var name = $('[data-role="widgetConfig"]').attr('data-name');
var title = $('[data-role="widgetConfig"] [name="title"]').val();
var path = $('[data-role="widgetConfig"]').attr('data-path');
if (!title) title = name;
var widget_var = '';
$('[data-role="widgetConfig"] [name]').each(function(index){
var _name = $(this).attr('name');
var _var = $(this).val()?$(this).val():'';
widget_var += "'"+_name+"'=>'"+_var+"',";
});
var code = "<?php getWidget('"+path+"',array("+widget_var+")) ?>";
$('[data-role="widgetPage"] [data-toggle="tooltip"]').tooltip();
$('#widgetCode').val(code);
var clipboard = new ClipboardJS('.js-clipboard');
clipboard.on('success', function (e) {
$(e.trigger)
.attr('title', '클립보드 복사완료!')
.tooltip('_fixTitle')
.tooltip('show')
.attr('title', '클립보드 복사')
.tooltip('_fixTitle')
e.clearSelection()
})
clipboard.on('error', function (e) {
var modifierKey = /Mac/i.test(navigator.userAgent) ? '\u2318' : 'Ctrl-'
var fallbackMsg = 'Press ' + modifierKey + 'C to copy'
$(e.trigger)
.attr('title', fallbackMsg)
.tooltip('_fixTitle')
.tooltip('show')
.attr('title', 'Copy to clipboard')
.tooltip('_fixTitle')
})
});
$('[data-role="widgetConfig"]').on('click','[data-act="cancel"]',function(e) {
e.preventDefault();
resetPage();
});
$('[data-role="widgetPage"]').on('click','[data-act="remove"]',function(e){
e.preventDefault();
$(this).closest('.card').remove();
resetPage();
});
$(document).on('click','[data-role="widgetConfig"] [data-act="make"]',function() {
var button = $(this);
var mod = button.attr('data-mod')
if (mod=='bbs') modal = $('#modal-widget-makebbs');
if (mod=='postlist') modal = $('#modal-widget-makelist');
if (!mod) return false;
modal.modal('show');
})
$('#modal-widget-makebbs').on('shown.bs.modal', function (event) {
var modal = $(this)
modal.find('[name="id"]').trigger('focus')
})
$('#modal-widget-makebbs').on('hidden.bs.modal', function (event) {
var modal = $(this)
modal.find('input').val('').removeClass('is-invalid');
modal.find('[data-act="submit"]').attr('disabled',false);
modal.find('.invalid-tooltip').text('')
})
$('#modal-widget-makebbs').find('input').keyup(function() {
$(this).removeClass('is-invalid');
$('#modal-widget-makebbs').find('.invalid-feedback').text('')
});
$('#modal-widget-makebbs').on('click','[data-act="submit"]',function() {
var modal = $('#modal-widget-makebbs');
var button = $(this);
var id = modal.find('[name="id"]').val();
var name = modal.find('[name="name"]').val();
if (!id) {
modal.find('[name="id"]').focus().addClass('is-invalid');
modal.find('[name="id"]').nextAll('.invalid-feedback').text('게시판 아이디를 입력해주세요.')
return false
}
//아이디 유용성 체크
if (!chkIdValue(id)) {
modal.find('[name="id"]').focus().addClass('is-invalid');
modal.find('[name="id"]').nextAll('.invalid-feedback').text('영문 또는 숫자를 사용해주세요.')
return false
}
if (!name) {
modal.find('[name="name"]').focus().addClass('is-invalid');
modal.find('[name="name"]').nextAll('.invalid-feedback').text('게시판 이름을 입력해주세요.')
return false
}
button.attr('disabled',true);
setTimeout(function(){
$.post(rooturl+'/?r='+raccount+'&m=bbs&a=makebbs',{
id : id,
name : name,
send_mod : 'ajax'
},function(response,status){
if(status=='success'){
var result = $.parseJSON(response);
var error=result.error;
if (error=='id_exists') {
modal.find('[name="id"]').focus().addClass('is-invalid');
modal.find('[name="id"]').nextAll('.invalid-feedback').text('이미 같은 아이디의 게시판이 존재합니다.');
button.attr('disabled',false);
return false
}
modal.modal('hide');
$('[data-role="widgetConfig"]').find('[name="bid"]').append('<option value="'+id+'" data-name="'+name+'" data-link="/b/'+id+'">ㆍ '+name+'('+id+')</option>');
$('[data-role="widgetConfig"]').find('[name="bid"]').val(id).attr('selected','selected');
$('[data-role="widgetConfig"]').find('[name="title"]').val(name);
$('[data-role="widgetConfig"]').find('[name="link"]').val('/b/'+id);
} else {
button.attr('disabled',false);
alert('다시 시도해 주세요.')
return false
}
});
}, 500);
})
$('#modal-widget-makelist').on('shown.bs.modal', function (event) {
var modal = $(this)
modal.find('[name="name"]').trigger('focus')
})
$('#modal-widget-makelist').on('hidden.bs.modal', function (event) {
var modal = $(this)
modal.find('input').val('').removeClass('is-invalid');
modal.find('[data-act="submit"]').attr('disabled',false);
modal.find('.invalid-tooltip').text('')
})
$('#modal-widget-makelist').find('input').keyup(function() {
$(this).removeClass('is-invalid');
$('#modal-widget-makelist').find('.invalid-feedback').text('')
});
$('#modal-widget-makelist').on('click','[data-act="submit"]',function() {
var modal = $('#modal-widget-makelist');
var button = $(this);
var name = modal.find('[name="name"]').val();
if (!name) {
modal.find('[name="name"]').focus().addClass('is-invalid');
modal.find('[name="name"]').nextAll('.invalid-feedback').text('리스트명을 입력해주세요.')
return false
}
button.attr('disabled',true);
setTimeout(function(){
$.post(rooturl+'/?r='+raccount+'&m=post&a=regis_list',{
display : 3,
name : name,
send_mod : 'ajax'
},function(response,status){
if(status=='success'){
var result = $.parseJSON(response);
var error=result.error;
var id=result.id;
if (error=='name_exists') {
modal.find('[name="name"]').focus().addClass('is-invalid');
modal.find('[name="name"]').nextAll('.invalid-feedback').text('이미 같은 이름의 리스트가 존재합니다.');
button.attr('disabled',false);
return false
}
modal.modal('hide');
$('[data-role="widgetConfig"]').find('[name="listid"]').append('<option value="'+id+'">ㆍ '+name+'</option>');
$('[data-role="widgetConfig"]').find('[name="listid"]').val(id).attr('selected','selected');
} else {
button.attr('disabled',false);
alert('다시 시도해 주세요.')
return false
}
});
}, 500);
})
});