@@ -12,11 +12,13 @@ window.ddOffcanvas = Offcanvas;
1212
1313// Edition toggler (Open Source / Pro)
1414//
15- // The sidebar renders both edition menus (.version-opensource / .version-pro);
16- // this shows one, persists the choice, and keeps every segmented control on
17- // the page (desktop sidebar + mobile offcanvas) in sync. The sidebar and the
18- // control start hidden (see _custom.scss) and are revealed only after the
19- // stored edition is applied, so there is no flash of the wrong menu.
15+ // The sidebar renders both edition menus (.version-opensource / .version-pro).
16+ // Which menu shows — and which segmented-control button reads as selected —
17+ // is pure CSS keyed off html[data-dd-version] (see _custom.scss). An inline
18+ // script in custom-head.html stamps that attribute from localStorage before
19+ // first paint, so every page load renders the stored edition immediately with
20+ // no hide-then-reveal flicker. This module only handles toggling: update the
21+ // attribute, persist the choice, sync aria-checked for assistive tech.
2022( ( ) => {
2123 "use strict" ;
2224
@@ -41,26 +43,21 @@ window.ddOffcanvas = Offcanvas;
4143 } ;
4244
4345 const setVersion = ( version ) => {
44- document . querySelectorAll ( ".version-opensource, .version-pro" ) . forEach ( el => {
45- el . style . display = el . classList . contains ( `version-${ version } ` ) ? "block" : "none" ;
46- } ) ;
46+ // CSS shows the matching menu and highlights the matching button
47+ document . documentElement . dataset . ddVersion = version ;
4748
48- localStorage . setItem ( "version" , version ) ;
49+ try {
50+ localStorage . setItem ( "version" , version ) ;
51+ } catch ( e ) {
52+ // Storage blocked (private browsing) — toggle still works this page
53+ }
4954
50- // Sync every segmented control instance, then reveal it
51- document . querySelectorAll ( ".dd-version-seg" ) . forEach ( seg => {
52- seg . querySelectorAll ( "button[data-version-value]" ) . forEach ( btn => {
53- btn . setAttribute ( "aria-checked" , btn . dataset . versionValue === version ? "true" : "false" ) ;
54- } ) ;
55- seg . style . visibility = "visible" ;
55+ // aria-checked is for assistive tech only; visuals come from the
56+ // html[data-dd-version] attribute above
57+ document . querySelectorAll ( ".dd-version-seg button[data-version-value]" ) . forEach ( btn => {
58+ btn . setAttribute ( "aria-checked" , btn . dataset . versionValue === version ? "true" : "false" ) ;
5659 } ) ;
5760
58- // Unhide sidebar after version is applied
59- const sidebar = document . querySelector ( ".docs-sidebar" ) ;
60- if ( sidebar ) {
61- sidebar . style . visibility = "visible" ;
62- }
63-
6461 // Edition-aware top nav: route "Model Your Assets" to the page that
6562 // matches the selected version (see assetNavUrls above).
6663 document . querySelectorAll ( "a.nav-link" ) . forEach ( link => {
@@ -71,8 +68,10 @@ window.ddOffcanvas = Offcanvas;
7168 } ;
7269
7370 const initVersionToggle = ( ) => {
74- const storedVersion = localStorage . getItem ( "version" ) || "opensource" ;
75- setVersion ( storedVersion ) ;
71+ // custom-head.html already stamped the stored edition on <html> before
72+ // paint; re-applying it here syncs aria-checked and the nav link on
73+ // freshly parsed (or dynamically replaced) markup.
74+ setVersion ( document . documentElement . dataset . ddVersion || "opensource" ) ;
7675 } ;
7776
7877 // Delegated listener on body — catches every control instance
0 commit comments