Extend accessible sidebar groups and language section |
Add no-JavaScript-safe collapsible groups to Minerva sidebar |
||
| 第2行: | 第2行: | ||
'use strict'; | 'use strict'; | ||
var | var topicLabelList = [ | ||
'校园总览', | '校园总览', | ||
'区域与地点', | '区域与地点', | ||
| 第14行: | 第14行: | ||
'工具与浏览', | '工具与浏览', | ||
'语言' | '语言' | ||
] ); | ]; | ||
var topicLabels = new Set( topicLabelList ); | |||
function buildMinervaTopicGroups() { | |||
var navigation = document.getElementById( 'p-navigation' ); | |||
if ( !navigation || navigation.dataset.tyzxMobileGroupsBuilt === '1' ) { | |||
return; | |||
} | |||
var insertionPoint = navigation; | |||
topicLabelList.forEach( function ( label, index ) { | |||
var items = navigation.querySelectorAll( '.tyzx-mobile-group-' + index ); | |||
if ( !items.length ) { | |||
return; | |||
} | |||
var portlet = document.createElement( 'nav' ); | |||
var heading = document.createElement( 'h3' ); | |||
var content = document.createElement( 'div' ); | |||
var list = document.createElement( 'ul' ); | |||
portlet.id = 'p-tyzx-mobile-' + index; | |||
portlet.className = 'mw-portlet tyzx-minerva-sidebar-portlet'; | |||
heading.textContent = label; | |||
content.className = 'mw-portlet-body'; | |||
items.forEach( function ( item ) { | |||
list.appendChild( item ); | |||
} ); | |||
content.appendChild( list ); | |||
portlet.appendChild( heading ); | |||
portlet.appendChild( content ); | |||
insertionPoint.insertAdjacentElement( 'afterend', portlet ); | |||
insertionPoint = portlet; | |||
} ); | |||
navigation.dataset.tyzxMobileGroupsBuilt = '1'; | |||
} | |||
function storageKey( portlet ) { | function storageKey( portlet ) { | ||
| 第117行: | 第149行: | ||
function initializeSidebar() { | function initializeSidebar() { | ||
buildMinervaTopicGroups(); | |||
document.querySelectorAll( '.mw-portlet, .portlet.mw-portlet' ) | document.querySelectorAll( '.mw-portlet, .portlet.mw-portlet' ) | ||
.forEach( initializePortlet ); | .forEach( initializePortlet ); | ||