mediawiki-extensions-Tabber.../modules/ext.tabberNeue.codex/ext.tabberNeue.codex.js
H. C. Kruse 7f75899995
feat: add support for nested tabbers in Codex (#95)
* refactor: Apply some code cleanup

* feat: WIP dynamic nested tabber in codex

* feat: Make deeply nested tabbers work

* doc: fix comment position

---------

Co-authored-by: alistair3149 <alistair3149@users.noreply.github.com>
2023-07-11 22:06:57 -04:00

59 lines
1.1 KiB
JavaScript

const
Vue = require( 'vue' ),
App = require( './App.vue' );
/**
* @param {Element} tabber
* @return {void}
*/
function initApp( tabber ) {
const tabs = tabber.querySelectorAll( ':scope > .tabber__section > .tabber__panel' );
const tabberData = {
tabsData: [],
currentTab: ''
};
tabs.forEach( ( tab ) => {
const label = tab.getAttribute( 'data-title' );
tabberData.tabsData.push( {
name: mw.util.escapeIdForAttribute( label ),
label: label,
content: tab.innerHTML
} );
} );
tabberData.currentTab = tabberData.tabsData[ 0 ].name;
//@ts-ignore MediaWiki-specific function
Vue.createMwApp(
App, Object.assign( {
tabberData: tabberData
} )
)
.mount( tabber );
}
/**
* @param {Document} document
* @return {void}
*/
function main( document ) {
const tabbers = document.querySelectorAll( '.tabber:not( .tabber--live )' );
tabbers.forEach( initApp );
}
main( document );
/*
* Add hooks for Tabber when Visual Editor is used.
*/
mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init', function () {
// After saving edits
mw.hook( 'postEdit.afterRemoval' ).add( () => {
main( document );
} );
} );