미디어위키:Common.js
이터널 리턴 이스포츠 위키
다른 명령
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
mw.loader.using(['jquery.makeCollapsible'], function() {
/**
* 테이블의 실제 열 개수를 계산하는 함수
* colspan 속성을 고려하여 정확한 열 개수를 반환
*/
function getTableColumnCount(table) {
var $firstRow = $(table).find('tr:first');
if ($firstRow.length === 0) return 4;
var columnCount = 0;
$firstRow.find('th, td').each(function() {
var colspan = parseInt($(this).attr('colspan') || '1', 10);
columnCount += (isNaN(colspan) || colspan <= 0) ? 1 : colspan;
});
return columnCount > 0 ? columnCount : 4;
}
/**
* 테이블 접기/펼치기 토글 함수
*/
function toggleTable(table, button) {
var $table = $(table);
var $button = $(button);
var isCollapsed = $table.hasClass('mw-collapsed');
if (isCollapsed) {
$table.removeClass('mw-collapsed');
$table.find('tr').not(':first, .button-row').show();
$button.text('접기');
} else {
$table.addClass('mw-collapsed');
$table.find('tr').not(':first, .button-row').hide();
$button.text('펼치기');
}
}
/**
* 테이블에 접기/펼치기 버튼을 추가하고 초기화하는 함수
*/
function initNationalTable(table) {
var $table = $(table);
// 이미 버튼이 추가된 테이블은 건너뛰기
if ($table.find('.button-row').length > 0) {
return;
}
// 테이블의 실제 열 개수 계산
var columnCount = getTableColumnCount($table);
// 처음 로드될 때 접혀 있어야 할 테이블 초기화
var isInitiallyCollapsed = $table.hasClass('mw-collapsed');
if (isInitiallyCollapsed) {
$table.find('tr').not(':first, .button-row').hide();
}
// 첫 번째 <tr> 이후에 커스텀 접기/펼치기 버튼 추가
var buttonText = isInitiallyCollapsed ? '펼치기' : '접기';
var buttonHTML = '<tr class="button-row">' +
'<td colspan="' + columnCount + '" style="text-align:center;">' +
'<button class="toggle-button" type="button">' + buttonText + '</button>' +
'</td>' +
'</tr>';
$table.find('tr:first').after(buttonHTML);
$table.find('.button-row').css('display', 'table-row');
// 버튼 클릭 이벤트 (클릭 후 포커스 제거)
$table.find('.toggle-button').click(function() {
toggleTable($table, this);
$(this).blur(); // 클릭 후 포커스 제거
});
}
// 문서 로드 시 초기화
$(document).ready(function() {
$('.mw-collapsible.national').each(function() {
initNationalTable(this);
});
});
});