|
21 | 21 |
|
22 | 22 | // Initialize based on component type
|
23 | 23 | switch (componentType) {
|
| 24 | + case 'accordion': |
| 25 | + // Check if the accordion function exists in the global scope |
| 26 | + if (typeof accordion === 'function') { |
| 27 | + accordion(); |
| 28 | + element.setAttribute('data-initialized', 'true'); |
| 29 | + } else { |
| 30 | + console.warn('Accordion component requires accordion function. Make sure accordion.min.js is loaded.'); |
| 31 | + } |
| 32 | + break; |
24 | 33 | case 'sidebar':
|
25 | 34 | if (typeof sidebarNav === 'function' && typeof sidebarMenu === 'function') {
|
26 | 35 | sidebarNav();
|
|
47 | 56 | console.warn('Multi Select component requires multiSelect function');
|
48 | 57 | }
|
49 | 58 | break;
|
| 59 | + case 'language-switcher': |
| 60 | + if (typeof langSwitch === 'function') { |
| 61 | + langSwitch(); |
| 62 | + element.setAttribute('data-initialized', 'true'); |
| 63 | + } else { |
| 64 | + console.warn('Language Switcher component requires langSwitch function'); |
| 65 | + } |
| 66 | + break; |
| 67 | + |
50 | 68 | case 'country-header':
|
51 |
| - if (typeof navigationInitialize === 'function' && |
52 |
| - typeof langSwitch === 'function') { |
| 69 | + if (typeof navigationInitialize === 'function') { |
| 70 | + navigationInitialize(); |
| 71 | + navigationOverFlow(); |
| 72 | + |
| 73 | + // Add edge detection for multi-level menus |
| 74 | + if (typeof navigationMultiLevelEdgeDetection === 'function') { |
| 75 | + navigationMultiLevelEdgeDetection(); |
| 76 | + } |
| 77 | + element.setAttribute('data-initialized', 'true'); |
| 78 | + } else { |
| 79 | + console.warn('Country Header requires navigationInitialize function'); |
| 80 | + } |
| 81 | + break; |
| 82 | + case 'country-site-header': |
| 83 | + // Initialize functions based on the documented approach for external users |
| 84 | + if (typeof navigationInitialize === 'function') { |
| 85 | + // Call navigationInitialize without locale parameter as shown in documentation |
53 | 86 | navigationInitialize();
|
54 | 87 |
|
55 |
| - // Initialize overflow if the element has overflow attribute |
56 |
| - if (element.hasAttribute('data-overflow') && |
57 |
| - element.getAttribute('data-overflow') === 'true') { |
58 |
| - if (typeof navigationOverFlow === 'function') { |
59 |
| - navigationOverFlow(); |
60 |
| - } else { |
61 |
| - console.warn('Country Header overflow requires navigationOverFlow function'); |
62 |
| - } |
| 88 | + // Call navigationOverFlow if needed |
| 89 | + if (typeof navigationOverFlow === 'function') { |
| 90 | + navigationOverFlow(); |
63 | 91 | }
|
64 | 92 |
|
65 |
| - // Initialize multi-level edge detection |
| 93 | + // Call navigationMultiLevelEdgeDetection |
66 | 94 | if (typeof navigationMultiLevelEdgeDetection === 'function') {
|
67 | 95 | navigationMultiLevelEdgeDetection();
|
68 |
| - } else { |
69 |
| - console.warn('Country Header multi-level edge detection requires navigationMultiLevelEdgeDetection function'); |
70 |
| - } |
71 |
| - |
72 |
| - // Initialize language switcher |
73 |
| - if (typeof langSwitch === 'function') { |
74 |
| - langSwitch(); |
75 |
| - console.log("inside langSwitch"); |
76 | 96 | }
|
77 | 97 |
|
78 | 98 | element.setAttribute('data-initialized', 'true');
|
79 | 99 | } else {
|
80 |
| - console.warn('Country Header component requires navigationInitialize and langSwitch functions'); |
| 100 | + console.warn('CountrySiteHeader component requires navigationInitialize function'); |
| 101 | + } |
| 102 | + break; |
| 103 | + case 'modal': |
| 104 | + // Initialize modal functionality |
| 105 | + if (typeof modal === 'function') { |
| 106 | + modal(); |
| 107 | + element.setAttribute('data-initialized', 'true'); |
| 108 | + } else { |
| 109 | + console.warn('Modal component requires modal function'); |
81 | 110 | }
|
82 | 111 | break;
|
83 | 112 | }
|
|
91 | 120 | initializeComponents();
|
92 | 121 | }
|
93 | 122 |
|
94 |
| - // Also run when the window loads (as a fallback) |
| 123 | + // Also run when the window loads (as a fallback) // wait until whole dom is loaded |
95 | 124 | window.addEventListener('load', function() {
|
96 | 125 | // Check for any components that weren't initialized yet
|
97 | 126 | const uninitializedComponents = document.querySelectorAll('[data-undpds-component]:not([data-initialized])');
|
|
0 commit comments