Skip to content

Commit d0a5ce6

Browse files
Merge pull request #80 from kallewesterling/main
Adding checkbox to control test/prod domain
2 parents 40a8d0e + 2ddd7fd commit d0a5ce6

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

production/skilljar-theme-v2.1.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,8 @@ document.addEventListener("DOMContentLoaded", () => {
27162716
${page.isPageCatalog ? "stylePathCatalogPage" : ""}
27172717
</p>`);
27182718

2719+
innerHTML.push(`<input type="checkbox" id="cg-baseurl-staging" />`);
2720+
27192721
// Add course edit link
27202722
if (course.id) {
27212723
innerHTML.push(
@@ -2933,3 +2935,30 @@ function shoot() {
29332935
},
29342936
});
29352937
}
2938+
2939+
document.addEventListener('DOMContentLoaded', function() {
2940+
const checkbox = document.getElementById('cg-baseurl-staging');
2941+
2942+
if (checkbox) {
2943+
function updateLinks(useTestDomain) {
2944+
const links = document.querySelectorAll('a[href*="' + DOMAIN.prod.url + '"], a[href*="' + DOMAIN.stage.url + '"]');
2945+
links.forEach(link => {
2946+
const url = new URL(link.href);
2947+
if (useTestDomain && url.hostname === DOMAIN.prod.url) {
2948+
url.hostname = DOMAIN.stage.url;
2949+
} else if (!useTestDomain && url.hostname === DOMAIN.stage.url) {
2950+
url.hostname = DOMAIN.prod.url;
2951+
}
2952+
link.href = url.toString();
2953+
});
2954+
}
2955+
2956+
// initial state update if needed
2957+
updateLinks(checkbox.checked);
2958+
2959+
// toggle behavior
2960+
checkbox.addEventListener('change', function() {
2961+
updateLinks(this.checked);
2962+
});
2963+
}
2964+
});

0 commit comments

Comments
 (0)