72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
// /public/js/admin/form.js
|
|
window.initFormModal = function (context) {
|
|
const root = context || document;
|
|
const $root = $(root);
|
|
|
|
// ✅ 캘린더: 이미 datepicker 붙은 건 제외
|
|
$root.find(".calender").each(function () {
|
|
const $el = $(this);
|
|
if ($el.hasClass("hasDatepicker")) return;
|
|
$el.datepicker({
|
|
changeYear: true,
|
|
changeMonth: true,
|
|
yearRange: "-10:+0",
|
|
dateFormat: "yy-mm-dd"
|
|
});
|
|
});
|
|
|
|
// ✅ TinyMCE: 전체 remove() 금지, "컨텍스트 내부 textarea만" 처리
|
|
if (typeof tinymce !== "undefined") {
|
|
$root.find("textarea.tinymce").each(function () {
|
|
const id = this.id || ("tinymce_" + Math.random().toString(36).slice(2));
|
|
this.id = id;
|
|
|
|
// 이미 인스턴스 있으면 스킵
|
|
if (tinymce.get(id)) return;
|
|
|
|
tinymce.init({
|
|
selector: `#${CSS.escape(id)}`,
|
|
license_key: "gpl",
|
|
height: 250,
|
|
plugins: "advlist autolink lists link image charmap preview anchor",
|
|
toolbar: "undo redo | bold italic underline | align | link image | code fullscreen preview",
|
|
menubar: "file edit view insert format tools table help"
|
|
});
|
|
});
|
|
}
|
|
|
|
// ✅ Select2: 이미 select2 붙은 건 제외
|
|
$root.find(".select-field").each(function () {
|
|
const $el = $(this);
|
|
if ($el.hasClass("select2-hidden-accessible")) return;
|
|
|
|
$el.select2({
|
|
theme: "bootstrap-5",
|
|
tags: true,
|
|
allowClear: true,
|
|
width: "100%",
|
|
dropdownAutoWidth: true,
|
|
language: {
|
|
noResults: function () {
|
|
return "직접 입력 후 Enter";
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
// 디버그 로그는 필요 없으면 제거/조건부로
|
|
// console.log("✅ Form initialized inside modal:", root);
|
|
};
|
|
|
|
// ✅ 페이지 최초 1회
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
window.initFormModal(document);
|
|
});
|
|
|
|
// ✅ 모달 열릴 때: "해당 모달만" 초기화하되 중복 호출 방지(네임스페이스)
|
|
$(document)
|
|
.off("shown.bs.modal.initForm", ".modal")
|
|
.on("shown.bs.modal.initForm", ".modal", function () {
|
|
window.initFormModal(this);
|
|
});
|