MediaWiki:Minerva.js: Difference between revisions

From Church of God Knowledge Encyclopedia
Jump to navigation Jump to search
새 문서: All JavaScript here will be loaded for users of the MinervaNeue skin: All JavaScript here will be loaded for users of the MinervaNeue skin: // 모바일 메뉴 document .querySelector("#mw-mf-page-left #p-navigation") .insertAdjacentHTML( "afterend", '<ul id="p-main-categories" class="recommended-open"><li class="title-recommended open"><a><span>추천문서</span></a><span class="ico-arrow"></span></li><li class="recommended"><a href="/하나님의교회...
 
No edit summary
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
/* All JavaScript here will be loaded for users of the MinervaNeue skin */
/* All JavaScript here will be loaded for users of the MinervaNeue skin */
/* All JavaScript here will be loaded for users of the MinervaNeue skin */
function wikiLink(title) {
// 모바일 메뉴
    // 공백 → _ 치환 후 절대 경로 생성
    return mw.config.get('wgServer') + '/en/' + title.replace(/ /g, '_');
}
 
document
document
  .querySelector("#mw-mf-page-left #p-navigation")
    .querySelector('#mw-mf-page-left #p-navigation')
  .insertAdjacentHTML(
    .insertAdjacentHTML(
    "afterend",
        'afterend',
    '<ul id="p-main-categories" class="recommended-open"><li class="title-recommended open"><a><span>추천문서</span></a><span class="ico-arrow"></span></li><li class="recommended"><a href="/하나님의교회 세계복음선교협회"><span>하나님의 교회</span></a></li><li class="recommended"><a href="/안상홍"><span>그리스도 안상홍님</span></a></li><li class="recommended"><a href="/어머니 하나님"><span>어머니 하나님</span></a></li><li class="recommended"><a href="/안식일"><span>안식일</span></a></li><li class="recommended"><a href="/유월절"><span>유월절</span></a></li><li class="recommended"><a href="/복음과 새 언약"><span>복음과 새 언약</span></a></li><li class="recommended"><a href="/하나님의 교회 마지막 종교개혁"><span>마지막 종교개혁</span></a></li><li class="title-category"><a><span>카테고리 둘러보기</span></a><span class="ico-arrow"></span></li><li class="category"><a href="/분류:하나님의 교회"><span>하나님의 교회</span></a></li><li class="category"><a href="/분류:아버지"><span>아버지 하나님</span></a></li><li class="category"><a href="/분류:어머니"><span>어머니 하나님</span></a></li><li class="category"><a href="/분류:새 언약 복음"><span>새 언약 복음</span></a></li><li class="category"><a href="/분류:성경 일반"><span>성경 상식</span></a></li><li class="category"><a href="/분류:성경 이슈"><span>성경 이슈</span></a></li><li class="category"><a href="/분류:사회 공헌"><span>사회 공헌</span></a></li><li class="category"><a href="/분류:국제 협력"><span>국제 협력</span></a></li></ul>'
        '<ul id="p-main-categories">'+
  );
        '<li class="title-recommended"><a><span>Recommended Documents</span></a><span class="ico-arrow"></span></li>'+
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("World Mission Society Church of God") + '"><span>Church of God(Document)</span></a></li>' +
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("Ahnsahnghong") + '"><span>Christ Ahnsahnghong</span></a></li>' +
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("God the Mother") + '"><span>God the Mother</span></a></li>' +
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("Sabbath") + '"><span>Sabbath</span></a></li>' +
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("Passover") + '"><span>Passover</span></a></li>' +
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("Gospel and the New Covenant") + '"><span>Gospel and New Covenant</span></a></li>' +
        '<li class="title-category"><a><span>Browse by Category</span></a><span class="ico-arrow"></span></li>'+
'<li class="category" style="display:none;"><a href="' + wikiLink("en/Category:Church of God") + '"><span>Church of God</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:God the Father") + '"><span>God the Father</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:God the Mother") + '"><span>God the Mother</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Gospel of the New Covenant") + '"><span>Gospel of the New Covenant</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Bible Knowledge") + '"><span>Bible Knowledge</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Biblical Issues") + '"><span>Biblical Issues</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Community Service") + '"><span>Community Service</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Global Cooperation") + '"><span>Global Cooperation</span></a></li>' +
        '</ul>'
    );
 
