feat: allow nested Tabber to be shown in VE preview

This commit is contained in:
alistair3149 2023-07-05 22:57:05 -04:00
parent a29e3a22c0
commit 857f6f1f9f
No known key found for this signature in database
2 changed files with 46 additions and 28 deletions

View file

@ -63,21 +63,25 @@ ve.ce.MWTabberNode.prototype.onSetup = function () {
* @param {HTMLElement} tabber
*/
ve.ce.MWTabberNode.prototype.renderHeader = function ( tabber ) {
const nestedTabbers = tabber.querySelectorAll( '.tabber__panel:first-child .tabber' );
const renderSingleHeader = function ( element ) {
const
tabPanels = tabber.querySelectorAll( ':scope > .tabber__section > .tabber__panel' ),
container = document.createElement( 'header' ),
tabPanels = element.querySelectorAll( ':scope > .tabber__section > .tabber__panel' ),
header = element.querySelector( ':scope > .tabber__header' ),
tabList = document.createElement( 'nav' ),
indicator = document.createElement( 'div' ),
fragment = new DocumentFragment();
Array.prototype.forEach.call( tabPanels, function ( tabPanel, index ) {
const tab = document.createElement( 'a' );
tab.innerText = tabPanel.title;
tab.innerText = tabPanel.getAttribute( 'data-title' );
tab.classList.add( 'tabber__tab' );
// Make first tab active
if ( index === 0 ) {
tab.classList.add( 'tabber__tab--active' );
tab.setAttribute( 'aria-selected', true );
}
fragment.append( tab );
@ -85,13 +89,24 @@ ve.ce.MWTabberNode.prototype.renderHeader = function ( tabber ) {
tabList.append( fragment );
container.classList.add( 'tabber__header' );
tabList.classList.add( 'tabber__tabs' );
indicator.classList.add( 'tabber__indicator' );
container.append( tabList );
tabber.prepend( container );
header.append( tabList, indicator );
tabber.classList.add( 'tabber--live' );
console.log( tabList );
indicator.style.width = tabList.firstElementChild.offsetWidth + 'px';
element.classList.add( 'tabber--live' );
};
if ( nestedTabbers.length > 0 ) {
Array.prototype.forEach.call( nestedTabbers, function ( nestedTabber ) {
renderSingleHeader( nestedTabber );
} );
}
renderSingleHeader( tabber );
lastHeader = tabber.firstElementChild;
};

View file

@ -63,20 +63,22 @@ ve.ce.MWTabberTranscludeNode.prototype.onSetup = function () {
* @param {HTMLElement} tabber
*/
ve.ce.MWTabberTranscludeNode.prototype.renderHeader = function ( tabber ) {
const tabPanels = tabber.querySelectorAll( ':scope > .tabber__section > .tabber__panel' ),
container = document.createElement( 'header' ),
const
tabPanels = tabber.querySelectorAll( ':scope > .tabber__section > .tabber__panel' ),
header = tabber.querySelector( ':scope > .tabber__header' ),
tabList = document.createElement( 'nav' ),
indicator = document.createElement( 'div' ),
fragment = new DocumentFragment();
Array.prototype.forEach.call( tabPanels, function ( tabPanel, index ) {
const tab = document.createElement( 'a' );
tab.innerText = tabPanel.title;
tab.innerText = tabPanel.getAttribute( 'data-title' );
tab.classList.add( 'tabber__tab' );
// Make first tab active
if ( index === 0 ) {
tab.classList.add( 'tabber__tab--active' );
tab.setAttribute( 'aria-selected', true );
}
fragment.append( tab );
@ -84,11 +86,12 @@ ve.ce.MWTabberTranscludeNode.prototype.renderHeader = function ( tabber ) {
tabList.append( fragment );
container.classList.add( 'tabber__header' );
tabList.classList.add( 'tabber__tabs' );
indicator.classList.add( 'tabber__indicator' );
container.append( tabList );
tabber.prepend( container );
header.append( tabList, indicator );
indicator.style.width = tabList.firstElementChild.offsetWidth + 'px';
tabber.classList.add( 'tabber--live' );