Stirling-PDF/src/main/resources/static/js/tab-container.js
reecebrowne d9eda14521
Fix tab container logic bug (#2840)
# Description of Changes

Please provide a summary of the changes, including:

Overhauled logic for tab-containers on sign page to fix compatibility
issues with new Tooltip system

Closes #(2839)

---

## Checklist

### General

- [x ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ x] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ x] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [ x] I have performed a self-review of my own code
- [x ] My changes generate no new warnings

### Documentation

- [ x] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ x] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ x] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ x] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
2025-01-31 23:03:32 +00:00

38 lines
1.2 KiB
JavaScript

TabContainer = {
initTabGroups() {
const groups = document.querySelectorAll('.tab-group');
const unloadedGroups = [...groups].filter((g) => !g.initialised);
unloadedGroups.forEach((group) => {
const containers = group.querySelectorAll('.tab-container');
const tabTitles = [...containers].map((c) => c.getAttribute('data-title'));
const tabList = document.createElement('div');
tabList.classList.add('tab-buttons');
tabTitles.forEach((title) => {
const tabButton = document.createElement('button');
tabButton.innerHTML = title;
tabButton.onclick = (e) => {
this.setActiveTab(e.target);
};
tabList.appendChild(tabButton);
});
group.prepend(tabList);
this.setActiveTab(tabList.firstChild);
group.initialised = true;
});
},
setActiveTab(tabButton) {
const group = tabButton.closest('.tab-group');
group.querySelectorAll('.active').forEach((el) => el.classList.remove('active'));
tabButton.classList.add('active');
group.querySelector(`[data-title="${tabButton.innerHTML}"]`).classList.add('active');
},
};
document.addEventListener('DOMContentLoaded', () => {
TabContainer.initTabGroups();
});