Skip to content

Commit 0081c0a

Browse files
committed
Fix JavaScript showTab override scope issues
Wrap showTab override in IIFE and add function existence checks to prevent runtime errors when review functions are called before they're fully defined. Fixes issues with review loading on tab switch and initial page load.
1 parent 00e3916 commit 0081c0a

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed
42.7 KB
Binary file not shown.

docs/script.js

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -701,41 +701,51 @@ function displayAuditData(methodStats, reviewsByMethod, lastUpdated) {
701701
auditTab.innerHTML = html;
702702
}
703703

704-
// Store original showTab function
705-
let originalShowTab = showTab;
706-
707-
// Override showTab to load reviews when switching tabs
708-
function showTabWithReviews(tabId) {
709-
// Call original showTab
710-
originalShowTab(tabId);
711-
712-
// Load reviews for the current tab
713-
setTimeout(() => {
714-
const validMethods = ['coattendance', 'field-degree', 'path-structure', 'centrality', 'clustering', 'components'];
715-
if (validMethods.includes(tabId)) {
716-
loadReviewsForTab(tabId);
717-
} else if (tabId === 'audit') {
718-
loadAuditData();
719-
}
720-
}, 100);
721-
}
722-
723-
// Replace showTab
724-
showTab = showTabWithReviews;
704+
// Wrap the original showTab function to add review loading
705+
(function() {
706+
// Store original showTab function
707+
const originalShowTab = showTab;
708+
709+
// Override showTab to load reviews when switching tabs
710+
window.showTab = function(tabId) {
711+
// Call original showTab
712+
originalShowTab(tabId);
713+
714+
// Load reviews for the current tab
715+
setTimeout(() => {
716+
const validMethods = ['coattendance', 'field-degree', 'path-structure', 'centrality', 'clustering', 'components'];
717+
if (validMethods.includes(tabId)) {
718+
if (typeof loadReviewsForTab === 'function') {
719+
loadReviewsForTab(tabId);
720+
}
721+
} else if (tabId === 'audit') {
722+
if (typeof loadAuditData === 'function') {
723+
loadAuditData();
724+
}
725+
}
726+
}, 100);
727+
};
728+
})();
725729

726730
// Load reviews on page load
727731
document.addEventListener('DOMContentLoaded', function() {
728732
// Load reviews for initial tab
729-
const activeTab = document.querySelector('.tab-pane.active');
730-
if (activeTab) {
731-
const tabId = activeTab.id;
732-
if (tabId && tabId !== 'summary') {
733-
if (tabId === 'audit') {
734-
loadAuditData();
735-
} else {
736-
loadReviewsForTab(tabId);
733+
setTimeout(() => {
734+
const activeTab = document.querySelector('.tab-pane.active');
735+
if (activeTab) {
736+
const tabId = activeTab.id;
737+
if (tabId && tabId !== 'summary') {
738+
if (tabId === 'audit') {
739+
if (typeof loadAuditData === 'function') {
740+
loadAuditData();
741+
}
742+
} else {
743+
if (typeof loadReviewsForTab === 'function') {
744+
loadReviewsForTab(tabId);
745+
}
746+
}
737747
}
738748
}
739-
}
749+
}, 500);
740750
});
741751

0 commit comments

Comments
 (0)