1- // the new final link to load
2- newLink = "" ;
3- newVersion = "" ;
4- currentVersion = "" ;
5-
6- // the fileRequested
7- fileRequested = "" ;
8-
9- //Array prototype to check if an element is in an array
10- Array . prototype . contains = function ( obj ) {
11- return this . indexOf ( obj ) > - 1 ;
12- }
1+ let newLink = "" ;
2+ let newVersion = "" ;
3+ let currentVersion = "" ;
4+ let fileRequested = "" ;
5+
6+ const urlMappings = {
7+ "openshift-acs" : "https://docs.openshift.com/acs/" ,
8+ "openshift-builds" : "https://docs.openshift.com/builds/" ,
9+ "openshift-enterprise" : "https://docs.openshift.com/container-platform/" ,
10+ "openshift-gitops" : "https://docs.openshift.com/gitops/" ,
11+ "openshift-origin" : "https://docs.okd.io/" ,
12+ "openshift-pipelines" : "https://docs.openshift.com/pipelines/" ,
13+ "openshift-serverless" : "https://docs.openshift.com/serverless/" ,
14+ } ;
1315
1416function versionSelector ( list ) {
17+ "use strict" ;
1518
16- // the version we want
1719 newVersion = list [ list . selectedIndex ] . value ;
20+ currentVersion = window . location . pathname . split ( "/" ) [ 2 ] ;
1821
19- // spilt the current path
20- var pathArray = window . location . pathname . split ( '/' ) ;
21-
22- // so we can get the current version
23- currentVersion = pathArray [ 2 ] ;
22+ let baseUrl = urlMappings [ dk ] ;
2423
25- // if switching major versions, just take the user to the main landing page
26- // as files change a lot between major versions.
27-
28- if ( currentVersion . charAt ( 0 ) === newVersion . charAt ( 0 ) ) {
29- // the file path is just the version number + the end of the path
30- fileRequested =
31- window . location . pathname . substring (
32- window . location . pathname . lastIndexOf ( currentVersion ) +
33- currentVersion . length ) ;
34- } else {
35- fileRequested = "/welcome/index.html" ;
24+ //Handle special OCP case
25+ if ( [ "3.0" , "3.1" , "3.2" ] . includes ( newVersion ) && dk === "openshift-enterprise" ) {
26+ baseUrl = "https://docs.openshift.com/enterprise/" ;
3627 }
3728
38- // alert(fileRequested);
39-
40- // in 3.3 and above, we changed to container-platform
41- if ( [ '3.0' , '3.1' , '3.2' ] . contains ( newVersion ) ) {
42- newLink = "https://docs.openshift.com/enterprise/" +
43- newVersion +
44- fileRequested ;
45- } else if ( [ '3.65' , '3.66' , '3.67' , '3.68' , '3.69' , '3.70' , '3.71' , '3.72' , '3.73' , '3.74' , '4.0' ] . contains ( newVersion ) ) {
46- // check and handle links for RHACS versions
47- newLink = "https://docs.openshift.com/acs/" +
48- newVersion +
49- fileRequested ;
50- } else if ( [ '1.28' , '1.29' ] . contains ( newVersion ) ) {
51- // check and handle links for Serverless versions
52- newLink = "https://docs.openshift.com/serverless/" +
53- newVersion +
54- fileRequested ;
55- } else if ( [ '1.8' , '1.9' ] . contains ( newVersion ) ) {
56- // check and handle links for GitOps versions
57- newLink = "https://docs.openshift.com/gitops/" +
58- newVersion +
59- fileRequested ;
29+ if ( dk === "openshift-enterprise" && currentVersion . charAt ( 0 ) !== newVersion . charAt ( 0 ) ) {
30+ fileRequested = "/welcome/index.html" ;
6031 } else {
61- //if distro key is openshift enterprise
62- if ( dk == "openshift-enterprise" ) {
63- newLink = "https://docs.openshift.com/container-platform/" +
64- newVersion +
65- fileRequested ;
66- }
67- else if ( dk == "openshift-origin" ) {
68- newLink = "https://docs.okd.io/" +
69- newVersion +
70- fileRequested ;
71- }
32+ const versionIndex = window . location . pathname . lastIndexOf ( currentVersion ) + currentVersion . length ;
33+ fileRequested = window . location . pathname . substring ( versionIndex ) ;
7234 }
7335
36+ newLink = `${ baseUrl } ${ newVersion } ${ fileRequested } ` ;
37+
7438 // without doing async loads, there is no way to know if the path actually
7539 // exists - so we will just have to load
7640 // window.location = newLink;
@@ -79,36 +43,28 @@ function versionSelector(list) {
7943 type : 'HEAD' ,
8044 url : newLink ,
8145 success : function ( ) {
82- window . location = newLink ;
46+ window . location . href = newLink ;
8347 } ,
8448 error : function ( jqXHR , exception ) {
8549 if ( jqXHR . status == 404 ) {
8650 list . value = currentVersion ;
87- if ( confirm ( "This page doesn't exist in version " + newVersion + ". Click OK to search the " + newVersion + " docs OR Cancel to stay on this page." ) ) {
88- if ( [ '3.65' , '3.66' , '3.67' , '3.68' , '3.69' , '3.70' , '3.71' , '3.72' , '3.73' , '3.74' , '4.0' ] . contains ( newVersion ) ) {
89- window . location = "https://google.com/search?q=site:https://docs.openshift.com/acs/" + newVersion + " " + document . title ; }
90- else if ( [ '1.28' , '1.29' ] . contains ( newVersion ) ) {
91- window . location = "https://google.com/search?q=site:https://docs.openshift.com/serverless/" + newVersion + " " + document . title ; }
92- else if ( [ '1.8' , '1.9' ] . contains ( newVersion ) ) {
93- window . location = "https://google.com/search?q=site:https://docs.openshift.com/gitops/" + newVersion + " " + document . title ; }
94- else {
95- if ( dk == "openshift-enterprise" ) {
96- window . location = "https://google.com/search?q=site:https://docs.openshift.com/enterprise/" + newVersion + " " + document . title ;
97- } else {
98- if ( dk == "openshift-origin" ) {
99- window . location = "https://google.com/search?q=site:https://docs.okd.io/" + newVersion + " " + document . title ;
100- }
101- }
51+ const confirmMessage = `This page doesn't exist in version ${ newVersion } . Click OK to search the ${ newVersion } docs OR Cancel to stay on this page.` ;
52+ if ( confirm ( confirmMessage ) ) {
53+ let searchUrl ;
54+ if ( [ "3.0" , "3.1" , "3.2" ] . includes ( newVersion ) && dk === "openshift-enterprise" ) {
55+ searchUrl = `https://google.com/search?q=site:${ baseUrl } ${ newVersion } ${ document . title } ` ;
56+ } else {
57+ searchUrl = `https://google.com/search?q=site:${ urlMappings [ dk ] } ${ newVersion } ${ document . title } ` ;
10258 }
59+ window . location . href = searchUrl ;
10360 } else {
10461 // do nothing, user doesn't want to search
10562 }
10663 } else {
107- window . location = newLink ; // assumption here is that we can follow through with a redirect
64+ window . location . href = newLink ; // assumption here is that we can follow through with a redirect
10865 }
10966 }
11067 } ) ;
111-
11268}
11369
11470// checks what language was selected and then sends the user to the portal for their localized version
@@ -289,4 +245,4 @@ function addReferrer() {
289245 }
290246
291247
292- }
248+ }
0 commit comments