tabs: allow codified tabs to be colored

This commit is contained in:
Sören Weber 2023-06-08 14:53:22 +02:00
parent 0a3662be61
commit cef256eb40
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
3 changed files with 16 additions and 9 deletions
static/js

View file

@ -67,18 +67,22 @@ function adjustContentWidth(){
function fixCodeTabs(){
/* if only a single code block is contained in the tab and no style was selected, treat it like style=code */
var codeTabPanels = Array.from( document.querySelectorAll( '.tab-content.tab-panel-style.initial' ) ).filter( function( tabPanel ){
var codeTabPanels = Array.from( document.querySelectorAll( '.tab-content.tab-panel-style' ) ).filter( function( tabPanel ){
return tabPanel.querySelector( '.tab-content-text > div.highlight:only-child, .tab-content-text > pre.pre-code:only-child');
});
codeTabPanels.forEach( function( tabPanel ){
tabPanel.classList.remove( 'initial' );
tabPanel.classList.add( 'code' );
tabId = tabPanel.dataset.tabItem;
var p = tabPanel.parentNode.parentNode;
var tabId = tabPanel.dataset.tabItem;
var tabButton = p.querySelector( '.tab-nav-button.tab-panel-style[data-tab-item="'+tabId+'"]' );
tabButton.classList.remove( 'initial' );
tabButton.classList.add( 'code' );
if( tabPanel.classList.contains( 'initial' ) ){
tabButton.classList.remove( 'initial' );
tabButton.classList.add( 'code' );
tabPanel.classList.remove( 'initial' );
tabPanel.classList.add( 'code' );
}
// mark code blocks for FF without :has()
tabPanel.classList.add( 'codify' );
});
}