Skip to content

Commit

Permalink
Introduce initTabs
Browse files Browse the repository at this point in the history
  • Loading branch information
takayukister committed Aug 31, 2024
1 parent 0f3336c commit 1bf6150
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
25 changes: 2 additions & 23 deletions admin/includes/js/src/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
import { switchTab } from './tabs';
import { init as initTabs, switchTab } from './tabs';
import { init as v1Init } from './tag-generator-v1';
import { init as v2Init } from './tag-generator-v2';

document.addEventListener( 'DOMContentLoaded', event => {
document.querySelectorAll(
'#contact-form-editor-tabs li'
).forEach( tab => {
tab.addEventListener( 'click', event => {
switchTab( tab.dataset?.panel );
event.preventDefault();
} );
} );

document.querySelectorAll(
'.contact-form-editor-panel'
).forEach( panel => {
if ( panel.classList.contains( 'active' ) ) {
document.querySelector(
'#contact-form-editor'
)?.setAttribute( 'data-active-tab', panel.id );
} else {
panel.style.setProperty( 'display', 'none' );
}
} );

switchTab( document.querySelector( 'input[name="active-tab"]' )?.value );
initTabs();

document.querySelectorAll(
'[data-taggen="open-dialog"]'
Expand Down
29 changes: 28 additions & 1 deletion admin/includes/js/src/tabs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
const init = () => {
document.querySelectorAll(
'#contact-form-editor-tabs li'
).forEach( tab => {
tab.addEventListener( 'click', event => {
switchTab( tab.dataset?.panel );
event.preventDefault();
} );
} );

document.querySelectorAll(
'.contact-form-editor-panel'
).forEach( panel => {
if ( panel.classList.contains( 'active' ) ) {
document.querySelector(
'#contact-form-editor'
)?.setAttribute( 'data-active-tab', panel.id );
} else {
panel.style.setProperty( 'display', 'none' );
}
} );

switchTab( document.querySelector( 'input[name="active-tab"]' )?.value );
};


const switchTab = id => {
if ( ! id ) {
return;
Expand Down Expand Up @@ -42,5 +68,6 @@ const switchTab = id => {


export {
switchTab
init,
switchTab,
};

0 comments on commit 1bf6150

Please sign in to comment.