1
+ const toggleModeEl = document . getElementById ( "toggle-mode" ) ;
2
+ const mapEl = document . querySelector ( "arcgis-map" ) ;
3
+ const darkModeCss = document . getElementById ( "jsapi-mode-dark" ) ;
4
+ const lightModeCss = document . getElementById ( "jsapi-mode-light" ) ;
5
+ const liveRegion = document . getElementById ( "liveRegion" ) ;
6
+ const searchEl = document . getElementById ( "search-el" ) ;
7
+ const expandEl = document . getElementById ( "expand-el" ) ;
8
+
9
+ let mode = "light" ;
10
+
11
+ toggleModeEl . addEventListener ( "click" , handleModeChange ) ;
12
+
13
+
14
+ // Initialize the mutation observer
15
+ // Resource: https://developers.arcgis.com/javascript/latest/watch-for-changes/#using-a-mutation-observer
16
+ const observer = new MutationObserver ( ( mutations , observer ) => {
17
+ for ( let mutation of mutations ) {
18
+ // Mutation observer change message
19
+ const mutationMessage = `MutationObserver: ${ mutation . attributeName } has changed to ${ mutation . target [ mutation . attributeName ] } ` ;
20
+ console . log ( mutationMessage ) ;
21
+ // Set focus on the arcgis-search if the component is expanded
22
+ // Else set focus on the arcgis-expand
23
+ if ( mutation . target [ mutation . attributeName ] == true ) {
24
+ searchEl . focusSearch ( ) ;
25
+ } else {
26
+ const expandEls = document . querySelectorAll ( ".esri-expand__toggle > calcite-action" ) ;
27
+ expandEls [ 0 ] . setFocus ( ) ;
28
+ }
29
+ }
30
+ } ) ;
31
+
32
+ // Start observing the arcgis-expand's "expanded" attribute
33
+ observer . observe ( expandEl , {
34
+ attributeFilter : [ "expanded" ]
35
+ } ) ;
36
+
37
+
38
+ function handleModeChange ( ) {
39
+ mode = mode === "dark" ? "light" : "dark" ;
40
+ const isDarkMode = mode === "dark" ;
41
+ darkModeCss . disabled = ! isDarkMode ;
42
+ lightModeCss . disabled = isDarkMode ;
43
+ toggleModeEl . icon = isDarkMode ? "moon" : "brightness" ;
44
+ document . body . className = isDarkMode ? "calcite-mode-dark" : "" ;
45
+
46
+ document . querySelectorAll ( `.calcite-mode-${ isDarkMode ? "light" : "dark" } ` ) . forEach ( node =>
47
+ node . classList . replace ( `calcite-mode-${ isDarkMode ? "light" : "dark" } ` , `calcite-mode-${ mode } ` )
48
+ ) ;
49
+ }
0 commit comments