2023-07-05 21:43:41 +00:00
|
|
|
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;
|
|
|
|
|
2023-07-12 02:07:37 +00:00
|
|
|
// @ts-ignore MediaWiki-specific function
|
2023-07-05 21:43:41 +00:00
|
|
|
Vue.createMwApp(
|
|
|
|
App, Object.assign( {
|
|
|
|
tabberData: tabberData
|
|
|
|
} )
|
|
|
|
)
|
|
|
|
.mount( tabber );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2023-08-31 19:35:22 +00:00
|
|
|
function main() {
|
2023-07-05 21:43:41 +00:00
|
|
|
const tabbers = document.querySelectorAll( '.tabber:not( .tabber--live )' );
|
|
|
|
|
2023-07-12 02:06:57 +00:00
|
|
|
tabbers.forEach( initApp );
|
2023-07-05 21:43:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-31 19:35:22 +00:00
|
|
|
mw.hook( 'wikipage.content' ).add( function () {
|
|
|
|
main();
|
|
|
|
} );
|
2023-07-06 02:10:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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( () => {
|
2023-08-31 19:35:22 +00:00
|
|
|
main();
|
2023-07-06 02:10:49 +00:00
|
|
|
} );
|
|
|
|
} );
|