MediaWiki:Minerva.js: Difference between revisions

No edit summary
Tags: Mobile edit Mobile web edit
No edit summary
 
(3 intermediate revisions by the same user 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 */
// 모바일 메뉴에서 '둘러보기' 문서 보여주기
function wikiLink(title) {
    // 공백 → _ 치환 후 절대 경로 생성
    return mw.config.get('wgServer') + '/en/' + title.replace(/ /g, '_');
}


document
document
Line 8: Line 11:
         '<ul id="p-main-categories">'+
         '<ul id="p-main-categories">'+
         '<li class="title-recommended"><a><span>Recommended Documents</span></a><span class="ico-arrow"></span></li>'+
         '<li class="title-recommended"><a><span>Recommended Documents</span></a><span class="ico-arrow"></span></li>'+
        '<li class="recommended" style="display:none;"><a href="/en/World_Mission_Society_Church_of_God"><span>Church of God(Document)</span></a></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="/en/Ahnsahnghong"><span>Christ Ahnsahnghong</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="/en/God_the_Mother"><span>God the Mother</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="/en/Sabbath"><span>Sabbath</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="/en/Passover"><span>Passover</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="/en/Gospel_and_the_New_Covenant"><span>Gospel and New Covenant</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="title-category"><a><span>Browse by Category</span></a><span class="ico-arrow"></span></li>'+
        '<li class="category" style="display:none;"><a href="/en/Category:Church_of_God"><span>Church of God</span></a></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="/en/Category:God_the_Father"><span>God the Father</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="/en/Category:God_the_Mother"><span>God the Mother</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="/en/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:Gospel of the New Covenant") + '"><span>Gospel of the New Covenant</span></a></li>' +
        '<li class="category" style="display:none;"><a href="/en/Category:Bible_Knowledge"><span>Bible Knowledge</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="/en/Category:Biblical_Issues"><span>Biblical Issues</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="/en/Category:Community_Service"><span>Community Service</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="/en/Category:Global_Cooperation"><span>Global Cooperation</span></a></li>'+
            '<li class="category" style="display:none;"><a href="' + wikiLink("Category:Global Cooperation") + '"><span>Global Cooperation</span></a></li>' +
         '</ul>'
         '</ul>'
     );
     );
Line 75: Line 78:
             }
             }
         });
         });
    });
});
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();
     });
     });
});
});