<script>
(function () {
/* ── 파일명 업데이트 ── */
window.updateFileName = function (input, index) {
var fileName = input.files[0] ? input.files[0].name : 'No file selected';
var el = document.getElementById('file_name_' + index);
if (!el) return;
el.innerText = fileName;
el.style.color = '#00f2ff';
};
/* ── 파일 슬롯 추가 ── */
window.file_add = function () {
var rows = document.querySelectorAll('.file-row:not(.active)');
if (rows.length > 0) rows[0].classList.add('active');
};
/* ── 메모 토글 ── */
function bindMemoToggle() {
var btn = document.getElementById('memo-toggle-btn');
var area = document.getElementById('memo-area');
if (!btn || !area) return;
btn.addEventListener('click', function () {
area.classList.toggle('open');
btn.setAttribute('aria-expanded', area.classList.contains('open') ? 'true' : 'false');
});
}
/* ── 날짜/시간 피커 자동 오픈 ── */
function bindDateTimePicker() {
['wr_date_custom', 'wr_time_custom'].forEach(function (id) {
var field = document.getElementById(id);
if (!field) return;
var openPicker = function () {
if (typeof field.showPicker === 'function') field.showPicker();
};
field.addEventListener('click', openPicker);
field.addEventListener('focus', openPicker);
});
}
/* ── 글자수 제한 ── */
<?php if ($write_min || $write_max) { ?>
var char_min = parseInt(<?php echo $write_min; ?>);
var char_max = parseInt(<?php echo $write_max; ?>);
check_byte('wr_content', 'char_count');
$(function () {
$('#wr_content').on('keyup', function () {
check_byte('wr_content', 'char_count');
});
});
<?php } ?>
/* ── 폼 제출 ── */
window.fwrite_submit = function (f) {
<?php echo $editor_js; ?>
<?php if ($write_min || $write_max) { ?>
if (document.getElementById('char_count')) {
var cnt = parseInt(check_byte('wr_content', 'char_count'));
if (char_min > 0 && char_min > cnt) {
alert('내용은 ' + char_min + '글자 이상 쓰셔야 합니다.');
return false;
}
if (char_max > 0 && char_max < cnt) {
alert('내용은 ' + char_max + '글자 이하로 쓰셔야 합니다.');
return false;
}
}
<?php } ?>
<?php echo $captcha_js; ?>
var submitBtn = document.getElementById('btn_submit');
if (submitBtn) submitBtn.disabled = true;
return true;
};
/* ── 초기화 ── */
bindMemoToggle();
bindDateTimePicker();
})();
</script>