Skip to content

Commit 9ec1954

Browse files
committed
updating global scope by removing window.UNDP
1 parent 3a480fc commit 9ec1954

File tree

1 file changed

+56
-58
lines changed

1 file changed

+56
-58
lines changed

stories/assets/js/init-loader.js

+56-58
Original file line numberDiff line numberDiff line change
@@ -22,68 +22,66 @@ export const initializeComponents = (Story, context) => {
2222
// Initialize based on component type
2323
switch (componentType) {
2424
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 {
2929
import("../js/lang-switcher.js").then(module => {
3030
if (module && typeof module.langSwitch === 'function') {
3131
module.langSwitch();
3232
}
3333
element.setAttribute('data-initialized', 'true');
3434
}).catch(err => console.error('Error initializing language-switcher:', err));
35-
// }
35+
}
3636
break;
3737

3838
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 {
4543
import("../js/accordion.js").then(module => {
4644
if (module && typeof module.accordion === 'function') {
4745
module.accordion();
4846
}
4947
element.setAttribute('data-initialized', 'true');
5048
}).catch(err => console.error('Error initializing accordion:', err));
51-
// }
49+
}
5250
break;
5351

5452
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 {
5957
import("../js/modal.js").then(module => {
6058
if (module && typeof module.modal === 'function') {
6159
module.modal();
6260
}
6361
element.setAttribute('data-initialized', 'true');
6462
}).catch(err => console.error('Error initializing accordion:', err));
65-
// }
63+
}
6664
break;
6765
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+
}
8381

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 {
8785
import("../js/swiper.js").then(module => {
8886
if (module && typeof module.swiper === 'function') {
8987
const targetSelector = element.getAttribute('data-selector');
@@ -105,63 +103,63 @@ export const initializeComponents = (Story, context) => {
105103
}
106104
element.setAttribute('data-initialized', 'true');
107105
}).catch(err => console.error('Error initializing swiper:', err));
108-
// }
106+
}
109107
break;
110108
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 {
115113
import("../js/lightbox-gallery.js").then(module => {
116114
if (module && typeof module.lightboxGallery === 'function') {
117115
module.lightboxGallery();
118116
}
119117
element.setAttribute('data-initialized', 'true');
120118
}).catch(err => console.error('Error initializing lightbox gallery :', err));
121-
// }
119+
}
122120
break;
123121
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 {
129127
import("../js/parallax.js").then(module => {
130128
if (module && typeof module.parallaxEffect === 'function') {
131129
const { triggerElement, targetSelector, triggerHook, endTriggerHook, direction, breakpoints } = options;
132130
module.parallaxEffect(triggerElement, targetSelector, triggerHook, endTriggerHook, direction, breakpoints);
133131
}
134132
element.setAttribute('data-initialized', 'true');
135133
}).catch(err => console.error('Error initializing parallax effect:', err));
136-
// }
134+
}
137135
break;
138136
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 {
144142
import("../js/animation.js").then(module => {
145143
if (module && typeof module.default === 'function') {
146144
const selector = element.getAttribute('data-selector');
147145
module.default(selector);
148146
}
149147
element.setAttribute('data-initialized', 'true');
150148
}).catch(err => console.error('Error initializing expandToSize:', err));
151-
// }
149+
}
152150
break;
153151
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 {
158156
import("../js/tabs.js").then(module => {
159157
if (module && typeof module.tabs === 'function') {
160158
module.tabs();
161159
}
162160
element.setAttribute('data-initialized', 'true');
163161
}).catch(err => console.error('Error initializing tabs:', err));
164-
// }
162+
}
165163
break;
166164
}
167165
});

0 commit comments

Comments
 (0)