@@ -7,6 +7,7 @@ const optionMap = [...selectorOptions].map((o) => ({
77 text : o . dataset . label ,
88 class : o . dataset . class ,
99 labelType : o . dataset . labelType ,
10+ default : o . dataset . defaultValue ,
1011 labelOnly : o . hidden ,
1112 selected : o . selected ,
1213 inScope : true ,
@@ -23,7 +24,9 @@ const prodMatrix = {
2324 'neo4j-enterprise' : 'neo4j-ee' ,
2425}
2526
26- const defaultProd = 'auradb-enterprise'
27+ // get the default product from optionMap
28+ const defaultProdArray = optionMap . find ( ( prod ) => prod . default === 'true' )
29+ const defaultProd = defaultProdArray ? defaultProdArray . value : optionMap [ 0 ] . value
2730
2831const defaultClasses = [ 'exampleblock' , 'sect2' , 'sect1' ]
2932
@@ -55,7 +58,7 @@ document.addEventListener('DOMContentLoaded', function () {
5558 if ( labelShow ) {
5659 labelShow . addEventListener ( 'click' , function ( c ) {
5760 c . stopPropagation ( )
58- toggleLabels ( c )
61+ toggleLabels ( c . target . checked )
5962 } )
6063 }
6164
@@ -79,7 +82,7 @@ document.addEventListener('DOMContentLoaded', function () {
7982 // console.log(`classes on the element: ${elClasses}`)
8083
8184 // get an array of classes that match the select options
82- const labelsToAdd = optionNames . filter ( function ( obj ) {
85+ let labelsToAdd = optionNames . filter ( function ( obj ) {
8386 return elClasses . indexOf ( obj ) !== - 1
8487 } ) . sort ( )
8588
@@ -100,17 +103,27 @@ document.addEventListener('DOMContentLoaded', function () {
100103 return
101104 }
102105
106+ const allLabels = Object . values ( prodMatrix )
107+ let availableOn = true
108+ const difference = allLabels . filter ( ( l ) => ! labelsToAdd . includes ( l ) )
109+ if ( difference && difference . length <= 2 ) {
110+ labelsToAdd = difference
111+ availableOn = false
112+ }
113+
103114 if ( labelsToAdd && labelsToAdd . length > 0 ) {
104115 labelsToAdd . forEach ( ( label ) => {
105- addLabel ( el , label )
116+ if ( label !== 'all' ) {
117+ addLabel ( el , label , availableOn )
118+ }
106119 } )
107120 }
108121 } )
109122
110123 // if we've removed elements we need to clean the toc by removing entries for those elements
111124 cleanToc ( )
112125
113- function addLabel ( el , match ) {
126+ function addLabel ( el , match , availableOn ) {
114127 const div = createElement ( 'div' , 'paragraph' )
115128 let labelType = 'labels'
116129
@@ -133,8 +146,11 @@ document.addEventListener('DOMContentLoaded', function () {
133146 const p = createElement ( 'p' )
134147 const span = createElement ( 'span' , `label label--${ match } group--${ group } ` )
135148
136- const text = getProductFromOptionMap ( match )
137-
149+ let text = getProductFromOptionMap ( match )
150+ if ( ! availableOn ) {
151+ text = 'Not available on ' + text
152+ span . classList . add ( 'not-available' )
153+ }
138154 span . textContent = text
139155 p . appendChild ( span )
140156
@@ -174,17 +190,25 @@ document.addEventListener('DOMContentLoaded', function () {
174190 prodSelector . addEventListener ( 'change' , function ( e ) {
175191 e . stopPropagation ( )
176192
193+ // if localhost
194+ if ( curURL . host . indexOf ( 'localhost' ) !== - 1 ) {
195+ setVisibility ( hiddenOptionNames , e . target . value === 'all' )
196+ return
197+ }
198+
199+ const currentProd = Object . keys ( prodMatrix ) . find ( ( key ) => prodMatrix [ key ] === e . target . dataset . current )
200+ const newProd = Object . keys ( prodMatrix ) . find ( ( key ) => prodMatrix [ key ] === e . target . value )
201+ const re = new RegExp ( `/${ currentProd } /` )
202+ let newURL
203+
177204 // if we're using a proxied path, just load the new url
178205 if ( selectionFromPath ) {
179- // get the new url
180- const currentProd = Object . keys ( prodMatrix ) . find ( ( key ) => prodMatrix [ key ] === e . target . dataset . current )
181- const newProd = Object . keys ( prodMatrix ) . find ( ( key ) => prodMatrix [ key ] === e . target . value )
182- const newURL = curURL . href . replace ( currentProd , newProd )
183- document . location . replace ( newURL )
206+ newURL = newProd ? curURL . href . replace ( re , `/${ newProd } /` ) : curURL . href . replace ( re , '' )
184207 } else {
185- // reset everything
186- setVisibility ( hiddenOptionNames )
208+ newURL = curURL . href . split ( '#' ) [ 0 ] . concat ( newProd ) . concat ( curURL . hash )
187209 }
210+
211+ if ( newURL ) document . location . replace ( newURL )
188212 } )
189213
190214 var versionSelector = document . querySelector ( 'body.cheat-sheet .version-selector' )
@@ -211,7 +235,7 @@ document.addEventListener('DOMContentLoaded', function () {
211235 } )
212236 }
213237
214- setVisibility ( hiddenOptionNames )
238+ setVisibility ( hiddenOptionNames , prodSelector . dataset . current === 'all' )
215239
216240 const matchTo = parseFloat ( document . querySelector ( '.nav-container .selectors' ) . getBoundingClientRect ( ) . height )
217241 const firstSection = document . querySelector ( 'article h2' )
@@ -226,19 +250,22 @@ document.addEventListener('DOMContentLoaded', function () {
226250 } )
227251} )
228252
229- function setVisibility ( hiddenOptionNames ) {
253+ function setVisibility ( hiddenOptionNames , showLabels = false ) {
230254 // reset everything
231- clearClass ( 'hidden' )
232- clearClass ( 'hide-this' )
233- clearClass ( 'selectors-match' )
255+ clearClasses ( [ 'hidden' , 'hide-this' , 'selectors-match' ] )
256+ // clearClass('hide-this')
257+ // clearClass('selectors-match')
234258 selectorMatch ( hiddenOptionNames )
235259 hideTocEntries ( )
260+ toggleLabels ( showLabels )
236261 document . querySelector ( 'body.cheat-sheet' ) . style . opacity = '1'
237262}
238263
239- function clearClass ( cl ) {
240- document . querySelectorAll ( `.toc-menu .${ cl } , .content .sect1.${ cl } , .content .sect2.${ cl } , .content .exampleblock.${ cl } ` ) . forEach ( ( el ) => {
241- el . classList . remove ( cl )
264+ function clearClasses ( cl ) {
265+ cl . forEach ( ( c ) => {
266+ document . querySelectorAll ( `.toc-menu .${ c } , .content .sect1.${ c } , .content .sect2.${ c } , .content .exampleblock.${ c } ` ) . forEach ( ( el ) => {
267+ el . classList . remove ( c )
268+ } )
242269 } )
243270}
244271
@@ -459,7 +486,7 @@ function removeDefaultClasses (c) {
459486
460487function toggleLabels ( l ) {
461488 document . querySelectorAll ( 'span.group--products' ) . forEach ( ( div ) => {
462- if ( l . target . checked ) {
489+ if ( l ) {
463490 div . style . display = 'flex'
464491 } else {
465492 div . style . display = 'none'
0 commit comments