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

광주문화예술인문스토리플랫폼
이동: 둘러보기, 검색
1번째 줄: 1번째 줄:
 
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
 
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
document.addEventListener("DOMContentLoaded", function () {
+
mw.hook('wikipage.content').add(function ($content) {
     var input = document.getElementById("myInput");
+
    // 보기(view) 화면에서만 동작하게 (편집창 등에서는 스킵)
     if (!input) return;
+
    if (mw.config.get('wgAction') !== 'view') {
 +
        return;
 +
    }
 +
 
 +
    // content 안에서 myInput 요소 찾기
 +
     var input = document.getElementById('myInput');
 +
     if (!input) {
 +
        return;
 +
    }
 +
 
 +
    // divTable / tbody / row 찾기
 +
    var tbody = document.querySelector('.divTable .tbody');
 +
    if (!tbody) {
 +
        return;
 +
    }
 +
 
 +
    var rows = tbody.getElementsByClassName('row');
 +
    if (!rows.length) {
 +
        return;
 +
    }
  
 +
    // 실제 필터 함수
 
     function filterEpisodes() {
 
     function filterEpisodes() {
         var filter = (input.textContent || input.innerText || "").toUpperCase();
+
        // contenteditable div에서 텍스트 읽기
         var tbody  = document.querySelector(".divTable .tbody");
+
         var text = input.textContent || input.innerText || '';
        if (!tbody) return;
+
         var filter = text.trim().toUpperCase();
  
         var rows = tbody.getElementsByClassName("row");
+
         // 400행이라도 이 정도 루프는 부담 없음
 
         for (var i = 0; i < rows.length; i++) {
 
         for (var i = 0; i < rows.length; i++) {
             var txtValue = rows[i].textContent || rows[i].innerText;
+
             var rowText = rows[i].textContent || rows[i].innerText || '';
             if (txtValue.toUpperCase().indexOf(filter) > -1) {
+
             if (!filter || rowText.toUpperCase().indexOf(filter) > -1) {
                 rows[i].style.display = "";
+
                 rows[i].style.display = '';   // 보이기
 
             } else {
 
             } else {
                 rows[i].style.display = "none";
+
                 rows[i].style.display = 'none'; // 숨기기
 
             }
 
             }
 
         }
 
         }
 
     }
 
     }
  
     input.addEventListener("keyup", filterEpisodes);
+
    // 타이핑할 때마다 필터 적용
     input.addEventListener("input", filterEpisodes);
+
     input.addEventListener('input', filterEpisodes);
 +
     input.addEventListener('keyup', filterEpisodes);
 
});
 
});

2025년 11월 26일 (수) 17:21 판

/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
mw.hook('wikipage.content').add(function ($content) {
    // 보기(view) 화면에서만 동작하게 (편집창 등에서는 스킵)
    if (mw.config.get('wgAction') !== 'view') {
        return;
    }

    // content 안에서 myInput 요소 찾기
    var input = document.getElementById('myInput');
    if (!input) {
        return;
    }

    // divTable / tbody / row 찾기
    var tbody = document.querySelector('.divTable .tbody');
    if (!tbody) {
        return;
    }

    var rows = tbody.getElementsByClassName('row');
    if (!rows.length) {
        return;
    }

    // 실제 필터 함수
    function filterEpisodes() {
        // contenteditable div에서 텍스트 읽기
        var text = input.textContent || input.innerText || '';
        var filter = text.trim().toUpperCase();

        // 400행이라도 이 정도 루프는 부담 없음
        for (var i = 0; i < rows.length; i++) {
            var rowText = rows[i].textContent || rows[i].innerText || '';
            if (!filter || rowText.toUpperCase().indexOf(filter) > -1) {
                rows[i].style.display = '';   // 보이기
            } else {
                rows[i].style.display = 'none'; // 숨기기
            }
        }
    }

    // 타이핑할 때마다 필터 적용
    input.addEventListener('input', filterEpisodes);
    input.addEventListener('keyup', filterEpisodes);
});