File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+ } ) ;
You can’t perform that action at this time.
0 commit comments