@modernman00/shared-js-lib 1.2.37 → 1.2.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CountryCode.js +24 -10
- package/config/version.php +1 -1
- package/package.json +1 -1
package/CountryCode.js
CHANGED
|
@@ -204,17 +204,31 @@ export const countryCodes = {
|
|
|
204
204
|
};
|
|
205
205
|
|
|
206
206
|
export const injectCountryCode = async (countryId, mobileId) => {
|
|
207
|
-
const
|
|
208
|
-
const
|
|
207
|
+
const MAX_RETRIES = 10;
|
|
208
|
+
const RETRY_INTERVAL = 100; // ms
|
|
209
209
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
210
|
+
const waitForElements = (retries = 0) => {
|
|
211
|
+
const countryEl = id(countryId);
|
|
212
|
+
const mobileEl = id(mobileId);
|
|
213
|
+
|
|
214
|
+
if (countryEl && mobileEl) {
|
|
215
|
+
countryEl.addEventListener('change', async (e) => {
|
|
216
|
+
const value = e.target.value;
|
|
217
|
+
mobileEl.value = (await countryCodes[value]) || '';
|
|
218
|
+
});
|
|
219
|
+
} else if (retries < MAX_RETRIES) {
|
|
220
|
+
setTimeout(() => waitForElements(retries + 1), RETRY_INTERVAL);
|
|
221
|
+
} else {
|
|
222
|
+
showError(`injectCountryCode failed: Missing element(s) — ${!countryEl ? countryId : ''} ${!mobileEl ? mobileId : ''}`);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
214
225
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
226
|
+
// Ensure DOM is ready
|
|
227
|
+
if (document.readyState === 'loading') {
|
|
228
|
+
document.addEventListener('DOMContentLoaded', () => waitForElements());
|
|
229
|
+
} else {
|
|
230
|
+
waitForElements();
|
|
231
|
+
}
|
|
219
232
|
};
|
|
220
233
|
|
|
234
|
+
|
package/config/version.php
CHANGED
package/package.json
CHANGED