1
+ // the new final link to load
2
+ newLink = "" ;
3
+ newVersion = "" ;
4
+ currentVersion = "" ;
5
+
6
+ // the fileRequested
7
+ fileRequested = "" ;
8
+
1
9
function versionSelector ( list ) {
2
10
3
11
// the version we want
4
12
newVersion = list [ list . selectedIndex ] . value ;
5
13
6
- // the new final link to load
7
- newLink = "" ;
8
-
9
- // the fileRequested
10
- var fileRequested = "" ;
11
-
12
14
// spilt the current path
13
15
var pathArray = window . location . pathname . split ( '/' ) ;
14
16
@@ -28,7 +30,6 @@ function versionSelector(list) {
28
30
fileRequested = "/welcome/index.html" ;
29
31
}
30
32
31
-
32
33
// alert(fileRequested);
33
34
34
35
// in 3.3 and above, we changed to container-platform
@@ -44,7 +45,27 @@ function versionSelector(list) {
44
45
45
46
// without doing async loads, there is no way to know if the path actually
46
47
// exists - so we will just have to load
47
- window . location = newLink ;
48
+ // window.location = newLink;
49
+ // testing async validations
50
+ $ . ajax ( {
51
+ type : 'HEAD' ,
52
+ url : newLink ,
53
+ success : function ( ) {
54
+ window . location = newLink ;
55
+ } ,
56
+ error : function ( jqXHR , exception ) {
57
+ if ( jqXHR . status == 404 ) {
58
+ list . value = currentVersion ;
59
+ if ( confirm ( "This page doesn't exist in version " + newVersion + ". Click OK to search the " + newVersion + " docs OR Cancel to stay on this page." ) ) {
60
+ window . location = "https://google.com/search?q=site:https://docs.openshift.com/container-platform/" + newVersion + " " + document . title ;
61
+ } else {
62
+ // do nothing, user doesn't want to search
63
+ }
64
+ } else {
65
+ window . location = newLink ; // assumption here is that we can follow through with a redirect
66
+ }
67
+ }
68
+ } ) ;
48
69
49
70
}
50
71
@@ -58,20 +79,41 @@ function selectLang(langList) {
58
79
console . log ( "Win Path: " + winPath ) ;
59
80
60
81
var currentVersion = document . getElementById ( "version-selector" ) . value ;
61
- // var currentVersion = "4.7";
62
82
console . log ( "CurrentVersion: " + currentVersion ) ;
63
83
64
84
// path for the file to reference on portal (the last bit removes .html)
65
- var path = winPath . substring ( winPath . lastIndexOf ( currentVersion ) + currentVersion . length , winPath . length - 5 ) ;
85
+ var path = winPath . substring ( winPath . lastIndexOf ( currentVersion ) + ( currentVersion . length + 1 ) , winPath . length - 5 ) ;
86
+
87
+ var parts = path . split ( "/" ) ;
88
+
89
+ console . log ( parts ) ;
90
+
91
+ // map things to html-single. While plain HTML is preferred, it is harder to map and get all anchors right. html-single ensures there is no 404 and the user at least lands on the right book
92
+ console . log ( parts [ parts . length - 1 ] ) ;
93
+
94
+ var anchorid = parts [ parts . length - 1 ] ;
95
+ var book = parts [ 0 ] ;
96
+
97
+ // add changed book names here
98
+ if ( book == "updating" ) book = "updating_clusters" ;
99
+ if ( book == "virt" ) book = "openshift_virtualization" ;
100
+ if ( book == "post_installation_configuration" ) book = "post-installation_configuration" ;
101
+
102
+ // var section = parts[1].replace(/\_/g, "-"); // replace underscore with dash
103
+ // var section = subGroup.toLowerCase().replace(" ", "-");
104
+ // console.log(section);
105
+ // var subsection = parts[2].replace(/\_/g, "-");
106
+ // console.log(subsection);
107
+
108
+ // path = book + "/" + section + "#" + subsection;
109
+ path = book + "#" + anchorid ;
66
110
67
111
console . log ( "Path: " + path ) ;
68
112
69
113
var portalBaseURL = "https://access.redhat.com/documentation" ;
70
- var finalURL = portalBaseURL + "/" + lang + "/openshift_container_platform/" + currentVersion + "/html/" + path ;
114
+ var finalURL = portalBaseURL + "/" + lang + "/openshift_container_platform/" + currentVersion + "/html-single /" + path ;
71
115
72
116
console . log ( "Final URL: " + finalURL ) ;
73
-
74
- // alert(finalURL);
75
117
window . location . href = finalURL ;
76
118
77
119
}
0 commit comments