@@ -6,6 +6,7 @@ import SearchFormController from "../carte/search_solution_form_controller"
6
6
export default class extends Controller < HTMLElement > {
7
7
static values = {
8
8
location : Object ,
9
+ iframe : Boolean ,
9
10
}
10
11
static outlets = [ "address-autocomplete" , "search-solution-form" ]
11
12
declare addressAutocompleteOutlets : Array < AdresseAutocompleteController >
@@ -15,12 +16,34 @@ export default class extends Controller<HTMLElement> {
15
16
latitude : string | null
16
17
longitude : string | null
17
18
}
19
+ declare iframeValue : boolean
18
20
19
21
connect ( ) {
20
- document . addEventListener (
21
- "turbo:frame-load" ,
22
- this . fetchLocationFromSessionStorageOnFirstLoad . bind ( this ) ,
23
- )
22
+ document . addEventListener ( "turbo:frame-load" , this . #initRecurringEvents. bind ( this ) )
23
+ }
24
+
25
+ #initRecurringEvents( event ) {
26
+ /**
27
+ These methods must be called every time we add elements to the dom through a turbo-frame
28
+ so that all new DOM nodes get updated.
29
+ */
30
+ this . fetchLocationFromSessionStorageOnFirstLoad ( event )
31
+ this . configureIframeSpecificUI ( )
32
+ }
33
+
34
+ configureIframeSpecificUI ( ) {
35
+ if ( sessionStorage . getItem ( "iframe" ) === "true" ) {
36
+ this . iframeValue = true
37
+ }
38
+
39
+ if ( this . iframeValue ) {
40
+ document . querySelectorAll < HTMLLinkElement > ( 'a[href^="/"]' ) . forEach ( ( link ) => {
41
+ const url = new URL ( link . href , window . location . origin )
42
+ url . searchParams . set ( "iframe" , "1" )
43
+ link . href = url . toString ( )
44
+ } )
45
+ sessionStorage . setItem ( "iframe" , "true" )
46
+ }
24
47
}
25
48
26
49
fetchLocationFromSessionStorageOnFirstLoad ( event ) {
0 commit comments