intl-tel-input 21.2.7 → 22.0.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 +24 -28
- package/build/css/intlTelInput.css +19 -38
- 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/i18n/ar/index.mjs +3 -2
- package/build/js/i18n/bg/index.mjs +3 -2
- package/build/js/i18n/bn/index.mjs +3 -2
- package/build/js/i18n/de/index.mjs +3 -2
- package/build/js/i18n/el/index.mjs +3 -2
- package/build/js/i18n/en/index.mjs +3 -2
- package/build/js/i18n/es/index.mjs +3 -2
- package/build/js/i18n/fr/index.mjs +3 -2
- package/build/js/i18n/hi/index.mjs +3 -2
- package/build/js/i18n/hu/index.mjs +3 -2
- package/build/js/i18n/id/index.mjs +3 -2
- package/build/js/i18n/index.mjs +24 -23
- package/build/js/i18n/ja/index.mjs +3 -2
- package/build/js/i18n/ko/index.mjs +3 -2
- package/build/js/i18n/mr/index.mjs +3 -2
- package/build/js/i18n/nl/index.mjs +3 -2
- package/build/js/i18n/pt/index.mjs +3 -2
- package/build/js/i18n/ro/index.mjs +3 -2
- package/build/js/i18n/ru/index.mjs +3 -2
- package/build/js/i18n/te/index.mjs +3 -2
- package/build/js/i18n/th/index.mjs +3 -2
- package/build/js/i18n/tr/index.mjs +3 -2
- package/build/js/i18n/ur/index.mjs +3 -2
- package/build/js/i18n/zh/index.mjs +3 -2
- package/build/js/intlTelInput.d.ts +277 -281
- package/build/js/intlTelInput.js +230 -333
- package/build/js/intlTelInput.min.js +2 -2
- package/build/js/utils.js +1 -1
- package/package.json +1 -1
- package/react/build/IntlTelInput.cjs +1 -1
- package/react/build/IntlTelInput.d.ts +277 -281
- package/react/build/IntlTelInput.js +1 -1
package/build/js/intlTelInput.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* International Telephone Input
|
|
2
|
+
* International Telephone Input v22.0.0
|
|
3
3
|
* https://github.com/jackocnr/intl-tel-input.git
|
|
4
4
|
* Licensed under the MIT license
|
|
5
5
|
*/
|
|
@@ -1118,7 +1118,7 @@ var factoryOutput = (() => {
|
|
|
1118
1118
|
}
|
|
1119
1119
|
var data_default = allCountries;
|
|
1120
1120
|
|
|
1121
|
-
// src/js/i18n/en/countries.
|
|
1121
|
+
// src/js/i18n/en/countries.ts
|
|
1122
1122
|
var countries_default = {
|
|
1123
1123
|
af: "Afghanistan",
|
|
1124
1124
|
ax: "\xC5land Islands",
|
|
@@ -1371,7 +1371,7 @@ var factoryOutput = (() => {
|
|
|
1371
1371
|
zw: "Zimbabwe"
|
|
1372
1372
|
};
|
|
1373
1373
|
|
|
1374
|
-
// src/js/i18n/en/interface.
|
|
1374
|
+
// src/js/i18n/en/interface.ts
|
|
1375
1375
|
var interface_default = {
|
|
1376
1376
|
selectedCountryAriaLabel: "Selected country",
|
|
1377
1377
|
noCountrySelected: "No country selected",
|
|
@@ -1385,7 +1385,7 @@ var factoryOutput = (() => {
|
|
|
1385
1385
|
xk: "Kosovo"
|
|
1386
1386
|
};
|
|
1387
1387
|
|
|
1388
|
-
// src/js/i18n/en/index.
|
|
1388
|
+
// src/js/i18n/en/index.ts
|
|
1389
1389
|
var en_default = { ...countries_default, ...interface_default };
|
|
1390
1390
|
|
|
1391
1391
|
// src/js/intl-tel-input.ts
|
|
@@ -1395,10 +1395,10 @@ var factoryOutput = (() => {
|
|
|
1395
1395
|
allowDropdown: true,
|
|
1396
1396
|
//* Add a placeholder in the input with an example number for the selected country.
|
|
1397
1397
|
autoPlaceholder: "polite",
|
|
1398
|
-
//* Add a country search input at the top of the dropdown.
|
|
1399
|
-
countrySearch: true,
|
|
1400
1398
|
//* Modify the parentClass.
|
|
1401
1399
|
containerClass: "",
|
|
1400
|
+
//* The order of the countries in the dropdown. Defaults to alphabetical.
|
|
1401
|
+
countryOrder: null,
|
|
1402
1402
|
//* Modify the auto placeholder.
|
|
1403
1403
|
customPlaceholder: null,
|
|
1404
1404
|
//* Append menu to specified element.
|
|
@@ -1425,12 +1425,10 @@ var factoryOutput = (() => {
|
|
|
1425
1425
|
onlyCountries: [],
|
|
1426
1426
|
//* Number type to use for placeholders.
|
|
1427
1427
|
placeholderNumberType: "MOBILE",
|
|
1428
|
-
//*
|
|
1429
|
-
preferredCountries: [],
|
|
1430
|
-
//* Option to hide the flags - must be used with showSelectedDialCode, or allowDropdown=false.
|
|
1428
|
+
//* Show flags - for both the selected country, and in the country dropdown
|
|
1431
1429
|
showFlags: true,
|
|
1432
1430
|
//* Display the international dial code next to the selected flag.
|
|
1433
|
-
|
|
1431
|
+
separateDialCode: false,
|
|
1434
1432
|
//* Only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length.
|
|
1435
1433
|
strictMode: false,
|
|
1436
1434
|
//* Use full screen popup instead of dropdown for country list.
|
|
@@ -1465,13 +1463,6 @@ var factoryOutput = (() => {
|
|
|
1465
1463
|
];
|
|
1466
1464
|
var getNumeric = (s) => s.replace(/\D/g, "");
|
|
1467
1465
|
var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
|
|
1468
|
-
var toggleClass = (el, className, shouldHaveClass) => {
|
|
1469
|
-
if (shouldHaveClass && !el.classList.contains(className)) {
|
|
1470
|
-
el.classList.add(className);
|
|
1471
|
-
} else if (!shouldHaveClass && el.classList.contains(className)) {
|
|
1472
|
-
el.classList.remove(className);
|
|
1473
|
-
}
|
|
1474
|
-
};
|
|
1475
1466
|
var isRegionlessNanp = (number) => {
|
|
1476
1467
|
const numeric = getNumeric(number);
|
|
1477
1468
|
if (numeric.charAt(0) === "1") {
|
|
@@ -1480,15 +1471,6 @@ var factoryOutput = (() => {
|
|
|
1480
1471
|
}
|
|
1481
1472
|
return false;
|
|
1482
1473
|
};
|
|
1483
|
-
var countryNameSort = (a, b) => {
|
|
1484
|
-
if (a.name < b.name) {
|
|
1485
|
-
return -1;
|
|
1486
|
-
}
|
|
1487
|
-
if (a.name > b.name) {
|
|
1488
|
-
return 1;
|
|
1489
|
-
}
|
|
1490
|
-
return 0;
|
|
1491
|
-
};
|
|
1492
1474
|
var translateCursorPosition = (relevantChars, formattedValue, prevCaretPos, isDeleteForwards) => {
|
|
1493
1475
|
if (prevCaretPos === 0 && !isDeleteForwards) {
|
|
1494
1476
|
return 0;
|
|
@@ -1518,7 +1500,7 @@ var factoryOutput = (() => {
|
|
|
1518
1500
|
return el;
|
|
1519
1501
|
};
|
|
1520
1502
|
var forEachInstance = (method) => {
|
|
1521
|
-
const { instances } =
|
|
1503
|
+
const { instances } = intlTelInput;
|
|
1522
1504
|
Object.values(instances).forEach((instance) => instance[method]());
|
|
1523
1505
|
};
|
|
1524
1506
|
var Iti = class {
|
|
@@ -1528,7 +1510,6 @@ var factoryOutput = (() => {
|
|
|
1528
1510
|
promise;
|
|
1529
1511
|
//* Private
|
|
1530
1512
|
telInput;
|
|
1531
|
-
activeItem;
|
|
1532
1513
|
highlightedItem;
|
|
1533
1514
|
options;
|
|
1534
1515
|
hadInitialPlaceholder;
|
|
@@ -1538,7 +1519,6 @@ var factoryOutput = (() => {
|
|
|
1538
1519
|
dialCodeMaxLen;
|
|
1539
1520
|
dialCodeToIso2Map;
|
|
1540
1521
|
dialCodes;
|
|
1541
|
-
preferredCountries;
|
|
1542
1522
|
countryContainer;
|
|
1543
1523
|
selectedCountry;
|
|
1544
1524
|
selectedCountryInner;
|
|
@@ -1573,7 +1553,6 @@ var factoryOutput = (() => {
|
|
|
1573
1553
|
constructor(input, customOptions = {}) {
|
|
1574
1554
|
this.id = id++;
|
|
1575
1555
|
this.telInput = input;
|
|
1576
|
-
this.activeItem = null;
|
|
1577
1556
|
this.highlightedItem = null;
|
|
1578
1557
|
this.options = Object.assign({}, defaults, customOptions);
|
|
1579
1558
|
this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
|
|
@@ -1583,12 +1562,9 @@ var factoryOutput = (() => {
|
|
|
1583
1562
|
if (this.options.useFullscreenPopup) {
|
|
1584
1563
|
this.options.fixDropdownWidth = false;
|
|
1585
1564
|
}
|
|
1586
|
-
if (this.options.
|
|
1587
|
-
this.options.
|
|
1588
|
-
|
|
1589
|
-
const forceShowFlags = this.options.allowDropdown && !this.options.showSelectedDialCode;
|
|
1590
|
-
if (!this.options.showFlags && forceShowFlags) {
|
|
1591
|
-
this.options.showFlags = true;
|
|
1565
|
+
if (this.options.separateDialCode) {
|
|
1566
|
+
this.options.allowDropdown = true;
|
|
1567
|
+
this.options.nationalMode = false;
|
|
1592
1568
|
}
|
|
1593
1569
|
if (this.options.useFullscreenPopup && !this.options.dropdownContainer) {
|
|
1594
1570
|
this.options.dropdownContainer = document.body;
|
|
@@ -1614,15 +1590,39 @@ var factoryOutput = (() => {
|
|
|
1614
1590
|
//********************
|
|
1615
1591
|
//* PRIVATE METHODS
|
|
1616
1592
|
//********************
|
|
1617
|
-
//* Prepare all of the country data, including onlyCountries, excludeCountries
|
|
1593
|
+
//* Prepare all of the country data, including onlyCountries, excludeCountries, countryOrder options.
|
|
1618
1594
|
_processCountryData() {
|
|
1619
1595
|
this._processAllCountries();
|
|
1620
1596
|
this._processDialCodes();
|
|
1621
|
-
this._processPreferredCountries();
|
|
1622
1597
|
this._translateCountryNames();
|
|
1623
|
-
if (this.options.
|
|
1624
|
-
this.
|
|
1625
|
-
}
|
|
1598
|
+
if (this.options.countryOrder) {
|
|
1599
|
+
this.options.countryOrder = this.options.countryOrder.map((country) => country.toLowerCase());
|
|
1600
|
+
}
|
|
1601
|
+
this._sortCountries();
|
|
1602
|
+
}
|
|
1603
|
+
_sortCountries() {
|
|
1604
|
+
this.countries.sort((a, b) => {
|
|
1605
|
+
const { countryOrder } = this.options;
|
|
1606
|
+
if (countryOrder) {
|
|
1607
|
+
const aIndex = countryOrder.indexOf(a.iso2);
|
|
1608
|
+
const bIndex = countryOrder.indexOf(b.iso2);
|
|
1609
|
+
const aIndexExists = aIndex > -1;
|
|
1610
|
+
const bIndexExists = bIndex > -1;
|
|
1611
|
+
if (aIndexExists || bIndexExists) {
|
|
1612
|
+
if (aIndexExists && bIndexExists) {
|
|
1613
|
+
return aIndex - bIndex;
|
|
1614
|
+
}
|
|
1615
|
+
return aIndexExists ? -1 : 1;
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
if (a.name < b.name) {
|
|
1619
|
+
return -1;
|
|
1620
|
+
}
|
|
1621
|
+
if (a.name > b.name) {
|
|
1622
|
+
return 1;
|
|
1623
|
+
}
|
|
1624
|
+
return 0;
|
|
1625
|
+
});
|
|
1626
1626
|
}
|
|
1627
1627
|
//* Add a dial code to this.dialCodeToIso2Map.
|
|
1628
1628
|
_addToDialCodeMap(iso2, dialCode, priority) {
|
|
@@ -1698,17 +1698,6 @@ var factoryOutput = (() => {
|
|
|
1698
1698
|
}
|
|
1699
1699
|
}
|
|
1700
1700
|
}
|
|
1701
|
-
//* Process preferred countries - iterate through the preferences, fetching the country data for each one.
|
|
1702
|
-
_processPreferredCountries() {
|
|
1703
|
-
this.preferredCountries = [];
|
|
1704
|
-
for (let i = 0; i < this.options.preferredCountries.length; i++) {
|
|
1705
|
-
const iso2 = this.options.preferredCountries[i].toLowerCase();
|
|
1706
|
-
const countryData = this._getCountryData(iso2, true);
|
|
1707
|
-
if (countryData) {
|
|
1708
|
-
this.preferredCountries.push(countryData);
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
1701
|
//* Generate all of the markup for the plugin: the selected country overlay, and the dropdown.
|
|
1713
1702
|
_generateMarkup() {
|
|
1714
1703
|
this.telInput.classList.add("iti__tel-input");
|
|
@@ -1717,23 +1706,19 @@ var factoryOutput = (() => {
|
|
|
1717
1706
|
}
|
|
1718
1707
|
const {
|
|
1719
1708
|
allowDropdown,
|
|
1720
|
-
|
|
1709
|
+
separateDialCode,
|
|
1721
1710
|
showFlags,
|
|
1722
1711
|
containerClass,
|
|
1723
1712
|
hiddenInput,
|
|
1724
1713
|
dropdownContainer,
|
|
1725
1714
|
fixDropdownWidth,
|
|
1726
1715
|
useFullscreenPopup,
|
|
1727
|
-
countrySearch,
|
|
1728
1716
|
i18n
|
|
1729
1717
|
} = this.options;
|
|
1730
1718
|
let parentClass = "iti";
|
|
1731
1719
|
if (allowDropdown) {
|
|
1732
1720
|
parentClass += " iti--allow-dropdown";
|
|
1733
1721
|
}
|
|
1734
|
-
if (showSelectedDialCode) {
|
|
1735
|
-
parentClass += " iti--show-selected-dial-code";
|
|
1736
|
-
}
|
|
1737
1722
|
if (showFlags) {
|
|
1738
1723
|
parentClass += " iti--show-flags";
|
|
1739
1724
|
}
|
|
@@ -1745,7 +1730,7 @@ var factoryOutput = (() => {
|
|
|
1745
1730
|
}
|
|
1746
1731
|
const wrapper = createEl("div", { class: parentClass });
|
|
1747
1732
|
this.telInput.parentNode?.insertBefore(wrapper, this.telInput);
|
|
1748
|
-
if (
|
|
1733
|
+
if (allowDropdown || showFlags) {
|
|
1749
1734
|
this.countryContainer = createEl(
|
|
1750
1735
|
"div",
|
|
1751
1736
|
{ class: "iti__country-container" },
|
|
@@ -1759,46 +1744,45 @@ var factoryOutput = (() => {
|
|
|
1759
1744
|
...allowDropdown && {
|
|
1760
1745
|
"aria-expanded": "false",
|
|
1761
1746
|
"aria-label": this.options.i18n.selectedCountryAriaLabel,
|
|
1762
|
-
"aria-haspopup":
|
|
1763
|
-
"aria-controls":
|
|
1764
|
-
|
|
1747
|
+
"aria-haspopup": "true",
|
|
1748
|
+
"aria-controls": `iti-${this.id}__dropdown-content`,
|
|
1749
|
+
"role": "combobox"
|
|
1765
1750
|
}
|
|
1766
1751
|
},
|
|
1767
1752
|
this.countryContainer
|
|
1768
1753
|
);
|
|
1769
|
-
|
|
1754
|
+
const selectedCountryPrimary = createEl("div", { class: "iti__selected-country-primary" }, this.selectedCountry);
|
|
1755
|
+
this.selectedCountryInner = createEl("div", null, selectedCountryPrimary);
|
|
1770
1756
|
this.selectedCountryA11yText = createEl(
|
|
1771
1757
|
"span",
|
|
1772
1758
|
{ class: "iti__a11y-text" },
|
|
1773
1759
|
this.selectedCountryInner
|
|
1774
1760
|
);
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
this.selectedCountry.setAttribute("aria-disabled", "true");
|
|
1779
|
-
}
|
|
1780
|
-
if (showSelectedDialCode) {
|
|
1781
|
-
this.selectedDialCode = createEl(
|
|
1782
|
-
"div",
|
|
1783
|
-
{ class: "iti__selected-dial-code" },
|
|
1784
|
-
this.selectedCountry
|
|
1785
|
-
);
|
|
1786
|
-
}
|
|
1787
|
-
if (allowDropdown) {
|
|
1788
|
-
if (!this.telInput.disabled) {
|
|
1761
|
+
if (this.telInput.disabled) {
|
|
1762
|
+
this.selectedCountry.setAttribute("aria-disabled", "true");
|
|
1763
|
+
} else {
|
|
1789
1764
|
this.selectedCountry.setAttribute("tabindex", "0");
|
|
1790
1765
|
}
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1766
|
+
if (allowDropdown) {
|
|
1767
|
+
this.dropdownArrow = createEl(
|
|
1768
|
+
"div",
|
|
1769
|
+
{ class: "iti__arrow", "aria-hidden": "true" },
|
|
1770
|
+
selectedCountryPrimary
|
|
1771
|
+
);
|
|
1772
|
+
}
|
|
1773
|
+
if (separateDialCode) {
|
|
1774
|
+
this.selectedDialCode = createEl(
|
|
1775
|
+
"div",
|
|
1776
|
+
{ class: "iti__selected-dial-code" },
|
|
1777
|
+
this.selectedCountry
|
|
1778
|
+
);
|
|
1779
|
+
}
|
|
1780
|
+
if (allowDropdown) {
|
|
1781
|
+
const extraClasses = fixDropdownWidth ? "" : "iti--flexible-dropdown-width";
|
|
1782
|
+
this.dropdownContent = createEl("div", {
|
|
1783
|
+
id: `iti-${this.id}__dropdown-content`,
|
|
1784
|
+
class: `iti__dropdown-content iti__hide ${extraClasses}`
|
|
1785
|
+
});
|
|
1802
1786
|
this.searchInput = createEl(
|
|
1803
1787
|
"input",
|
|
1804
1788
|
{
|
|
@@ -1819,48 +1803,33 @@ var factoryOutput = (() => {
|
|
|
1819
1803
|
{ class: "iti__a11y-text" },
|
|
1820
1804
|
this.dropdownContent
|
|
1821
1805
|
);
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
"ul",
|
|
1825
|
-
{
|
|
1826
|
-
class: "iti__country-list",
|
|
1827
|
-
id: `iti-${this.id}__country-listbox`,
|
|
1828
|
-
role: "listbox",
|
|
1829
|
-
"aria-label": i18n.countryListAriaLabel
|
|
1830
|
-
},
|
|
1831
|
-
this.dropdownContent
|
|
1832
|
-
);
|
|
1833
|
-
if (this.preferredCountries.length && !countrySearch) {
|
|
1834
|
-
this._appendListItems(this.preferredCountries, "iti__preferred", true);
|
|
1835
|
-
createEl(
|
|
1836
|
-
"li",
|
|
1806
|
+
this.countryList = createEl(
|
|
1807
|
+
"ul",
|
|
1837
1808
|
{
|
|
1838
|
-
class: "
|
|
1839
|
-
|
|
1809
|
+
class: "iti__country-list",
|
|
1810
|
+
id: `iti-${this.id}__country-listbox`,
|
|
1811
|
+
role: "listbox",
|
|
1812
|
+
"aria-label": i18n.countryListAriaLabel
|
|
1840
1813
|
},
|
|
1841
|
-
this.
|
|
1814
|
+
this.dropdownContent
|
|
1842
1815
|
);
|
|
1843
|
-
|
|
1844
|
-
this._appendListItems(this.countries, "iti__standard");
|
|
1845
|
-
if (countrySearch) {
|
|
1816
|
+
this._appendListItems(this.countries, "iti__standard");
|
|
1846
1817
|
this._updateSearchResultsText();
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1818
|
+
if (dropdownContainer) {
|
|
1819
|
+
let dropdownClasses = "iti iti--container";
|
|
1820
|
+
if (useFullscreenPopup) {
|
|
1821
|
+
dropdownClasses += " iti--fullscreen-popup";
|
|
1822
|
+
} else {
|
|
1823
|
+
dropdownClasses += " iti--inline-dropdown";
|
|
1824
|
+
}
|
|
1825
|
+
this.dropdown = createEl("div", { class: dropdownClasses });
|
|
1826
|
+
this.dropdown.appendChild(this.dropdownContent);
|
|
1852
1827
|
} else {
|
|
1853
|
-
|
|
1828
|
+
this.countryContainer.appendChild(this.dropdownContent);
|
|
1854
1829
|
}
|
|
1855
|
-
if (countrySearch) {
|
|
1856
|
-
dropdownClasses += " iti--country-search";
|
|
1857
|
-
}
|
|
1858
|
-
this.dropdown = createEl("div", { class: dropdownClasses });
|
|
1859
|
-
this.dropdown.appendChild(this.dropdownContent);
|
|
1860
|
-
} else {
|
|
1861
|
-
this.countryContainer.appendChild(this.dropdownContent);
|
|
1862
1830
|
}
|
|
1863
1831
|
}
|
|
1832
|
+
wrapper.appendChild(this.telInput);
|
|
1864
1833
|
if (hiddenInput) {
|
|
1865
1834
|
const telInputName = this.telInput.getAttribute("name") || "";
|
|
1866
1835
|
const names = hiddenInput(telInputName);
|
|
@@ -1881,14 +1850,13 @@ var factoryOutput = (() => {
|
|
|
1881
1850
|
}
|
|
1882
1851
|
}
|
|
1883
1852
|
//* For each of the passed countries: add a country <li> to the countryList <ul> container.
|
|
1884
|
-
_appendListItems(countries, className
|
|
1853
|
+
_appendListItems(countries, className) {
|
|
1885
1854
|
for (let i = 0; i < countries.length; i++) {
|
|
1886
1855
|
const c = countries[i];
|
|
1887
|
-
const idSuffix = preferred ? "-preferred" : "";
|
|
1888
1856
|
const listItem = createEl(
|
|
1889
1857
|
"li",
|
|
1890
1858
|
{
|
|
1891
|
-
id: `iti-${this.id}__item-${c.iso2}
|
|
1859
|
+
id: `iti-${this.id}__item-${c.iso2}`,
|
|
1892
1860
|
class: `iti__country ${className}`,
|
|
1893
1861
|
tabindex: "-1",
|
|
1894
1862
|
role: "option",
|
|
@@ -1911,8 +1879,6 @@ var factoryOutput = (() => {
|
|
|
1911
1879
|
//* Set the initial state of the input value and the selected country by:
|
|
1912
1880
|
//* 1. Extracting a dial code from the given number
|
|
1913
1881
|
//* 2. Using explicit initialCountry
|
|
1914
|
-
//* 3. Picking the first preferred country
|
|
1915
|
-
//* 4. Picking the first country
|
|
1916
1882
|
_setInitialState(overrideAutoCountry = false) {
|
|
1917
1883
|
const attributeValue = this.telInput.getAttribute("value");
|
|
1918
1884
|
const inputValue = this.telInput.value;
|
|
@@ -2002,12 +1968,12 @@ var factoryOutput = (() => {
|
|
|
2002
1968
|
}
|
|
2003
1969
|
//* Init many requests: utils script / geo ip lookup.
|
|
2004
1970
|
_initRequests() {
|
|
2005
|
-
if (this.options.utilsScript && !
|
|
2006
|
-
if (
|
|
2007
|
-
|
|
1971
|
+
if (this.options.utilsScript && !intlTelInput.utils) {
|
|
1972
|
+
if (intlTelInput.documentReady()) {
|
|
1973
|
+
intlTelInput.loadUtils(this.options.utilsScript);
|
|
2008
1974
|
} else {
|
|
2009
1975
|
window.addEventListener("load", () => {
|
|
2010
|
-
|
|
1976
|
+
intlTelInput.loadUtils(this.options.utilsScript);
|
|
2011
1977
|
});
|
|
2012
1978
|
}
|
|
2013
1979
|
} else {
|
|
@@ -2021,17 +1987,17 @@ var factoryOutput = (() => {
|
|
|
2021
1987
|
}
|
|
2022
1988
|
//* Perform the geo ip lookup.
|
|
2023
1989
|
_loadAutoCountry() {
|
|
2024
|
-
if (
|
|
1990
|
+
if (intlTelInput.autoCountry) {
|
|
2025
1991
|
this.handleAutoCountry();
|
|
2026
|
-
} else if (!
|
|
2027
|
-
|
|
1992
|
+
} else if (!intlTelInput.startedLoadingAutoCountry) {
|
|
1993
|
+
intlTelInput.startedLoadingAutoCountry = true;
|
|
2028
1994
|
if (typeof this.options.geoIpLookup === "function") {
|
|
2029
1995
|
this.options.geoIpLookup(
|
|
2030
1996
|
(iso2 = "") => {
|
|
2031
1997
|
const iso2Lower = iso2.toLowerCase();
|
|
2032
1998
|
const isValidIso2 = iso2Lower && this._getCountryData(iso2Lower, true);
|
|
2033
1999
|
if (isValidIso2) {
|
|
2034
|
-
|
|
2000
|
+
intlTelInput.autoCountry = iso2Lower;
|
|
2035
2001
|
setTimeout(() => forEachInstance("handleAutoCountry"));
|
|
2036
2002
|
} else {
|
|
2037
2003
|
this._setInitialState(true);
|
|
@@ -2048,7 +2014,7 @@ var factoryOutput = (() => {
|
|
|
2048
2014
|
}
|
|
2049
2015
|
//* Initialize the tel input listeners.
|
|
2050
2016
|
_initTelInputListeners() {
|
|
2051
|
-
const { strictMode, formatAsYouType } = this.options;
|
|
2017
|
+
const { strictMode, formatAsYouType, separateDialCode } = this.options;
|
|
2052
2018
|
let userOverrideFormatting = false;
|
|
2053
2019
|
this._handleInputEvent = (e) => {
|
|
2054
2020
|
if (this._updateCountryFromNumber(this.telInput.value)) {
|
|
@@ -2073,17 +2039,26 @@ var factoryOutput = (() => {
|
|
|
2073
2039
|
}
|
|
2074
2040
|
};
|
|
2075
2041
|
this.telInput.addEventListener("input", this._handleInputEvent);
|
|
2076
|
-
if (strictMode) {
|
|
2042
|
+
if (strictMode || separateDialCode) {
|
|
2077
2043
|
this._handleKeydownEvent = (e) => {
|
|
2078
2044
|
if (e.key && e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
|
|
2079
|
-
|
|
2080
|
-
const isNumeric = /^[0-9]$/.test(e.key);
|
|
2081
|
-
const isAllowedChar = isInitialPlus || isNumeric;
|
|
2082
|
-
const fullNumber = this._getFullNumber();
|
|
2083
|
-
const coreNumber = window.intlTelInputUtils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
|
|
2084
|
-
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
|
|
2085
|
-
if (!isAllowedChar || hasReachedMaxLength) {
|
|
2045
|
+
if (separateDialCode && e.key === "+") {
|
|
2086
2046
|
e.preventDefault();
|
|
2047
|
+
this._openDropdown();
|
|
2048
|
+
this.searchInput.value = "+";
|
|
2049
|
+
this._filterCountries("", true);
|
|
2050
|
+
return;
|
|
2051
|
+
}
|
|
2052
|
+
if (strictMode) {
|
|
2053
|
+
const isInitialPlus = this.telInput.selectionStart === 0 && e.key === "+";
|
|
2054
|
+
const isNumeric = /^[0-9]$/.test(e.key);
|
|
2055
|
+
const isAllowedChar = isInitialPlus || isNumeric;
|
|
2056
|
+
const fullNumber = this._getFullNumber();
|
|
2057
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
|
|
2058
|
+
const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
|
|
2059
|
+
if (!isAllowedChar || hasReachedMaxLength) {
|
|
2060
|
+
e.preventDefault();
|
|
2061
|
+
}
|
|
2087
2062
|
}
|
|
2088
2063
|
}
|
|
2089
2064
|
};
|
|
@@ -2105,26 +2080,19 @@ var factoryOutput = (() => {
|
|
|
2105
2080
|
}
|
|
2106
2081
|
//* Open the dropdown.
|
|
2107
2082
|
_openDropdown() {
|
|
2108
|
-
const { fixDropdownWidth
|
|
2083
|
+
const { fixDropdownWidth } = this.options;
|
|
2109
2084
|
if (fixDropdownWidth) {
|
|
2110
2085
|
this.dropdownContent.style.width = `${this.telInput.offsetWidth}px`;
|
|
2111
2086
|
}
|
|
2112
2087
|
this.dropdownContent.classList.remove("iti__hide");
|
|
2113
2088
|
this.selectedCountry.setAttribute("aria-expanded", "true");
|
|
2114
2089
|
this._setDropdownPosition();
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
this.
|
|
2118
|
-
|
|
2119
|
-
const firstCountryItem = this.countryList.firstElementChild;
|
|
2120
|
-
if (firstCountryItem) {
|
|
2121
|
-
this._highlightListItem(firstCountryItem, false);
|
|
2122
|
-
this.countryList.scrollTop = 0;
|
|
2123
|
-
}
|
|
2124
|
-
if (countrySearch) {
|
|
2125
|
-
this.searchInput.focus();
|
|
2126
|
-
}
|
|
2090
|
+
const firstCountryItem = this.countryList.firstElementChild;
|
|
2091
|
+
if (firstCountryItem) {
|
|
2092
|
+
this._highlightListItem(firstCountryItem, false);
|
|
2093
|
+
this.countryList.scrollTop = 0;
|
|
2127
2094
|
}
|
|
2095
|
+
this.searchInput.focus();
|
|
2128
2096
|
this._bindDropdownListeners();
|
|
2129
2097
|
this.dropdownArrow.classList.add("iti__arrow--up");
|
|
2130
2098
|
this._trigger("open:countrydropdown");
|
|
@@ -2136,21 +2104,9 @@ var factoryOutput = (() => {
|
|
|
2136
2104
|
}
|
|
2137
2105
|
if (!this.options.useFullscreenPopup) {
|
|
2138
2106
|
const inputPosRelativeToVP = this.telInput.getBoundingClientRect();
|
|
2139
|
-
const scrollTop = document.documentElement.scrollTop;
|
|
2140
|
-
const inputTopAbsolute = inputPosRelativeToVP.top + scrollTop;
|
|
2141
2107
|
const inputHeight = this.telInput.offsetHeight;
|
|
2142
|
-
const dropdownHeight = this.dropdownContent.offsetHeight;
|
|
2143
|
-
const dropdownFitsBelow = inputTopAbsolute + inputHeight + dropdownHeight < scrollTop + window.innerHeight;
|
|
2144
|
-
const dropdownFitsAbove = inputTopAbsolute - dropdownHeight > scrollTop;
|
|
2145
|
-
const positionDropdownAboveInput = !this.options.countrySearch && !dropdownFitsBelow && dropdownFitsAbove;
|
|
2146
|
-
toggleClass(
|
|
2147
|
-
this.dropdownContent,
|
|
2148
|
-
"iti__dropdown-content--dropup",
|
|
2149
|
-
positionDropdownAboveInput
|
|
2150
|
-
);
|
|
2151
2108
|
if (this.options.dropdownContainer) {
|
|
2152
|
-
|
|
2153
|
-
this.dropdown.style.top = `${inputPosRelativeToVP.top + extraTop}px`;
|
|
2109
|
+
this.dropdown.style.top = `${inputPosRelativeToVP.top + inputHeight}px`;
|
|
2154
2110
|
this.dropdown.style.left = `${inputPosRelativeToVP.left}px`;
|
|
2155
2111
|
this._handleWindowScroll = () => this._closeDropdown();
|
|
2156
2112
|
window.addEventListener("scroll", this._handleWindowScroll);
|
|
@@ -2187,8 +2143,6 @@ var factoryOutput = (() => {
|
|
|
2187
2143
|
"click",
|
|
2188
2144
|
this._handleClickOffToClose
|
|
2189
2145
|
);
|
|
2190
|
-
let query = "";
|
|
2191
|
-
let queryTimer = null;
|
|
2192
2146
|
this._handleKeydownOnDropdown = (e) => {
|
|
2193
2147
|
if (["ArrowUp", "ArrowDown", "Enter", "Escape"].includes(e.key)) {
|
|
2194
2148
|
e.preventDefault();
|
|
@@ -2201,41 +2155,28 @@ var factoryOutput = (() => {
|
|
|
2201
2155
|
this._closeDropdown();
|
|
2202
2156
|
}
|
|
2203
2157
|
}
|
|
2204
|
-
if (!this.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
|
|
2205
|
-
e.stopPropagation();
|
|
2206
|
-
if (queryTimer) {
|
|
2207
|
-
clearTimeout(queryTimer);
|
|
2208
|
-
}
|
|
2209
|
-
query += e.key.toLowerCase();
|
|
2210
|
-
this._searchForCountry(query);
|
|
2211
|
-
queryTimer = setTimeout(() => {
|
|
2212
|
-
query = "";
|
|
2213
|
-
}, 1e3);
|
|
2214
|
-
}
|
|
2215
2158
|
};
|
|
2216
2159
|
document.addEventListener("keydown", this._handleKeydownOnDropdown);
|
|
2217
|
-
|
|
2218
|
-
const
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
this.searchInput.addEventListener("click", (e) => e.stopPropagation());
|
|
2238
|
-
}
|
|
2160
|
+
const doFilter = () => {
|
|
2161
|
+
const inputQuery = this.searchInput.value.trim();
|
|
2162
|
+
if (inputQuery) {
|
|
2163
|
+
this._filterCountries(inputQuery);
|
|
2164
|
+
} else {
|
|
2165
|
+
this._filterCountries("", true);
|
|
2166
|
+
}
|
|
2167
|
+
};
|
|
2168
|
+
let keyupTimer = null;
|
|
2169
|
+
this._handleSearchChange = () => {
|
|
2170
|
+
if (keyupTimer) {
|
|
2171
|
+
clearTimeout(keyupTimer);
|
|
2172
|
+
}
|
|
2173
|
+
keyupTimer = setTimeout(() => {
|
|
2174
|
+
doFilter();
|
|
2175
|
+
keyupTimer = null;
|
|
2176
|
+
}, 100);
|
|
2177
|
+
};
|
|
2178
|
+
this.searchInput.addEventListener("input", this._handleSearchChange);
|
|
2179
|
+
this.searchInput.addEventListener("click", (e) => e.stopPropagation());
|
|
2239
2180
|
}
|
|
2240
2181
|
_filterCountries(query, isReset = false) {
|
|
2241
2182
|
let isFirst = true;
|
|
@@ -2276,17 +2217,12 @@ var factoryOutput = (() => {
|
|
|
2276
2217
|
//* Highlight the next/prev item in the list (and ensure it is visible).
|
|
2277
2218
|
_handleUpDownKey(key) {
|
|
2278
2219
|
let next = key === "ArrowUp" ? this.highlightedItem?.previousElementSibling : this.highlightedItem?.nextElementSibling;
|
|
2279
|
-
if (next) {
|
|
2280
|
-
if (next.classList.contains("iti__divider")) {
|
|
2281
|
-
next = key === "ArrowUp" ? next.previousElementSibling : next.nextElementSibling;
|
|
2282
|
-
}
|
|
2283
|
-
} else if (this.countryList.childElementCount > 1) {
|
|
2220
|
+
if (!next && this.countryList.childElementCount > 1) {
|
|
2284
2221
|
next = key === "ArrowUp" ? this.countryList.lastElementChild : this.countryList.firstElementChild;
|
|
2285
2222
|
}
|
|
2286
2223
|
if (next) {
|
|
2287
|
-
this._scrollTo(next
|
|
2288
|
-
|
|
2289
|
-
this._highlightListItem(next, doFocus);
|
|
2224
|
+
this._scrollTo(next);
|
|
2225
|
+
this._highlightListItem(next, false);
|
|
2290
2226
|
}
|
|
2291
2227
|
}
|
|
2292
2228
|
//* Select the currently highlighted item.
|
|
@@ -2295,28 +2231,15 @@ var factoryOutput = (() => {
|
|
|
2295
2231
|
this._selectListItem(this.highlightedItem);
|
|
2296
2232
|
}
|
|
2297
2233
|
}
|
|
2298
|
-
//* Find the first list item whose name starts with the query string.
|
|
2299
|
-
_searchForCountry(query) {
|
|
2300
|
-
for (let i = 0; i < this.countries.length; i++) {
|
|
2301
|
-
const c = this.countries[i];
|
|
2302
|
-
const startsWith = c.name.substr(0, query.length).toLowerCase() === query;
|
|
2303
|
-
if (startsWith) {
|
|
2304
|
-
const listItem = c.nodeById[this.id];
|
|
2305
|
-
this._highlightListItem(listItem, false);
|
|
2306
|
-
this._scrollTo(listItem, true);
|
|
2307
|
-
break;
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
}
|
|
2311
2234
|
//* Update the input's value to the given val (format first if possible)
|
|
2312
2235
|
//* NOTE: this is called from _setInitialState, handleUtils and setNumber.
|
|
2313
2236
|
_updateValFromNumber(fullNumber) {
|
|
2314
2237
|
let number = fullNumber;
|
|
2315
|
-
if (this.options.formatOnDisplay &&
|
|
2316
|
-
const useNational = this.options.nationalMode || number.charAt(0) !== "+" && !this.options.
|
|
2317
|
-
const { NATIONAL, INTERNATIONAL } =
|
|
2238
|
+
if (this.options.formatOnDisplay && intlTelInput.utils && this.selectedCountryData) {
|
|
2239
|
+
const useNational = this.options.nationalMode || number.charAt(0) !== "+" && !this.options.separateDialCode;
|
|
2240
|
+
const { NATIONAL, INTERNATIONAL } = intlTelInput.utils.numberFormat;
|
|
2318
2241
|
const format = useNational ? NATIONAL : INTERNATIONAL;
|
|
2319
|
-
number =
|
|
2242
|
+
number = intlTelInput.utils.formatNumber(
|
|
2320
2243
|
number,
|
|
2321
2244
|
this.selectedCountryData.iso2,
|
|
2322
2245
|
format
|
|
@@ -2338,7 +2261,7 @@ var factoryOutput = (() => {
|
|
|
2338
2261
|
}
|
|
2339
2262
|
number = `+${number}`;
|
|
2340
2263
|
}
|
|
2341
|
-
if (this.options.
|
|
2264
|
+
if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") {
|
|
2342
2265
|
number = `+${selectedDialCode}${number}`;
|
|
2343
2266
|
}
|
|
2344
2267
|
const dialCode = this._getDialCode(number, true);
|
|
@@ -2380,12 +2303,10 @@ var factoryOutput = (() => {
|
|
|
2380
2303
|
"aria-activedescendant",
|
|
2381
2304
|
listItem.getAttribute("id") || ""
|
|
2382
2305
|
);
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
);
|
|
2388
|
-
}
|
|
2306
|
+
this.searchInput.setAttribute(
|
|
2307
|
+
"aria-activedescendant",
|
|
2308
|
+
listItem.getAttribute("id") || ""
|
|
2309
|
+
);
|
|
2389
2310
|
if (shouldFocus) {
|
|
2390
2311
|
this.highlightedItem.focus();
|
|
2391
2312
|
}
|
|
@@ -2403,10 +2324,10 @@ var factoryOutput = (() => {
|
|
|
2403
2324
|
}
|
|
2404
2325
|
throw new Error(`No country data for '${iso2}'`);
|
|
2405
2326
|
}
|
|
2406
|
-
//* Update the selected country, dial code (if
|
|
2327
|
+
//* Update the selected country, dial code (if separateDialCode), placeholder, title, and active list item.
|
|
2407
2328
|
//* Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry.
|
|
2408
2329
|
_setCountry(iso2) {
|
|
2409
|
-
const {
|
|
2330
|
+
const { separateDialCode, showFlags, i18n } = this.options;
|
|
2410
2331
|
const prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
|
|
2411
2332
|
this.selectedCountryData = iso2 ? this._getCountryData(iso2, false) || {} : {};
|
|
2412
2333
|
if (this.selectedCountryData.iso2) {
|
|
@@ -2415,11 +2336,9 @@ var factoryOutput = (() => {
|
|
|
2415
2336
|
if (this.selectedCountryInner) {
|
|
2416
2337
|
let flagClass = "";
|
|
2417
2338
|
let a11yText = "";
|
|
2418
|
-
if (iso2) {
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
a11yText = `${this.selectedCountryData.name} +${this.selectedCountryData.dialCode}`;
|
|
2422
|
-
}
|
|
2339
|
+
if (iso2 && showFlags) {
|
|
2340
|
+
flagClass = `iti__flag iti__${iso2}`;
|
|
2341
|
+
a11yText = `${this.selectedCountryData.name} +${this.selectedCountryData.dialCode}`;
|
|
2423
2342
|
} else {
|
|
2424
2343
|
flagClass = "iti__flag iti__globe";
|
|
2425
2344
|
a11yText = i18n.noCountrySelected;
|
|
@@ -2427,69 +2346,51 @@ var factoryOutput = (() => {
|
|
|
2427
2346
|
this.selectedCountryInner.className = flagClass;
|
|
2428
2347
|
this.selectedCountryA11yText.textContent = a11yText;
|
|
2429
2348
|
}
|
|
2430
|
-
this._setSelectedCountryTitleAttribute(iso2,
|
|
2431
|
-
if (
|
|
2349
|
+
this._setSelectedCountryTitleAttribute(iso2, separateDialCode);
|
|
2350
|
+
if (separateDialCode) {
|
|
2432
2351
|
const dialCode = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
|
|
2433
2352
|
this.selectedDialCode.innerHTML = dialCode;
|
|
2434
2353
|
const selectedCountryWidth = this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth();
|
|
2354
|
+
const inputPadding = selectedCountryWidth + 8;
|
|
2435
2355
|
if (this.isRTL) {
|
|
2436
|
-
this.telInput.style.paddingRight = `${
|
|
2356
|
+
this.telInput.style.paddingRight = `${inputPadding}px`;
|
|
2437
2357
|
} else {
|
|
2438
|
-
this.telInput.style.paddingLeft = `${
|
|
2358
|
+
this.telInput.style.paddingLeft = `${inputPadding}px`;
|
|
2439
2359
|
}
|
|
2440
2360
|
}
|
|
2441
2361
|
this._updatePlaceholder();
|
|
2442
2362
|
this._updateMaxLength();
|
|
2443
|
-
if (allowDropdown && !countrySearch) {
|
|
2444
|
-
const prevItem = this.activeItem;
|
|
2445
|
-
if (prevItem) {
|
|
2446
|
-
prevItem.classList.remove("iti__active");
|
|
2447
|
-
prevItem.setAttribute("aria-selected", "false");
|
|
2448
|
-
}
|
|
2449
|
-
if (iso2) {
|
|
2450
|
-
const nextItem = this.countryList.querySelector(
|
|
2451
|
-
`#iti-${this.id}__item-${iso2}-preferred`
|
|
2452
|
-
) || this.countryList.querySelector(
|
|
2453
|
-
`#iti-${this.id}__item-${iso2}`
|
|
2454
|
-
);
|
|
2455
|
-
if (nextItem) {
|
|
2456
|
-
nextItem.setAttribute("aria-selected", "true");
|
|
2457
|
-
nextItem.classList.add("iti__active");
|
|
2458
|
-
this.activeItem = nextItem;
|
|
2459
|
-
}
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
2363
|
return prevCountry.iso2 !== iso2;
|
|
2463
2364
|
}
|
|
2464
2365
|
//* Update the maximum valid number length for the currently selected country.
|
|
2465
2366
|
_updateMaxLength() {
|
|
2466
|
-
if (this.options.strictMode &&
|
|
2367
|
+
if (this.options.strictMode && intlTelInput.utils) {
|
|
2467
2368
|
if (this.selectedCountryData.iso2) {
|
|
2468
|
-
const numberType =
|
|
2469
|
-
let exampleNumber =
|
|
2369
|
+
const numberType = intlTelInput.utils.numberType[this.options.placeholderNumberType];
|
|
2370
|
+
let exampleNumber = intlTelInput.utils.getExampleNumber(
|
|
2470
2371
|
this.selectedCountryData.iso2,
|
|
2471
2372
|
false,
|
|
2472
2373
|
numberType,
|
|
2473
2374
|
true
|
|
2474
2375
|
);
|
|
2475
2376
|
let validNumber = exampleNumber;
|
|
2476
|
-
while (
|
|
2377
|
+
while (intlTelInput.utils.isPossibleNumber(exampleNumber, this.selectedCountryData.iso2)) {
|
|
2477
2378
|
validNumber = exampleNumber;
|
|
2478
2379
|
exampleNumber += "0";
|
|
2479
2380
|
}
|
|
2480
|
-
const coreNumber =
|
|
2381
|
+
const coreNumber = intlTelInput.utils.getCoreNumber(validNumber, this.selectedCountryData.iso2);
|
|
2481
2382
|
this.maxCoreNumberLength = coreNumber.length;
|
|
2482
2383
|
} else {
|
|
2483
2384
|
this.maxCoreNumberLength = null;
|
|
2484
2385
|
}
|
|
2485
2386
|
}
|
|
2486
2387
|
}
|
|
2487
|
-
_setSelectedCountryTitleAttribute(iso2 = null,
|
|
2388
|
+
_setSelectedCountryTitleAttribute(iso2 = null, separateDialCode) {
|
|
2488
2389
|
if (!this.selectedCountry) {
|
|
2489
2390
|
return;
|
|
2490
2391
|
}
|
|
2491
2392
|
let title;
|
|
2492
|
-
if (iso2 && !
|
|
2393
|
+
if (iso2 && !separateDialCode) {
|
|
2493
2394
|
title = `${this.selectedCountryData.name}: +${this.selectedCountryData.dialCode}`;
|
|
2494
2395
|
} else if (iso2) {
|
|
2495
2396
|
title = this.selectedCountryData.name;
|
|
@@ -2500,7 +2401,7 @@ var factoryOutput = (() => {
|
|
|
2500
2401
|
}
|
|
2501
2402
|
//* When the input is in a hidden container during initialisation, we must inject some markup
|
|
2502
2403
|
//* into the end of the DOM to calculate the correct offsetWidth.
|
|
2503
|
-
//* NOTE: this is only used when
|
|
2404
|
+
//* NOTE: this is only used when separateDialCode is enabled, so countryContainer and selectedCountry
|
|
2504
2405
|
//* will definitely exist.
|
|
2505
2406
|
_getHiddenSelectedCountryWidth() {
|
|
2506
2407
|
if (this.telInput.parentNode) {
|
|
@@ -2526,9 +2427,9 @@ var factoryOutput = (() => {
|
|
|
2526
2427
|
customPlaceholder
|
|
2527
2428
|
} = this.options;
|
|
2528
2429
|
const shouldSetPlaceholder = autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && autoPlaceholder === "polite";
|
|
2529
|
-
if (
|
|
2530
|
-
const numberType =
|
|
2531
|
-
let placeholder = this.selectedCountryData.iso2 ?
|
|
2430
|
+
if (intlTelInput.utils && shouldSetPlaceholder) {
|
|
2431
|
+
const numberType = intlTelInput.utils.numberType[placeholderNumberType];
|
|
2432
|
+
let placeholder = this.selectedCountryData.iso2 ? intlTelInput.utils.getExampleNumber(
|
|
2532
2433
|
this.selectedCountryData.iso2,
|
|
2533
2434
|
nationalMode,
|
|
2534
2435
|
numberType
|
|
@@ -2560,14 +2461,10 @@ var factoryOutput = (() => {
|
|
|
2560
2461
|
if (this.highlightedItem) {
|
|
2561
2462
|
this.highlightedItem.setAttribute("aria-selected", "false");
|
|
2562
2463
|
}
|
|
2563
|
-
|
|
2564
|
-
this.searchInput.removeAttribute("aria-activedescendant");
|
|
2565
|
-
}
|
|
2464
|
+
this.searchInput.removeAttribute("aria-activedescendant");
|
|
2566
2465
|
this.dropdownArrow.classList.remove("iti__arrow--up");
|
|
2567
2466
|
document.removeEventListener("keydown", this._handleKeydownOnDropdown);
|
|
2568
|
-
|
|
2569
|
-
this.searchInput.removeEventListener("input", this._handleSearchChange);
|
|
2570
|
-
}
|
|
2467
|
+
this.searchInput.removeEventListener("input", this._handleSearchChange);
|
|
2571
2468
|
document.documentElement.removeEventListener(
|
|
2572
2469
|
"click",
|
|
2573
2470
|
this._handleClickOffToClose
|
|
@@ -2588,7 +2485,7 @@ var factoryOutput = (() => {
|
|
|
2588
2485
|
this._trigger("close:countrydropdown");
|
|
2589
2486
|
}
|
|
2590
2487
|
//* Check if an element is visible within it's container, else scroll until it is.
|
|
2591
|
-
_scrollTo(element
|
|
2488
|
+
_scrollTo(element) {
|
|
2592
2489
|
const container = this.countryList;
|
|
2593
2490
|
const scrollTop = document.documentElement.scrollTop;
|
|
2594
2491
|
const containerHeight = container.offsetHeight;
|
|
@@ -2597,17 +2494,10 @@ var factoryOutput = (() => {
|
|
|
2597
2494
|
const elementHeight = element.offsetHeight;
|
|
2598
2495
|
const elementTop = element.getBoundingClientRect().top + scrollTop;
|
|
2599
2496
|
const elementBottom = elementTop + elementHeight;
|
|
2600
|
-
|
|
2601
|
-
const middleOffset = containerHeight / 2 - elementHeight / 2;
|
|
2497
|
+
const newScrollTop = elementTop - containerTop + container.scrollTop;
|
|
2602
2498
|
if (elementTop < containerTop) {
|
|
2603
|
-
if (middle) {
|
|
2604
|
-
newScrollTop -= middleOffset;
|
|
2605
|
-
}
|
|
2606
2499
|
container.scrollTop = newScrollTop;
|
|
2607
2500
|
} else if (elementBottom > containerBottom) {
|
|
2608
|
-
if (middle) {
|
|
2609
|
-
newScrollTop += middleOffset;
|
|
2610
|
-
}
|
|
2611
2501
|
const heightDifference = containerHeight - elementHeight;
|
|
2612
2502
|
container.scrollTop = newScrollTop - heightDifference;
|
|
2613
2503
|
}
|
|
@@ -2656,23 +2546,23 @@ var factoryOutput = (() => {
|
|
|
2656
2546
|
}
|
|
2657
2547
|
return dialCode;
|
|
2658
2548
|
}
|
|
2659
|
-
//* Get the input val, adding the dial code if
|
|
2549
|
+
//* Get the input val, adding the dial code if separateDialCode is enabled.
|
|
2660
2550
|
_getFullNumber() {
|
|
2661
2551
|
const val = this.telInput.value.trim();
|
|
2662
2552
|
const { dialCode } = this.selectedCountryData;
|
|
2663
2553
|
let prefix;
|
|
2664
2554
|
const numericVal = getNumeric(val);
|
|
2665
|
-
if (this.options.
|
|
2555
|
+
if (this.options.separateDialCode && val.charAt(0) !== "+" && dialCode && numericVal) {
|
|
2666
2556
|
prefix = `+${dialCode}`;
|
|
2667
2557
|
} else {
|
|
2668
2558
|
prefix = "";
|
|
2669
2559
|
}
|
|
2670
2560
|
return prefix + val;
|
|
2671
2561
|
}
|
|
2672
|
-
//* Remove the dial code if
|
|
2562
|
+
//* Remove the dial code if separateDialCode is enabled also cap the length if the input has a maxlength attribute
|
|
2673
2563
|
_beforeSetNumber(fullNumber) {
|
|
2674
2564
|
let number = fullNumber;
|
|
2675
|
-
if (this.options.
|
|
2565
|
+
if (this.options.separateDialCode) {
|
|
2676
2566
|
let dialCode = this._getDialCode(number);
|
|
2677
2567
|
if (dialCode) {
|
|
2678
2568
|
dialCode = `+${this.selectedCountryData.dialCode}`;
|
|
@@ -2689,9 +2579,9 @@ var factoryOutput = (() => {
|
|
|
2689
2579
|
//* Format the number as the user types.
|
|
2690
2580
|
_formatNumberAsYouType() {
|
|
2691
2581
|
const val = this._getFullNumber();
|
|
2692
|
-
const result =
|
|
2582
|
+
const result = intlTelInput.utils ? intlTelInput.utils.formatNumberAsYouType(val, this.selectedCountryData.iso2) : val;
|
|
2693
2583
|
const { dialCode } = this.selectedCountryData;
|
|
2694
|
-
if (this.options.
|
|
2584
|
+
if (this.options.separateDialCode && this.telInput.value.charAt(0) !== "+" && result.includes(`+${dialCode}`)) {
|
|
2695
2585
|
const afterDialCode = result.split(`+${dialCode}`)[1] || "";
|
|
2696
2586
|
return afterDialCode.trim();
|
|
2697
2587
|
}
|
|
@@ -2702,8 +2592,8 @@ var factoryOutput = (() => {
|
|
|
2702
2592
|
//**************************
|
|
2703
2593
|
//* This is called when the geoip call returns.
|
|
2704
2594
|
handleAutoCountry() {
|
|
2705
|
-
if (this.options.initialCountry === "auto" &&
|
|
2706
|
-
this.defaultCountry =
|
|
2595
|
+
if (this.options.initialCountry === "auto" && intlTelInput.autoCountry) {
|
|
2596
|
+
this.defaultCountry = intlTelInput.autoCountry;
|
|
2707
2597
|
if (!this.telInput.value) {
|
|
2708
2598
|
this.setCountry(this.defaultCountry);
|
|
2709
2599
|
}
|
|
@@ -2712,7 +2602,7 @@ var factoryOutput = (() => {
|
|
|
2712
2602
|
}
|
|
2713
2603
|
//* This is called when the utils request completes.
|
|
2714
2604
|
handleUtils() {
|
|
2715
|
-
if (
|
|
2605
|
+
if (intlTelInput.utils) {
|
|
2716
2606
|
if (this.telInput.value) {
|
|
2717
2607
|
this._updateValFromNumber(this.telInput.value);
|
|
2718
2608
|
}
|
|
@@ -2755,12 +2645,12 @@ var factoryOutput = (() => {
|
|
|
2755
2645
|
const wrapper = this.telInput.parentNode;
|
|
2756
2646
|
wrapper?.parentNode?.insertBefore(this.telInput, wrapper);
|
|
2757
2647
|
wrapper?.parentNode?.removeChild(wrapper);
|
|
2758
|
-
delete
|
|
2648
|
+
delete intlTelInput.instances[this.id];
|
|
2759
2649
|
}
|
|
2760
2650
|
//* Get the extension from the current number.
|
|
2761
2651
|
getExtension() {
|
|
2762
|
-
if (
|
|
2763
|
-
return
|
|
2652
|
+
if (intlTelInput.utils) {
|
|
2653
|
+
return intlTelInput.utils.getExtension(
|
|
2764
2654
|
this._getFullNumber(),
|
|
2765
2655
|
this.selectedCountryData.iso2
|
|
2766
2656
|
);
|
|
@@ -2769,9 +2659,9 @@ var factoryOutput = (() => {
|
|
|
2769
2659
|
}
|
|
2770
2660
|
//* Format the number to the given format.
|
|
2771
2661
|
getNumber(format) {
|
|
2772
|
-
if (
|
|
2662
|
+
if (intlTelInput.utils) {
|
|
2773
2663
|
const { iso2 } = this.selectedCountryData;
|
|
2774
|
-
return
|
|
2664
|
+
return intlTelInput.utils.formatNumber(
|
|
2775
2665
|
this._getFullNumber(),
|
|
2776
2666
|
iso2,
|
|
2777
2667
|
format
|
|
@@ -2781,8 +2671,8 @@ var factoryOutput = (() => {
|
|
|
2781
2671
|
}
|
|
2782
2672
|
//* Get the type of the entered number e.g. landline/mobile.
|
|
2783
2673
|
getNumberType() {
|
|
2784
|
-
if (
|
|
2785
|
-
return
|
|
2674
|
+
if (intlTelInput.utils) {
|
|
2675
|
+
return intlTelInput.utils.getNumberType(
|
|
2786
2676
|
this._getFullNumber(),
|
|
2787
2677
|
this.selectedCountryData.iso2
|
|
2788
2678
|
);
|
|
@@ -2795,27 +2685,27 @@ var factoryOutput = (() => {
|
|
|
2795
2685
|
}
|
|
2796
2686
|
//* Get the validation error.
|
|
2797
2687
|
getValidationError() {
|
|
2798
|
-
if (
|
|
2688
|
+
if (intlTelInput.utils) {
|
|
2799
2689
|
const { iso2 } = this.selectedCountryData;
|
|
2800
|
-
return
|
|
2690
|
+
return intlTelInput.utils.getValidationError(this._getFullNumber(), iso2);
|
|
2801
2691
|
}
|
|
2802
2692
|
return -99;
|
|
2803
2693
|
}
|
|
2804
|
-
//* Validate the input val
|
|
2694
|
+
//* Validate the input val
|
|
2805
2695
|
isValidNumber(mobileOnly = true) {
|
|
2806
2696
|
const val = this._getFullNumber();
|
|
2807
2697
|
if (/\p{L}/u.test(val)) {
|
|
2808
2698
|
return false;
|
|
2809
2699
|
}
|
|
2810
|
-
return
|
|
2700
|
+
return intlTelInput.utils ? intlTelInput.utils.isPossibleNumber(val, this.selectedCountryData.iso2, mobileOnly) : null;
|
|
2811
2701
|
}
|
|
2812
|
-
//* Validate the input val (precise)
|
|
2702
|
+
//* Validate the input val (precise)
|
|
2813
2703
|
isValidNumberPrecise() {
|
|
2814
2704
|
const val = this._getFullNumber();
|
|
2815
2705
|
if (/\p{L}/u.test(val)) {
|
|
2816
2706
|
return false;
|
|
2817
2707
|
}
|
|
2818
|
-
return
|
|
2708
|
+
return intlTelInput.utils ? intlTelInput.utils.isValidNumber(val, this.selectedCountryData.iso2) : null;
|
|
2819
2709
|
}
|
|
2820
2710
|
//* Update the selected country, and update the input val accordingly.
|
|
2821
2711
|
setCountry(iso2) {
|
|
@@ -2840,9 +2730,17 @@ var factoryOutput = (() => {
|
|
|
2840
2730
|
this._updatePlaceholder();
|
|
2841
2731
|
}
|
|
2842
2732
|
};
|
|
2843
|
-
var
|
|
2733
|
+
var injectUtilsScriptTag = (path, handleSuccess, handleFailure) => {
|
|
2844
2734
|
const script = document.createElement("script");
|
|
2845
2735
|
script.onload = () => {
|
|
2736
|
+
if (window.intlTelInputUtils) {
|
|
2737
|
+
intlTelInput.utils = window.intlTelInputUtils;
|
|
2738
|
+
delete window.intlTelInputUtils;
|
|
2739
|
+
if (window.intlTelInputUtilsBackup) {
|
|
2740
|
+
window.intlTelInputUtils = window.intlTelInputUtilsBackup;
|
|
2741
|
+
delete window.intlTelInputUtilsBackup;
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2846
2744
|
forEachInstance("handleUtils");
|
|
2847
2745
|
if (handleSuccess) {
|
|
2848
2746
|
handleSuccess();
|
|
@@ -2860,40 +2758,39 @@ var factoryOutput = (() => {
|
|
|
2860
2758
|
document.body.appendChild(script);
|
|
2861
2759
|
};
|
|
2862
2760
|
var loadUtils = (path) => {
|
|
2863
|
-
if (!
|
|
2864
|
-
|
|
2761
|
+
if (!intlTelInput.utils && !intlTelInput.startedLoadingUtilsScript) {
|
|
2762
|
+
intlTelInput.startedLoadingUtilsScript = true;
|
|
2865
2763
|
return new Promise(
|
|
2866
|
-
(resolve, reject) =>
|
|
2764
|
+
(resolve, reject) => injectUtilsScriptTag(path, resolve, reject)
|
|
2867
2765
|
);
|
|
2868
2766
|
}
|
|
2869
2767
|
return null;
|
|
2870
2768
|
};
|
|
2871
|
-
|
|
2872
|
-
|
|
2769
|
+
var intlTelInput = Object.assign(
|
|
2770
|
+
(input, options) => {
|
|
2771
|
+
const iti = new Iti(input, options);
|
|
2772
|
+
iti._init();
|
|
2773
|
+
input.setAttribute("data-intl-tel-input-id", iti.id.toString());
|
|
2774
|
+
intlTelInput.instances[iti.id] = iti;
|
|
2775
|
+
return iti;
|
|
2776
|
+
},
|
|
2777
|
+
{
|
|
2873
2778
|
defaults,
|
|
2874
|
-
//* Using a
|
|
2779
|
+
//* Using a static var like this allows us to mock it in the tests.
|
|
2875
2780
|
documentReady: () => document.readyState === "complete",
|
|
2876
2781
|
//* Get the country data object.
|
|
2877
2782
|
getCountryData: () => data_default,
|
|
2878
2783
|
//* A getter for the plugin instance.
|
|
2879
2784
|
getInstance: (input) => {
|
|
2880
2785
|
const id2 = input.getAttribute("data-intl-tel-input-id");
|
|
2881
|
-
return id2 ?
|
|
2786
|
+
return id2 ? intlTelInput.instances[id2] : null;
|
|
2882
2787
|
},
|
|
2883
2788
|
//* A map from instance ID to instance object.
|
|
2884
2789
|
instances: {},
|
|
2885
2790
|
loadUtils,
|
|
2886
|
-
version: "
|
|
2887
|
-
}
|
|
2888
|
-
|
|
2889
|
-
}
|
|
2890
|
-
var intlTelInput = (input, options) => {
|
|
2891
|
-
const iti = new Iti(input, options);
|
|
2892
|
-
iti._init();
|
|
2893
|
-
input.setAttribute("data-intl-tel-input-id", iti.id.toString());
|
|
2894
|
-
window.intlTelInputGlobals.instances[iti.id] = iti;
|
|
2895
|
-
return iti;
|
|
2896
|
-
};
|
|
2791
|
+
version: "22.0.0"
|
|
2792
|
+
}
|
|
2793
|
+
);
|
|
2897
2794
|
var intl_tel_input_default = intlTelInput;
|
|
2898
2795
|
return __toCommonJS(intl_tel_input_exports);
|
|
2899
2796
|
})();
|