// Recommended Documents 토글
document.querySelector('#p-main-categories .title-recommended')
    .addEventListener('click', function (event) {
        event.stopPropagation(); // 사이드바 닫힘 방지
        openList(this, '.recommended');
    });
 
// Browse by Category 토글
document.querySelector('#p-main-categories .title-category')
    .addEventListener('click', function (event) {
        event.stopPropagation(); // 사이드바 닫힘 방지
        openList(this, '.category');
    });
 
function openList(titleLi, selector) {
    titleLi.classList.toggle('open');
    let next = titleLi.nextElementSibling;
    while (next && !next.classList.contains('title-recommended') && !next.classList.contains('title-category')) {
        if (next.matches(selector)) {
            next.style.display = (next.style.display === 'none' || next.style.display === '') ? 'block' : 'none';
        }
        next = next.nextElementSibling;
    }
}


document
// 유튜브 썸네일
  .querySelector("#p-main-categories .title-recommended")
document.querySelectorAll('iframe').forEach(function(iframe){
  .addEventListener("click", function () {
    iframe.parentElement.classList.add('video-wrap');
    openList(this, "recommended-open");
});
  });
 
document
mw.loader.using(['jquery']).then(function() {
  .querySelector("#p-main-categories .title-category")
    $(function() {
  .addEventListener("click", function () {
        var modal = $('#myLayer');
     openList(this, "category-open");
        var btn = $('#selectLanguage'); // jQuery 선택자 사용
   });
        var span = $('.close-button').first();
 
        btn.click(function() {
            modal.show();
        });
 
        span.click(function() {
            modal.hide();
        });
 
        $(window).click(function(event) {
            if ($(event.target).is(modal)) {
                modal.hide();
            }
        });
    });
});
function fillMobileLanguageFromInterwiki() {
    var $mobileList = $('#mobile-language');
 
    // 인터위키 링크 읽기
    var $interwikiLinks = $('#p-lang ul.minerva-languages .interlanguage-link a');
    if (!$interwikiLinks.length) return;
 
    const langMap = {
        'ko': 'Korean',
        'en': 'English',
        'es': 'Spanish',
        'vi': 'Vietnamese',
        'ne': 'Nepali',
        'pt': 'Portuguese'
    };
 
    $mobileList.empty();
 
    $interwikiLinks.each(function () {
        var $a      = $(this);
        var href     = $a.attr('href');
        var langCode = $a.attr('lang');
        var autonym  = $a.find('span').text() || $a.text();   // English, Español ...
        var korean   = langMap[langCode] || '';
        var label    = korean ? (autonym + ' (' + korean + ')') : autonym;


function openList(titleLi, listClass) {
        var $li  = $('<li>');
  var list = document.querySelector("#p-main-categories");
        var $new = $('<a>', { href: href, text: label });
  if (list.classList.contains(listClass)) {
    list.classList.remove(listClass);
  } else {
    list.classList.add(listClass);
  }


  if (titleLi.classList.contains("open")) {
        $li.append($new);
    titleLi.classList.remove("open");
        $mobileList.append($li);
  } else {
    });
    titleLi.classList.add("open");
  }
}
}
mw.loader.using(['jquery']).then(function () {
    $(function () {
        // body DOM 변경 감시
        var observer = new MutationObserver(function (mutations) {
            mutations.forEach(function (m) {
                $(m.addedNodes).each(function () {
                    var $node = $(this);
                    if ($node.is('#mobile-language') || $node.find('#mobile-language').length) {
                        fillMobileLanguageFromInterwiki();
                    }
                });
            });
        });
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
        // 혹시 이미 열려 있는 상태에서 로딩될 수도 있으니 한 번 시도
        fillMobileLanguageFromInterwiki();
    });
});

Latest revision as of 17:23, 24 November 2025

/* All JavaScript here will be loaded for users of the MinervaNeue skin */
function wikiLink(title) {
    // 공백 → _ 치환 후 절대 경로 생성
    return mw.config.get('wgServer') + '/en/' + title.replace(/ /g, '_');
}

