65 lines
2.7 KiB
JavaScript
65 lines
2.7 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function() {
|
|
//class가 calender인 inputbox용,날짜field용
|
|
if (document.querySelector(".calender")) {
|
|
$(".calender").datepicker({
|
|
changeYear: true,
|
|
changeMonth: true,
|
|
yearRange: "-10:+0",
|
|
dateFormat: "yy-mm-dd"
|
|
});
|
|
}
|
|
if (document.querySelector(".tinymce")) {
|
|
// HTML 문서가 표준 모드로 렌더링되고 있는지 확인
|
|
if (document.compatMode !== "CSS1Compat") {
|
|
console.error("문서가 표준 모드가 아닙니다.");
|
|
return;
|
|
}
|
|
tinymce.init({
|
|
selector: 'textarea',
|
|
license_key: 'gpl',
|
|
height: 250,
|
|
plugins: 'advlist autolink lists link image charmap preview anchor',
|
|
toolbar: 'undo redo blocks fontfamily fontsize forecolor backcolor | bold italic underline strikethrough | align numlist bullist | link image | table media | code fullscreen preview',
|
|
menubar: 'file edit view insert format tools table help'
|
|
});
|
|
}
|
|
if (document.querySelector(".select-field")) {
|
|
//class가 select-field인 SelectBox용
|
|
$(".select-field").select2({
|
|
theme: "classic",
|
|
width: 'style',
|
|
dropdownAutoWidth: true
|
|
});
|
|
}
|
|
if (document.querySelector('#domain')) {
|
|
const domainSelecor = document.querySelector('#domain')
|
|
const errorBox = document.getElementById('domain-errors');
|
|
|
|
const tagify = new Tagify(domainSelecor, {
|
|
enforceWhitelist: false,
|
|
whitelist: [],
|
|
duplicates: false,
|
|
delimiters: ", ",
|
|
pattern: /[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/ // 도메인주소 패턴
|
|
});
|
|
// ✅ 패턴이 맞지 않을 때
|
|
tagify.on('invalid', e => {
|
|
const value = e.detail.data.value;
|
|
errorBox.innerText = `"${value}" 은(는) 유효한 도메인 형식이 아니거나 중복됩니다. 예: domain.co.kr`;
|
|
});
|
|
// ✅ 서버에서 존재 여부 확인
|
|
tagify.on('add', async e => {
|
|
const domain = e.detail.data.value;
|
|
const res = await fetch('/admin/equipment/part/domain/confirm', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({domain})
|
|
});
|
|
const results = await res.json();
|
|
if (exists = results.exists === true || results.exists === 'true') {
|
|
tagify.removeTag(domain); // 이미 존재하는 도메인 제거
|
|
errorBox.innerText = results.message;
|
|
}
|
|
});
|
|
}
|
|
}); |