퍼블 동기화
This commit is contained in:
@@ -2,6 +2,78 @@ etUI.utils.ready(function () {
|
||||
console.log('document ready');
|
||||
etUI.initUI();
|
||||
|
||||
// [공통] 헤더 스크롤 관련 기능
|
||||
etUI.pages.headerScroll = function () {
|
||||
const header = document.querySelector('.header');
|
||||
const modalFulls = document.querySelectorAll('.component-modal');
|
||||
|
||||
const updateHeaderClass = () => {
|
||||
if (!header) return;
|
||||
header.classList.toggle('scroll', window.scrollY > 0);
|
||||
};
|
||||
|
||||
const updateModalHeaderClass = () => {
|
||||
modalFulls.forEach(modalFull => {
|
||||
const modalContent = modalFull.querySelector('.modal-content');
|
||||
const modalHeader = modalFull.querySelector('.modal-header');
|
||||
if (modalContent && modalHeader) {
|
||||
const isScroll = modalContent.scrollTop > 0;
|
||||
modalHeader.classList.toggle('scroll', isScroll);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
etUI.hooks.useEventListener(window, 'scroll', updateHeaderClass);
|
||||
|
||||
modalFulls.forEach(modalFull => {
|
||||
const modalContent = modalFull.querySelector('.modal-content');
|
||||
if (modalContent) {
|
||||
modalContent.addEventListener('scroll', updateModalHeaderClass);
|
||||
}
|
||||
});
|
||||
|
||||
updateHeaderClass();
|
||||
};
|
||||
|
||||
// [공통] container 클래스 업데이트
|
||||
etUI.pages.updateContainerClassByLayout = function () {
|
||||
const container = document.getElementById('container');
|
||||
if (!container) return;
|
||||
|
||||
const hasFixedBtns = document.querySelector('.component-btns.fixed');
|
||||
const hasFooter = document.querySelector('footer');
|
||||
|
||||
// 조건에 맞게 클래스 추가/제거
|
||||
if (hasFixedBtns) {
|
||||
container.classList.add('btm-fixbtn');
|
||||
} else {
|
||||
container.classList.remove('btm-fixbtn');
|
||||
}
|
||||
|
||||
if (hasFooter) {
|
||||
container.classList.add('btm-footer');
|
||||
} else {
|
||||
container.classList.remove('btm-footer');
|
||||
}
|
||||
};
|
||||
|
||||
// [공통] 탭 버튼 활성화 토글
|
||||
etUI.pages.tabButtonToggle = function () {
|
||||
const tabGroups = document.querySelectorAll('.component-btns.type-tab');
|
||||
|
||||
tabGroups.forEach(group => {
|
||||
const buttons = group.querySelectorAll('.btn');
|
||||
|
||||
buttons.forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
buttons.forEach(btn => btn.classList.remove('active'));
|
||||
|
||||
button.classList.add('active');
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// [공통] 스위치 체크 스타일
|
||||
etUI.pages.initSwitchStyleToggle = function () {
|
||||
const switches = document.querySelectorAll('.switch-inner input[type="checkbox"]');
|
||||
@@ -111,47 +183,9 @@ etUI.utils.ready(function () {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// all(전체선택)
|
||||
document.querySelectorAll('.component-select .select-box.all').forEach(allBox => {
|
||||
allBox.addEventListener('click', function (e) {
|
||||
const selectBox = e.target.closest('.component-select').querySelector('.select-box');
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
// active 상태면 이벤트x
|
||||
if (this.classList.contains('active')) return;
|
||||
|
||||
// all 버튼 제외한 나머지 셀렉트박스 텍스트 초기화
|
||||
document.querySelectorAll('.component-select .select-box').forEach(activeBox => {
|
||||
if (allBox) {
|
||||
const selectTxt = activeBox.querySelector('.select-txt');
|
||||
if (selectTxt) {
|
||||
selectTxt.textContent = '';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Selectbox.js의 removeAllActiveClass 함수 사용
|
||||
selectBoxComp.removeAllActiveClass(defaultTexts);
|
||||
|
||||
// all 버튼에 active 클래스 추가 (직접 구현)
|
||||
if (this) {
|
||||
this.classList.add('active');
|
||||
}
|
||||
activeSelectBox = this;
|
||||
|
||||
// all일 경우 옵션 숨기기
|
||||
const options = this.closest('.component-select').querySelector('.select-options');
|
||||
if (options) {
|
||||
options.style.display = 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// [공통] 직접 입력 option 선택 시 input 표시
|
||||
// [공통] option 선택 시 매칭되는 input 표시
|
||||
etUI.pages.initDirectInputToggle = function () {
|
||||
const selectGroups = document.querySelectorAll('.select-group');
|
||||
|
||||
@@ -159,17 +193,18 @@ etUI.utils.ready(function () {
|
||||
const select = group.querySelector('.component-select');
|
||||
const selectBox = select.querySelector('.select-box');
|
||||
const options = select.querySelectorAll('.option');
|
||||
const directInput = group.querySelector('.component-input');
|
||||
const inputs = group.querySelectorAll('.component-input');
|
||||
|
||||
// 직접입력 input이 없다면 skip
|
||||
if (!directInput) return;
|
||||
|
||||
// 직접입력 input 기본 숨김
|
||||
directInput.style.display = 'none';
|
||||
// 모든 input 기본 숨김
|
||||
inputs.forEach(input => {
|
||||
input.style.display = 'none';
|
||||
});
|
||||
|
||||
const updateVisibility = (selectedText) => {
|
||||
const isDirect = selectedText === '직접 입력';
|
||||
directInput.style.display = isDirect ? '' : 'none';
|
||||
inputs.forEach(input => {
|
||||
const matchValue = input.getAttribute('data-option');
|
||||
input.style.display = matchValue === selectedText ? '' : 'none';
|
||||
});
|
||||
};
|
||||
|
||||
// 초기 상태 설정
|
||||
@@ -187,10 +222,41 @@ etUI.utils.ready(function () {
|
||||
});
|
||||
};
|
||||
|
||||
// [공통] appbar 아이콘 활성화
|
||||
etUI.pages.activeAppbarOnPath = function () {
|
||||
const appbar = document.querySelector('.footer-menu');
|
||||
const currentPath = window.location.pathname;
|
||||
|
||||
if (!appbar) return;
|
||||
|
||||
appbar.querySelectorAll('.active').forEach(el => el.classList.remove('active'));
|
||||
|
||||
// 경로와 클래스 매핑
|
||||
const pathMap = {
|
||||
'/pages/ACCO': 'menu-acco',
|
||||
'/pages/REGI': 'menu-regi',
|
||||
'/pages/STAT': 'menu-stat',
|
||||
'/pages/INFO': 'menu-info',
|
||||
};
|
||||
|
||||
// 경로에 해당하는 앱바 아이콘 활성화
|
||||
for (const [path, className] of Object.entries(pathMap)) {
|
||||
if (currentPath.includes(path)) {
|
||||
const targetElement = appbar.querySelector(`.${className}`);
|
||||
if (targetElement) targetElement.classList.add('active');
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
document.fonts.ready.then(() => {
|
||||
etUI.pages.initSwitchStyleToggle();
|
||||
etUI.pages.initPriceInputComma();
|
||||
etUI.pages.radioSelectbox();
|
||||
etUI.pages.initDirectInputToggle();
|
||||
etUI.pages.updateContainerClassByLayout();
|
||||
etUI.pages.activeAppbarOnPath();
|
||||
etUI.pages.headerScroll();
|
||||
etUI.pages.tabButtonToggle();
|
||||
});
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,825 @@
|
||||
function useA11yKeyEvent() {
|
||||
function firstNodeFocusOut(target, handler) {
|
||||
return etUI.hooks.useEventListener(target, 'keydown', (e) => {
|
||||
if (e.key === 'Tab' && e.shiftKey) {
|
||||
handler();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function lastNodeFocusOut(target, handler) {
|
||||
return etUI.hooks.useEventListener(target, 'keydown', (e) => {
|
||||
if (e.key === 'Tab' && !e.shiftKey) {
|
||||
handler();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
firstNodeFocusOut,
|
||||
lastNodeFocusOut,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* target)의 외부를 클릭했을 때 콜백 함수를 실행
|
||||
* 예외적으로 클릭을 허용할 요소들의 선택자를 포함하는 배열을 옵션으로 받을 수 있습니다.
|
||||
*
|
||||
* @param {Element} target - 클릭 이벤트의 외부 클릭 감지를 수행할 대상 DOM 요소입니다.(필수)
|
||||
* @param {Function} callback - 외부 클릭이 감지되었을 때 실행할 콜백 함수입니다.(필수)
|
||||
* @param {Array<string>} exceptions - 외부 클릭 감지에서 예외 처리할 요소들의 선택자를 포함하는 배열입니다.(옵션)
|
||||
*/
|
||||
function useClickOutside(target, callback, exceptions = []) {
|
||||
return etUI.hooks.useEventListener(document, 'click', (event) => {
|
||||
const isClickInsideException = exceptions.some((selector) => {
|
||||
const exceptionElement = document.querySelector(selector);
|
||||
return exceptionElement && exceptionElement.contains(event.target);
|
||||
});
|
||||
|
||||
if (!target.contains(event.target) && !isClickInsideException) {
|
||||
callback(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
function useCore(
|
||||
initialProps = {},
|
||||
initialState = {},
|
||||
render,
|
||||
options = {
|
||||
dataset: true,
|
||||
},
|
||||
) {
|
||||
const actions = {};
|
||||
let $target;
|
||||
const cleanups = [];
|
||||
const NO_BUBBLING_EVENTS = ['blur', 'focus', 'focusin', 'focusout', 'pointerleave'];
|
||||
const onStateChange = () => {};
|
||||
let stateCallback;
|
||||
const props = new Proxy(initialProps, {
|
||||
set: (target, key, value) => {
|
||||
Reflect.set(target, key, value);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
const state = new Proxy(initialState, {
|
||||
set: (target, key, value) => {
|
||||
Reflect.set(target, key, value);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
function setTarget(_$target, { stateCallback: _stateCallback } = {}) {
|
||||
$target = _$target;
|
||||
if (_stateCallback) {
|
||||
stateCallback = _stateCallback;
|
||||
}
|
||||
|
||||
if (options.dataset) {
|
||||
const { getPropsFromDataset, getVarsFromDataset } = etUI.hooks.useDataset($target);
|
||||
const datasetProps = getPropsFromDataset();
|
||||
const datasetVars = getVarsFromDataset();
|
||||
|
||||
setProps({ ...props, ...datasetProps });
|
||||
setState({ ...state, ...datasetVars }, { silent: true, immediate: true });
|
||||
}
|
||||
}
|
||||
|
||||
function setProps(newProps) {
|
||||
Object.keys(newProps).forEach((key) => {
|
||||
props[key] = newProps[key];
|
||||
});
|
||||
}
|
||||
|
||||
function setState(newState, { silent = false, immediate = false } = {}) {
|
||||
if (etUI.utils.isDeepEqual(state, newState)) return;
|
||||
|
||||
Object.keys(newState).forEach((key) => {
|
||||
state[key] = newState[key];
|
||||
});
|
||||
if (!silent && render !== undefined && render !== null && typeof render === 'function') {
|
||||
render(immediate);
|
||||
}
|
||||
|
||||
if (options.dataset) {
|
||||
const { setVarsFromDataset } = etUI.hooks.useDataset($target);
|
||||
setVarsFromDataset(state);
|
||||
}
|
||||
|
||||
stateCallback && stateCallback(state);
|
||||
}
|
||||
|
||||
function addEvent(eventType, selector, callback) {
|
||||
const $eventTarget = selector ? $target.querySelector(selector) : $target;
|
||||
|
||||
if (NO_BUBBLING_EVENTS.includes(eventType)) {
|
||||
const cleanup = etUI.hooks.useEventListener($eventTarget, eventType, callback);
|
||||
return cleanups.push(cleanup);
|
||||
}
|
||||
|
||||
const eventHandler = (event) => {
|
||||
let $eventTarget = event.target.closest(selector);
|
||||
|
||||
if (!selector) {
|
||||
$eventTarget = event.target;
|
||||
}
|
||||
|
||||
if ($eventTarget) {
|
||||
callback(event);
|
||||
}
|
||||
};
|
||||
|
||||
$target.addEventListener(eventType, eventHandler);
|
||||
const cleanup = () => $target.removeEventListener(eventType, eventHandler);
|
||||
cleanups.push(cleanup);
|
||||
}
|
||||
|
||||
function removeEvent() {
|
||||
etUI.utils.allCleanups(cleanups);
|
||||
}
|
||||
|
||||
return {
|
||||
cleanups,
|
||||
setTarget,
|
||||
actions,
|
||||
state,
|
||||
props,
|
||||
setState,
|
||||
setProps,
|
||||
addEvent,
|
||||
removeEvent,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* useDataset
|
||||
* @param $target {HTMLElement}
|
||||
*/
|
||||
function useDataset($target) {
|
||||
let datasetProps = {},
|
||||
datasetVars = {};
|
||||
|
||||
function getDatasetByPrefix(prefix) {
|
||||
const dataset = {};
|
||||
Object.keys($target.dataset).forEach((key) => {
|
||||
let value = $target.dataset[key];
|
||||
if (value === 'true') {
|
||||
value = true;
|
||||
} else if (value === 'false') {
|
||||
value = false;
|
||||
} else if(typeof value === 'string' && value.includes('{')){
|
||||
value = JSON.parse(value);
|
||||
} else if(!isNaN(value)) {
|
||||
value = parseFloat(value);
|
||||
}
|
||||
|
||||
if(key.startsWith(prefix)){
|
||||
dataset[etUI.utils.removePrefixCamelString(key, prefix)] = value;
|
||||
}
|
||||
});
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
function getDatasetExceptPrefix(prefix) {
|
||||
const dataset = {};
|
||||
|
||||
Object.keys($target.dataset).forEach((key) => {
|
||||
let value = $target.dataset[key];
|
||||
|
||||
if (value === 'true') {
|
||||
value = true;
|
||||
} else if (value === 'false') {
|
||||
value = false;
|
||||
}
|
||||
|
||||
if(!key.startsWith(prefix)){
|
||||
dataset[etUI.utils.removePrefixCamelString(key, prefix)] = value;
|
||||
}
|
||||
});
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
function setDatasetByPrefix(data, prefix) {
|
||||
Object.keys(data).forEach((key) => {
|
||||
if(prefix){
|
||||
$target.dataset[`${prefix}${etUI.utils.capitalize(key)}`] = data[key];
|
||||
}else{
|
||||
$target.dataset[key] = data[key];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getPropsFromDataset() {
|
||||
datasetProps = getDatasetByPrefix('props');
|
||||
return datasetProps;
|
||||
}
|
||||
|
||||
function getVarsFromDataset() {
|
||||
datasetVars = getDatasetExceptPrefix('props');
|
||||
return datasetVars;
|
||||
}
|
||||
|
||||
function setPropsFromDataset(props) {
|
||||
setDatasetByPrefix(props, 'props');
|
||||
}
|
||||
|
||||
function setVarsFromDataset(vars) {
|
||||
setDatasetByPrefix(vars, '');
|
||||
}
|
||||
|
||||
function setStringToObject(props) {
|
||||
// dataset에서 객체 형태인 스트링값 타입 객체로 바꿔줌
|
||||
for (const key in props) {
|
||||
if (!(typeof props[key] === 'boolean') && props[key].includes('{')) {
|
||||
props[key] = JSON.parse(props[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
return {
|
||||
getPropsFromDataset,
|
||||
setPropsFromDataset,
|
||||
getVarsFromDataset,
|
||||
setVarsFromDataset,
|
||||
setStringToObject,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
function useDialog() {
|
||||
let $layerWrapBox;
|
||||
|
||||
function createLayerWrap() {
|
||||
$layerWrapBox = document.createElement('div');
|
||||
$layerWrapBox.classList.add('layer-wrap');
|
||||
document.body.appendChild($layerWrapBox);
|
||||
}
|
||||
|
||||
const alert = (...opts) => {
|
||||
let $layerWrap = document.querySelector('.layer-wrap');
|
||||
const dialog = new etUI.components.Dialog();
|
||||
|
||||
if (!$layerWrap) {
|
||||
createLayerWrap();
|
||||
$layerWrap = $layerWrapBox;
|
||||
}
|
||||
|
||||
if (typeof opts[0] === 'string') {
|
||||
dialog.core.init($layerWrap, { dialogType: 'alert', message: opts[0], callback: opts[1] });
|
||||
} else if (typeof opts[0] === 'object') {
|
||||
dialog.core.init($layerWrap, { dialogType: 'alert', ...opts[0] });
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
};
|
||||
|
||||
const confirm = (...opts) => {
|
||||
let $layerWrap = document.querySelector('.layer-wrap');
|
||||
const dialog = new etUI.components.Dialog();
|
||||
|
||||
if (!$layerWrap) {
|
||||
createLayerWrap();
|
||||
$layerWrap = $layerWrapBox;
|
||||
}
|
||||
|
||||
if (typeof opts[0] === 'string') {
|
||||
dialog.core.init($layerWrap, { dialogType: 'confirm', message: opts[0], positiveCallback: opts[1] });
|
||||
} else if (typeof opts[0] === 'object') {
|
||||
dialog.core.init($layerWrap, { dialogType: 'confirm', ...opts[0] });
|
||||
}
|
||||
|
||||
dialog.open();
|
||||
};
|
||||
|
||||
const previewImage = (...opts) => {
|
||||
let $layerWrap = document.querySelector('.layer-wrap');
|
||||
const dialog = new etUI.components.Dialog();
|
||||
|
||||
if (!$layerWrap) {
|
||||
createLayerWrap();
|
||||
$layerWrap = $layerWrapBox;
|
||||
}
|
||||
|
||||
dialog.core.init($layerWrap, { dialogType: 'previewImage', ...opts[0] });
|
||||
|
||||
dialog.open();
|
||||
};
|
||||
|
||||
const toastBasic = (...opts) => {
|
||||
let $toastWrap = document.querySelector('.toast-wrap')
|
||||
const toast = new etUI.components.Toast();
|
||||
|
||||
if (!$toastWrap) return;
|
||||
|
||||
toast.core.init($toastWrap, {type: 'basic', ...opts[0]});
|
||||
toast.open();
|
||||
}
|
||||
|
||||
const toastCloseBtn = (...opts) => {
|
||||
let $toastWrap = document.querySelector('.toast-wrap')
|
||||
const toast = new etUI.components.Toast();
|
||||
|
||||
if (!$toastWrap) return;
|
||||
|
||||
toast.core.init($toastWrap, {type: 'close', ...opts[0]});
|
||||
toast.open();
|
||||
}
|
||||
|
||||
const toastLinkBtn = (...opts) => {
|
||||
let $toastWrap = document.querySelector('.toast-wrap')
|
||||
const toast = new etUI.components.Toast();
|
||||
|
||||
if (!$toastWrap) return;
|
||||
|
||||
toast.core.init($toastWrap, {type: 'link', ...opts[0]});
|
||||
toast.open();
|
||||
}
|
||||
|
||||
return {
|
||||
alert,
|
||||
confirm,
|
||||
previewImage,
|
||||
toastBasic,
|
||||
toastCloseBtn,
|
||||
toastLinkBtn,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
function dialogTmpl() {
|
||||
const $templateHTML = ({ dialogType, type, title, message, positiveText, negativeText }) => `
|
||||
<div class="component-dialog">
|
||||
<div class="dialog-dimm"></div>
|
||||
<div class="dialog-frame">
|
||||
<div class="dialog-container">
|
||||
<div class="dialog-header">
|
||||
${title ? `<h3 class="dialog-tit">${title}</h3>` : ''}
|
||||
</div>
|
||||
<div class="dialog-content">
|
||||
${dialogType === 'alert' ? `<span class="${type}">icon</span>` : ''}
|
||||
|
||||
${dialogType === 'alert' ? `<p class="dialog-info">${message.replace(/\n/g, '<br>')}</p>` : ''}
|
||||
${dialogType === 'confirm' ? `<p class="dialog-info" style="text-align:left;">${message.replace(/\n/g, '<br>')}</p>` : ''}
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
${positiveText ? `<button type="button" class="btn dialog-positive btn-primary">${positiveText}</button>` : ''}
|
||||
${dialogType === 'confirm' ? `<button type="button" class="btn dialog-negative btn-tertiary">${negativeText}</button>` : ''}
|
||||
</div>
|
||||
|
||||
${dialogType === 'alert' ? `<button type="button" class="dialog-close"><span class="hide-txt">팝업 닫기</span></button>` : ''}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const $templatePreviewImageHTML = ({ dialogType, images, title }) => `
|
||||
<div class="component-dialog dialog-preview-image">
|
||||
<div class="dialog-dimm"></div>
|
||||
<div class="dialog-frame">
|
||||
<div class="dialog-container">
|
||||
<div class="dialog-header">
|
||||
${title ? `<h3 class="dialog-tit">${title}</h3>` : ''}
|
||||
</div>
|
||||
<div class="dialog-content">
|
||||
<div class="component-swiper">
|
||||
<!-- Additional required wrapper -->
|
||||
<div class="swiper-wrapper">
|
||||
${images
|
||||
.map(
|
||||
(image) => `
|
||||
<div class="swiper-slide">
|
||||
<img src="${image.src}" alt="${image.alt}" />
|
||||
</div>
|
||||
`,
|
||||
)
|
||||
.join('')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn btn-square btn-white dialog-negative">닫기</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
return {
|
||||
$templateHTML,
|
||||
$templatePreviewImageHTML,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* useEventListener
|
||||
* @param target {HTMLElement|HTMLElement[]}
|
||||
* @param type {string}
|
||||
* @param listener {function}
|
||||
* @param options {object}
|
||||
* @returns {function(): *}
|
||||
*/
|
||||
function useEventListener(target, type, listener, options = {}) {
|
||||
if (NodeList.prototype.isPrototypeOf(target)) {
|
||||
target.forEach((element) => element.addEventListener(type, listener, options));
|
||||
return () => target.forEach((element) => element.removeEventListener(type, listener, options));
|
||||
}
|
||||
|
||||
target.addEventListener(type, listener, options);
|
||||
return () => target.removeEventListener(type, listener, options);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* getBoundingClientRect
|
||||
* @param { Element } parent
|
||||
* @param { String } selector
|
||||
* @returns
|
||||
*/
|
||||
function useGetClientRect(parent, selector) {
|
||||
const rect = parent.querySelector(selector)?.getBoundingClientRect();
|
||||
if (!rect) return {};
|
||||
else
|
||||
return {
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
top: rect.top,
|
||||
bottom: rect.bottom,
|
||||
left: rect.left,
|
||||
right: rect.right,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
function useLayer(type = 'modal') {
|
||||
function getVisibleLayer() {
|
||||
const $layerComponents = Array.from(document.querySelector('.layer-wrap').children).filter(($el) => {
|
||||
const isModalComponent = $el.classList.contains('component-modal');
|
||||
const isDialogComponent = $el.classList.contains('component-dialog');
|
||||
|
||||
return isModalComponent || isDialogComponent;
|
||||
});
|
||||
|
||||
return $layerComponents.filter(($el) => {
|
||||
const style = window.getComputedStyle($el);
|
||||
return style.display !== 'none';
|
||||
});
|
||||
}
|
||||
|
||||
function getTopDepth() {
|
||||
const $visibleLayerComponents = getVisibleLayer();
|
||||
return 100 + $visibleLayerComponents.length;
|
||||
}
|
||||
|
||||
function setLayerOpacity(defaultOpacity = 0.5) {
|
||||
const $visibleLayerComponents = getVisibleLayer();
|
||||
$visibleLayerComponents.forEach(($el, index) => {
|
||||
const opacity = etUI.utils.getBlendOpacity(defaultOpacity, $visibleLayerComponents.length);
|
||||
|
||||
if ($el.querySelector('.modal-dimm')) {
|
||||
$el.querySelector('.modal-dimm').style.backgroundColor = `rgba(0, 0, 0, ${opacity})`;
|
||||
}
|
||||
|
||||
if ($el.querySelector('.dialog-dimm')) {
|
||||
$el.querySelector('.dialog-dimm').style.backgroundColor = `rgba(0, 0, 0, ${opacity})`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// modal 떴을때 덜컹거리는 거 없애는 test 중
|
||||
function enableScrollLock() {
|
||||
document.documentElement.style.overflow = 'hidden';
|
||||
// const scrollY = window.scrollY;
|
||||
// document.documentElement.style.overflowY = 'scroll';
|
||||
// document.body.style.position = 'fixed';
|
||||
// document.body.style.top = `-${scrollY}px`;
|
||||
// document.body.style.width = '100%';
|
||||
}
|
||||
|
||||
function disableScrollLock() {
|
||||
const $visibleLayerComponents = getVisibleLayer();
|
||||
// console.log('$visibleLayerComponents', $visibleLayerComponents);
|
||||
// if ($visibleLayerComponents.length === 0) {
|
||||
// document.documentElement.style.overflow = null;
|
||||
// }
|
||||
document.documentElement.style.overflow = null;
|
||||
|
||||
// const scrollY = parseInt(document.body.style.top || '0') * -1;
|
||||
// document.documentElement.style.overflowY = '';
|
||||
// document.body.style.position = '';
|
||||
// document.body.style.top = '';
|
||||
// document.body.style.width = '';
|
||||
// window.scrollTo(0, scrollY);
|
||||
}
|
||||
|
||||
return {
|
||||
getVisibleLayer,
|
||||
getTopDepth,
|
||||
setLayerOpacity,
|
||||
enableScrollLock,
|
||||
disableScrollLock,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
function useMediaQuery(){
|
||||
function mediaQueryAction(...args){
|
||||
const gsapMediaQuery = gsap.matchMedia();
|
||||
|
||||
if (gsapMediaQuery) {
|
||||
gsapMediaQuery.kill();
|
||||
}
|
||||
|
||||
const mediaQueryCondition = etUI.utils.getMediaQueryCondition(etUI.config.media.names, etUI.config.media.points)
|
||||
|
||||
gsapMediaQuery.add(mediaQueryCondition, ...args);
|
||||
|
||||
return gsapMediaQuery;
|
||||
}
|
||||
|
||||
return {
|
||||
mediaQueryAction,
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
function useMutationState(){
|
||||
let $target, $ref = {
|
||||
$state: {}
|
||||
}, mutationObserver, render;
|
||||
|
||||
function initMutationState(_$target, _render){
|
||||
$target = _$target
|
||||
render = _render;
|
||||
|
||||
setMutationObserver()
|
||||
setStateByDataset()
|
||||
}
|
||||
|
||||
function setStateByDataset(){
|
||||
const filteredDataset = {};
|
||||
const dataset = $target.dataset;
|
||||
|
||||
Object.keys(dataset).forEach((key) => {
|
||||
if(key.startsWith('vars')){
|
||||
filteredDataset[key.replace('vars', '').toLowerCase()] = dataset[key];
|
||||
}
|
||||
})
|
||||
|
||||
setState(filteredDataset)
|
||||
render();
|
||||
}
|
||||
|
||||
function setMutationObserver(){
|
||||
const config = { attributes: true, childList: false, subtree: false };
|
||||
|
||||
const callback = (mutationList, observer) => {
|
||||
for (const mutation of mutationList) {
|
||||
if (mutation.type === 'attributes'
|
||||
&& mutation.attributeName !== 'style'
|
||||
&& mutation.attributeName !== 'class'
|
||||
) {
|
||||
setStateByDataset()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mutationObserver = new MutationObserver(callback);
|
||||
mutationObserver.observe($target, config);
|
||||
}
|
||||
|
||||
function setState(newState){
|
||||
$ref.$state = { ...$ref.$state, ...newState };
|
||||
}
|
||||
|
||||
function setDataState(newState) {
|
||||
const $newState = { ...$ref.$state, ...newState };
|
||||
|
||||
Object.keys($newState).forEach((key) => {
|
||||
$target.dataset[`vars${etUI.utils.capitalize(key)}`] = $newState[key];
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
$ref,
|
||||
setState,
|
||||
setDataState,
|
||||
initMutationState
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
function useSelectBoxTemp() {
|
||||
const $templateCustomHTML = {
|
||||
label(text) {
|
||||
return `
|
||||
<div id="combo1-label" class="combo-label">${text}</div>
|
||||
`;
|
||||
},
|
||||
selectBtn(text) {
|
||||
return `
|
||||
<button type="button" id="combo1" class="select-box" role="combobox" aria-controls="listbox1" aria-expanded="false" aria-labelledby="combo1-label" aria-activedescendant="">
|
||||
<span style="pointer-events: none;">${text}</span>
|
||||
</button>
|
||||
`;
|
||||
},
|
||||
itemsWrap(itemsHTML) {
|
||||
return `
|
||||
<ul id="listbox1" class="select-options" role="listbox" aria-labelledby="combo1-label" tabindex="-1">
|
||||
${itemsHTML}
|
||||
</ul>
|
||||
`;
|
||||
},
|
||||
items(item, selected = false) {
|
||||
return `
|
||||
<li role="option" class="option" aria-selected="${selected}" data-value="${item.value}">
|
||||
${item.text}
|
||||
</li>
|
||||
`;
|
||||
},
|
||||
};
|
||||
|
||||
const $templateBasicHTML = {
|
||||
label(text) {
|
||||
return `
|
||||
<div id="combo1-label" class="combo-label">${text}</div>
|
||||
`;
|
||||
},
|
||||
selectBtn(text) {
|
||||
return `
|
||||
<option value="" selected disabled hidden>${text}</option>
|
||||
`;
|
||||
},
|
||||
itemsWrap(itemsHTML) {
|
||||
return `
|
||||
<select class="select-list" required>
|
||||
${itemsHTML}
|
||||
</select>
|
||||
`;
|
||||
},
|
||||
items(item, selected = false) {
|
||||
return `
|
||||
<option value="${item.value}">${item.text}</option>
|
||||
`;
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
$templateCustomHTML,
|
||||
$templateBasicHTML,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
function useState(initialValue = {}, callback) {
|
||||
const state = new Proxy(initialValue, {
|
||||
set: (target, key, value) => {
|
||||
target[key] = value;
|
||||
|
||||
if (callback) {
|
||||
callback(target);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const setState = (newState) => {
|
||||
Object.keys(newState).forEach((key) => {
|
||||
state[key] = newState[key];
|
||||
})
|
||||
}
|
||||
|
||||
return [state, setState];
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
function useSwiperTmpl() {
|
||||
const $templateHTML = {
|
||||
navigation() {
|
||||
return `
|
||||
<button type="button" class="swiper-button-prev">이전</button>
|
||||
<button type="button" class="swiper-button-next">다음</button>
|
||||
`;
|
||||
},
|
||||
pagination() {
|
||||
return `
|
||||
<div class="swiper-pagination"></div>
|
||||
`;
|
||||
},
|
||||
autoplay() {
|
||||
return `
|
||||
<button type="button" class="swiper-autoplay play"></button>
|
||||
`;
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
$templateHTML,
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* temp timeline
|
||||
* @returns
|
||||
*/
|
||||
function useTransition() {
|
||||
// select
|
||||
const useSelectShow = (target, type, option) => {
|
||||
if (!target) return;
|
||||
const timeline = gsap.timeline({ paused: true });
|
||||
|
||||
const optionList = {
|
||||
fast: { duration: 0.15 },
|
||||
normal: { duration: 0.3 },
|
||||
slow: { duration: 0.7 },
|
||||
};
|
||||
const gsapOption = { ...optionList[type], ...option };
|
||||
|
||||
timeline.to(target, {
|
||||
alpha: 0,
|
||||
ease: 'linear',
|
||||
onComplete() {
|
||||
target.style.display = 'none';
|
||||
},
|
||||
...gsapOption,
|
||||
});
|
||||
|
||||
return {
|
||||
timelineEl: timeline._recent.vars,
|
||||
timeline: (state) => {
|
||||
state
|
||||
? gsap.to(target, {
|
||||
onStart: () => {
|
||||
target.style.display = 'block';
|
||||
},
|
||||
ease: 'linear',
|
||||
alpha: 1,
|
||||
...gsapOption,
|
||||
})
|
||||
: gsap.to(target, {
|
||||
alpha: 0,
|
||||
ease: 'linear',
|
||||
onComplete() {
|
||||
target.style.display = 'none';
|
||||
target.closest('.component-select').classList.remove('show');
|
||||
target.closest('.component-select').classList.add('hide');
|
||||
},
|
||||
...gsapOption,
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const selectDimmShow = (target) => {
|
||||
if (!target) return;
|
||||
|
||||
gsap.to(target, {
|
||||
onStart: () => {
|
||||
target.style.display = 'block';
|
||||
},
|
||||
ease: 'linear',
|
||||
alpha: 0.6,
|
||||
duration: 0.15,
|
||||
overwrite: true
|
||||
})
|
||||
}
|
||||
|
||||
const selectDimmClose = (target) => {
|
||||
if (!target) return;
|
||||
|
||||
gsap.to(target, {
|
||||
alpha: 0,
|
||||
ease: 'linear',
|
||||
duration: 0.15,
|
||||
onComplete() {
|
||||
target.style.display = 'none';
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
useSelectShow,
|
||||
selectDimmShow,
|
||||
selectDimmClose
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user