File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
$(function () {
boardCaptionToggle();
checkboxAllToggle();
accordionToggle()
})
function boardCaptionToggle() {
/**
* ✅ boardCaptionToggle()
*
* - 접근성 준수를 위한 테이블 캡션 자동 생성 함수
* - 각 .table 요소 내 <table>의 <th> 텍스트를 기반으로 caption 생성
* - 상단 제목(.tb_tit01 또는 .content_title)을 함께 조합
* - 입력형(폼요소 포함) 테이블은 "정보입력" 문구, 일반형은 "정보제공" 문구 사용
*
*/
$(".table").each(function (idx, itm) {
const $table = $(itm).find("table");
let subTit = "";
// 1️⃣ 테이블 제목 찾기
if ($(itm).prev(".tb_tit01").length === 1) {
subTit = $(itm).prev(".tb_tit01").find(".tb_tit01_left p").text();
} else {
subTit = $(itm).closest(".content_title").find("h3").text();
}
// 2️⃣ th 텍스트 모두 가져오기
let thText = "";
const thList = $table.find("th");
thList.each(function (index) {
thText += $(this).text();
if (index < thList.length - 1) thText += ", ";
});
// 3️⃣ 기존 caption 제거 (중복 방지)
$table.find("caption").remove();
// 4️⃣ 입력형 여부 판단
const hasInputElements = $table.find("input, select, textarea, button").length > 0;
const isInputType = $(itm).hasClass("form_wrap") || hasInputElements;
// 5️⃣ caption 내용 구성
const captionText = isInputType ?
`${subTit} : ${thText} 등의 정보입력` :
`${subTit} : ${thText} 등의 정보제공`;
// 6️⃣ caption 추가
$table.prepend(`<caption>${captionText}</caption>`);
});
}
function checkboxAllToggle() {
/**
* ✅ checkboxAllToggle()
*
* [기능 설명]
* - id가 "_all"로 끝나는 체크박스를 클릭하면
* 같은 name을 가진 모든 체크박스를 선택/해제함.
* - 개별 체크박스 상태가 변경되면
* 전체 선택 체크박스의 상태도 자동으로 갱신됨.
*
*/
// 1️⃣ id가 '_all'로 끝나는 전체 선택용 체크박스 찾기
const $allCheckboxes = $("input[type='checkbox'][id$='_all']");
// 2️⃣ 전체 선택 체크박스 클릭 시 → 같은 name 그룹 모두 체크/해제
$allCheckboxes.on("change", function () {
const name = $(this).attr("name"); // 그룹 구분용 name 속성
const isChecked = $(this).is(":checked"); // 현재 전체 체크박스의 상태(true/false)
// 같은 name을 가진 모든 체크박스 상태 변경
$(`input[type='checkbox'][name='${name}']`).prop("checked", isChecked);
});
// 3️⃣ 개별 체크박스 클릭 시 → 전체 선택 체크박스 상태 갱신
$("input[type='checkbox']").not($allCheckboxes).on("change", function () {
const name = $(this).attr("name"); // 현재 클릭된 체크박스의 name
const $group = $(`input[type='checkbox'][name='${name}']`).not(`[id$='_all']`); // 전체선택 제외한 같은 그룹
const total = $group.length; // 그룹 내 전체 체크박스 수
const checked = $group.filter(":checked").length; // 체크된 개수
// 모든 체크박스가 선택되어 있으면 전체선택 체크박스도 체크, 아니면 해제
$(`input[type='checkbox'][id$='_all'][name='${name}']`).prop("checked", total === checked);
});
}
function accordionToggle(selector = ".accordion_header", duration = 400) {
const $headers = $(selector);
// 초기 상태 닫기
$(".accordion_body").hide();
$headers.off("click.accordion").on("click.accordion", function () {
const $this = $(this);
const $body = $this.next(".accordion_body");
const isOpen = $this.hasClass("active");
// 전체 닫기
$(".accordion_header").removeClass("active");
$(".accordion_body").slideUp(duration);
// 클릭한 것만 열기
if (!isOpen) {
$this.addClass("active");
$body.slideDown(duration);
}
});
}