Skip to content

Commit

Permalink
tabs: fix false codify detection if only contained in subtabs matcorn…
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Jun 8, 2023
1 parent efce383 commit 5a2ffac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion static/css/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ html[dir="rtl"] #sidebar ul.collapsible-menu > li > label > i.fa-chevron-right {
}

/* remove margin if only a single code block is contained in the tab (FF without :has using .codify style) */
#body .tab-content.tab-panel-style.codify > .tab-content-text{
#body .tab-content.codify > .tab-content-text{
padding: 0;
}
#body .tab-content-text:has(> div.highlight:only-child){
Expand Down
20 changes: 10 additions & 10 deletions static/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +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' ) ).filter( function( tabPanel ){
return tabPanel.querySelector( '.tab-content-text > div.highlight:only-child, .tab-content-text > pre.pre-code:only-child');
var codeTabContents = Array.from( document.querySelectorAll( '.tab-content.tab-panel-style' ) ).filter( function( tabContent ){
return tabContent.querySelector( '*:scope > .tab-content-text > div.highlight:only-child, *:scope > .tab-content-text > pre.pre-code:only-child');
});

codeTabPanels.forEach( function( tabPanel ){
var p = tabPanel.parentNode.parentNode;
var tabId = tabPanel.dataset.tabItem;
var tabButton = p.querySelector( '.tab-nav-button.tab-panel-style[data-tab-item="'+tabId+'"]' );
if( tabPanel.classList.contains( 'initial' ) ){
codeTabContents.forEach( function( tabContent ){
var tabId = tabContent.dataset.tabItem;
var tabPanel = tabContent.parentNode.parentNode;
var tabButton = tabPanel.querySelector( '.tab-nav-button.tab-panel-style[data-tab-item="'+tabId+'"]' );
if( tabContent.classList.contains( 'initial' ) ){
tabButton.classList.remove( 'initial' );
tabButton.classList.add( 'code' );
tabPanel.classList.remove( 'initial' );
tabPanel.classList.add( 'code' );
tabContent.classList.remove( 'initial' );
tabContent.classList.add( 'code' );
}
// mark code blocks for FF without :has()
tabPanel.classList.add( 'codify' );
tabContent.classList.add( 'codify' );
});
}

Expand Down

0 comments on commit 5a2ffac

Please sign in to comment.