1- jQuery ( window ) . load ( function ( ) {
2- var location = window . location ;
3- versionSwitcher ( jQuery ) ;
4- } ) ;
1+ jQuery ( window ) . load ( function ( ) {
2+ versionSwitcher ( jQuery ) . then ( function ( ) { } ) ;
3+ } ) ;
54
65/**
76 * Utility to browse different versions of the documentation. Requires the versions.js file loaded, which lists the
87 * available (relevant) versions of a particular publication.
98 */
10- function versionSwitcher ( $ )
11- {
12- var MAX_STABLE_COUNT = 2 ;
13- var DOCS_BASE_URL = window . docMeta . commonDocsBaseUri ;
14- var THIS_DOC_BASE_URI = window . docMeta . unversionedDocBaseUri ;
15-
16- var currentVersion = window . docMeta . version ;
17- var currentPage = window . neo4jPageId ;
9+ async function versionSwitcher ( $ ) {
10+ const docMeta = await window . docMeta ;
11+ const THIS_DOC_BASE_URI = docMeta . unversionedDocBaseUri ;
12+ const currentPage = docMeta . neo4jPageId ;
1813
1914 loadVersions ( ) ;
2015
@@ -23,56 +18,59 @@ function versionSwitcher( $ )
2318 * Non-existing entries will be unlinked. Current version will be marked as such.
2419 */
2520 function loadVersions ( ) {
26- var $navHeader = $ ( 'header' ) ;
27- var $additionalVersions = $ ( '<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="dropdownMenu1"/>' ) ;
28- var versionCount = 0 ;
29- $ . each ( window . docMeta . availableDocVersions , function ( index , version ) {
30- if ( version === currentVersion ) {
31- return ;
32- }
33- else {
34- addVersion ( version , $additionalVersions ) ;
21+ const $navHeader = $ ( 'header' ) ;
22+ const $additionalVersions = $ ( '<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="dropdownMenu1"/>' ) ;
23+ let versionCount = 0 ;
24+ let currentVersion = docMeta . version
25+ const availableVersions = docMeta . availableDocVersions ;
26+ console . log ( 'availableVersions' , availableVersions )
27+ availableVersions . forEach ( function ( version ) {
28+ if ( version !== currentVersion ) {
29+ addVersion ( version , $additionalVersions ) ;
3530 versionCount ++ ;
3631 }
37- } ) ;
38- if ( versionCount == 0 ) {
39- var $dropdown = $ ( '<div id="additional-versions"><div class="additional-versions">Version: ' + currentVersion + ' </div></div>' ) ;
32+ } ) ;
33+
34+ let $dropdown ;
35+ if ( versionCount === 0 ) {
36+ $dropdown = $ ( '<div id="additional-versions"><div class="additional-versions">Version: ' + currentVersion + ' </div></div>' ) ;
4037 } else {
41- var $dropdown = $ ( '<div id="additional-versions"><div class="dropdown"><a class="dropdown-toggle"id="dropdownMenu1" data-toggle="dropdown">Version: ' + currentVersion + ' <i class="fa fa-caret-down"></i></a></div></div>' ) ;
42- $dropdown . children ( ) . first ( ) . append ( $additionalVersions ) ;
38+ $dropdown = $ ( '<div id="additional-versions"><div class="dropdown"><a class="dropdown-toggle"id="dropdownMenu1" data-toggle="dropdown">Version: ' + currentVersion + ' <i class="fa fa-caret-down"></i></a></div></div>' ) ;
39+ $dropdown . children ( ) . first ( ) . append ( $additionalVersions ) ;
4340 }
44- $navHeader . append ( $dropdown ) ;
41+ $navHeader . append ( $dropdown ) ;
4542 }
4643
47- function addVersion ( version , $container ) {
48- var $optionWrapper = $ ( '<li />' ) ;
49- var $newOption = $ ( '<a role="menuitem">' + version + '</a>' ) . appendTo ( $optionWrapper ) ;
44+ function addVersion ( version , $container ) {
45+ var $optionWrapper = $ ( '<li />' ) ;
46+ var $newOption = $ ( '<a role="menuitem">' + version + '</a>' ) . appendTo ( $optionWrapper ) ;
5047 var url = THIS_DOC_BASE_URI + version + '/' + currentPage ;
51- $container . append ( $optionWrapper ) ;
52- checkUrlExistence ( url , function ( ) {
53- $newOption . attr ( 'href' , url ) ;
54- $newOption . attr ( 'title' , 'See this page in version ' + version + '.' ) ;
55- } , function ( ) {
56- $newOption . attr ( 'title' , 'This page does not exist in version ' + version + '.' ) ;
57- $optionWrapper . addClass ( 'disabled' ) ;
48+ $container . append ( $optionWrapper ) ;
49+ checkUrlExistence ( url , function ( ) {
50+ $newOption . attr ( 'href' , url ) ;
51+ $newOption . attr ( 'title' , 'See this page in version ' + version + '.' ) ;
52+ } , function ( ) {
53+ $newOption . attr ( 'title' , 'This page does not exist in version ' + version + '.' ) ;
54+ $optionWrapper . addClass ( 'disabled' ) ;
5855 }
5956 ) ;
6057 }
6158
6259 /**
6360 * Check if a specific URL exists. The success and failure functions will be automatically called on finish.
6461 */
65- function checkUrlExistence ( url , success , failure ) {
62+ function checkUrlExistence ( url , success , failure ) {
6663 var settings = {
67- 'type' : 'HEAD' ,
68- 'async' : true ,
69- 'url' : url
64+ 'type' : 'HEAD' ,
65+ 'async' : true ,
66+ 'url' : url
7067 } ;
71- if ( success )
68+ if ( success )
7269 settings . success = success ;
73- if ( failure )
70+ if ( failure )
7471 settings . error = failure ;
75- $ . ajax ( settings ) ;
72+ $ . ajax ( settings ) ;
7673 }
7774}
75+
7876// vim: set ts=2 sw=2:
0 commit comments