document
    .querySelector('#mw-mf-page-left #p-navigation')
    .insertAdjacentHTML(
        'afterend',
        '<ul id="p-main-categories">'+
        	'<li class="title-recommended"><a><span>Recommended Documents</span></a><span class="ico-arrow"></span></li>'+
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("World Mission Society Church of God") + '"><span>Church of God(Document)</span></a></li>' +
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("Ahnsahnghong") + '"><span>Christ Ahnsahnghong</span></a></li>' +
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("God the Mother") + '"><span>God the Mother</span></a></li>' +
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("Sabbath") + '"><span>Sabbath</span></a></li>' +
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("Passover") + '"><span>Passover</span></a></li>' +
            '<li class="recommended" style="display:none;"><a href="' + wikiLink("Gospel and the New Covenant") + '"><span>Gospel and New Covenant</span></a></li>' +
        	'<li class="title-category"><a><span>Browse by Category</span></a><span class="ico-arrow"></span></li>'+
 '<li class="category" style="display:none;"><a href="' + wikiLink("en/Category:Church of God") + '"><span>Church of God</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:God the Father") + '"><span>God the Father</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:God the Mother") + '"><span>God the Mother</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Gospel of the New Covenant") + '"><span>Gospel of the New Covenant</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Bible Knowledge") + '"><span>Bible Knowledge</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Biblical Issues") + '"><span>Biblical Issues</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Community Service") + '"><span>Community Service</span></a></li>' +
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Global Cooperation") + '"><span>Global Cooperation</span></a></li>' +
        '</ul>'
    );

// Recommended Documents 토글
document.querySelector('#p-main-categories .title-recommended')
    .addEventListener('click', function (event) {
        event.stopPropagation(); // 사이드바 닫힘 방지
        openList(this, '.recommended');
    });

// Browse by Category 토글
document.querySelector('#p-main-categories .title-category')
    .addEventListener('click', function (event) {
        event.stopPropagation(); // 사이드바 닫힘 방지
        openList(this, '.category');
    });

function openList(titleLi, selector) {
    titleLi.classList.toggle('open');
    let next = titleLi.nextElementSibling;
    while (next && !next.classList.contains('title-recommended') && !next.classList.contains('title-category')) {
        if (next.matches(selector)) {
            next.style.display = (next.style.display === 'none' || next.style.display === '') ? 'block' : 'none';
        }
        next = next.nextElementSibling;
    }
}

// 유튜브 썸네일
document.querySelectorAll('iframe').forEach(function(iframe){
    iframe.parentElement.classList.add('video-wrap');
});

mw.loader.using(['jquery']).then(function() {
    $(function() {
        var modal = $('#myLayer');
        var btn = $('#selectLanguage'); // jQuery 선택자 사용
        var span = $('.close-button').first();

        btn.click(function() {
            modal.show();
        });

        span.click(function() {
            modal.hide();
        });

        $(window).click(function(event) {
            if ($(event.target).is(modal)) {
                modal.hide();
            }
        });
    });
});
function fillMobileLanguageFromInterwiki() {
    var $mobileList = $('#mobile-language');

    // 인터위키 링크 읽기
    var $interwikiLinks = $('#p-lang ul.minerva-languages .interlanguage-link a');
    if (!$interwikiLinks.length) return;

    const langMap = {
        'ko': 'Korean',
        'en': 'English',
        'es': 'Spanish',
        'vi': 'Vietnamese',
        'ne': 'Nepali',
        'pt': 'Portuguese'
    };

    $mobileList.empty();

    $interwikiLinks.each(function () {
        var $a       = $(this);
        var href     = $a.attr('href');
        var langCode = $a.attr('lang');
        var autonym  = $a.find('span').text() || $a.text();   // English, Español ...
        var korean   = langMap[langCode] || '';
        var label    = korean ? (autonym + ' (' + korean + ')') : autonym;

        var $li  = $('<li>');
        var $new = $('<a>', { href: href, text: label });

        $li.append($new);
        $mobileList.append($li);
    });
}

mw.loader.using(['jquery']).then(function () {
    $(function () {
        // body DOM 변경 감시
        var observer = new MutationObserver(function (mutations) {
            mutations.forEach(function (m) {
                $(m.addedNodes).each(function () {
                    var $node = $(this);
                    if ($node.is('#mobile-language') || $node.find('#mobile-language').length) {
                        fillMobileLanguageFromInterwiki();
                    }
                });
            });
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });

        // 혹시 이미 열려 있는 상태에서 로딩될 수도 있으니 한 번 시도
        fillMobileLanguageFromInterwiki();
    });
});