Skip to content

Commit

Permalink
correctly autoselect http/s
Browse files Browse the repository at this point in the history
Signed-off-by: JD <156010594+5u6r054@users.noreply.github.com>
  • Loading branch information
5u6r054 committed Jul 31, 2024
1 parent c17797a commit ef7de1e
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions pkg/api/templates/swagger.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,29 @@
],
layout: "StandaloneLayout",
onComplete: function() {
const currentScheme = window.location.protocol.slice(0, -1);
const schemeSelect = document.querySelector('.scheme-container select');
if (schemeSelect) {
schemeSelect.value = currentScheme;
schemeSelect.dispatchEvent(new Event('change'));
}
setTimeout(function() {
const currentScheme = window.location.protocol.slice(0, -1);
const schemeSelect = document.querySelector('.scheme-container select');
if (schemeSelect) {
schemeSelect.value = currentScheme;
schemeSelect.dispatchEvent(new Event('change'));
}
}, 100); // Small delay to ensure UI is fully rendered

// Add this after the setTimeout in the onComplete function
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
const schemeSelect = document.querySelector('.scheme-container select');
if (schemeSelect && schemeSelect.value !== currentScheme) {
schemeSelect.value = currentScheme;
schemeSelect.dispatchEvent(new Event('change'));
}
}
});
});

observer.observe(document.body, { childList: true, subtree: true });
}
});
}
Expand Down

0 comments on commit ef7de1e

Please sign in to comment.