Add no-JavaScript-safe collapsible groups to Minerva sidebar |
Render Minerva sidebar groups from server-generated navigation data |
||
| 第20行: | 第20行: | ||
var navigation = document.getElementById( 'p-navigation' ); | var navigation = document.getElementById( 'p-navigation' ); | ||
if ( !navigation || navigation.dataset.tyzxMobileGroupsBuilt === '1' ) { | if ( !navigation || navigation.dataset.tyzxMobileGroupsBuilt === '1' ) { | ||
return; | |||
} | |||
var groups = window.mw && mw.config ? mw.config.get( 'wgTyzxSidebarGroups' ) : null; | |||
if ( !Array.isArray( groups ) || !groups.length ) { | |||
return; | return; | ||
} | } | ||
var insertionPoint = navigation; | var insertionPoint = navigation; | ||
groups.forEach( function ( group, index ) { | |||
var portlet = document.createElement( 'nav' ); | var portlet = document.createElement( 'nav' ); | ||
var heading = document.createElement( 'h3' ); | var heading = document.createElement( 'h3' ); | ||
| 第34行: | 第34行: | ||
portlet.id = 'p-tyzx-mobile-' + index; | portlet.id = 'p-tyzx-mobile-' + index; | ||
portlet.className = 'mw-portlet tyzx-minerva-sidebar-portlet'; | portlet.className = 'mw-portlet tyzx-minerva-sidebar-portlet'; | ||
heading.textContent = label; | heading.textContent = group.label; | ||
content.className = 'mw-portlet-body'; | content.className = 'mw-portlet-body'; | ||
group.links.forEach( function ( link, linkIndex ) { | |||
var item = document.createElement( 'li' ); | |||
var anchor = document.createElement( 'a' ); | |||
item.id = 'n-tyzx-mobile-' + index + '-' + linkIndex; | |||
item.className = 'mw-list-item ' + ( link.class || '' ); | |||
anchor.href = link.href; | |||
anchor.textContent = link.text; | |||
if ( link.lang ) { | |||
anchor.lang = link.lang; | |||
} | |||
if ( link.hreflang ) { | |||
anchor.hreflang = link.hreflang; | |||
} | |||
if ( item.classList.contains( 'tyzx-sidebar-language-current' ) ) { | |||
anchor.setAttribute( 'aria-current', 'true' ); | |||
} | |||
item.appendChild( anchor ); | |||
list.appendChild( item ); | list.appendChild( item ); | ||
} ); | } ); | ||