@@ -22,68 +22,66 @@ export const initializeComponents = (Story, context) => {
22
22
// Initialize based on component type
23
23
switch ( componentType ) {
24
24
case 'language-switcher' :
25
- // if (typeof window.UNDP?. langSwitch === 'function') {
26
- // window.UNDP. langSwitch();
27
- // element.setAttribute('data-initialized', 'true');
28
- // } else {
25
+ if ( typeof langSwitch === 'function' ) {
26
+ langSwitch ( ) ;
27
+ element . setAttribute ( 'data-initialized' , 'true' ) ;
28
+ } else {
29
29
import ( "../js/lang-switcher.js" ) . then ( module => {
30
30
if ( module && typeof module . langSwitch === 'function' ) {
31
31
module . langSwitch ( ) ;
32
32
}
33
33
element . setAttribute ( 'data-initialized' , 'true' ) ;
34
34
} ) . catch ( err => console . error ( 'Error initializing language-switcher:' , err ) ) ;
35
- // }
35
+ }
36
36
break ;
37
37
38
38
case 'accordion' :
39
- // try without window.UNDP
40
- // location of data initialized
41
- // if (typeof window.UNDP?.accordion === 'function') {
42
- // window.UNDP.accordion();
43
- // element.setAttribute('data-initialized', 'true');
44
- // } else {
39
+ if ( typeof accordion === 'function' ) {
40
+ accordion ( ) ;
41
+ element . setAttribute ( 'data-initialized' , 'true' ) ;
42
+ } else {
45
43
import ( "../js/accordion.js" ) . then ( module => {
46
44
if ( module && typeof module . accordion === 'function' ) {
47
45
module . accordion ( ) ;
48
46
}
49
47
element . setAttribute ( 'data-initialized' , 'true' ) ;
50
48
} ) . catch ( err => console . error ( 'Error initializing accordion:' , err ) ) ;
51
- // }
49
+ }
52
50
break ;
53
51
54
52
case 'modal' :
55
- // if (typeof window.UNDP?. modal === 'function') {
56
- // window.UNDP. modal();
57
- // element.setAttribute('data-initialized', 'true');
58
- // } else {
53
+ if ( typeof modal === 'function' ) {
54
+ modal ( ) ;
55
+ element . setAttribute ( 'data-initialized' , 'true' ) ;
56
+ } else {
59
57
import ( "../js/modal.js" ) . then ( module => {
60
58
if ( module && typeof module . modal === 'function' ) {
61
59
module . modal ( ) ;
62
60
}
63
61
element . setAttribute ( 'data-initialized' , 'true' ) ;
64
62
} ) . catch ( err => console . error ( 'Error initializing accordion:' , err ) ) ;
65
- // }
63
+ }
66
64
break ;
67
65
case 'swiper' :
68
- // if (typeof window.UNDP?. swiper === 'function') {
69
- // const targetSelector = element.getAttribute('data-selector');
70
- // let arrowsSelector = element.getAttribute('data-arrows-selector');
71
- // const optionsAttr = element.getAttribute('data-options');
72
- // if (arrowsSelector === "false") {
73
- // arrowsSelector = false;
74
- // }
75
- // let swiperOptions = {};
76
- // if (optionsAttr) {
77
- // try {
78
- // swiperOptions = JSON.parse(optionsAttr);
79
- // } catch (error) {
80
- // console.warn('Invalid swiper options format:', error);
81
- // }
82
- // }
66
+ if ( typeof swiper === 'function' ) {
67
+ const targetSelector = element . getAttribute ( 'data-selector' ) ;
68
+ let arrowsSelector = element . getAttribute ( 'data-arrows-selector' ) ;
69
+ const optionsAttr = element . getAttribute ( 'data-options' ) ;
70
+ if ( arrowsSelector === "false" ) {
71
+ arrowsSelector = false ;
72
+ }
73
+ let swiperOptions = { } ;
74
+ if ( optionsAttr ) {
75
+ try {
76
+ swiperOptions = JSON . parse ( optionsAttr ) ;
77
+ } catch ( error ) {
78
+ console . warn ( 'Invalid swiper options format:' , error ) ;
79
+ }
80
+ }
83
81
84
- // window.UNDP. swiper(targetSelector, arrowsSelector, swiperOptions);
85
- // element.setAttribute('data-initialized', 'true');
86
- // } else {
82
+ swiper ( targetSelector , arrowsSelector , swiperOptions ) ;
83
+ element . setAttribute ( 'data-initialized' , 'true' ) ;
84
+ } else {
87
85
import ( "../js/swiper.js" ) . then ( module => {
88
86
if ( module && typeof module . swiper === 'function' ) {
89
87
const targetSelector = element . getAttribute ( 'data-selector' ) ;
@@ -105,63 +103,63 @@ export const initializeComponents = (Story, context) => {
105
103
}
106
104
element . setAttribute ( 'data-initialized' , 'true' ) ;
107
105
} ) . catch ( err => console . error ( 'Error initializing swiper:' , err ) ) ;
108
- // }
106
+ }
109
107
break ;
110
108
case 'lightbox-gallery' :
111
- // if (typeof window.UNDP?. lightboxGallery === 'function') {
112
- // window.UNDP. lightboxGallery();
113
- // element.setAttribute('data-initialized', 'true');
114
- // } else {
109
+ if ( typeof lightboxGallery === 'function' ) {
110
+ lightboxGallery ( ) ;
111
+ element . setAttribute ( 'data-initialized' , 'true' ) ;
112
+ } else {
115
113
import ( "../js/lightbox-gallery.js" ) . then ( module => {
116
114
if ( module && typeof module . lightboxGallery === 'function' ) {
117
115
module . lightboxGallery ( ) ;
118
116
}
119
117
element . setAttribute ( 'data-initialized' , 'true' ) ;
120
118
} ) . catch ( err => console . error ( 'Error initializing lightbox gallery :' , err ) ) ;
121
- // }
119
+ }
122
120
break ;
123
121
case 'parallax' :
124
- // if (typeof window.UNDP?. parallaxEffect === 'function') {
125
- // const { triggerElement, targetSelector, triggerHook, endTriggerHook, direction, breakpoints } = options;
126
- // window.UNDP. parallaxEffect(triggerElement, targetSelector, triggerHook, endTriggerHook, direction, breakpoints);
127
- // element.setAttribute('data-initialized', 'true');
128
- // } else {
122
+ if ( typeof parallaxEffect === 'function' ) {
123
+ const { triggerElement, targetSelector, triggerHook, endTriggerHook, direction, breakpoints } = options ;
124
+ parallaxEffect ( triggerElement , targetSelector , triggerHook , endTriggerHook , direction , breakpoints ) ;
125
+ element . setAttribute ( 'data-initialized' , 'true' ) ;
126
+ } else {
129
127
import ( "../js/parallax.js" ) . then ( module => {
130
128
if ( module && typeof module . parallaxEffect === 'function' ) {
131
129
const { triggerElement, targetSelector, triggerHook, endTriggerHook, direction, breakpoints } = options ;
132
130
module . parallaxEffect ( triggerElement , targetSelector , triggerHook , endTriggerHook , direction , breakpoints ) ;
133
131
}
134
132
element . setAttribute ( 'data-initialized' , 'true' ) ;
135
133
} ) . catch ( err => console . error ( 'Error initializing parallax effect:' , err ) ) ;
136
- // }
134
+ }
137
135
break ;
138
136
case 'expandToSize' :
139
- // if (typeof window.UNDP?. expandToSize === 'function') {
140
- // const selector = element.getAttribute('data-selector');
141
- // window.UNDP. expandToSize(selector);
142
- // element.setAttribute('data-initialized', 'true');
143
- // } else {
137
+ if ( typeof expandToSize === 'function' ) {
138
+ const selector = element . getAttribute ( 'data-selector' ) ;
139
+ expandToSize ( selector ) ;
140
+ element . setAttribute ( 'data-initialized' , 'true' ) ;
141
+ } else {
144
142
import ( "../js/animation.js" ) . then ( module => {
145
143
if ( module && typeof module . default === 'function' ) {
146
144
const selector = element . getAttribute ( 'data-selector' ) ;
147
145
module . default ( selector ) ;
148
146
}
149
147
element . setAttribute ( 'data-initialized' , 'true' ) ;
150
148
} ) . catch ( err => console . error ( 'Error initializing expandToSize:' , err ) ) ;
151
- // }
149
+ }
152
150
break ;
153
151
case 'tabs' :
154
- // if (typeof window.UNDP?. tabs === 'function') {
155
- // window.UNDP. tabs();
156
- // element.setAttribute('data-initialized', 'true');
157
- // } else {
152
+ if ( typeof tabs === 'function' ) {
153
+ tabs ( ) ;
154
+ element . setAttribute ( 'data-initialized' , 'true' ) ;
155
+ } else {
158
156
import ( "../js/tabs.js" ) . then ( module => {
159
157
if ( module && typeof module . tabs === 'function' ) {
160
158
module . tabs ( ) ;
161
159
}
162
160
element . setAttribute ( 'data-initialized' , 'true' ) ;
163
161
} ) . catch ( err => console . error ( 'Error initializing tabs:' , err ) ) ;
164
- // }
162
+ }
165
163
break ;
166
164
}
167
165
} ) ;
0 commit comments