Skip to content

Commit 165e8b4

Browse files
committed
Fix #6
Signed-off-by: David Weik <[email protected]>
1 parent 5925d1b commit 165e8b4

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Change: The Prompt Builder object now filters for projects with the Prompt-Engineering tag
77
- Change: The Prompt Builder object now supports deprecation of LLMs
88
- Fix: Instead of using hyphens, invalid characters are removed fully for *validate-python-package-name.js*
9+
- Add: Deep-Linking support for Tabs
910

1011
## SAS Portal Framework for SAS Viya v1.2.2
1112

index.html

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,69 @@
153153

154154
// Generate Portal
155155
authWithViya(VIYA, SASLOGIN, PORTAL, SASPORTAL);
156+
157+
// Function to activate a tab based on its ID
158+
function activateTab(tabId) {
159+
const tabButton = document.getElementById(tabId);
160+
if (tabButton) {
161+
const bsTab = new bootstrap.Tab(tabButton);
162+
bsTab.show();
163+
history.pushState(null, '', '#' + tabId);
164+
} else {
165+
console.warn(`Tab button with ID '${tabId}' not found.`);
166+
}
167+
}
168+
169+
// This function encapsulates all initialization logic for tabs and deeplinks
170+
function initializeTabsAndDeeplinks() {
171+
let attempts = 0;
172+
const maxAttempts = 20;
173+
const intervalTime = 1000;
174+
175+
const checkTabsInterval = setInterval(() => {
176+
const tabButtons = document.querySelectorAll('.nav-tabs .nav-link');
177+
178+
if (tabButtons.length > 0 && document.readyState === 'complete') {
179+
console.log(document.readyState);
180+
clearInterval(checkTabsInterval);
181+
const initialHash = window.location.hash.substring(1);
182+
if (initialHash) {
183+
activateTab(initialHash);
184+
} else {
185+
const activeTabButton = document.querySelector('.nav-tabs .nav-link.active');
186+
if (activeTabButton) {
187+
history.replaceState(null, '', '#' + activeTabButton.id);
188+
} else {
189+
const firstTabButton = document.querySelector('.nav-tabs .nav-link');
190+
if (firstTabButton) {
191+
activateTab(firstTabButton.id);
192+
}
193+
}
194+
}
195+
196+
tabButtons.forEach(button => {
197+
button.addEventListener('shown.bs.tab', function (event) {
198+
const newTabId = event.target.id;
199+
history.pushState(null, '', '#' + newTabId);
200+
});
201+
});
202+
} else {
203+
attempts++;
204+
if (attempts >= maxAttempts) {
205+
clearInterval(checkTabsInterval);
206+
console.error('Max attempts reached: Tab elements not found after', maxAttempts * intervalTime / 1000, 'seconds.');
207+
} else {
208+
console.log(`Attempt ${attempts}: Waiting for tab elements...`);
209+
}
210+
}
211+
}, intervalTime);
212+
}
213+
214+
if(document.readyState === 'loading') {
215+
document.addEventListener('DOMContentLoaded', initializeTabsAndDeeplinks);
216+
} else {
217+
initializeTabsAndDeeplinks();
218+
}
156219
</script>
157220
</body>
158221
</html>

0 commit comments

Comments
 (0)