intl-tel-input 25.10.11 → 25.11.0
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/README.md +62 -59
- package/angular/README.md +1 -1
- package/angular/build/IntlTelInput.js +671 -624
- package/angular/build/IntlTelInputWithUtils.js +674 -627
- package/angular/build/types/intl-tel-input.d.ts +17 -71
- package/angular/build/types/modules/core/ui.d.ts +44 -0
- package/angular/build/types/modules/format/formatting.d.ts +3 -3
- package/angular/build/types/modules/types/events.d.ts +8 -0
- package/angular/build/types/modules/types/public-api.d.ts +3 -0
- package/angular/build/types/modules/utils/dom.d.ts +5 -0
- package/build/css/intlTelInput.css +1 -13
- package/build/css/intlTelInput.min.css +1 -1
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput.d.ts +83 -74
- package/build/js/intlTelInput.js +759 -669
- package/build/js/intlTelInput.min.js +4 -4
- package/build/js/intlTelInputWithUtils.js +763 -673
- package/build/js/intlTelInputWithUtils.min.js +4 -4
- package/build/js/utils.js +4 -4
- package/package.json +2 -1
- package/react/README.md +1 -1
- package/react/build/IntlTelInput.cjs +758 -668
- package/react/build/IntlTelInput.d.ts +83 -74
- package/react/build/IntlTelInput.js +758 -668
- package/react/build/IntlTelInputWithUtils.cjs +762 -672
- package/react/build/IntlTelInputWithUtils.js +762 -672
- package/vue/README.md +1 -1
- package/vue/build/IntlTelInput.mjs +710 -600
- package/vue/build/IntlTelInputWithUtils.mjs +989 -879
|
@@ -2050,6 +2050,7 @@ var getNumeric = (s) => s.replace(/\D/g, "");
|
|
|
2050
2050
|
var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
|
|
2051
2051
|
|
|
2052
2052
|
// src/js/modules/utils/dom.ts
|
|
2053
|
+
var buildClassNames = (flags) => Object.keys(flags).filter((k) => Boolean(flags[k])).join(" ");
|
|
2053
2054
|
var createEl = (tagName, attrs, container) => {
|
|
2054
2055
|
const el = document.createElement(tagName);
|
|
2055
2056
|
if (attrs) {
|
|
@@ -2061,258 +2062,23 @@ var createEl = (tagName, attrs, container) => {
|
|
|
2061
2062
|
return el;
|
|
2062
2063
|
};
|
|
2063
2064
|
|
|
2064
|
-
// src/js/modules/
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
if (onlyCountries.length) {
|
|
2068
|
-
const lowerCaseOnlyCountries = onlyCountries.map((country) => country.toLowerCase());
|
|
2069
|
-
return data_default.filter((country) => lowerCaseOnlyCountries.includes(country.iso2));
|
|
2070
|
-
} else if (excludeCountries.length) {
|
|
2071
|
-
const lowerCaseExcludeCountries = excludeCountries.map((country) => country.toLowerCase());
|
|
2072
|
-
return data_default.filter((country) => !lowerCaseExcludeCountries.includes(country.iso2));
|
|
2073
|
-
}
|
|
2074
|
-
return data_default;
|
|
2075
|
-
}
|
|
2076
|
-
function translateCountryNames(countries, options) {
|
|
2077
|
-
for (const c of countries) {
|
|
2078
|
-
const iso2 = c.iso2.toLowerCase();
|
|
2079
|
-
if (options.i18n[iso2]) {
|
|
2080
|
-
c.name = options.i18n[iso2];
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
function processDialCodes(countries, options) {
|
|
2085
|
-
const dialCodes = /* @__PURE__ */ new Set();
|
|
2086
|
-
let dialCodeMaxLen = 0;
|
|
2087
|
-
const dialCodeToIso2Map = {};
|
|
2088
|
-
const _addToDialCodeMap = (iso2, dialCode, priority) => {
|
|
2089
|
-
if (!iso2 || !dialCode) {
|
|
2090
|
-
return;
|
|
2091
|
-
}
|
|
2092
|
-
if (dialCode.length > dialCodeMaxLen) {
|
|
2093
|
-
dialCodeMaxLen = dialCode.length;
|
|
2094
|
-
}
|
|
2095
|
-
if (!dialCodeToIso2Map.hasOwnProperty(dialCode)) {
|
|
2096
|
-
dialCodeToIso2Map[dialCode] = [];
|
|
2097
|
-
}
|
|
2098
|
-
const iso2List = dialCodeToIso2Map[dialCode];
|
|
2099
|
-
if (iso2List.includes(iso2)) {
|
|
2100
|
-
return;
|
|
2101
|
-
}
|
|
2102
|
-
const index = priority !== void 0 ? priority : iso2List.length;
|
|
2103
|
-
iso2List[index] = iso2;
|
|
2104
|
-
};
|
|
2105
|
-
for (const c of countries) {
|
|
2106
|
-
if (!dialCodes.has(c.dialCode)) {
|
|
2107
|
-
dialCodes.add(c.dialCode);
|
|
2108
|
-
}
|
|
2109
|
-
for (let k = 1; k < c.dialCode.length; k++) {
|
|
2110
|
-
const partialDialCode = c.dialCode.substring(0, k);
|
|
2111
|
-
_addToDialCodeMap(c.iso2, partialDialCode);
|
|
2112
|
-
}
|
|
2113
|
-
_addToDialCodeMap(c.iso2, c.dialCode, c.priority);
|
|
2114
|
-
}
|
|
2115
|
-
if (options.onlyCountries.length || options.excludeCountries.length) {
|
|
2116
|
-
dialCodes.forEach((dialCode) => {
|
|
2117
|
-
dialCodeToIso2Map[dialCode] = dialCodeToIso2Map[dialCode].filter(Boolean);
|
|
2118
|
-
});
|
|
2119
|
-
}
|
|
2120
|
-
for (const c of countries) {
|
|
2121
|
-
if (c.areaCodes) {
|
|
2122
|
-
const rootIso2Code = dialCodeToIso2Map[c.dialCode][0];
|
|
2123
|
-
for (const areaCode of c.areaCodes) {
|
|
2124
|
-
for (let k = 1; k < areaCode.length; k++) {
|
|
2125
|
-
const partialAreaCode = areaCode.substring(0, k);
|
|
2126
|
-
const partialDialCode = c.dialCode + partialAreaCode;
|
|
2127
|
-
_addToDialCodeMap(rootIso2Code, partialDialCode);
|
|
2128
|
-
_addToDialCodeMap(c.iso2, partialDialCode);
|
|
2129
|
-
}
|
|
2130
|
-
_addToDialCodeMap(c.iso2, c.dialCode + areaCode);
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
return { dialCodes, dialCodeMaxLen, dialCodeToIso2Map };
|
|
2135
|
-
}
|
|
2136
|
-
function sortCountries(countries, options) {
|
|
2137
|
-
if (options.countryOrder) {
|
|
2138
|
-
options.countryOrder = options.countryOrder.map((iso2) => iso2.toLowerCase());
|
|
2139
|
-
}
|
|
2140
|
-
countries.sort((a, b) => {
|
|
2141
|
-
const { countryOrder } = options;
|
|
2142
|
-
if (countryOrder) {
|
|
2143
|
-
const aIndex = countryOrder.indexOf(a.iso2);
|
|
2144
|
-
const bIndex = countryOrder.indexOf(b.iso2);
|
|
2145
|
-
const aIndexExists = aIndex > -1;
|
|
2146
|
-
const bIndexExists = bIndex > -1;
|
|
2147
|
-
if (aIndexExists || bIndexExists) {
|
|
2148
|
-
if (aIndexExists && bIndexExists) {
|
|
2149
|
-
return aIndex - bIndex;
|
|
2150
|
-
}
|
|
2151
|
-
return aIndexExists ? -1 : 1;
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
return a.name.localeCompare(b.name);
|
|
2155
|
-
});
|
|
2156
|
-
}
|
|
2157
|
-
function cacheSearchTokens(countries) {
|
|
2158
|
-
for (const c of countries) {
|
|
2159
|
-
c.normalisedName = normaliseString(c.name);
|
|
2160
|
-
c.initials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
|
|
2161
|
-
c.dialCodePlus = `+${c.dialCode}`;
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
|
|
2165
|
-
// src/js/modules/format/formatting.ts
|
|
2166
|
-
function beforeSetNumber(fullNumber, dialCode, separateDialCode, selectedCountryData) {
|
|
2167
|
-
let number = fullNumber;
|
|
2168
|
-
if (separateDialCode) {
|
|
2169
|
-
if (dialCode) {
|
|
2170
|
-
dialCode = `+${selectedCountryData.dialCode}`;
|
|
2171
|
-
const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
|
|
2172
|
-
number = number.substring(start);
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
return number;
|
|
2176
|
-
}
|
|
2177
|
-
function formatNumberAsYouType(fullNumber, telInputValue, utils, selectedCountryData, separateDialCode) {
|
|
2178
|
-
const result = utils ? utils.formatNumberAsYouType(fullNumber, selectedCountryData.iso2) : fullNumber;
|
|
2179
|
-
const { dialCode } = selectedCountryData;
|
|
2180
|
-
if (separateDialCode && telInputValue.charAt(0) !== "+" && result.includes(`+${dialCode}`)) {
|
|
2181
|
-
const afterDialCode = result.split(`+${dialCode}`)[1] || "";
|
|
2182
|
-
return afterDialCode.trim();
|
|
2183
|
-
}
|
|
2184
|
-
return result;
|
|
2185
|
-
}
|
|
2186
|
-
|
|
2187
|
-
// src/js/modules/format/caret.ts
|
|
2188
|
-
function translateCursorPosition(relevantChars, formattedValue, prevCaretPos, isDeleteForwards) {
|
|
2189
|
-
if (prevCaretPos === 0 && !isDeleteForwards) {
|
|
2190
|
-
return 0;
|
|
2191
|
-
}
|
|
2192
|
-
let relevantCharCount = 0;
|
|
2193
|
-
for (let i = 0; i < formattedValue.length; i++) {
|
|
2194
|
-
if (/[+0-9]/.test(formattedValue[i])) {
|
|
2195
|
-
relevantCharCount++;
|
|
2196
|
-
}
|
|
2197
|
-
if (relevantCharCount === relevantChars && !isDeleteForwards) {
|
|
2198
|
-
return i + 1;
|
|
2199
|
-
}
|
|
2200
|
-
if (isDeleteForwards && relevantCharCount === relevantChars + 1) {
|
|
2201
|
-
return i;
|
|
2202
|
-
}
|
|
2203
|
-
}
|
|
2204
|
-
return formattedValue.length;
|
|
2205
|
-
}
|
|
2206
|
-
|
|
2207
|
-
// src/js/modules/data/nanp-regionless.ts
|
|
2208
|
-
var regionlessNanpNumbers = [
|
|
2209
|
-
"800",
|
|
2210
|
-
"822",
|
|
2211
|
-
"833",
|
|
2212
|
-
"844",
|
|
2213
|
-
"855",
|
|
2214
|
-
"866",
|
|
2215
|
-
"877",
|
|
2216
|
-
"880",
|
|
2217
|
-
"881",
|
|
2218
|
-
"882",
|
|
2219
|
-
"883",
|
|
2220
|
-
"884",
|
|
2221
|
-
"885",
|
|
2222
|
-
"886",
|
|
2223
|
-
"887",
|
|
2224
|
-
"888",
|
|
2225
|
-
"889"
|
|
2226
|
-
];
|
|
2227
|
-
var isRegionlessNanp = (number) => {
|
|
2228
|
-
const numeric = getNumeric(number);
|
|
2229
|
-
if (numeric.charAt(0) === "1") {
|
|
2230
|
-
const areaCode = numeric.substring(1, 4);
|
|
2231
|
-
return regionlessNanpNumbers.includes(areaCode);
|
|
2232
|
-
}
|
|
2233
|
-
return false;
|
|
2234
|
-
};
|
|
2235
|
-
|
|
2236
|
-
// src/js/intl-tel-input.ts
|
|
2237
|
-
for (const c of data_default) {
|
|
2238
|
-
c.name = en_default[c.iso2];
|
|
2239
|
-
}
|
|
2240
|
-
var id = 0;
|
|
2241
|
-
var iso2Set = new Set(data_default.map((c) => c.iso2));
|
|
2242
|
-
var isIso2 = (val) => iso2Set.has(val);
|
|
2243
|
-
var forEachInstance = (method, ...args) => {
|
|
2244
|
-
const { instances } = intlTelInput;
|
|
2245
|
-
Object.values(instances).forEach((instance) => instance[method](...args));
|
|
2246
|
-
};
|
|
2247
|
-
var Iti = class _Iti {
|
|
2248
|
-
/**
|
|
2249
|
-
* Build a space-delimited class string from an object map of className -> truthy/falsey.
|
|
2250
|
-
* Only keys with truthy values are included.
|
|
2251
|
-
*/
|
|
2252
|
-
static _buildClassNames(flags) {
|
|
2253
|
-
return Object.keys(flags).filter((k) => Boolean(flags[k])).join(" ");
|
|
2254
|
-
}
|
|
2255
|
-
constructor(input, customOptions = {}) {
|
|
2256
|
-
this.id = id++;
|
|
2257
|
-
this.telInput = input;
|
|
2065
|
+
// src/js/modules/core/ui.ts
|
|
2066
|
+
var UI = class {
|
|
2067
|
+
constructor(input, options, id2) {
|
|
2258
2068
|
this.highlightedItem = null;
|
|
2259
|
-
|
|
2069
|
+
input.dataset.intlTelInputId = id2.toString();
|
|
2070
|
+
this.telInput = input;
|
|
2071
|
+
this.options = options;
|
|
2072
|
+
this.id = id2;
|
|
2260
2073
|
this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
|
|
2261
|
-
}
|
|
2262
|
-
_detectEnvironmentAndLayout() {
|
|
2263
|
-
this.isAndroid = typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
2264
2074
|
this.isRTL = !!this.telInput.closest("[dir=rtl]");
|
|
2265
|
-
this.telInput.dir = "ltr";
|
|
2266
|
-
const showOnDefaultSide = this.options.allowDropdown || this.options.separateDialCode;
|
|
2267
|
-
this.showSelectedCountryOnLeft = this.isRTL ? !showOnDefaultSide : showOnDefaultSide;
|
|
2268
2075
|
if (this.options.separateDialCode) {
|
|
2269
|
-
|
|
2270
|
-
this.originalPaddingRight = this.telInput.style.paddingRight;
|
|
2271
|
-
} else {
|
|
2272
|
-
this.originalPaddingLeft = this.telInput.style.paddingLeft;
|
|
2273
|
-
}
|
|
2076
|
+
this.originalPaddingLeft = this.telInput.style.paddingLeft;
|
|
2274
2077
|
}
|
|
2275
2078
|
}
|
|
2276
|
-
_createInitPromises() {
|
|
2277
|
-
const autoCountryPromise = new Promise((resolve, reject) => {
|
|
2278
|
-
this.resolveAutoCountryPromise = resolve;
|
|
2279
|
-
this.rejectAutoCountryPromise = reject;
|
|
2280
|
-
});
|
|
2281
|
-
const utilsScriptPromise = new Promise((resolve, reject) => {
|
|
2282
|
-
this.resolveUtilsScriptPromise = resolve;
|
|
2283
|
-
this.rejectUtilsScriptPromise = reject;
|
|
2284
|
-
});
|
|
2285
|
-
this.promise = Promise.all([autoCountryPromise, utilsScriptPromise]);
|
|
2286
|
-
}
|
|
2287
|
-
//* Can't be private as it's called from intlTelInput convenience wrapper.
|
|
2288
|
-
_init() {
|
|
2289
|
-
applyOptionSideEffects(this.options);
|
|
2290
|
-
this._detectEnvironmentAndLayout();
|
|
2291
|
-
this._createInitPromises();
|
|
2292
|
-
this.selectedCountryData = {};
|
|
2293
|
-
this._processCountryData();
|
|
2294
|
-
this._generateMarkup();
|
|
2295
|
-
this._setInitialState();
|
|
2296
|
-
this._initListeners();
|
|
2297
|
-
this._initRequests();
|
|
2298
|
-
}
|
|
2299
|
-
//********************
|
|
2300
|
-
//* PRIVATE METHODS
|
|
2301
|
-
//********************
|
|
2302
|
-
//* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
|
|
2303
|
-
_processCountryData() {
|
|
2304
|
-
this.countries = processAllCountries(this.options);
|
|
2305
|
-
const dialRes = processDialCodes(this.countries, this.options);
|
|
2306
|
-
this.dialCodes = dialRes.dialCodes;
|
|
2307
|
-
this.dialCodeMaxLen = dialRes.dialCodeMaxLen;
|
|
2308
|
-
this.dialCodeToIso2Map = dialRes.dialCodeToIso2Map;
|
|
2309
|
-
translateCountryNames(this.countries, this.options);
|
|
2310
|
-
sortCountries(this.countries, this.options);
|
|
2311
|
-
this.countryByIso2 = new Map(this.countries.map((c) => [c.iso2, c]));
|
|
2312
|
-
cacheSearchTokens(this.countries);
|
|
2313
|
-
}
|
|
2314
2079
|
//* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
|
|
2315
|
-
|
|
2080
|
+
generateMarkup(countries) {
|
|
2081
|
+
this.countries = countries;
|
|
2316
2082
|
this._prepareTelInput();
|
|
2317
2083
|
const wrapper = this._createWrapperAndInsert();
|
|
2318
2084
|
this._maybeBuildCountryContainer(wrapper);
|
|
@@ -2322,7 +2088,7 @@ var Iti = class _Iti {
|
|
|
2322
2088
|
}
|
|
2323
2089
|
_prepareTelInput() {
|
|
2324
2090
|
this.telInput.classList.add("iti__tel-input");
|
|
2325
|
-
if (!this.telInput.hasAttribute("autocomplete") && !
|
|
2091
|
+
if (!this.telInput.hasAttribute("autocomplete") && !this.telInput.form?.hasAttribute("autocomplete")) {
|
|
2326
2092
|
this.telInput.setAttribute("autocomplete", "off");
|
|
2327
2093
|
}
|
|
2328
2094
|
}
|
|
@@ -2333,23 +2099,22 @@ var Iti = class _Iti {
|
|
|
2333
2099
|
containerClass,
|
|
2334
2100
|
useFullscreenPopup
|
|
2335
2101
|
} = this.options;
|
|
2336
|
-
const parentClasses =
|
|
2337
|
-
|
|
2102
|
+
const parentClasses = buildClassNames({
|
|
2103
|
+
iti: true,
|
|
2338
2104
|
"iti--allow-dropdown": allowDropdown,
|
|
2339
2105
|
"iti--show-flags": showFlags,
|
|
2340
2106
|
"iti--inline-dropdown": !useFullscreenPopup,
|
|
2341
2107
|
[containerClass]: Boolean(containerClass)
|
|
2342
2108
|
});
|
|
2343
2109
|
const wrapper = createEl("div", { class: parentClasses });
|
|
2344
|
-
|
|
2110
|
+
if (this.isRTL) {
|
|
2111
|
+
wrapper.setAttribute("dir", "ltr");
|
|
2112
|
+
}
|
|
2113
|
+
this.telInput.before(wrapper);
|
|
2345
2114
|
return wrapper;
|
|
2346
2115
|
}
|
|
2347
2116
|
_maybeBuildCountryContainer(wrapper) {
|
|
2348
|
-
const {
|
|
2349
|
-
allowDropdown,
|
|
2350
|
-
separateDialCode,
|
|
2351
|
-
showFlags
|
|
2352
|
-
} = this.options;
|
|
2117
|
+
const { allowDropdown, separateDialCode, showFlags } = this.options;
|
|
2353
2118
|
if (allowDropdown || showFlags || separateDialCode) {
|
|
2354
2119
|
this.countryContainer = createEl(
|
|
2355
2120
|
"div",
|
|
@@ -2357,11 +2122,6 @@ var Iti = class _Iti {
|
|
|
2357
2122
|
{ class: "iti__country-container iti__v-hide" },
|
|
2358
2123
|
wrapper
|
|
2359
2124
|
);
|
|
2360
|
-
if (this.showSelectedCountryOnLeft) {
|
|
2361
|
-
this.countryContainer.style.left = "0px";
|
|
2362
|
-
} else {
|
|
2363
|
-
this.countryContainer.style.right = "0px";
|
|
2364
|
-
}
|
|
2365
2125
|
if (allowDropdown) {
|
|
2366
2126
|
this.selectedCountry = createEl(
|
|
2367
2127
|
"button",
|
|
@@ -2405,7 +2165,7 @@ var Iti = class _Iti {
|
|
|
2405
2165
|
if (separateDialCode) {
|
|
2406
2166
|
this.selectedDialCode = createEl(
|
|
2407
2167
|
"div",
|
|
2408
|
-
{ class: "iti__selected-dial-code"
|
|
2168
|
+
{ class: "iti__selected-dial-code" },
|
|
2409
2169
|
this.selectedCountry
|
|
2410
2170
|
);
|
|
2411
2171
|
}
|
|
@@ -2430,6 +2190,9 @@ var Iti = class _Iti {
|
|
|
2430
2190
|
role: "dialog",
|
|
2431
2191
|
"aria-modal": "true"
|
|
2432
2192
|
});
|
|
2193
|
+
if (this.isRTL) {
|
|
2194
|
+
this.dropdownContent.setAttribute("dir", "rtl");
|
|
2195
|
+
}
|
|
2433
2196
|
if (countrySearch) {
|
|
2434
2197
|
this._buildSearchUI();
|
|
2435
2198
|
}
|
|
@@ -2444,12 +2207,12 @@ var Iti = class _Iti {
|
|
|
2444
2207
|
this.dropdownContent
|
|
2445
2208
|
);
|
|
2446
2209
|
this._appendListItems();
|
|
2447
|
-
if (countrySearch) {
|
|
2448
|
-
this.
|
|
2210
|
+
if (this.options.countrySearch) {
|
|
2211
|
+
this.updateSearchResultsA11yText();
|
|
2449
2212
|
}
|
|
2450
2213
|
if (dropdownContainer) {
|
|
2451
|
-
const dropdownClasses =
|
|
2452
|
-
|
|
2214
|
+
const dropdownClasses = buildClassNames({
|
|
2215
|
+
iti: true,
|
|
2453
2216
|
"iti--container": true,
|
|
2454
2217
|
"iti--fullscreen-popup": useFullscreenPopup,
|
|
2455
2218
|
"iti--inline-dropdown": !useFullscreenPopup,
|
|
@@ -2495,7 +2258,7 @@ var Iti = class _Iti {
|
|
|
2495
2258
|
"aria-label": i18n.searchPlaceholder,
|
|
2496
2259
|
"aria-controls": `iti-${this.id}__country-listbox`,
|
|
2497
2260
|
"aria-autocomplete": "list",
|
|
2498
|
-
|
|
2261
|
+
autocomplete: "off"
|
|
2499
2262
|
},
|
|
2500
2263
|
searchWrapper
|
|
2501
2264
|
);
|
|
@@ -2532,80 +2295,478 @@ var Iti = class _Iti {
|
|
|
2532
2295
|
},
|
|
2533
2296
|
this.dropdownContent
|
|
2534
2297
|
);
|
|
2535
|
-
this.searchNoResults.textContent = i18n.zeroSearchResults;
|
|
2298
|
+
this.searchNoResults.textContent = i18n.zeroSearchResults;
|
|
2299
|
+
}
|
|
2300
|
+
_maybeUpdateInputPaddingAndReveal() {
|
|
2301
|
+
if (this.countryContainer) {
|
|
2302
|
+
this.updateInputPadding();
|
|
2303
|
+
this.countryContainer.classList.remove("iti__v-hide");
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
_maybeBuildHiddenInputs(wrapper) {
|
|
2307
|
+
const { hiddenInput } = this.options;
|
|
2308
|
+
if (hiddenInput) {
|
|
2309
|
+
const telInputName = this.telInput.getAttribute("name") || "";
|
|
2310
|
+
const names = hiddenInput(telInputName);
|
|
2311
|
+
if (names.phone) {
|
|
2312
|
+
const existingInput = this.telInput.form?.querySelector(
|
|
2313
|
+
`input[name="${names.phone}"]`
|
|
2314
|
+
);
|
|
2315
|
+
if (existingInput) {
|
|
2316
|
+
this.hiddenInput = existingInput;
|
|
2317
|
+
} else {
|
|
2318
|
+
this.hiddenInput = createEl("input", {
|
|
2319
|
+
type: "hidden",
|
|
2320
|
+
name: names.phone
|
|
2321
|
+
});
|
|
2322
|
+
wrapper.appendChild(this.hiddenInput);
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
if (names.country) {
|
|
2326
|
+
const existingInput = this.telInput.form?.querySelector(
|
|
2327
|
+
`input[name="${names.country}"]`
|
|
2328
|
+
);
|
|
2329
|
+
if (existingInput) {
|
|
2330
|
+
this.hiddenInputCountry = existingInput;
|
|
2331
|
+
} else {
|
|
2332
|
+
this.hiddenInputCountry = createEl("input", {
|
|
2333
|
+
type: "hidden",
|
|
2334
|
+
name: names.country
|
|
2335
|
+
});
|
|
2336
|
+
wrapper.appendChild(this.hiddenInputCountry);
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
//* For each country: add a country list item <li> to the countryList <ul> container.
|
|
2342
|
+
_appendListItems() {
|
|
2343
|
+
const frag = document.createDocumentFragment();
|
|
2344
|
+
for (let i = 0; i < this.countries.length; i++) {
|
|
2345
|
+
const c = this.countries[i];
|
|
2346
|
+
const liClass = buildClassNames({
|
|
2347
|
+
iti__country: true,
|
|
2348
|
+
iti__highlight: i === 0
|
|
2349
|
+
});
|
|
2350
|
+
const listItem = createEl("li", {
|
|
2351
|
+
id: `iti-${this.id}__item-${c.iso2}`,
|
|
2352
|
+
class: liClass,
|
|
2353
|
+
tabindex: "-1",
|
|
2354
|
+
role: "option",
|
|
2355
|
+
"aria-selected": "false"
|
|
2356
|
+
});
|
|
2357
|
+
listItem.dataset.dialCode = c.dialCode;
|
|
2358
|
+
listItem.dataset.countryCode = c.iso2;
|
|
2359
|
+
c.nodeById[this.id] = listItem;
|
|
2360
|
+
if (this.options.showFlags) {
|
|
2361
|
+
createEl("div", { class: `iti__flag iti__${c.iso2}` }, listItem);
|
|
2362
|
+
}
|
|
2363
|
+
const nameEl = createEl("span", { class: "iti__country-name" }, listItem);
|
|
2364
|
+
nameEl.textContent = c.name;
|
|
2365
|
+
const dialEl = createEl("span", { class: "iti__dial-code" }, listItem);
|
|
2366
|
+
if (this.isRTL) {
|
|
2367
|
+
dialEl.setAttribute("dir", "ltr");
|
|
2368
|
+
}
|
|
2369
|
+
dialEl.textContent = `+${c.dialCode}`;
|
|
2370
|
+
frag.appendChild(listItem);
|
|
2371
|
+
}
|
|
2372
|
+
this.countryList.appendChild(frag);
|
|
2373
|
+
}
|
|
2374
|
+
//* Update the input padding to make space for the selected country/dial code.
|
|
2375
|
+
updateInputPadding() {
|
|
2376
|
+
if (this.selectedCountry) {
|
|
2377
|
+
const saneDefaultWidth = this.options.separateDialCode ? 78 : 42;
|
|
2378
|
+
const selectedCountryWidth = this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth() || saneDefaultWidth;
|
|
2379
|
+
const inputPadding = selectedCountryWidth + 6;
|
|
2380
|
+
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
//* When input is in a hidden container during init, we cannot calculate the selected country width.
|
|
2384
|
+
//* Fix: clone the markup, make it invisible, add it to the end of the DOM, and then measure it's width.
|
|
2385
|
+
//* To get the right styling to apply, all we need is a shallow clone of the container,
|
|
2386
|
+
//* and then to inject a deep clone of the selectedCountry element.
|
|
2387
|
+
_getHiddenSelectedCountryWidth() {
|
|
2388
|
+
if (this.telInput.parentNode) {
|
|
2389
|
+
let body;
|
|
2390
|
+
try {
|
|
2391
|
+
body = window.top.document.body;
|
|
2392
|
+
} catch (e) {
|
|
2393
|
+
body = document.body;
|
|
2394
|
+
}
|
|
2395
|
+
const containerClone = this.telInput.parentNode.cloneNode(
|
|
2396
|
+
false
|
|
2397
|
+
);
|
|
2398
|
+
containerClone.style.visibility = "hidden";
|
|
2399
|
+
body.appendChild(containerClone);
|
|
2400
|
+
const countryContainerClone = this.countryContainer.cloneNode();
|
|
2401
|
+
containerClone.appendChild(countryContainerClone);
|
|
2402
|
+
const selectedCountryClone = this.selectedCountry.cloneNode(
|
|
2403
|
+
true
|
|
2404
|
+
);
|
|
2405
|
+
countryContainerClone.appendChild(selectedCountryClone);
|
|
2406
|
+
const width = selectedCountryClone.offsetWidth;
|
|
2407
|
+
body.removeChild(containerClone);
|
|
2408
|
+
return width;
|
|
2409
|
+
}
|
|
2410
|
+
return 0;
|
|
2411
|
+
}
|
|
2412
|
+
//* Update search results text (for a11y).
|
|
2413
|
+
updateSearchResultsA11yText() {
|
|
2414
|
+
const { i18n } = this.options;
|
|
2415
|
+
const count = this.countryList.childElementCount;
|
|
2416
|
+
let searchText;
|
|
2417
|
+
if (count === 0) {
|
|
2418
|
+
searchText = i18n.zeroSearchResults;
|
|
2419
|
+
} else {
|
|
2420
|
+
if (i18n.searchResultsText) {
|
|
2421
|
+
searchText = i18n.searchResultsText(count);
|
|
2422
|
+
} else if (count === 1) {
|
|
2423
|
+
searchText = i18n.oneSearchResult;
|
|
2424
|
+
} else {
|
|
2425
|
+
searchText = i18n.multipleSearchResults.replace(
|
|
2426
|
+
"${count}",
|
|
2427
|
+
count.toString()
|
|
2428
|
+
);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
this.searchResultsA11yText.textContent = searchText;
|
|
2432
|
+
}
|
|
2433
|
+
//* Check if an element is visible within it's container, else scroll until it is.
|
|
2434
|
+
scrollTo(element) {
|
|
2435
|
+
const container = this.countryList;
|
|
2436
|
+
const scrollTop = document.documentElement.scrollTop;
|
|
2437
|
+
const containerHeight = container.offsetHeight;
|
|
2438
|
+
const containerTop = container.getBoundingClientRect().top + scrollTop;
|
|
2439
|
+
const containerBottom = containerTop + containerHeight;
|
|
2440
|
+
const elementHeight = element.offsetHeight;
|
|
2441
|
+
const elementTop = element.getBoundingClientRect().top + scrollTop;
|
|
2442
|
+
const elementBottom = elementTop + elementHeight;
|
|
2443
|
+
const newScrollTop = elementTop - containerTop + container.scrollTop;
|
|
2444
|
+
if (elementTop < containerTop) {
|
|
2445
|
+
container.scrollTop = newScrollTop;
|
|
2446
|
+
} else if (elementBottom > containerBottom) {
|
|
2447
|
+
const heightDifference = containerHeight - elementHeight;
|
|
2448
|
+
container.scrollTop = newScrollTop - heightDifference;
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
//* Remove highlighting from other list items and highlight the given item.
|
|
2452
|
+
highlightListItem(listItem, shouldFocus) {
|
|
2453
|
+
const prevItem = this.highlightedItem;
|
|
2454
|
+
if (prevItem) {
|
|
2455
|
+
prevItem.classList.remove("iti__highlight");
|
|
2456
|
+
prevItem.setAttribute("aria-selected", "false");
|
|
2457
|
+
}
|
|
2458
|
+
this.highlightedItem = listItem;
|
|
2459
|
+
if (this.highlightedItem) {
|
|
2460
|
+
this.highlightedItem.classList.add("iti__highlight");
|
|
2461
|
+
this.highlightedItem.setAttribute("aria-selected", "true");
|
|
2462
|
+
if (this.options.countrySearch) {
|
|
2463
|
+
const activeDescendant = this.highlightedItem.getAttribute("id") || "";
|
|
2464
|
+
this.searchInput.setAttribute(
|
|
2465
|
+
"aria-activedescendant",
|
|
2466
|
+
activeDescendant
|
|
2467
|
+
);
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
if (shouldFocus) {
|
|
2471
|
+
this.highlightedItem.focus();
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
//* Country search: Filter the country list to the given array of countries.
|
|
2475
|
+
filterCountries(matchedCountries) {
|
|
2476
|
+
this.countryList.innerHTML = "";
|
|
2477
|
+
let noCountriesAddedYet = true;
|
|
2478
|
+
for (const c of matchedCountries) {
|
|
2479
|
+
const listItem = c.nodeById[this.id];
|
|
2480
|
+
if (listItem) {
|
|
2481
|
+
this.countryList.appendChild(listItem);
|
|
2482
|
+
if (noCountriesAddedYet) {
|
|
2483
|
+
this.highlightListItem(listItem, false);
|
|
2484
|
+
noCountriesAddedYet = false;
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
if (noCountriesAddedYet) {
|
|
2489
|
+
this.highlightListItem(null, false);
|
|
2490
|
+
if (this.searchNoResults) {
|
|
2491
|
+
this.searchNoResults.classList.remove("iti__hide");
|
|
2492
|
+
}
|
|
2493
|
+
} else if (this.searchNoResults) {
|
|
2494
|
+
this.searchNoResults.classList.add("iti__hide");
|
|
2495
|
+
}
|
|
2496
|
+
this.countryList.scrollTop = 0;
|
|
2497
|
+
this.updateSearchResultsA11yText();
|
|
2498
|
+
}
|
|
2499
|
+
destroy() {
|
|
2500
|
+
this.telInput.iti = void 0;
|
|
2501
|
+
delete this.telInput.dataset.intlTelInputId;
|
|
2502
|
+
if (this.options.separateDialCode) {
|
|
2503
|
+
this.telInput.style.paddingLeft = this.originalPaddingLeft;
|
|
2504
|
+
}
|
|
2505
|
+
const wrapper = this.telInput.parentNode;
|
|
2506
|
+
wrapper.before(this.telInput);
|
|
2507
|
+
wrapper.remove();
|
|
2508
|
+
this.telInput = null;
|
|
2509
|
+
this.countryContainer = null;
|
|
2510
|
+
this.selectedCountry = null;
|
|
2511
|
+
this.selectedCountryInner = null;
|
|
2512
|
+
this.selectedDialCode = null;
|
|
2513
|
+
this.dropdownArrow = null;
|
|
2514
|
+
this.dropdownContent = null;
|
|
2515
|
+
this.searchInput = null;
|
|
2516
|
+
this.searchIcon = null;
|
|
2517
|
+
this.searchClearButton = null;
|
|
2518
|
+
this.searchNoResults = null;
|
|
2519
|
+
this.searchResultsA11yText = null;
|
|
2520
|
+
this.countryList = null;
|
|
2521
|
+
this.dropdown = null;
|
|
2522
|
+
this.hiddenInput = null;
|
|
2523
|
+
this.hiddenInputCountry = null;
|
|
2524
|
+
this.highlightedItem = null;
|
|
2525
|
+
for (const c of this.countries) {
|
|
2526
|
+
delete c.nodeById[this.id];
|
|
2527
|
+
}
|
|
2528
|
+
this.countries = null;
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
|
|
2532
|
+
// src/js/modules/data/country-data.ts
|
|
2533
|
+
function processAllCountries(options) {
|
|
2534
|
+
const { onlyCountries, excludeCountries } = options;
|
|
2535
|
+
if (onlyCountries.length) {
|
|
2536
|
+
const lowerCaseOnlyCountries = onlyCountries.map((country) => country.toLowerCase());
|
|
2537
|
+
return data_default.filter((country) => lowerCaseOnlyCountries.includes(country.iso2));
|
|
2538
|
+
} else if (excludeCountries.length) {
|
|
2539
|
+
const lowerCaseExcludeCountries = excludeCountries.map((country) => country.toLowerCase());
|
|
2540
|
+
return data_default.filter((country) => !lowerCaseExcludeCountries.includes(country.iso2));
|
|
2541
|
+
}
|
|
2542
|
+
return data_default;
|
|
2543
|
+
}
|
|
2544
|
+
function translateCountryNames(countries, options) {
|
|
2545
|
+
for (const c of countries) {
|
|
2546
|
+
const iso2 = c.iso2.toLowerCase();
|
|
2547
|
+
if (options.i18n[iso2]) {
|
|
2548
|
+
c.name = options.i18n[iso2];
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
function processDialCodes(countries, options) {
|
|
2553
|
+
const dialCodes = /* @__PURE__ */ new Set();
|
|
2554
|
+
let dialCodeMaxLen = 0;
|
|
2555
|
+
const dialCodeToIso2Map = {};
|
|
2556
|
+
const _addToDialCodeMap = (iso2, dialCode, priority) => {
|
|
2557
|
+
if (!iso2 || !dialCode) {
|
|
2558
|
+
return;
|
|
2559
|
+
}
|
|
2560
|
+
if (dialCode.length > dialCodeMaxLen) {
|
|
2561
|
+
dialCodeMaxLen = dialCode.length;
|
|
2562
|
+
}
|
|
2563
|
+
if (!dialCodeToIso2Map.hasOwnProperty(dialCode)) {
|
|
2564
|
+
dialCodeToIso2Map[dialCode] = [];
|
|
2565
|
+
}
|
|
2566
|
+
const iso2List = dialCodeToIso2Map[dialCode];
|
|
2567
|
+
if (iso2List.includes(iso2)) {
|
|
2568
|
+
return;
|
|
2569
|
+
}
|
|
2570
|
+
const index = priority !== void 0 ? priority : iso2List.length;
|
|
2571
|
+
iso2List[index] = iso2;
|
|
2572
|
+
};
|
|
2573
|
+
for (const c of countries) {
|
|
2574
|
+
if (!dialCodes.has(c.dialCode)) {
|
|
2575
|
+
dialCodes.add(c.dialCode);
|
|
2576
|
+
}
|
|
2577
|
+
for (let k = 1; k < c.dialCode.length; k++) {
|
|
2578
|
+
const partialDialCode = c.dialCode.substring(0, k);
|
|
2579
|
+
_addToDialCodeMap(c.iso2, partialDialCode);
|
|
2580
|
+
}
|
|
2581
|
+
_addToDialCodeMap(c.iso2, c.dialCode, c.priority);
|
|
2582
|
+
}
|
|
2583
|
+
if (options.onlyCountries.length || options.excludeCountries.length) {
|
|
2584
|
+
dialCodes.forEach((dialCode) => {
|
|
2585
|
+
dialCodeToIso2Map[dialCode] = dialCodeToIso2Map[dialCode].filter(Boolean);
|
|
2586
|
+
});
|
|
2587
|
+
}
|
|
2588
|
+
for (const c of countries) {
|
|
2589
|
+
if (c.areaCodes) {
|
|
2590
|
+
const rootIso2Code = dialCodeToIso2Map[c.dialCode][0];
|
|
2591
|
+
for (const areaCode of c.areaCodes) {
|
|
2592
|
+
for (let k = 1; k < areaCode.length; k++) {
|
|
2593
|
+
const partialAreaCode = areaCode.substring(0, k);
|
|
2594
|
+
const partialDialCode = c.dialCode + partialAreaCode;
|
|
2595
|
+
_addToDialCodeMap(rootIso2Code, partialDialCode);
|
|
2596
|
+
_addToDialCodeMap(c.iso2, partialDialCode);
|
|
2597
|
+
}
|
|
2598
|
+
_addToDialCodeMap(c.iso2, c.dialCode + areaCode);
|
|
2599
|
+
}
|
|
2600
|
+
}
|
|
2601
|
+
}
|
|
2602
|
+
return { dialCodes, dialCodeMaxLen, dialCodeToIso2Map };
|
|
2603
|
+
}
|
|
2604
|
+
function sortCountries(countries, options) {
|
|
2605
|
+
if (options.countryOrder) {
|
|
2606
|
+
options.countryOrder = options.countryOrder.map((iso2) => iso2.toLowerCase());
|
|
2607
|
+
}
|
|
2608
|
+
countries.sort((a, b) => {
|
|
2609
|
+
const { countryOrder } = options;
|
|
2610
|
+
if (countryOrder) {
|
|
2611
|
+
const aIndex = countryOrder.indexOf(a.iso2);
|
|
2612
|
+
const bIndex = countryOrder.indexOf(b.iso2);
|
|
2613
|
+
const aIndexExists = aIndex > -1;
|
|
2614
|
+
const bIndexExists = bIndex > -1;
|
|
2615
|
+
if (aIndexExists || bIndexExists) {
|
|
2616
|
+
if (aIndexExists && bIndexExists) {
|
|
2617
|
+
return aIndex - bIndex;
|
|
2618
|
+
}
|
|
2619
|
+
return aIndexExists ? -1 : 1;
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
return a.name.localeCompare(b.name);
|
|
2623
|
+
});
|
|
2624
|
+
}
|
|
2625
|
+
function cacheSearchTokens(countries) {
|
|
2626
|
+
for (const c of countries) {
|
|
2627
|
+
c.normalisedName = normaliseString(c.name);
|
|
2628
|
+
c.initials = c.name.split(/[^a-zA-ZÀ-ÿа-яА-Я]/).map((word) => word[0]).join("").toLowerCase();
|
|
2629
|
+
c.dialCodePlus = `+${c.dialCode}`;
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
// src/js/modules/format/formatting.ts
|
|
2634
|
+
function beforeSetNumber(fullNumber, dialCode, separateDialCode, selectedCountryData) {
|
|
2635
|
+
let number = fullNumber;
|
|
2636
|
+
if (separateDialCode) {
|
|
2637
|
+
if (dialCode) {
|
|
2638
|
+
dialCode = `+${selectedCountryData.dialCode}`;
|
|
2639
|
+
const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
|
|
2640
|
+
number = number.substring(start);
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
return number;
|
|
2644
|
+
}
|
|
2645
|
+
function formatNumberAsYouType(fullNumber, telInputValue, utils, selectedCountryData, separateDialCode) {
|
|
2646
|
+
const result = utils ? utils.formatNumberAsYouType(fullNumber, selectedCountryData.iso2) : fullNumber;
|
|
2647
|
+
const { dialCode } = selectedCountryData;
|
|
2648
|
+
if (separateDialCode && telInputValue.charAt(0) !== "+" && result.includes(`+${dialCode}`)) {
|
|
2649
|
+
const afterDialCode = result.split(`+${dialCode}`)[1] || "";
|
|
2650
|
+
return afterDialCode.trim();
|
|
2651
|
+
}
|
|
2652
|
+
return result;
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2655
|
+
// src/js/modules/format/caret.ts
|
|
2656
|
+
function translateCursorPosition(relevantChars, formattedValue, prevCaretPos, isDeleteForwards) {
|
|
2657
|
+
if (prevCaretPos === 0 && !isDeleteForwards) {
|
|
2658
|
+
return 0;
|
|
2659
|
+
}
|
|
2660
|
+
let relevantCharCount = 0;
|
|
2661
|
+
for (let i = 0; i < formattedValue.length; i++) {
|
|
2662
|
+
if (/[+0-9]/.test(formattedValue[i])) {
|
|
2663
|
+
relevantCharCount++;
|
|
2664
|
+
}
|
|
2665
|
+
if (relevantCharCount === relevantChars && !isDeleteForwards) {
|
|
2666
|
+
return i + 1;
|
|
2667
|
+
}
|
|
2668
|
+
if (isDeleteForwards && relevantCharCount === relevantChars + 1) {
|
|
2669
|
+
return i;
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
return formattedValue.length;
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
// src/js/modules/data/nanp-regionless.ts
|
|
2676
|
+
var regionlessNanpNumbers = [
|
|
2677
|
+
"800",
|
|
2678
|
+
"822",
|
|
2679
|
+
"833",
|
|
2680
|
+
"844",
|
|
2681
|
+
"855",
|
|
2682
|
+
"866",
|
|
2683
|
+
"877",
|
|
2684
|
+
"880",
|
|
2685
|
+
"881",
|
|
2686
|
+
"882",
|
|
2687
|
+
"883",
|
|
2688
|
+
"884",
|
|
2689
|
+
"885",
|
|
2690
|
+
"886",
|
|
2691
|
+
"887",
|
|
2692
|
+
"888",
|
|
2693
|
+
"889"
|
|
2694
|
+
];
|
|
2695
|
+
var isRegionlessNanp = (number) => {
|
|
2696
|
+
const numeric = getNumeric(number);
|
|
2697
|
+
if (numeric.charAt(0) === "1") {
|
|
2698
|
+
const areaCode = numeric.substring(1, 4);
|
|
2699
|
+
return regionlessNanpNumbers.includes(areaCode);
|
|
2700
|
+
}
|
|
2701
|
+
return false;
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
// src/js/intl-tel-input.ts
|
|
2705
|
+
for (const c of data_default) {
|
|
2706
|
+
c.name = countries_default[c.iso2];
|
|
2707
|
+
}
|
|
2708
|
+
var id = 0;
|
|
2709
|
+
var iso2Set = new Set(data_default.map((c) => c.iso2));
|
|
2710
|
+
var isIso2 = (val) => iso2Set.has(val);
|
|
2711
|
+
var Iti = class _Iti {
|
|
2712
|
+
constructor(input, customOptions = {}) {
|
|
2713
|
+
this.id = id++;
|
|
2714
|
+
this.options = { ...defaults, ...customOptions };
|
|
2715
|
+
applyOptionSideEffects(this.options);
|
|
2716
|
+
this.ui = new UI(input, this.options, this.id);
|
|
2717
|
+
this.isAndroid = _Iti._getIsAndroid();
|
|
2718
|
+
this.promise = this._createInitPromises();
|
|
2719
|
+
this.countries = processAllCountries(this.options);
|
|
2720
|
+
const { dialCodes, dialCodeMaxLen, dialCodeToIso2Map } = processDialCodes(
|
|
2721
|
+
this.countries,
|
|
2722
|
+
this.options
|
|
2723
|
+
);
|
|
2724
|
+
this.dialCodes = dialCodes;
|
|
2725
|
+
this.dialCodeMaxLen = dialCodeMaxLen;
|
|
2726
|
+
this.dialCodeToIso2Map = dialCodeToIso2Map;
|
|
2727
|
+
this.countryByIso2 = new Map(this.countries.map((c) => [c.iso2, c]));
|
|
2728
|
+
this._init();
|
|
2536
2729
|
}
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
this._updateInputPadding();
|
|
2540
|
-
this.countryContainer.classList.remove("iti__v-hide");
|
|
2541
|
-
}
|
|
2730
|
+
static _getIsAndroid() {
|
|
2731
|
+
return typeof navigator !== "undefined" ? /Android/i.test(navigator.userAgent) : false;
|
|
2542
2732
|
}
|
|
2543
|
-
|
|
2544
|
-
const
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
this.hiddenInput = createEl("input", {
|
|
2554
|
-
type: "hidden",
|
|
2555
|
-
name: names.phone
|
|
2556
|
-
});
|
|
2557
|
-
wrapper.appendChild(this.hiddenInput);
|
|
2558
|
-
}
|
|
2559
|
-
}
|
|
2560
|
-
if (names.country) {
|
|
2561
|
-
const existingInput = this.telInput.form?.querySelector(`input[name="${names.country}"]`);
|
|
2562
|
-
if (existingInput) {
|
|
2563
|
-
this.hiddenInputCountry = existingInput;
|
|
2564
|
-
} else {
|
|
2565
|
-
this.hiddenInputCountry = createEl("input", {
|
|
2566
|
-
type: "hidden",
|
|
2567
|
-
name: names.country
|
|
2568
|
-
});
|
|
2569
|
-
wrapper.appendChild(this.hiddenInputCountry);
|
|
2570
|
-
}
|
|
2571
|
-
}
|
|
2572
|
-
}
|
|
2733
|
+
_createInitPromises() {
|
|
2734
|
+
const autoCountryPromise = new Promise((resolve, reject) => {
|
|
2735
|
+
this.resolveAutoCountryPromise = resolve;
|
|
2736
|
+
this.rejectAutoCountryPromise = reject;
|
|
2737
|
+
});
|
|
2738
|
+
const utilsScriptPromise = new Promise((resolve, reject) => {
|
|
2739
|
+
this.resolveUtilsScriptPromise = resolve;
|
|
2740
|
+
this.rejectUtilsScriptPromise = reject;
|
|
2741
|
+
});
|
|
2742
|
+
return Promise.all([autoCountryPromise, utilsScriptPromise]);
|
|
2573
2743
|
}
|
|
2574
|
-
//*
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
c.nodeById[this.id] = listItem;
|
|
2593
|
-
let content = "";
|
|
2594
|
-
if (this.options.showFlags) {
|
|
2595
|
-
content += `<div class='iti__flag iti__${c.iso2}'></div>`;
|
|
2596
|
-
}
|
|
2597
|
-
content += `<span class='iti__country-name'>${c.name}</span>`;
|
|
2598
|
-
content += `<span class='iti__dial-code' dir='ltr'>+${c.dialCode}</span>`;
|
|
2599
|
-
listItem.insertAdjacentHTML("beforeend", content);
|
|
2600
|
-
}
|
|
2744
|
+
//* Can't be private as it's called from intlTelInput convenience wrapper.
|
|
2745
|
+
_init() {
|
|
2746
|
+
this.selectedCountryData = {};
|
|
2747
|
+
this.abortController = new AbortController();
|
|
2748
|
+
this._processCountryData();
|
|
2749
|
+
this.ui.generateMarkup(this.countries);
|
|
2750
|
+
this._setInitialState();
|
|
2751
|
+
this._initListeners();
|
|
2752
|
+
this._initRequests();
|
|
2753
|
+
}
|
|
2754
|
+
//********************
|
|
2755
|
+
//* PRIVATE METHODS
|
|
2756
|
+
//********************
|
|
2757
|
+
//* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
|
|
2758
|
+
_processCountryData() {
|
|
2759
|
+
translateCountryNames(this.countries, this.options);
|
|
2760
|
+
sortCountries(this.countries, this.options);
|
|
2761
|
+
cacheSearchTokens(this.countries);
|
|
2601
2762
|
}
|
|
2602
2763
|
//* Set the initial state of the input value and the selected country by:
|
|
2603
2764
|
//* 1. Extracting a dial code from the given number
|
|
2604
2765
|
//* 2. Using explicit initialCountry
|
|
2605
2766
|
_setInitialState(overrideAutoCountry = false) {
|
|
2606
|
-
const attributeValue = this.telInput.getAttribute("value");
|
|
2607
|
-
const inputValue = this.telInput.value;
|
|
2608
|
-
const useAttribute = attributeValue && attributeValue.
|
|
2767
|
+
const attributeValue = this.ui.telInput.getAttribute("value");
|
|
2768
|
+
const inputValue = this.ui.telInput.value;
|
|
2769
|
+
const useAttribute = attributeValue && attributeValue.startsWith("+") && (!inputValue || !inputValue.startsWith("+"));
|
|
2609
2770
|
const val = useAttribute ? attributeValue : inputValue;
|
|
2610
2771
|
const dialCode = this._getDialCode(val);
|
|
2611
2772
|
const isRegionlessNanpNumber = isRegionlessNanp(val);
|
|
@@ -2635,47 +2796,49 @@ var Iti = class _Iti {
|
|
|
2635
2796
|
if (this.options.allowDropdown) {
|
|
2636
2797
|
this._initDropdownListeners();
|
|
2637
2798
|
}
|
|
2638
|
-
if ((this.hiddenInput || this.hiddenInputCountry) && this.telInput.form) {
|
|
2799
|
+
if ((this.ui.hiddenInput || this.ui.hiddenInputCountry) && this.ui.telInput.form) {
|
|
2639
2800
|
this._initHiddenInputListener();
|
|
2640
2801
|
}
|
|
2641
2802
|
}
|
|
2642
2803
|
//* Update hidden input on form submit.
|
|
2643
2804
|
_initHiddenInputListener() {
|
|
2644
|
-
|
|
2645
|
-
if (this.hiddenInput) {
|
|
2646
|
-
this.hiddenInput.value = this.getNumber();
|
|
2805
|
+
const handleHiddenInputSubmit = () => {
|
|
2806
|
+
if (this.ui.hiddenInput) {
|
|
2807
|
+
this.ui.hiddenInput.value = this.getNumber();
|
|
2647
2808
|
}
|
|
2648
|
-
if (this.hiddenInputCountry) {
|
|
2649
|
-
this.hiddenInputCountry.value = this.
|
|
2809
|
+
if (this.ui.hiddenInputCountry) {
|
|
2810
|
+
this.ui.hiddenInputCountry.value = this.selectedCountryData.iso2 || "";
|
|
2650
2811
|
}
|
|
2651
2812
|
};
|
|
2652
|
-
this.telInput.form?.addEventListener(
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
);
|
|
2813
|
+
this.ui.telInput.form?.addEventListener("submit", handleHiddenInputSubmit, {
|
|
2814
|
+
signal: this.abortController.signal
|
|
2815
|
+
});
|
|
2656
2816
|
}
|
|
2657
2817
|
//* initialise the dropdown listeners.
|
|
2658
2818
|
_initDropdownListeners() {
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2819
|
+
const signal = this.abortController.signal;
|
|
2820
|
+
const handleLabelClick = (e) => {
|
|
2821
|
+
if (this.ui.dropdownContent.classList.contains("iti__hide")) {
|
|
2822
|
+
this.ui.telInput.focus();
|
|
2662
2823
|
} else {
|
|
2663
2824
|
e.preventDefault();
|
|
2664
2825
|
}
|
|
2665
2826
|
};
|
|
2666
|
-
const label = this.telInput.closest("label");
|
|
2827
|
+
const label = this.ui.telInput.closest("label");
|
|
2667
2828
|
if (label) {
|
|
2668
|
-
label.addEventListener("click",
|
|
2829
|
+
label.addEventListener("click", handleLabelClick, { signal });
|
|
2669
2830
|
}
|
|
2670
|
-
|
|
2671
|
-
const dropdownClosed = this.dropdownContent.classList.contains("iti__hide");
|
|
2672
|
-
if (dropdownClosed && !this.telInput.disabled && !this.telInput.readOnly) {
|
|
2831
|
+
const handleClickSelectedCountry = () => {
|
|
2832
|
+
const dropdownClosed = this.ui.dropdownContent.classList.contains("iti__hide");
|
|
2833
|
+
if (dropdownClosed && !this.ui.telInput.disabled && !this.ui.telInput.readOnly) {
|
|
2673
2834
|
this._openDropdown();
|
|
2674
2835
|
}
|
|
2675
2836
|
};
|
|
2676
|
-
this.selectedCountry.addEventListener("click",
|
|
2677
|
-
|
|
2678
|
-
|
|
2837
|
+
this.ui.selectedCountry.addEventListener("click", handleClickSelectedCountry, {
|
|
2838
|
+
signal
|
|
2839
|
+
});
|
|
2840
|
+
const handleCountryContainerKeydown = (e) => {
|
|
2841
|
+
const isDropdownHidden = this.ui.dropdownContent.classList.contains("iti__hide");
|
|
2679
2842
|
if (isDropdownHidden && ["ArrowUp", "ArrowDown", " ", "Enter"].includes(e.key)) {
|
|
2680
2843
|
e.preventDefault();
|
|
2681
2844
|
e.stopPropagation();
|
|
@@ -2685,26 +2848,29 @@ var Iti = class _Iti {
|
|
|
2685
2848
|
this._closeDropdown();
|
|
2686
2849
|
}
|
|
2687
2850
|
};
|
|
2688
|
-
this.countryContainer.addEventListener(
|
|
2851
|
+
this.ui.countryContainer.addEventListener(
|
|
2689
2852
|
"keydown",
|
|
2690
|
-
|
|
2853
|
+
handleCountryContainerKeydown,
|
|
2854
|
+
{ signal }
|
|
2691
2855
|
);
|
|
2692
2856
|
}
|
|
2693
2857
|
//* Init many requests: utils script / geo ip lookup.
|
|
2694
2858
|
_initRequests() {
|
|
2695
|
-
|
|
2859
|
+
const { loadUtils, initialCountry, geoIpLookup } = this.options;
|
|
2696
2860
|
if (loadUtils && !intlTelInput.utils) {
|
|
2697
|
-
|
|
2861
|
+
const doAttachUtils = () => {
|
|
2698
2862
|
intlTelInput.attachUtils(loadUtils)?.catch(() => {
|
|
2699
2863
|
});
|
|
2700
2864
|
};
|
|
2701
2865
|
if (intlTelInput.documentReady()) {
|
|
2702
|
-
|
|
2866
|
+
doAttachUtils();
|
|
2703
2867
|
} else {
|
|
2704
|
-
|
|
2705
|
-
|
|
2868
|
+
const handlePageLoad = () => {
|
|
2869
|
+
doAttachUtils();
|
|
2706
2870
|
};
|
|
2707
|
-
window.addEventListener("load",
|
|
2871
|
+
window.addEventListener("load", handlePageLoad, {
|
|
2872
|
+
signal: this.abortController.signal
|
|
2873
|
+
});
|
|
2708
2874
|
}
|
|
2709
2875
|
} else {
|
|
2710
2876
|
this.resolveUtilsScriptPromise();
|
|
@@ -2744,8 +2910,8 @@ var Iti = class _Iti {
|
|
|
2744
2910
|
}
|
|
2745
2911
|
_openDropdownWithPlus() {
|
|
2746
2912
|
this._openDropdown();
|
|
2747
|
-
this.searchInput.value = "+";
|
|
2748
|
-
this.
|
|
2913
|
+
this.ui.searchInput.value = "+";
|
|
2914
|
+
this._filterCountriesByQuery("");
|
|
2749
2915
|
}
|
|
2750
2916
|
//* Initialize the tel input listeners.
|
|
2751
2917
|
_initTelInputListeners() {
|
|
@@ -2754,55 +2920,77 @@ var Iti = class _Iti {
|
|
|
2754
2920
|
this._maybeBindPasteListener();
|
|
2755
2921
|
}
|
|
2756
2922
|
_bindInputListener() {
|
|
2757
|
-
const {
|
|
2923
|
+
const {
|
|
2924
|
+
strictMode,
|
|
2925
|
+
formatAsYouType,
|
|
2926
|
+
separateDialCode,
|
|
2927
|
+
allowDropdown,
|
|
2928
|
+
countrySearch
|
|
2929
|
+
} = this.options;
|
|
2758
2930
|
let userOverrideFormatting = false;
|
|
2759
|
-
if (/\p{L}/u.test(this.telInput.value)) {
|
|
2931
|
+
if (/\p{L}/u.test(this.ui.telInput.value)) {
|
|
2760
2932
|
userOverrideFormatting = true;
|
|
2761
2933
|
}
|
|
2762
|
-
|
|
2934
|
+
const handleInputEvent = (e) => {
|
|
2763
2935
|
if (this.isAndroid && e?.data === "+" && separateDialCode && allowDropdown && countrySearch) {
|
|
2764
|
-
const currentCaretPos = this.telInput.selectionStart || 0;
|
|
2765
|
-
const valueBeforeCaret = this.telInput.value.substring(
|
|
2766
|
-
|
|
2767
|
-
|
|
2936
|
+
const currentCaretPos = this.ui.telInput.selectionStart || 0;
|
|
2937
|
+
const valueBeforeCaret = this.ui.telInput.value.substring(
|
|
2938
|
+
0,
|
|
2939
|
+
currentCaretPos - 1
|
|
2940
|
+
);
|
|
2941
|
+
const valueAfterCaret = this.ui.telInput.value.substring(currentCaretPos);
|
|
2942
|
+
this.ui.telInput.value = valueBeforeCaret + valueAfterCaret;
|
|
2768
2943
|
this._openDropdownWithPlus();
|
|
2769
2944
|
return;
|
|
2770
2945
|
}
|
|
2771
|
-
if (this._updateCountryFromNumber(this.telInput.value)) {
|
|
2946
|
+
if (this._updateCountryFromNumber(this.ui.telInput.value)) {
|
|
2772
2947
|
this._triggerCountryChange();
|
|
2773
2948
|
}
|
|
2774
2949
|
const isFormattingChar = e?.data && /[^+0-9]/.test(e.data);
|
|
2775
|
-
const isPaste = e?.inputType === "insertFromPaste" && this.telInput.value;
|
|
2950
|
+
const isPaste = e?.inputType === "insertFromPaste" && this.ui.telInput.value;
|
|
2776
2951
|
if (isFormattingChar || isPaste && !strictMode) {
|
|
2777
2952
|
userOverrideFormatting = true;
|
|
2778
|
-
} else if (!/[^+0-9]/.test(this.telInput.value)) {
|
|
2953
|
+
} else if (!/[^+0-9]/.test(this.ui.telInput.value)) {
|
|
2779
2954
|
userOverrideFormatting = false;
|
|
2780
2955
|
}
|
|
2781
2956
|
const isSetNumber = e?.detail && e.detail["isSetNumber"];
|
|
2782
2957
|
if (formatAsYouType && !userOverrideFormatting && !isSetNumber) {
|
|
2783
|
-
const currentCaretPos = this.telInput.selectionStart || 0;
|
|
2784
|
-
const valueBeforeCaret = this.telInput.value.substring(
|
|
2785
|
-
|
|
2958
|
+
const currentCaretPos = this.ui.telInput.selectionStart || 0;
|
|
2959
|
+
const valueBeforeCaret = this.ui.telInput.value.substring(
|
|
2960
|
+
0,
|
|
2961
|
+
currentCaretPos
|
|
2962
|
+
);
|
|
2963
|
+
const relevantCharsBeforeCaret = valueBeforeCaret.replace(
|
|
2964
|
+
/[^+0-9]/g,
|
|
2965
|
+
""
|
|
2966
|
+
).length;
|
|
2786
2967
|
const isDeleteForwards = e?.inputType === "deleteContentForward";
|
|
2787
2968
|
const fullNumber = this._getFullNumber();
|
|
2788
2969
|
const formattedValue = formatNumberAsYouType(
|
|
2789
2970
|
fullNumber,
|
|
2790
|
-
this.telInput.value,
|
|
2971
|
+
this.ui.telInput.value,
|
|
2791
2972
|
intlTelInput.utils,
|
|
2792
2973
|
this.selectedCountryData,
|
|
2793
2974
|
this.options.separateDialCode
|
|
2794
2975
|
);
|
|
2795
|
-
const newCaretPos = translateCursorPosition(
|
|
2796
|
-
|
|
2797
|
-
|
|
2976
|
+
const newCaretPos = translateCursorPosition(
|
|
2977
|
+
relevantCharsBeforeCaret,
|
|
2978
|
+
formattedValue,
|
|
2979
|
+
currentCaretPos,
|
|
2980
|
+
isDeleteForwards
|
|
2981
|
+
);
|
|
2982
|
+
this.ui.telInput.value = formattedValue;
|
|
2983
|
+
this.ui.telInput.setSelectionRange(newCaretPos, newCaretPos);
|
|
2798
2984
|
}
|
|
2799
2985
|
};
|
|
2800
|
-
this.telInput.addEventListener("input",
|
|
2986
|
+
this.ui.telInput.addEventListener("input", handleInputEvent, {
|
|
2987
|
+
signal: this.abortController.signal
|
|
2988
|
+
});
|
|
2801
2989
|
}
|
|
2802
2990
|
_maybeBindKeydownListener() {
|
|
2803
2991
|
const { strictMode, separateDialCode, allowDropdown, countrySearch } = this.options;
|
|
2804
2992
|
if (strictMode || separateDialCode) {
|
|
2805
|
-
|
|
2993
|
+
const handleKeydownEvent = (e) => {
|
|
2806
2994
|
if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
2807
2995
|
if (separateDialCode && allowDropdown && countrySearch && e.key === "+") {
|
|
2808
2996
|
e.preventDefault();
|
|
@@ -2810,14 +2998,17 @@ var Iti = class _Iti {
|
|
|
2810
2998
|
return;
|
|
2811
2999
|
}
|
|
2812
3000
|
if (strictMode) {
|
|
2813
|
-
const value = this.telInput.value;
|
|
2814
|
-
const alreadyHasPlus = value.
|
|
2815
|
-
const isInitialPlus = !alreadyHasPlus && this.telInput.selectionStart === 0 && e.key === "+";
|
|
3001
|
+
const value = this.ui.telInput.value;
|
|
3002
|
+
const alreadyHasPlus = value.startsWith("+");
|
|
3003
|
+
const isInitialPlus = !alreadyHasPlus && this.ui.telInput.selectionStart === 0 && e.key === "+";
|
|
2816
3004
|
const isNumeric = /^[0-9]$/.test(e.key);
|
|
2817
3005
|
const isAllowedChar = separateDialCode ? isNumeric : isInitialPlus || isNumeric;
|
|
2818
|
-
const newValue = value.slice(0, this.telInput.selectionStart) + e.key + value.slice(this.telInput.selectionEnd);
|
|
3006
|
+
const newValue = value.slice(0, this.ui.telInput.selectionStart) + e.key + value.slice(this.ui.telInput.selectionEnd);
|
|
2819
3007
|
const newFullNumber = this._getFullNumber(newValue);
|
|
2820
|
-
const coreNumber = intlTelInput.utils.getCoreNumber(
|
|
3008
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(
|
|
3009
|
+
newFullNumber,
|
|
3010
|
+
this.selectedCountryData.iso2
|
|
3011
|
+
);
|
|
2821
3012
|
const hasExceededMaxLength = this.maxCoreNumberLength && coreNumber.length > this.maxCoreNumberLength;
|
|
2822
3013
|
const newCountry = this._getNewCountryFromNumber(newFullNumber);
|
|
2823
3014
|
const isChangingDialCode = newCountry !== null;
|
|
@@ -2827,14 +3018,16 @@ var Iti = class _Iti {
|
|
|
2827
3018
|
}
|
|
2828
3019
|
}
|
|
2829
3020
|
};
|
|
2830
|
-
this.telInput.addEventListener("keydown",
|
|
3021
|
+
this.ui.telInput.addEventListener("keydown", handleKeydownEvent, {
|
|
3022
|
+
signal: this.abortController.signal
|
|
3023
|
+
});
|
|
2831
3024
|
}
|
|
2832
3025
|
}
|
|
2833
3026
|
_maybeBindPasteListener() {
|
|
2834
3027
|
if (this.options.strictMode) {
|
|
2835
|
-
|
|
3028
|
+
const handlePasteEvent = (e) => {
|
|
2836
3029
|
e.preventDefault();
|
|
2837
|
-
const input = this.telInput;
|
|
3030
|
+
const input = this.ui.telInput;
|
|
2838
3031
|
const selStart = input.selectionStart;
|
|
2839
3032
|
const selEnd = input.selectionEnd;
|
|
2840
3033
|
const before = input.value.slice(0, selStart);
|
|
@@ -2869,82 +3062,95 @@ var Iti = class _Iti {
|
|
|
2869
3062
|
input.setSelectionRange(caretPos, caretPos);
|
|
2870
3063
|
input.dispatchEvent(new InputEvent("input", { bubbles: true }));
|
|
2871
3064
|
};
|
|
2872
|
-
this.telInput.addEventListener("paste",
|
|
3065
|
+
this.ui.telInput.addEventListener("paste", handlePasteEvent, {
|
|
3066
|
+
signal: this.abortController.signal
|
|
3067
|
+
});
|
|
2873
3068
|
}
|
|
2874
3069
|
}
|
|
2875
3070
|
//* Adhere to the input's maxlength attr.
|
|
2876
3071
|
_cap(number) {
|
|
2877
|
-
const max =
|
|
3072
|
+
const max = Number(this.ui.telInput.getAttribute("maxlength"));
|
|
2878
3073
|
return max && number.length > max ? number.substring(0, max) : number;
|
|
2879
3074
|
}
|
|
2880
|
-
//* Trigger a custom event on the input.
|
|
3075
|
+
//* Trigger a custom event on the input (typed via ItiEventMap).
|
|
2881
3076
|
_trigger(name, detailProps = {}) {
|
|
2882
3077
|
const e = new CustomEvent(name, {
|
|
2883
3078
|
bubbles: true,
|
|
2884
3079
|
cancelable: true,
|
|
2885
3080
|
detail: detailProps
|
|
2886
3081
|
});
|
|
2887
|
-
this.telInput.dispatchEvent(e);
|
|
3082
|
+
this.ui.telInput.dispatchEvent(e);
|
|
2888
3083
|
}
|
|
2889
3084
|
//* Open the dropdown.
|
|
2890
3085
|
_openDropdown() {
|
|
2891
3086
|
const { fixDropdownWidth, countrySearch } = this.options;
|
|
3087
|
+
this.dropdownAbortController = new AbortController();
|
|
2892
3088
|
if (fixDropdownWidth) {
|
|
2893
|
-
this.dropdownContent.style.width = `${this.telInput.offsetWidth}px`;
|
|
3089
|
+
this.ui.dropdownContent.style.width = `${this.ui.telInput.offsetWidth}px`;
|
|
2894
3090
|
}
|
|
2895
|
-
this.dropdownContent.classList.remove("iti__hide");
|
|
2896
|
-
this.selectedCountry.setAttribute("aria-expanded", "true");
|
|
3091
|
+
this.ui.dropdownContent.classList.remove("iti__hide");
|
|
3092
|
+
this.ui.selectedCountry.setAttribute("aria-expanded", "true");
|
|
2897
3093
|
this._setDropdownPosition();
|
|
2898
3094
|
if (countrySearch) {
|
|
2899
|
-
const firstCountryItem = this.countryList.firstElementChild;
|
|
3095
|
+
const firstCountryItem = this.ui.countryList.firstElementChild;
|
|
2900
3096
|
if (firstCountryItem) {
|
|
2901
|
-
this.
|
|
2902
|
-
this.countryList.scrollTop = 0;
|
|
3097
|
+
this.ui.highlightListItem(firstCountryItem, false);
|
|
3098
|
+
this.ui.countryList.scrollTop = 0;
|
|
2903
3099
|
}
|
|
2904
|
-
this.searchInput.focus();
|
|
3100
|
+
this.ui.searchInput.focus();
|
|
2905
3101
|
}
|
|
2906
3102
|
this._bindDropdownListeners();
|
|
2907
|
-
this.dropdownArrow.classList.add("iti__arrow--up");
|
|
3103
|
+
this.ui.dropdownArrow.classList.add("iti__arrow--up");
|
|
2908
3104
|
this._trigger("open:countrydropdown");
|
|
2909
3105
|
}
|
|
2910
3106
|
//* Set the dropdown position
|
|
2911
3107
|
_setDropdownPosition() {
|
|
2912
3108
|
if (this.options.dropdownContainer) {
|
|
2913
|
-
this.options.dropdownContainer.appendChild(this.dropdown);
|
|
3109
|
+
this.options.dropdownContainer.appendChild(this.ui.dropdown);
|
|
2914
3110
|
}
|
|
2915
3111
|
if (!this.options.useFullscreenPopup) {
|
|
2916
|
-
const inputPosRelativeToVP = this.telInput.getBoundingClientRect();
|
|
2917
|
-
const inputHeight = this.telInput.offsetHeight;
|
|
3112
|
+
const inputPosRelativeToVP = this.ui.telInput.getBoundingClientRect();
|
|
3113
|
+
const inputHeight = this.ui.telInput.offsetHeight;
|
|
2918
3114
|
if (this.options.dropdownContainer) {
|
|
2919
|
-
this.dropdown.style.top = `${inputPosRelativeToVP.top + inputHeight}px`;
|
|
2920
|
-
this.dropdown.style.left = `${inputPosRelativeToVP.left}px`;
|
|
2921
|
-
|
|
2922
|
-
window.addEventListener("scroll",
|
|
3115
|
+
this.ui.dropdown.style.top = `${inputPosRelativeToVP.top + inputHeight}px`;
|
|
3116
|
+
this.ui.dropdown.style.left = `${inputPosRelativeToVP.left}px`;
|
|
3117
|
+
const handleWindowScroll = () => this._closeDropdown();
|
|
3118
|
+
window.addEventListener("scroll", handleWindowScroll, {
|
|
3119
|
+
signal: this.dropdownAbortController.signal
|
|
3120
|
+
});
|
|
2923
3121
|
}
|
|
2924
3122
|
}
|
|
2925
3123
|
}
|
|
2926
3124
|
//* We only bind dropdown listeners when the dropdown is open.
|
|
2927
3125
|
_bindDropdownListeners() {
|
|
2928
|
-
|
|
2929
|
-
|
|
3126
|
+
const signal = this.dropdownAbortController.signal;
|
|
3127
|
+
const handleMouseoverCountryList = (e) => {
|
|
3128
|
+
const listItem = e.target?.closest(
|
|
3129
|
+
".iti__country"
|
|
3130
|
+
);
|
|
2930
3131
|
if (listItem) {
|
|
2931
|
-
this.
|
|
3132
|
+
this.ui.highlightListItem(listItem, false);
|
|
2932
3133
|
}
|
|
2933
3134
|
};
|
|
2934
|
-
this.countryList.addEventListener(
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
)
|
|
2938
|
-
|
|
2939
|
-
|
|
3135
|
+
this.ui.countryList.addEventListener("mouseover", handleMouseoverCountryList, {
|
|
3136
|
+
signal
|
|
3137
|
+
});
|
|
3138
|
+
const handleClickCountryList = (e) => {
|
|
3139
|
+
const listItem = e.target?.closest(
|
|
3140
|
+
".iti__country"
|
|
3141
|
+
);
|
|
2940
3142
|
if (listItem) {
|
|
2941
3143
|
this._selectListItem(listItem);
|
|
2942
3144
|
}
|
|
2943
3145
|
};
|
|
2944
|
-
this.countryList.addEventListener("click",
|
|
2945
|
-
|
|
3146
|
+
this.ui.countryList.addEventListener("click", handleClickCountryList, {
|
|
3147
|
+
signal
|
|
3148
|
+
});
|
|
3149
|
+
const handleClickOffToClose = (e) => {
|
|
2946
3150
|
const target = e.target;
|
|
2947
|
-
const clickedInsideDropdown = !!target.closest(
|
|
3151
|
+
const clickedInsideDropdown = !!target.closest(
|
|
3152
|
+
`#iti-${this.id}__dropdown-content`
|
|
3153
|
+
);
|
|
2948
3154
|
if (!clickedInsideDropdown) {
|
|
2949
3155
|
this._closeDropdown();
|
|
2950
3156
|
}
|
|
@@ -2952,12 +3158,13 @@ var Iti = class _Iti {
|
|
|
2952
3158
|
setTimeout(() => {
|
|
2953
3159
|
document.documentElement.addEventListener(
|
|
2954
3160
|
"click",
|
|
2955
|
-
|
|
3161
|
+
handleClickOffToClose,
|
|
3162
|
+
{ signal }
|
|
2956
3163
|
);
|
|
2957
3164
|
}, 0);
|
|
2958
3165
|
let query = "";
|
|
2959
3166
|
let queryTimer = null;
|
|
2960
|
-
|
|
3167
|
+
const handleKeydownOnDropdown = (e) => {
|
|
2961
3168
|
if (["ArrowUp", "ArrowDown", "Enter", "Escape"].includes(e.key)) {
|
|
2962
3169
|
e.preventDefault();
|
|
2963
3170
|
e.stopPropagation();
|
|
@@ -2981,19 +3188,19 @@ var Iti = class _Iti {
|
|
|
2981
3188
|
}, 1e3);
|
|
2982
3189
|
}
|
|
2983
3190
|
};
|
|
2984
|
-
document.addEventListener("keydown",
|
|
3191
|
+
document.addEventListener("keydown", handleKeydownOnDropdown, { signal });
|
|
2985
3192
|
if (this.options.countrySearch) {
|
|
2986
3193
|
const doFilter = () => {
|
|
2987
|
-
const inputQuery = this.searchInput.value.trim();
|
|
2988
|
-
this.
|
|
2989
|
-
if (this.searchInput.value) {
|
|
2990
|
-
this.searchClearButton.classList.remove("iti__hide");
|
|
3194
|
+
const inputQuery = this.ui.searchInput.value.trim();
|
|
3195
|
+
this._filterCountriesByQuery(inputQuery);
|
|
3196
|
+
if (this.ui.searchInput.value) {
|
|
3197
|
+
this.ui.searchClearButton.classList.remove("iti__hide");
|
|
2991
3198
|
} else {
|
|
2992
|
-
this.searchClearButton.classList.add("iti__hide");
|
|
3199
|
+
this.ui.searchClearButton.classList.add("iti__hide");
|
|
2993
3200
|
}
|
|
2994
3201
|
};
|
|
2995
3202
|
let keyupTimer = null;
|
|
2996
|
-
|
|
3203
|
+
const handleSearchChange = () => {
|
|
2997
3204
|
if (keyupTimer) {
|
|
2998
3205
|
clearTimeout(keyupTimer);
|
|
2999
3206
|
}
|
|
@@ -3002,13 +3209,17 @@ var Iti = class _Iti {
|
|
|
3002
3209
|
keyupTimer = null;
|
|
3003
3210
|
}, 100);
|
|
3004
3211
|
};
|
|
3005
|
-
this.searchInput.addEventListener("input",
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3212
|
+
this.ui.searchInput.addEventListener("input", handleSearchChange, {
|
|
3213
|
+
signal
|
|
3214
|
+
});
|
|
3215
|
+
const handleSearchClear = () => {
|
|
3216
|
+
this.ui.searchInput.value = "";
|
|
3217
|
+
this.ui.searchInput.focus();
|
|
3009
3218
|
doFilter();
|
|
3010
3219
|
};
|
|
3011
|
-
this.searchClearButton.addEventListener("click",
|
|
3220
|
+
this.ui.searchClearButton.addEventListener("click", handleSearchClear, {
|
|
3221
|
+
signal
|
|
3222
|
+
});
|
|
3012
3223
|
}
|
|
3013
3224
|
}
|
|
3014
3225
|
//* Hidden search (countrySearch disabled): Find the first list item whose name starts with the query string.
|
|
@@ -3017,42 +3228,21 @@ var Iti = class _Iti {
|
|
|
3017
3228
|
const startsWith = c.name.substring(0, query.length).toLowerCase() === query;
|
|
3018
3229
|
if (startsWith) {
|
|
3019
3230
|
const listItem = c.nodeById[this.id];
|
|
3020
|
-
this.
|
|
3021
|
-
this.
|
|
3231
|
+
this.ui.highlightListItem(listItem, false);
|
|
3232
|
+
this.ui.scrollTo(listItem);
|
|
3022
3233
|
break;
|
|
3023
3234
|
}
|
|
3024
3235
|
}
|
|
3025
3236
|
}
|
|
3026
|
-
//* Country search
|
|
3027
|
-
|
|
3028
|
-
this.countryList.innerHTML = "";
|
|
3237
|
+
//* Country search: Filter the countries according to the search query.
|
|
3238
|
+
_filterCountriesByQuery(query) {
|
|
3029
3239
|
let matchedCountries;
|
|
3030
3240
|
if (query === "") {
|
|
3031
3241
|
matchedCountries = this.countries;
|
|
3032
3242
|
} else {
|
|
3033
3243
|
matchedCountries = this._getMatchedCountries(query);
|
|
3034
3244
|
}
|
|
3035
|
-
|
|
3036
|
-
for (const c of matchedCountries) {
|
|
3037
|
-
const listItem = c.nodeById[this.id];
|
|
3038
|
-
if (listItem) {
|
|
3039
|
-
this.countryList.appendChild(listItem);
|
|
3040
|
-
if (noCountriesAddedYet) {
|
|
3041
|
-
this._highlightListItem(listItem, false);
|
|
3042
|
-
noCountriesAddedYet = false;
|
|
3043
|
-
}
|
|
3044
|
-
}
|
|
3045
|
-
}
|
|
3046
|
-
if (noCountriesAddedYet) {
|
|
3047
|
-
this._highlightListItem(null, false);
|
|
3048
|
-
if (this.searchNoResults) {
|
|
3049
|
-
this.searchNoResults.classList.remove("iti__hide");
|
|
3050
|
-
}
|
|
3051
|
-
} else if (this.searchNoResults) {
|
|
3052
|
-
this.searchNoResults.classList.add("iti__hide");
|
|
3053
|
-
}
|
|
3054
|
-
this.countryList.scrollTop = 0;
|
|
3055
|
-
this._updateSearchResultsA11yText();
|
|
3245
|
+
this.ui.filterCountries(matchedCountries);
|
|
3056
3246
|
}
|
|
3057
3247
|
_getMatchedCountries(query) {
|
|
3058
3248
|
const normalisedQuery = normaliseString(query);
|
|
@@ -3086,39 +3276,21 @@ var Iti = class _Iti {
|
|
|
3086
3276
|
...initialsMatches.sort((a, b) => a.priority - b.priority)
|
|
3087
3277
|
];
|
|
3088
3278
|
}
|
|
3089
|
-
//* Update search results text (for a11y).
|
|
3090
|
-
_updateSearchResultsA11yText() {
|
|
3091
|
-
const { i18n } = this.options;
|
|
3092
|
-
const count = this.countryList.childElementCount;
|
|
3093
|
-
let searchText;
|
|
3094
|
-
if (count === 0) {
|
|
3095
|
-
searchText = i18n.zeroSearchResults;
|
|
3096
|
-
} else {
|
|
3097
|
-
if (i18n.searchResultsText) {
|
|
3098
|
-
searchText = i18n.searchResultsText(count);
|
|
3099
|
-
} else if (count === 1) {
|
|
3100
|
-
searchText = i18n.oneSearchResult;
|
|
3101
|
-
} else {
|
|
3102
|
-
searchText = i18n.multipleSearchResults.replace("${count}", count.toString());
|
|
3103
|
-
}
|
|
3104
|
-
}
|
|
3105
|
-
this.searchResultsA11yText.textContent = searchText;
|
|
3106
|
-
}
|
|
3107
3279
|
//* Highlight the next/prev item in the list (and ensure it is visible).
|
|
3108
3280
|
_handleUpDownKey(key) {
|
|
3109
|
-
let next = key === "ArrowUp" ? this.highlightedItem?.previousElementSibling : this.highlightedItem?.nextElementSibling;
|
|
3110
|
-
if (!next && this.countryList.childElementCount > 1) {
|
|
3111
|
-
next = key === "ArrowUp" ? this.countryList.lastElementChild : this.countryList.firstElementChild;
|
|
3281
|
+
let next = key === "ArrowUp" ? this.ui.highlightedItem?.previousElementSibling : this.ui.highlightedItem?.nextElementSibling;
|
|
3282
|
+
if (!next && this.ui.countryList.childElementCount > 1) {
|
|
3283
|
+
next = key === "ArrowUp" ? this.ui.countryList.lastElementChild : this.ui.countryList.firstElementChild;
|
|
3112
3284
|
}
|
|
3113
3285
|
if (next) {
|
|
3114
|
-
this.
|
|
3115
|
-
this.
|
|
3286
|
+
this.ui.scrollTo(next);
|
|
3287
|
+
this.ui.highlightListItem(next, false);
|
|
3116
3288
|
}
|
|
3117
3289
|
}
|
|
3118
3290
|
//* Select the currently highlighted item.
|
|
3119
3291
|
_handleEnterKey() {
|
|
3120
|
-
if (this.highlightedItem) {
|
|
3121
|
-
this._selectListItem(this.highlightedItem);
|
|
3292
|
+
if (this.ui.highlightedItem) {
|
|
3293
|
+
this._selectListItem(this.ui.highlightedItem);
|
|
3122
3294
|
}
|
|
3123
3295
|
}
|
|
3124
3296
|
//* Update the input's value to the given val (format first if possible)
|
|
@@ -3126,7 +3298,7 @@ var Iti = class _Iti {
|
|
|
3126
3298
|
_updateValFromNumber(fullNumber) {
|
|
3127
3299
|
let number = fullNumber;
|
|
3128
3300
|
if (this.options.formatOnDisplay && intlTelInput.utils && this.selectedCountryData) {
|
|
3129
|
-
const useNational = this.options.nationalMode || number.
|
|
3301
|
+
const useNational = this.options.nationalMode || !number.startsWith("+") && !this.options.separateDialCode;
|
|
3130
3302
|
const { NATIONAL, INTERNATIONAL } = intlTelInput.utils.numberFormat;
|
|
3131
3303
|
const format = useNational ? NATIONAL : INTERNATIONAL;
|
|
3132
3304
|
number = intlTelInput.utils.formatNumber(
|
|
@@ -3136,7 +3308,7 @@ var Iti = class _Iti {
|
|
|
3136
3308
|
);
|
|
3137
3309
|
}
|
|
3138
3310
|
number = this._beforeSetNumber(number);
|
|
3139
|
-
this.telInput.value = number;
|
|
3311
|
+
this.ui.telInput.value = number;
|
|
3140
3312
|
}
|
|
3141
3313
|
//* Check if need to select a new country based on the given number
|
|
3142
3314
|
//* Note: called from _setInitialState, keyup handler, setNumber.
|
|
@@ -3150,11 +3322,11 @@ var Iti = class _Iti {
|
|
|
3150
3322
|
// if there is a selected country, and the number doesn't start with a dial code, then add it
|
|
3151
3323
|
_ensureHasDialCode(number) {
|
|
3152
3324
|
const { dialCode, nationalPrefix } = this.selectedCountryData;
|
|
3153
|
-
const alreadyHasPlus = number.
|
|
3325
|
+
const alreadyHasPlus = number.startsWith("+");
|
|
3154
3326
|
if (alreadyHasPlus || !dialCode) {
|
|
3155
3327
|
return number;
|
|
3156
3328
|
}
|
|
3157
|
-
const hasPrefix = nationalPrefix && number.
|
|
3329
|
+
const hasPrefix = nationalPrefix && number.startsWith(nationalPrefix) && !this.options.separateDialCode;
|
|
3158
3330
|
const cleanNumber = hasPrefix ? number.substring(1) : number;
|
|
3159
3331
|
return `+${dialCode}${cleanNumber}`;
|
|
3160
3332
|
}
|
|
@@ -3187,7 +3359,9 @@ var Iti = class _Iti {
|
|
|
3187
3359
|
}
|
|
3188
3360
|
const { areaCodes, priority } = this.selectedCountryData;
|
|
3189
3361
|
if (areaCodes) {
|
|
3190
|
-
const dialCodeAreaCodes = areaCodes.map(
|
|
3362
|
+
const dialCodeAreaCodes = areaCodes.map(
|
|
3363
|
+
(areaCode) => `${selectedDialCode}${areaCode}`
|
|
3364
|
+
);
|
|
3191
3365
|
for (const dialCodeAreaCode of dialCodeAreaCodes) {
|
|
3192
3366
|
if (numeric.startsWith(dialCodeAreaCode)) {
|
|
3193
3367
|
return null;
|
|
@@ -3201,33 +3375,13 @@ var Iti = class _Iti {
|
|
|
3201
3375
|
if (!isValidSelection && !alreadySelected) {
|
|
3202
3376
|
return iso2Codes[0];
|
|
3203
3377
|
}
|
|
3204
|
-
} else if (number.
|
|
3378
|
+
} else if (number.startsWith("+") && numeric.length) {
|
|
3205
3379
|
return "";
|
|
3206
3380
|
} else if ((!number || number === "+") && !selectedIso2) {
|
|
3207
3381
|
return this.defaultCountry;
|
|
3208
3382
|
}
|
|
3209
3383
|
return null;
|
|
3210
3384
|
}
|
|
3211
|
-
//* Remove highlighting from other list items and highlight the given item.
|
|
3212
|
-
_highlightListItem(listItem, shouldFocus) {
|
|
3213
|
-
const prevItem = this.highlightedItem;
|
|
3214
|
-
if (prevItem) {
|
|
3215
|
-
prevItem.classList.remove("iti__highlight");
|
|
3216
|
-
prevItem.setAttribute("aria-selected", "false");
|
|
3217
|
-
}
|
|
3218
|
-
this.highlightedItem = listItem;
|
|
3219
|
-
if (this.highlightedItem) {
|
|
3220
|
-
this.highlightedItem.classList.add("iti__highlight");
|
|
3221
|
-
this.highlightedItem.setAttribute("aria-selected", "true");
|
|
3222
|
-
if (this.options.countrySearch) {
|
|
3223
|
-
const activeDescendant = this.highlightedItem.getAttribute("id") || "";
|
|
3224
|
-
this.searchInput.setAttribute("aria-activedescendant", activeDescendant);
|
|
3225
|
-
}
|
|
3226
|
-
}
|
|
3227
|
-
if (shouldFocus) {
|
|
3228
|
-
this.highlightedItem.focus();
|
|
3229
|
-
}
|
|
3230
|
-
}
|
|
3231
3385
|
//* Update the selected country, dial code (if separateDialCode), placeholder, title, and active list item.
|
|
3232
3386
|
//* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
|
|
3233
3387
|
_setCountry(iso2) {
|
|
@@ -3237,7 +3391,7 @@ var Iti = class _Iti {
|
|
|
3237
3391
|
if (this.selectedCountryData.iso2) {
|
|
3238
3392
|
this.defaultCountry = this.selectedCountryData.iso2;
|
|
3239
3393
|
}
|
|
3240
|
-
if (this.selectedCountry) {
|
|
3394
|
+
if (this.ui.selectedCountry) {
|
|
3241
3395
|
const flagClass = iso2 && showFlags ? `iti__flag iti__${iso2}` : "iti__flag iti__globe";
|
|
3242
3396
|
let ariaLabel, title;
|
|
3243
3397
|
if (iso2) {
|
|
@@ -3248,32 +3402,19 @@ var Iti = class _Iti {
|
|
|
3248
3402
|
title = i18n.noCountrySelected;
|
|
3249
3403
|
ariaLabel = i18n.noCountrySelected;
|
|
3250
3404
|
}
|
|
3251
|
-
this.selectedCountryInner.className = flagClass;
|
|
3252
|
-
this.selectedCountry.setAttribute("title", title);
|
|
3253
|
-
this.selectedCountry.setAttribute("aria-label", ariaLabel);
|
|
3405
|
+
this.ui.selectedCountryInner.className = flagClass;
|
|
3406
|
+
this.ui.selectedCountry.setAttribute("title", title);
|
|
3407
|
+
this.ui.selectedCountry.setAttribute("aria-label", ariaLabel);
|
|
3254
3408
|
}
|
|
3255
3409
|
if (separateDialCode) {
|
|
3256
3410
|
const dialCode = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
3257
|
-
this.selectedDialCode.
|
|
3258
|
-
this.
|
|
3411
|
+
this.ui.selectedDialCode.textContent = dialCode;
|
|
3412
|
+
this.ui.updateInputPadding();
|
|
3259
3413
|
}
|
|
3260
3414
|
this._updatePlaceholder();
|
|
3261
3415
|
this._updateMaxLength();
|
|
3262
3416
|
return prevIso2 !== iso2;
|
|
3263
3417
|
}
|
|
3264
|
-
//* Update the input padding to make space for the selected country/dial code.
|
|
3265
|
-
_updateInputPadding() {
|
|
3266
|
-
if (this.selectedCountry) {
|
|
3267
|
-
const saneDefaultWidth = this.options.separateDialCode ? 78 : 42;
|
|
3268
|
-
const selectedCountryWidth = this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth() || saneDefaultWidth;
|
|
3269
|
-
const inputPadding = selectedCountryWidth + 6;
|
|
3270
|
-
if (this.showSelectedCountryOnLeft) {
|
|
3271
|
-
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
3272
|
-
} else {
|
|
3273
|
-
this.telInput.style.paddingRight = `${inputPadding}px`;
|
|
3274
|
-
}
|
|
3275
|
-
}
|
|
3276
|
-
}
|
|
3277
3418
|
//* Update the maximum valid number length for the currently selected country.
|
|
3278
3419
|
_updateMaxLength() {
|
|
3279
3420
|
const { strictMode, placeholderNumberType, validationNumberTypes } = this.options;
|
|
@@ -3288,7 +3429,11 @@ var Iti = class _Iti {
|
|
|
3288
3429
|
true
|
|
3289
3430
|
);
|
|
3290
3431
|
let validNumber = exampleNumber;
|
|
3291
|
-
while (intlTelInput.utils.isPossibleNumber(
|
|
3432
|
+
while (intlTelInput.utils.isPossibleNumber(
|
|
3433
|
+
exampleNumber,
|
|
3434
|
+
iso2,
|
|
3435
|
+
validationNumberTypes
|
|
3436
|
+
)) {
|
|
3292
3437
|
validNumber = exampleNumber;
|
|
3293
3438
|
exampleNumber += "0";
|
|
3294
3439
|
}
|
|
@@ -3302,31 +3447,6 @@ var Iti = class _Iti {
|
|
|
3302
3447
|
}
|
|
3303
3448
|
}
|
|
3304
3449
|
}
|
|
3305
|
-
//* When input is in a hidden container during init, we cannot calculate the selected country width.
|
|
3306
|
-
//* Fix: clone the markup, make it invisible, add it to the end of the DOM, and then measure it's width.
|
|
3307
|
-
//* To get the right styling to apply, all we need is a shallow clone of the container,
|
|
3308
|
-
//* and then to inject a deep clone of the selectedCountry element.
|
|
3309
|
-
_getHiddenSelectedCountryWidth() {
|
|
3310
|
-
if (this.telInput.parentNode) {
|
|
3311
|
-
let body;
|
|
3312
|
-
try {
|
|
3313
|
-
body = window.top.document.body;
|
|
3314
|
-
} catch (e) {
|
|
3315
|
-
body = document.body;
|
|
3316
|
-
}
|
|
3317
|
-
const containerClone = this.telInput.parentNode.cloneNode(false);
|
|
3318
|
-
containerClone.style.visibility = "hidden";
|
|
3319
|
-
body.appendChild(containerClone);
|
|
3320
|
-
const countryContainerClone = this.countryContainer.cloneNode();
|
|
3321
|
-
containerClone.appendChild(countryContainerClone);
|
|
3322
|
-
const selectedCountryClone = this.selectedCountry.cloneNode(true);
|
|
3323
|
-
countryContainerClone.appendChild(selectedCountryClone);
|
|
3324
|
-
const width = selectedCountryClone.offsetWidth;
|
|
3325
|
-
body.removeChild(containerClone);
|
|
3326
|
-
return width;
|
|
3327
|
-
}
|
|
3328
|
-
return 0;
|
|
3329
|
-
}
|
|
3330
3450
|
//* Update the input placeholder to an example number from the currently selected country.
|
|
3331
3451
|
_updatePlaceholder() {
|
|
3332
3452
|
const {
|
|
@@ -3335,7 +3455,7 @@ var Iti = class _Iti {
|
|
|
3335
3455
|
nationalMode,
|
|
3336
3456
|
customPlaceholder
|
|
3337
3457
|
} = this.options;
|
|
3338
|
-
const shouldSetPlaceholder = autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && autoPlaceholder === "polite";
|
|
3458
|
+
const shouldSetPlaceholder = autoPlaceholder === "aggressive" || !this.ui.hadInitialPlaceholder && autoPlaceholder === "polite";
|
|
3339
3459
|
if (intlTelInput.utils && shouldSetPlaceholder) {
|
|
3340
3460
|
const numberType = intlTelInput.utils.numberType[placeholderNumberType];
|
|
3341
3461
|
let placeholder = this.selectedCountryData.iso2 ? intlTelInput.utils.getExampleNumber(
|
|
@@ -3347,98 +3467,66 @@ var Iti = class _Iti {
|
|
|
3347
3467
|
if (typeof customPlaceholder === "function") {
|
|
3348
3468
|
placeholder = customPlaceholder(placeholder, this.selectedCountryData);
|
|
3349
3469
|
}
|
|
3350
|
-
this.telInput.setAttribute("placeholder", placeholder);
|
|
3470
|
+
this.ui.telInput.setAttribute("placeholder", placeholder);
|
|
3351
3471
|
}
|
|
3352
3472
|
}
|
|
3353
3473
|
//* Called when the user selects a list item from the dropdown.
|
|
3354
3474
|
_selectListItem(listItem) {
|
|
3355
|
-
const iso2 = listItem.
|
|
3475
|
+
const iso2 = listItem.dataset.countryCode;
|
|
3356
3476
|
const countryChanged = this._setCountry(iso2);
|
|
3357
3477
|
this._closeDropdown();
|
|
3358
|
-
const dialCode = listItem.
|
|
3478
|
+
const dialCode = listItem.dataset.dialCode;
|
|
3359
3479
|
this._updateDialCode(dialCode);
|
|
3360
3480
|
if (this.options.formatOnDisplay) {
|
|
3361
|
-
this._updateValFromNumber(this.telInput.value);
|
|
3481
|
+
this._updateValFromNumber(this.ui.telInput.value);
|
|
3362
3482
|
}
|
|
3363
|
-
this.telInput.focus();
|
|
3483
|
+
this.ui.telInput.focus();
|
|
3364
3484
|
if (countryChanged) {
|
|
3365
3485
|
this._triggerCountryChange();
|
|
3366
3486
|
}
|
|
3367
3487
|
}
|
|
3368
3488
|
//* Close the dropdown and unbind any listeners.
|
|
3369
3489
|
_closeDropdown() {
|
|
3370
|
-
this.dropdownContent.classList.
|
|
3371
|
-
|
|
3372
|
-
if (this.highlightedItem) {
|
|
3373
|
-
this.highlightedItem.setAttribute("aria-selected", "false");
|
|
3490
|
+
if (this.ui.dropdownContent.classList.contains("iti__hide")) {
|
|
3491
|
+
return;
|
|
3374
3492
|
}
|
|
3375
|
-
|
|
3376
|
-
|
|
3493
|
+
this.ui.dropdownContent.classList.add("iti__hide");
|
|
3494
|
+
this.ui.selectedCountry.setAttribute("aria-expanded", "false");
|
|
3495
|
+
if (this.ui.highlightedItem) {
|
|
3496
|
+
this.ui.highlightedItem.setAttribute("aria-selected", "false");
|
|
3377
3497
|
}
|
|
3378
|
-
this.dropdownArrow.classList.remove("iti__arrow--up");
|
|
3379
3498
|
if (this.options.countrySearch) {
|
|
3380
|
-
this.searchInput.
|
|
3381
|
-
this.searchClearButton.removeEventListener("click", this._handleSearchClear);
|
|
3499
|
+
this.ui.searchInput.removeAttribute("aria-activedescendant");
|
|
3382
3500
|
}
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
this._handleClickOffToClose
|
|
3387
|
-
);
|
|
3388
|
-
this.countryList.removeEventListener(
|
|
3389
|
-
"mouseover",
|
|
3390
|
-
this._handleMouseoverCountryList
|
|
3391
|
-
);
|
|
3392
|
-
this.countryList.removeEventListener("click", this._handleClickCountryList);
|
|
3501
|
+
this.ui.dropdownArrow.classList.remove("iti__arrow--up");
|
|
3502
|
+
this.dropdownAbortController.abort();
|
|
3503
|
+
this.dropdownAbortController = null;
|
|
3393
3504
|
if (this.options.dropdownContainer) {
|
|
3394
|
-
|
|
3395
|
-
window.removeEventListener("scroll", this._handleWindowScroll);
|
|
3396
|
-
}
|
|
3397
|
-
if (this.dropdown.parentNode) {
|
|
3398
|
-
this.dropdown.parentNode.removeChild(this.dropdown);
|
|
3399
|
-
}
|
|
3505
|
+
this.ui.dropdown.remove();
|
|
3400
3506
|
}
|
|
3401
3507
|
this._trigger("close:countrydropdown");
|
|
3402
3508
|
}
|
|
3403
|
-
//* Check if an element is visible within it's container, else scroll until it is.
|
|
3404
|
-
_scrollTo(element) {
|
|
3405
|
-
const container = this.countryList;
|
|
3406
|
-
const scrollTop = document.documentElement.scrollTop;
|
|
3407
|
-
const containerHeight = container.offsetHeight;
|
|
3408
|
-
const containerTop = container.getBoundingClientRect().top + scrollTop;
|
|
3409
|
-
const containerBottom = containerTop + containerHeight;
|
|
3410
|
-
const elementHeight = element.offsetHeight;
|
|
3411
|
-
const elementTop = element.getBoundingClientRect().top + scrollTop;
|
|
3412
|
-
const elementBottom = elementTop + elementHeight;
|
|
3413
|
-
const newScrollTop = elementTop - containerTop + container.scrollTop;
|
|
3414
|
-
if (elementTop < containerTop) {
|
|
3415
|
-
container.scrollTop = newScrollTop;
|
|
3416
|
-
} else if (elementBottom > containerBottom) {
|
|
3417
|
-
const heightDifference = containerHeight - elementHeight;
|
|
3418
|
-
container.scrollTop = newScrollTop - heightDifference;
|
|
3419
|
-
}
|
|
3420
|
-
}
|
|
3421
3509
|
//* Replace any existing dial code with the new one
|
|
3422
3510
|
//* Note: called from _selectListItem and setCountry
|
|
3423
3511
|
_updateDialCode(newDialCodeBare) {
|
|
3424
|
-
const inputVal = this.telInput.value;
|
|
3512
|
+
const inputVal = this.ui.telInput.value;
|
|
3425
3513
|
const newDialCode = `+${newDialCodeBare}`;
|
|
3426
3514
|
let newNumber;
|
|
3427
|
-
if (inputVal.
|
|
3515
|
+
if (inputVal.startsWith("+")) {
|
|
3428
3516
|
const prevDialCode = this._getDialCode(inputVal);
|
|
3429
3517
|
if (prevDialCode) {
|
|
3430
3518
|
newNumber = inputVal.replace(prevDialCode, newDialCode);
|
|
3431
3519
|
} else {
|
|
3432
3520
|
newNumber = newDialCode;
|
|
3433
3521
|
}
|
|
3434
|
-
this.telInput.value = newNumber;
|
|
3522
|
+
this.ui.telInput.value = newNumber;
|
|
3435
3523
|
}
|
|
3436
3524
|
}
|
|
3437
3525
|
//* Try and extract a valid international dial code from a full telephone number.
|
|
3438
3526
|
//* Note: returns the raw string inc plus character and any whitespace/dots etc.
|
|
3439
3527
|
_getDialCode(number, includeAreaCode) {
|
|
3440
3528
|
let dialCode = "";
|
|
3441
|
-
if (number.
|
|
3529
|
+
if (number.startsWith("+")) {
|
|
3442
3530
|
let numericChars = "";
|
|
3443
3531
|
for (let i = 0; i < number.length; i++) {
|
|
3444
3532
|
const c = number.charAt(i);
|
|
@@ -3464,11 +3552,11 @@ var Iti = class _Iti {
|
|
|
3464
3552
|
}
|
|
3465
3553
|
//* Get the input val, adding the dial code if separateDialCode is enabled.
|
|
3466
3554
|
_getFullNumber(overrideVal) {
|
|
3467
|
-
const val = overrideVal || this.telInput.value.trim();
|
|
3555
|
+
const val = overrideVal || this.ui.telInput.value.trim();
|
|
3468
3556
|
const { dialCode } = this.selectedCountryData;
|
|
3469
3557
|
let prefix;
|
|
3470
3558
|
const numericVal = getNumeric(val);
|
|
3471
|
-
if (this.options.separateDialCode && val.
|
|
3559
|
+
if (this.options.separateDialCode && !val.startsWith("+") && dialCode && numericVal) {
|
|
3472
3560
|
prefix = `+${dialCode}`;
|
|
3473
3561
|
} else {
|
|
3474
3562
|
prefix = "";
|
|
@@ -3497,7 +3585,7 @@ var Iti = class _Iti {
|
|
|
3497
3585
|
handleAutoCountry() {
|
|
3498
3586
|
if (this.options.initialCountry === "auto" && intlTelInput.autoCountry) {
|
|
3499
3587
|
this.defaultCountry = intlTelInput.autoCountry;
|
|
3500
|
-
const hasSelectedCountryOrGlobe = this.selectedCountryData.iso2 || this.selectedCountryInner.classList.contains("iti__globe");
|
|
3588
|
+
const hasSelectedCountryOrGlobe = this.selectedCountryData.iso2 || this.ui.selectedCountryInner.classList.contains("iti__globe");
|
|
3501
3589
|
if (!hasSelectedCountryOrGlobe) {
|
|
3502
3590
|
this.setCountry(this.defaultCountry);
|
|
3503
3591
|
}
|
|
@@ -3507,8 +3595,8 @@ var Iti = class _Iti {
|
|
|
3507
3595
|
//* This is called when the utils request completes.
|
|
3508
3596
|
handleUtils() {
|
|
3509
3597
|
if (intlTelInput.utils) {
|
|
3510
|
-
if (this.telInput.value) {
|
|
3511
|
-
this._updateValFromNumber(this.telInput.value);
|
|
3598
|
+
if (this.ui.telInput.value) {
|
|
3599
|
+
this._updateValFromNumber(this.ui.telInput.value);
|
|
3512
3600
|
}
|
|
3513
3601
|
if (this.selectedCountryData.iso2) {
|
|
3514
3602
|
this._updatePlaceholder();
|
|
@@ -3522,49 +3610,20 @@ var Iti = class _Iti {
|
|
|
3522
3610
|
//********************
|
|
3523
3611
|
//* Remove plugin.
|
|
3524
3612
|
destroy() {
|
|
3525
|
-
this.telInput
|
|
3526
|
-
|
|
3527
|
-
if (allowDropdown) {
|
|
3528
|
-
this._closeDropdown();
|
|
3529
|
-
this.selectedCountry.removeEventListener(
|
|
3530
|
-
"click",
|
|
3531
|
-
this._handleClickSelectedCountry
|
|
3532
|
-
);
|
|
3533
|
-
this.countryContainer.removeEventListener(
|
|
3534
|
-
"keydown",
|
|
3535
|
-
this._handleCountryContainerKeydown
|
|
3536
|
-
);
|
|
3537
|
-
const label = this.telInput.closest("label");
|
|
3538
|
-
if (label) {
|
|
3539
|
-
label.removeEventListener("click", this._handleLabelClick);
|
|
3540
|
-
}
|
|
3541
|
-
}
|
|
3542
|
-
const { form } = this.telInput;
|
|
3543
|
-
if (this._handleHiddenInputSubmit && form) {
|
|
3544
|
-
form.removeEventListener("submit", this._handleHiddenInputSubmit);
|
|
3545
|
-
}
|
|
3546
|
-
this.telInput.removeEventListener("input", this._handleInputEvent);
|
|
3547
|
-
if (this._handleKeydownEvent) {
|
|
3548
|
-
this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
|
|
3549
|
-
}
|
|
3550
|
-
if (this._handlePasteEvent) {
|
|
3551
|
-
this.telInput.removeEventListener("paste", this._handlePasteEvent);
|
|
3613
|
+
if (!this.ui.telInput) {
|
|
3614
|
+
return;
|
|
3552
3615
|
}
|
|
3553
|
-
if (this.
|
|
3554
|
-
|
|
3616
|
+
if (this.options.allowDropdown) {
|
|
3617
|
+
this._closeDropdown();
|
|
3555
3618
|
}
|
|
3556
|
-
this.
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3619
|
+
this.abortController.abort();
|
|
3620
|
+
this.abortController = null;
|
|
3621
|
+
this.ui.destroy();
|
|
3622
|
+
if (intlTelInput.instances instanceof Map) {
|
|
3623
|
+
intlTelInput.instances.delete(this.id);
|
|
3624
|
+
} else {
|
|
3625
|
+
delete intlTelInput.instances[this.id];
|
|
3563
3626
|
}
|
|
3564
|
-
const wrapper = this.telInput.parentNode;
|
|
3565
|
-
wrapper?.parentNode?.insertBefore(this.telInput, wrapper);
|
|
3566
|
-
wrapper?.parentNode?.removeChild(wrapper);
|
|
3567
|
-
delete intlTelInput.instances[this.id];
|
|
3568
3627
|
}
|
|
3569
3628
|
//* Get the extension from the current number.
|
|
3570
3629
|
getExtension() {
|
|
@@ -3610,19 +3669,34 @@ var Iti = class _Iti {
|
|
|
3610
3669
|
}
|
|
3611
3670
|
return -99;
|
|
3612
3671
|
}
|
|
3613
|
-
//* Validate the input val
|
|
3672
|
+
//* Validate the input val using number length only
|
|
3614
3673
|
isValidNumber() {
|
|
3674
|
+
const { dialCode, iso2 } = this.selectedCountryData;
|
|
3675
|
+
if (dialCode === "44" && intlTelInput.utils) {
|
|
3676
|
+
const number = this._getFullNumber();
|
|
3677
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(number, iso2);
|
|
3678
|
+
if (coreNumber[0] === "7" && coreNumber.length !== 10) {
|
|
3679
|
+
return false;
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3615
3682
|
return this._validateNumber(false);
|
|
3616
3683
|
}
|
|
3617
|
-
//* Validate the input val
|
|
3684
|
+
//* Validate the input val with precise validation
|
|
3618
3685
|
isValidNumberPrecise() {
|
|
3619
3686
|
return this._validateNumber(true);
|
|
3620
3687
|
}
|
|
3621
3688
|
_utilsIsPossibleNumber(val) {
|
|
3622
|
-
return intlTelInput.utils ? intlTelInput.utils.isPossibleNumber(
|
|
3689
|
+
return intlTelInput.utils ? intlTelInput.utils.isPossibleNumber(
|
|
3690
|
+
val,
|
|
3691
|
+
this.selectedCountryData.iso2,
|
|
3692
|
+
this.options.validationNumberTypes
|
|
3693
|
+
) : null;
|
|
3623
3694
|
}
|
|
3624
3695
|
//* Shared internal validation logic to handle alpha character extension rules.
|
|
3625
3696
|
_validateNumber(precise) {
|
|
3697
|
+
if (!intlTelInput.utils) {
|
|
3698
|
+
return null;
|
|
3699
|
+
}
|
|
3626
3700
|
if (!this.selectedCountryData.iso2) {
|
|
3627
3701
|
return false;
|
|
3628
3702
|
}
|
|
@@ -3639,7 +3713,11 @@ var Iti = class _Iti {
|
|
|
3639
3713
|
return testValidity(val);
|
|
3640
3714
|
}
|
|
3641
3715
|
_utilsIsValidNumber(val) {
|
|
3642
|
-
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(
|
|
3716
|
+
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(
|
|
3717
|
+
val,
|
|
3718
|
+
this.selectedCountryData.iso2,
|
|
3719
|
+
this.options.validationNumberTypes
|
|
3720
|
+
) : null;
|
|
3643
3721
|
}
|
|
3644
3722
|
//* Update the selected country, and update the input val accordingly.
|
|
3645
3723
|
setCountry(iso2) {
|
|
@@ -3653,7 +3731,7 @@ var Iti = class _Iti {
|
|
|
3653
3731
|
this._setCountry(iso2Lower);
|
|
3654
3732
|
this._updateDialCode(this.selectedCountryData.dialCode);
|
|
3655
3733
|
if (this.options.formatOnDisplay) {
|
|
3656
|
-
this._updateValFromNumber(this.telInput.value);
|
|
3734
|
+
this._updateValFromNumber(this.ui.telInput.value);
|
|
3657
3735
|
}
|
|
3658
3736
|
this._triggerCountryChange();
|
|
3659
3737
|
}
|
|
@@ -3673,11 +3751,11 @@ var Iti = class _Iti {
|
|
|
3673
3751
|
this._updatePlaceholder();
|
|
3674
3752
|
}
|
|
3675
3753
|
setDisabled(disabled) {
|
|
3676
|
-
this.telInput.disabled = disabled;
|
|
3754
|
+
this.ui.telInput.disabled = disabled;
|
|
3677
3755
|
if (disabled) {
|
|
3678
|
-
this.selectedCountry.setAttribute("disabled", "true");
|
|
3756
|
+
this.ui.selectedCountry.setAttribute("disabled", "true");
|
|
3679
3757
|
} else {
|
|
3680
|
-
this.selectedCountry.removeAttribute("disabled");
|
|
3758
|
+
this.ui.selectedCountry.removeAttribute("disabled");
|
|
3681
3759
|
}
|
|
3682
3760
|
}
|
|
3683
3761
|
};
|
|
@@ -3691,13 +3769,19 @@ var attachUtils = (source) => {
|
|
|
3691
3769
|
return Promise.reject(error);
|
|
3692
3770
|
}
|
|
3693
3771
|
} else {
|
|
3694
|
-
return Promise.reject(
|
|
3772
|
+
return Promise.reject(
|
|
3773
|
+
new TypeError(
|
|
3774
|
+
`The argument passed to attachUtils must be a function that returns a promise for the utilities module, not ${typeof source}`
|
|
3775
|
+
)
|
|
3776
|
+
);
|
|
3695
3777
|
}
|
|
3696
3778
|
intlTelInput.startedLoadingUtilsScript = true;
|
|
3697
3779
|
return loadCall.then((module) => {
|
|
3698
3780
|
const utils = module?.default;
|
|
3699
3781
|
if (!utils || typeof utils !== "object") {
|
|
3700
|
-
throw new TypeError(
|
|
3782
|
+
throw new TypeError(
|
|
3783
|
+
"The loader function passed to attachUtils did not resolve to a module object with utils as its default export."
|
|
3784
|
+
);
|
|
3701
3785
|
}
|
|
3702
3786
|
intlTelInput.utils = utils;
|
|
3703
3787
|
forEachInstance("handleUtils");
|
|
@@ -3709,11 +3793,17 @@ var attachUtils = (source) => {
|
|
|
3709
3793
|
}
|
|
3710
3794
|
return null;
|
|
3711
3795
|
};
|
|
3796
|
+
var forEachInstance = (method, ...args) => {
|
|
3797
|
+
Object.values(intlTelInput.instances).forEach((instance) => {
|
|
3798
|
+
const fn = instance[method];
|
|
3799
|
+
if (typeof fn === "function") {
|
|
3800
|
+
fn.apply(instance, args);
|
|
3801
|
+
}
|
|
3802
|
+
});
|
|
3803
|
+
};
|
|
3712
3804
|
var intlTelInput = Object.assign(
|
|
3713
3805
|
(input, options) => {
|
|
3714
3806
|
const iti = new Iti(input, options);
|
|
3715
|
-
iti._init();
|
|
3716
|
-
input.setAttribute("data-intl-tel-input-id", iti.id.toString());
|
|
3717
3807
|
intlTelInput.instances[iti.id] = iti;
|
|
3718
3808
|
input.iti = iti;
|
|
3719
3809
|
return iti;
|
|
@@ -3726,7 +3816,7 @@ var intlTelInput = Object.assign(
|
|
|
3726
3816
|
getCountryData: () => data_default,
|
|
3727
3817
|
//* A getter for the plugin instance.
|
|
3728
3818
|
getInstance: (input) => {
|
|
3729
|
-
const id2 = input.
|
|
3819
|
+
const id2 = input.dataset.intlTelInputId;
|
|
3730
3820
|
return id2 ? intlTelInput.instances[id2] : null;
|
|
3731
3821
|
},
|
|
3732
3822
|
//* A map from instance ID to instance object.
|
|
@@ -3734,7 +3824,7 @@ var intlTelInput = Object.assign(
|
|
|
3734
3824
|
attachUtils,
|
|
3735
3825
|
startedLoadingUtilsScript: false,
|
|
3736
3826
|
startedLoadingAutoCountry: false,
|
|
3737
|
-
version: "25.
|
|
3827
|
+
version: "25.11.0"
|
|
3738
3828
|
}
|
|
3739
3829
|
);
|
|
3740
3830
|
var intl_tel_input_default = intlTelInput;
|