미디어위키:Minerva.js: 두 판 사이의 차이
편집 요약 없음 태그: 되돌려진 기여 |
Resultofunion (토론 | 기여) 편집 요약 없음 |
||
| (사용자 2명의 중간 판 4개는 보이지 않습니다) | |||
| 1번째 줄: | 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) { | function wikiLink(title) { | ||
return mw.config.get('wgServer') + '/' + title.replace(/ /g, '_'); | return mw.config.get('wgServer') + '/' + title.replace(/ /g, '_'); | ||
} | } | ||
document | document | ||
.querySelector('#mw-mf-page-left #p-navigation') | .querySelector('#mw-mf-page-left #p-navigation') | ||
| 12번째 줄: | 8번째 줄: | ||
'afterend', | 'afterend', | ||
'<ul id="p-main-categories" class="recommended-open">' + | '<ul id="p-main-categories" class="recommended-open">' + | ||
'<li class="title-recommended"><a><span>추천문서</span></a><span class="ico-arrow"></span></li>' + | // open 클래스 | ||
'<li class="recommended"><a href=" | '<li class="title-recommended open"><a><span>추천문서</span></a><span class="ico-arrow"></span></li>' + | ||
'<li class="recommended"><a href="'+wikiLink("하나님의교회 세계복음선교협회")+'"><span>하나님의 교회</span></a></li>' + | |||
'<li class="recommended"><a href="'+wikiLink("안상홍")+'"><span>그리스도 안상홍님</span></a></li>' + | '<li class="recommended"><a href="'+wikiLink("안상홍")+'"><span>그리스도 안상홍님</span></a></li>' + | ||
'<li class="recommended"><a href="'+wikiLink("어머니 하나님")+'"><span>어머니 하나님</span></a></li>' + | '<li class="recommended"><a href="'+wikiLink("어머니 하나님")+'"><span>어머니 하나님</span></a></li>' + | ||
| 20번째 줄: | 17번째 줄: | ||
'<li class="recommended"><a href="'+wikiLink("복음과 새 언약")+'"><span>복음과 새 언약</span></a></li>' + | '<li class="recommended"><a href="'+wikiLink("복음과 새 언약")+'"><span>복음과 새 언약</span></a></li>' + | ||
'<li class="recommended"><a href="'+wikiLink("하나님의 교회 마지막 종교개혁")+'"><span>마지막 종교개혁</span></a></li>' + | '<li class="recommended"><a href="'+wikiLink("하나님의 교회 마지막 종교개혁")+'"><span>마지막 종교개혁</span></a></li>' + | ||
'<li class="title-category"><a><span>카테고리 둘러보기</span></a><span class="ico-arrow"></span></li>' + | '<li class="title-category"><a><span>카테고리 둘러보기</span></a><span class="ico-arrow"></span></li>' + | ||
'<li class="category"><a href="'+wikiLink("분류:하나님의 교회")+'"><span>하나님의 교회</span></a></li>' + | '<li class="category"><a href="'+wikiLink("분류:하나님의 교회")+'"><span>하나님의 교회</span></a></li>' + | ||
| 53번째 줄: | 50번째 줄: | ||
); | ); | ||
// -- | // 메뉴 상태 초기화 | ||
document.querySelectorAll('#p-main-categories .recommended').forEach(function(li){ | |||
document.querySelectorAll('#p-main-categories ' + | li.style.display = 'block'; // 추천문서만 open | ||
}); | |||
['.category', '.family', '.youtube'].forEach(function(selector) { | |||
document.querySelectorAll('#p-main-categories ' + selector).forEach(function(li) { | |||
li.style.display = 'none'; | li.style.display = 'none'; | ||
}); | }); | ||
}); | }); | ||
// 토글 | // 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'); | |||
}); | |||
// Family Sites 토글 | |||
document.querySelector('#p-main-categories .title-family') | |||
.addEventListener('click', function (event) { | |||
event.stopPropagation(); | |||
openList(this, '.family'); | |||
}); | |||
// Youtube Channel 토글 | |||
document.querySelector('#p-main-categories .title-youtube') | |||
.addEventListener('click', function (event) { | |||
event.stopPropagation(); | |||
openList(this, '.youtube'); | |||
}); | |||
function openList(titleLi, selector) { | function openList(titleLi, selector) { | ||
titleLi.classList.toggle('open'); | titleLi.classList.toggle('open'); | ||
let next = titleLi.nextElementSibling; | let next = titleLi.nextElementSibling; | ||
while ( | |||
while (next && !next.classList.contains('title-recommended') && | next && | ||
!next.classList.contains('title-recommended') && | |||
!next.classList.contains('title-category') && | |||
!next.classList.contains('title-family') && | |||
!next.classList.contains('title-youtube') | |||
) { | |||
if (next.matches(selector)) { | if (next.matches(selector)) { | ||
next.style.display = | next.style.display = (next.style.display === 'none' || next.style.display === '') ? 'block' : 'none'; | ||
} | } | ||
next = next.nextElementSibling; | next = next.nextElementSibling; | ||
} | } | ||
} | } | ||
// 유튜브 썸네일 | |||
// 유튜브 썸네일 | |||
document.querySelectorAll('iframe').forEach(function (iframe) { | document.querySelectorAll('iframe').forEach(function (iframe) { | ||
var $container = iframe.parentElement; | var $container = iframe.parentElement; | ||
| 119번째 줄: | 123번째 줄: | ||
} | } | ||
}); | }); | ||
}); | |||
}); | |||
function fillMobileLanguageFromInterwiki() { | |||
var $mobileList = $('#mobile-language'); | |||
// 인터위키 링크 읽기 | |||
var $interwikiLinks = $('#p-lang ul.minerva-languages .interlanguage-link a'); | |||
if (!$interwikiLinks.length) return; | |||
var langMap = { | |||
'ko': '한국어', | |||
'en': '영어', | |||
'es': '스페인어', | |||
'vi': '베트남어', | |||
'ne': '네팔어', | |||
'pt': '포르투갈어' | |||
}; | |||
$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(); | |||
}); | }); | ||
}); | }); | ||