본문으로 이동

미디어위키:Common.js: 두 판 사이의 차이

Langrisser Wiki
신규: 대문 mainsection 그리드 등급 탭 클릭 필터링(vanilla JS)
 
DOMContentLoaded 타이밍 버그 수정: site JS는 이미 로드된 뒤라 해당 이벤트가 지나가버려 리스너가 전혀 등록 안 됐음 -> jQuery ready로 전환
1번째 줄: 1번째 줄:
/* 대문 mainsection 그리드 등급 탭 필터링 */
/* 대문 mainsection 그리드 등급 탭 필터링 */
document.addEventListener( 'DOMContentLoaded', function () {
$( function () {
var tabLists = document.querySelectorAll( '.mainsection-tabs' );
var tabLists = document.querySelectorAll( '.mainsection-tabs' );
for ( var i = 0; i < tabLists.length; i++ ) {
for ( var i = 0; i < tabLists.length; i++ ) {

2026년 7월 14일 (화) 10:35 판

/* 대문 mainsection 그리드 등급 탭 필터링 */
$( function () {
	var tabLists = document.querySelectorAll( '.mainsection-tabs' );
	for ( var i = 0; i < tabLists.length; i++ ) {
		var tabs = tabLists[ i ];
		if ( !tabs.children.length ) {
			continue;
		}
		var box = tabs.closest( '.mainsection-box' );
		if ( !box ) {
			continue;
		}
		var items = tabs.querySelectorAll( 'li' );
		items.forEach( function ( li ) {
			li.addEventListener( 'click', function () {
				items.forEach( function ( other ) {
					other.classList.remove( 'active' );
				} );
				li.classList.add( 'active' );

				var rarity = li.getAttribute( 'data-rarity' );
				var slots = box.querySelectorAll( '.mainsection-slot[data-rarity]' );
				slots.forEach( function ( slot ) {
					if ( rarity === 'all' || slot.getAttribute( 'data-rarity' ) === rarity ) {
						slot.style.display = '';
					} else {
						slot.style.display = 'none';
					}
				} );
			} );
		} );
	}
} );