@@ -311,6 +311,18 @@ var setupSearchButtons = () => {
311
311
* - DOCUMENTATION_OPTIONS.theme_switcher_url
312
312
*/
313
313
314
+ /**
315
+ * path component of URL
316
+ */
317
+ var getCurrentUrlPath = ( ) => {
318
+ if ( DOCUMENTATION_OPTIONS . BUILDER == "dirhtml" ) {
319
+ return DOCUMENTATION_OPTIONS . pagename == "index"
320
+ ? `/`
321
+ : `${ DOCUMENTATION_OPTIONS . pagename } /` ;
322
+ }
323
+ return `${ DOCUMENTATION_OPTIONS . pagename } .html` ;
324
+ } ;
325
+
314
326
/**
315
327
* Check if corresponding page path exists in other version of docs
316
328
* and, if so, go there instead of the homepage of the other docs version
@@ -320,15 +332,7 @@ var setupSearchButtons = () => {
320
332
async function checkPageExistsAndRedirect ( event ) {
321
333
// ensure we don't follow the initial link
322
334
event . preventDefault ( ) ;
323
- let currentFilePath ;
324
- if ( DOCUMENTATION_OPTIONS . BUILDER == "dirhtml" ) {
325
- currentFilePath =
326
- DOCUMENTATION_OPTIONS . pagename == "index"
327
- ? `/`
328
- : `${ DOCUMENTATION_OPTIONS . pagename } /` ;
329
- } else {
330
- currentFilePath = `${ DOCUMENTATION_OPTIONS . pagename } .html` ;
331
- }
335
+ const currentFilePath = getCurrentUrlPath ( ) ;
332
336
let tryUrl = event . currentTarget . getAttribute ( "href" ) ;
333
337
let otherDocsHomepage = tryUrl . replace ( currentFilePath , "" ) ;
334
338
try {
@@ -380,15 +384,7 @@ async function fetchVersionSwitcherJSON(url) {
380
384
381
385
// Populate the version switcher from the JSON data
382
386
function populateVersionSwitcher ( data , versionSwitcherBtns ) {
383
- let currentFilePath ;
384
- if ( DOCUMENTATION_OPTIONS . BUILDER == "dirhtml" ) {
385
- currentFilePath =
386
- DOCUMENTATION_OPTIONS . pagename == "index"
387
- ? `/`
388
- : `${ DOCUMENTATION_OPTIONS . pagename } /` ;
389
- } else {
390
- currentFilePath = `${ DOCUMENTATION_OPTIONS . pagename } .html` ;
391
- }
387
+ const currentFilePath = getCurrentUrlPath ( ) ;
392
388
versionSwitcherBtns . forEach ( ( btn ) => {
393
389
// Set empty strings by default so that these attributes exist and can be used in CSS selectors
394
390
btn . dataset [ "activeVersionName" ] = "" ;
@@ -506,14 +502,7 @@ function showVersionWarningBanner(data) {
506
502
inner . classList = "sidebar-message" ;
507
503
button . classList =
508
504
"btn text-wrap font-weight-bold ms-3 my-1 align-baseline pst-button-link-to-stable-version" ;
509
- if ( DOCUMENTATION_OPTIONS . BUILDER == "dirhtml" ) {
510
- button . href =
511
- DOCUMENTATION_OPTIONS . pagename == "index"
512
- ? `/`
513
- : `${ DOCUMENTATION_OPTIONS . pagename } /` ;
514
- } else {
515
- button . href = `${ DOCUMENTATION_OPTIONS . pagename } .html` ;
516
- }
505
+ button . href = getCurrentUrlPath ( ) ;
517
506
button . innerText = "Switch to stable version" ;
518
507
button . onclick = checkPageExistsAndRedirect ;
519
508
// add the version-dependent text
0 commit comments